summaryrefslogtreecommitdiffstats
path: root/sys/net80211/ieee80211.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/net80211/ieee80211.c')
-rw-r--r--sys/net80211/ieee80211.c459
1 files changed, 275 insertions, 184 deletions
diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c
index 7bbeedc..d7e0122 100644
--- a/sys/net80211/ieee80211.c
+++ b/sys/net80211/ieee80211.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,70 +37,84 @@ __FBSDID("$FreeBSD$");
* IEEE 802.11 generic handler
*/
-#include "opt_inet.h"
-
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/mbuf.h>
-#include <sys/malloc.h>
#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/endian.h>
-#include <sys/errno.h>
-#include <sys/bus.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-
-#include <machine/atomic.h>
+#include <sys/socket.h>
+
#include <net/if.h>
-#include <net/if_dl.h>
#include <net/if_media.h>
-#include <net/if_arp.h>
#include <net/ethernet.h>
-#include <net/if_llc.h>
-#include <net/route.h>
#include <net80211/ieee80211_var.h>
#include <net/bpf.h>
-#ifdef INET
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#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[] = {
"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 u_int8_t ieee80211_vapmap[32]; /* enough for 256 */
+static struct mtx ieee80211_vap_mtx;
+MTX_SYSINIT(ieee80211, &ieee80211_vap_mtx, "net80211 instances", MTX_DEF);
+
+static void
+ieee80211_add_vap(struct ieee80211com *ic)
+{
+#define N(a) (sizeof(a)/sizeof(a[0]))
+ int i;
+ u_int8_t b;
+
+ mtx_lock(&ieee80211_vap_mtx);
+ 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);
+ mtx_unlock(&ieee80211_vap_mtx);
+#undef N
+}
+
+static void
+ieee80211_remove_vap(struct ieee80211com *ic)
+{
+ mtx_lock(&ieee80211_vap_mtx);
+ 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);
+ mtx_unlock(&ieee80211_vap_mtx);
+}
+
void
-ieee80211_ifattach(struct ifnet *ifp)
+ieee80211_ifattach(struct ieee80211com *ic)
{
- struct ieee80211com *ic = (void *)ifp;
+ struct ifnet *ifp = ic->ic_ifp;
struct ieee80211_channel *c;
int i;
ether_ifattach(ifp, ic->ic_myaddr);
bpfattach2(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,7 +149,9 @@ ieee80211_ifattach(struct ifnet *ifp)
if (IEEE80211_IS_CHAN_FHSS(c))
ic->ic_modecaps |= 1<<IEEE80211_MODE_FH;
if (IEEE80211_IS_CHAN_T(c))
- ic->ic_modecaps |= 1<<IEEE80211_MODE_TURBO;
+ ic->ic_modecaps |= 1<<IEEE80211_MODE_TURBO_A;
+ if (IEEE80211_IS_CHAN_108G(c))
+ ic->ic_modecaps |= 1<<IEEE80211_MODE_TURBO_G;
}
}
/* validate ic->ic_curmode */
@@ -143,25 +159,45 @@ ieee80211_ifattach(struct ifnet *ifp)
ic->ic_curmode = IEEE80211_MODE_AUTO;
ic->ic_des_chan = IEEE80211_CHAN_ANYC; /* any channel is ok */
+ /*
+ * Enable WME by default if we're capable.
+ */
+ if (ic->ic_caps & IEEE80211_C_WME)
+ ic->ic_flags |= IEEE80211_F_WME;
+
(void) ieee80211_setmode(ic, ic->ic_curmode);
if (ic->ic_lintval == 0)
- ic->ic_lintval = 100; /* default sleep */
+ ic->ic_lintval = IEEE80211_BINTVAL_DEFAULT;
ic->ic_bmisstimeout = 7*ic->ic_lintval; /* default 7 beacons */
+ ic->ic_dtim_period = IEEE80211_DTIM_DEFAULT;
+ IEEE80211_BEACON_LOCK_INIT(ic, "beacon");
+
+ 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 */
}
void
-ieee80211_ifdetach(struct ifnet *ifp)
+ieee80211_ifdetach(struct ieee80211com *ic)
{
- struct ieee80211com *ic = (void *)ifp;
+ struct ifnet *ifp = ic->ic_ifp;
- ieee80211_proto_detach(ifp);
- ieee80211_crypto_detach(ifp);
- ieee80211_node_detach(ifp);
+ ieee80211_remove_vap(ic);
+
+ ieee80211_sysctl_detach(ic);
+ ieee80211_proto_detach(ic);
+ ieee80211_crypto_detach(ic);
+ ieee80211_node_detach(ic);
ifmedia_removeall(&ic->ic_media);
+
+ IEEE80211_BEACON_LOCK_DESTROY(ic);
+
bpfdetach(ifp);
ether_ifdetach(ifp);
}
@@ -203,11 +239,11 @@ ieee80211_chan2ieee(struct ieee80211com *ic, struct ieee80211_channel *c)
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 */
}
}
@@ -244,13 +280,13 @@ ieee80211_ieee2mhz(u_int chan, u_int flags)
* 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;
@@ -260,7 +296,7 @@ ieee80211_media_init(struct ifnet *ifp,
* 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);
/*
* Fill in media characteristics.
@@ -276,6 +312,7 @@ ieee80211_media_init(struct ifnet *ifp,
IFM_IEEE80211_11G,
IFM_IEEE80211_FH,
IFM_IEEE80211_11A | IFM_IEEE80211_TURBO,
+ IFM_IEEE80211_11G | IFM_IEEE80211_TURBO,
};
if ((ic->ic_modecaps & (1<<mode)) == 0)
continue;
@@ -291,16 +328,12 @@ ieee80211_media_init(struct ifnet *ifp,
ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_MONITOR);
if (mode == IEEE80211_MODE_AUTO)
continue;
- if_printf(ifp, "%s rates: ", ieee80211_phymode_name[mode]);
rs = &ic->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);
@@ -326,7 +359,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],
@@ -352,6 +384,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<<mode)) == 0)
+ continue;
+ if_printf(ifp, "%s rates: ", ieee80211_phymode_name[mode]);
+ rs = &ic->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)
{
@@ -366,17 +423,50 @@ findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate)
}
/*
+ * Find an instance by it's mac address.
+ */
+struct ieee80211com *
+ieee80211_find_vap(const u_int8_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.
@@ -401,13 +491,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.
@@ -514,14 +607,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
@@ -534,24 +628,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;
- 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 != -1) {
+ /*
+ * 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;
@@ -579,58 +688,41 @@ ieee80211_media_status(struct ifnet *ifp, struct ifmediareq *imr)
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)
-{
- struct ieee80211com *ic = (void *)ifp;
-
- 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)
+ieee80211_watchdog(struct ieee80211com *ic)
{
- 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;
- }
+ struct ieee80211_node_table *nt;
+ int need_inact_timer = 0;
+
+ 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 != NULL && 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;
}
/*
@@ -649,7 +741,8 @@ ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode)
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;
@@ -657,8 +750,9 @@ ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode)
/* validate new mode */
if ((ic->ic_modecaps & (1<<mode)) == 0) {
- IEEE80211_DPRINTF(("%s: mode %u not supported (caps 0x%x)\n",
- __func__, mode, ic->ic_modecaps));
+ IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY,
+ "%s: mode %u not supported (caps 0x%x)\n",
+ __func__, mode, ic->ic_modecaps);
return EINVAL;
}
@@ -680,8 +774,8 @@ ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode)
}
}
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;
}
@@ -713,56 +807,82 @@ ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode)
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_5GHZ(chan)) {
+ /*
+ * This assumes all 11a turbo channels are also
+ * usable withut turbo, which is currently true.
+ */
+ if (ic->ic_curmode == IEEE80211_MODE_TURBO_A)
+ return IEEE80211_MODE_TURBO_A;
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;
}
@@ -812,7 +932,7 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode m
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:
@@ -830,6 +950,7 @@ ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode m
/* NB: hack, 11g matches both 11b+11a rates */
/* fall thru... */
case IEEE80211_MODE_11G:
+ case IEEE80211_MODE_TURBO_G:
mask |= IFM_IEEE80211_11G;
break;
}
@@ -869,33 +990,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:
- 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, rc4, 1, 1, 1);
-MODULE_DEPEND(wlan, ether, 1, 1, 1);
OpenPOWER on IntegriCloud