--- src/sys/netproto/802_11/wlan/ieee80211.c 2006/01/14 13:36:39 1.5 +++ src/sys/netproto/802_11/wlan/ieee80211.c 2006/05/18 13:51:46 1.6 @@ -1,6 +1,6 @@ /* * Copyright (c) 2001 Atsushi Onoe - * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,7 +29,7 @@ * (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/net80211/ieee80211.c,v 1.13 2004/05/30 17:57:45 phk Exp $ + * $FreeBSD: src/sys/net80211/ieee80211.c,v 1.19.2.7 2006/03/11 19:25:23 sam Exp $ * $DragonFly$ */ @@ -37,70 +37,106 @@ * IEEE 802.11 generic handler */ -#include "opt_inet.h" - #include #include -#include -#include #include -#include +#include + #include -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include #include +#include #include -#include -#include #include #include -#ifdef INET -#include -#include -#endif - -#ifdef IEEE80211_DEBUG -int ieee80211_debug = 0; -SYSCTL_INT(_debug, OID_AUTO, ieee80211, CTLFLAG_RW, &ieee80211_debug, - 0, "IEEE 802.11 media debugging printfs"); -#endif - -static void ieee80211_set11gbasicrates(struct ieee80211_rateset *, - enum ieee80211_phymode); - -static const char *ieee80211_phymode_name[] = { +const char *ieee80211_phymode_name[] = { "auto", /* IEEE80211_MODE_AUTO */ "11a", /* IEEE80211_MODE_11A */ "11b", /* IEEE80211_MODE_11B */ "11g", /* IEEE80211_MODE_11G */ "FH", /* IEEE80211_MODE_FH */ - "turbo", /* IEEE80211_MODE_TURBO */ + "turboA", /* IEEE80211_MODE_TURBO_A */ + "turboG", /* IEEE80211_MODE_TURBO_G */ }; +/* list of all instances */ +SLIST_HEAD(ieee80211_list, ieee80211com); +static struct ieee80211_list ieee80211_list = + SLIST_HEAD_INITIALIZER(ieee80211_list); +static uint8_t ieee80211_vapmap[32]; /* enough for 256 */ + +static void +ieee80211_add_vap(struct ieee80211com *ic) +{ +#define N(a) (sizeof(a)/sizeof(a[0])) + int i; + uint8_t b; + + crit_enter(); + + ic->ic_vap = 0; + for (i = 0; i < N(ieee80211_vapmap) && ieee80211_vapmap[i] == 0xff; i++) + ic->ic_vap += NBBY; + if (i == N(ieee80211_vapmap)) + panic("vap table full"); + for (b = ieee80211_vapmap[i]; b & 1; b >>= 1) + ic->ic_vap++; + setbit(ieee80211_vapmap, ic->ic_vap); + SLIST_INSERT_HEAD(&ieee80211_list, ic, ic_next); + + crit_exit(); +#undef N +} + +static void +ieee80211_remove_vap(struct ieee80211com *ic) +{ + crit_enter(); + + SLIST_REMOVE(&ieee80211_list, ic, ieee80211com, ic_next); + KASSERT(ic->ic_vap < sizeof(ieee80211_vapmap)*NBBY, + ("invalid vap id %d", ic->ic_vap)); + KASSERT(isset(ieee80211_vapmap, ic->ic_vap), + ("vap id %d not allocated", ic->ic_vap)); + clrbit(ieee80211_vapmap, ic->ic_vap); + + crit_exit(); +} + +/* + * Default reset method for use with the ioctl support. This + * method is invoked after any state change in the 802.11 + * layer that should be propagated to the hardware but not + * require re-initialization of the 802.11 state machine (e.g + * rescanning for an ap). We always return ENETRESET which + * should cause the driver to re-initialize the device. Drivers + * can override this method to implement more optimized support. + */ +static int +ieee80211_default_reset(struct ifnet *ifp) +{ + return ENETRESET; +} + void -ieee80211_ifattach(struct ifnet *ifp) +ieee80211_ifattach(struct ieee80211com *ic) { - struct ieee80211com *ic = (void *)ifp; + struct ifnet *ifp; struct ieee80211_channel *c; int i; + ifp = &ic->ic_ac.ac_if; + ic->ic_ifp = ifp; + ether_ifattach(ifp, ic->ic_myaddr, NULL); bpfattach_dlt(ifp, DLT_IEEE802_11, sizeof(struct ieee80211_frame_addr4), &ic->ic_rawbpf); - ieee80211_crypto_attach(ifp); + + ieee80211_crypto_attach(ic); /* * Fill in 802.11 available channel set, mark @@ -135,33 +171,79 @@ ieee80211_ifattach(struct ifnet *ifp) if (IEEE80211_IS_CHAN_FHSS(c)) ic->ic_modecaps |= 1<ic_modecaps |= 1<ic_modecaps |= 1<ic_modecaps |= 1<ic_curchan == NULL) { + /* arbitrarily pick the first channel */ + ic->ic_curchan = &ic->ic_channels[i]; + } } } /* validate ic->ic_curmode */ if ((ic->ic_modecaps & (1<ic_curmode)) == 0) ic->ic_curmode = IEEE80211_MODE_AUTO; ic->ic_des_chan = IEEE80211_CHAN_ANYC; /* any channel is ok */ - +#if 0 + /* + * Enable WME by default if we're capable. + */ + if (ic->ic_caps & IEEE80211_C_WME) + ic->ic_flags |= IEEE80211_F_WME; +#endif + if (ic->ic_caps & IEEE80211_C_BURST) + ic->ic_flags |= IEEE80211_F_BURST; ieee80211_setmode(ic, ic->ic_curmode); - if (ic->ic_lintval == 0) - ic->ic_lintval = 100; /* default sleep */ - ic->ic_bmisstimeout = 7*ic->ic_lintval; /* default 7 beacons */ + ic->ic_bintval = IEEE80211_BINTVAL_DEFAULT; + ic->ic_bmissthreshold = IEEE80211_HWBMISS_DEFAULT; + ic->ic_dtim_period = IEEE80211_DTIM_DEFAULT; + + ic->ic_lintval = ic->ic_bintval; + ic->ic_txpowlimit = IEEE80211_TXPOWER_MAX; - ieee80211_node_attach(ifp); - ieee80211_proto_attach(ifp); + ieee80211_node_attach(ic); + ieee80211_proto_attach(ic); + + ieee80211_add_vap(ic); + + ieee80211_sysctl_attach(ic); /* NB: requires ic_vap */ + + /* + * Install a default reset method for the ioctl support. + * The driver is expected to fill this in before calling us. + */ + if (ic->ic_reset == NULL) + ic->ic_reset = ieee80211_default_reset; } void -ieee80211_ifdetach(struct ifnet *ifp) +ieee80211_ifdetach(struct ieee80211com *ic) { - struct ieee80211com *ic = (void *)ifp; + struct ifnet *ifp = ic->ic_ifp; + + ieee80211_remove_vap(ic); + + ieee80211_sysctl_detach(ic); + ieee80211_proto_detach(ic); + ieee80211_crypto_detach(ic); + + /* + * XXX + * ieee80211_node_detach() -> ieee80211_node_table_cleanup() + * -> ieee80211_free_allnodes_locked() + * will assert the serializer + * In order to make the assertion work, hold serializer here + * + * SHOULD BE REMOVED + */ + lwkt_serialize_enter(ifp->if_serializer); + ieee80211_node_detach(ic); + lwkt_serialize_exit(ifp->if_serializer); - ieee80211_proto_detach(ifp); - ieee80211_crypto_detach(ifp); - ieee80211_node_detach(ifp); ifmedia_removeall(&ic->ic_media); + + bpfdetach(ifp); ether_ifdetach(ifp); } @@ -202,11 +284,11 @@ ieee80211_chan2ieee(struct ieee80211com else if (c == IEEE80211_CHAN_ANYC) return IEEE80211_CHAN_ANY; else if (c != NULL) { - if_printf(&ic->ic_if, "invalid channel freq %u flags %x\n", + if_printf(ic->ic_ifp, "invalid channel freq %u flags %x\n", c->ic_freq, c->ic_flags); return 0; /* XXX */ } else { - if_printf(&ic->ic_if, "invalid channel (NULL)\n"); + if_printf(ic->ic_ifp, "invalid channel (NULL)\n"); return 0; /* XXX */ } } @@ -243,23 +325,36 @@ ieee80211_ieee2mhz(u_int chan, u_int fla * ieee80211_attach and before most anything else. */ void -ieee80211_media_init(struct ifnet *ifp, +ieee80211_media_init(struct ieee80211com *ic, ifm_change_cb_t media_change, ifm_stat_cb_t media_stat) { #define ADD(_ic, _s, _o) \ ifmedia_add(&(_ic)->ic_media, \ IFM_MAKEWORD(IFM_IEEE80211, (_s), (_o), 0), 0, NULL) - struct ieee80211com *ic = (void *)ifp; + struct ifnet *ifp = ic->ic_ifp; struct ifmediareq imr; int i, j, mode, rate, maxrate, mword, mopt, r; struct ieee80211_rateset *rs; struct ieee80211_rateset allrates; /* + * XXX + * ieee80211_node_lateattach() -> ieee80211_rest_bss() + * -> ieee80211_alloc_node() -> ieee80211_setup_node() + * will assert the serializer + * In order to make the assertion work, hold serializer here + * + * SHOULD BE REMOVED + */ + lwkt_serialize_enter(ifp->if_serializer); + + /* * Do late attach work that must wait for any subclass * (i.e. driver) work such as overriding methods. */ - ieee80211_node_lateattach(ifp); + ieee80211_node_lateattach(ic); + + lwkt_serialize_exit(ifp->if_serializer); /* * Fill in media characteristics. @@ -268,13 +363,14 @@ ieee80211_media_init(struct ifnet *ifp, maxrate = 0; memset(&allrates, 0, sizeof(allrates)); for (mode = IEEE80211_MODE_AUTO; mode < IEEE80211_MODE_MAX; mode++) { - static const u_int mopts[] = { + static const u_int mopts[] = { IFM_AUTO, IFM_IEEE80211_11A, IFM_IEEE80211_11B, IFM_IEEE80211_11G, IFM_IEEE80211_FH, IFM_IEEE80211_11A | IFM_IEEE80211_TURBO, + IFM_IEEE80211_11G | IFM_IEEE80211_TURBO, }; if ((ic->ic_modecaps & (1<ic_sup_rates[mode]; for (i = 0; i < rs->rs_nrates; i++) { rate = rs->rs_rates[i]; mword = ieee80211_rate2media(ic, rate, mode); if (mword == 0) continue; - printf("%s%d%sMbps", (i != 0 ? " " : ""), - (rate & IEEE80211_RATE_VAL) / 2, - ((rate & 0x1) != 0 ? ".5" : "")); ADD(ic, mword, mopt); if (ic->ic_caps & IEEE80211_C_IBSS) ADD(ic, mword, mopt | IFM_IEEE80211_ADHOC); @@ -325,7 +417,6 @@ ieee80211_media_init(struct ifnet *ifp, if (rate > maxrate) maxrate = rate; } - printf("\n"); } for (i = 0; i < allrates.rs_nrates; i++) { mword = ieee80211_rate2media(ic, allrates.rs_rates[i], @@ -351,6 +442,31 @@ ieee80211_media_init(struct ifnet *ifp, #undef ADD } +void +ieee80211_announce(struct ieee80211com *ic) +{ + struct ifnet *ifp = ic->ic_ifp; + int i, mode, rate, mword; + struct ieee80211_rateset *rs; + + for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { + if ((ic->ic_modecaps & (1<ic_sup_rates[mode]; + for (i = 0; i < rs->rs_nrates; i++) { + rate = rs->rs_rates[i]; + mword = ieee80211_rate2media(ic, rate, mode); + if (mword == 0) + continue; + printf("%s%d%sMbps", (i != 0 ? " " : ""), + (rate & IEEE80211_RATE_VAL) / 2, + ((rate & 0x1) != 0 ? ".5" : "")); + } + printf("\n"); + } +} + static int findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate) { @@ -365,17 +481,50 @@ findrate(struct ieee80211com *ic, enum i } /* + * Find an instance by it's mac address. + */ +struct ieee80211com * +ieee80211_find_vap(const uint8_t mac[IEEE80211_ADDR_LEN]) +{ + struct ieee80211com *ic; + + /* XXX lock */ + SLIST_FOREACH(ic, &ieee80211_list, ic_next) + if (IEEE80211_ADDR_EQ(mac, ic->ic_myaddr)) + return ic; + return NULL; +} + +static struct ieee80211com * +ieee80211_find_instance(struct ifnet *ifp) +{ + struct ieee80211com *ic; + + /* XXX lock */ + /* XXX not right for multiple instances but works for now */ + SLIST_FOREACH(ic, &ieee80211_list, ic_next) + if (ic->ic_ifp == ifp) + return ic; + return NULL; +} + +/* * Handle a media change request. */ int ieee80211_media_change(struct ifnet *ifp) { - struct ieee80211com *ic = (void *)ifp; + struct ieee80211com *ic; struct ifmedia_entry *ime; enum ieee80211_opmode newopmode; enum ieee80211_phymode newphymode; int i, j, newrate, error = 0; + ic = ieee80211_find_instance(ifp); + if (!ic) { + if_printf(ifp, "%s: no 802.11 instance!\n", __func__); + return EINVAL; + } ime = ic->ic_media.ifm_cur; /* * First, identify the phy mode. @@ -400,13 +549,16 @@ ieee80211_media_change(struct ifnet *ifp return EINVAL; } /* - * Turbo mode is an ``option''. Eventually it - * needs to be applied to 11g too. + * Turbo mode is an ``option''. + * XXX does not apply to AUTO */ if (ime->ifm_media & IFM_IEEE80211_TURBO) { - if (newphymode != IEEE80211_MODE_11A) + if (newphymode == IEEE80211_MODE_11A) + newphymode = IEEE80211_MODE_TURBO_A; + else if (newphymode == IEEE80211_MODE_11G) + newphymode = IEEE80211_MODE_TURBO_G; + else return EINVAL; - newphymode = IEEE80211_MODE_TURBO; } /* * Validate requested mode is available. @@ -513,14 +665,15 @@ ieee80211_media_change(struct ifnet *ifp break; case IEEE80211_M_IBSS: ic->ic_flags |= IEEE80211_F_IBSSON; -#ifdef notdef - if (ic->ic_curmode == IEEE80211_MODE_11G) - ieee80211_set11gbasicrates( - &ic->ic_suprates[newphymode], - IEEE80211_MODE_11B); -#endif break; } + /* + * Yech, slot time may change depending on the + * operating mode so reset it to be sure everything + * is setup appropriately. + */ + ieee80211_reset_erp(ic); + ieee80211_wme_initparams(ic); /* after opmode change */ error = ENETRESET; } #ifdef notdef @@ -533,26 +686,39 @@ ieee80211_media_change(struct ifnet *ifp void ieee80211_media_status(struct ifnet *ifp, struct ifmediareq *imr) { - struct ieee80211com *ic = (void *)ifp; - struct ieee80211_node *ni = NULL; - int old_status = imr->ifm_status; + struct ieee80211com *ic; + struct ieee80211_rateset *rs; + ic = ieee80211_find_instance(ifp); + if (!ic) { + if_printf(ifp, "%s: no 802.11 instance!\n", __func__); + return; + } imr->ifm_status = IFM_AVALID; imr->ifm_active = IFM_IEEE80211; -/* XXX - if (ic->ic_state == IEEE80211_S_RUN) { + if (ic->ic_state == IEEE80211_S_RUN) imr->ifm_status |= IFM_ACTIVE; - ifp->if_link_state = LINK_STATE_UP; + /* + * Calculate a current rate if possible. + */ + if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE) { + /* + * A fixed rate is set, report that. + */ + rs = &ic->ic_sup_rates[ic->ic_curmode]; + imr->ifm_active |= ieee80211_rate2media(ic, + rs->rs_rates[ic->ic_fixed_rate], ic->ic_curmode); + } else if (ic->ic_opmode == IEEE80211_M_STA) { + /* + * In station mode report the current transmit rate. + */ + rs = &ic->ic_bss->ni_rates; + imr->ifm_active |= ieee80211_rate2media(ic, + rs->rs_rates[ic->ic_bss->ni_txrate], ic->ic_curmode); } else - ifp->if_link_state = LINK_STATE_DOWN; -*/ - imr->ifm_active |= IFM_AUTO; + imr->ifm_active |= IFM_AUTO; switch (ic->ic_opmode) { case IEEE80211_M_STA: - ni = ic->ic_bss; - /* calculate rate subtype */ - imr->ifm_active |= ieee80211_rate2media(ic, - ni->ni_rates.rs_rates[ni->ni_txrate], ic->ic_curmode); break; case IEEE80211_M_IBSS: imr->ifm_active |= IFM_IEEE80211_ADHOC; @@ -580,58 +746,41 @@ ieee80211_media_status(struct ifnet *ifp case IEEE80211_MODE_FH: imr->ifm_active |= IFM_IEEE80211_FH; break; - case IEEE80211_MODE_TURBO: + case IEEE80211_MODE_TURBO_A: imr->ifm_active |= IFM_IEEE80211_11A | IFM_IEEE80211_TURBO; break; + case IEEE80211_MODE_TURBO_G: + imr->ifm_active |= IFM_IEEE80211_11G + | IFM_IEEE80211_TURBO; + break; } - - /* Notify that the link state has changed. */ - if (imr->ifm_status != old_status) - rt_ifmsg(ifp); } void -ieee80211_watchdog(struct ifnet *ifp) +ieee80211_watchdog(struct ieee80211com *ic) { - struct ieee80211com *ic = (void *)ifp; + struct ieee80211_node_table *nt; + int need_inact_timer = 0; - if (ic->ic_mgt_timer && --ic->ic_mgt_timer == 0) - ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); - if (ic->ic_inact_timer && --ic->ic_inact_timer == 0) - ieee80211_timeout_nodes(ic); - - if (ic->ic_mgt_timer != 0 || ic->ic_inact_timer != 0) - ifp->if_timer = 1; -} - -/* - * Mark the basic rates for the 11g rate table based on the - * operating mode. For real 11g we mark all the 11b rates - * and 6, 12, and 24 OFDM. For 11b compatibility we mark only - * 11b rates. There's also a pseudo 11a-mode used to mark only - * the basic OFDM rates. - */ -static void -ieee80211_set11gbasicrates(struct ieee80211_rateset *rs, enum ieee80211_phymode mode) -{ - static const struct ieee80211_rateset basic[] = { - { 3, { 12, 24, 48 } }, /* IEEE80211_MODE_11A */ - { 4, { 2, 4, 11, 22 } }, /* IEEE80211_MODE_11B */ - { 7, { 2, 4, 11, 22, 12, 24, 48 } },/* IEEE80211_MODE_11G */ - { 0 }, /* IEEE80211_MODE_FH */ - { 0 }, /* IEEE80211_MODE_TURBO */ - }; - int i, j; - - for (i = 0; i < rs->rs_nrates; i++) { - rs->rs_rates[i] &= IEEE80211_RATE_VAL; - for (j = 0; j < basic[mode].rs_nrates; j++) - if (basic[mode].rs_rates[j] == rs->rs_rates[i]) { - rs->rs_rates[i] |= IEEE80211_RATE_BASIC; - break; - } + if (ic->ic_state != IEEE80211_S_INIT) { + if (ic->ic_mgt_timer && --ic->ic_mgt_timer == 0) + ieee80211_new_state(ic, IEEE80211_S_SCAN, 0); + nt = &ic->ic_scan; + if (nt->nt_inact_timer) { + if (--nt->nt_inact_timer == 0) + nt->nt_timeout(nt); + need_inact_timer += nt->nt_inact_timer; + } + nt = &ic->ic_sta; + if (nt->nt_inact_timer) { + if (--nt->nt_inact_timer == 0) + nt->nt_timeout(nt); + need_inact_timer += nt->nt_inact_timer; + } } + if (ic->ic_mgt_timer != 0 || need_inact_timer) + ic->ic_ifp->if_timer = 1; } /* @@ -650,7 +799,8 @@ ieee80211_setmode(struct ieee80211com *i IEEE80211_CHAN_B, /* IEEE80211_MODE_11B */ IEEE80211_CHAN_PUREG, /* IEEE80211_MODE_11G */ IEEE80211_CHAN_FHSS, /* IEEE80211_MODE_FH */ - IEEE80211_CHAN_T, /* IEEE80211_MODE_TURBO */ + IEEE80211_CHAN_T, /* IEEE80211_MODE_TURBO_A */ + IEEE80211_CHAN_108G, /* IEEE80211_MODE_TURBO_G */ }; struct ieee80211_channel *c; u_int modeflags; @@ -658,8 +808,9 @@ ieee80211_setmode(struct ieee80211com *i /* validate new mode */ if ((ic->ic_modecaps & (1<ic_modecaps)); + IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY, + "%s: mode %u not supported (caps 0x%x)\n", + __func__, mode, ic->ic_modecaps); return EINVAL; } @@ -671,9 +822,11 @@ ieee80211_setmode(struct ieee80211com *i modeflags = chanflags[mode]; for (i = 0; i <= IEEE80211_CHAN_MAX; i++) { c = &ic->ic_channels[i]; + if (c->ic_flags == 0) + continue; if (mode == IEEE80211_MODE_AUTO) { - /* ignore turbo channels for autoselect */ - if ((c->ic_flags &~ IEEE80211_CHAN_TURBO) != 0) + /* ignore static turbo channels for autoselect */ + if (!IEEE80211_IS_CHAN_T(c)) break; } else { if ((c->ic_flags & modeflags) == modeflags) @@ -681,8 +834,8 @@ ieee80211_setmode(struct ieee80211com *i } } if (i > IEEE80211_CHAN_MAX) { - IEEE80211_DPRINTF(("%s: no channels found for mode %u\n", - __func__, mode)); + IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY, + "%s: no channels found for mode %u\n", __func__, mode); return EINVAL; } @@ -692,9 +845,11 @@ ieee80211_setmode(struct ieee80211com *i memset(ic->ic_chan_active, 0, sizeof(ic->ic_chan_active)); for (i = 0; i <= IEEE80211_CHAN_MAX; i++) { c = &ic->ic_channels[i]; + if (c->ic_flags == 0) + continue; if (mode == IEEE80211_MODE_AUTO) { - /* take anything but pure turbo channels */ - if ((c->ic_flags &~ IEEE80211_CHAN_TURBO) != 0) + /* take anything but static turbo channels */ + if (!IEEE80211_IS_CHAN_T(c)) setbit(ic->ic_chan_active, i); } else { if ((c->ic_flags & modeflags) == modeflags) @@ -714,57 +869,80 @@ ieee80211_setmode(struct ieee80211com *i ic->ic_ibss_chan = &ic->ic_channels[i]; break; } + KASSERT(ic->ic_ibss_chan != NULL && + isset(ic->ic_chan_active, + ieee80211_chan2ieee(ic, ic->ic_ibss_chan)), + ("Bad IBSS channel %u", + ieee80211_chan2ieee(ic, ic->ic_ibss_chan))); } + /* + * If the desired channel is set but no longer valid then reset it. + */ + if (ic->ic_des_chan != IEEE80211_CHAN_ANYC && + isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ic->ic_des_chan))) + ic->ic_des_chan = IEEE80211_CHAN_ANYC; /* - * Set/reset state flags that influence beacon contents, etc. - * - * XXX what if we have stations already associated??? - * XXX probably not right for autoselect? + * Do mode-specific rate setup. */ - if (ic->ic_caps & IEEE80211_C_SHPREAMBLE) - ic->ic_flags |= IEEE80211_F_SHPREAMBLE; if (mode == IEEE80211_MODE_11G) { - if (ic->ic_caps & IEEE80211_C_SHSLOT) - ic->ic_flags |= IEEE80211_F_SHSLOT; + /* + * Use a mixed 11b/11g rate set. + */ ieee80211_set11gbasicrates(&ic->ic_sup_rates[mode], IEEE80211_MODE_11G); - } else { - ic->ic_flags &= ~IEEE80211_F_SHSLOT; + } else if (mode == IEEE80211_MODE_11B) { + /* + * Force pure 11b rate set. + */ + ieee80211_set11gbasicrates(&ic->ic_sup_rates[mode], + IEEE80211_MODE_11B); } + /* + * Setup an initial rate set according to the + * current/default channel selected above. This + * will be changed when scanning but must exist + * now so driver have a consistent state of ic_ibss_chan. + */ + if (ic->ic_bss) /* NB: can be called before lateattach */ + ic->ic_bss->ni_rates = ic->ic_sup_rates[mode]; ic->ic_curmode = mode; + ieee80211_reset_erp(ic); /* reset ERP state */ + ieee80211_wme_initparams(ic); /* reset WME stat */ + return 0; #undef N } /* * Return the phy mode for with the specified channel so the - * caller can select a rate set. This is problematic and the - * work here assumes how things work elsewhere in this code. + * caller can select a rate set. This is problematic for channels + * where multiple operating modes are possible (e.g. 11g+11b). + * In those cases we defer to the current operating mode when set. */ enum ieee80211_phymode ieee80211_chan2mode(struct ieee80211com *ic, struct ieee80211_channel *chan) { - /* - * NB: this assumes the channel would not be supplied to us - * unless it was already compatible with the current mode. - */ - if (ic->ic_curmode != IEEE80211_MODE_AUTO) - return ic->ic_curmode; - /* - * In autoselect mode; deduce a mode based on the channel - * characteristics. We assume that turbo-only channels - * are not considered when the channel set is constructed. - */ - if (IEEE80211_IS_CHAN_5GHZ(chan)) + if (IEEE80211_IS_CHAN_T(chan)) { + return IEEE80211_MODE_TURBO_A; + } else if (IEEE80211_IS_CHAN_5GHZ(chan)) { return IEEE80211_MODE_11A; - else if (IEEE80211_IS_CHAN_FHSS(chan)) + } else if (IEEE80211_IS_CHAN_FHSS(chan)) { return IEEE80211_MODE_FH; - else if (chan->ic_flags & (IEEE80211_CHAN_OFDM|IEEE80211_CHAN_DYN)) + } else if (chan->ic_flags & (IEEE80211_CHAN_OFDM|IEEE80211_CHAN_DYN)) { + /* + * This assumes all 11g channels are also usable + * for 11b, which is currently true. + */ + if (ic->ic_curmode == IEEE80211_MODE_TURBO_G) + return IEEE80211_MODE_TURBO_G; + if (ic->ic_curmode == IEEE80211_MODE_11B) + return IEEE80211_MODE_11B; return IEEE80211_MODE_11G; - else + } else { return IEEE80211_MODE_11B; + } } /* @@ -813,7 +991,7 @@ ieee80211_rate2media(struct ieee80211com mask = rate & IEEE80211_RATE_VAL; switch (mode) { case IEEE80211_MODE_11A: - case IEEE80211_MODE_TURBO: + case IEEE80211_MODE_TURBO_A: mask |= IFM_IEEE80211_11A; break; case IEEE80211_MODE_11B: @@ -831,6 +1009,7 @@ ieee80211_rate2media(struct ieee80211com /* NB: hack, 11g matches both 11b+11a rates */ /* fall thru... */ case IEEE80211_MODE_11G: + case IEEE80211_MODE_TURBO_G: mask |= IFM_IEEE80211_11G; break; } @@ -870,33 +1049,3 @@ ieee80211_media2rate(int mword) ieeerates[IFM_SUBTYPE(mword)] : 0; #undef N } - -/* - * Module glue. - * - * NB: the module name is "wlan" for compatibility with NetBSD. - */ - -static int -ieee80211_modevent(module_t mod, int type, void *unused) -{ - switch (type) { - case MOD_LOAD: - if (bootverbose) - printf("wlan: <802.11 Link Layer>\n"); - return 0; - case MOD_UNLOAD: - case MOD_SHUTDOWN: - return 0; - } - return EINVAL; -} - -static moduledata_t ieee80211_mod = { - "wlan", - ieee80211_modevent, - 0 -}; -DECLARE_MODULE(wlan, ieee80211_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); -MODULE_VERSION(wlan, 1); -MODULE_DEPEND(wlan, crypto, 1, 1, 1);