update madwifi
[linux-2.6/zen-sources.git] / drivers / net / wireless / madwifi / net80211 / ieee80211_proto.c
blobe8927190ea721e41796c372dc0ac8c9c924b851d
1 /*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $Id: ieee80211_proto.c 3734 2008-06-19 16:58:07Z proski $
34 #ifndef EXPORT_SYMTAB
35 #define EXPORT_SYMTAB
36 #endif
39 * IEEE 802.11 protocol support.
41 #ifndef AUTOCONF_INCLUDED
42 #include <linux/config.h>
43 #endif
44 #include <linux/version.h>
45 #include <linux/kmod.h>
46 #include <linux/module.h>
47 #include <linux/skbuff.h>
48 #include <linux/netdevice.h>
50 #include "if_media.h"
52 #include <net80211/ieee80211_var.h>
54 /* XXX tunables */
55 #define AGGRESSIVE_MODE_SWITCH_HYSTERESIS 3 /* pkts / 100ms */
56 #define HIGH_PRI_SWITCH_THRESH 10 /* pkts / 100ms */
58 #define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2)
60 const char *ieee80211_mgt_subtype_name[] = {
61 "assoc_req", "assoc_resp", "reassoc_req", "reassoc_resp",
62 "probe_req", "probe_resp", "reserved#6", "reserved#7",
63 "beacon", "atim", "disassoc", "auth",
64 "deauth", "reserved#13", "reserved#14", "reserved#15"
66 EXPORT_SYMBOL(ieee80211_mgt_subtype_name);
67 const char *ieee80211_ctl_subtype_name[] = {
68 "reserved#0", "reserved#1", "reserved#2", "reserved#3",
69 "reserved#3", "reserved#5", "reserved#6", "reserved#7",
70 "reserved#8", "reserved#9", "ps_poll", "rts",
71 "cts", "ack", "cf_end", "cf_end_ack"
73 EXPORT_SYMBOL(ieee80211_ctl_subtype_name);
74 const char *ieee80211_state_name[IEEE80211_S_MAX] = {
75 "INIT", /* IEEE80211_S_INIT */
76 "SCAN", /* IEEE80211_S_SCAN */
77 "AUTH", /* IEEE80211_S_AUTH */
78 "ASSOC", /* IEEE80211_S_ASSOC */
79 "RUN" /* IEEE80211_S_RUN */
81 EXPORT_SYMBOL(ieee80211_state_name);
82 const char *ieee80211_wme_acnames[] = {
83 "WME_AC_BE",
84 "WME_AC_BK",
85 "WME_AC_VI",
86 "WME_AC_VO",
87 "WME_UPSD",
89 EXPORT_SYMBOL(ieee80211_wme_acnames);
91 static int ieee80211_newstate(struct ieee80211vap *, enum ieee80211_state, int);
92 static void ieee80211_tx_timeout(unsigned long);
93 #ifdef ATH_SUPERG_XR
94 static void ieee80211_start_xrvap(unsigned long);
95 #endif
96 void ieee80211_auth_setup(void);
98 void
99 ieee80211_proto_attach(struct ieee80211com *ic)
102 ic->ic_protmode = IEEE80211_PROT_CTSONLY;
103 ic->ic_rssi_ewma = 0;
105 ic->ic_wme.wme_hipri_switch_hysteresis =
106 AGGRESSIVE_MODE_SWITCH_HYSTERESIS;
108 /* initialize management frame handlers */
109 ic->ic_recv_mgmt = ieee80211_recv_mgmt;
110 ic->ic_send_mgmt = ieee80211_send_mgmt;
112 ieee80211_auth_setup();
115 void
116 ieee80211_proto_detach(struct ieee80211com *ic)
120 void
121 ieee80211_proto_vattach(struct ieee80211vap *vap)
123 #ifdef notdef
124 vap->iv_rtsthreshold = IEEE80211_RTS_DEFAULT;
125 #else
126 vap->iv_rtsthreshold = IEEE80211_RTS_MAX;
127 #endif
128 vap->iv_fragthreshold = 2346; /* XXX not used yet */
129 vap->iv_fixed_rate = IEEE80211_FIXED_RATE_NONE;
130 init_timer(&vap->iv_mgtsend);
131 init_timer(&vap->iv_xrvapstart);
132 init_timer(&vap->iv_swbmiss);
133 init_timer(&vap->iv_csa_timer);
134 vap->iv_mgtsend.function = ieee80211_tx_timeout;
135 vap->iv_mgtsend.data = (unsigned long) vap;
137 /* protocol state change handler */
138 vap->iv_newstate = ieee80211_newstate;
141 void
142 ieee80211_proto_vdetach(struct ieee80211vap *vap)
145 * This should not be needed as we detach when reseting
146 * the state but be conservative here since the
147 * authenticator may do things like spawn kernel threads.
149 if (vap->iv_auth->ia_detach)
150 vap->iv_auth->ia_detach(vap);
153 * Detach any ACL'ator.
155 if (vap->iv_acl != NULL)
156 vap->iv_acl->iac_detach(vap);
160 * Simple-minded authenticator module support.
163 #define IEEE80211_AUTH_MAX (IEEE80211_AUTH_WPA+1)
164 /* XXX well-known names */
165 static const char *auth_modnames[IEEE80211_AUTH_MAX] = {
166 "wlan_internal", /* IEEE80211_AUTH_NONE */
167 "wlan_internal", /* IEEE80211_AUTH_OPEN */
168 "wlan_internal", /* IEEE80211_AUTH_SHARED */
169 "wlan_xauth", /* IEEE80211_AUTH_8021X */
170 "wlan_internal", /* IEEE80211_AUTH_AUTO */
171 "wlan_xauth", /* IEEE80211_AUTH_WPA */
173 static const struct ieee80211_authenticator *authenticators[IEEE80211_AUTH_MAX];
175 static const struct ieee80211_authenticator auth_internal = {
176 .ia_name = "wlan_internal",
177 .ia_attach = NULL,
178 .ia_detach = NULL,
179 .ia_node_join = NULL,
180 .ia_node_leave = NULL,
184 * Setup internal authenticators once; they are never unregistered.
186 void
187 ieee80211_auth_setup(void)
189 ieee80211_authenticator_register(IEEE80211_AUTH_OPEN, &auth_internal);
190 ieee80211_authenticator_register(IEEE80211_AUTH_SHARED, &auth_internal);
191 ieee80211_authenticator_register(IEEE80211_AUTH_AUTO, &auth_internal);
194 const struct ieee80211_authenticator *
195 ieee80211_authenticator_get(int auth)
197 if (auth >= IEEE80211_AUTH_MAX)
198 return NULL;
199 if (authenticators[auth] == NULL)
200 ieee80211_load_module(auth_modnames[auth]);
201 return authenticators[auth];
204 void
205 ieee80211_authenticator_register(int type,
206 const struct ieee80211_authenticator *auth)
208 if (type >= IEEE80211_AUTH_MAX)
209 return;
210 authenticators[type] = auth;
212 EXPORT_SYMBOL(ieee80211_authenticator_register);
214 void
215 ieee80211_authenticator_unregister(int type)
217 if (type >= IEEE80211_AUTH_MAX)
218 return;
219 authenticators[type] = NULL;
221 EXPORT_SYMBOL(ieee80211_authenticator_unregister);
224 * Very simple-minded authenticator backend module support.
226 /* XXX just one for now */
227 static const struct ieee80211_authenticator_backend *backend = NULL;
229 void
230 ieee80211_authenticator_backend_register(
231 const struct ieee80211_authenticator_backend *be)
233 printk(KERN_INFO "wlan: %s backend registered\n", be->iab_name);
234 backend = be;
236 EXPORT_SYMBOL(ieee80211_authenticator_backend_register);
238 void
239 ieee80211_authenticator_backend_unregister(
240 const struct ieee80211_authenticator_backend * be)
242 if (backend == be)
243 backend = NULL;
244 printk(KERN_INFO "wlan: %s backend unregistered\n",
245 be->iab_name);
247 EXPORT_SYMBOL(ieee80211_authenticator_backend_unregister);
249 const struct ieee80211_authenticator_backend *
250 ieee80211_authenticator_backend_get(const char *name)
252 return backend && strcmp(backend->iab_name, name) == 0 ? backend : NULL;
254 EXPORT_SYMBOL(ieee80211_authenticator_backend_get);
257 * Very simple-minded ACL module support.
259 /* XXX just one for now */
260 static const struct ieee80211_aclator *acl = NULL;
262 void
263 ieee80211_aclator_register(const struct ieee80211_aclator *iac)
265 printk(KERN_INFO "wlan: %s acl policy registered\n", iac->iac_name);
266 acl = iac;
268 EXPORT_SYMBOL(ieee80211_aclator_register);
270 void
271 ieee80211_aclator_unregister(const struct ieee80211_aclator *iac)
273 if (acl == iac)
274 acl = NULL;
275 printk(KERN_INFO "wlan: %s acl policy unregistered\n", iac->iac_name);
277 EXPORT_SYMBOL(ieee80211_aclator_unregister);
279 const struct ieee80211_aclator *
280 ieee80211_aclator_get(const char *name)
282 if (acl == NULL)
283 ieee80211_load_module("wlan_acl");
284 return acl && strcmp(acl->iac_name, name) == 0 ? acl : NULL;
286 EXPORT_SYMBOL(ieee80211_aclator_get);
288 #ifdef IEEE80211_DEBUG
289 void
290 ieee80211_print_essid(const u_int8_t *essid, int len)
292 int i;
293 const u_int8_t *p;
295 if (len > IEEE80211_NWID_LEN)
296 len = IEEE80211_NWID_LEN;
297 /* determine printable or not */
298 for (i = 0, p = essid; i < len; i++, p++) {
299 if (*p < ' ' || *p > 0x7e)
300 break;
302 if (i == len) {
303 printk("\"");
304 for (i = 0, p = essid; i < len; i++, p++)
305 printk("%c", *p);
306 printk("\"");
307 } else {
308 printk("0x");
309 for (i = 0, p = essid; i < len; i++, p++)
310 printk("%02x", *p);
313 EXPORT_SYMBOL(ieee80211_print_essid);
315 void
316 ieee80211_dump_pkt(struct ieee80211com *ic, const u_int8_t *buf,
317 int len, int rate, int rssi, int tx)
319 const struct ieee80211_frame *wh;
320 int i;
322 wh = (const struct ieee80211_frame *)buf;
323 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
324 case IEEE80211_FC1_DIR_NODS:
325 printk("NoDS " MAC_FMT, MAC_ADDR(wh->i_addr2));
326 printk("->" MAC_FMT, MAC_ADDR(wh->i_addr1));
327 printk("(" MAC_FMT ")", MAC_ADDR(wh->i_addr3));
328 break;
329 case IEEE80211_FC1_DIR_TODS:
330 printk("ToDS " MAC_FMT, MAC_ADDR(wh->i_addr2));
331 printk("->" MAC_FMT, MAC_ADDR(wh->i_addr3));
332 printk("(" MAC_FMT ")", MAC_ADDR(wh->i_addr1));
333 break;
334 case IEEE80211_FC1_DIR_FROMDS:
335 printk("FrDS " MAC_FMT, MAC_ADDR(wh->i_addr3));
336 printk("->" MAC_FMT, MAC_ADDR(wh->i_addr1));
337 printk("(" MAC_FMT ")", MAC_ADDR(wh->i_addr2));
338 break;
339 case IEEE80211_FC1_DIR_DSTODS:
340 printk("InDS " MAC_FMT, MAC_ADDR((u_int8_t *)&wh[1]));
341 printk("->" MAC_FMT, MAC_ADDR(wh->i_addr3));
342 printk("(" MAC_FMT, MAC_ADDR(wh->i_addr2));
343 printk("->" MAC_FMT ")", MAC_ADDR(wh->i_addr1));
344 break;
346 switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
347 case IEEE80211_FC0_TYPE_DATA:
348 printk(" data");
349 break;
350 case IEEE80211_FC0_TYPE_MGT:
351 printk(" %s", ieee80211_mgt_subtype_name[
352 (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK)
353 >> IEEE80211_FC0_SUBTYPE_SHIFT]);
354 break;
355 default:
356 printk(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
357 break;
359 if (IEEE80211_QOS_HAS_SEQ(wh)) {
360 const struct ieee80211_qosframe *qwh =
361 (const struct ieee80211_qosframe *)buf;
362 printk(" QoS [TID %u%s]", qwh->i_qos[0] & IEEE80211_QOS_TID,
363 qwh->i_qos[0] & IEEE80211_QOS_ACKPOLICY ? " ACM" : "");
365 if (wh->i_fc[1] & IEEE80211_FC1_PROT) {
366 int off;
368 if (tx)
369 off = ieee80211_anyhdrspace(ic, wh);
370 else
371 off = ieee80211_anyhdrsize(wh);
372 printk(" Prot. [IV %.02x %.02x %.02x",
373 buf[off + 0], buf[off + 1], buf[off + 2]);
374 if (buf[off + IEEE80211_WEP_IVLEN] & IEEE80211_WEP_EXTIV)
375 printk(" %.02x %.02x %.02x",
376 buf[off + 4], buf[off + 5], buf[off + 6]);
377 printk(" KID %u]", buf[off + IEEE80211_WEP_IVLEN] >> 6);
379 if (rate >= 0)
380 printk(" %dM", rate / 2);
381 if (rssi >= 0)
382 printk(" +%d", rssi);
383 printk("\n");
384 if (len > 0) {
385 for (i = 0; i < len; i++) {
386 if ((i % 8) == 0)
387 printk(" ");
388 if ((i % 16) == 0)
389 printk("\n");
390 printk("%02x ", buf[i]);
392 printk("\n\n");
395 EXPORT_SYMBOL(ieee80211_dump_pkt);
396 #endif
399 ieee80211_fix_rate(struct ieee80211_node *ni, int flags)
401 #define RV(v) ((v) & IEEE80211_RATE_VAL)
402 struct ieee80211vap *vap = ni->ni_vap;
403 struct ieee80211com *ic = ni->ni_ic;
404 int i, j, ignore, error;
405 int okrate, badrate, fixedrate;
406 struct ieee80211_rateset *srs, *nrs;
407 u_int8_t r;
409 error = 0;
410 okrate = badrate = fixedrate = 0;
411 srs = &ic->ic_sup_rates[ieee80211_chan2mode(ni->ni_chan)];
412 nrs = &ni->ni_rates;
413 fixedrate = IEEE80211_FIXED_RATE_NONE;
414 for (i = 0; i < nrs->rs_nrates;) {
415 ignore = 0;
416 if (flags & IEEE80211_F_DOSORT) {
418 * Sort rates.
420 for (j = i + 1; j < nrs->rs_nrates; j++) {
421 if (RV(nrs->rs_rates[i]) > RV(nrs->rs_rates[j])) {
422 r = nrs->rs_rates[i];
423 nrs->rs_rates[i] = nrs->rs_rates[j];
424 nrs->rs_rates[j] = r;
428 r = nrs->rs_rates[i] & IEEE80211_RATE_VAL;
429 badrate = r;
432 * remove 0 rates
433 * they don't make sense and can lead to trouble later
435 if (r == 0) {
436 nrs->rs_nrates--;
437 for (j = i; j < nrs->rs_nrates; j++)
438 nrs->rs_rates[j] = nrs->rs_rates[j + 1];
439 nrs->rs_rates[j] = 0;
440 continue;
444 * Check for fixed rate.
446 if (r == vap->iv_fixed_rate)
447 fixedrate = r;
448 if (flags & IEEE80211_F_DONEGO) {
450 * Check against supported rates.
452 for (j = 0; j < srs->rs_nrates; j++) {
453 if (r == RV(srs->rs_rates[j])) {
455 * Overwrite with the supported rate
456 * value so any basic rate bit is set.
457 * This ensures that response we send
458 * to stations have the necessary basic
459 * rate bit set.
461 nrs->rs_rates[i] = srs->rs_rates[j];
462 break;
465 if (j == srs->rs_nrates) {
467 * A rate in the node's rate set is not
468 * supported. If this is a basic rate and we
469 * are operating as an AP then this is an error.
470 * Otherwise we just discard/ignore the rate.
471 * Note that this is important for 11b stations
472 * when they want to associate with an 11g AP.
474 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
475 (nrs->rs_rates[i] & IEEE80211_RATE_BASIC))
476 error++;
477 ignore++;
480 if (flags & IEEE80211_F_DODEL) {
482 * Delete unacceptable rates.
484 if (ignore) {
485 nrs->rs_nrates--;
486 for (j = i; j < nrs->rs_nrates; j++)
487 nrs->rs_rates[j] = nrs->rs_rates[j + 1];
488 nrs->rs_rates[j] = 0;
489 continue;
492 if (!ignore)
493 okrate = nrs->rs_rates[i];
494 i++;
496 if (okrate == 0 || error != 0 ||
497 ((flags & IEEE80211_F_DOFRATE) && fixedrate != vap->iv_fixed_rate))
498 return badrate | IEEE80211_RATE_BASIC;
499 else
500 return RV(okrate);
501 #undef RV
505 * Reset 11g-related state.
507 void
508 ieee80211_reset_erp(struct ieee80211com *ic, enum ieee80211_phymode mode)
510 #define IS_11G(m) \
511 ((m) == IEEE80211_MODE_11G || (m) == IEEE80211_MODE_TURBO_G)
513 ic->ic_flags &= ~IEEE80211_F_USEPROT;
515 * Preserve the long slot and nonerp station count if
516 * switching between 11g and turboG. Otherwise, inactivity
517 * will cause the turbo station to disassociate and possibly
518 * try to leave the network.
519 * XXX not right if really trying to reset state
521 if (IS_11G(mode) ^ IS_11G(ic->ic_curmode)) {
522 ic->ic_nonerpsta = 0;
523 ic->ic_longslotsta = 0;
527 * Short slot time is enabled only when operating in 11g
528 * and not in an IBSS. We must also honor whether or not
529 * the driver is capable of doing it.
531 ieee80211_set_shortslottime(ic,
532 IEEE80211_IS_CHAN_A(ic->ic_curchan) ||
533 (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
534 ic->ic_opmode == IEEE80211_M_HOSTAP &&
535 (ic->ic_caps & IEEE80211_C_SHSLOT)));
537 * Set short preamble and ERP barker-preamble flags.
539 if (IEEE80211_IS_CHAN_A(ic->ic_curchan) ||
540 (ic->ic_caps & IEEE80211_C_SHPREAMBLE)) {
541 ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
542 ic->ic_flags &= ~IEEE80211_F_USEBARKER;
543 } else {
544 ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
545 ic->ic_flags |= IEEE80211_F_USEBARKER;
547 #undef IS_11G
551 * Set the short slot time state and notify the driver.
553 void
554 ieee80211_set_shortslottime(struct ieee80211com *ic, int onoff)
556 if (onoff)
557 ic->ic_flags |= IEEE80211_F_SHSLOT;
558 else
559 ic->ic_flags &= ~IEEE80211_F_SHSLOT;
560 /* notify driver */
561 if (ic->ic_updateslot != NULL)
562 ic->ic_updateslot(ic->ic_dev);
566 * Check if the specified rate set supports ERP.
567 * NB: the rate set is assumed to be sorted.
570 ieee80211_iserp_rateset(struct ieee80211com *ic, struct ieee80211_rateset *rs)
572 static const int rates[] = { 2, 4, 11, 22, 12, 24, 48 };
573 int i, j;
575 if (rs->rs_nrates < ARRAY_SIZE(rates))
576 return 0;
577 for (i = 0; i < ARRAY_SIZE(rates); i++) {
578 for (j = 0; j < rs->rs_nrates; j++) {
579 int r = rs->rs_rates[j] & IEEE80211_RATE_VAL;
580 if (rates[i] == r)
581 goto next;
582 if (r > rates[i])
583 return 0;
585 return 0;
586 next:
589 return 1;
592 static const struct ieee80211_rateset basic11g[IEEE80211_MODE_MAX] = {
593 { 0 }, /* IEEE80211_MODE_AUTO */
594 { 3, { 12, 24, 48 } }, /* IEEE80211_MODE_11A */
595 { 2, { 2, 4 } }, /* IEEE80211_MODE_11B */
596 { 4, { 2, 4, 11, 22 } }, /* IEEE80211_MODE_11G (mixed b/g) */
597 { 0 }, /* IEEE80211_MODE_FH */
598 { 3, { 12, 24, 48 } }, /* IEEE80211_MODE_TURBO_A */
599 { 4, { 2, 4, 11, 22 } }, /* IEEE80211_MODE_TURBO_G (mixed b/g) */
603 * Mark the basic rates for the 11g rate table based on the
604 * specified mode. For 11b compatibility we mark only 11b
605 * rates. There's also a pseudo 11a-mode used to mark only
606 * the basic OFDM rates; this is used to exclude 11b stations
607 * from an 11g bss.
609 void
610 ieee80211_set11gbasicrates(struct ieee80211_rateset *rs, enum ieee80211_phymode mode)
612 int i, j;
614 KASSERT(mode < IEEE80211_MODE_MAX, ("invalid mode %u", mode));
615 for (i = 0; i < rs->rs_nrates; i++) {
616 rs->rs_rates[i] &= IEEE80211_RATE_VAL;
617 for (j = 0; j < basic11g[mode].rs_nrates; j++)
618 if (basic11g[mode].rs_rates[j] == rs->rs_rates[i]) {
619 rs->rs_rates[i] |= IEEE80211_RATE_BASIC;
620 break;
626 * Deduce the 11g setup by examining the rates
627 * that are marked basic.
629 enum ieee80211_phymode
630 ieee80211_get11gbasicrates(struct ieee80211_rateset *rs)
632 struct ieee80211_rateset basic;
633 int i;
635 memset(&basic, 0, sizeof(basic));
636 for (i = 0; i < rs->rs_nrates; i++)
637 if (rs->rs_rates[i] & IEEE80211_RATE_BASIC)
638 basic.rs_rates[basic.rs_nrates++] =
639 rs->rs_rates[i] & IEEE80211_RATE_VAL;
640 for (i = 0; i < IEEE80211_MODE_MAX; i++)
641 if (memcmp(&basic, &basic11g[i], sizeof(basic)) == 0)
642 return i;
643 return IEEE80211_MODE_AUTO;
646 void
647 ieee80211_wme_initparams(struct ieee80211vap *vap)
649 struct ieee80211com *ic = vap->iv_ic;
651 IEEE80211_LOCK_IRQ(ic);
652 ieee80211_wme_initparams_locked(vap);
653 IEEE80211_UNLOCK_IRQ(ic);
656 void
657 ieee80211_wme_initparams_locked(struct ieee80211vap *vap)
659 struct ieee80211com *ic = vap->iv_ic;
660 struct ieee80211_wme_state *wme = &ic->ic_wme;
661 struct phyParamType {
662 u_int8_t aifsn;
663 u_int8_t logcwmin;
664 u_int8_t logcwmax;
665 u_int16_t txopLimit;
666 u_int8_t acm;
668 enum ieee80211_phymode mode;
670 struct phyParamType *pPhyParam, *pBssPhyParam;
672 static struct phyParamType phyParamForAC_BE[IEEE80211_MODE_MAX] = {
673 /* IEEE80211_MODE_AUTO */ { 3, 4, 6, 0, 0 },
674 /* IEEE80211_MODE_11A */ { 3, 4, 6, 0, 0 },
675 /* IEEE80211_MODE_11B */ { 3, 5, 7, 0, 0 },
676 /* IEEE80211_MODE_11G */ { 3, 4, 6, 0, 0 },
677 /* IEEE80211_MODE_FH */ { 3, 5, 7, 0, 0 },
678 /* IEEE80211_MODE_TURBO */ { 2, 3, 5, 0, 0 },
679 /* IEEE80211_MODE_TURBO */ { 2, 3, 5, 0, 0 }};
680 static struct phyParamType phyParamForAC_BK[IEEE80211_MODE_MAX] = {
681 /* IEEE80211_MODE_AUTO */ { 7, 4, 10, 0, 0 },
682 /* IEEE80211_MODE_11A */ { 7, 4, 10, 0, 0 },
683 /* IEEE80211_MODE_11B */ { 7, 5, 10, 0, 0 },
684 /* IEEE80211_MODE_11G */ { 7, 4, 10, 0, 0 },
685 /* IEEE80211_MODE_FH */ { 7, 5, 10, 0, 0 },
686 /* IEEE80211_MODE_TURBO */ { 7, 3, 10, 0, 0 },
687 /* IEEE80211_MODE_TURBO */ { 7, 3, 10, 0, 0 }};
688 static struct phyParamType phyParamForAC_VI[IEEE80211_MODE_MAX] = {
689 /* IEEE80211_MODE_AUTO */ { 1, 3, 4, 94, 0 },
690 /* IEEE80211_MODE_11A */ { 1, 3, 4, 94, 0 },
691 /* IEEE80211_MODE_11B */ { 1, 4, 5, 188, 0 },
692 /* IEEE80211_MODE_11G */ { 1, 3, 4, 94, 0 },
693 /* IEEE80211_MODE_FH */ { 1, 4, 5, 188, 0 },
694 /* IEEE80211_MODE_TURBO */ { 1, 2, 3, 94, 0 },
695 /* IEEE80211_MODE_TURBO */ { 1, 2, 3, 94, 0 }};
696 static struct phyParamType phyParamForAC_VO[IEEE80211_MODE_MAX] = {
697 /* IEEE80211_MODE_AUTO */ { 1, 2, 3, 47, 0 },
698 /* IEEE80211_MODE_11A */ { 1, 2, 3, 47, 0 },
699 /* IEEE80211_MODE_11B */ { 1, 3, 4, 102, 0 },
700 /* IEEE80211_MODE_11G */ { 1, 2, 3, 47, 0 },
701 /* IEEE80211_MODE_FH */ { 1, 3, 4, 102, 0 },
702 /* IEEE80211_MODE_TURBO */ { 1, 2, 2, 47, 0 },
703 /* IEEE80211_MODE_TURBO */ { 1, 2, 2, 47, 0 }};
705 static struct phyParamType bssPhyParamForAC_BE[IEEE80211_MODE_MAX] = {
706 /* IEEE80211_MODE_AUTO */ { 3, 4, 10, 0, 0 },
707 /* IEEE80211_MODE_11A */ { 3, 4, 10, 0, 0 },
708 /* IEEE80211_MODE_11B */ { 3, 5, 10, 0, 0 },
709 /* IEEE80211_MODE_11G */ { 3, 4, 10, 0, 0 },
710 /* IEEE80211_MODE_FH */ { 3, 5, 10, 0, 0 },
711 /* IEEE80211_MODE_TURBO */ { 2, 3, 10, 0, 0 },
712 /* IEEE80211_MODE_TURBO */ { 2, 3, 10, 0, 0 }};
713 static struct phyParamType bssPhyParamForAC_VI[IEEE80211_MODE_MAX] = {
714 /* IEEE80211_MODE_AUTO */ { 2, 3, 4, 94, 0 },
715 /* IEEE80211_MODE_11A */ { 2, 3, 4, 94, 0 },
716 /* IEEE80211_MODE_11B */ { 2, 4, 5, 188, 0 },
717 /* IEEE80211_MODE_11G */ { 2, 3, 4, 94, 0 },
718 /* IEEE80211_MODE_FH */ { 2, 4, 5, 188, 0 },
719 /* IEEE80211_MODE_TURBO */ { 2, 2, 3, 94, 0 },
720 /* IEEE80211_MODE_TURBO */ { 2, 2, 3, 94, 0 }};
721 static struct phyParamType bssPhyParamForAC_VO[IEEE80211_MODE_MAX] = {
722 /* IEEE80211_MODE_AUTO */ { 2, 2, 3, 47, 0 },
723 /* IEEE80211_MODE_11A */ { 2, 2, 3, 47, 0 },
724 /* IEEE80211_MODE_11B */ { 2, 3, 4, 102, 0 },
725 /* IEEE80211_MODE_11G */ { 2, 2, 3, 47, 0 },
726 /* IEEE80211_MODE_FH */ { 2, 3, 4, 102, 0 },
727 /* IEEE80211_MODE_TURBO */ { 1, 2, 2, 47, 0 },
728 /* IEEE80211_MODE_TURBO */ { 1, 2, 2, 47, 0 }};
730 int i;
732 IEEE80211_LOCK_ASSERT(ic);
734 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
735 return;
737 * Select mode; we can be called early in which case we
738 * always use auto mode. We know we'll be called when
739 * entering the RUN state with bsschan setup properly
740 * so state will eventually get set correctly
742 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
743 mode = ieee80211_chan2mode(ic->ic_bsschan);
744 else
745 mode = IEEE80211_MODE_AUTO;
746 for (i = 0; i < WME_NUM_AC; i++) {
747 switch (i) {
748 case WME_AC_BK:
749 pPhyParam = &phyParamForAC_BK[mode];
750 pBssPhyParam = &phyParamForAC_BK[mode];
751 break;
752 case WME_AC_VI:
753 pPhyParam = &phyParamForAC_VI[mode];
754 pBssPhyParam = &bssPhyParamForAC_VI[mode];
755 break;
756 case WME_AC_VO:
757 pPhyParam = &phyParamForAC_VO[mode];
758 pBssPhyParam = &bssPhyParamForAC_VO[mode];
759 break;
760 case WME_AC_BE:
761 default:
762 pPhyParam = &phyParamForAC_BE[mode];
763 pBssPhyParam = &bssPhyParamForAC_BE[mode];
764 break;
767 if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
768 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_acm =
769 pPhyParam->acm;
770 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_aifsn =
771 pPhyParam->aifsn;
772 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_logcwmin =
773 pPhyParam->logcwmin;
774 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_logcwmax =
775 pPhyParam->logcwmax;
776 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_txopLimit =
777 pPhyParam->txopLimit;
778 } else {
779 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_acm =
780 pBssPhyParam->acm;
781 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_aifsn =
782 pBssPhyParam->aifsn;
783 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_logcwmin =
784 pBssPhyParam->logcwmin;
785 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_logcwmax =
786 pBssPhyParam->logcwmax;
787 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_txopLimit =
788 pBssPhyParam->txopLimit;
790 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_acm =
791 pBssPhyParam->acm;
792 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_aifsn =
793 pBssPhyParam->aifsn;
794 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_logcwmin =
795 pBssPhyParam->logcwmin;
796 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_logcwmax =
797 pBssPhyParam->logcwmax;
798 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_txopLimit =
799 pBssPhyParam->txopLimit;
801 /* NB: check ic_bss to avoid NULL deref on initial attach */
802 if (vap->iv_bss != NULL) {
804 * Calculate aggressive mode switching threshold based
805 * on beacon interval.
807 wme->wme_hipri_switch_thresh =
808 (HIGH_PRI_SWITCH_THRESH * vap->iv_bss->ni_intval) / 100;
809 ieee80211_wme_updateparams_locked(vap);
814 * Update WME parameters for ourself and the BSS.
816 void
817 ieee80211_wme_updateparams_locked(struct ieee80211vap *vap)
819 static const struct { u_int8_t aifsn; u_int8_t logcwmin; u_int8_t logcwmax; u_int16_t txopLimit;}
820 phyParam[IEEE80211_MODE_MAX] = {
821 /* IEEE80211_MODE_AUTO */ { 2, 4, 10, 64 },
822 /* IEEE80211_MODE_11A */ { 2, 4, 10, 64 },
823 /* IEEE80211_MODE_11B */ { 2, 5, 10, 64 },
824 /* IEEE80211_MODE_11G */ { 2, 4, 10, 64 },
825 /* IEEE80211_MODE_FH */ { 2, 5, 10, 64 },
826 /* IEEE80211_MODE_TURBO */ { 1, 3, 10, 64 }};
827 struct ieee80211com *ic = vap->iv_ic;
828 struct ieee80211_wme_state *wme = &ic->ic_wme;
829 enum ieee80211_phymode mode;
830 int i;
832 IEEE80211_LOCK_ASSERT(vap->iv_ic);
834 /* set up the channel access parameters for the physical device */
836 for (i = 0; i < WME_NUM_AC; i++) {
837 wme->wme_chanParams.cap_wmeParams[i].wmep_aifsn =
838 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_aifsn;
839 wme->wme_chanParams.cap_wmeParams[i].wmep_logcwmin =
840 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_logcwmin;
841 wme->wme_chanParams.cap_wmeParams[i].wmep_logcwmax =
842 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_logcwmax;
843 wme->wme_chanParams.cap_wmeParams[i].wmep_txopLimit =
844 wme->wme_wmeChanParams.cap_wmeParams[i].wmep_txopLimit;
845 wme->wme_bssChanParams.cap_wmeParams[i].wmep_aifsn =
846 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_aifsn;
847 wme->wme_bssChanParams.cap_wmeParams[i].wmep_logcwmin =
848 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_logcwmin;
849 wme->wme_bssChanParams.cap_wmeParams[i].wmep_logcwmax =
850 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_logcwmax;
851 wme->wme_bssChanParams.cap_wmeParams[i].wmep_txopLimit =
852 wme->wme_wmeBssChanParams.cap_wmeParams[i].wmep_txopLimit;
856 * Select mode; we can be called early in which case we
857 * always use auto mode. We know we'll be called when
858 * entering the RUN state with bsschan setup properly
859 * so state will eventually get set correctly
861 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
862 mode = ieee80211_chan2mode(ic->ic_bsschan);
863 else
864 mode = IEEE80211_MODE_AUTO;
865 if ((vap->iv_opmode == IEEE80211_M_HOSTAP &&
866 (wme->wme_flags & WME_F_AGGRMODE) != 0) ||
867 (vap->iv_opmode != IEEE80211_M_HOSTAP &&
868 (vap->iv_bss->ni_flags & IEEE80211_NODE_QOS) == 0) ||
869 (vap->iv_flags & IEEE80211_F_WME) == 0) {
870 struct ieee80211vap *tmpvap;
871 u_int8_t burstEnabled = 0;
872 /* check if bursting enabled on at least one vap */
873 TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
874 if (tmpvap->iv_ath_cap & IEEE80211_ATHC_BURST) {
875 burstEnabled = 1;
876 break;
879 wme->wme_chanParams.cap_wmeParams[WME_AC_BE].wmep_aifsn =
880 phyParam[mode].aifsn;
881 wme->wme_chanParams.cap_wmeParams[WME_AC_BE].wmep_logcwmin =
882 phyParam[mode].logcwmin;
883 wme->wme_chanParams.cap_wmeParams[WME_AC_BE].wmep_logcwmax =
884 phyParam[mode].logcwmax;
885 wme->wme_chanParams.cap_wmeParams[WME_AC_BE].wmep_txopLimit =
886 burstEnabled ? phyParam[mode].txopLimit : 0;
887 wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE].wmep_aifsn =
888 phyParam[mode].aifsn;
889 wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE].wmep_logcwmin =
890 phyParam[mode].logcwmin;
891 wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE].wmep_logcwmax =
892 phyParam[mode].logcwmax;
893 wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE].wmep_txopLimit =
894 burstEnabled ? phyParam[mode].txopLimit : 0;
897 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
898 ic->ic_sta_assoc < 2 && (wme->wme_flags & WME_F_AGGRMODE) != 0) {
899 static const u_int8_t logCwMin[IEEE80211_MODE_MAX] = {
900 /* IEEE80211_MODE_AUTO */ 3,
901 /* IEEE80211_MODE_11A */ 3,
902 /* IEEE80211_MODE_11B */ 4,
903 /* IEEE80211_MODE_11G */ 3,
904 /* IEEE80211_MODE_FH */ 4,
905 /* IEEE80211_MODE_TURBO_A */ 3,
906 /* IEEE80211_MODE_TURBO_G */ 3
909 wme->wme_chanParams.cap_wmeParams[WME_AC_BE].wmep_logcwmin =
910 wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE].wmep_logcwmin =
911 logCwMin[mode];
913 if (vap->iv_opmode == IEEE80211_M_HOSTAP) { /* XXX ibss? */
915 * Arrange for a beacon update and bump the parameter
916 * set number so associated stations load the new values.
918 wme->wme_bssChanParams.cap_info_count =
919 (wme->wme_bssChanParams.cap_info_count + 1) & WME_QOSINFO_COUNT;
920 vap->iv_flags |= IEEE80211_F_WMEUPDATE;
923 wme->wme_update(ic);
925 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
926 "%s: WME params updated, cap_info 0x%x\n", __func__,
927 vap->iv_opmode == IEEE80211_M_STA ?
928 wme->wme_wmeChanParams.cap_info_count :
929 wme->wme_bssChanParams.cap_info_count);
932 EXPORT_SYMBOL(ieee80211_wme_updateparams);
934 void
935 ieee80211_wme_updateparams(struct ieee80211vap *vap)
937 struct ieee80211com *ic = vap->iv_ic;
939 if (ic->ic_caps & IEEE80211_C_WME) {
940 IEEE80211_LOCK_IRQ(ic);
941 ieee80211_wme_updateparams_locked(vap);
942 IEEE80211_UNLOCK_IRQ(ic);
947 * Start a vap. If this is the first vap running on the
948 * underlying device then we first bring it up.
951 ieee80211_init(struct net_device *dev, int forcescan)
953 #define IS_RUNNING(_dev) \
954 ((_dev->flags & (IFF_RUNNING|IFF_UP)) == (IFF_RUNNING|IFF_UP))
955 struct ieee80211vap *vap = dev->priv;
956 struct ieee80211com *ic = vap->iv_ic;
957 struct net_device *parent = ic->ic_dev;
959 IEEE80211_DPRINTF(vap,
960 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
961 "start running (state=%d)\n", vap->iv_state);
964 if ((dev->flags & IFF_RUNNING) == 0) {
965 if (ic->ic_nopened++ == 0 &&
966 (parent->flags & IFF_RUNNING) == 0)
967 dev_open(parent);
969 * Mark us running. Note that we do this after
970 * opening the parent device to avoid recursion.
972 dev->flags |= IFF_RUNNING; /* mark us running */
975 * If the parent is up and running, then kick the
976 * 802.11 state machine as appropriate.
977 * XXX parent should always be up+running
979 if (IS_RUNNING(ic->ic_dev)) {
980 if (vap->iv_opmode == IEEE80211_M_STA) {
981 if (ic->ic_roaming != IEEE80211_ROAMING_MANUAL) {
982 /* Try to be intelligent about clocking the
983 * state machine. If we're currently in RUN
984 * state then we should be able to apply any
985 * new state/parameters simply by
986 * re-associating. Otherwise we need to
987 * re-scan to select an appropriate ap. */
988 if (vap->iv_state != IEEE80211_S_RUN ||
989 forcescan) {
990 IEEE80211_DPRINTF(vap,
991 IEEE80211_MSG_STATE |
992 IEEE80211_MSG_DEBUG,
993 "Bringing vap %p[%s] "
994 "to %s\n",
995 vap, vap->iv_nickname,
996 ieee80211_state_name
997 [IEEE80211_S_SCAN]);
998 ieee80211_new_state(vap,
999 IEEE80211_S_SCAN, 0);
1000 } else {
1001 IEEE80211_DPRINTF(vap,
1002 IEEE80211_MSG_STATE |
1003 IEEE80211_MSG_DEBUG,
1004 "Bringing vap %p[%s] "
1005 "to %s\n",
1006 vap, vap->iv_nickname,
1007 ieee80211_state_name
1008 [IEEE80211_S_ASSOC]);
1009 ieee80211_new_state(vap,
1010 IEEE80211_S_ASSOC, 1);
1013 } else {
1015 * When the old state is running the vap must
1016 * be brought to init.
1018 if (vap->iv_state == IEEE80211_S_RUN) {
1019 IEEE80211_DPRINTF(vap,
1020 IEEE80211_MSG_STATE |
1021 IEEE80211_MSG_DEBUG,
1022 "Bringing vap %p[%s] to %s\n",
1023 vap, vap->iv_nickname,
1024 ieee80211_state_name
1025 [IEEE80211_S_INIT]);
1026 ieee80211_new_state(vap,
1027 IEEE80211_S_INIT, -1);
1030 * For monitor+wds modes there's nothing to do but
1031 * start running. Otherwise, if this is the first
1032 * vap to be brought up, start a scan which may be
1033 * preempted if the station is locked to a particular
1034 * channel.
1036 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
1037 vap->iv_opmode == IEEE80211_M_WDS) {
1038 IEEE80211_DPRINTF(vap,
1039 IEEE80211_MSG_STATE |
1040 IEEE80211_MSG_DEBUG,
1041 "Bringing vap %p[%s] to %s\n",
1042 vap, vap->iv_nickname,
1043 ieee80211_state_name
1044 [IEEE80211_S_RUN]);
1045 ieee80211_new_state(vap, IEEE80211_S_RUN, -1);
1046 } else {
1047 IEEE80211_DPRINTF(vap,
1048 IEEE80211_MSG_STATE |
1049 IEEE80211_MSG_DEBUG,
1050 "Bringing vap %p[%s] to %s\n",
1051 vap, vap->iv_nickname,
1052 ieee80211_state_name
1053 [IEEE80211_S_SCAN]);
1054 ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1059 return 0;
1060 #undef IS_RUNNING
1064 ieee80211_open(struct net_device *dev)
1066 return ieee80211_init(dev, 0);
1070 * Start all runnable VAPs on a device.
1072 void
1073 ieee80211_start_running(struct ieee80211com *ic)
1075 struct ieee80211vap *vap;
1076 struct net_device *dev;
1078 /* XXX locking */
1079 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1080 dev = vap->iv_dev;
1081 /* NB: avoid recursion */
1082 if ((dev->flags & IFF_UP) && !(dev->flags & IFF_RUNNING))
1083 ieee80211_open(dev);
1086 EXPORT_SYMBOL(ieee80211_start_running);
1089 * Stop a vap. We force it down using the state machine
1090 * then mark its device not running. If this is the last
1091 * vap running on the underlying device then we close it
1092 * too to ensure it will be properly initialized when the
1093 * next vap is brought up.
1096 ieee80211_stop(struct net_device *dev)
1098 struct ieee80211vap *vap = dev->priv;
1099 struct ieee80211com *ic = vap->iv_ic;
1100 struct net_device *parent = ic->ic_dev;
1102 IEEE80211_DPRINTF(vap,
1103 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1104 "%s\n", "stop running");
1106 ieee80211_new_state(vap, IEEE80211_S_INIT, -1);
1107 if (dev->flags & IFF_RUNNING) {
1108 dev->flags &= ~IFF_RUNNING; /* mark us stopped */
1109 del_timer(&vap->iv_mgtsend);
1110 if (--ic->ic_nopened == 0 && (parent->flags & IFF_RUNNING))
1111 dev_close(parent);
1113 #ifdef ATH_SUPERG_XR
1115 * also stop the XR vap.
1117 if (vap->iv_xrvap && !(vap->iv_flags & IEEE80211_F_XR)) {
1118 ieee80211_stop(vap->iv_xrvap->iv_dev);
1119 del_timer(&vap->iv_xrvapstart);
1120 vap->iv_xrvap->iv_dev->flags = dev->flags;
1122 #endif
1123 return 0;
1125 EXPORT_SYMBOL(ieee80211_stop);
1128 * Stop all VAPs running on a device.
1130 void
1131 ieee80211_stop_running(struct ieee80211com *ic)
1133 struct ieee80211vap *vap;
1134 struct net_device *dev;
1136 /* XXX locking */
1137 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1138 dev = vap->iv_dev;
1139 if (dev->flags & IFF_RUNNING) /* NB: avoid recursion */
1140 ieee80211_stop(dev);
1143 EXPORT_SYMBOL(ieee80211_stop_running);
1145 #ifdef ATH_SUPERG_DYNTURBO
1147 * Switch between turbo and non-turbo operating modes.
1148 * Use the specified channel flags to locate the new
1149 * channel, update 802.11 state, and then call back into
1150 * the driver to effect the change.
1152 void
1153 ieee80211_dturbo_switch(struct ieee80211com *ic, int newflags)
1155 #ifdef IEEE80211_DEBUG
1156 /* XXX use first vap for debug flags */
1157 struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
1158 #endif
1159 struct ieee80211_channel *chan;
1161 chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags);
1162 if (chan == NULL) { /* XXX should not happen */
1163 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPG,
1164 "%s: no channel with freq %u flags 0x%x\n",
1165 __func__, ic->ic_bsschan->ic_freq, newflags);
1166 return;
1169 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPG,
1170 "%s: %s -> %s (freq %u flags 0x%x)\n", __func__,
1171 ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)],
1172 ieee80211_phymode_name[ieee80211_chan2mode(chan)],
1173 chan->ic_freq, chan->ic_flags);
1175 ic->ic_bsschan = chan;
1176 ic->ic_curchan = chan;
1177 ic->ic_set_channel(ic);
1178 /* NB: do not need to reset ERP state because in sta mode */
1180 EXPORT_SYMBOL(ieee80211_dturbo_switch);
1181 #endif /* ATH_SUPERG_DYNTURBO */
1183 void
1184 ieee80211_beacon_miss(struct ieee80211com *ic)
1186 struct ieee80211vap *vap;
1188 if (ic->ic_flags & IEEE80211_F_SCAN) {
1189 /* XXX check ic_curchan != ic_bsschan? */
1190 return;
1192 /* XXX locking */
1193 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1194 IEEE80211_DPRINTF(vap,
1195 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1196 "%s\n", "beacon miss");
1199 * Our handling is only meaningful for stations that are
1200 * associated; any other conditions else will be handled
1201 * through different means (e.g. the tx timeout on mgt frames).
1203 if (vap->iv_opmode != IEEE80211_M_STA ||
1204 vap->iv_state != IEEE80211_S_RUN)
1205 continue;
1206 if (ic->ic_roaming == IEEE80211_ROAMING_AUTO) {
1207 #ifdef ATH_SUPERG_DYNTURBO
1209 * If we receive a beacon miss interrupt when using
1210 * dynamic turbo, attempt to switch modes before
1211 * reassociating.
1213 if (IEEE80211_ATH_CAP(vap, vap->iv_bss, IEEE80211_ATHC_TURBOP))
1214 ieee80211_dturbo_switch(ic,
1215 ic->ic_bsschan->ic_flags ^
1216 IEEE80211_CHAN_TURBO);
1217 #endif /* ATH_SUPERG_DYNTURBO */
1219 * Try to reassociate before scanning for a new ap.
1221 ieee80211_new_state(vap, IEEE80211_S_ASSOC, 1);
1222 } else {
1224 * Somebody else is controlling state changes (e.g.
1225 * a user-mode app) don't do anything that would
1226 * confuse them; just drop into scan mode so they'll
1227 * notified of the state change and given control.
1229 ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1233 EXPORT_SYMBOL(ieee80211_beacon_miss);
1236 * STA software beacon timer callback. This is called
1237 * only when we have a series beacon misses.
1239 static void
1240 ieee80211_sta_swbmiss(unsigned long arg)
1242 struct ieee80211vap *vap = (struct ieee80211vap *)arg;
1243 ieee80211_beacon_miss(vap->iv_ic);
1247 * Per-ieee80211vap watchdog timer callback. This
1248 * is used only to timeout the xmit of management frames.
1250 static void
1251 ieee80211_tx_timeout(unsigned long arg)
1253 struct ieee80211vap *vap = (struct ieee80211vap *)arg;
1255 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1256 "%s: state %s%s\n", __func__,
1257 ieee80211_state_name[vap->iv_state],
1258 vap->iv_ic->ic_flags & IEEE80211_F_SCAN ? ", scan active" : "");
1260 if (vap->iv_state != IEEE80211_S_INIT &&
1261 (vap->iv_ic->ic_flags & IEEE80211_F_SCAN) == 0) {
1263 * NB: it's safe to specify a timeout as the reason here;
1264 * it'll only be used in the right state.
1266 ieee80211_new_state(vap, IEEE80211_S_SCAN,
1267 IEEE80211_SCAN_FAIL_TIMEOUT);
1271 static void
1272 sta_disassoc(void *arg, struct ieee80211_node *ni)
1274 struct ieee80211vap *vap = arg;
1276 if (ni->ni_vap == vap && ni->ni_associd != 0) {
1277 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DISASSOC,
1278 IEEE80211_REASON_ASSOC_LEAVE);
1279 ieee80211_node_leave(ni);
1283 static void
1284 sta_deauth(void *arg, struct ieee80211_node *ni)
1286 struct ieee80211vap *vap = arg;
1288 if (ni->ni_vap == vap)
1289 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH,
1290 IEEE80211_REASON_ASSOC_LEAVE);
1294 * Context: softIRQ (tasklet) and process
1297 ieee80211_new_state(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1299 struct ieee80211com *ic = vap->iv_ic;
1300 int rc;
1302 IEEE80211_VAPS_LOCK_BH(ic);
1303 rc = vap->iv_newstate(vap, nstate, arg);
1304 IEEE80211_VAPS_UNLOCK_BH(ic);
1305 return rc;
1308 static int
1309 __ieee80211_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1311 struct ieee80211com *ic = vap->iv_ic;
1312 struct ieee80211_node *ni;
1313 enum ieee80211_state ostate;
1315 ostate = vap->iv_state;
1316 vap->iv_state = nstate; /* state transition */
1317 del_timer(&vap->iv_mgtsend);
1318 if ((vap->iv_opmode != IEEE80211_M_HOSTAP) &&
1319 (ostate != IEEE80211_S_SCAN))
1320 ieee80211_cancel_scan(vap); /* background scan */
1321 ni = vap->iv_bss; /* NB: no reference held */
1322 switch (nstate) {
1323 case IEEE80211_S_INIT:
1324 switch (ostate) {
1325 case IEEE80211_S_INIT:
1326 break;
1327 case IEEE80211_S_RUN:
1328 switch (vap->iv_opmode) {
1329 case IEEE80211_M_STA:
1330 IEEE80211_SEND_MGMT(ni,
1331 IEEE80211_FC0_SUBTYPE_DISASSOC,
1332 IEEE80211_REASON_ASSOC_LEAVE);
1333 ieee80211_sta_leave(ni);
1334 break;
1335 case IEEE80211_M_HOSTAP:
1336 ieee80211_iterate_nodes(&ic->ic_sta,
1337 sta_disassoc, vap);
1338 break;
1339 default:
1340 break;
1342 goto reset;
1343 case IEEE80211_S_ASSOC:
1344 switch (vap->iv_opmode) {
1345 case IEEE80211_M_STA:
1346 IEEE80211_SEND_MGMT(ni,
1347 IEEE80211_FC0_SUBTYPE_DEAUTH,
1348 IEEE80211_REASON_AUTH_LEAVE);
1349 break;
1350 case IEEE80211_M_HOSTAP:
1351 ieee80211_iterate_nodes(&ic->ic_sta,
1352 sta_deauth, vap);
1353 break;
1354 default:
1355 break;
1357 goto reset;
1358 case IEEE80211_S_SCAN:
1359 ieee80211_cancel_scan(vap);
1360 goto reset;
1361 case IEEE80211_S_AUTH:
1362 reset:
1363 ieee80211_reset_bss(vap);
1364 break;
1366 if (vap->iv_auth != NULL && vap->iv_auth->ia_detach != NULL)
1367 vap->iv_auth->ia_detach(vap);
1368 break;
1369 case IEEE80211_S_SCAN:
1370 switch (ostate) {
1371 case IEEE80211_S_INIT:
1372 createibss:
1373 if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
1374 vap->iv_opmode == IEEE80211_M_IBSS ||
1375 vap->iv_opmode == IEEE80211_M_AHDEMO) &&
1376 vap->iv_des_chan != IEEE80211_CHAN_ANYC) {
1378 * AP operation and we already have a channel;
1379 * bypass the scan and startup immediately.
1381 ieee80211_create_ibss(vap, vap->iv_des_chan);
1382 } else {
1383 ieee80211_check_scan(vap,
1384 IEEE80211_SCAN_ACTIVE |
1385 IEEE80211_SCAN_FLUSH,
1386 IEEE80211_SCAN_FOREVER,
1387 vap->iv_des_nssid, vap->iv_des_ssid,
1388 NULL);
1390 break;
1391 case IEEE80211_S_SCAN:
1392 case IEEE80211_S_AUTH:
1393 case IEEE80211_S_ASSOC:
1395 * These can happen either because of a timeout
1396 * on an assoc/auth response or because of a
1397 * change in state that requires a reset. For
1398 * the former we're called with a non-zero arg
1399 * that is the cause for the failure; pass this
1400 * to the scan code so it can update state.
1401 * Otherwise trigger a new scan unless we're in
1402 * manual roaming mode in which case an application
1403 * must issue an explicit scan request.
1405 if (arg != 0)
1406 ieee80211_scan_assoc_fail(ic,
1407 vap->iv_bss->ni_macaddr, arg);
1408 if (ic->ic_roaming == IEEE80211_ROAMING_AUTO)
1409 ieee80211_check_scan(vap,
1410 IEEE80211_SCAN_ACTIVE,
1411 IEEE80211_SCAN_FOREVER,
1412 vap->iv_des_nssid, vap->iv_des_ssid,
1413 NULL);
1414 break;
1415 case IEEE80211_S_RUN: /* beacon miss */
1416 if (vap->iv_opmode == IEEE80211_M_STA) {
1417 ieee80211_sta_leave(ni);
1418 vap->iv_flags &= ~IEEE80211_F_SIBSS; /* XXX */
1419 if (ic->ic_roaming == IEEE80211_ROAMING_AUTO)
1420 ieee80211_check_scan(vap,
1421 IEEE80211_SCAN_ACTIVE,
1422 IEEE80211_SCAN_FOREVER,
1423 vap->iv_des_nssid,
1424 vap->iv_des_ssid,
1425 NULL);
1426 } else {
1427 ieee80211_iterate_nodes(&ic->ic_sta,
1428 sta_disassoc, vap);
1429 goto createibss;
1431 break;
1433 break;
1434 case IEEE80211_S_AUTH:
1435 /* auth frames are possible between IBSS nodes,
1436 * see 802.11-1999, chapter 5.7.6 */
1437 KASSERT(vap->iv_opmode == IEEE80211_M_STA ||
1438 vap->iv_opmode == IEEE80211_M_IBSS,
1439 ("switch to %s state when operating in mode %u",
1440 ieee80211_state_name[nstate], vap->iv_opmode));
1441 switch (ostate) {
1442 case IEEE80211_S_INIT:
1443 case IEEE80211_S_SCAN:
1444 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, 1);
1445 break;
1446 case IEEE80211_S_AUTH:
1447 case IEEE80211_S_ASSOC:
1448 switch (arg) {
1449 case IEEE80211_FC0_SUBTYPE_AUTH:
1450 /* ??? */
1451 IEEE80211_SEND_MGMT(ni,
1452 IEEE80211_FC0_SUBTYPE_AUTH, 2);
1453 break;
1454 case IEEE80211_FC0_SUBTYPE_DEAUTH:
1455 IEEE80211_SEND_MGMT(ni,
1456 IEEE80211_FC0_SUBTYPE_AUTH, 1);
1457 break;
1459 break;
1460 case IEEE80211_S_RUN:
1461 switch (arg) {
1462 case IEEE80211_FC0_SUBTYPE_AUTH:
1463 IEEE80211_SEND_MGMT(ni,
1464 IEEE80211_FC0_SUBTYPE_AUTH, 2);
1465 vap->iv_state = ostate; /* stay RUN */
1466 break;
1467 case IEEE80211_FC0_SUBTYPE_DEAUTH:
1468 ieee80211_sta_leave(ni);
1469 if (ic->ic_roaming == IEEE80211_ROAMING_AUTO) {
1470 /* try to reauth */
1471 IEEE80211_SEND_MGMT(ni,
1472 IEEE80211_FC0_SUBTYPE_AUTH, 1);
1474 break;
1476 break;
1478 break;
1479 case IEEE80211_S_ASSOC:
1480 KASSERT(vap->iv_opmode == IEEE80211_M_STA,
1481 ("switch to %s state when operating in mode %u",
1482 ieee80211_state_name[nstate], vap->iv_opmode));
1483 switch (ostate) {
1484 case IEEE80211_S_INIT:
1485 case IEEE80211_S_SCAN:
1486 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ANY,
1487 "%s: invalid transition\n", __func__);
1488 break;
1489 case IEEE80211_S_AUTH:
1490 case IEEE80211_S_ASSOC:
1491 IEEE80211_SEND_MGMT(ni,
1492 IEEE80211_FC0_SUBTYPE_ASSOC_REQ, 0);
1493 break;
1494 case IEEE80211_S_RUN:
1495 ieee80211_sta_leave(ni);
1496 if (ic->ic_roaming == IEEE80211_ROAMING_AUTO) {
1497 /* NB: caller specifies ASSOC/REASSOC by arg */
1498 IEEE80211_SEND_MGMT(ni, arg ?
1499 IEEE80211_FC0_SUBTYPE_REASSOC_REQ :
1500 IEEE80211_FC0_SUBTYPE_ASSOC_REQ, 0);
1502 break;
1504 break;
1505 case IEEE80211_S_RUN:
1506 if (vap->iv_flags & IEEE80211_F_WPA) {
1507 /* XXX validate prerequisites */
1510 switch (ostate) {
1511 case IEEE80211_S_INIT:
1512 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
1513 vap->iv_opmode == IEEE80211_M_WDS ||
1514 vap->iv_opmode == IEEE80211_M_HOSTAP) {
1516 * Already have a channel; bypass the
1517 * scan and startup immediately.
1519 ieee80211_create_ibss(vap, ic->ic_curchan);
1521 /* In WDS mode, allocate and initialize peer node. */
1522 if (vap->iv_opmode == IEEE80211_M_WDS) {
1523 /* XXX: This is horribly non-atomic. */
1524 struct ieee80211_node *wds_ni =
1525 ieee80211_find_node(&ic->ic_sta,
1526 vap->wds_mac);
1528 if (wds_ni == NULL) {
1529 wds_ni = ieee80211_alloc_node_table(
1530 vap,
1531 vap->wds_mac);
1532 if (wds_ni != NULL) {
1533 ieee80211_add_wds_addr(
1534 &ic->ic_sta,
1535 wds_ni,
1536 vap->wds_mac,
1538 ieee80211_ref_node(wds_ni); /* pin in memory */
1540 else
1541 IEEE80211_DPRINTF(
1542 vap,
1543 IEEE80211_MSG_NODE,
1544 "%s: Unable to "
1545 "allocate node for "
1546 "WDS: " MAC_FMT "\n",
1547 __func__,
1548 MAC_ADDR(
1549 vap->wds_mac)
1553 if (wds_ni != NULL) {
1554 ieee80211_node_authorize(wds_ni);
1555 wds_ni->ni_chan =
1556 vap->iv_bss->ni_chan;
1557 wds_ni->ni_capinfo =
1558 ni->ni_capinfo;
1559 wds_ni->ni_associd = 1;
1560 wds_ni->ni_ath_flags =
1561 vap->iv_ath_cap;
1564 break;
1566 /* fall thru... */
1567 case IEEE80211_S_AUTH:
1568 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ANY,
1569 "%s: invalid transition\n", __func__);
1570 break;
1571 case IEEE80211_S_RUN:
1572 break;
1573 case IEEE80211_S_SCAN: /* adhoc/hostap mode */
1574 case IEEE80211_S_ASSOC: /* infra mode */
1575 KASSERT(ni->ni_txrate < ni->ni_rates.rs_nrates,
1576 ("%s: bogus xmit rate %u setup", __func__,
1577 ni->ni_txrate));
1578 #ifdef IEEE80211_DEBUG
1579 if (ieee80211_msg_debug(vap)) {
1580 ieee80211_note(vap, "%s with " MAC_FMT " ssid ",
1581 (vap->iv_opmode == IEEE80211_M_STA ?
1582 "associated" : "synchronized "),
1583 MAC_ADDR(vap->iv_bssid));
1584 ieee80211_print_essid(vap->iv_bss->ni_essid,
1585 ni->ni_esslen);
1586 printk(" channel %d start %uMb\n",
1587 ieee80211_chan2ieee(ic, ic->ic_curchan),
1588 IEEE80211_RATE2MBS(ni->ni_rates.rs_rates[ni->ni_txrate]));
1590 #endif
1591 if (vap->iv_opmode == IEEE80211_M_STA) {
1592 ieee80211_scan_assoc_success(ic,
1593 ni->ni_macaddr);
1594 ieee80211_notify_node_join(ni,
1595 (arg == IEEE80211_FC0_SUBTYPE_ASSOC_RESP) | \
1596 (arg == IEEE80211_FC0_SUBTYPE_REASSOC_RESP));
1598 break;
1601 /* WDS/Repeater: Start software beacon timer for STA */
1602 if (ostate != IEEE80211_S_RUN &&
1603 (vap->iv_opmode == IEEE80211_M_STA &&
1604 vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS)) {
1605 vap->iv_swbmiss.function = ieee80211_sta_swbmiss;
1606 vap->iv_swbmiss.data = (unsigned long) vap;
1607 vap->iv_swbmiss_period = IEEE80211_TU_TO_JIFFIES(
1608 vap->iv_ic->ic_bmissthreshold * ni->ni_intval);
1610 mod_timer(&vap->iv_swbmiss, jiffies + vap->iv_swbmiss_period);
1614 * Start/stop the authenticator when operating as an
1615 * AP. We delay until here to allow configuration to
1616 * happen out of order.
1618 /* XXX WDS? */
1619 if (vap->iv_opmode == IEEE80211_M_HOSTAP && /* XXX IBSS/AHDEMO */
1620 vap->iv_auth->ia_attach != NULL) {
1621 /* XXX check failure */
1622 vap->iv_auth->ia_attach(vap);
1623 } else if (vap->iv_auth->ia_detach != NULL)
1624 vap->iv_auth->ia_detach(vap);
1626 * When 802.1x is not in use mark the port authorized
1627 * at this point so traffic can flow.
1629 if (ni->ni_authmode != IEEE80211_AUTH_8021X)
1630 ieee80211_node_authorize(ni);
1631 #ifdef ATH_SUPERG_XR
1633 * fire a timer to bring up XR vap if configured.
1635 if (ostate != IEEE80211_S_RUN &&
1636 vap->iv_xrvap &&
1637 !(vap->iv_flags & IEEE80211_F_XR)) {
1638 vap->iv_xrvapstart.function = ieee80211_start_xrvap;
1639 vap->iv_xrvapstart.data = (unsigned long) vap->iv_xrvap;
1640 mod_timer(&vap->iv_xrvapstart, jiffies + HZ); /* start xr vap on next second */
1642 * do not let the normal vap automatically bring up XR vap.
1643 * let the timer handler start the XR vap. if you let the
1644 * normal vap automatically start the XR vap normal vap will not
1645 * have the bssid initialized and the XR vap will use the
1646 * invalid bssid in XRIE of its beacon.
1648 if (vap->iv_xrvap->iv_flags_ext & IEEE80211_FEXT_SCAN_PENDING)
1649 vap->iv_xrvap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_PENDING;
1652 * when an XR vap transitions to RUN state,
1653 * normal vap needs to update the XR IE
1654 * with the xr vaps MAC address.
1656 if (vap->iv_flags & IEEE80211_F_XR)
1657 vap->iv_xrvap->iv_flags |= IEEE80211_F_XRUPDATE;
1658 #endif
1659 break;
1661 return 0;
1664 /* Get the dominant state of the device (init, running, or scanning
1665 * (and/or associating)) */
1666 static int get_dominant_state(struct ieee80211com *ic) {
1667 int nscanning = 0;
1668 int nrunning = 0;
1669 struct ieee80211vap *tmpvap;
1671 TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
1672 if (tmpvap->iv_opmode == IEEE80211_M_MONITOR)
1673 /* skip monitor vaps as their
1674 * S_RUN shouldn't have any
1675 * influence on modifying state
1676 * transition */
1677 continue;
1678 if (tmpvap->iv_state == IEEE80211_S_RUN)
1679 nrunning++;
1680 else if (tmpvap->iv_state == IEEE80211_S_SCAN ||
1681 tmpvap->iv_state == IEEE80211_S_AUTH ||
1682 tmpvap->iv_state == IEEE80211_S_ASSOC) {
1683 KASSERT((nscanning <= 1), ("Two VAPs cannot scan at "
1684 "the same time"));
1685 nscanning++;
1688 KASSERT(!(nscanning && nrunning), ("SCAN and RUN can't happen at the "
1689 "same time"));
1690 KASSERT((nscanning <= 1), ("Two VAPs must not SCAN at the "
1691 "same time"));
1693 if (nrunning > 0)
1694 return IEEE80211_S_RUN;
1695 else if (nscanning > 0)
1696 return IEEE80211_S_SCAN;
1697 else
1698 return IEEE80211_S_INIT;
1701 static void
1702 dump_vap_states(struct ieee80211com *ic, struct ieee80211vap *highlighed)
1704 /* RE-count the number of VAPs in RUN, SCAN states */
1705 int nrunning = 0;
1706 int nscanning = 0;
1707 struct ieee80211vap *tmpvap;
1708 TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
1709 IEEE80211_DPRINTF(tmpvap, IEEE80211_MSG_STATE,
1710 "%s: VAP %s%p[%24s]%s = %s%s%s.\n", __func__,
1711 (highlighed == tmpvap ? "*" : " "),
1712 tmpvap, tmpvap->iv_nickname,
1713 (highlighed == tmpvap ? "*" : " "),
1714 ieee80211_state_name[tmpvap->iv_state],
1715 (tmpvap->iv_state == IEEE80211_S_RUN) ?
1716 "[RUNNING]" : "",
1717 (tmpvap->iv_state == IEEE80211_S_SCAN ||
1718 tmpvap->iv_state == IEEE80211_S_AUTH ||
1719 tmpvap->iv_state == IEEE80211_S_ASSOC) ?
1720 "[SCANNING]" : ""
1722 /* Ignore monitors they are passive */
1723 if (tmpvap->iv_opmode == IEEE80211_M_MONITOR) {
1724 continue;
1726 if (tmpvap->iv_state == IEEE80211_S_RUN) {
1727 KASSERT((nscanning == 0), ("SCAN and RUN can't happen "
1728 "at the same time"));
1729 nrunning++;
1731 if (tmpvap->iv_state == IEEE80211_S_SCAN ||
1732 /* STA in WDS/Repeater */
1733 tmpvap->iv_state == IEEE80211_S_AUTH ||
1734 tmpvap->iv_state == IEEE80211_S_ASSOC) {
1735 KASSERT((nscanning == 0), ("Two VAPs cannot scan at "
1736 "the same time"));
1737 KASSERT((nrunning == 0), ("SCAN and RUN can't happen "
1738 "at the same time"));
1739 nscanning++;
1744 static int
1745 ieee80211_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
1747 struct ieee80211com *ic = vap->iv_ic;
1748 enum ieee80211_state ostate;
1749 enum ieee80211_state dstate;
1750 int blocked = 0;
1751 struct ieee80211vap *tmpvap;
1753 ostate = vap->iv_state;
1754 dstate = get_dominant_state(ic);
1756 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1757 "%s: %p[%s] %s -> %s (dominant %s)\n",
1758 __func__, vap, vap->iv_nickname,
1759 ieee80211_state_name[ostate],
1760 ieee80211_state_name[nstate],
1761 ieee80211_state_name[dstate]);
1763 switch (nstate) {
1764 case IEEE80211_S_AUTH:
1765 case IEEE80211_S_ASSOC:
1766 case IEEE80211_S_SCAN:
1767 switch (dstate) {
1768 case IEEE80211_S_RUN:
1769 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
1770 vap->iv_opmode == IEEE80211_M_WDS ||
1771 vap->iv_opmode == IEEE80211_M_HOSTAP) {
1772 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1773 "%s: Jumping directly to RUN "
1774 "on VAP %p [%s].\n",
1775 __func__, vap,
1776 vap->iv_nickname);
1777 /* One or more VAPs are running, so
1778 * non-station VAPs can skip SCAN/AUTH/ASSOC
1779 * states and just run. */
1780 __ieee80211_newstate(vap, IEEE80211_S_RUN, arg);
1781 } else {
1782 /* We'll use this flag briefly to mark
1783 * transition in progress */
1784 ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_PENDING;
1785 /* IEEE80211_M_IBSS or IEEE80211_M_STA VAP
1786 * is forced to scan, we need to change
1787 * all other VAPs state to S_INIT and pend for
1788 * the scan completion */
1789 TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
1790 if ((vap != tmpvap) &&
1791 (tmpvap->iv_opmode !=
1792 IEEE80211_M_MONITOR)) {
1793 IEEE80211_DPRINTF(vap,
1794 IEEE80211_MSG_STATE,
1795 "%s: Setting "
1796 "SCAN_PENDING "
1797 "flag on "
1798 "VAP %p "
1799 "[%s].\n",
1800 __func__,
1801 tmpvap,
1802 tmpvap->
1803 iv_nickname);
1804 tmpvap->iv_flags_ext |=
1805 IEEE80211_FEXT_SCAN_PENDING;
1806 if (tmpvap->iv_state !=
1807 IEEE80211_S_INIT) {
1808 IEEE80211_DPRINTF(vap,
1809 IEEE80211_MSG_STATE,
1810 "%s: "
1811 "Forcing "
1812 "INIT "
1813 "state "
1814 "on "
1815 "VAP "
1816 "%p "
1817 "[%s].\n",
1818 __func__,
1819 tmpvap,
1820 tmpvap->
1821 iv_nickname);
1822 tmpvap->iv_newstate(tmpvap,
1823 IEEE80211_S_INIT,
1825 } else {
1826 IEEE80211_DPRINTF(vap,
1827 IEEE80211_MSG_STATE,
1828 "%s: "
1829 "NOT "
1830 "forcing "
1831 "INIT "
1832 "state "
1833 "on "
1834 "VAP "
1835 "%p "
1836 "[%s].\n",
1837 __func__,
1838 tmpvap,
1839 tmpvap->
1840 iv_nickname);
1844 /* We used this flag briefly to mark transition in progress */
1845 ic->ic_flags_ext &= ~IEEE80211_FEXT_SCAN_PENDING;
1846 /* Transition S_INIT -> S_SCAN */
1847 __ieee80211_newstate(vap, nstate, arg);
1848 break;
1850 break;
1851 case IEEE80211_S_SCAN:
1852 case IEEE80211_S_AUTH:
1853 case IEEE80211_S_ASSOC:
1854 /* this VAP was scanning */
1855 /* STA in WDS/Repeater needs to bring up other VAPs */
1856 if (ostate == IEEE80211_S_SCAN ||
1857 ostate == IEEE80211_S_AUTH ||
1858 ostate == IEEE80211_S_ASSOC) {
1859 /* Transition (S_SCAN|S_AUTH|S_ASSOC) ->
1860 * S_SCAN */
1861 __ieee80211_newstate(vap, nstate, arg);
1862 } else {
1863 /* Someone else is scanning, so block the
1864 * transition */
1865 vap->iv_flags_ext |=
1866 IEEE80211_FEXT_SCAN_PENDING;
1867 __ieee80211_newstate(vap, IEEE80211_S_INIT,
1868 arg);
1869 blocked = 1;
1871 break;
1872 case IEEE80211_S_INIT:
1873 /* Transition S_INIT -> S_SCAN */
1874 __ieee80211_newstate(vap, nstate, arg);
1875 break;
1877 break;
1879 case IEEE80211_S_RUN:
1880 /* this VAP was scanning */
1881 /* STA in WDS/Repeater needs to bring up other VAPs */
1882 if (ostate == IEEE80211_S_SCAN ||
1883 ostate == IEEE80211_S_AUTH ||
1884 ostate == IEEE80211_S_ASSOC) {
1885 /* Transition (S_SCAN|S_AUTH|S_ASSOC) -> S_RUN */
1886 __ieee80211_newstate(vap, nstate, arg);
1887 /* Then bring up all other vaps pending on the scan */
1888 dstate = get_dominant_state(ic);
1889 if (dstate == IEEE80211_S_RUN) {
1890 TAILQ_FOREACH(tmpvap, &ic->ic_vaps, iv_next) {
1891 if ((vap != tmpvap) &&
1892 (tmpvap->iv_opmode !=
1893 IEEE80211_M_MONITOR) &&
1894 (tmpvap->iv_flags_ext &
1895 IEEE80211_FEXT_SCAN_PENDING)) {
1896 IEEE80211_DPRINTF(vap,
1897 IEEE80211_MSG_STATE,
1898 "%s: Clearing "
1899 "SCAN_PENDING "
1900 "flag from VAP "
1901 "%p [%s] and "
1902 "transitioning "
1903 "to RUN state.\n",
1904 __func__, tmpvap,
1905 tmpvap->iv_nickname);
1906 tmpvap->iv_flags_ext &=
1907 ~IEEE80211_FEXT_SCAN_PENDING;
1908 if (tmpvap->iv_state !=
1909 IEEE80211_S_RUN) {
1910 tmpvap->iv_newstate(tmpvap,
1911 IEEE80211_S_RUN, 0);
1912 } else if (tmpvap->iv_opmode ==
1913 IEEE80211_M_HOSTAP) {
1914 /* Force other AP through
1915 * -> INIT -> RUN to make
1916 * sure beacons are
1917 * reallocated */
1918 tmpvap->iv_newstate(tmpvap,
1919 IEEE80211_S_INIT, 0);
1920 tmpvap->iv_newstate(tmpvap,
1921 IEEE80211_S_RUN, 0);
1926 } else if (dstate == IEEE80211_S_SCAN) {
1927 /* Force to scan pending... someone is scanning */
1928 vap->iv_flags_ext |= IEEE80211_FEXT_SCAN_PENDING;
1929 __ieee80211_newstate(vap, IEEE80211_S_INIT, arg);
1930 blocked = 1;
1931 } else {
1932 __ieee80211_newstate(vap, nstate, arg);
1934 break;
1935 default:
1936 __ieee80211_newstate(vap, nstate, arg);
1939 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
1940 "%s: %s requested transition %s -> %s on VAP %p [%s]. "
1941 "Dominant state is %s.\n",
1942 __func__,
1943 (blocked ? "BLOCKED" : "ALLOWED"),
1944 ieee80211_state_name[ostate],
1945 ieee80211_state_name[nstate],
1946 vap,
1947 vap->iv_nickname,
1948 ieee80211_state_name[dstate]);
1950 dump_vap_states(ic, vap);
1951 return 0;
1954 #ifdef ATH_SUPERG_XR
1956 * start the XR vap .
1957 * called from a timer when normal vap enters RUN state .
1959 static void
1960 ieee80211_start_xrvap(unsigned long data)
1962 struct ieee80211vap *vap = (struct ieee80211vap *)data;
1963 /* make sure that the normal vap is still in RUN state */
1964 if (vap->iv_xrvap->iv_state == IEEE80211_S_RUN)
1965 ieee80211_init(vap->iv_dev, 0);
1968 #endif