2004-08-10 04:57:20 +04:00
|
|
|
/* $NetBSD: an.c,v 1.31 2004/08/10 00:57:20 dyoung Exp $ */
|
2000-12-12 02:16:50 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997, 1998, 1999
|
|
|
|
* Bill Paul <wpaul@ctr.columbia.edu>. 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: src/sys/dev/an/if_an.c,v 1.12 2000/11/13 23:04:12 wpaul Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Aironet 4500/4800 802.11 PCMCIA/ISA/PCI driver for FreeBSD.
|
|
|
|
*
|
|
|
|
* Written by Bill Paul <wpaul@ctr.columbia.edu>
|
|
|
|
* Electrical Engineering Department
|
|
|
|
* Columbia University, New York City
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ported to NetBSD from FreeBSD by Atsushi Onoe at the San Diego
|
|
|
|
* IETF meeting.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-08-10 04:57:20 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.31 2004/08/10 00:57:20 dyoung Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
2000-12-12 02:16:50 +03:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
2001-06-21 16:49:06 +04:00
|
|
|
#include <sys/proc.h>
|
2001-06-29 15:24:42 +04:00
|
|
|
#include <sys/md4.h>
|
2004-01-28 18:07:52 +03:00
|
|
|
#include <sys/endian.h>
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
2004-01-28 18:07:52 +03:00
|
|
|
#include <net/if_llc.h>
|
2003-07-06 11:54:43 +04:00
|
|
|
#include <net/if_media.h>
|
2000-12-12 02:16:50 +03:00
|
|
|
#include <net/if_types.h>
|
|
|
|
|
2003-10-13 10:45:32 +04:00
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
#include <net80211/ieee80211_compat.h>
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <dev/ic/anreg.h>
|
2000-12-12 08:11:15 +03:00
|
|
|
#include <dev/ic/anvar.h>
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
static int an_reset(struct an_softc *);
|
|
|
|
static void an_wait(struct an_softc *);
|
|
|
|
static int an_init(struct ifnet *);
|
|
|
|
static void an_stop(struct ifnet *, int);
|
|
|
|
static void an_start(struct ifnet *);
|
|
|
|
static void an_watchdog(struct ifnet *);
|
|
|
|
static int an_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static int an_media_change(struct ifnet *);
|
|
|
|
static void an_media_status(struct ifnet *, struct ifmediareq *);
|
|
|
|
|
|
|
|
static int an_set_nwkey(struct an_softc *, struct ieee80211_nwkey *);
|
|
|
|
static int an_set_nwkey_wep(struct an_softc *, struct ieee80211_nwkey *);
|
|
|
|
static int an_set_nwkey_eap(struct an_softc *, struct ieee80211_nwkey *);
|
|
|
|
static int an_get_nwkey(struct an_softc *, struct ieee80211_nwkey *);
|
|
|
|
static int an_write_wepkey(struct an_softc *, int, struct an_wepkey *, int);
|
|
|
|
|
|
|
|
static void an_rx_intr(struct an_softc *);
|
|
|
|
static void an_tx_intr(struct an_softc *, int);
|
|
|
|
static void an_linkstat_intr(struct an_softc *);
|
|
|
|
|
|
|
|
static int an_cmd(struct an_softc *, int, int);
|
|
|
|
static int an_seek_bap(struct an_softc *, int, int);
|
|
|
|
static int an_read_bap(struct an_softc *, int, int, void *, int);
|
|
|
|
static int an_write_bap(struct an_softc *, int, int, void *, int);
|
|
|
|
static int an_mwrite_bap(struct an_softc *, int, int, struct mbuf *, int);
|
|
|
|
static int an_read_rid(struct an_softc *, int, void *, int *);
|
|
|
|
static int an_write_rid(struct an_softc *, int, void *, int);
|
|
|
|
|
|
|
|
static int an_alloc_fid(struct an_softc *, int, int *);
|
|
|
|
|
|
|
|
static int an_newstate(struct ieee80211com *, enum ieee80211_state, int);
|
|
|
|
|
|
|
|
#ifdef AN_DEBUG
|
|
|
|
int an_debug = 0;
|
|
|
|
|
|
|
|
#define DPRINTF(X) if (an_debug) printf X
|
|
|
|
#define DPRINTF2(X) if (an_debug > 1) printf X
|
|
|
|
#else
|
|
|
|
#define DPRINTF(X)
|
|
|
|
#define DPRINTF2(X)
|
2000-12-12 02:16:50 +03:00
|
|
|
#endif
|
|
|
|
|
2000-12-19 11:00:55 +03:00
|
|
|
int
|
|
|
|
an_attach(struct an_softc *sc)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ifnet *ifp = &ic->ic_if;
|
2000-12-19 11:00:55 +03:00
|
|
|
int i, s;
|
2004-01-28 18:07:52 +03:00
|
|
|
struct an_rid_wepkey *akey;
|
|
|
|
int buflen, kid, rid;
|
|
|
|
int chan, chan_min, chan_max;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2000-12-19 11:00:55 +03:00
|
|
|
s = splnet();
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_invalid = 0;
|
|
|
|
|
2000-12-19 11:00:55 +03:00
|
|
|
an_wait(sc);
|
2004-01-28 18:07:52 +03:00
|
|
|
if (an_reset(sc) != 0) {
|
|
|
|
sc->sc_invalid = 1;
|
|
|
|
splx(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
/* Load factory config */
|
2004-01-28 18:07:52 +03:00
|
|
|
if (an_cmd(sc, AN_CMD_READCFG, 0) != 0) {
|
2000-12-19 11:00:55 +03:00
|
|
|
splx(s);
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error("%s: failed to load config data\n",
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return 1;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the current configuration */
|
2004-01-28 18:07:52 +03:00
|
|
|
buflen = sizeof(sc->sc_config);
|
|
|
|
if (an_read_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, &buflen) != 0) {
|
2000-12-19 11:00:55 +03:00
|
|
|
splx(s);
|
2004-01-28 18:07:52 +03:00
|
|
|
aprint_error("%s: read config failed\n", sc->sc_dev.dv_xname);
|
|
|
|
return 1;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the card capabilities */
|
2004-01-28 18:07:52 +03:00
|
|
|
buflen = sizeof(sc->sc_caps);
|
|
|
|
if (an_read_rid(sc, AN_RID_CAPABILITIES, &sc->sc_caps, &buflen) != 0) {
|
2000-12-19 11:00:55 +03:00
|
|
|
splx(s);
|
2004-01-28 18:07:52 +03:00
|
|
|
aprint_error("%s: read caps failed\n", sc->sc_dev.dv_xname);
|
|
|
|
return 1;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
#ifdef AN_DEBUG
|
|
|
|
if (an_debug) {
|
|
|
|
static const int dumprid[] = {
|
|
|
|
AN_RID_GENCONFIG, AN_RID_CAPABILITIES, AN_RID_SSIDLIST,
|
|
|
|
AN_RID_APLIST, AN_RID_STATUS, AN_RID_ENCAP
|
|
|
|
};
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
for (rid = 0; rid < sizeof(dumprid)/sizeof(dumprid[0]); rid++) {
|
|
|
|
buflen = sizeof(sc->sc_buf);
|
|
|
|
if (an_read_rid(sc, dumprid[rid], &sc->sc_buf, &buflen)
|
|
|
|
!= 0)
|
|
|
|
continue;
|
|
|
|
printf("%04x (%d):\n", dumprid[rid], buflen);
|
|
|
|
for (i = 0; i < (buflen + 1) / 2; i++)
|
|
|
|
printf(" %04x", sc->sc_buf.sc_val[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
#endif
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
/* Read WEP settings from persistent memory */
|
2004-01-28 18:07:52 +03:00
|
|
|
akey = &sc->sc_buf.sc_wepkey;
|
|
|
|
buflen = sizeof(struct an_rid_wepkey);
|
|
|
|
rid = AN_RID_WEP_VOLATILE; /* first persistent key */
|
|
|
|
while (an_read_rid(sc, rid, akey, &buflen) == 0) {
|
|
|
|
kid = le16toh(akey->an_key_index);
|
|
|
|
DPRINTF(("an_attach: wep rid=0x%x len=%d(%d) index=0x%04x "
|
|
|
|
"mac[0]=%02x keylen=%d\n",
|
|
|
|
rid, buflen, sizeof(*akey), kid,
|
|
|
|
akey->an_mac_addr[0], le16toh(akey->an_key_len)));
|
|
|
|
if (kid == 0xffff) {
|
|
|
|
sc->sc_tx_perskey = akey->an_mac_addr[0];
|
|
|
|
sc->sc_tx_key = -1;
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
if (kid >= IEEE80211_WEP_NKID)
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_perskeylen[kid] = le16toh(akey->an_key_len);
|
|
|
|
sc->sc_wepkeys[kid].an_wep_keylen = -1;
|
|
|
|
rid = AN_RID_WEP_PERSISTENT; /* for next key */
|
|
|
|
buflen = sizeof(struct an_rid_wepkey);
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
aprint_normal("%s: %s %s (firmware %s)\n", sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_caps.an_manufname, sc->sc_caps.an_prodname,
|
|
|
|
sc->sc_caps.an_prodvers);
|
|
|
|
|
|
|
|
memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
ifp->if_softc = sc;
|
2001-06-21 16:49:06 +04:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_NOTRAILERS | IFF_SIMPLEX |
|
|
|
|
IFF_MULTICAST | IFF_ALLMULTI;
|
2000-12-12 02:16:50 +03:00
|
|
|
ifp->if_ioctl = an_ioctl;
|
|
|
|
ifp->if_start = an_start;
|
|
|
|
ifp->if_init = an_init;
|
|
|
|
ifp->if_stop = an_stop;
|
|
|
|
ifp->if_watchdog = an_watchdog;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
ic->ic_phytype = IEEE80211_T_DS;
|
|
|
|
ic->ic_opmode = IEEE80211_M_STA;
|
|
|
|
ic->ic_caps = IEEE80211_C_WEP | IEEE80211_C_PMGT | IEEE80211_C_IBSS |
|
|
|
|
IEEE80211_C_MONITOR;
|
|
|
|
ic->ic_state = IEEE80211_S_INIT;
|
|
|
|
IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
switch (le16toh(sc->sc_caps.an_regdomain)) {
|
|
|
|
default:
|
|
|
|
case AN_REGDOMAIN_USA:
|
|
|
|
case AN_REGDOMAIN_CANADA:
|
|
|
|
chan_min = 1; chan_max = 11; break;
|
|
|
|
case AN_REGDOMAIN_EUROPE:
|
|
|
|
case AN_REGDOMAIN_AUSTRALIA:
|
|
|
|
chan_min = 1; chan_max = 13; break;
|
|
|
|
case AN_REGDOMAIN_JAPAN:
|
|
|
|
chan_min = 14; chan_max = 14; break;
|
|
|
|
case AN_REGDOMAIN_SPAIN:
|
|
|
|
chan_min = 10; chan_max = 11; break;
|
|
|
|
case AN_REGDOMAIN_FRANCE:
|
|
|
|
chan_min = 10; chan_max = 13; break;
|
|
|
|
case AN_REGDOMAIN_JAPANWIDE:
|
|
|
|
chan_min = 1; chan_max = 14; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (chan = chan_min; chan <= chan_max; chan++) {
|
|
|
|
ic->ic_channels[chan].ic_freq =
|
|
|
|
ieee80211_ieee2mhz(chan, IEEE80211_CHAN_2GHZ);
|
|
|
|
ic->ic_channels[chan].ic_flags = IEEE80211_CHAN_B;
|
|
|
|
}
|
|
|
|
ic->ic_ibss_chan = &ic->ic_channels[chan_min];
|
|
|
|
|
|
|
|
aprint_normal("%s: 802.11 address: %s, channel: %d-%d\n",
|
|
|
|
ifp->if_xname, ether_sprintf(ic->ic_myaddr), chan_min, chan_max);
|
|
|
|
|
|
|
|
/* Find supported rate */
|
|
|
|
for (i = 0; i < sizeof(sc->sc_caps.an_rates); i++) {
|
|
|
|
if (sc->sc_caps.an_rates[i] == 0)
|
|
|
|
continue;
|
|
|
|
ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[
|
|
|
|
ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates++] =
|
|
|
|
sc->sc_caps.an_rates[i];
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call MI attach routine.
|
|
|
|
*/
|
|
|
|
if_attach(ifp);
|
2004-01-28 18:07:52 +03:00
|
|
|
ieee80211_ifattach(ifp);
|
|
|
|
|
|
|
|
sc->sc_newstate = ic->ic_newstate;
|
|
|
|
ic->ic_newstate = an_newstate;
|
|
|
|
|
|
|
|
ieee80211_media_init(ifp, an_media_change, an_media_status);
|
|
|
|
sc->sc_attached = 1;
|
2000-12-19 11:00:55 +03:00
|
|
|
splx(s);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
return 0;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-12-19 11:00:55 +03:00
|
|
|
an_detach(struct an_softc *sc)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-12-12 02:16:50 +03:00
|
|
|
int s;
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (!sc->sc_attached)
|
|
|
|
return 0;
|
|
|
|
|
2000-12-12 02:16:50 +03:00
|
|
|
s = splnet();
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_invalid = 1;
|
2000-12-12 02:16:50 +03:00
|
|
|
an_stop(ifp, 1);
|
2004-01-28 18:07:52 +03:00
|
|
|
ifmedia_delete_instance(&sc->sc_ic.ic_media, IFM_INST_ANY);
|
|
|
|
ieee80211_ifdetach(ifp);
|
2000-12-12 02:16:50 +03:00
|
|
|
if_detach(ifp);
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-12-19 11:00:55 +03:00
|
|
|
an_activate(struct device *self, enum devact act)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
|
|
|
struct an_softc *sc = (struct an_softc *)self;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_invalid = 1;
|
|
|
|
if_deactivate(&sc->sc_ic.ic_if);
|
2000-12-12 02:16:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-12-19 11:00:55 +03:00
|
|
|
void
|
|
|
|
an_power(int why, void *arg)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct an_softc *sc = arg;
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
2000-12-19 11:00:55 +03:00
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
switch (why) {
|
|
|
|
case PWR_SUSPEND:
|
|
|
|
case PWR_STANDBY:
|
2001-06-21 16:49:06 +04:00
|
|
|
an_stop(ifp, 1);
|
2000-12-19 11:00:55 +03:00
|
|
|
break;
|
|
|
|
case PWR_RESUME:
|
2004-01-28 18:07:52 +03:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2001-06-28 14:34:17 +04:00
|
|
|
an_init(ifp);
|
2004-01-28 18:07:52 +03:00
|
|
|
(void)an_intr(sc);
|
|
|
|
}
|
2000-12-19 11:00:55 +03:00
|
|
|
break;
|
|
|
|
case PWR_SOFTSUSPEND:
|
|
|
|
case PWR_SOFTSTANDBY:
|
|
|
|
case PWR_SOFTRESUME:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-28 18:07:52 +03:00
|
|
|
an_shutdown(struct an_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sc->sc_attached)
|
|
|
|
an_stop(&sc->sc_ic.ic_if, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
an_intr(void *arg)
|
2000-12-19 11:00:55 +03:00
|
|
|
{
|
2001-06-21 16:49:06 +04:00
|
|
|
struct an_softc *sc = arg;
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
|
|
|
int i;
|
|
|
|
u_int16_t status;
|
2000-12-19 11:00:55 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (!sc->sc_enabled || sc->sc_invalid ||
|
|
|
|
(sc->sc_dev.dv_flags & DVF_ACTIVE) == 0 ||
|
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0) {
|
|
|
|
CSR_WRITE_2(sc, AN_INT_EN, 0);
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, ~0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maximum 10 loops per interrupt */
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
if (!sc->sc_enabled || sc->sc_invalid)
|
|
|
|
return 1;
|
|
|
|
if (CSR_READ_2(sc, AN_SW0) != AN_MAGIC) {
|
|
|
|
DPRINTF(("an_intr: magic number changed: %x\n",
|
|
|
|
CSR_READ_2(sc, AN_SW0)));
|
|
|
|
sc->sc_invalid = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
status = CSR_READ_2(sc, AN_EVENT_STAT);
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, status & ~(AN_INTRS));
|
|
|
|
if ((status & AN_INTRS) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (status & AN_EV_RX)
|
|
|
|
an_rx_intr(sc);
|
|
|
|
|
|
|
|
if (status & (AN_EV_TX | AN_EV_TX_EXC))
|
|
|
|
an_tx_intr(sc, status);
|
|
|
|
|
|
|
|
if (status & AN_EV_LINKSTAT)
|
|
|
|
an_linkstat_intr(sc);
|
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_OACTIVE) == 0 &&
|
|
|
|
sc->sc_ic.ic_state == IEEE80211_S_RUN &&
|
|
|
|
!IFQ_IS_EMPTY(&ifp->if_snd))
|
|
|
|
an_start(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2000-12-19 11:00:55 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
2004-01-28 18:07:52 +03:00
|
|
|
an_init(struct ifnet *ifp)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
int i, error, fid;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
DPRINTF(("an_init: enabled %d\n", sc->sc_enabled));
|
|
|
|
if (!sc->sc_enabled) {
|
|
|
|
if (sc->sc_enable)
|
|
|
|
(*sc->sc_enable)(sc);
|
|
|
|
an_wait(sc);
|
|
|
|
sc->sc_enabled = 1;
|
|
|
|
} else {
|
|
|
|
an_stop(ifp, 0);
|
|
|
|
if ((error = an_reset(sc)) != 0) {
|
|
|
|
printf("%s: failed to reset\n", ifp->if_xname);
|
|
|
|
an_stop(ifp, 1);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CSR_WRITE_2(sc, AN_SW0, AN_MAGIC);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* Allocate the TX buffers */
|
|
|
|
for (i = 0; i < AN_TX_RING_CNT; i++) {
|
|
|
|
if ((error = an_alloc_fid(sc, AN_TX_MAX_LEN, &fid)) != 0) {
|
|
|
|
printf("%s: failed to allocate nic memory\n",
|
|
|
|
ifp->if_xname);
|
|
|
|
an_stop(ifp, 1);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
DPRINTF2(("an_init: txbuf %d allocated %x\n", i, fid));
|
|
|
|
sc->sc_txd[i].d_fid = fid;
|
|
|
|
sc->sc_txd[i].d_inuse = 0;
|
|
|
|
}
|
|
|
|
sc->sc_txcur = sc->sc_txnext = 0;
|
|
|
|
|
|
|
|
IEEE80211_ADDR_COPY(sc->sc_config.an_macaddr, ic->ic_myaddr);
|
|
|
|
sc->sc_config.an_scanmode = htole16(AN_SCANMODE_ACTIVE);
|
|
|
|
sc->sc_config.an_authtype = htole16(AN_AUTHTYPE_OPEN); /*XXX*/
|
2004-07-23 12:31:39 +04:00
|
|
|
if (ic->ic_flags & IEEE80211_F_PRIVACY) {
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_config.an_authtype |=
|
|
|
|
htole16(AN_AUTHTYPE_PRIVACY_IN_USE);
|
|
|
|
if (sc->sc_use_leap)
|
|
|
|
sc->sc_config.an_authtype |=
|
|
|
|
htole16(AN_AUTHTYPE_LEAP);
|
|
|
|
}
|
|
|
|
sc->sc_config.an_listen_interval = htole16(ic->ic_lintval);
|
|
|
|
sc->sc_config.an_beacon_period = htole16(ic->ic_lintval);
|
|
|
|
if (ic->ic_flags & IEEE80211_F_PMGTON)
|
|
|
|
sc->sc_config.an_psave_mode = htole16(AN_PSAVE_PSP);
|
|
|
|
else
|
|
|
|
sc->sc_config.an_psave_mode = htole16(AN_PSAVE_CAM);
|
|
|
|
sc->sc_config.an_ds_channel =
|
|
|
|
htole16(ieee80211_chan2ieee(ic, ic->ic_ibss_chan));
|
|
|
|
|
|
|
|
switch (ic->ic_opmode) {
|
|
|
|
case IEEE80211_M_STA:
|
|
|
|
sc->sc_config.an_opmode =
|
|
|
|
htole16(AN_OPMODE_INFRASTRUCTURE_STATION);
|
|
|
|
sc->sc_config.an_rxmode = htole16(AN_RXMODE_BC_MC_ADDR);
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
case IEEE80211_M_IBSS:
|
|
|
|
sc->sc_config.an_opmode = htole16(AN_OPMODE_IBSS_ADHOC);
|
|
|
|
sc->sc_config.an_rxmode = htole16(AN_RXMODE_BC_MC_ADDR);
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
case IEEE80211_M_MONITOR:
|
|
|
|
sc->sc_config.an_opmode =
|
|
|
|
htole16(AN_OPMODE_INFRASTRUCTURE_STATION);
|
|
|
|
sc->sc_config.an_rxmode =
|
|
|
|
htole16(AN_RXMODE_80211_MONITOR_ANYBSS);
|
|
|
|
sc->sc_config.an_authtype = htole16(AN_AUTHTYPE_NONE);
|
2004-07-23 12:31:39 +04:00
|
|
|
if (ic->ic_flags & IEEE80211_F_PRIVACY)
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_config.an_authtype |=
|
|
|
|
htole16(AN_AUTHTYPE_PRIVACY_IN_USE |
|
|
|
|
AN_AUTHTYPE_ALLOW_UNENCRYPTED);
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
default:
|
|
|
|
printf("%s: bad opmode %d\n", ifp->if_xname, ic->ic_opmode);
|
|
|
|
an_stop(ifp, 1);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
sc->sc_config.an_rxmode |= htole16(AN_RXMODE_NO_8023_HEADER);
|
|
|
|
|
|
|
|
/* Set the ssid list */
|
|
|
|
memset(&sc->sc_buf, 0, sizeof(sc->sc_buf.sc_ssidlist));
|
|
|
|
sc->sc_buf.sc_ssidlist.an_entry[0].an_ssid_len =
|
|
|
|
htole16(ic->ic_des_esslen);
|
|
|
|
if (ic->ic_des_esslen)
|
|
|
|
memcpy(sc->sc_buf.sc_ssidlist.an_entry[0].an_ssid,
|
|
|
|
ic->ic_des_essid, ic->ic_des_esslen);
|
|
|
|
if (an_write_rid(sc, AN_RID_SSIDLIST, &sc->sc_buf,
|
|
|
|
sizeof(sc->sc_buf.sc_ssidlist)) != 0) {
|
|
|
|
printf("%s: failed to write ssid list\n", ifp->if_xname);
|
|
|
|
an_stop(ifp, 1);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the AP list */
|
|
|
|
memset(&sc->sc_buf, 0, sizeof(sc->sc_buf.sc_aplist));
|
|
|
|
(void)an_write_rid(sc, AN_RID_APLIST, &sc->sc_buf,
|
|
|
|
sizeof(sc->sc_buf.sc_aplist));
|
|
|
|
|
|
|
|
/* Set the encapsulation */
|
|
|
|
for (i = 0; i < AN_ENCAP_NENTS; i++) {
|
|
|
|
sc->sc_buf.sc_encap.an_entry[i].an_ethertype = htole16(0);
|
|
|
|
sc->sc_buf.sc_encap.an_entry[i].an_action =
|
|
|
|
htole16(AN_RXENCAP_RFC1024 | AN_TXENCAP_RFC1024);
|
|
|
|
}
|
|
|
|
(void)an_write_rid(sc, AN_RID_ENCAP, &sc->sc_buf,
|
|
|
|
sizeof(sc->sc_buf.sc_encap));
|
|
|
|
|
|
|
|
/* Set the WEP Keys */
|
2004-07-23 12:31:39 +04:00
|
|
|
if (ic->ic_flags & IEEE80211_F_PRIVACY)
|
2004-01-28 18:07:52 +03:00
|
|
|
an_write_wepkey(sc, AN_RID_WEP_VOLATILE, sc->sc_wepkeys,
|
|
|
|
sc->sc_tx_key);
|
|
|
|
|
|
|
|
/* Set the configuration */
|
|
|
|
#ifdef AN_DEBUG
|
|
|
|
if (an_debug) {
|
|
|
|
printf("write config:\n");
|
|
|
|
for (i = 0; i < sizeof(sc->sc_config) / 2; i++)
|
|
|
|
printf(" %04x", ((u_int16_t *)&sc->sc_config)[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (an_write_rid(sc, AN_RID_GENCONFIG, &sc->sc_config,
|
|
|
|
sizeof(sc->sc_config)) != 0) {
|
|
|
|
printf("%s: failed to write config\n", ifp->if_xname);
|
|
|
|
an_stop(ifp, 1);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable the MAC */
|
|
|
|
if (an_cmd(sc, AN_CMD_ENABLE, 0)) {
|
|
|
|
printf("%s: failed to enable MAC\n", sc->sc_dev.dv_xname);
|
|
|
|
an_stop(ifp, 1);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
an_cmd(sc, AN_CMD_SET_MODE, 0xffff);
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
ic->ic_state = IEEE80211_S_INIT;
|
|
|
|
if (ic->ic_opmode == IEEE80211_M_MONITOR)
|
|
|
|
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
|
|
|
|
|
|
|
|
/* enable interrupts */
|
|
|
|
CSR_WRITE_2(sc, AN_INT_EN, AN_INTRS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
an_stop(struct ifnet *ifp, int disable)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
int i, s;
|
|
|
|
|
|
|
|
if (!sc->sc_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DPRINTF(("an_stop: disable %d\n", disable));
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
ieee80211_new_state(&sc->sc_ic, IEEE80211_S_INIT, -1);
|
|
|
|
if (!sc->sc_invalid) {
|
|
|
|
an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
|
|
|
|
CSR_WRITE_2(sc, AN_INT_EN, 0);
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < AN_TX_RING_CNT; i++)
|
|
|
|
an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->sc_txd[i].d_fid);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_tx_timer = 0;
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
|
|
|
|
|
|
|
|
if (disable) {
|
|
|
|
if (sc->sc_disable)
|
|
|
|
(*sc->sc_disable)(sc);
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
an_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = (struct an_softc *)ifp->if_softc;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ieee80211_node *ni;
|
|
|
|
struct ieee80211_frame *wh;
|
|
|
|
struct an_txframe frmhdr;
|
|
|
|
struct mbuf *m;
|
|
|
|
u_int16_t len;
|
|
|
|
int cur, fid;
|
|
|
|
|
|
|
|
if (!sc->sc_enabled || sc->sc_invalid) {
|
|
|
|
DPRINTF(("an_start: noop: enabled %d invalid %d\n",
|
|
|
|
sc->sc_enabled, sc->sc_invalid));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&frmhdr, 0, sizeof(frmhdr));
|
|
|
|
cur = sc->sc_txnext;
|
|
|
|
for (;;) {
|
|
|
|
if (ic->ic_state != IEEE80211_S_RUN) {
|
|
|
|
DPRINTF(("an_start: not running %d\n", ic->ic_state));
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m);
|
|
|
|
if (m == NULL) {
|
|
|
|
DPRINTF2(("an_start: no pending mbuf\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sc->sc_txd[cur].d_inuse) {
|
|
|
|
DPRINTF2(("an_start: %x/%d busy\n",
|
|
|
|
sc->sc_txd[cur].d_fid, cur));
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
ifp->if_opackets++;
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
if ((m = ieee80211_encap(ifp, m, &ni)) == NULL) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-10 04:57:20 +04:00
|
|
|
if (ni != NULL)
|
|
|
|
ieee80211_release_node(ic, ni);
|
2004-01-28 18:07:52 +03:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ic->ic_rawbpf)
|
|
|
|
bpf_mtap(ic->ic_rawbpf, m);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wh = mtod(m, struct ieee80211_frame *);
|
2004-07-23 12:31:39 +04:00
|
|
|
if (ic->ic_flags & IEEE80211_F_PRIVACY)
|
2004-01-28 18:07:52 +03:00
|
|
|
wh->i_fc[1] |= IEEE80211_FC1_WEP;
|
|
|
|
m_copydata(m, 0, sizeof(struct ieee80211_frame),
|
|
|
|
(caddr_t)&frmhdr.an_whdr);
|
|
|
|
|
|
|
|
/* insert payload length in front of llc/snap */
|
|
|
|
len = htons(m->m_pkthdr.len - sizeof(struct ieee80211_frame));
|
|
|
|
m_adj(m, sizeof(struct ieee80211_frame) - sizeof(len));
|
|
|
|
if (mtod(m, u_long) & 0x01)
|
|
|
|
memcpy(mtod(m, caddr_t), &len, sizeof(len));
|
|
|
|
else
|
|
|
|
*mtod(m, u_int16_t *) = len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Aironet firmware apparently convert the packet
|
|
|
|
* with longer than 1500 bytes in length into LLC/SNAP.
|
|
|
|
* If we have 1500 bytes in ethernet payload, it is
|
|
|
|
* 1508 bytes including LLC/SNAP and will be inserted
|
|
|
|
* additional LLC/SNAP header with 1501-1508 in its
|
|
|
|
* ethertype !!
|
|
|
|
* So we skip LLC/SNAP header and force firmware to
|
|
|
|
* convert it to LLC/SNAP again.
|
|
|
|
*/
|
|
|
|
m_adj(m, sizeof(struct llc));
|
|
|
|
|
|
|
|
frmhdr.an_tx_ctl = htole16(AN_TXCTL_80211);
|
|
|
|
frmhdr.an_tx_payload_len = htole16(m->m_pkthdr.len);
|
|
|
|
frmhdr.an_gaplen = htole16(AN_TXGAP_802_11);
|
|
|
|
|
|
|
|
if (ic->ic_fixed_rate != -1)
|
|
|
|
frmhdr.an_tx_rate =
|
|
|
|
ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[
|
|
|
|
ic->ic_fixed_rate] & IEEE80211_RATE_VAL;
|
|
|
|
else
|
|
|
|
frmhdr.an_tx_rate = 0;
|
|
|
|
|
|
|
|
#ifdef AN_DEBUG
|
|
|
|
if ((ifp->if_flags & (IFF_DEBUG|IFF_LINK2)) ==
|
|
|
|
(IFF_DEBUG|IFF_LINK2)) {
|
|
|
|
ieee80211_dump_pkt((u_int8_t *)&frmhdr.an_whdr,
|
|
|
|
sizeof(struct ieee80211_frame), -1, 0);
|
|
|
|
printf(" txctl 0x%x plen %u\n",
|
|
|
|
le16toh(frmhdr.an_tx_ctl),
|
|
|
|
le16toh(frmhdr.an_tx_payload_len));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (sizeof(frmhdr) + AN_TXGAP_802_11 + sizeof(len) +
|
|
|
|
m->m_pkthdr.len > AN_TX_MAX_LEN) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
m_freem(m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fid = sc->sc_txd[cur].d_fid;
|
|
|
|
if (an_write_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) != 0) {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
m_freem(m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* dummy write to avoid seek. */
|
|
|
|
an_write_bap(sc, fid, -1, &frmhdr, AN_TXGAP_802_11);
|
|
|
|
an_mwrite_bap(sc, fid, -1, m, m->m_pkthdr.len);
|
|
|
|
m_freem(m);
|
|
|
|
|
|
|
|
DPRINTF2(("an_start: send %d byte via %x/%d\n",
|
|
|
|
ntohs(len) + sizeof(struct ieee80211_frame),
|
|
|
|
fid, cur));
|
|
|
|
sc->sc_txd[cur].d_inuse = 1;
|
|
|
|
if (an_cmd(sc, AN_CMD_TX, fid)) {
|
|
|
|
printf("%s: xmit failed\n", ifp->if_xname);
|
|
|
|
sc->sc_txd[cur].d_inuse = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sc->sc_tx_timer = 5;
|
|
|
|
ifp->if_timer = 1;
|
|
|
|
AN_INC(cur, AN_TX_RING_CNT);
|
|
|
|
sc->sc_txnext = cur;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
an_reset(struct an_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
DPRINTF(("an_reset\n"));
|
|
|
|
|
|
|
|
if (!sc->sc_enabled)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
an_cmd(sc, AN_CMD_ENABLE, 0);
|
|
|
|
an_cmd(sc, AN_CMD_FW_RESTART, 0);
|
|
|
|
an_cmd(sc, AN_CMD_NOOP2, 0);
|
|
|
|
|
|
|
|
if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT) {
|
|
|
|
printf("%s: reset failed\n", sc->sc_dev.dv_xname);
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
an_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (!sc->sc_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sc->sc_tx_timer) {
|
|
|
|
if (--sc->sc_tx_timer == 0) {
|
|
|
|
printf("%s: device timeout\n", ifp->if_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
an_init(ifp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifp->if_timer = 1;
|
|
|
|
}
|
|
|
|
ieee80211_watchdog(ifp);
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
|
|
|
an_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0)
|
|
|
|
return ENXIO;
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
s = splnet();
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFFLAGS:
|
2001-06-29 15:24:42 +04:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
if (sc->sc_enabled) {
|
|
|
|
/*
|
|
|
|
* To avoid rescanning another access point,
|
|
|
|
* do not call an_init() here. Instead, only
|
|
|
|
* reflect promisc mode settings.
|
|
|
|
*/
|
|
|
|
error = an_cmd(sc, AN_CMD_SET_MODE,
|
|
|
|
(ifp->if_flags & IFF_PROMISC) ? 0xffff : 0);
|
|
|
|
} else
|
|
|
|
error = an_init(ifp);
|
|
|
|
} else if (sc->sc_enabled)
|
2001-06-21 16:49:06 +04:00
|
|
|
an_stop(ifp, 1);
|
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
/* we don't have multicast filter. */
|
|
|
|
error = 0;
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
case SIOCS80211NWKEY:
|
|
|
|
error = an_set_nwkey(sc, (struct ieee80211_nwkey *)data);
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
|
|
|
case SIOCG80211NWKEY:
|
|
|
|
error = an_get_nwkey(sc, (struct ieee80211_nwkey *)data);
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-28 18:07:52 +03:00
|
|
|
error = ieee80211_ioctl(ifp, command, data);
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
if (error == ENETRESET) {
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
error = an_init(ifp);
|
|
|
|
else
|
|
|
|
error = 0;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
splx(s);
|
|
|
|
return error;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* TBD factor with ieee80211_media_change */
|
|
|
|
static int
|
|
|
|
an_media_change(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ifmedia_entry *ime;
|
|
|
|
enum ieee80211_opmode newmode;
|
|
|
|
int i, rate, error = 0;
|
|
|
|
|
|
|
|
ime = ic->ic_media.ifm_cur;
|
|
|
|
if (IFM_SUBTYPE(ime->ifm_media) == IFM_AUTO) {
|
|
|
|
i = -1;
|
|
|
|
} else {
|
|
|
|
struct ieee80211_rateset *rs =
|
|
|
|
&ic->ic_sup_rates[IEEE80211_MODE_11B];
|
|
|
|
rate = ieee80211_media2rate(ime->ifm_media);
|
|
|
|
if (rate == 0)
|
|
|
|
return EINVAL;
|
|
|
|
for (i = 0; i < rs->rs_nrates; i++) {
|
|
|
|
if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == rate)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == rs->rs_nrates)
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (ic->ic_fixed_rate != i) {
|
|
|
|
ic->ic_fixed_rate = i;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ime->ifm_media & IFM_IEEE80211_ADHOC)
|
|
|
|
newmode = IEEE80211_M_IBSS;
|
|
|
|
else if (ime->ifm_media & IFM_IEEE80211_HOSTAP)
|
|
|
|
newmode = IEEE80211_M_HOSTAP;
|
|
|
|
else if (ime->ifm_media & IFM_IEEE80211_MONITOR)
|
|
|
|
newmode = IEEE80211_M_MONITOR;
|
|
|
|
else
|
|
|
|
newmode = IEEE80211_M_STA;
|
|
|
|
if (ic->ic_opmode != newmode) {
|
|
|
|
ic->ic_opmode = newmode;
|
|
|
|
error = ENETRESET;
|
|
|
|
}
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
error = an_init(ifp);
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
ifp->if_baudrate = ifmedia_baudrate(ic->ic_media.ifm_cur->ifm_media);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
an_media_status(struct ifnet *ifp, struct ifmediareq *imr)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ifp->if_softc;
|
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
int rate, buflen;
|
|
|
|
|
|
|
|
if (sc->sc_enabled == 0) {
|
|
|
|
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)
|
|
|
|
imr->ifm_status |= IFM_ACTIVE;
|
|
|
|
buflen = sizeof(sc->sc_buf);
|
|
|
|
if (ic->ic_fixed_rate != -1)
|
|
|
|
rate = ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[
|
|
|
|
ic->ic_fixed_rate] & IEEE80211_RATE_VAL;
|
|
|
|
else if (an_read_rid(sc, AN_RID_STATUS, &sc->sc_buf, &buflen) != 0)
|
|
|
|
rate = 0;
|
|
|
|
else
|
|
|
|
rate = le16toh(sc->sc_buf.sc_status.an_current_tx_rate);
|
|
|
|
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_HOSTAP:
|
|
|
|
imr->ifm_active |= IFM_IEEE80211_HOSTAP;
|
|
|
|
break;
|
|
|
|
case IEEE80211_M_MONITOR:
|
|
|
|
imr->ifm_active |= IFM_IEEE80211_MONITOR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
|
|
|
an_set_nwkey(struct an_softc *sc, struct ieee80211_nwkey *nwkey)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2001-06-29 15:24:42 +04:00
|
|
|
int error;
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
2001-06-21 16:49:06 +04:00
|
|
|
u_int16_t prevauth;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
error = 0;
|
2004-01-28 18:07:52 +03:00
|
|
|
prevauth = sc->sc_config.an_authtype;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
switch (nwkey->i_wepon) {
|
|
|
|
case IEEE80211_NWKEY_OPEN:
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_config.an_authtype = AN_AUTHTYPE_OPEN;
|
2004-07-23 12:31:39 +04:00
|
|
|
ic->ic_flags &= ~IEEE80211_F_PRIVACY;
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
case IEEE80211_NWKEY_WEP:
|
|
|
|
case IEEE80211_NWKEY_WEP | IEEE80211_NWKEY_PERSIST:
|
2001-06-29 15:24:42 +04:00
|
|
|
error = an_set_nwkey_wep(sc, nwkey);
|
2004-01-28 18:07:52 +03:00
|
|
|
if (error == 0 || error == ENETRESET) {
|
|
|
|
sc->sc_config.an_authtype =
|
2001-06-21 16:49:06 +04:00
|
|
|
AN_AUTHTYPE_OPEN | AN_AUTHTYPE_PRIVACY_IN_USE;
|
2004-07-23 12:31:39 +04:00
|
|
|
ic->ic_flags |= IEEE80211_F_PRIVACY;
|
2004-01-28 18:07:52 +03:00
|
|
|
}
|
2001-06-29 15:24:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IEEE80211_NWKEY_EAP:
|
|
|
|
error = an_set_nwkey_eap(sc, nwkey);
|
2004-01-28 18:07:52 +03:00
|
|
|
if (error == 0 || error == ENETRESET) {
|
|
|
|
sc->sc_config.an_authtype = AN_AUTHTYPE_OPEN |
|
2001-06-29 15:24:42 +04:00
|
|
|
AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_LEAP;
|
2004-07-23 12:31:39 +04:00
|
|
|
ic->ic_flags |= IEEE80211_F_PRIVACY;
|
2004-01-28 18:07:52 +03:00
|
|
|
}
|
2001-06-29 15:24:42 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
if (error == 0 && prevauth != sc->sc_config.an_authtype)
|
2001-06-29 15:24:42 +04:00
|
|
|
error = ENETRESET;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
an_set_nwkey_wep(struct an_softc *sc, struct ieee80211_nwkey *nwkey)
|
|
|
|
{
|
|
|
|
int i, txkey, anysetkey, needreset, error;
|
2001-07-18 06:06:44 +04:00
|
|
|
struct an_wepkey keys[IEEE80211_WEP_NKID];
|
2001-06-29 15:24:42 +04:00
|
|
|
|
|
|
|
error = 0;
|
|
|
|
memset(keys, 0, sizeof(keys));
|
|
|
|
anysetkey = needreset = 0;
|
|
|
|
|
|
|
|
/* load argument and sanity check */
|
2001-07-18 06:06:44 +04:00
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
|
|
|
|
keys[i].an_wep_keylen = nwkey->i_key[i].i_keylen;
|
|
|
|
if (keys[i].an_wep_keylen < 0)
|
2001-06-29 15:24:42 +04:00
|
|
|
continue;
|
2001-07-18 06:06:44 +04:00
|
|
|
if (keys[i].an_wep_keylen != 0 &&
|
|
|
|
keys[i].an_wep_keylen < IEEE80211_WEP_KEYLEN)
|
2001-06-29 15:24:42 +04:00
|
|
|
return EINVAL;
|
2001-07-18 06:06:44 +04:00
|
|
|
if (keys[i].an_wep_keylen > sizeof(keys[i].an_wep_key))
|
2001-06-29 15:24:42 +04:00
|
|
|
return EINVAL;
|
|
|
|
if ((error = copyin(nwkey->i_key[i].i_keydat,
|
2001-07-18 06:06:44 +04:00
|
|
|
keys[i].an_wep_key, keys[i].an_wep_keylen)) != 0)
|
2001-06-29 15:24:42 +04:00
|
|
|
return error;
|
|
|
|
anysetkey++;
|
|
|
|
}
|
|
|
|
txkey = nwkey->i_defkid - 1;
|
|
|
|
if (txkey >= 0) {
|
|
|
|
if (txkey >= IEEE80211_WEP_NKID)
|
|
|
|
return EINVAL;
|
|
|
|
/* default key must have a valid value */
|
|
|
|
if (keys[txkey].an_wep_keylen == 0 ||
|
|
|
|
(keys[txkey].an_wep_keylen < 0 &&
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_perskeylen[txkey] == 0))
|
2001-06-29 15:24:42 +04:00
|
|
|
return EINVAL;
|
|
|
|
anysetkey++;
|
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
DPRINTF(("an_set_nwkey_wep: %s: %sold(%d:%d,%d,%d,%d) "
|
|
|
|
"pers(%d:%d,%d,%d,%d) new(%d:%d,%d,%d,%d)\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
((nwkey->i_wepon & IEEE80211_NWKEY_PERSIST) ? "persist: " : ""),
|
|
|
|
sc->sc_tx_key,
|
|
|
|
sc->sc_wepkeys[0].an_wep_keylen, sc->sc_wepkeys[1].an_wep_keylen,
|
|
|
|
sc->sc_wepkeys[2].an_wep_keylen, sc->sc_wepkeys[3].an_wep_keylen,
|
|
|
|
sc->sc_tx_perskey,
|
|
|
|
sc->sc_perskeylen[0], sc->sc_perskeylen[1],
|
|
|
|
sc->sc_perskeylen[2], sc->sc_perskeylen[3],
|
|
|
|
txkey,
|
|
|
|
keys[0].an_wep_keylen, keys[1].an_wep_keylen,
|
|
|
|
keys[2].an_wep_keylen, keys[3].an_wep_keylen));
|
2001-06-29 15:24:42 +04:00
|
|
|
if (!(nwkey->i_wepon & IEEE80211_NWKEY_PERSIST)) {
|
|
|
|
/* set temporary keys */
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_tx_key = txkey;
|
2001-07-18 06:06:44 +04:00
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
|
2001-06-29 15:24:42 +04:00
|
|
|
if (keys[i].an_wep_keylen < 0)
|
|
|
|
continue;
|
2004-01-28 18:07:52 +03:00
|
|
|
memcpy(&sc->sc_wepkeys[i], &keys[i], sizeof(keys[i]));
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2001-06-29 15:24:42 +04:00
|
|
|
} else {
|
|
|
|
/* set persist keys */
|
2001-06-21 16:49:06 +04:00
|
|
|
if (anysetkey) {
|
2001-06-29 15:24:42 +04:00
|
|
|
/* prepare to write nvram */
|
2001-06-21 16:49:06 +04:00
|
|
|
if (!sc->sc_enabled) {
|
2001-06-29 15:24:42 +04:00
|
|
|
if (sc->sc_enable)
|
2001-06-21 16:49:06 +04:00
|
|
|
(*sc->sc_enable)(sc);
|
2001-06-29 15:24:42 +04:00
|
|
|
an_wait(sc);
|
2001-06-21 16:49:06 +04:00
|
|
|
sc->sc_enabled = 1;
|
|
|
|
error = an_write_wepkey(sc,
|
2001-06-29 15:24:42 +04:00
|
|
|
AN_RID_WEP_PERSISTENT, keys, txkey);
|
2001-06-21 16:49:06 +04:00
|
|
|
if (sc->sc_disable)
|
|
|
|
(*sc->sc_disable)(sc);
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
} else {
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
|
|
|
error = an_write_wepkey(sc,
|
2001-06-29 15:24:42 +04:00
|
|
|
AN_RID_WEP_PERSISTENT, keys, txkey);
|
2001-06-21 16:49:06 +04:00
|
|
|
an_cmd(sc, AN_CMD_ENABLE, 0);
|
|
|
|
}
|
|
|
|
if (error)
|
2001-06-29 15:24:42 +04:00
|
|
|
return error;
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2001-06-29 15:24:42 +04:00
|
|
|
if (txkey >= 0)
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_tx_perskey = txkey;
|
|
|
|
if (sc->sc_tx_key >= 0) {
|
|
|
|
sc->sc_tx_key = -1;
|
2001-06-21 16:49:06 +04:00
|
|
|
needreset++;
|
2001-06-29 15:24:42 +04:00
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
|
2004-01-28 18:07:52 +03:00
|
|
|
if (sc->sc_wepkeys[i].an_wep_keylen >= 0) {
|
|
|
|
memset(&sc->sc_wepkeys[i].an_wep_key, 0,
|
|
|
|
sizeof(sc->sc_wepkeys[i].an_wep_key));
|
|
|
|
sc->sc_wepkeys[i].an_wep_keylen = -1;
|
2001-06-29 15:24:42 +04:00
|
|
|
needreset++;
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
|
|
|
if (keys[i].an_wep_keylen >= 0)
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_perskeylen[i] = keys[i].an_wep_keylen;
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2001-06-29 15:24:42 +04:00
|
|
|
}
|
|
|
|
if (needreset) {
|
|
|
|
/* firmware restart to reload persistent key */
|
|
|
|
an_reset(sc);
|
|
|
|
}
|
|
|
|
if (anysetkey || needreset)
|
2001-06-21 16:49:06 +04:00
|
|
|
error = ENETRESET;
|
2001-06-29 15:24:42 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
an_set_nwkey_eap(struct an_softc *sc, struct ieee80211_nwkey *nwkey)
|
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int i, error, len;
|
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
|
|
|
struct an_rid_leapkey *key;
|
2001-06-29 15:24:42 +04:00
|
|
|
u_int16_t unibuf[sizeof(key->an_key)];
|
2004-01-28 18:07:52 +03:00
|
|
|
static const int leap_rid[] = { AN_RID_LEAP_PASS, AN_RID_LEAP_USER };
|
2001-06-29 15:24:42 +04:00
|
|
|
MD4_CTX ctx;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (nwkey->i_key[0].i_keydat == NULL &&
|
|
|
|
nwkey->i_key[1].i_keydat == NULL)
|
|
|
|
return 0;
|
|
|
|
if (!sc->sc_enabled)
|
|
|
|
return ENXIO;
|
|
|
|
an_cmd(sc, AN_CMD_DISABLE, 0);
|
2004-01-28 18:07:52 +03:00
|
|
|
key = &sc->sc_buf.sc_leapkey;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (nwkey->i_key[i].i_keydat == NULL)
|
|
|
|
continue;
|
|
|
|
len = nwkey->i_key[i].i_keylen;
|
|
|
|
if (len > sizeof(key->an_key))
|
2001-06-29 15:24:42 +04:00
|
|
|
return EINVAL;
|
|
|
|
memset(key, 0, sizeof(*key));
|
2004-01-28 18:07:52 +03:00
|
|
|
key->an_key_len = htole16(len);
|
|
|
|
if ((error = copyin(nwkey->i_key[i].i_keydat, key->an_key,
|
|
|
|
len)) != 0)
|
2001-06-29 15:24:42 +04:00
|
|
|
return error;
|
2004-01-28 18:07:52 +03:00
|
|
|
if (i == 1) {
|
|
|
|
/*
|
|
|
|
* Cisco seems to use PasswordHash and PasswordHashHash
|
|
|
|
* in RFC-2759 (MS-CHAP-V2).
|
|
|
|
*/
|
|
|
|
memset(unibuf, 0, sizeof(unibuf));
|
|
|
|
/* XXX: convert password to unicode */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
unibuf[i] = key->an_key[i];
|
|
|
|
/* set PasswordHash */
|
|
|
|
MD4Init(&ctx);
|
|
|
|
MD4Update(&ctx, (u_int8_t *)unibuf, len * 2);
|
|
|
|
MD4Final(key->an_key, &ctx);
|
|
|
|
/* set PasswordHashHash */
|
|
|
|
MD4Init(&ctx);
|
|
|
|
MD4Update(&ctx, key->an_key, 16);
|
|
|
|
MD4Final(key->an_key + 16, &ctx);
|
|
|
|
key->an_key_len = htole16(32);
|
|
|
|
}
|
|
|
|
if ((error = an_write_rid(sc, leap_rid[i], key,
|
|
|
|
sizeof(*key))) != 0) {
|
|
|
|
printf("%s: LEAP set failed\n", ifp->if_xname);
|
|
|
|
return error;
|
|
|
|
}
|
2001-06-29 15:24:42 +04:00
|
|
|
}
|
|
|
|
error = an_cmd(sc, AN_CMD_ENABLE, 0);
|
|
|
|
if (error)
|
|
|
|
printf("%s: an_set_nwkey: failed to enable MAC\n",
|
2004-01-28 18:07:52 +03:00
|
|
|
ifp->if_xname);
|
2001-06-29 15:24:42 +04:00
|
|
|
else
|
2001-06-21 16:49:06 +04:00
|
|
|
error = ENETRESET;
|
|
|
|
return error;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
|
|
|
an_get_nwkey(struct an_softc *sc, struct ieee80211_nwkey *nwkey)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2001-06-21 16:49:06 +04:00
|
|
|
int i, error;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
error = 0;
|
2004-01-28 18:07:52 +03:00
|
|
|
if (sc->sc_config.an_authtype & AN_AUTHTYPE_LEAP)
|
2001-06-21 16:49:06 +04:00
|
|
|
nwkey->i_wepon = IEEE80211_NWKEY_EAP;
|
2004-01-28 18:07:52 +03:00
|
|
|
else if (sc->sc_config.an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE)
|
2001-06-21 16:49:06 +04:00
|
|
|
nwkey->i_wepon = IEEE80211_NWKEY_WEP;
|
2000-12-12 02:16:50 +03:00
|
|
|
else
|
2001-06-21 16:49:06 +04:00
|
|
|
nwkey->i_wepon = IEEE80211_NWKEY_OPEN;
|
2004-01-28 18:07:52 +03:00
|
|
|
if (sc->sc_tx_key == -1)
|
|
|
|
nwkey->i_defkid = sc->sc_tx_perskey + 1;
|
2001-06-21 16:49:06 +04:00
|
|
|
else
|
2004-01-28 18:07:52 +03:00
|
|
|
nwkey->i_defkid = sc->sc_tx_key + 1;
|
2001-06-21 16:49:06 +04:00
|
|
|
if (nwkey->i_key[0].i_keydat == NULL)
|
|
|
|
return 0;
|
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
|
|
|
|
if (nwkey->i_key[i].i_keydat == NULL)
|
|
|
|
continue;
|
|
|
|
/* do not show any keys to non-root user */
|
|
|
|
if ((error = suser(curproc->p_ucred, &curproc->p_acflag)) != 0)
|
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
nwkey->i_key[i].i_keylen = sc->sc_wepkeys[i].an_wep_keylen;
|
2001-06-21 16:49:06 +04:00
|
|
|
if (nwkey->i_key[i].i_keylen < 0) {
|
2004-01-28 18:07:52 +03:00
|
|
|
if (sc->sc_perskeylen[i] == 0)
|
2001-06-21 16:49:06 +04:00
|
|
|
nwkey->i_key[i].i_keylen = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
if ((error = copyout(sc->sc_wepkeys[i].an_wep_key,
|
2001-06-21 16:49:06 +04:00
|
|
|
nwkey->i_key[i].i_keydat,
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_wepkeys[i].an_wep_keylen)) != 0)
|
2001-06-21 16:49:06 +04:00
|
|
|
break;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
return error;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
|
|
|
an_write_wepkey(struct an_softc *sc, int type, struct an_wepkey *keys, int kid)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2001-06-21 16:49:06 +04:00
|
|
|
int i, error;
|
2004-01-28 18:07:52 +03:00
|
|
|
struct an_rid_wepkey *akey;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
error = 0;
|
2004-01-28 18:07:52 +03:00
|
|
|
akey = &sc->sc_buf.sc_wepkey;
|
|
|
|
memset(akey, 0, sizeof(struct an_rid_wepkey));
|
2001-06-21 16:49:06 +04:00
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
|
|
|
|
if (keys[i].an_wep_keylen < 0 ||
|
|
|
|
keys[i].an_wep_keylen > sizeof(akey->an_key))
|
|
|
|
continue;
|
2004-01-28 18:07:52 +03:00
|
|
|
akey->an_key_len = htole16(keys[i].an_wep_keylen);
|
|
|
|
akey->an_key_index = htole16(i);
|
2001-06-21 16:49:06 +04:00
|
|
|
akey->an_mac_addr[0] = 1; /* default mac */
|
2004-01-28 18:07:52 +03:00
|
|
|
memcpy(akey->an_key, keys[i].an_wep_key, keys[i].an_wep_keylen);
|
|
|
|
if ((error = an_write_rid(sc, type, akey, sizeof(*akey))) != 0)
|
2001-06-21 16:49:06 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (kid >= 0) {
|
2004-01-28 18:07:52 +03:00
|
|
|
akey->an_key_index = htole16(0xffff);
|
2001-06-21 16:49:06 +04:00
|
|
|
akey->an_mac_addr[0] = kid;
|
2004-01-28 18:07:52 +03:00
|
|
|
akey->an_key_len = htole16(0);
|
2001-06-21 16:49:06 +04:00
|
|
|
memset(akey->an_key, 0, sizeof(akey->an_key));
|
2004-01-28 18:07:52 +03:00
|
|
|
error = an_write_rid(sc, type, akey, sizeof(*akey));
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
return error;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
/*
|
|
|
|
* Low level functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2004-01-28 18:07:52 +03:00
|
|
|
an_rx_intr(struct an_softc *sc)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
|
|
|
struct ifnet *ifp = &ic->ic_if;
|
|
|
|
struct ieee80211_frame *wh;
|
|
|
|
struct ieee80211_node *ni;
|
|
|
|
struct an_rxframe frmhdr;
|
2001-06-21 16:49:06 +04:00
|
|
|
struct mbuf *m;
|
2004-01-28 18:07:52 +03:00
|
|
|
u_int16_t status;
|
|
|
|
int fid, off, len;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
fid = CSR_READ_2(sc, AN_RX_FID);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* First read in the frame header */
|
|
|
|
if (an_read_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) != 0) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_RX);
|
2001-06-21 16:49:06 +04:00
|
|
|
ifp->if_ierrors++;
|
2004-01-28 18:07:52 +03:00
|
|
|
DPRINTF(("an_rx_intr: read fid %x failed\n", fid));
|
2001-06-21 16:49:06 +04:00
|
|
|
return;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
#ifdef AN_DEBUG
|
|
|
|
if ((ifp->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2)) {
|
|
|
|
ieee80211_dump_pkt((u_int8_t *)&frmhdr.an_whdr,
|
|
|
|
sizeof(struct ieee80211_frame), frmhdr.an_rx_rate,
|
|
|
|
frmhdr.an_rx_signal_strength);
|
|
|
|
printf(" time 0x%x status 0x%x plen %u chan %u"
|
|
|
|
" plcp %02x %02x %02x %02x gap %u\n",
|
|
|
|
le32toh(frmhdr.an_rx_time), le16toh(frmhdr.an_rx_status),
|
|
|
|
le16toh(frmhdr.an_rx_payload_len), frmhdr.an_rx_chan,
|
|
|
|
frmhdr.an_plcp_hdr[0], frmhdr.an_plcp_hdr[1],
|
|
|
|
frmhdr.an_plcp_hdr[2], frmhdr.an_plcp_hdr[3],
|
|
|
|
le16toh(frmhdr.an_gaplen));
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
|
|
|
#endif
|
2004-01-28 18:07:52 +03:00
|
|
|
|
|
|
|
status = le16toh(frmhdr.an_rx_status);
|
|
|
|
if ((status & AN_STAT_ERRSTAT) != 0 &&
|
|
|
|
ic->ic_opmode != IEEE80211_M_MONITOR) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_RX);
|
2001-06-21 16:49:06 +04:00
|
|
|
ifp->if_ierrors++;
|
2004-01-28 18:07:52 +03:00
|
|
|
DPRINTF(("an_rx_intr: fid %x status %x\n", fid, status));
|
2001-06-21 16:49:06 +04:00
|
|
|
return;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
len = le16toh(frmhdr.an_rx_payload_len);
|
|
|
|
off = ALIGN(sizeof(struct ieee80211_frame));
|
|
|
|
|
|
|
|
if (off + len > MCLBYTES) {
|
|
|
|
if (ic->ic_opmode != IEEE80211_M_MONITOR) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_RX);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
DPRINTF(("an_rx_intr: oversized packet %d\n", len));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = 0;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_RX);
|
2001-06-21 16:49:06 +04:00
|
|
|
ifp->if_ierrors++;
|
2004-01-28 18:07:52 +03:00
|
|
|
DPRINTF(("an_rx_intr: MGET failed\n"));
|
2001-06-21 16:49:06 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
if (off + len > MHLEN) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_RX);
|
|
|
|
m_freem(m);
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
DPRINTF(("an_rx_intr: MCLGET failed\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m->m_data += off - sizeof(struct ieee80211_frame);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (ic->ic_opmode != IEEE80211_M_MONITOR) {
|
|
|
|
/*
|
|
|
|
* The gap and the payload length should be skipped.
|
|
|
|
* Make dummy read to avoid seek.
|
|
|
|
*/
|
|
|
|
an_read_bap(sc, fid, -1, m->m_data,
|
|
|
|
le16toh(frmhdr.an_gaplen) + sizeof(u_int16_t));
|
|
|
|
#ifdef AN_DEBUG
|
|
|
|
if ((ifp->if_flags & (IFF_DEBUG|IFF_LINK2)) ==
|
|
|
|
(IFF_DEBUG|IFF_LINK2)) {
|
|
|
|
int i;
|
|
|
|
printf(" gap&len");
|
|
|
|
for (i = 0;
|
|
|
|
i < le16toh(frmhdr.an_gaplen) + sizeof(u_int16_t);
|
|
|
|
i++)
|
|
|
|
printf(" %02x", mtod(m, u_int8_t *)[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
memcpy(m->m_data, &frmhdr.an_whdr, sizeof(struct ieee80211_frame));
|
|
|
|
an_read_bap(sc, fid, -1, 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, AN_EVENT_ACK, AN_EV_RX);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
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;
|
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
ni = ieee80211_find_rxnode(ic, wh);
|
|
|
|
ieee80211_input(ifp, m, ni, frmhdr.an_rx_signal_strength,
|
|
|
|
le32toh(frmhdr.an_rx_time));
|
2004-08-10 04:57:20 +04:00
|
|
|
ieee80211_release_node(ic, ni);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static void
|
2004-01-28 18:07:52 +03:00
|
|
|
an_tx_intr(struct an_softc *sc, int status)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ic.ic_if;
|
|
|
|
int cur, fid;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_tx_timer = 0;
|
2001-06-21 16:49:06 +04:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
fid = CSR_READ_2(sc, AN_TX_CMP_FID);
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, status & (AN_EV_TX | AN_EV_TX_EXC));
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
if (status & AN_EV_TX_EXC)
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
else
|
|
|
|
ifp->if_opackets++;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
cur = sc->sc_txcur;
|
|
|
|
if (sc->sc_txd[cur].d_fid == fid) {
|
|
|
|
sc->sc_txd[cur].d_inuse = 0;
|
|
|
|
DPRINTF2(("an_tx_intr: sent %x/%d\n", fid, cur));
|
|
|
|
AN_INC(cur, AN_TX_RING_CNT);
|
|
|
|
sc->sc_txcur = cur;
|
|
|
|
} else {
|
|
|
|
for (cur = 0; cur < AN_TX_RING_CNT; cur++) {
|
|
|
|
if (fid == sc->sc_txd[cur].d_fid) {
|
|
|
|
sc->sc_txd[cur].d_inuse = 0;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
2004-01-28 18:07:52 +03:00
|
|
|
printf("%s: tx mismatch: "
|
2001-06-21 16:49:06 +04:00
|
|
|
"expected %x(%d), actual %x(%d)\n",
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_txd[sc->sc_txcur].d_fid, sc->sc_txcur,
|
|
|
|
fid, cur);
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
return;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
static void
|
|
|
|
an_linkstat_intr(struct an_softc *sc)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
struct ieee80211com *ic = &sc->sc_ic;
|
2001-06-21 16:49:06 +04:00
|
|
|
u_int16_t status;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
status = CSR_READ_2(sc, AN_LINKSTAT);
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_LINKSTAT);
|
|
|
|
DPRINTF(("an_linkstat_intr: status 0x%x\n", status));
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (status == AN_LINKSTAT_ASSOCIATED) {
|
|
|
|
if (ic->ic_state != IEEE80211_S_RUN ||
|
|
|
|
ic->ic_opmode == IEEE80211_M_IBSS)
|
|
|
|
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
|
|
|
|
} else {
|
|
|
|
if (ic->ic_opmode == IEEE80211_M_STA)
|
|
|
|
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* Must be called at proper protection level! */
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
|
|
|
an_cmd(struct an_softc *sc, int cmd, int val)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int i, status;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
/* make sure that previous command completed */
|
|
|
|
if (CSR_READ_2(sc, AN_COMMAND) & AN_CMD_BUSY) {
|
2004-01-28 18:07:52 +03:00
|
|
|
if (sc->sc_ic.ic_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: command 0x%x busy\n", sc->sc_dev.dv_xname,
|
2001-06-21 16:49:06 +04:00
|
|
|
CSR_READ_2(sc, AN_COMMAND));
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CLR_STUCK_BUSY);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
CSR_WRITE_2(sc, AN_PARAM0, val);
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM1, 0);
|
|
|
|
CSR_WRITE_2(sc, AN_PARAM2, 0);
|
|
|
|
CSR_WRITE_2(sc, AN_COMMAND, cmd);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (cmd == AN_CMD_FW_RESTART) {
|
|
|
|
/* XXX: should sleep here */
|
|
|
|
DELAY(100*1000);
|
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
|
|
|
if (CSR_READ_2(sc, AN_EVENT_STAT) & AN_EV_CMD)
|
|
|
|
break;
|
|
|
|
DELAY(10);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
status = CSR_READ_2(sc, AN_STATUS);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
/* clear stuck command busy if necessary */
|
|
|
|
if (CSR_READ_2(sc, AN_COMMAND) & AN_CMD_BUSY)
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CLR_STUCK_BUSY);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
/* Ack the command */
|
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CMD);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
if (i == AN_TIMEOUT) {
|
2004-01-28 18:07:52 +03:00
|
|
|
if (sc->sc_ic.ic_if.if_flags & IFF_DEBUG)
|
2001-06-21 16:49:06 +04:00
|
|
|
printf("%s: command 0x%x param 0x%x timeout\n",
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_dev.dv_xname, cmd, val);
|
2001-06-21 16:49:06 +04:00
|
|
|
return ETIMEDOUT;
|
2000-12-19 11:00:55 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
if (status & AN_STAT_CMD_RESULT) {
|
|
|
|
if (sc->sc_ic.ic_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: command 0x%x param 0x%x status 0x%x "
|
|
|
|
"resp 0x%x 0x%x 0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, cmd, val, status,
|
|
|
|
CSR_READ_2(sc, AN_RESP0), CSR_READ_2(sc, AN_RESP1),
|
|
|
|
CSR_READ_2(sc, AN_RESP2));
|
2001-06-21 16:49:06 +04:00
|
|
|
return EIO;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
/*
|
|
|
|
* Wait for firmware come up after power enabled.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
an_wait(struct an_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
CSR_WRITE_2(sc, AN_COMMAND, AN_CMD_NOOP2);
|
|
|
|
for (i = 0; i < 3*hz; i++) {
|
|
|
|
if (CSR_READ_2(sc, AN_EVENT_STAT) & AN_EV_CMD)
|
|
|
|
break;
|
|
|
|
(void)tsleep(sc, PWAIT, "anatch", 1);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_CMD);
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
2004-01-28 18:07:52 +03:00
|
|
|
an_seek_bap(struct an_softc *sc, int id, int off)
|
2001-06-21 16:49:06 +04:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int i, status;
|
2000-12-13 23:21:10 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
CSR_WRITE_2(sc, AN_SEL0, id);
|
|
|
|
CSR_WRITE_2(sc, AN_OFF0, off);
|
2001-06-21 16:49:06 +04:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
for (i = 0; ; i++) {
|
|
|
|
status = CSR_READ_2(sc, AN_OFF0);
|
|
|
|
if ((status & AN_OFF_BUSY) == 0)
|
|
|
|
break;
|
|
|
|
if (i == AN_TIMEOUT) {
|
|
|
|
printf("%s: timeout in an_seek_bap to 0x%x/0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, id, off);
|
|
|
|
sc->sc_bap_off = AN_OFF_ERR; /* invalidate */
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
|
|
|
DELAY(10);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
if (status & AN_OFF_ERR) {
|
|
|
|
printf("%s: failed in an_seek_bap to 0x%x/0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, id, off);
|
|
|
|
sc->sc_bap_off = AN_OFF_ERR; /* invalidate */
|
2001-06-21 16:49:06 +04:00
|
|
|
return EIO;
|
2004-01-28 18:07:52 +03:00
|
|
|
}
|
|
|
|
sc->sc_bap_id = id;
|
|
|
|
sc->sc_bap_off = off;
|
2001-06-21 16:49:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
2004-01-28 18:07:52 +03:00
|
|
|
an_read_bap(struct an_softc *sc, int id, int off, void *buf, int buflen)
|
2001-06-21 16:49:06 +04:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int error, cnt;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (buflen == 0)
|
|
|
|
return 0;
|
|
|
|
if (off == -1)
|
|
|
|
off = sc->sc_bap_off;
|
|
|
|
if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
|
|
|
|
if ((error = an_seek_bap(sc, id, off)) != 0)
|
|
|
|
return EIO;
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
cnt = (buflen + 1) / 2;
|
|
|
|
CSR_READ_MULTI_STREAM_2(sc, AN_DATA0, (u_int16_t *)buf, cnt);
|
|
|
|
sc->sc_bap_off += cnt * 2;
|
2001-06-21 16:49:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
2004-01-28 18:07:52 +03:00
|
|
|
an_write_bap(struct an_softc *sc, int id, int off, void *buf, int buflen)
|
2001-06-21 16:49:06 +04:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int error, cnt;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (buflen == 0)
|
|
|
|
return 0;
|
|
|
|
if (off == -1)
|
|
|
|
off = sc->sc_bap_off;
|
|
|
|
if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
|
|
|
|
if ((error = an_seek_bap(sc, id, off)) != 0)
|
2001-06-21 16:49:06 +04:00
|
|
|
return EIO;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
cnt = (buflen + 1) / 2;
|
|
|
|
CSR_WRITE_MULTI_STREAM_2(sc, AN_DATA0, (u_int16_t *)buf, cnt);
|
|
|
|
sc->sc_bap_off += cnt * 2;
|
2001-06-21 16:49:06 +04:00
|
|
|
return 0;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
2004-01-28 18:07:52 +03:00
|
|
|
an_mwrite_bap(struct an_softc *sc, int id, int off, struct mbuf *m, int totlen)
|
2000-12-12 02:16:50 +03:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int error, len, cnt;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
if (off == -1)
|
|
|
|
off = sc->sc_bap_off;
|
|
|
|
if (id != sc->sc_bap_id || off != sc->sc_bap_off) {
|
|
|
|
if ((error = an_seek_bap(sc, id, off)) != 0)
|
2001-06-21 16:49:06 +04:00
|
|
|
return EIO;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
for (len = 0; m != NULL; m = m->m_next) {
|
|
|
|
if (m->m_len == 0)
|
|
|
|
continue;
|
|
|
|
len = min(m->m_len, totlen);
|
|
|
|
|
|
|
|
if ((mtod(m, u_long) & 0x1) || (len & 0x1)) {
|
|
|
|
m_copydata(m, 0, totlen, (caddr_t)&sc->sc_buf.sc_txbuf);
|
|
|
|
cnt = (totlen + 1) / 2;
|
|
|
|
CSR_WRITE_MULTI_STREAM_2(sc, AN_DATA0,
|
|
|
|
sc->sc_buf.sc_val, cnt);
|
|
|
|
off += cnt * 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cnt = len / 2;
|
|
|
|
CSR_WRITE_MULTI_STREAM_2(sc, AN_DATA0, mtod(m, u_int16_t *),
|
|
|
|
cnt);
|
|
|
|
off += len;
|
|
|
|
totlen -= len;
|
2001-06-21 16:49:06 +04:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_bap_off = off;
|
2001-06-21 16:49:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
static int
|
2004-01-28 18:07:52 +03:00
|
|
|
an_alloc_fid(struct an_softc *sc, int len, int *idp)
|
2001-06-21 16:49:06 +04:00
|
|
|
{
|
2004-01-28 18:07:52 +03:00
|
|
|
int i;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) {
|
|
|
|
printf("%s: failed to allocate %d bytes on NIC\n",
|
2004-01-28 18:07:52 +03:00
|
|
|
sc->sc_dev.dv_xname, len);
|
2001-06-21 16:49:06 +04:00
|
|
|
return ENOMEM;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2001-06-21 16:49:06 +04:00
|
|
|
for (i = 0; i < AN_TIMEOUT; i++) {
|
|
|
|
if (CSR_READ_2(sc, AN_EVENT_STAT) & AN_EV_ALLOC)
|
|
|
|
break;
|
2004-01-28 18:07:52 +03:00
|
|
|
if (i == AN_TIMEOUT) {
|
|
|
|
printf("%s: timeout in alloc\n", sc->sc_dev.dv_xname);
|
|
|
|
return ETIMEDOUT;
|
|
|
|
}
|
2001-06-21 16:49:06 +04:00
|
|
|
DELAY(10);
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
*idp = CSR_READ_2(sc, AN_ALLOC_FID);
|
2001-06-21 16:49:06 +04:00
|
|
|
CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_ALLOC);
|
|
|
|
return 0;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
static int
|
|
|
|
an_read_rid(struct an_softc *sc, int rid, void *buf, int *buflenp)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
u_int16_t len;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* Tell the NIC to enter record read mode. */
|
|
|
|
error = an_cmd(sc, AN_CMD_ACCESS | AN_ACCESS_READ, rid);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* length in byte, including length itself */
|
|
|
|
error = an_read_bap(sc, rid, 0, &len, sizeof(len));
|
|
|
|
if (error)
|
|
|
|
return error;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
len = le16toh(len) - 2;
|
|
|
|
if (*buflenp < len) {
|
|
|
|
printf("%s: record buffer is too small, "
|
|
|
|
"rid=%x, size=%d, len=%d\n",
|
|
|
|
sc->sc_dev.dv_xname, rid, *buflenp, len);
|
|
|
|
return ENOSPC;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
*buflenp = len;
|
|
|
|
return an_read_bap(sc, rid, sizeof(len), buf, len);
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
static int
|
|
|
|
an_write_rid(struct an_softc *sc, int rid, void *buf, int buflen)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
u_int16_t len;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
/* length in byte, including length itself */
|
|
|
|
len = htole16(buflen + 2);
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
error = an_write_bap(sc, rid, 0, &len, sizeof(len));
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = an_write_bap(sc, rid, sizeof(len), buf, buflen);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
return an_cmd(sc, AN_CMD_ACCESS | AN_ACCESS_WRITE, rid);
|
|
|
|
}
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
static int
|
|
|
|
an_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
|
|
|
|
{
|
|
|
|
struct an_softc *sc = ic->ic_softc;
|
|
|
|
struct ieee80211_node *ni = ic->ic_bss;
|
|
|
|
enum ieee80211_state ostate;
|
|
|
|
int buflen;
|
|
|
|
|
|
|
|
ostate = ic->ic_state;
|
|
|
|
DPRINTF(("an_newstate: %s -> %s\n", ieee80211_state_name[ostate],
|
|
|
|
ieee80211_state_name[nstate]));
|
|
|
|
|
|
|
|
switch (nstate) {
|
|
|
|
case IEEE80211_S_INIT:
|
|
|
|
ic->ic_flags &= ~IEEE80211_F_IBSSON;
|
|
|
|
return (*sc->sc_newstate)(ic, nstate, arg);
|
|
|
|
|
|
|
|
case IEEE80211_S_RUN:
|
|
|
|
buflen = sizeof(sc->sc_buf);
|
|
|
|
an_read_rid(sc, AN_RID_STATUS, &sc->sc_buf, &buflen);
|
|
|
|
IEEE80211_ADDR_COPY(ni->ni_bssid,
|
|
|
|
sc->sc_buf.sc_status.an_cur_bssid);
|
|
|
|
IEEE80211_ADDR_COPY(ni->ni_macaddr, ni->ni_bssid);
|
|
|
|
ni->ni_chan = &ic->ic_channels[
|
|
|
|
le16toh(sc->sc_buf.sc_status.an_cur_channel)];
|
|
|
|
ni->ni_esslen = le16toh(sc->sc_buf.sc_status.an_ssidlen);
|
|
|
|
if (ni->ni_esslen > IEEE80211_NWID_LEN)
|
|
|
|
ni->ni_esslen = IEEE80211_NWID_LEN; /*XXX*/
|
|
|
|
memcpy(ni->ni_essid, sc->sc_buf.sc_status.an_ssid,
|
|
|
|
ni->ni_esslen);
|
|
|
|
ni->ni_rates = ic->ic_sup_rates[IEEE80211_MODE_11B]; /*XXX*/
|
|
|
|
if (ic->ic_if.if_flags & IFF_DEBUG) {
|
|
|
|
printf("%s: ", sc->sc_dev.dv_xname);
|
|
|
|
if (ic->ic_opmode == IEEE80211_M_STA)
|
|
|
|
printf("associated ");
|
|
|
|
else
|
|
|
|
printf("synchronized ");
|
|
|
|
printf("with %s ssid ", ether_sprintf(ni->ni_bssid));
|
|
|
|
ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
|
|
|
|
printf(" channel %u start %uMb\n",
|
|
|
|
le16toh(sc->sc_buf.sc_status.an_cur_channel),
|
|
|
|
le16toh(sc->sc_buf.sc_status.an_current_tx_rate)/2);
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
break;
|
2000-12-12 02:16:50 +03:00
|
|
|
|
2004-01-28 18:07:52 +03:00
|
|
|
default:
|
|
|
|
break;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|
2004-01-28 18:07:52 +03:00
|
|
|
ic->ic_state = nstate;
|
|
|
|
/* skip standard ieee80211 handling */
|
|
|
|
return 0;
|
2000-12-12 02:16:50 +03:00
|
|
|
}
|