2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * IEEE 802.11 protocol support.
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
41 #include <sys/socket.h>
42 #include <sys/sockio.h>
45 #include <net/if_media.h>
46 #include <net/ethernet.h> /* XXX for ether_sprintf */
48 #include <net80211/ieee80211_var.h>
49 #include <net80211/ieee80211_adhoc.h>
50 #include <net80211/ieee80211_sta.h>
51 #include <net80211/ieee80211_hostap.h>
52 #include <net80211/ieee80211_wds.h>
53 #ifdef IEEE80211_SUPPORT_MESH
54 #include <net80211/ieee80211_mesh.h>
56 #include <net80211/ieee80211_monitor.h>
57 #include <net80211/ieee80211_input.h>
60 #define AGGRESSIVE_MODE_SWITCH_HYSTERESIS 3 /* pkts / 100ms */
61 #define HIGH_PRI_SWITCH_THRESH 10 /* pkts / 100ms */
63 const char *ieee80211_mgt_subtype_name[] = {
64 "assoc_req", "assoc_resp", "reassoc_req", "reassoc_resp",
65 "probe_req", "probe_resp", "reserved#6", "reserved#7",
66 "beacon", "atim", "disassoc", "auth",
67 "deauth", "action", "action_noack", "reserved#15"
69 const char *ieee80211_ctl_subtype_name[] = {
70 "reserved#0", "reserved#1", "reserved#2", "reserved#3",
71 "reserved#3", "reserved#5", "reserved#6", "reserved#7",
72 "reserved#8", "reserved#9", "ps_poll", "rts",
73 "cts", "ack", "cf_end", "cf_end_ack"
75 const char *ieee80211_opmode_name[IEEE80211_OPMODE_MAX] = {
76 "IBSS", /* IEEE80211_M_IBSS */
77 "STA", /* IEEE80211_M_STA */
78 "WDS", /* IEEE80211_M_WDS */
79 "AHDEMO", /* IEEE80211_M_AHDEMO */
80 "HOSTAP", /* IEEE80211_M_HOSTAP */
81 "MONITOR", /* IEEE80211_M_MONITOR */
82 "MBSS" /* IEEE80211_M_MBSS */
84 const char *ieee80211_state_name[IEEE80211_S_MAX] = {
85 "INIT", /* IEEE80211_S_INIT */
86 "SCAN", /* IEEE80211_S_SCAN */
87 "AUTH", /* IEEE80211_S_AUTH */
88 "ASSOC", /* IEEE80211_S_ASSOC */
89 "CAC", /* IEEE80211_S_CAC */
90 "RUN", /* IEEE80211_S_RUN */
91 "CSA", /* IEEE80211_S_CSA */
92 "SLEEP", /* IEEE80211_S_SLEEP */
94 const char *ieee80211_wme_acnames[] = {
102 static void beacon_miss(void *, int);
103 static void beacon_swmiss(void *, int);
104 static void parent_updown(void *, int);
105 static void update_mcast(void *, int);
106 static void update_promisc(void *, int);
107 static void update_channel(void *, int);
108 static void update_chw(void *, int);
109 static void ieee80211_newstate_cb(void *, int);
112 null_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
113 const struct ieee80211_bpf_params *params)
115 struct ifnet *ifp = ni->ni_ic->ic_ifp;
117 if_printf(ifp, "missing ic_raw_xmit callback, drop frame\n");
123 ieee80211_proto_attach(struct ieee80211com *ic)
125 struct ifnet *ifp = ic->ic_ifp;
127 /* override the 802.3 setting */
128 ifp->if_hdrlen = ic->ic_headroom
129 + sizeof(struct ieee80211_qosframe_addr4)
130 + IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN
131 + IEEE80211_WEP_EXTIVLEN;
132 /* XXX no way to recalculate on ifdetach */
133 if (ALIGN(ifp->if_hdrlen) > max_linkhdr) {
134 /* XXX sanity check... */
135 max_linkhdr = ALIGN(ifp->if_hdrlen);
136 max_hdr = max_linkhdr + max_protohdr;
137 max_datalen = MHLEN - max_hdr;
139 ic->ic_protmode = IEEE80211_PROT_CTSONLY;
141 TASK_INIT(&ic->ic_parent_task, 0, parent_updown, ifp);
142 TASK_INIT(&ic->ic_mcast_task, 0, update_mcast, ic);
143 TASK_INIT(&ic->ic_promisc_task, 0, update_promisc, ic);
144 TASK_INIT(&ic->ic_chan_task, 0, update_channel, ic);
145 TASK_INIT(&ic->ic_bmiss_task, 0, beacon_miss, ic);
146 TASK_INIT(&ic->ic_chw_task, 0, update_chw, ic);
148 ic->ic_wme.wme_hipri_switch_hysteresis =
149 AGGRESSIVE_MODE_SWITCH_HYSTERESIS;
151 /* initialize management frame handlers */
152 ic->ic_send_mgmt = ieee80211_send_mgmt;
153 ic->ic_raw_xmit = null_raw_xmit;
155 ieee80211_adhoc_attach(ic);
156 ieee80211_sta_attach(ic);
157 ieee80211_wds_attach(ic);
158 ieee80211_hostap_attach(ic);
159 #ifdef IEEE80211_SUPPORT_MESH
160 ieee80211_mesh_attach(ic);
162 ieee80211_monitor_attach(ic);
166 ieee80211_proto_detach(struct ieee80211com *ic)
168 ieee80211_monitor_detach(ic);
169 #ifdef IEEE80211_SUPPORT_MESH
170 ieee80211_mesh_detach(ic);
172 ieee80211_hostap_detach(ic);
173 ieee80211_wds_detach(ic);
174 ieee80211_adhoc_detach(ic);
175 ieee80211_sta_detach(ic);
179 null_update_beacon(struct ieee80211vap *vap, int item)
184 ieee80211_proto_vattach(struct ieee80211vap *vap)
186 struct ieee80211com *ic = vap->iv_ic;
187 struct ifnet *ifp = vap->iv_ifp;
190 /* override the 802.3 setting */
191 ifp->if_hdrlen = ic->ic_ifp->if_hdrlen;
193 vap->iv_rtsthreshold = IEEE80211_RTS_DEFAULT;
194 vap->iv_fragthreshold = IEEE80211_FRAG_DEFAULT;
195 vap->iv_bmiss_max = IEEE80211_BMISS_MAX;
196 callout_init_mtx(&vap->iv_swbmiss, IEEE80211_LOCK_OBJ(ic), 0);
197 callout_init(&vap->iv_mgtsend, CALLOUT_MPSAFE);
198 TASK_INIT(&vap->iv_nstate_task, 0, ieee80211_newstate_cb, vap);
199 TASK_INIT(&vap->iv_swbmiss_task, 0, beacon_swmiss, vap);
201 * Install default tx rate handling: no fixed rate, lowest
202 * supported rate for mgmt and multicast frames. Default
203 * max retry count. These settings can be changed by the
204 * driver and/or user applications.
206 for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++) {
207 const struct ieee80211_rateset *rs = &ic->ic_sup_rates[i];
209 vap->iv_txparms[i].ucastrate = IEEE80211_FIXED_RATE_NONE;
212 * Setting the management rate to MCS 0 assumes that the
213 * BSS Basic rate set is empty and the BSS Basic MCS set
216 * Since we're not checking this, default to the lowest
217 * defined rate for this mode.
219 * At least one 11n AP (DLINK DIR-825) is reported to drop
220 * some MCS management traffic (eg BA response frames.)
222 * See also: 9.6.0 of the 802.11n-2009 specification.
225 if (i == IEEE80211_MODE_11NA || i == IEEE80211_MODE_11NG) {
226 vap->iv_txparms[i].mgmtrate = 0 | IEEE80211_RATE_MCS;
227 vap->iv_txparms[i].mcastrate = 0 | IEEE80211_RATE_MCS;
229 vap->iv_txparms[i].mgmtrate =
230 rs->rs_rates[0] & IEEE80211_RATE_VAL;
231 vap->iv_txparms[i].mcastrate =
232 rs->rs_rates[0] & IEEE80211_RATE_VAL;
235 vap->iv_txparms[i].mgmtrate = rs->rs_rates[0] & IEEE80211_RATE_VAL;
236 vap->iv_txparms[i].mcastrate = rs->rs_rates[0] & IEEE80211_RATE_VAL;
237 vap->iv_txparms[i].maxretry = IEEE80211_TXMAX_DEFAULT;
239 vap->iv_roaming = IEEE80211_ROAMING_AUTO;
241 vap->iv_update_beacon = null_update_beacon;
242 vap->iv_deliver_data = ieee80211_deliver_data;
244 /* attach support for operating mode */
245 ic->ic_vattach[vap->iv_opmode](vap);
249 ieee80211_proto_vdetach(struct ieee80211vap *vap)
251 #define FREEAPPIE(ie) do { \
253 free(ie, M_80211_NODE_IE); \
256 * Detach operating mode module.
258 if (vap->iv_opdetach != NULL)
259 vap->iv_opdetach(vap);
261 * This should not be needed as we detach when reseting
262 * the state but be conservative here since the
263 * authenticator may do things like spawn kernel threads.
265 if (vap->iv_auth->ia_detach != NULL)
266 vap->iv_auth->ia_detach(vap);
268 * Detach any ACL'ator.
270 if (vap->iv_acl != NULL)
271 vap->iv_acl->iac_detach(vap);
273 FREEAPPIE(vap->iv_appie_beacon);
274 FREEAPPIE(vap->iv_appie_probereq);
275 FREEAPPIE(vap->iv_appie_proberesp);
276 FREEAPPIE(vap->iv_appie_assocreq);
277 FREEAPPIE(vap->iv_appie_assocresp);
278 FREEAPPIE(vap->iv_appie_wpa);
283 * Simple-minded authenticator module support.
286 #define IEEE80211_AUTH_MAX (IEEE80211_AUTH_WPA+1)
287 /* XXX well-known names */
288 static const char *auth_modnames[IEEE80211_AUTH_MAX] = {
289 "wlan_internal", /* IEEE80211_AUTH_NONE */
290 "wlan_internal", /* IEEE80211_AUTH_OPEN */
291 "wlan_internal", /* IEEE80211_AUTH_SHARED */
292 "wlan_xauth", /* IEEE80211_AUTH_8021X */
293 "wlan_internal", /* IEEE80211_AUTH_AUTO */
294 "wlan_xauth", /* IEEE80211_AUTH_WPA */
296 static const struct ieee80211_authenticator *authenticators[IEEE80211_AUTH_MAX];
298 static const struct ieee80211_authenticator auth_internal = {
299 .ia_name = "wlan_internal",
302 .ia_node_join = NULL,
303 .ia_node_leave = NULL,
307 * Setup internal authenticators once; they are never unregistered.
310 ieee80211_auth_setup(void)
312 ieee80211_authenticator_register(IEEE80211_AUTH_OPEN, &auth_internal);
313 ieee80211_authenticator_register(IEEE80211_AUTH_SHARED, &auth_internal);
314 ieee80211_authenticator_register(IEEE80211_AUTH_AUTO, &auth_internal);
316 SYSINIT(wlan_auth, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_auth_setup, NULL);
318 const struct ieee80211_authenticator *
319 ieee80211_authenticator_get(int auth)
321 if (auth >= IEEE80211_AUTH_MAX)
323 if (authenticators[auth] == NULL)
324 ieee80211_load_module(auth_modnames[auth]);
325 return authenticators[auth];
329 ieee80211_authenticator_register(int type,
330 const struct ieee80211_authenticator *auth)
332 if (type >= IEEE80211_AUTH_MAX)
334 authenticators[type] = auth;
338 ieee80211_authenticator_unregister(int type)
341 if (type >= IEEE80211_AUTH_MAX)
343 authenticators[type] = NULL;
347 * Very simple-minded ACL module support.
349 /* XXX just one for now */
350 static const struct ieee80211_aclator *acl = NULL;
353 ieee80211_aclator_register(const struct ieee80211_aclator *iac)
355 printf("wlan: %s acl policy registered\n", iac->iac_name);
360 ieee80211_aclator_unregister(const struct ieee80211_aclator *iac)
364 printf("wlan: %s acl policy unregistered\n", iac->iac_name);
367 const struct ieee80211_aclator *
368 ieee80211_aclator_get(const char *name)
371 ieee80211_load_module("wlan_acl");
372 return acl != NULL && strcmp(acl->iac_name, name) == 0 ? acl : NULL;
376 ieee80211_print_essid(const uint8_t *essid, int len)
381 if (len > IEEE80211_NWID_LEN)
382 len = IEEE80211_NWID_LEN;
383 /* determine printable or not */
384 for (i = 0, p = essid; i < len; i++, p++) {
385 if (*p < ' ' || *p > 0x7e)
390 for (i = 0, p = essid; i < len; i++, p++)
395 for (i = 0, p = essid; i < len; i++, p++)
401 ieee80211_dump_pkt(struct ieee80211com *ic,
402 const uint8_t *buf, int len, int rate, int rssi)
404 const struct ieee80211_frame *wh;
407 wh = (const struct ieee80211_frame *)buf;
408 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
409 case IEEE80211_FC1_DIR_NODS:
410 printf("NODS %s", ether_sprintf(wh->i_addr2));
411 printf("->%s", ether_sprintf(wh->i_addr1));
412 printf("(%s)", ether_sprintf(wh->i_addr3));
414 case IEEE80211_FC1_DIR_TODS:
415 printf("TODS %s", ether_sprintf(wh->i_addr2));
416 printf("->%s", ether_sprintf(wh->i_addr3));
417 printf("(%s)", ether_sprintf(wh->i_addr1));
419 case IEEE80211_FC1_DIR_FROMDS:
420 printf("FRDS %s", ether_sprintf(wh->i_addr3));
421 printf("->%s", ether_sprintf(wh->i_addr1));
422 printf("(%s)", ether_sprintf(wh->i_addr2));
424 case IEEE80211_FC1_DIR_DSTODS:
425 printf("DSDS %s", ether_sprintf((const uint8_t *)&wh[1]));
426 printf("->%s", ether_sprintf(wh->i_addr3));
427 printf("(%s", ether_sprintf(wh->i_addr2));
428 printf("->%s)", ether_sprintf(wh->i_addr1));
431 switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
432 case IEEE80211_FC0_TYPE_DATA:
435 case IEEE80211_FC0_TYPE_MGT:
436 printf(" %s", ieee80211_mgt_subtype_name[
437 (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK)
438 >> IEEE80211_FC0_SUBTYPE_SHIFT]);
441 printf(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
444 if (IEEE80211_QOS_HAS_SEQ(wh)) {
445 const struct ieee80211_qosframe *qwh =
446 (const struct ieee80211_qosframe *)buf;
447 printf(" QoS [TID %u%s]", qwh->i_qos[0] & IEEE80211_QOS_TID,
448 qwh->i_qos[0] & IEEE80211_QOS_ACKPOLICY ? " ACM" : "");
450 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
453 off = ieee80211_anyhdrspace(ic, wh);
454 printf(" WEP [IV %.02x %.02x %.02x",
455 buf[off+0], buf[off+1], buf[off+2]);
456 if (buf[off+IEEE80211_WEP_IVLEN] & IEEE80211_WEP_EXTIV)
457 printf(" %.02x %.02x %.02x",
458 buf[off+4], buf[off+5], buf[off+6]);
459 printf(" KID %u]", buf[off+IEEE80211_WEP_IVLEN] >> 6);
462 printf(" %dM", rate / 2);
464 printf(" +%d", rssi);
467 for (i = 0; i < len; i++) {
470 printf("%02x", buf[i]);
477 findrix(const struct ieee80211_rateset *rs, int r)
481 for (i = 0; i < rs->rs_nrates; i++)
482 if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == r)
488 ieee80211_fix_rate(struct ieee80211_node *ni,
489 struct ieee80211_rateset *nrs, int flags)
491 #define RV(v) ((v) & IEEE80211_RATE_VAL)
492 struct ieee80211vap *vap = ni->ni_vap;
493 struct ieee80211com *ic = ni->ni_ic;
494 int i, j, rix, error;
495 int okrate, badrate, fixedrate, ucastrate;
496 const struct ieee80211_rateset *srs;
500 okrate = badrate = 0;
501 ucastrate = vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)].ucastrate;
502 if (ucastrate != IEEE80211_FIXED_RATE_NONE) {
504 * Workaround awkwardness with fixed rate. We are called
505 * to check both the legacy rate set and the HT rate set
506 * but we must apply any legacy fixed rate check only to the
507 * legacy rate set and vice versa. We cannot tell what type
508 * of rate set we've been given (legacy or HT) but we can
509 * distinguish the fixed rate type (MCS have 0x80 set).
510 * So to deal with this the caller communicates whether to
511 * check MCS or legacy rate using the flags and we use the
512 * type of any fixed rate to avoid applying an MCS to a
513 * legacy rate and vice versa.
515 if (ucastrate & 0x80) {
516 if (flags & IEEE80211_F_DOFRATE)
517 flags &= ~IEEE80211_F_DOFRATE;
518 } else if ((ucastrate & 0x80) == 0) {
519 if (flags & IEEE80211_F_DOFMCS)
520 flags &= ~IEEE80211_F_DOFMCS;
522 /* NB: required to make MCS match below work */
523 ucastrate &= IEEE80211_RATE_VAL;
525 fixedrate = IEEE80211_FIXED_RATE_NONE;
527 * XXX we are called to process both MCS and legacy rates;
528 * we must use the appropriate basic rate set or chaos will
529 * ensue; for now callers that want MCS must supply
530 * IEEE80211_F_DOBRS; at some point we'll need to split this
531 * function so there are two variants, one for MCS and one
534 if (flags & IEEE80211_F_DOBRS)
535 srs = (const struct ieee80211_rateset *)
536 ieee80211_get_suphtrates(ic, ni->ni_chan);
538 srs = ieee80211_get_suprates(ic, ni->ni_chan);
539 for (i = 0; i < nrs->rs_nrates; ) {
540 if (flags & IEEE80211_F_DOSORT) {
544 for (j = i + 1; j < nrs->rs_nrates; j++) {
545 if (RV(nrs->rs_rates[i]) > RV(nrs->rs_rates[j])) {
546 r = nrs->rs_rates[i];
547 nrs->rs_rates[i] = nrs->rs_rates[j];
548 nrs->rs_rates[j] = r;
552 r = nrs->rs_rates[i] & IEEE80211_RATE_VAL;
555 * Check for fixed rate.
560 * Check against supported rates.
562 rix = findrix(srs, r);
563 if (flags & IEEE80211_F_DONEGO) {
566 * A rate in the node's rate set is not
567 * supported. If this is a basic rate and we
568 * are operating as a STA then this is an error.
569 * Otherwise we just discard/ignore the rate.
571 if ((flags & IEEE80211_F_JOIN) &&
572 (nrs->rs_rates[i] & IEEE80211_RATE_BASIC))
574 } else if ((flags & IEEE80211_F_JOIN) == 0) {
576 * Overwrite with the supported rate
577 * value so any basic rate bit is set.
579 nrs->rs_rates[i] = srs->rs_rates[rix];
582 if ((flags & IEEE80211_F_DODEL) && rix < 0) {
584 * Delete unacceptable rates.
587 for (j = i; j < nrs->rs_nrates; j++)
588 nrs->rs_rates[j] = nrs->rs_rates[j + 1];
589 nrs->rs_rates[j] = 0;
593 okrate = nrs->rs_rates[i];
596 if (okrate == 0 || error != 0 ||
597 ((flags & (IEEE80211_F_DOFRATE|IEEE80211_F_DOFMCS)) &&
598 fixedrate != ucastrate)) {
599 IEEE80211_NOTE(vap, IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni,
600 "%s: flags 0x%x okrate %d error %d fixedrate 0x%x "
601 "ucastrate %x\n", __func__, fixedrate, ucastrate, flags);
602 return badrate | IEEE80211_RATE_BASIC;
609 * Reset 11g-related state.
612 ieee80211_reset_erp(struct ieee80211com *ic)
614 ic->ic_flags &= ~IEEE80211_F_USEPROT;
615 ic->ic_nonerpsta = 0;
616 ic->ic_longslotsta = 0;
618 * Short slot time is enabled only when operating in 11g
619 * and not in an IBSS. We must also honor whether or not
620 * the driver is capable of doing it.
622 ieee80211_set_shortslottime(ic,
623 IEEE80211_IS_CHAN_A(ic->ic_curchan) ||
624 IEEE80211_IS_CHAN_HT(ic->ic_curchan) ||
625 (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
626 ic->ic_opmode == IEEE80211_M_HOSTAP &&
627 (ic->ic_caps & IEEE80211_C_SHSLOT)));
629 * Set short preamble and ERP barker-preamble flags.
631 if (IEEE80211_IS_CHAN_A(ic->ic_curchan) ||
632 (ic->ic_caps & IEEE80211_C_SHPREAMBLE)) {
633 ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
634 ic->ic_flags &= ~IEEE80211_F_USEBARKER;
636 ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
637 ic->ic_flags |= IEEE80211_F_USEBARKER;
642 * Set the short slot time state and notify the driver.
645 ieee80211_set_shortslottime(struct ieee80211com *ic, int onoff)
648 ic->ic_flags |= IEEE80211_F_SHSLOT;
650 ic->ic_flags &= ~IEEE80211_F_SHSLOT;
652 if (ic->ic_updateslot != NULL)
653 ic->ic_updateslot(ic->ic_ifp);
657 * Check if the specified rate set supports ERP.
658 * NB: the rate set is assumed to be sorted.
661 ieee80211_iserp_rateset(const struct ieee80211_rateset *rs)
663 static const int rates[] = { 2, 4, 11, 22, 12, 24, 48 };
666 if (rs->rs_nrates < nitems(rates))
668 for (i = 0; i < nitems(rates); i++) {
669 for (j = 0; j < rs->rs_nrates; j++) {
670 int r = rs->rs_rates[j] & IEEE80211_RATE_VAL;
684 * Mark the basic rates for the rate table based on the
685 * operating mode. For real 11g we mark all the 11b rates
686 * and 6, 12, and 24 OFDM. For 11b compatibility we mark only
687 * 11b rates. There's also a pseudo 11a-mode used to mark only
688 * the basic OFDM rates.
691 setbasicrates(struct ieee80211_rateset *rs,
692 enum ieee80211_phymode mode, int add)
694 static const struct ieee80211_rateset basic[IEEE80211_MODE_MAX] = {
695 [IEEE80211_MODE_11A] = { 3, { 12, 24, 48 } },
696 [IEEE80211_MODE_11B] = { 2, { 2, 4 } },
698 [IEEE80211_MODE_11G] = { 4, { 2, 4, 11, 22 } },
699 [IEEE80211_MODE_TURBO_A] = { 3, { 12, 24, 48 } },
700 [IEEE80211_MODE_TURBO_G] = { 4, { 2, 4, 11, 22 } },
701 [IEEE80211_MODE_STURBO_A] = { 3, { 12, 24, 48 } },
702 [IEEE80211_MODE_HALF] = { 3, { 6, 12, 24 } },
703 [IEEE80211_MODE_QUARTER] = { 3, { 3, 6, 12 } },
704 [IEEE80211_MODE_11NA] = { 3, { 12, 24, 48 } },
706 [IEEE80211_MODE_11NG] = { 4, { 2, 4, 11, 22 } },
710 for (i = 0; i < rs->rs_nrates; i++) {
712 rs->rs_rates[i] &= IEEE80211_RATE_VAL;
713 for (j = 0; j < basic[mode].rs_nrates; j++)
714 if (basic[mode].rs_rates[j] == rs->rs_rates[i]) {
715 rs->rs_rates[i] |= IEEE80211_RATE_BASIC;
722 * Set the basic rates in a rate set.
725 ieee80211_setbasicrates(struct ieee80211_rateset *rs,
726 enum ieee80211_phymode mode)
728 setbasicrates(rs, mode, 0);
732 * Add basic rates to a rate set.
735 ieee80211_addbasicrates(struct ieee80211_rateset *rs,
736 enum ieee80211_phymode mode)
738 setbasicrates(rs, mode, 1);
742 * WME protocol support.
744 * The default 11a/b/g/n parameters come from the WiFi Alliance WMM
745 * System Interopability Test Plan (v1.4, Appendix F) and the 802.11n
746 * Draft 2.0 Test Plan (Appendix D).
748 * Static/Dynamic Turbo mode settings come from Atheros.
750 typedef struct phyParamType {
758 static const struct phyParamType phyParamForAC_BE[IEEE80211_MODE_MAX] = {
759 [IEEE80211_MODE_AUTO] = { 3, 4, 6, 0, 0 },
760 [IEEE80211_MODE_11A] = { 3, 4, 6, 0, 0 },
761 [IEEE80211_MODE_11B] = { 3, 4, 6, 0, 0 },
762 [IEEE80211_MODE_11G] = { 3, 4, 6, 0, 0 },
763 [IEEE80211_MODE_FH] = { 3, 4, 6, 0, 0 },
764 [IEEE80211_MODE_TURBO_A]= { 2, 3, 5, 0, 0 },
765 [IEEE80211_MODE_TURBO_G]= { 2, 3, 5, 0, 0 },
766 [IEEE80211_MODE_STURBO_A]={ 2, 3, 5, 0, 0 },
767 [IEEE80211_MODE_HALF] = { 3, 4, 6, 0, 0 },
768 [IEEE80211_MODE_QUARTER]= { 3, 4, 6, 0, 0 },
769 [IEEE80211_MODE_11NA] = { 3, 4, 6, 0, 0 },
770 [IEEE80211_MODE_11NG] = { 3, 4, 6, 0, 0 },
772 static const struct phyParamType phyParamForAC_BK[IEEE80211_MODE_MAX] = {
773 [IEEE80211_MODE_AUTO] = { 7, 4, 10, 0, 0 },
774 [IEEE80211_MODE_11A] = { 7, 4, 10, 0, 0 },
775 [IEEE80211_MODE_11B] = { 7, 4, 10, 0, 0 },
776 [IEEE80211_MODE_11G] = { 7, 4, 10, 0, 0 },
777 [IEEE80211_MODE_FH] = { 7, 4, 10, 0, 0 },
778 [IEEE80211_MODE_TURBO_A]= { 7, 3, 10, 0, 0 },
779 [IEEE80211_MODE_TURBO_G]= { 7, 3, 10, 0, 0 },
780 [IEEE80211_MODE_STURBO_A]={ 7, 3, 10, 0, 0 },
781 [IEEE80211_MODE_HALF] = { 7, 4, 10, 0, 0 },
782 [IEEE80211_MODE_QUARTER]= { 7, 4, 10, 0, 0 },
783 [IEEE80211_MODE_11NA] = { 7, 4, 10, 0, 0 },
784 [IEEE80211_MODE_11NG] = { 7, 4, 10, 0, 0 },
786 static const struct phyParamType phyParamForAC_VI[IEEE80211_MODE_MAX] = {
787 [IEEE80211_MODE_AUTO] = { 1, 3, 4, 94, 0 },
788 [IEEE80211_MODE_11A] = { 1, 3, 4, 94, 0 },
789 [IEEE80211_MODE_11B] = { 1, 3, 4, 188, 0 },
790 [IEEE80211_MODE_11G] = { 1, 3, 4, 94, 0 },
791 [IEEE80211_MODE_FH] = { 1, 3, 4, 188, 0 },
792 [IEEE80211_MODE_TURBO_A]= { 1, 2, 3, 94, 0 },
793 [IEEE80211_MODE_TURBO_G]= { 1, 2, 3, 94, 0 },
794 [IEEE80211_MODE_STURBO_A]={ 1, 2, 3, 94, 0 },
795 [IEEE80211_MODE_HALF] = { 1, 3, 4, 94, 0 },
796 [IEEE80211_MODE_QUARTER]= { 1, 3, 4, 94, 0 },
797 [IEEE80211_MODE_11NA] = { 1, 3, 4, 94, 0 },
798 [IEEE80211_MODE_11NG] = { 1, 3, 4, 94, 0 },
800 static const struct phyParamType phyParamForAC_VO[IEEE80211_MODE_MAX] = {
801 [IEEE80211_MODE_AUTO] = { 1, 2, 3, 47, 0 },
802 [IEEE80211_MODE_11A] = { 1, 2, 3, 47, 0 },
803 [IEEE80211_MODE_11B] = { 1, 2, 3, 102, 0 },
804 [IEEE80211_MODE_11G] = { 1, 2, 3, 47, 0 },
805 [IEEE80211_MODE_FH] = { 1, 2, 3, 102, 0 },
806 [IEEE80211_MODE_TURBO_A]= { 1, 2, 2, 47, 0 },
807 [IEEE80211_MODE_TURBO_G]= { 1, 2, 2, 47, 0 },
808 [IEEE80211_MODE_STURBO_A]={ 1, 2, 2, 47, 0 },
809 [IEEE80211_MODE_HALF] = { 1, 2, 3, 47, 0 },
810 [IEEE80211_MODE_QUARTER]= { 1, 2, 3, 47, 0 },
811 [IEEE80211_MODE_11NA] = { 1, 2, 3, 47, 0 },
812 [IEEE80211_MODE_11NG] = { 1, 2, 3, 47, 0 },
815 static const struct phyParamType bssPhyParamForAC_BE[IEEE80211_MODE_MAX] = {
816 [IEEE80211_MODE_AUTO] = { 3, 4, 10, 0, 0 },
817 [IEEE80211_MODE_11A] = { 3, 4, 10, 0, 0 },
818 [IEEE80211_MODE_11B] = { 3, 4, 10, 0, 0 },
819 [IEEE80211_MODE_11G] = { 3, 4, 10, 0, 0 },
820 [IEEE80211_MODE_FH] = { 3, 4, 10, 0, 0 },
821 [IEEE80211_MODE_TURBO_A]= { 2, 3, 10, 0, 0 },
822 [IEEE80211_MODE_TURBO_G]= { 2, 3, 10, 0, 0 },
823 [IEEE80211_MODE_STURBO_A]={ 2, 3, 10, 0, 0 },
824 [IEEE80211_MODE_HALF] = { 3, 4, 10, 0, 0 },
825 [IEEE80211_MODE_QUARTER]= { 3, 4, 10, 0, 0 },
826 [IEEE80211_MODE_11NA] = { 3, 4, 10, 0, 0 },
827 [IEEE80211_MODE_11NG] = { 3, 4, 10, 0, 0 },
829 static const struct phyParamType bssPhyParamForAC_VI[IEEE80211_MODE_MAX] = {
830 [IEEE80211_MODE_AUTO] = { 2, 3, 4, 94, 0 },
831 [IEEE80211_MODE_11A] = { 2, 3, 4, 94, 0 },
832 [IEEE80211_MODE_11B] = { 2, 3, 4, 188, 0 },
833 [IEEE80211_MODE_11G] = { 2, 3, 4, 94, 0 },
834 [IEEE80211_MODE_FH] = { 2, 3, 4, 188, 0 },
835 [IEEE80211_MODE_TURBO_A]= { 2, 2, 3, 94, 0 },
836 [IEEE80211_MODE_TURBO_G]= { 2, 2, 3, 94, 0 },
837 [IEEE80211_MODE_STURBO_A]={ 2, 2, 3, 94, 0 },
838 [IEEE80211_MODE_HALF] = { 2, 3, 4, 94, 0 },
839 [IEEE80211_MODE_QUARTER]= { 2, 3, 4, 94, 0 },
840 [IEEE80211_MODE_11NA] = { 2, 3, 4, 94, 0 },
841 [IEEE80211_MODE_11NG] = { 2, 3, 4, 94, 0 },
843 static const struct phyParamType bssPhyParamForAC_VO[IEEE80211_MODE_MAX] = {
844 [IEEE80211_MODE_AUTO] = { 2, 2, 3, 47, 0 },
845 [IEEE80211_MODE_11A] = { 2, 2, 3, 47, 0 },
846 [IEEE80211_MODE_11B] = { 2, 2, 3, 102, 0 },
847 [IEEE80211_MODE_11G] = { 2, 2, 3, 47, 0 },
848 [IEEE80211_MODE_FH] = { 2, 2, 3, 102, 0 },
849 [IEEE80211_MODE_TURBO_A]= { 1, 2, 2, 47, 0 },
850 [IEEE80211_MODE_TURBO_G]= { 1, 2, 2, 47, 0 },
851 [IEEE80211_MODE_STURBO_A]={ 1, 2, 2, 47, 0 },
852 [IEEE80211_MODE_HALF] = { 2, 2, 3, 47, 0 },
853 [IEEE80211_MODE_QUARTER]= { 2, 2, 3, 47, 0 },
854 [IEEE80211_MODE_11NA] = { 2, 2, 3, 47, 0 },
855 [IEEE80211_MODE_11NG] = { 2, 2, 3, 47, 0 },
859 _setifsparams(struct wmeParams *wmep, const paramType *phy)
861 wmep->wmep_aifsn = phy->aifsn;
862 wmep->wmep_logcwmin = phy->logcwmin;
863 wmep->wmep_logcwmax = phy->logcwmax;
864 wmep->wmep_txopLimit = phy->txopLimit;
868 setwmeparams(struct ieee80211vap *vap, const char *type, int ac,
869 struct wmeParams *wmep, const paramType *phy)
871 wmep->wmep_acm = phy->acm;
872 _setifsparams(wmep, phy);
874 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
875 "set %s (%s) [acm %u aifsn %u logcwmin %u logcwmax %u txop %u]\n",
876 ieee80211_wme_acnames[ac], type,
877 wmep->wmep_acm, wmep->wmep_aifsn, wmep->wmep_logcwmin,
878 wmep->wmep_logcwmax, wmep->wmep_txopLimit);
882 ieee80211_wme_initparams_locked(struct ieee80211vap *vap)
884 struct ieee80211com *ic = vap->iv_ic;
885 struct ieee80211_wme_state *wme = &ic->ic_wme;
886 const paramType *pPhyParam, *pBssPhyParam;
887 struct wmeParams *wmep;
888 enum ieee80211_phymode mode;
891 IEEE80211_LOCK_ASSERT(ic);
893 if ((ic->ic_caps & IEEE80211_C_WME) == 0 || ic->ic_nrunning > 1)
897 * Clear the wme cap_info field so a qoscount from a previous
898 * vap doesn't confuse later code which only parses the beacon
899 * field and updates hardware when said field changes.
900 * Otherwise the hardware is programmed with defaults, not what
901 * the beacon actually announces.
903 wme->wme_wmeChanParams.cap_info = 0;
906 * Select mode; we can be called early in which case we
907 * always use auto mode. We know we'll be called when
908 * entering the RUN state with bsschan setup properly
909 * so state will eventually get set correctly
911 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
912 mode = ieee80211_chan2mode(ic->ic_bsschan);
914 mode = IEEE80211_MODE_AUTO;
915 for (i = 0; i < WME_NUM_AC; i++) {
918 pPhyParam = &phyParamForAC_BK[mode];
919 pBssPhyParam = &phyParamForAC_BK[mode];
922 pPhyParam = &phyParamForAC_VI[mode];
923 pBssPhyParam = &bssPhyParamForAC_VI[mode];
926 pPhyParam = &phyParamForAC_VO[mode];
927 pBssPhyParam = &bssPhyParamForAC_VO[mode];
931 pPhyParam = &phyParamForAC_BE[mode];
932 pBssPhyParam = &bssPhyParamForAC_BE[mode];
935 wmep = &wme->wme_wmeChanParams.cap_wmeParams[i];
936 if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
937 setwmeparams(vap, "chan", i, wmep, pPhyParam);
939 setwmeparams(vap, "chan", i, wmep, pBssPhyParam);
941 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[i];
942 setwmeparams(vap, "bss ", i, wmep, pBssPhyParam);
944 /* NB: check ic_bss to avoid NULL deref on initial attach */
945 if (vap->iv_bss != NULL) {
947 * Calculate agressive mode switching threshold based
948 * on beacon interval. This doesn't need locking since
949 * we're only called before entering the RUN state at
950 * which point we start sending beacon frames.
952 wme->wme_hipri_switch_thresh =
953 (HIGH_PRI_SWITCH_THRESH * vap->iv_bss->ni_intval) / 100;
954 wme->wme_flags &= ~WME_F_AGGRMODE;
955 ieee80211_wme_updateparams(vap);
960 ieee80211_wme_initparams(struct ieee80211vap *vap)
962 struct ieee80211com *ic = vap->iv_ic;
965 ieee80211_wme_initparams_locked(vap);
966 IEEE80211_UNLOCK(ic);
970 * Update WME parameters for ourself and the BSS.
973 ieee80211_wme_updateparams_locked(struct ieee80211vap *vap)
975 static const paramType aggrParam[IEEE80211_MODE_MAX] = {
976 [IEEE80211_MODE_AUTO] = { 2, 4, 10, 64, 0 },
977 [IEEE80211_MODE_11A] = { 2, 4, 10, 64, 0 },
978 [IEEE80211_MODE_11B] = { 2, 5, 10, 64, 0 },
979 [IEEE80211_MODE_11G] = { 2, 4, 10, 64, 0 },
980 [IEEE80211_MODE_FH] = { 2, 5, 10, 64, 0 },
981 [IEEE80211_MODE_TURBO_A] = { 1, 3, 10, 64, 0 },
982 [IEEE80211_MODE_TURBO_G] = { 1, 3, 10, 64, 0 },
983 [IEEE80211_MODE_STURBO_A] = { 1, 3, 10, 64, 0 },
984 [IEEE80211_MODE_HALF] = { 2, 4, 10, 64, 0 },
985 [IEEE80211_MODE_QUARTER] = { 2, 4, 10, 64, 0 },
986 [IEEE80211_MODE_11NA] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/
987 [IEEE80211_MODE_11NG] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/
989 struct ieee80211com *ic = vap->iv_ic;
990 struct ieee80211_wme_state *wme = &ic->ic_wme;
991 const struct wmeParams *wmep;
992 struct wmeParams *chanp, *bssp;
993 enum ieee80211_phymode mode;
998 * Set up the channel access parameters for the physical
999 * device. First populate the configured settings.
1001 for (i = 0; i < WME_NUM_AC; i++) {
1002 chanp = &wme->wme_chanParams.cap_wmeParams[i];
1003 wmep = &wme->wme_wmeChanParams.cap_wmeParams[i];
1004 chanp->wmep_aifsn = wmep->wmep_aifsn;
1005 chanp->wmep_logcwmin = wmep->wmep_logcwmin;
1006 chanp->wmep_logcwmax = wmep->wmep_logcwmax;
1007 chanp->wmep_txopLimit = wmep->wmep_txopLimit;
1009 chanp = &wme->wme_bssChanParams.cap_wmeParams[i];
1010 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[i];
1011 chanp->wmep_aifsn = wmep->wmep_aifsn;
1012 chanp->wmep_logcwmin = wmep->wmep_logcwmin;
1013 chanp->wmep_logcwmax = wmep->wmep_logcwmax;
1014 chanp->wmep_txopLimit = wmep->wmep_txopLimit;
1018 * Select mode; we can be called early in which case we
1019 * always use auto mode. We know we'll be called when
1020 * entering the RUN state with bsschan setup properly
1021 * so state will eventually get set correctly
1023 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
1024 mode = ieee80211_chan2mode(ic->ic_bsschan);
1026 mode = IEEE80211_MODE_AUTO;
1029 * This implements agressive mode as found in certain
1030 * vendors' AP's. When there is significant high
1031 * priority (VI/VO) traffic in the BSS throttle back BE
1032 * traffic by using conservative parameters. Otherwise
1033 * BE uses agressive params to optimize performance of
1034 * legacy/non-QoS traffic.
1037 /* Hostap? Only if aggressive mode is enabled */
1038 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
1039 (wme->wme_flags & WME_F_AGGRMODE) != 0)
1043 * Station? Only if we're in a non-QoS BSS.
1045 else if ((vap->iv_opmode == IEEE80211_M_STA &&
1046 (vap->iv_bss->ni_flags & IEEE80211_NODE_QOS) == 0))
1050 * IBSS? Only if we we have WME enabled.
1052 else if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
1053 (vap->iv_flags & IEEE80211_F_WME))
1057 * If WME is disabled on this VAP, default to aggressive mode
1058 * regardless of the configuration.
1060 if ((vap->iv_flags & IEEE80211_F_WME) == 0)
1068 chanp = &wme->wme_chanParams.cap_wmeParams[WME_AC_BE];
1069 bssp = &wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE];
1071 chanp->wmep_aifsn = bssp->wmep_aifsn = aggrParam[mode].aifsn;
1072 chanp->wmep_logcwmin = bssp->wmep_logcwmin =
1073 aggrParam[mode].logcwmin;
1074 chanp->wmep_logcwmax = bssp->wmep_logcwmax =
1075 aggrParam[mode].logcwmax;
1076 chanp->wmep_txopLimit = bssp->wmep_txopLimit =
1077 (vap->iv_flags & IEEE80211_F_BURST) ?
1078 aggrParam[mode].txopLimit : 0;
1079 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
1080 "update %s (chan+bss) [acm %u aifsn %u logcwmin %u "
1081 "logcwmax %u txop %u]\n", ieee80211_wme_acnames[WME_AC_BE],
1082 chanp->wmep_acm, chanp->wmep_aifsn, chanp->wmep_logcwmin,
1083 chanp->wmep_logcwmax, chanp->wmep_txopLimit);
1088 * Change the contention window based on the number of associated
1089 * stations. If the number of associated stations is 1 and
1090 * aggressive mode is enabled, lower the contention window even
1093 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
1094 ic->ic_sta_assoc < 2 && (wme->wme_flags & WME_F_AGGRMODE) != 0) {
1095 static const uint8_t logCwMin[IEEE80211_MODE_MAX] = {
1096 [IEEE80211_MODE_AUTO] = 3,
1097 [IEEE80211_MODE_11A] = 3,
1098 [IEEE80211_MODE_11B] = 4,
1099 [IEEE80211_MODE_11G] = 3,
1100 [IEEE80211_MODE_FH] = 4,
1101 [IEEE80211_MODE_TURBO_A] = 3,
1102 [IEEE80211_MODE_TURBO_G] = 3,
1103 [IEEE80211_MODE_STURBO_A] = 3,
1104 [IEEE80211_MODE_HALF] = 3,
1105 [IEEE80211_MODE_QUARTER] = 3,
1106 [IEEE80211_MODE_11NA] = 3,
1107 [IEEE80211_MODE_11NG] = 3,
1109 chanp = &wme->wme_chanParams.cap_wmeParams[WME_AC_BE];
1110 bssp = &wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE];
1112 chanp->wmep_logcwmin = bssp->wmep_logcwmin = logCwMin[mode];
1113 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
1114 "update %s (chan+bss) logcwmin %u\n",
1115 ieee80211_wme_acnames[WME_AC_BE], chanp->wmep_logcwmin);
1119 * Arrange for the beacon update.
1121 * XXX what about MBSS, WDS?
1123 if (vap->iv_opmode == IEEE80211_M_HOSTAP
1124 || vap->iv_opmode == IEEE80211_M_IBSS) {
1126 * Arrange for a beacon update and bump the parameter
1127 * set number so associated stations load the new values.
1129 wme->wme_bssChanParams.cap_info =
1130 (wme->wme_bssChanParams.cap_info+1) & WME_QOSINFO_COUNT;
1131 ieee80211_beacon_notify(vap, IEEE80211_BEACON_WME);
1134 wme->wme_update(ic);
1136 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
1137 "%s: WME params updated, cap_info 0x%x\n", __func__,
1138 vap->iv_opmode == IEEE80211_M_STA ?
1139 wme->wme_wmeChanParams.cap_info :
1140 wme->wme_bssChanParams.cap_info);
1144 ieee80211_wme_updateparams(struct ieee80211vap *vap)
1146 struct ieee80211com *ic = vap->iv_ic;
1148 if (ic->ic_caps & IEEE80211_C_WME) {
1150 ieee80211_wme_updateparams_locked(vap);
1151 IEEE80211_UNLOCK(ic);
1156 parent_updown(void *arg, int npending)
1158 struct ifnet *parent = arg;
1160 parent->if_ioctl(parent, SIOCSIFFLAGS, NULL);
1164 update_mcast(void *arg, int npending)
1166 struct ieee80211com *ic = arg;
1167 struct ifnet *parent = ic->ic_ifp;
1169 ic->ic_update_mcast(parent);
1173 update_promisc(void *arg, int npending)
1175 struct ieee80211com *ic = arg;
1176 struct ifnet *parent = ic->ic_ifp;
1178 ic->ic_update_promisc(parent);
1182 update_channel(void *arg, int npending)
1184 struct ieee80211com *ic = arg;
1186 ic->ic_set_channel(ic);
1187 ieee80211_radiotap_chan_change(ic);
1191 update_chw(void *arg, int npending)
1193 struct ieee80211com *ic = arg;
1196 * XXX should we defer the channel width _config_ update until now?
1198 ic->ic_update_chw(ic);
1202 * Block until the parent is in a known state. This is
1203 * used after any operations that dispatch a task (e.g.
1204 * to auto-configure the parent device up/down).
1207 ieee80211_waitfor_parent(struct ieee80211com *ic)
1209 taskqueue_block(ic->ic_tq);
1210 ieee80211_draintask(ic, &ic->ic_parent_task);
1211 ieee80211_draintask(ic, &ic->ic_mcast_task);
1212 ieee80211_draintask(ic, &ic->ic_promisc_task);
1213 ieee80211_draintask(ic, &ic->ic_chan_task);
1214 ieee80211_draintask(ic, &ic->ic_bmiss_task);
1215 ieee80211_draintask(ic, &ic->ic_chw_task);
1216 taskqueue_unblock(ic->ic_tq);
1220 * Start a vap running. If this is the first vap to be
1221 * set running on the underlying device then we
1222 * automatically bring the device up.
1225 ieee80211_start_locked(struct ieee80211vap *vap)
1227 struct ifnet *ifp = vap->iv_ifp;
1228 struct ieee80211com *ic = vap->iv_ic;
1229 struct ifnet *parent = ic->ic_ifp;
1231 IEEE80211_LOCK_ASSERT(ic);
1233 IEEE80211_DPRINTF(vap,
1234 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1235 "start running, %d vaps running\n", ic->ic_nrunning);
1237 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
1239 * Mark us running. Note that it's ok to do this first;
1240 * if we need to bring the parent device up we defer that
1241 * to avoid dropping the com lock. We expect the device
1242 * to respond to being marked up by calling back into us
1243 * through ieee80211_start_all at which point we'll come
1244 * back in here and complete the work.
1246 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1248 * We are not running; if this we are the first vap
1249 * to be brought up auto-up the parent if necessary.
1251 if (ic->ic_nrunning++ == 0 &&
1252 (parent->if_drv_flags & IFF_DRV_RUNNING) == 0) {
1253 IEEE80211_DPRINTF(vap,
1254 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1255 "%s: up parent %s\n", __func__, parent->if_xname);
1256 parent->if_flags |= IFF_UP;
1257 ieee80211_runtask(ic, &ic->ic_parent_task);
1262 * If the parent is up and running, then kick the
1263 * 802.11 state machine as appropriate.
1265 if ((parent->if_drv_flags & IFF_DRV_RUNNING) &&
1266 vap->iv_roaming != IEEE80211_ROAMING_MANUAL) {
1267 if (vap->iv_opmode == IEEE80211_M_STA) {
1269 /* XXX bypasses scan too easily; disable for now */
1271 * Try to be intelligent about clocking the state
1272 * machine. If we're currently in RUN state then
1273 * we should be able to apply any new state/parameters
1274 * simply by re-associating. Otherwise we need to
1275 * re-scan to select an appropriate ap.
1277 if (vap->iv_state >= IEEE80211_S_RUN)
1278 ieee80211_new_state_locked(vap,
1279 IEEE80211_S_ASSOC, 1);
1282 ieee80211_new_state_locked(vap,
1283 IEEE80211_S_SCAN, 0);
1286 * For monitor+wds mode there's nothing to do but
1287 * start running. Otherwise if this is the first
1288 * vap to be brought up, start a scan which may be
1289 * preempted if the station is locked to a particular
1292 vap->iv_flags_ext |= IEEE80211_FEXT_REINIT;
1293 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
1294 vap->iv_opmode == IEEE80211_M_WDS)
1295 ieee80211_new_state_locked(vap,
1296 IEEE80211_S_RUN, -1);
1298 ieee80211_new_state_locked(vap,
1299 IEEE80211_S_SCAN, 0);
1305 * Start a single vap.
1308 ieee80211_init(void *arg)
1310 struct ieee80211vap *vap = arg;
1312 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1315 IEEE80211_LOCK(vap->iv_ic);
1316 ieee80211_start_locked(vap);
1317 IEEE80211_UNLOCK(vap->iv_ic);
1321 * Start all runnable vap's on a device.
1324 ieee80211_start_all(struct ieee80211com *ic)
1326 struct ieee80211vap *vap;
1329 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1330 struct ifnet *ifp = vap->iv_ifp;
1331 if (IFNET_IS_UP_RUNNING(ifp)) /* NB: avoid recursion */
1332 ieee80211_start_locked(vap);
1334 IEEE80211_UNLOCK(ic);
1338 * Stop a vap. We force it down using the state machine
1339 * then mark it's ifnet not running. If this is the last
1340 * vap running on the underlying device then we close it
1341 * too to insure it will be properly initialized when the
1342 * next vap is brought up.
1345 ieee80211_stop_locked(struct ieee80211vap *vap)
1347 struct ieee80211com *ic = vap->iv_ic;
1348 struct ifnet *ifp = vap->iv_ifp;
1349 struct ifnet *parent = ic->ic_ifp;
1351 IEEE80211_LOCK_ASSERT(ic);
1353 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1354 "stop running, %d vaps running\n", ic->ic_nrunning);
1356 ieee80211_new_state_locked(vap, IEEE80211_S_INIT, -1);
1357 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1358 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; /* mark us stopped */
1359 if (--ic->ic_nrunning == 0 &&
1360 (parent->if_drv_flags & IFF_DRV_RUNNING)) {
1361 IEEE80211_DPRINTF(vap,
1362 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1363 "down parent %s\n", parent->if_xname);
1364 parent->if_flags &= ~IFF_UP;
1365 ieee80211_runtask(ic, &ic->ic_parent_task);
1371 ieee80211_stop(struct ieee80211vap *vap)
1373 struct ieee80211com *ic = vap->iv_ic;
1376 ieee80211_stop_locked(vap);
1377 IEEE80211_UNLOCK(ic);
1381 * Stop all vap's running on a device.
1384 ieee80211_stop_all(struct ieee80211com *ic)
1386 struct ieee80211vap *vap;
1389 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1390 struct ifnet *ifp = vap->iv_ifp;
1391 if (IFNET_IS_UP_RUNNING(ifp)) /* NB: avoid recursion */
1392 ieee80211_stop_locked(vap);
1394 IEEE80211_UNLOCK(ic);
1396 ieee80211_waitfor_parent(ic);
1400 * Stop all vap's running on a device and arrange
1401 * for those that were running to be resumed.
1404 ieee80211_suspend_all(struct ieee80211com *ic)
1406 struct ieee80211vap *vap;
1409 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1410 struct ifnet *ifp = vap->iv_ifp;
1411 if (IFNET_IS_UP_RUNNING(ifp)) { /* NB: avoid recursion */
1412 vap->iv_flags_ext |= IEEE80211_FEXT_RESUME;
1413 ieee80211_stop_locked(vap);
1416 IEEE80211_UNLOCK(ic);
1418 ieee80211_waitfor_parent(ic);
1422 * Start all vap's marked for resume.
1425 ieee80211_resume_all(struct ieee80211com *ic)
1427 struct ieee80211vap *vap;
1430 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1431 struct ifnet *ifp = vap->iv_ifp;
1432 if (!IFNET_IS_UP_RUNNING(ifp) &&
1433 (vap->iv_flags_ext & IEEE80211_FEXT_RESUME)) {
1434 vap->iv_flags_ext &= ~IEEE80211_FEXT_RESUME;
1435 ieee80211_start_locked(vap);
1438 IEEE80211_UNLOCK(ic);
1442 ieee80211_beacon_miss(struct ieee80211com *ic)
1445 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
1446 /* Process in a taskq, the handler may reenter the driver */
1447 ieee80211_runtask(ic, &ic->ic_bmiss_task);
1449 IEEE80211_UNLOCK(ic);
1453 beacon_miss(void *arg, int npending)
1455 struct ieee80211com *ic = arg;
1456 struct ieee80211vap *vap;
1459 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1461 * We only pass events through for sta vap's in RUN state;
1462 * may be too restrictive but for now this saves all the
1463 * handlers duplicating these checks.
1465 if (vap->iv_opmode == IEEE80211_M_STA &&
1466 vap->iv_state >= IEEE80211_S_RUN &&
1467 vap->iv_bmiss != NULL)
1470 IEEE80211_UNLOCK(ic);
1474 beacon_swmiss(void *arg, int npending)
1476 struct ieee80211vap *vap = arg;
1477 struct ieee80211com *ic = vap->iv_ic;
1480 if (vap->iv_state == IEEE80211_S_RUN) {
1481 /* XXX Call multiple times if npending > zero? */
1484 IEEE80211_UNLOCK(ic);
1488 * Software beacon miss handling. Check if any beacons
1489 * were received in the last period. If not post a
1490 * beacon miss; otherwise reset the counter.
1493 ieee80211_swbmiss(void *arg)
1495 struct ieee80211vap *vap = arg;
1496 struct ieee80211com *ic = vap->iv_ic;
1498 IEEE80211_LOCK_ASSERT(ic);
1500 /* XXX sleep state? */
1501 KASSERT(vap->iv_state == IEEE80211_S_RUN,
1502 ("wrong state %d", vap->iv_state));
1504 if (ic->ic_flags & IEEE80211_F_SCAN) {
1506 * If scanning just ignore and reset state. If we get a
1507 * bmiss after coming out of scan because we haven't had
1508 * time to receive a beacon then we should probe the AP
1509 * before posting a real bmiss (unless iv_bmiss_max has
1510 * been artifiically lowered). A cleaner solution might
1511 * be to disable the timer on scan start/end but to handle
1512 * case of multiple sta vap's we'd need to disable the
1513 * timers of all affected vap's.
1515 vap->iv_swbmiss_count = 0;
1516 } else if (vap->iv_swbmiss_count == 0) {
1517 if (vap->iv_bmiss != NULL)
1518 ieee80211_runtask(ic, &vap->iv_swbmiss_task);
1520 vap->iv_swbmiss_count = 0;
1521 callout_reset(&vap->iv_swbmiss, vap->iv_swbmiss_period,
1522 ieee80211_swbmiss, vap);
1526 * Start an 802.11h channel switch. We record the parameters,
1527 * mark the operation pending, notify each vap through the
1528 * beacon update mechanism so it can update the beacon frame
1529 * contents, and then switch vap's to CSA state to block outbound
1530 * traffic. Devices that handle CSA directly can use the state
1531 * switch to do the right thing so long as they call
1532 * ieee80211_csa_completeswitch when it's time to complete the
1533 * channel change. Devices that depend on the net80211 layer can
1534 * use ieee80211_beacon_update to handle the countdown and the
1538 ieee80211_csa_startswitch(struct ieee80211com *ic,
1539 struct ieee80211_channel *c, int mode, int count)
1541 struct ieee80211vap *vap;
1543 IEEE80211_LOCK_ASSERT(ic);
1545 ic->ic_csa_newchan = c;
1546 ic->ic_csa_mode = mode;
1547 ic->ic_csa_count = count;
1548 ic->ic_flags |= IEEE80211_F_CSAPENDING;
1549 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1550 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
1551 vap->iv_opmode == IEEE80211_M_IBSS ||
1552 vap->iv_opmode == IEEE80211_M_MBSS)
1553 ieee80211_beacon_notify(vap, IEEE80211_BEACON_CSA);
1554 /* switch to CSA state to block outbound traffic */
1555 if (vap->iv_state == IEEE80211_S_RUN)
1556 ieee80211_new_state_locked(vap, IEEE80211_S_CSA, 0);
1558 ieee80211_notify_csa(ic, c, mode, count);
1562 * Complete the channel switch by transitioning all CSA VAPs to RUN.
1563 * This is called by both the completion and cancellation functions
1564 * so each VAP is placed back in the RUN state and can thus transmit.
1567 csa_completeswitch(struct ieee80211com *ic)
1569 struct ieee80211vap *vap;
1571 ic->ic_csa_newchan = NULL;
1572 ic->ic_flags &= ~IEEE80211_F_CSAPENDING;
1574 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
1575 if (vap->iv_state == IEEE80211_S_CSA)
1576 ieee80211_new_state_locked(vap, IEEE80211_S_RUN, 0);
1580 * Complete an 802.11h channel switch started by ieee80211_csa_startswitch.
1581 * We clear state and move all vap's in CSA state to RUN state
1582 * so they can again transmit.
1584 * Although this may not be completely correct, update the BSS channel
1585 * for each VAP to the newly configured channel. The setcurchan sets
1586 * the current operating channel for the interface (so the radio does
1587 * switch over) but the VAP BSS isn't updated, leading to incorrectly
1588 * reported information via ioctl.
1591 ieee80211_csa_completeswitch(struct ieee80211com *ic)
1593 struct ieee80211vap *vap;
1595 IEEE80211_LOCK_ASSERT(ic);
1597 KASSERT(ic->ic_flags & IEEE80211_F_CSAPENDING, ("csa not pending"));
1599 ieee80211_setcurchan(ic, ic->ic_csa_newchan);
1600 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
1601 if (vap->iv_state == IEEE80211_S_CSA)
1602 vap->iv_bss->ni_chan = ic->ic_curchan;
1604 csa_completeswitch(ic);
1608 * Cancel an 802.11h channel switch started by ieee80211_csa_startswitch.
1609 * We clear state and move all vap's in CSA state to RUN state
1610 * so they can again transmit.
1613 ieee80211_csa_cancelswitch(struct ieee80211com *ic)
1615 IEEE80211_LOCK_ASSERT(ic);
1617 csa_completeswitch(ic);
1621 * Complete a DFS CAC started by ieee80211_dfs_cac_start.
1622 * We clear state and move all vap's in CAC state to RUN state.
1625 ieee80211_cac_completeswitch(struct ieee80211vap *vap0)
1627 struct ieee80211com *ic = vap0->iv_ic;
1628 struct ieee80211vap *vap;
1632 * Complete CAC state change for lead vap first; then
1633 * clock all the other vap's waiting.
1635 KASSERT(vap0->iv_state == IEEE80211_S_CAC,
1636 ("wrong state %d", vap0->iv_state));
1637 ieee80211_new_state_locked(vap0, IEEE80211_S_RUN, 0);
1639 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
1640 if (vap->iv_state == IEEE80211_S_CAC)
1641 ieee80211_new_state_locked(vap, IEEE80211_S_RUN, 0);
1642 IEEE80211_UNLOCK(ic);
1646 * Force all vap's other than the specified vap to the INIT state
1647 * and mark them as waiting for a scan to complete. These vaps
1648 * will be brought up when the scan completes and the scanning vap
1649 * reaches RUN state by wakeupwaiting.
1652 markwaiting(struct ieee80211vap *vap0)
1654 struct ieee80211com *ic = vap0->iv_ic;
1655 struct ieee80211vap *vap;
1657 IEEE80211_LOCK_ASSERT(ic);
1660 * A vap list entry can not disappear since we are running on the
1661 * taskqueue and a vap destroy will queue and drain another state
1664 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1667 if (vap->iv_state != IEEE80211_S_INIT) {
1668 /* NB: iv_newstate may drop the lock */
1669 vap->iv_newstate(vap, IEEE80211_S_INIT, 0);
1670 IEEE80211_LOCK_ASSERT(ic);
1671 vap->iv_flags_ext |= IEEE80211_FEXT_SCANWAIT;
1677 * Wakeup all vap's waiting for a scan to complete. This is the
1678 * companion to markwaiting (above) and is used to coordinate
1679 * multiple vaps scanning.
1680 * This is called from the state taskqueue.
1683 wakeupwaiting(struct ieee80211vap *vap0)
1685 struct ieee80211com *ic = vap0->iv_ic;
1686 struct ieee80211vap *vap;
1688 IEEE80211_LOCK_ASSERT(ic);
1691 * A vap list entry can not disappear since we are running on the
1692 * taskqueue and a vap destroy will queue and drain another state
1695 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1698 if (vap->iv_flags_ext & IEEE80211_FEXT_SCANWAIT) {
1699 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANWAIT;
1700 /* NB: sta's cannot go INIT->RUN */
1701 /* NB: iv_newstate may drop the lock */
1702 vap->iv_newstate(vap,
1703 vap->iv_opmode == IEEE80211_M_STA ?
1704 IEEE80211_S_SCAN : IEEE80211_S_RUN, 0);
1705 IEEE80211_LOCK_ASSERT(ic);
1711 * Handle post state change work common to all operating modes.
1714 ieee80211_newstate_cb(void *xvap, int npending)
1716 struct ieee80211vap *vap = xvap;
1717 struct ieee80211com *ic = vap->iv_ic;
1718 enum ieee80211_state nstate, ostate;
1722 nstate = vap->iv_nstate;
1723 arg = vap->iv_nstate_arg;
1725 if (vap->iv_flags_ext & IEEE80211_FEXT_REINIT) {
1727 * We have been requested to drop back to the INIT before
1728 * proceeding to the new state.
1730 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1731 "%s: %s -> %s arg %d\n", __func__,
1732 ieee80211_state_name[vap->iv_state],
1733 ieee80211_state_name[IEEE80211_S_INIT], arg);
1734 vap->iv_newstate(vap, IEEE80211_S_INIT, arg);
1735 IEEE80211_LOCK_ASSERT(ic);
1736 vap->iv_flags_ext &= ~IEEE80211_FEXT_REINIT;
1739 ostate = vap->iv_state;
1740 if (nstate == IEEE80211_S_SCAN && ostate != IEEE80211_S_INIT) {
1742 * SCAN was forced; e.g. on beacon miss. Force other running
1743 * vap's to INIT state and mark them as waiting for the scan to
1744 * complete. This insures they don't interfere with our
1745 * scanning. Since we are single threaded the vaps can not
1746 * transition again while we are executing.
1748 * XXX not always right, assumes ap follows sta
1752 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1753 "%s: %s -> %s arg %d\n", __func__,
1754 ieee80211_state_name[ostate], ieee80211_state_name[nstate], arg);
1756 rc = vap->iv_newstate(vap, nstate, arg);
1757 IEEE80211_LOCK_ASSERT(ic);
1758 vap->iv_flags_ext &= ~IEEE80211_FEXT_STATEWAIT;
1760 /* State transition failed */
1761 KASSERT(rc != EINPROGRESS, ("iv_newstate was deferred"));
1762 KASSERT(nstate != IEEE80211_S_INIT,
1763 ("INIT state change failed"));
1764 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1765 "%s: %s returned error %d\n", __func__,
1766 ieee80211_state_name[nstate], rc);
1770 /* No actual transition, skip post processing */
1771 if (ostate == nstate)
1774 if (nstate == IEEE80211_S_RUN) {
1776 * OACTIVE may be set on the vap if the upper layer
1777 * tried to transmit (e.g. IPv6 NDP) before we reach
1778 * RUN state. Clear it and restart xmit.
1780 * Note this can also happen as a result of SLEEP->RUN
1781 * (i.e. coming out of power save mode).
1783 vap->iv_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1786 * XXX TODO Kick-start a VAP queue - this should be a method!
1789 /* bring up any vaps waiting on us */
1791 } else if (nstate == IEEE80211_S_INIT) {
1793 * Flush the scan cache if we did the last scan (XXX?)
1794 * and flush any frames on send queues from this vap.
1795 * Note the mgt q is used only for legacy drivers and
1796 * will go away shortly.
1798 ieee80211_scan_flush(vap);
1801 * XXX TODO: ic/vap queue flush
1805 IEEE80211_UNLOCK(ic);
1809 * Public interface for initiating a state machine change.
1810 * This routine single-threads the request and coordinates
1811 * the scheduling of multiple vaps for the purpose of selecting
1812 * an operating channel. Specifically the following scenarios
1814 * o only one vap can be selecting a channel so on transition to
1815 * SCAN state if another vap is already scanning then
1816 * mark the caller for later processing and return without
1817 * doing anything (XXX? expectations by caller of synchronous operation)
1818 * o only one vap can be doing CAC of a channel so on transition to
1819 * CAC state if another vap is already scanning for radar then
1820 * mark the caller for later processing and return without
1821 * doing anything (XXX? expectations by caller of synchronous operation)
1822 * o if another vap is already running when a request is made
1823 * to SCAN then an operating channel has been chosen; bypass
1824 * the scan and just join the channel
1826 * Note that the state change call is done through the iv_newstate
1827 * method pointer so any driver routine gets invoked. The driver
1828 * will normally call back into operating mode-specific
1829 * ieee80211_newstate routines (below) unless it needs to completely
1830 * bypass the state machine (e.g. because the firmware has it's
1831 * own idea how things should work). Bypassing the net80211 layer
1832 * is usually a mistake and indicates lack of proper integration
1833 * with the net80211 layer.
1836 ieee80211_new_state_locked(struct ieee80211vap *vap,
1837 enum ieee80211_state nstate, int arg)
1839 struct ieee80211com *ic = vap->iv_ic;
1840 struct ieee80211vap *vp;
1841 enum ieee80211_state ostate;
1842 int nrunning, nscanning;
1844 IEEE80211_LOCK_ASSERT(ic);
1846 if (vap->iv_flags_ext & IEEE80211_FEXT_STATEWAIT) {
1847 if (vap->iv_nstate == IEEE80211_S_INIT) {
1849 * XXX The vap is being stopped, do no allow any other
1850 * state changes until this is completed.
1853 } else if (vap->iv_state != vap->iv_nstate) {
1855 /* Warn if the previous state hasn't completed. */
1856 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1857 "%s: pending %s -> %s transition lost\n", __func__,
1858 ieee80211_state_name[vap->iv_state],
1859 ieee80211_state_name[vap->iv_nstate]);
1861 /* XXX temporarily enable to identify issues */
1862 if_printf(vap->iv_ifp,
1863 "%s: pending %s -> %s transition lost\n",
1864 __func__, ieee80211_state_name[vap->iv_state],
1865 ieee80211_state_name[vap->iv_nstate]);
1870 nrunning = nscanning = 0;
1871 /* XXX can track this state instead of calculating */
1872 TAILQ_FOREACH(vp, &ic->ic_vaps, iv_next) {
1874 if (vp->iv_state >= IEEE80211_S_RUN)
1876 /* XXX doesn't handle bg scan */
1877 /* NB: CAC+AUTH+ASSOC treated like SCAN */
1878 else if (vp->iv_state > IEEE80211_S_INIT)
1882 ostate = vap->iv_state;
1883 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1884 "%s: %s -> %s (nrunning %d nscanning %d)\n", __func__,
1885 ieee80211_state_name[ostate], ieee80211_state_name[nstate],
1886 nrunning, nscanning);
1888 case IEEE80211_S_SCAN:
1889 if (ostate == IEEE80211_S_INIT) {
1891 * INIT -> SCAN happens on initial bringup.
1893 KASSERT(!(nscanning && nrunning),
1894 ("%d scanning and %d running", nscanning, nrunning));
1897 * Someone is scanning, defer our state
1898 * change until the work has completed.
1900 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1901 "%s: defer %s -> %s\n",
1902 __func__, ieee80211_state_name[ostate],
1903 ieee80211_state_name[nstate]);
1904 vap->iv_flags_ext |= IEEE80211_FEXT_SCANWAIT;
1909 * Someone is operating; just join the channel
1913 /* XXX check each opmode, adhoc? */
1914 if (vap->iv_opmode == IEEE80211_M_STA)
1915 nstate = IEEE80211_S_SCAN;
1917 nstate = IEEE80211_S_RUN;
1918 #ifdef IEEE80211_DEBUG
1919 if (nstate != IEEE80211_S_SCAN) {
1920 IEEE80211_DPRINTF(vap,
1921 IEEE80211_MSG_STATE,
1922 "%s: override, now %s -> %s\n",
1924 ieee80211_state_name[ostate],
1925 ieee80211_state_name[nstate]);
1931 case IEEE80211_S_RUN:
1932 if (vap->iv_opmode == IEEE80211_M_WDS &&
1933 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) &&
1936 * Legacy WDS with someone else scanning; don't
1937 * go online until that completes as we should
1938 * follow the other vap to the channel they choose.
1940 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1941 "%s: defer %s -> %s (legacy WDS)\n", __func__,
1942 ieee80211_state_name[ostate],
1943 ieee80211_state_name[nstate]);
1944 vap->iv_flags_ext |= IEEE80211_FEXT_SCANWAIT;
1947 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
1948 IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
1949 (vap->iv_flags_ext & IEEE80211_FEXT_DFS) &&
1950 !IEEE80211_IS_CHAN_CACDONE(ic->ic_bsschan)) {
1952 * This is a DFS channel, transition to CAC state
1953 * instead of RUN. This allows us to initiate
1954 * Channel Availability Check (CAC) as specified
1957 nstate = IEEE80211_S_CAC;
1958 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1959 "%s: override %s -> %s (DFS)\n", __func__,
1960 ieee80211_state_name[ostate],
1961 ieee80211_state_name[nstate]);
1964 case IEEE80211_S_INIT:
1965 /* cancel any scan in progress */
1966 ieee80211_cancel_scan(vap);
1967 if (ostate == IEEE80211_S_INIT ) {
1968 /* XXX don't believe this */
1969 /* INIT -> INIT. nothing to do */
1970 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANWAIT;
1976 /* defer the state change to a thread */
1977 vap->iv_nstate = nstate;
1978 vap->iv_nstate_arg = arg;
1979 vap->iv_flags_ext |= IEEE80211_FEXT_STATEWAIT;
1980 ieee80211_runtask(ic, &vap->iv_nstate_task);
1985 ieee80211_new_state(struct ieee80211vap *vap,
1986 enum ieee80211_state nstate, int arg)
1988 struct ieee80211com *ic = vap->iv_ic;
1992 rc = ieee80211_new_state_locked(vap, nstate, arg);
1993 IEEE80211_UNLOCK(ic);