FreeBSD kernel WLAN code
ieee80211_proto.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2001 Atsushi Onoe
5 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
6 * Copyright (c) 2012 IEEE
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD$");
32
33/*
34 * IEEE 802.11 protocol support.
35 */
36
37#include "opt_inet.h"
38#include "opt_wlan.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/malloc.h>
44
45#include <sys/socket.h>
46#include <sys/sockio.h>
47
48#include <net/if.h>
49#include <net/if_var.h>
50#include <net/if_media.h>
51#include <net/ethernet.h> /* XXX for ether_sprintf */
52
58#ifdef IEEE80211_SUPPORT_MESH
60#endif
63
64/* XXX tunables */
65#define AGGRESSIVE_MODE_SWITCH_HYSTERESIS 3 /* pkts / 100ms */
66#define HIGH_PRI_SWITCH_THRESH 10 /* pkts / 100ms */
67
68const char *mgt_subtype_name[] = {
69 "assoc_req", "assoc_resp", "reassoc_req", "reassoc_resp",
70 "probe_req", "probe_resp", "timing_adv", "reserved#7",
71 "beacon", "atim", "disassoc", "auth",
72 "deauth", "action", "action_noack", "reserved#15"
73};
74const char *ctl_subtype_name[] = {
75 "reserved#0", "reserved#1", "reserved#2", "reserved#3",
76 "reserved#4", "reserved#5", "reserved#6", "control_wrap",
77 "bar", "ba", "ps_poll", "rts",
78 "cts", "ack", "cf_end", "cf_end_ack"
79};
81 "IBSS", /* IEEE80211_M_IBSS */
82 "STA", /* IEEE80211_M_STA */
83 "WDS", /* IEEE80211_M_WDS */
84 "AHDEMO", /* IEEE80211_M_AHDEMO */
85 "HOSTAP", /* IEEE80211_M_HOSTAP */
86 "MONITOR", /* IEEE80211_M_MONITOR */
87 "MBSS" /* IEEE80211_M_MBSS */
88};
90 "INIT", /* IEEE80211_S_INIT */
91 "SCAN", /* IEEE80211_S_SCAN */
92 "AUTH", /* IEEE80211_S_AUTH */
93 "ASSOC", /* IEEE80211_S_ASSOC */
94 "CAC", /* IEEE80211_S_CAC */
95 "RUN", /* IEEE80211_S_RUN */
96 "CSA", /* IEEE80211_S_CSA */
97 "SLEEP", /* IEEE80211_S_SLEEP */
98};
99const char *ieee80211_wme_acnames[] = {
100 "WME_AC_BE",
101 "WME_AC_BK",
102 "WME_AC_VI",
103 "WME_AC_VO",
104 "WME_UPSD",
105};
106
107/*
108 * Reason code descriptions were (mostly) obtained from
109 * IEEE Std 802.11-2012, pp. 442-445 Table 8-36.
110 */
111const char *
113{
114 switch (reason) {
116 return ("unspecified");
118 return ("previous authentication is expired");
120 return ("sending STA is leaving/has left IBSS or ESS");
122 return ("disassociated due to inactivity");
124 return ("too many associated STAs");
126 return ("class 2 frame received from nonauthenticated STA");
128 return ("class 3 frame received from nonassociated STA");
130 return ("sending STA is leaving/has left BSS");
132 return ("STA requesting (re)association is not authenticated");
134 return ("information in the Power Capability element is "
135 "unacceptable");
137 return ("information in the Supported Channels element is "
138 "unacceptable");
140 return ("invalid element");
142 return ("MIC failure");
144 return ("4-Way handshake timeout");
146 return ("group key update timeout");
148 return ("element in 4-Way handshake different from "
149 "(re)association request/probe response/beacon frame");
151 return ("invalid group cipher");
153 return ("invalid pairwise cipher");
155 return ("invalid AKMP");
157 return ("unsupported version in RSN IE");
159 return ("invalid capabilities in RSN IE");
161 return ("IEEE 802.1X authentication failed");
163 return ("cipher suite rejected because of the security "
164 "policy");
166 return ("unspecified (QoS-related)");
168 return ("QoS AP lacks sufficient bandwidth for this QoS STA");
170 return ("too many frames need to be acknowledged");
172 return ("STA is transmitting outside the limits of its TXOPs");
174 return ("requested from peer STA (the STA is "
175 "resetting/leaving the BSS)");
177 return ("requested from peer STA (it does not want to use "
178 "the mechanism)");
180 return ("requested from peer STA (setup is required for the "
181 "used mechanism)");
183 return ("requested from peer STA (timeout)");
185 return ("SME cancels the mesh peering instance (not related "
186 "to the maximum number of peer mesh STAs)");
188 return ("maximum number of peer mesh STAs was reached");
190 return ("the received information violates the Mesh "
191 "Configuration policy configured in the mesh STA "
192 "profile");
194 return ("the mesh STA has received a Mesh Peering Close "
195 "message requesting to close the mesh peering");
197 return ("the mesh STA has resent dot11MeshMaxRetries Mesh "
198 "Peering Open messages, without receiving a Mesh "
199 "Peering Confirm message");
201 return ("the confirmTimer for the mesh peering instance times "
202 "out");
204 return ("the mesh STA fails to unwrap the GTK or the values "
205 "in the wrapped contents do not match");
207 return ("the mesh STA receives inconsistent information about "
208 "the mesh parameters between Mesh Peering Management "
209 "frames");
211 return ("the mesh STA fails the authenticated mesh peering "
212 "exchange because due to failure in selecting "
213 "pairwise/group ciphersuite");
215 return ("the mesh STA does not have proxy information for "
216 "this external destination");
218 return ("the mesh STA does not have forwarding information "
219 "for this destination");
221 return ("the mesh STA determines that the link to the next "
222 "hop of an active path in its forwarding information "
223 "is no longer usable");
225 return ("the MAC address of the STA already exists in the "
226 "mesh BSS");
228 return ("the mesh STA performs channel switch to meet "
229 "regulatory requirements");
231 return ("the mesh STA performs channel switch with "
232 "unspecified reason");
233 default:
234 return ("reserved/unknown");
235 }
236}
237
238static void beacon_miss(void *, int);
239static void beacon_swmiss(void *, int);
240static void parent_updown(void *, int);
241static void update_mcast(void *, int);
242static void update_promisc(void *, int);
243static void update_channel(void *, int);
244static void update_chw(void *, int);
245static void vap_update_wme(void *, int);
246static void vap_update_slot(void *, int);
247static void restart_vaps(void *, int);
248static void vap_update_erp_protmode(void *, int);
249static void vap_update_preamble(void *, int);
250static void vap_update_ht_protmode(void *, int);
251static void ieee80211_newstate_cb(void *, int);
252
253static int
254null_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
255 const struct ieee80211_bpf_params *params)
256{
257
258 ic_printf(ni->ni_ic, "missing ic_raw_xmit callback, drop frame\n");
259 m_freem(m);
260 return ENETDOWN;
261}
262
263void
265{
266 uint8_t hdrlen;
267
268 /* override the 802.3 setting */
269 hdrlen = ic->ic_headroom
270 + sizeof(struct ieee80211_qosframe_addr4)
273 /* XXX no way to recalculate on ifdetach */
274 if (ALIGN(hdrlen) > max_linkhdr) {
275 /* XXX sanity check... */
276 max_linkhdr = ALIGN(hdrlen);
277 max_hdr = max_linkhdr + max_protohdr;
278 max_datalen = MHLEN - max_hdr;
279 }
280 //ic->ic_protmode = IEEE80211_PROT_CTSONLY;
281
282 TASK_INIT(&ic->ic_parent_task, 0, parent_updown, ic);
283 TASK_INIT(&ic->ic_mcast_task, 0, update_mcast, ic);
284 TASK_INIT(&ic->ic_promisc_task, 0, update_promisc, ic);
285 TASK_INIT(&ic->ic_chan_task, 0, update_channel, ic);
286 TASK_INIT(&ic->ic_bmiss_task, 0, beacon_miss, ic);
287 TASK_INIT(&ic->ic_chw_task, 0, update_chw, ic);
288 TASK_INIT(&ic->ic_restart_task, 0, restart_vaps, ic);
289
292
293 /* initialize management frame handlers */
296
301#ifdef IEEE80211_SUPPORT_MESH
303#endif
305}
306
307void
309{
311#ifdef IEEE80211_SUPPORT_MESH
313#endif
318}
319
320static void
321null_update_beacon(struct ieee80211vap *vap, int item)
322{
323}
324
325void
327{
328 struct ieee80211com *ic = vap->iv_ic;
329 struct ifnet *ifp = vap->iv_ifp;
330 int i;
331
332 /* override the 802.3 setting */
333 ifp->if_hdrlen = ic->ic_headroom
334 + sizeof(struct ieee80211_qosframe_addr4)
337
341 callout_init_mtx(&vap->iv_swbmiss, IEEE80211_LOCK_OBJ(ic), 0);
342 callout_init(&vap->iv_mgtsend, 1);
343 TASK_INIT(&vap->iv_nstate_task, 0, ieee80211_newstate_cb, vap);
344 TASK_INIT(&vap->iv_swbmiss_task, 0, beacon_swmiss, vap);
345 TASK_INIT(&vap->iv_wme_task, 0, vap_update_wme, vap);
346 TASK_INIT(&vap->iv_slot_task, 0, vap_update_slot, vap);
347 TASK_INIT(&vap->iv_erp_protmode_task, 0, vap_update_erp_protmode, vap);
348 TASK_INIT(&vap->iv_ht_protmode_task, 0, vap_update_ht_protmode, vap);
349 TASK_INIT(&vap->iv_preamble_task, 0, vap_update_preamble, vap);
350 /*
351 * Install default tx rate handling: no fixed rate, lowest
352 * supported rate for mgmt and multicast frames. Default
353 * max retry count. These settings can be changed by the
354 * driver and/or user applications.
355 */
356 for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++) {
357 if (isclr(ic->ic_modecaps, i))
358 continue;
359
360 const struct ieee80211_rateset *rs = &ic->ic_sup_rates[i];
361
363
364 /*
365 * Setting the management rate to MCS 0 assumes that the
366 * BSS Basic rate set is empty and the BSS Basic MCS set
367 * is not.
368 *
369 * Since we're not checking this, default to the lowest
370 * defined rate for this mode.
371 *
372 * At least one 11n AP (DLINK DIR-825) is reported to drop
373 * some MCS management traffic (eg BA response frames.)
374 *
375 * See also: 9.6.0 of the 802.11n-2009 specification.
376 */
377#ifdef NOTYET
378 if (i == IEEE80211_MODE_11NA || i == IEEE80211_MODE_11NG) {
381 } else {
382 vap->iv_txparms[i].mgmtrate =
384 vap->iv_txparms[i].mcastrate =
386 }
387#endif
391 }
393
397
398 /* attach support for operating mode */
399 ic->ic_vattach[vap->iv_opmode](vap);
400}
401
402void
404{
405#define FREEAPPIE(ie) do { \
406 if (ie != NULL) \
407 IEEE80211_FREE(ie, M_80211_NODE_IE); \
408} while (0)
409 /*
410 * Detach operating mode module.
411 */
412 if (vap->iv_opdetach != NULL)
413 vap->iv_opdetach(vap);
414 /*
415 * This should not be needed as we detach when reseting
416 * the state but be conservative here since the
417 * authenticator may do things like spawn kernel threads.
418 */
419 if (vap->iv_auth->ia_detach != NULL)
420 vap->iv_auth->ia_detach(vap);
421 /*
422 * Detach any ACL'ator.
423 */
424 if (vap->iv_acl != NULL)
425 vap->iv_acl->iac_detach(vap);
426
433#undef FREEAPPIE
434}
435
436/*
437 * Simple-minded authenticator module support.
438 */
439
440#define IEEE80211_AUTH_MAX (IEEE80211_AUTH_WPA+1)
441/* XXX well-known names */
442static const char *auth_modnames[IEEE80211_AUTH_MAX] = {
443 "wlan_internal", /* IEEE80211_AUTH_NONE */
444 "wlan_internal", /* IEEE80211_AUTH_OPEN */
445 "wlan_internal", /* IEEE80211_AUTH_SHARED */
446 "wlan_xauth", /* IEEE80211_AUTH_8021X */
447 "wlan_internal", /* IEEE80211_AUTH_AUTO */
448 "wlan_xauth", /* IEEE80211_AUTH_WPA */
449};
451
453 .ia_name = "wlan_internal",
454 .ia_attach = NULL,
455 .ia_detach = NULL,
456 .ia_node_join = NULL,
457 .ia_node_leave = NULL,
458};
459
460/*
461 * Setup internal authenticators once; they are never unregistered.
462 */
463static void
465{
469}
470SYSINIT(wlan_auth, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_auth_setup, NULL);
471
472const struct ieee80211_authenticator *
474{
475 if (auth >= IEEE80211_AUTH_MAX)
476 return NULL;
477 if (authenticators[auth] == NULL)
479 return authenticators[auth];
480}
481
482void
484 const struct ieee80211_authenticator *auth)
485{
486 if (type >= IEEE80211_AUTH_MAX)
487 return;
488 authenticators[type] = auth;
489}
490
491void
493{
494
495 if (type >= IEEE80211_AUTH_MAX)
496 return;
497 authenticators[type] = NULL;
498}
499
500/*
501 * Very simple-minded ACL module support.
502 */
503/* XXX just one for now */
504static const struct ieee80211_aclator *acl = NULL;
505
506void
508{
509 printf("wlan: %s acl policy registered\n", iac->iac_name);
510 acl = iac;
511}
512
513void
515{
516 if (acl == iac)
517 acl = NULL;
518 printf("wlan: %s acl policy unregistered\n", iac->iac_name);
519}
520
521const struct ieee80211_aclator *
522ieee80211_aclator_get(const char *name)
523{
524 if (acl == NULL)
525 ieee80211_load_module("wlan_acl");
526 return acl != NULL && strcmp(acl->iac_name, name) == 0 ? acl : NULL;
527}
528
529void
530ieee80211_print_essid(const uint8_t *essid, int len)
531{
532 const uint8_t *p;
533 int i;
534
535 if (len > IEEE80211_NWID_LEN)
536 len = IEEE80211_NWID_LEN;
537 /* determine printable or not */
538 for (i = 0, p = essid; i < len; i++, p++) {
539 if (*p < ' ' || *p > 0x7e)
540 break;
541 }
542 if (i == len) {
543 printf("\"");
544 for (i = 0, p = essid; i < len; i++, p++)
545 printf("%c", *p);
546 printf("\"");
547 } else {
548 printf("0x");
549 for (i = 0, p = essid; i < len; i++, p++)
550 printf("%02x", *p);
551 }
552}
553
554void
556 const uint8_t *buf, int len, int rate, int rssi)
557{
558 const struct ieee80211_frame *wh;
559 int i;
560
561 wh = (const struct ieee80211_frame *)buf;
562 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
564 printf("NODS %s", ether_sprintf(wh->i_addr2));
565 printf("->%s", ether_sprintf(wh->i_addr1));
566 printf("(%s)", ether_sprintf(wh->i_addr3));
567 break;
569 printf("TODS %s", ether_sprintf(wh->i_addr2));
570 printf("->%s", ether_sprintf(wh->i_addr3));
571 printf("(%s)", ether_sprintf(wh->i_addr1));
572 break;
574 printf("FRDS %s", ether_sprintf(wh->i_addr3));
575 printf("->%s", ether_sprintf(wh->i_addr1));
576 printf("(%s)", ether_sprintf(wh->i_addr2));
577 break;
579 printf("DSDS %s", ether_sprintf((const uint8_t *)&wh[1]));
580 printf("->%s", ether_sprintf(wh->i_addr3));
581 printf("(%s", ether_sprintf(wh->i_addr2));
582 printf("->%s)", ether_sprintf(wh->i_addr1));
583 break;
584 }
585 switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
587 printf(" data");
588 break;
590 printf(" %s", ieee80211_mgt_subtype_name(wh->i_fc[0]));
591 break;
592 default:
593 printf(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
594 break;
595 }
596 if (IEEE80211_QOS_HAS_SEQ(wh)) {
597 const struct ieee80211_qosframe *qwh =
598 (const struct ieee80211_qosframe *)buf;
599 printf(" QoS [TID %u%s]", qwh->i_qos[0] & IEEE80211_QOS_TID,
600 qwh->i_qos[0] & IEEE80211_QOS_ACKPOLICY ? " ACM" : "");
601 }
602 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
603 int off;
604
605 off = ieee80211_anyhdrspace(ic, wh);
606 printf(" WEP [IV %.02x %.02x %.02x",
607 buf[off+0], buf[off+1], buf[off+2]);
609 printf(" %.02x %.02x %.02x",
610 buf[off+4], buf[off+5], buf[off+6]);
611 printf(" KID %u]", buf[off+IEEE80211_WEP_IVLEN] >> 6);
612 }
613 if (rate >= 0)
614 printf(" %dM", rate / 2);
615 if (rssi >= 0)
616 printf(" +%d", rssi);
617 printf("\n");
618 if (len > 0) {
619 for (i = 0; i < len; i++) {
620 if ((i & 1) == 0)
621 printf(" ");
622 printf("%02x", buf[i]);
623 }
624 printf("\n");
625 }
626}
627
628static __inline int
629findrix(const struct ieee80211_rateset *rs, int r)
630{
631 int i;
632
633 for (i = 0; i < rs->rs_nrates; i++)
634 if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == r)
635 return i;
636 return -1;
637}
638
639int
641 struct ieee80211_rateset *nrs, int flags)
642{
643 struct ieee80211vap *vap = ni->ni_vap;
644 struct ieee80211com *ic = ni->ni_ic;
645 int i, j, rix, error;
646 int okrate, badrate, fixedrate, ucastrate;
647 const struct ieee80211_rateset *srs;
648 uint8_t r;
649
650 error = 0;
651 okrate = badrate = 0;
652 ucastrate = vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)].ucastrate;
653 if (ucastrate != IEEE80211_FIXED_RATE_NONE) {
654 /*
655 * Workaround awkwardness with fixed rate. We are called
656 * to check both the legacy rate set and the HT rate set
657 * but we must apply any legacy fixed rate check only to the
658 * legacy rate set and vice versa. We cannot tell what type
659 * of rate set we've been given (legacy or HT) but we can
660 * distinguish the fixed rate type (MCS have 0x80 set).
661 * So to deal with this the caller communicates whether to
662 * check MCS or legacy rate using the flags and we use the
663 * type of any fixed rate to avoid applying an MCS to a
664 * legacy rate and vice versa.
665 */
666 if (ucastrate & 0x80) {
667 if (flags & IEEE80211_F_DOFRATE)
668 flags &= ~IEEE80211_F_DOFRATE;
669 } else if ((ucastrate & 0x80) == 0) {
670 if (flags & IEEE80211_F_DOFMCS)
671 flags &= ~IEEE80211_F_DOFMCS;
672 }
673 /* NB: required to make MCS match below work */
674 ucastrate &= IEEE80211_RATE_VAL;
675 }
676 fixedrate = IEEE80211_FIXED_RATE_NONE;
677 /*
678 * XXX we are called to process both MCS and legacy rates;
679 * we must use the appropriate basic rate set or chaos will
680 * ensue; for now callers that want MCS must supply
681 * IEEE80211_F_DOBRS; at some point we'll need to split this
682 * function so there are two variants, one for MCS and one
683 * for legacy rates.
684 */
685 if (flags & IEEE80211_F_DOBRS)
686 srs = (const struct ieee80211_rateset *)
688 else
689 srs = ieee80211_get_suprates(ic, ni->ni_chan);
690 for (i = 0; i < nrs->rs_nrates; ) {
691 if (flags & IEEE80211_F_DOSORT) {
692 /*
693 * Sort rates.
694 */
695 for (j = i + 1; j < nrs->rs_nrates; j++) {
696 if (IEEE80211_RV(nrs->rs_rates[i]) >
697 IEEE80211_RV(nrs->rs_rates[j])) {
698 r = nrs->rs_rates[i];
699 nrs->rs_rates[i] = nrs->rs_rates[j];
700 nrs->rs_rates[j] = r;
701 }
702 }
703 }
704 r = nrs->rs_rates[i] & IEEE80211_RATE_VAL;
705 badrate = r;
706 /*
707 * Check for fixed rate.
708 */
709 if (r == ucastrate)
710 fixedrate = r;
711 /*
712 * Check against supported rates.
713 */
714 rix = findrix(srs, r);
715 if (flags & IEEE80211_F_DONEGO) {
716 if (rix < 0) {
717 /*
718 * A rate in the node's rate set is not
719 * supported. If this is a basic rate and we
720 * are operating as a STA then this is an error.
721 * Otherwise we just discard/ignore the rate.
722 */
723 if ((flags & IEEE80211_F_JOIN) &&
724 (nrs->rs_rates[i] & IEEE80211_RATE_BASIC))
725 error++;
726 } else if ((flags & IEEE80211_F_JOIN) == 0) {
727 /*
728 * Overwrite with the supported rate
729 * value so any basic rate bit is set.
730 */
731 nrs->rs_rates[i] = srs->rs_rates[rix];
732 }
733 }
734 if ((flags & IEEE80211_F_DODEL) && rix < 0) {
735 /*
736 * Delete unacceptable rates.
737 */
738 nrs->rs_nrates--;
739 for (j = i; j < nrs->rs_nrates; j++)
740 nrs->rs_rates[j] = nrs->rs_rates[j + 1];
741 nrs->rs_rates[j] = 0;
742 continue;
743 }
744 if (rix >= 0)
745 okrate = nrs->rs_rates[i];
746 i++;
747 }
748 if (okrate == 0 || error != 0 ||
750 fixedrate != ucastrate)) {
752 "%s: flags 0x%x okrate %d error %d fixedrate 0x%x "
753 "ucastrate %x\n", __func__, fixedrate, ucastrate, flags);
754 return badrate | IEEE80211_RATE_BASIC;
755 } else
756 return IEEE80211_RV(okrate);
757}
758
759/*
760 * Reset 11g-related state.
761 *
762 * This is for per-VAP ERP/11g state.
763 *
764 * Eventually everything in ieee80211_reset_erp() will be
765 * per-VAP and in here.
766 */
767void
769{
770 struct ieee80211com *ic = vap->iv_ic;
771
772 vap->iv_nonerpsta = 0;
773 vap->iv_longslotsta = 0;
774
775 vap->iv_flags &= ~IEEE80211_F_USEPROT;
776 /*
777 * Set short preamble and ERP barker-preamble flags.
778 */
782 vap->iv_flags &= ~IEEE80211_F_USEBARKER;
783 } else {
784 vap->iv_flags &= ~IEEE80211_F_SHPREAMBLE;
786 }
787
788 /*
789 * Short slot time is enabled only when operating in 11g
790 * and not in an IBSS. We must also honor whether or not
791 * the driver is capable of doing it.
792 */
798 (ic->ic_caps & IEEE80211_C_SHSLOT)));
799}
800
801/*
802 * Reset 11g-related state.
803 *
804 * Note this resets the global state and a caller should schedule
805 * a re-check of all the VAPs after setup to update said state.
806 */
807void
809{
810#if 0
811 ic->ic_flags &= ~IEEE80211_F_USEPROT;
812 /*
813 * Set short preamble and ERP barker-preamble flags.
814 */
818 ic->ic_flags &= ~IEEE80211_F_USEBARKER;
819 } else {
820 ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
822 }
823#endif
824 /* XXX TODO: schedule a new per-VAP ERP calculation */
825}
826
827/*
828 * Deferred slot time update.
829 *
830 * For per-VAP slot time configuration, call the VAP
831 * method if the VAP requires it. Otherwise, just call the
832 * older global method.
833 *
834 * If the per-VAP method is called then it's expected that
835 * the driver/firmware will take care of turning the per-VAP
836 * flags into slot time configuration.
837 *
838 * If the per-VAP method is not called then the global flags will be
839 * flipped into sync with the VAPs; ic_flags IEEE80211_F_SHSLOT will
840 * be set only if all of the vaps will have it set.
841 *
842 * Look at the comments for vap_update_erp_protmode() for more
843 * background; this assumes all VAPs are on the same channel.
844 */
845static void
846vap_update_slot(void *arg, int npending)
847{
848 struct ieee80211vap *vap = arg;
849 struct ieee80211com *ic = vap->iv_ic;
850 struct ieee80211vap *iv;
851 int num_shslot = 0, num_lgslot = 0;
852
853 /*
854 * Per-VAP path - we've already had the flags updated;
855 * so just notify the driver and move on.
856 */
857 if (vap->iv_updateslot != NULL) {
858 vap->iv_updateslot(vap);
859 return;
860 }
861
862 /*
863 * Iterate over all of the VAP flags to update the
864 * global flag.
865 *
866 * If all vaps have short slot enabled then flip on
867 * short slot. If any vap has it disabled then
868 * we leave it globally disabled. This should provide
869 * correct behaviour in a multi-BSS scenario where
870 * at least one VAP has short slot disabled for some
871 * reason.
872 */
873 IEEE80211_LOCK(ic);
874 TAILQ_FOREACH(iv, &ic->ic_vaps, iv_next) {
876 num_shslot++;
877 else
878 num_lgslot++;
879 }
880
881 /*
882 * It looks backwards but - if the number of short slot VAPs
883 * is zero then we're not short slot. Else, we have one
884 * or more short slot VAPs and we're checking to see if ANY
885 * of them have short slot disabled.
886 */
887 if (num_shslot == 0)
888 ic->ic_flags &= ~IEEE80211_F_SHSLOT;
889 else if (num_lgslot == 0)
892
893 /*
894 * Call the driver with our new global slot time flags.
895 */
896 if (ic->ic_updateslot != NULL)
897 ic->ic_updateslot(ic);
898}
899
900/*
901 * Deferred ERP protmode update.
902 *
903 * This currently calculates the global ERP protection mode flag
904 * based on each of the VAPs. Any VAP with it enabled is enough
905 * for the global flag to be enabled. All VAPs with it disabled
906 * is enough for it to be disabled.
907 *
908 * This may make sense right now for the supported hardware where
909 * net80211 is controlling the single channel configuration, but
910 * offload firmware that's doing channel changes (eg off-channel
911 * TDLS, off-channel STA, off-channel P2P STA/AP) may get some
912 * silly looking flag updates.
913 *
914 * Ideally the protection mode calculation is done based on the
915 * channel, and all VAPs using that channel will inherit it.
916 * But until that's what net80211 does, this wil have to do.
917 */
918static void
919vap_update_erp_protmode(void *arg, int npending)
920{
921 struct ieee80211vap *vap = arg;
922 struct ieee80211com *ic = vap->iv_ic;
923 struct ieee80211vap *iv;
924 int enable_protmode = 0;
925 int non_erp_present = 0;
926
927 /*
928 * Iterate over all of the VAPs to calculate the overlapping
929 * ERP protection mode configuration and ERP present math.
930 *
931 * For now we assume that if a driver can handle this per-VAP
932 * then it'll ignore the ic->ic_protmode variant and instead
933 * will look at the vap related flags.
934 */
935 IEEE80211_LOCK(ic);
936 TAILQ_FOREACH(iv, &ic->ic_vaps, iv_next) {
938 enable_protmode = 1;
940 non_erp_present = 1;
941 }
942
943 if (enable_protmode)
945 else
946 ic->ic_flags &= ~IEEE80211_F_USEPROT;
947
948 if (non_erp_present)
950 else
951 ic->ic_flags_ext &= ~IEEE80211_FEXT_NONERP_PR;
952
953 /* Beacon update on all VAPs */
955
957
959 "%s: called; enable_protmode=%d, non_erp_present=%d\n",
960 __func__, enable_protmode, non_erp_present);
961
962 /*
963 * Now that the global configuration flags are calculated,
964 * notify the VAP about its configuration.
965 *
966 * The global flags will be used when assembling ERP IEs
967 * for multi-VAP operation, even if it's on a different
968 * channel. Yes, that's going to need fixing in the
969 * future.
970 */
971 if (vap->iv_erp_protmode_update != NULL)
972 vap->iv_erp_protmode_update(vap);
973}
974
975/*
976 * Deferred ERP short preamble/barker update.
977 *
978 * All VAPs need to use short preamble for it to be globally
979 * enabled or not.
980 *
981 * Look at the comments for vap_update_erp_protmode() for more
982 * background; this assumes all VAPs are on the same channel.
983 */
984static void
985vap_update_preamble(void *arg, int npending)
986{
987 struct ieee80211vap *vap = arg;
988 struct ieee80211com *ic = vap->iv_ic;
989 struct ieee80211vap *iv;
990 int barker_count = 0, short_preamble_count = 0, count = 0;
991
992 /*
993 * Iterate over all of the VAPs to calculate the overlapping
994 * short or long preamble configuration.
995 *
996 * For now we assume that if a driver can handle this per-VAP
997 * then it'll ignore the ic->ic_flags variant and instead
998 * will look at the vap related flags.
999 */
1000 IEEE80211_LOCK(ic);
1001 TAILQ_FOREACH(iv, &ic->ic_vaps, iv_next) {
1003 barker_count++;
1005 short_preamble_count++;
1006 count++;
1007 }
1008
1009 /*
1010 * As with vap_update_erp_protmode(), the global flags are
1011 * currently used for beacon IEs.
1012 */
1014 "%s: called; barker_count=%d, short_preamble_count=%d\n",
1015 __func__, barker_count, short_preamble_count);
1016
1017 /*
1018 * Only flip on short preamble if all of the VAPs support
1019 * it.
1020 */
1021 if (barker_count == 0 && short_preamble_count == count) {
1023 ic->ic_flags &= ~IEEE80211_F_USEBARKER;
1024 } else {
1025 ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE;
1027 }
1029 "%s: global barker=%d preamble=%d\n",
1030 __func__,
1032 !! (ic->ic_flags & IEEE80211_F_SHPREAMBLE));
1033
1034 /* Beacon update on all VAPs */
1036
1037 IEEE80211_UNLOCK(ic);
1038
1039 /* Driver notification */
1040 if (vap->iv_erp_protmode_update != NULL)
1041 vap->iv_preamble_update(vap);
1042}
1043
1044/*
1045 * Deferred HT protmode update and beacon update.
1046 *
1047 * Look at the comments for vap_update_erp_protmode() for more
1048 * background; this assumes all VAPs are on the same channel.
1049 */
1050static void
1051vap_update_ht_protmode(void *arg, int npending)
1052{
1053 struct ieee80211vap *vap = arg;
1054 struct ieee80211vap *iv;
1055 struct ieee80211com *ic = vap->iv_ic;
1056 int num_vaps = 0, num_pure = 0, num_mixed = 0;
1057 int num_optional = 0, num_ht2040 = 0, num_nonht = 0;
1058 int num_ht_sta = 0, num_ht40_sta = 0, num_sta = 0;
1059 int num_nonhtpr = 0;
1060
1061 /*
1062 * Iterate over all of the VAPs to calculate everything.
1063 *
1064 * There are a few different flags to calculate:
1065 *
1066 * + whether there's HT only or HT+legacy stations;
1067 * + whether there's HT20, HT40, or HT20+HT40 stations;
1068 * + whether the desired protection mode is mixed, pure or
1069 * one of the two above.
1070 *
1071 * For now we assume that if a driver can handle this per-VAP
1072 * then it'll ignore the ic->ic_htprotmode / ic->ic_curhtprotmode
1073 * variant and instead will look at the vap related variables.
1074 *
1075 * XXX TODO: non-greenfield STAs present (IEEE80211_HTINFO_NONGF_PRESENT) !
1076 */
1077
1078 IEEE80211_LOCK(ic);
1079 TAILQ_FOREACH(iv, &ic->ic_vaps, iv_next) {
1080 num_vaps++;
1081 /* overlapping BSSes advertising non-HT status present */
1083 num_nonht++;
1084 /* Operating mode flags */
1086 num_nonhtpr++;
1089 num_pure++;
1090 break;
1092 num_optional++;
1093 break;
1095 num_ht2040++;
1096 break;
1098 num_mixed++;
1099 break;
1100 }
1101
1103 "%s: vap %s: nonht_pr=%d, curhtprotmode=0x%02x\n",
1104 __func__,
1107 iv->iv_curhtprotmode);
1108
1109 num_ht_sta += iv->iv_ht_sta_assoc;
1110 num_ht40_sta += iv->iv_ht40_sta_assoc;
1111 num_sta += iv->iv_sta_assoc;
1112 }
1113
1114 /*
1115 * Step 1 - if any VAPs indicate NONHT_PR set (overlapping BSS
1116 * non-HT present), set it here. This shouldn't be used by
1117 * anything but the old overlapping BSS logic so if any drivers
1118 * consume it, it's up to date.
1119 */
1120 if (num_nonht > 0)
1122 else
1123 ic->ic_flags_ht &= ~IEEE80211_FHT_NONHT_PR;
1124
1125 /*
1126 * Step 2 - default HT protection mode to MIXED (802.11-2016 10.26.3.1.)
1127 *
1128 * + If all VAPs are PURE, we can stay PURE.
1129 * + If all VAPs are PROTOPT, we can go to PROTOPT.
1130 * + If any VAP has HT20PR then it sees at least a HT40+HT20 station.
1131 * Note that we may have a VAP with one HT20 and a VAP with one HT40;
1132 * So we look at the sum ht and sum ht40 sta counts; if we have a
1133 * HT station and the HT20 != HT40 count, we have to do HT20PR here.
1134 * Note all stations need to be HT for this to be an option.
1135 * + The fall-through is MIXED, because it means we have some odd
1136 * non HT40-involved combination of opmode and this is the most
1137 * sensible default.
1138 */
1140
1141 if (num_pure == num_vaps)
1143
1144 if (num_optional == num_vaps)
1146
1147 /*
1148 * Note: we need /a/ HT40 station somewhere for this to
1149 * be a possibility.
1150 */
1151 if ((num_ht2040 > 0) ||
1152 ((num_ht_sta > 0) && (num_ht40_sta > 0) &&
1153 (num_ht_sta != num_ht40_sta)))
1155
1156 /*
1157 * Step 3 - if any of the stations across the VAPs are
1158 * non-HT then this needs to be flipped back to MIXED.
1159 */
1160 if (num_ht_sta != num_sta)
1162
1163 /*
1164 * Step 4 - If we see any overlapping BSS non-HT stations
1165 * via beacons then flip on NONHT_PRESENT.
1166 */
1167 if (num_nonhtpr > 0)
1169
1170 /* Notify all VAPs to potentially update their beacons */
1171 TAILQ_FOREACH(iv, &ic->ic_vaps, iv_next)
1173
1174 IEEE80211_UNLOCK(ic);
1175
1177 "%s: global: nonht_pr=%d ht_opmode=0x%02x\n",
1178 __func__,
1180 ic->ic_curhtprotmode);
1181
1182 /* Driver update */
1183 if (vap->iv_erp_protmode_update != NULL)
1184 vap->iv_ht_protmode_update(vap);
1185}
1186
1187/*
1188 * Set the short slot time state and notify the driver.
1189 *
1190 * This is the per-VAP slot time state.
1191 */
1192void
1194{
1195 struct ieee80211com *ic = vap->iv_ic;
1196
1197 /* XXX lock? */
1198
1199 /*
1200 * Only modify the per-VAP slot time.
1201 */
1202 if (onoff)
1204 else
1205 vap->iv_flags &= ~IEEE80211_F_SHSLOT;
1206
1208 "%s: called; onoff=%d\n", __func__, onoff);
1209 /* schedule the deferred slot flag update and update */
1211}
1212
1213/*
1214 * Update the VAP short /long / barker preamble state and
1215 * update beacon state if needed.
1216 *
1217 * For now it simply copies the global flags into the per-vap
1218 * flags and schedules the callback. Later this will support
1219 * both global and per-VAP flags, especially useful for
1220 * and STA+STA multi-channel operation (eg p2p).
1221 */
1222void
1224{
1225 struct ieee80211com *ic = vap->iv_ic;
1226
1227 /* XXX lock? */
1228
1230 "%s: called\n", __func__);
1231 /* schedule the deferred slot flag update and update */
1233}
1234
1235/*
1236 * Update the VAP 11g protection mode and update beacon state
1237 * if needed.
1238 */
1239void
1241{
1242 struct ieee80211com *ic = vap->iv_ic;
1243
1244 /* XXX lock? */
1245
1247 "%s: called\n", __func__);
1248 /* schedule the deferred slot flag update and update */
1250}
1251
1252/*
1253 * Update the VAP 11n protection mode and update beacon state
1254 * if needed.
1255 */
1256void
1258{
1259 struct ieee80211com *ic = vap->iv_ic;
1260
1261 /* XXX lock? */
1262
1264 "%s: called\n", __func__);
1265 /* schedule the deferred protmode update */
1267}
1268
1269/*
1270 * Check if the specified rate set supports ERP.
1271 * NB: the rate set is assumed to be sorted.
1272 */
1273int
1275{
1276 static const int rates[] = { 2, 4, 11, 22, 12, 24, 48 };
1277 int i, j;
1278
1279 if (rs->rs_nrates < nitems(rates))
1280 return 0;
1281 for (i = 0; i < nitems(rates); i++) {
1282 for (j = 0; j < rs->rs_nrates; j++) {
1283 int r = rs->rs_rates[j] & IEEE80211_RATE_VAL;
1284 if (rates[i] == r)
1285 goto next;
1286 if (r > rates[i])
1287 return 0;
1288 }
1289 return 0;
1290 next:
1291 ;
1292 }
1293 return 1;
1294}
1295
1296/*
1297 * Mark the basic rates for the rate table based on the
1298 * operating mode. For real 11g we mark all the 11b rates
1299 * and 6, 12, and 24 OFDM. For 11b compatibility we mark only
1300 * 11b rates. There's also a pseudo 11a-mode used to mark only
1301 * the basic OFDM rates.
1302 */
1303static void
1305 enum ieee80211_phymode mode, int add)
1306{
1307 static const struct ieee80211_rateset basic[IEEE80211_MODE_MAX] = {
1308 [IEEE80211_MODE_11A] = { 3, { 12, 24, 48 } },
1309 [IEEE80211_MODE_11B] = { 2, { 2, 4 } },
1310 /* NB: mixed b/g */
1311 [IEEE80211_MODE_11G] = { 4, { 2, 4, 11, 22 } },
1312 [IEEE80211_MODE_TURBO_A] = { 3, { 12, 24, 48 } },
1313 [IEEE80211_MODE_TURBO_G] = { 4, { 2, 4, 11, 22 } },
1314 [IEEE80211_MODE_STURBO_A] = { 3, { 12, 24, 48 } },
1315 [IEEE80211_MODE_HALF] = { 3, { 6, 12, 24 } },
1316 [IEEE80211_MODE_QUARTER] = { 3, { 3, 6, 12 } },
1317 [IEEE80211_MODE_11NA] = { 3, { 12, 24, 48 } },
1318 /* NB: mixed b/g */
1319 [IEEE80211_MODE_11NG] = { 4, { 2, 4, 11, 22 } },
1320 /* NB: mixed b/g */
1321 [IEEE80211_MODE_VHT_2GHZ] = { 4, { 2, 4, 11, 22 } },
1322 [IEEE80211_MODE_VHT_5GHZ] = { 3, { 12, 24, 48 } },
1323 };
1324 int i, j;
1325
1326 for (i = 0; i < rs->rs_nrates; i++) {
1327 if (!add)
1328 rs->rs_rates[i] &= IEEE80211_RATE_VAL;
1329 for (j = 0; j < basic[mode].rs_nrates; j++)
1330 if (basic[mode].rs_rates[j] == rs->rs_rates[i]) {
1332 break;
1333 }
1334 }
1335}
1336
1337/*
1338 * Set the basic rates in a rate set.
1339 */
1340void
1342 enum ieee80211_phymode mode)
1343{
1344 setbasicrates(rs, mode, 0);
1345}
1346
1347/*
1348 * Add basic rates to a rate set.
1349 */
1350void
1352 enum ieee80211_phymode mode)
1353{
1354 setbasicrates(rs, mode, 1);
1355}
1356
1357/*
1358 * WME protocol support.
1359 *
1360 * The default 11a/b/g/n parameters come from the WiFi Alliance WMM
1361 * System Interopability Test Plan (v1.4, Appendix F) and the 802.11n
1362 * Draft 2.0 Test Plan (Appendix D).
1363 *
1364 * Static/Dynamic Turbo mode settings come from Atheros.
1365 */
1366typedef struct phyParamType {
1367 uint8_t aifsn;
1368 uint8_t logcwmin;
1369 uint8_t logcwmax;
1370 uint16_t txopLimit;
1371 uint8_t acm;
1373
1375 [IEEE80211_MODE_AUTO] = { 3, 4, 6, 0, 0 },
1376 [IEEE80211_MODE_11A] = { 3, 4, 6, 0, 0 },
1377 [IEEE80211_MODE_11B] = { 3, 4, 6, 0, 0 },
1378 [IEEE80211_MODE_11G] = { 3, 4, 6, 0, 0 },
1379 [IEEE80211_MODE_FH] = { 3, 4, 6, 0, 0 },
1380 [IEEE80211_MODE_TURBO_A]= { 2, 3, 5, 0, 0 },
1381 [IEEE80211_MODE_TURBO_G]= { 2, 3, 5, 0, 0 },
1382 [IEEE80211_MODE_STURBO_A]={ 2, 3, 5, 0, 0 },
1383 [IEEE80211_MODE_HALF] = { 3, 4, 6, 0, 0 },
1384 [IEEE80211_MODE_QUARTER]= { 3, 4, 6, 0, 0 },
1385 [IEEE80211_MODE_11NA] = { 3, 4, 6, 0, 0 },
1386 [IEEE80211_MODE_11NG] = { 3, 4, 6, 0, 0 },
1387 [IEEE80211_MODE_VHT_2GHZ] = { 3, 4, 6, 0, 0 },
1388 [IEEE80211_MODE_VHT_5GHZ] = { 3, 4, 6, 0, 0 },
1389};
1391 [IEEE80211_MODE_AUTO] = { 7, 4, 10, 0, 0 },
1392 [IEEE80211_MODE_11A] = { 7, 4, 10, 0, 0 },
1393 [IEEE80211_MODE_11B] = { 7, 4, 10, 0, 0 },
1394 [IEEE80211_MODE_11G] = { 7, 4, 10, 0, 0 },
1395 [IEEE80211_MODE_FH] = { 7, 4, 10, 0, 0 },
1396 [IEEE80211_MODE_TURBO_A]= { 7, 3, 10, 0, 0 },
1397 [IEEE80211_MODE_TURBO_G]= { 7, 3, 10, 0, 0 },
1398 [IEEE80211_MODE_STURBO_A]={ 7, 3, 10, 0, 0 },
1399 [IEEE80211_MODE_HALF] = { 7, 4, 10, 0, 0 },
1400 [IEEE80211_MODE_QUARTER]= { 7, 4, 10, 0, 0 },
1401 [IEEE80211_MODE_11NA] = { 7, 4, 10, 0, 0 },
1402 [IEEE80211_MODE_11NG] = { 7, 4, 10, 0, 0 },
1403 [IEEE80211_MODE_VHT_2GHZ] = { 7, 4, 10, 0, 0 },
1404 [IEEE80211_MODE_VHT_5GHZ] = { 7, 4, 10, 0, 0 },
1405};
1407 [IEEE80211_MODE_AUTO] = { 1, 3, 4, 94, 0 },
1408 [IEEE80211_MODE_11A] = { 1, 3, 4, 94, 0 },
1409 [IEEE80211_MODE_11B] = { 1, 3, 4, 188, 0 },
1410 [IEEE80211_MODE_11G] = { 1, 3, 4, 94, 0 },
1411 [IEEE80211_MODE_FH] = { 1, 3, 4, 188, 0 },
1412 [IEEE80211_MODE_TURBO_A]= { 1, 2, 3, 94, 0 },
1413 [IEEE80211_MODE_TURBO_G]= { 1, 2, 3, 94, 0 },
1414 [IEEE80211_MODE_STURBO_A]={ 1, 2, 3, 94, 0 },
1415 [IEEE80211_MODE_HALF] = { 1, 3, 4, 94, 0 },
1416 [IEEE80211_MODE_QUARTER]= { 1, 3, 4, 94, 0 },
1417 [IEEE80211_MODE_11NA] = { 1, 3, 4, 94, 0 },
1418 [IEEE80211_MODE_11NG] = { 1, 3, 4, 94, 0 },
1419 [IEEE80211_MODE_VHT_2GHZ] = { 1, 3, 4, 94, 0 },
1420 [IEEE80211_MODE_VHT_5GHZ] = { 1, 3, 4, 94, 0 },
1421};
1423 [IEEE80211_MODE_AUTO] = { 1, 2, 3, 47, 0 },
1424 [IEEE80211_MODE_11A] = { 1, 2, 3, 47, 0 },
1425 [IEEE80211_MODE_11B] = { 1, 2, 3, 102, 0 },
1426 [IEEE80211_MODE_11G] = { 1, 2, 3, 47, 0 },
1427 [IEEE80211_MODE_FH] = { 1, 2, 3, 102, 0 },
1428 [IEEE80211_MODE_TURBO_A]= { 1, 2, 2, 47, 0 },
1429 [IEEE80211_MODE_TURBO_G]= { 1, 2, 2, 47, 0 },
1430 [IEEE80211_MODE_STURBO_A]={ 1, 2, 2, 47, 0 },
1431 [IEEE80211_MODE_HALF] = { 1, 2, 3, 47, 0 },
1432 [IEEE80211_MODE_QUARTER]= { 1, 2, 3, 47, 0 },
1433 [IEEE80211_MODE_11NA] = { 1, 2, 3, 47, 0 },
1434 [IEEE80211_MODE_11NG] = { 1, 2, 3, 47, 0 },
1435 [IEEE80211_MODE_VHT_2GHZ] = { 1, 2, 3, 47, 0 },
1436 [IEEE80211_MODE_VHT_5GHZ] = { 1, 2, 3, 47, 0 },
1437};
1438
1440 [IEEE80211_MODE_AUTO] = { 3, 4, 10, 0, 0 },
1441 [IEEE80211_MODE_11A] = { 3, 4, 10, 0, 0 },
1442 [IEEE80211_MODE_11B] = { 3, 4, 10, 0, 0 },
1443 [IEEE80211_MODE_11G] = { 3, 4, 10, 0, 0 },
1444 [IEEE80211_MODE_FH] = { 3, 4, 10, 0, 0 },
1445 [IEEE80211_MODE_TURBO_A]= { 2, 3, 10, 0, 0 },
1446 [IEEE80211_MODE_TURBO_G]= { 2, 3, 10, 0, 0 },
1447 [IEEE80211_MODE_STURBO_A]={ 2, 3, 10, 0, 0 },
1448 [IEEE80211_MODE_HALF] = { 3, 4, 10, 0, 0 },
1449 [IEEE80211_MODE_QUARTER]= { 3, 4, 10, 0, 0 },
1450 [IEEE80211_MODE_11NA] = { 3, 4, 10, 0, 0 },
1451 [IEEE80211_MODE_11NG] = { 3, 4, 10, 0, 0 },
1452};
1454 [IEEE80211_MODE_AUTO] = { 2, 3, 4, 94, 0 },
1455 [IEEE80211_MODE_11A] = { 2, 3, 4, 94, 0 },
1456 [IEEE80211_MODE_11B] = { 2, 3, 4, 188, 0 },
1457 [IEEE80211_MODE_11G] = { 2, 3, 4, 94, 0 },
1458 [IEEE80211_MODE_FH] = { 2, 3, 4, 188, 0 },
1459 [IEEE80211_MODE_TURBO_A]= { 2, 2, 3, 94, 0 },
1460 [IEEE80211_MODE_TURBO_G]= { 2, 2, 3, 94, 0 },
1461 [IEEE80211_MODE_STURBO_A]={ 2, 2, 3, 94, 0 },
1462 [IEEE80211_MODE_HALF] = { 2, 3, 4, 94, 0 },
1463 [IEEE80211_MODE_QUARTER]= { 2, 3, 4, 94, 0 },
1464 [IEEE80211_MODE_11NA] = { 2, 3, 4, 94, 0 },
1465 [IEEE80211_MODE_11NG] = { 2, 3, 4, 94, 0 },
1466};
1468 [IEEE80211_MODE_AUTO] = { 2, 2, 3, 47, 0 },
1469 [IEEE80211_MODE_11A] = { 2, 2, 3, 47, 0 },
1470 [IEEE80211_MODE_11B] = { 2, 2, 3, 102, 0 },
1471 [IEEE80211_MODE_11G] = { 2, 2, 3, 47, 0 },
1472 [IEEE80211_MODE_FH] = { 2, 2, 3, 102, 0 },
1473 [IEEE80211_MODE_TURBO_A]= { 1, 2, 2, 47, 0 },
1474 [IEEE80211_MODE_TURBO_G]= { 1, 2, 2, 47, 0 },
1475 [IEEE80211_MODE_STURBO_A]={ 1, 2, 2, 47, 0 },
1476 [IEEE80211_MODE_HALF] = { 2, 2, 3, 47, 0 },
1477 [IEEE80211_MODE_QUARTER]= { 2, 2, 3, 47, 0 },
1478 [IEEE80211_MODE_11NA] = { 2, 2, 3, 47, 0 },
1479 [IEEE80211_MODE_11NG] = { 2, 2, 3, 47, 0 },
1480};
1481
1482static void
1483_setifsparams(struct wmeParams *wmep, const paramType *phy)
1484{
1485 wmep->wmep_aifsn = phy->aifsn;
1486 wmep->wmep_logcwmin = phy->logcwmin;
1487 wmep->wmep_logcwmax = phy->logcwmax;
1488 wmep->wmep_txopLimit = phy->txopLimit;
1489}
1490
1491static void
1492setwmeparams(struct ieee80211vap *vap, const char *type, int ac,
1493 struct wmeParams *wmep, const paramType *phy)
1494{
1495 wmep->wmep_acm = phy->acm;
1496 _setifsparams(wmep, phy);
1497
1499 "set %s (%s) [acm %u aifsn %u logcwmin %u logcwmax %u txop %u]\n",
1500 ieee80211_wme_acnames[ac], type,
1501 wmep->wmep_acm, wmep->wmep_aifsn, wmep->wmep_logcwmin,
1502 wmep->wmep_logcwmax, wmep->wmep_txopLimit);
1503}
1504
1505static void
1507{
1508 struct ieee80211com *ic = vap->iv_ic;
1509 struct ieee80211_wme_state *wme = &ic->ic_wme;
1510 const paramType *pPhyParam, *pBssPhyParam;
1511 struct wmeParams *wmep;
1512 enum ieee80211_phymode mode;
1513 int i;
1514
1516
1517 if ((ic->ic_caps & IEEE80211_C_WME) == 0 || ic->ic_nrunning > 1)
1518 return;
1519
1520 /*
1521 * Clear the wme cap_info field so a qoscount from a previous
1522 * vap doesn't confuse later code which only parses the beacon
1523 * field and updates hardware when said field changes.
1524 * Otherwise the hardware is programmed with defaults, not what
1525 * the beacon actually announces.
1526 *
1527 * Note that we can't ever have 0xff as an actual value;
1528 * the only valid values are 0..15.
1529 */
1530 wme->wme_wmeChanParams.cap_info = 0xfe;
1531
1532 /*
1533 * Select mode; we can be called early in which case we
1534 * always use auto mode. We know we'll be called when
1535 * entering the RUN state with bsschan setup properly
1536 * so state will eventually get set correctly
1537 */
1539 mode = ieee80211_chan2mode(ic->ic_bsschan);
1540 else
1541 mode = IEEE80211_MODE_AUTO;
1542 for (i = 0; i < WME_NUM_AC; i++) {
1543 switch (i) {
1544 case WME_AC_BK:
1545 pPhyParam = &phyParamForAC_BK[mode];
1546 pBssPhyParam = &phyParamForAC_BK[mode];
1547 break;
1548 case WME_AC_VI:
1549 pPhyParam = &phyParamForAC_VI[mode];
1550 pBssPhyParam = &bssPhyParamForAC_VI[mode];
1551 break;
1552 case WME_AC_VO:
1553 pPhyParam = &phyParamForAC_VO[mode];
1554 pBssPhyParam = &bssPhyParamForAC_VO[mode];
1555 break;
1556 case WME_AC_BE:
1557 default:
1558 pPhyParam = &phyParamForAC_BE[mode];
1559 pBssPhyParam = &bssPhyParamForAC_BE[mode];
1560 break;
1561 }
1562 wmep = &wme->wme_wmeChanParams.cap_wmeParams[i];
1563 if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
1564 setwmeparams(vap, "chan", i, wmep, pPhyParam);
1565 } else {
1566 setwmeparams(vap, "chan", i, wmep, pBssPhyParam);
1567 }
1568 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[i];
1569 setwmeparams(vap, "bss ", i, wmep, pBssPhyParam);
1570 }
1571 /* NB: check ic_bss to avoid NULL deref on initial attach */
1572 if (vap->iv_bss != NULL) {
1573 /*
1574 * Calculate aggressive mode switching threshold based
1575 * on beacon interval. This doesn't need locking since
1576 * we're only called before entering the RUN state at
1577 * which point we start sending beacon frames.
1578 */
1580 (HIGH_PRI_SWITCH_THRESH * vap->iv_bss->ni_intval) / 100;
1581 wme->wme_flags &= ~WME_F_AGGRMODE;
1583 }
1584}
1585
1586void
1588{
1589 struct ieee80211com *ic = vap->iv_ic;
1590
1591 IEEE80211_LOCK(ic);
1593 IEEE80211_UNLOCK(ic);
1594}
1595
1596/*
1597 * Update WME parameters for ourself and the BSS.
1598 */
1599void
1601{
1602 static const paramType aggrParam[IEEE80211_MODE_MAX] = {
1603 [IEEE80211_MODE_AUTO] = { 2, 4, 10, 64, 0 },
1604 [IEEE80211_MODE_11A] = { 2, 4, 10, 64, 0 },
1605 [IEEE80211_MODE_11B] = { 2, 5, 10, 64, 0 },
1606 [IEEE80211_MODE_11G] = { 2, 4, 10, 64, 0 },
1607 [IEEE80211_MODE_FH] = { 2, 5, 10, 64, 0 },
1608 [IEEE80211_MODE_TURBO_A] = { 1, 3, 10, 64, 0 },
1609 [IEEE80211_MODE_TURBO_G] = { 1, 3, 10, 64, 0 },
1610 [IEEE80211_MODE_STURBO_A] = { 1, 3, 10, 64, 0 },
1611 [IEEE80211_MODE_HALF] = { 2, 4, 10, 64, 0 },
1612 [IEEE80211_MODE_QUARTER] = { 2, 4, 10, 64, 0 },
1613 [IEEE80211_MODE_11NA] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/
1614 [IEEE80211_MODE_11NG] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/
1615 [IEEE80211_MODE_VHT_2GHZ] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/
1616 [IEEE80211_MODE_VHT_5GHZ] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/
1617 };
1618 struct ieee80211com *ic = vap->iv_ic;
1619 struct ieee80211_wme_state *wme = &ic->ic_wme;
1620 const struct wmeParams *wmep;
1621 struct wmeParams *chanp, *bssp;
1622 enum ieee80211_phymode mode;
1623 int i;
1624 int do_aggrmode = 0;
1625
1626 /*
1627 * Set up the channel access parameters for the physical
1628 * device. First populate the configured settings.
1629 */
1630 for (i = 0; i < WME_NUM_AC; i++) {
1631 chanp = &wme->wme_chanParams.cap_wmeParams[i];
1632 wmep = &wme->wme_wmeChanParams.cap_wmeParams[i];
1633 chanp->wmep_aifsn = wmep->wmep_aifsn;
1634 chanp->wmep_logcwmin = wmep->wmep_logcwmin;
1635 chanp->wmep_logcwmax = wmep->wmep_logcwmax;
1636 chanp->wmep_txopLimit = wmep->wmep_txopLimit;
1637
1638 chanp = &wme->wme_bssChanParams.cap_wmeParams[i];
1639 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[i];
1640 chanp->wmep_aifsn = wmep->wmep_aifsn;
1641 chanp->wmep_logcwmin = wmep->wmep_logcwmin;
1642 chanp->wmep_logcwmax = wmep->wmep_logcwmax;
1643 chanp->wmep_txopLimit = wmep->wmep_txopLimit;
1644 }
1645
1646 /*
1647 * Select mode; we can be called early in which case we
1648 * always use auto mode. We know we'll be called when
1649 * entering the RUN state with bsschan setup properly
1650 * so state will eventually get set correctly
1651 */
1653 mode = ieee80211_chan2mode(ic->ic_bsschan);
1654 else
1655 mode = IEEE80211_MODE_AUTO;
1656
1657 /*
1658 * This implements aggressive mode as found in certain
1659 * vendors' AP's. When there is significant high
1660 * priority (VI/VO) traffic in the BSS throttle back BE
1661 * traffic by using conservative parameters. Otherwise
1662 * BE uses aggressive params to optimize performance of
1663 * legacy/non-QoS traffic.
1664 */
1665
1666 /* Hostap? Only if aggressive mode is enabled */
1667 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
1668 (wme->wme_flags & WME_F_AGGRMODE) != 0)
1669 do_aggrmode = 1;
1670
1671 /*
1672 * Station? Only if we're in a non-QoS BSS.
1673 */
1674 else if ((vap->iv_opmode == IEEE80211_M_STA &&
1675 (vap->iv_bss->ni_flags & IEEE80211_NODE_QOS) == 0))
1676 do_aggrmode = 1;
1677
1678 /*
1679 * IBSS? Only if we we have WME enabled.
1680 */
1681 else if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
1682 (vap->iv_flags & IEEE80211_F_WME))
1683 do_aggrmode = 1;
1684
1685 /*
1686 * If WME is disabled on this VAP, default to aggressive mode
1687 * regardless of the configuration.
1688 */
1689 if ((vap->iv_flags & IEEE80211_F_WME) == 0)
1690 do_aggrmode = 1;
1691
1692 /* XXX WDS? */
1693
1694 /* XXX MBSS? */
1695
1696 if (do_aggrmode) {
1697 chanp = &wme->wme_chanParams.cap_wmeParams[WME_AC_BE];
1699
1700 chanp->wmep_aifsn = bssp->wmep_aifsn = aggrParam[mode].aifsn;
1701 chanp->wmep_logcwmin = bssp->wmep_logcwmin =
1702 aggrParam[mode].logcwmin;
1703 chanp->wmep_logcwmax = bssp->wmep_logcwmax =
1704 aggrParam[mode].logcwmax;
1705 chanp->wmep_txopLimit = bssp->wmep_txopLimit =
1706 (vap->iv_flags & IEEE80211_F_BURST) ?
1707 aggrParam[mode].txopLimit : 0;
1709 "update %s (chan+bss) [acm %u aifsn %u logcwmin %u "
1710 "logcwmax %u txop %u]\n", ieee80211_wme_acnames[WME_AC_BE],
1711 chanp->wmep_acm, chanp->wmep_aifsn, chanp->wmep_logcwmin,
1712 chanp->wmep_logcwmax, chanp->wmep_txopLimit);
1713 }
1714
1715 /*
1716 * Change the contention window based on the number of associated
1717 * stations. If the number of associated stations is 1 and
1718 * aggressive mode is enabled, lower the contention window even
1719 * further.
1720 */
1721 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
1722 vap->iv_sta_assoc < 2 && (wme->wme_flags & WME_F_AGGRMODE) != 0) {
1723 static const uint8_t logCwMin[IEEE80211_MODE_MAX] = {
1724 [IEEE80211_MODE_AUTO] = 3,
1725 [IEEE80211_MODE_11A] = 3,
1726 [IEEE80211_MODE_11B] = 4,
1727 [IEEE80211_MODE_11G] = 3,
1728 [IEEE80211_MODE_FH] = 4,
1732 [IEEE80211_MODE_HALF] = 3,
1734 [IEEE80211_MODE_11NA] = 3,
1735 [IEEE80211_MODE_11NG] = 3,
1738 };
1739 chanp = &wme->wme_chanParams.cap_wmeParams[WME_AC_BE];
1741
1742 chanp->wmep_logcwmin = bssp->wmep_logcwmin = logCwMin[mode];
1744 "update %s (chan+bss) logcwmin %u\n",
1746 }
1747
1748 /* schedule the deferred WME update */
1749 ieee80211_runtask(ic, &vap->iv_wme_task);
1750
1752 "%s: WME params updated, cap_info 0x%x\n", __func__,
1753 vap->iv_opmode == IEEE80211_M_STA ?
1756}
1757
1758void
1760{
1761 struct ieee80211com *ic = vap->iv_ic;
1762
1763 if (ic->ic_caps & IEEE80211_C_WME) {
1764 IEEE80211_LOCK(ic);
1766 IEEE80211_UNLOCK(ic);
1767 }
1768}
1769
1770/*
1771 * Fetch the WME parameters for the given VAP.
1772 *
1773 * When net80211 grows p2p, etc support, this may return different
1774 * parameters for each VAP.
1775 */
1776void
1778{
1779
1780 memcpy(wp, &vap->iv_ic->ic_wme.wme_chanParams, sizeof(*wp));
1781}
1782
1783/*
1784 * For NICs which only support one set of WME paramaters (ie, softmac NICs)
1785 * there may be different VAP WME parameters but only one is "active".
1786 * This returns the "NIC" WME parameters for the currently active
1787 * context.
1788 */
1789void
1791{
1792
1793 memcpy(wp, &ic->ic_wme.wme_chanParams, sizeof(*wp));
1794}
1795
1796/*
1797 * Return whether to use QoS on a given WME queue.
1798 *
1799 * This is intended to be called from the transmit path of softmac drivers
1800 * which are setting NoAck bits in transmit descriptors.
1801 *
1802 * Ideally this would be set in some transmit field before the packet is
1803 * queued to the driver but net80211 isn't quite there yet.
1804 */
1805int
1807{
1808 /* Bounds/sanity check */
1809 if (ac < 0 || ac >= WME_NUM_AC)
1810 return (0);
1811
1812 /* Again, there's only one global context for now */
1814}
1815
1816static void
1817parent_updown(void *arg, int npending)
1818{
1819 struct ieee80211com *ic = arg;
1820
1821 ic->ic_parent(ic);
1822}
1823
1824static void
1825update_mcast(void *arg, int npending)
1826{
1827 struct ieee80211com *ic = arg;
1828
1829 ic->ic_update_mcast(ic);
1830}
1831
1832static void
1833update_promisc(void *arg, int npending)
1834{
1835 struct ieee80211com *ic = arg;
1836
1837 ic->ic_update_promisc(ic);
1838}
1839
1840static void
1841update_channel(void *arg, int npending)
1842{
1843 struct ieee80211com *ic = arg;
1844
1845 ic->ic_set_channel(ic);
1847}
1848
1849static void
1850update_chw(void *arg, int npending)
1851{
1852 struct ieee80211com *ic = arg;
1853
1854 /*
1855 * XXX should we defer the channel width _config_ update until now?
1856 */
1857 ic->ic_update_chw(ic);
1858}
1859
1860/*
1861 * Deferred WME parameter and beacon update.
1862 *
1863 * In preparation for per-VAP WME configuration, call the VAP
1864 * method if the VAP requires it. Otherwise, just call the
1865 * older global method. There isn't a per-VAP WME configuration
1866 * just yet so for now just use the global configuration.
1867 */
1868static void
1869vap_update_wme(void *arg, int npending)
1870{
1871 struct ieee80211vap *vap = arg;
1872 struct ieee80211com *ic = vap->iv_ic;
1873 struct ieee80211_wme_state *wme = &ic->ic_wme;
1874
1875 /* Driver update */
1876 if (vap->iv_wme_update != NULL)
1877 vap->iv_wme_update(vap,
1879 else
1880 ic->ic_wme.wme_update(ic);
1881
1882 IEEE80211_LOCK(ic);
1883 /*
1884 * Arrange for the beacon update.
1885 *
1886 * XXX what about MBSS, WDS?
1887 */
1888 if (vap->iv_opmode == IEEE80211_M_HOSTAP
1889 || vap->iv_opmode == IEEE80211_M_IBSS) {
1890 /*
1891 * Arrange for a beacon update and bump the parameter
1892 * set number so associated stations load the new values.
1893 */
1897 }
1898 IEEE80211_UNLOCK(ic);
1899}
1900
1901static void
1902restart_vaps(void *arg, int npending)
1903{
1904 struct ieee80211com *ic = arg;
1905
1908}
1909
1910/*
1911 * Block until the parent is in a known state. This is
1912 * used after any operations that dispatch a task (e.g.
1913 * to auto-configure the parent device up/down).
1914 */
1915void
1917{
1918 taskqueue_block(ic->ic_tq);
1925 taskqueue_unblock(ic->ic_tq);
1926}
1927
1928/*
1929 * Check to see whether the current channel needs reset.
1930 *
1931 * Some devices don't handle being given an invalid channel
1932 * in their operating mode very well (eg wpi(4) will throw a
1933 * firmware exception.)
1934 *
1935 * Return 0 if we're ok, 1 if the channel needs to be reset.
1936 *
1937 * See PR kern/202502.
1938 */
1939static int
1941{
1942 struct ieee80211com *ic = vap->iv_ic;
1943
1944 if ((vap->iv_opmode == IEEE80211_M_IBSS &&
1946 (vap->iv_opmode == IEEE80211_M_HOSTAP &&
1948 return (1);
1949 return (0);
1950}
1951
1952/*
1953 * Reset the curchan to a known good state.
1954 */
1955static void
1957{
1958 struct ieee80211com *ic = vap->iv_ic;
1959
1960 ic->ic_curchan = &ic->ic_channels[0];
1961}
1962
1963/*
1964 * Start a vap running. If this is the first vap to be
1965 * set running on the underlying device then we
1966 * automatically bring the device up.
1967 */
1968void
1970{
1971 struct ifnet *ifp = vap->iv_ifp;
1972 struct ieee80211com *ic = vap->iv_ic;
1973
1975
1978 "start running, %d vaps running\n", ic->ic_nrunning);
1979
1980 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
1981 /*
1982 * Mark us running. Note that it's ok to do this first;
1983 * if we need to bring the parent device up we defer that
1984 * to avoid dropping the com lock. We expect the device
1985 * to respond to being marked up by calling back into us
1986 * through ieee80211_start_all at which point we'll come
1987 * back in here and complete the work.
1988 */
1989 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1991
1992 /*
1993 * We are not running; if this we are the first vap
1994 * to be brought up auto-up the parent if necessary.
1995 */
1996 if (ic->ic_nrunning++ == 0) {
1997 /* reset the channel to a known good channel */
2000
2003 "%s: up parent %s\n", __func__, ic->ic_name);
2005 return;
2006 }
2007 }
2008 /*
2009 * If the parent is up and running, then kick the
2010 * 802.11 state machine as appropriate.
2011 */
2013 if (vap->iv_opmode == IEEE80211_M_STA) {
2014#if 0
2015 /* XXX bypasses scan too easily; disable for now */
2016 /*
2017 * Try to be intelligent about clocking the state
2018 * machine. If we're currently in RUN state then
2019 * we should be able to apply any new state/parameters
2020 * simply by re-associating. Otherwise we need to
2021 * re-scan to select an appropriate ap.
2022 */
2023 if (vap->iv_state >= IEEE80211_S_RUN)
2026 else
2027#endif
2029 IEEE80211_S_SCAN, 0);
2030 } else {
2031 /*
2032 * For monitor+wds mode there's nothing to do but
2033 * start running. Otherwise if this is the first
2034 * vap to be brought up, start a scan which may be
2035 * preempted if the station is locked to a particular
2036 * channel.
2037 */
2039 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
2040 vap->iv_opmode == IEEE80211_M_WDS)
2042 IEEE80211_S_RUN, -1);
2043 else
2045 IEEE80211_S_SCAN, 0);
2046 }
2047 }
2048}
2049
2050/*
2051 * Start a single vap.
2052 */
2053void
2055{
2056 struct ieee80211vap *vap = arg;
2057
2059 "%s\n", __func__);
2060
2061 IEEE80211_LOCK(vap->iv_ic);
2063 IEEE80211_UNLOCK(vap->iv_ic);
2064}
2065
2066/*
2067 * Start all runnable vap's on a device.
2068 */
2069void
2071{
2072 struct ieee80211vap *vap;
2073
2074 IEEE80211_LOCK(ic);
2075 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2076 struct ifnet *ifp = vap->iv_ifp;
2077 if (IFNET_IS_UP_RUNNING(ifp)) /* NB: avoid recursion */
2079 }
2080 IEEE80211_UNLOCK(ic);
2081}
2082
2083/*
2084 * Stop a vap. We force it down using the state machine
2085 * then mark it's ifnet not running. If this is the last
2086 * vap running on the underlying device then we close it
2087 * too to insure it will be properly initialized when the
2088 * next vap is brought up.
2089 */
2090void
2092{
2093 struct ieee80211com *ic = vap->iv_ic;
2094 struct ifnet *ifp = vap->iv_ifp;
2095
2097
2099 "stop running, %d vaps running\n", ic->ic_nrunning);
2100
2102 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
2103 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; /* mark us stopped */
2105 if (--ic->ic_nrunning == 0) {
2108 "down parent %s\n", ic->ic_name);
2110 }
2111 }
2112}
2113
2114void
2116{
2117 struct ieee80211com *ic = vap->iv_ic;
2118
2119 IEEE80211_LOCK(ic);
2121 IEEE80211_UNLOCK(ic);
2122}
2123
2124/*
2125 * Stop all vap's running on a device.
2126 */
2127void
2129{
2130 struct ieee80211vap *vap;
2131
2132 IEEE80211_LOCK(ic);
2133 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2134 struct ifnet *ifp = vap->iv_ifp;
2135 if (IFNET_IS_UP_RUNNING(ifp)) /* NB: avoid recursion */
2137 }
2138 IEEE80211_UNLOCK(ic);
2139
2141}
2142
2143/*
2144 * Stop all vap's running on a device and arrange
2145 * for those that were running to be resumed.
2146 */
2147void
2149{
2150 struct ieee80211vap *vap;
2151
2152 IEEE80211_LOCK(ic);
2153 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2154 struct ifnet *ifp = vap->iv_ifp;
2155 if (IFNET_IS_UP_RUNNING(ifp)) { /* NB: avoid recursion */
2158 }
2159 }
2160 IEEE80211_UNLOCK(ic);
2161
2163}
2164
2165/*
2166 * Start all vap's marked for resume.
2167 */
2168void
2170{
2171 struct ieee80211vap *vap;
2172
2173 IEEE80211_LOCK(ic);
2174 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2175 struct ifnet *ifp = vap->iv_ifp;
2176 if (!IFNET_IS_UP_RUNNING(ifp) &&
2178 vap->iv_flags_ext &= ~IEEE80211_FEXT_RESUME;
2180 }
2181 }
2182 IEEE80211_UNLOCK(ic);
2183}
2184
2185/*
2186 * Restart all vap's running on a device.
2187 */
2188void
2190{
2191 /*
2192 * NB: do not use ieee80211_runtask here, we will
2193 * block & drain net80211 taskqueue.
2194 */
2195 taskqueue_enqueue(taskqueue_thread, &ic->ic_restart_task);
2196}
2197
2198void
2200{
2201 IEEE80211_LOCK(ic);
2202 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
2203 /* Process in a taskq, the handler may reenter the driver */
2205 }
2206 IEEE80211_UNLOCK(ic);
2207}
2208
2209static void
2210beacon_miss(void *arg, int npending)
2211{
2212 struct ieee80211com *ic = arg;
2213 struct ieee80211vap *vap;
2214
2215 IEEE80211_LOCK(ic);
2216 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2217 /*
2218 * We only pass events through for sta vap's in RUN+ state;
2219 * may be too restrictive but for now this saves all the
2220 * handlers duplicating these checks.
2221 */
2222 if (vap->iv_opmode == IEEE80211_M_STA &&
2223 vap->iv_state >= IEEE80211_S_RUN &&
2224 vap->iv_bmiss != NULL)
2225 vap->iv_bmiss(vap);
2226 }
2227 IEEE80211_UNLOCK(ic);
2228}
2229
2230static void
2231beacon_swmiss(void *arg, int npending)
2232{
2233 struct ieee80211vap *vap = arg;
2234 struct ieee80211com *ic = vap->iv_ic;
2235
2236 IEEE80211_LOCK(ic);
2237 if (vap->iv_state >= IEEE80211_S_RUN) {
2238 /* XXX Call multiple times if npending > zero? */
2239 vap->iv_bmiss(vap);
2240 }
2241 IEEE80211_UNLOCK(ic);
2242}
2243
2244/*
2245 * Software beacon miss handling. Check if any beacons
2246 * were received in the last period. If not post a
2247 * beacon miss; otherwise reset the counter.
2248 */
2249void
2251{
2252 struct ieee80211vap *vap = arg;
2253 struct ieee80211com *ic = vap->iv_ic;
2254
2256
2257 KASSERT(vap->iv_state >= IEEE80211_S_RUN,
2258 ("wrong state %d", vap->iv_state));
2259
2260 if (ic->ic_flags & IEEE80211_F_SCAN) {
2261 /*
2262 * If scanning just ignore and reset state. If we get a
2263 * bmiss after coming out of scan because we haven't had
2264 * time to receive a beacon then we should probe the AP
2265 * before posting a real bmiss (unless iv_bmiss_max has
2266 * been artifiically lowered). A cleaner solution might
2267 * be to disable the timer on scan start/end but to handle
2268 * case of multiple sta vap's we'd need to disable the
2269 * timers of all affected vap's.
2270 */
2271 vap->iv_swbmiss_count = 0;
2272 } else if (vap->iv_swbmiss_count == 0) {
2273 if (vap->iv_bmiss != NULL)
2275 } else
2276 vap->iv_swbmiss_count = 0;
2277 callout_reset(&vap->iv_swbmiss, vap->iv_swbmiss_period,
2278 ieee80211_swbmiss, vap);
2279}
2280
2281/*
2282 * Start an 802.11h channel switch. We record the parameters,
2283 * mark the operation pending, notify each vap through the
2284 * beacon update mechanism so it can update the beacon frame
2285 * contents, and then switch vap's to CSA state to block outbound
2286 * traffic. Devices that handle CSA directly can use the state
2287 * switch to do the right thing so long as they call
2288 * ieee80211_csa_completeswitch when it's time to complete the
2289 * channel change. Devices that depend on the net80211 layer can
2290 * use ieee80211_beacon_update to handle the countdown and the
2291 * channel switch.
2292 */
2293void
2295 struct ieee80211_channel *c, int mode, int count)
2296{
2297 struct ieee80211vap *vap;
2298
2300
2301 ic->ic_csa_newchan = c;
2302 ic->ic_csa_mode = mode;
2303 ic->ic_csa_count = count;
2305 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2306 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
2307 vap->iv_opmode == IEEE80211_M_IBSS ||
2310 /* switch to CSA state to block outbound traffic */
2311 if (vap->iv_state == IEEE80211_S_RUN)
2313 }
2314 ieee80211_notify_csa(ic, c, mode, count);
2315}
2316
2317/*
2318 * Complete the channel switch by transitioning all CSA VAPs to RUN.
2319 * This is called by both the completion and cancellation functions
2320 * so each VAP is placed back in the RUN state and can thus transmit.
2321 */
2322static void
2324{
2325 struct ieee80211vap *vap;
2326
2327 ic->ic_csa_newchan = NULL;
2328 ic->ic_flags &= ~IEEE80211_F_CSAPENDING;
2329
2330 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2331 if (vap->iv_state == IEEE80211_S_CSA)
2333}
2334
2335/*
2336 * Complete an 802.11h channel switch started by ieee80211_csa_startswitch.
2337 * We clear state and move all vap's in CSA state to RUN state
2338 * so they can again transmit.
2339 *
2340 * Although this may not be completely correct, update the BSS channel
2341 * for each VAP to the newly configured channel. The setcurchan sets
2342 * the current operating channel for the interface (so the radio does
2343 * switch over) but the VAP BSS isn't updated, leading to incorrectly
2344 * reported information via ioctl.
2345 */
2346void
2348{
2349 struct ieee80211vap *vap;
2350
2352
2353 KASSERT(ic->ic_flags & IEEE80211_F_CSAPENDING, ("csa not pending"));
2354
2356 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2357 if (vap->iv_state == IEEE80211_S_CSA)
2358 vap->iv_bss->ni_chan = ic->ic_curchan;
2359
2361}
2362
2363/*
2364 * Cancel an 802.11h channel switch started by ieee80211_csa_startswitch.
2365 * We clear state and move all vap's in CSA state to RUN state
2366 * so they can again transmit.
2367 */
2368void
2370{
2372
2374}
2375
2376/*
2377 * Complete a DFS CAC started by ieee80211_dfs_cac_start.
2378 * We clear state and move all vap's in CAC state to RUN state.
2379 */
2380void
2382{
2383 struct ieee80211com *ic = vap0->iv_ic;
2384 struct ieee80211vap *vap;
2385
2386 IEEE80211_LOCK(ic);
2387 /*
2388 * Complete CAC state change for lead vap first; then
2389 * clock all the other vap's waiting.
2390 */
2391 KASSERT(vap0->iv_state == IEEE80211_S_CAC,
2392 ("wrong state %d", vap0->iv_state));
2394
2395 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
2396 if (vap->iv_state == IEEE80211_S_CAC && vap != vap0)
2398 IEEE80211_UNLOCK(ic);
2399}
2400
2401/*
2402 * Force all vap's other than the specified vap to the INIT state
2403 * and mark them as waiting for a scan to complete. These vaps
2404 * will be brought up when the scan completes and the scanning vap
2405 * reaches RUN state by wakeupwaiting.
2406 */
2407static void
2409{
2410 struct ieee80211com *ic = vap0->iv_ic;
2411 struct ieee80211vap *vap;
2412
2414
2415 /*
2416 * A vap list entry can not disappear since we are running on the
2417 * taskqueue and a vap destroy will queue and drain another state
2418 * change task.
2419 */
2420 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2421 if (vap == vap0)
2422 continue;
2423 if (vap->iv_state != IEEE80211_S_INIT) {
2424 /* NB: iv_newstate may drop the lock */
2425 vap->iv_newstate(vap, IEEE80211_S_INIT, 0);
2428 }
2429 }
2430}
2431
2432/*
2433 * Wakeup all vap's waiting for a scan to complete. This is the
2434 * companion to markwaiting (above) and is used to coordinate
2435 * multiple vaps scanning.
2436 * This is called from the state taskqueue.
2437 */
2438static void
2440{
2441 struct ieee80211com *ic = vap0->iv_ic;
2442 struct ieee80211vap *vap;
2443
2445
2446 /*
2447 * A vap list entry can not disappear since we are running on the
2448 * taskqueue and a vap destroy will queue and drain another state
2449 * change task.
2450 */
2451 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
2452 if (vap == vap0)
2453 continue;
2455 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANWAIT;
2456 /* NB: sta's cannot go INIT->RUN */
2457 /* NB: iv_newstate may drop the lock */
2458 vap->iv_newstate(vap,
2459 vap->iv_opmode == IEEE80211_M_STA ?
2462 }
2463 }
2464}
2465
2466/*
2467 * Handle post state change work common to all operating modes.
2468 */
2469static void
2470ieee80211_newstate_cb(void *xvap, int npending)
2471{
2472 struct ieee80211vap *vap = xvap;
2473 struct ieee80211com *ic = vap->iv_ic;
2474 enum ieee80211_state nstate, ostate;
2475 int arg, rc;
2476
2477 IEEE80211_LOCK(ic);
2478 nstate = vap->iv_nstate;
2479 arg = vap->iv_nstate_arg;
2480
2482 /*
2483 * We have been requested to drop back to the INIT before
2484 * proceeding to the new state.
2485 */
2486 /* Deny any state changes while we are here. */
2489 "%s: %s -> %s arg %d\n", __func__,
2491 ieee80211_state_name[vap->iv_nstate], arg);
2492 vap->iv_newstate(vap, vap->iv_nstate, 0);
2496 /* enqueue new state transition after cancel_scan() task */
2497 ieee80211_new_state_locked(vap, nstate, arg);
2498 goto done;
2499 }
2500
2501 ostate = vap->iv_state;
2502 if (nstate == IEEE80211_S_SCAN && ostate != IEEE80211_S_INIT) {
2503 /*
2504 * SCAN was forced; e.g. on beacon miss. Force other running
2505 * vap's to INIT state and mark them as waiting for the scan to
2506 * complete. This insures they don't interfere with our
2507 * scanning. Since we are single threaded the vaps can not
2508 * transition again while we are executing.
2509 *
2510 * XXX not always right, assumes ap follows sta
2511 */
2512 markwaiting(vap);
2513 }
2515 "%s: %s -> %s arg %d\n", __func__,
2516 ieee80211_state_name[ostate], ieee80211_state_name[nstate], arg);
2517
2518 rc = vap->iv_newstate(vap, nstate, arg);
2520 vap->iv_flags_ext &= ~IEEE80211_FEXT_STATEWAIT;
2521 if (rc != 0) {
2522 /* State transition failed */
2523 KASSERT(rc != EINPROGRESS, ("iv_newstate was deferred"));
2524 KASSERT(nstate != IEEE80211_S_INIT,
2525 ("INIT state change failed"));
2527 "%s: %s returned error %d\n", __func__,
2528 ieee80211_state_name[nstate], rc);
2529 goto done;
2530 }
2531
2532 /* No actual transition, skip post processing */
2533 if (ostate == nstate)
2534 goto done;
2535
2536 if (nstate == IEEE80211_S_RUN) {
2537 /*
2538 * OACTIVE may be set on the vap if the upper layer
2539 * tried to transmit (e.g. IPv6 NDP) before we reach
2540 * RUN state. Clear it and restart xmit.
2541 *
2542 * Note this can also happen as a result of SLEEP->RUN
2543 * (i.e. coming out of power save mode).
2544 */
2545 vap->iv_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2546
2547 /*
2548 * XXX TODO Kick-start a VAP queue - this should be a method!
2549 */
2550
2551 /* bring up any vaps waiting on us */
2552 wakeupwaiting(vap);
2553 } else if (nstate == IEEE80211_S_INIT) {
2554 /*
2555 * Flush the scan cache if we did the last scan (XXX?)
2556 * and flush any frames on send queues from this vap.
2557 * Note the mgt q is used only for legacy drivers and
2558 * will go away shortly.
2559 */
2561
2562 /*
2563 * XXX TODO: ic/vap queue flush
2564 */
2565 }
2566done:
2567 IEEE80211_UNLOCK(ic);
2568}
2569
2570/*
2571 * Public interface for initiating a state machine change.
2572 * This routine single-threads the request and coordinates
2573 * the scheduling of multiple vaps for the purpose of selecting
2574 * an operating channel. Specifically the following scenarios
2575 * are handled:
2576 * o only one vap can be selecting a channel so on transition to
2577 * SCAN state if another vap is already scanning then
2578 * mark the caller for later processing and return without
2579 * doing anything (XXX? expectations by caller of synchronous operation)
2580 * o only one vap can be doing CAC of a channel so on transition to
2581 * CAC state if another vap is already scanning for radar then
2582 * mark the caller for later processing and return without
2583 * doing anything (XXX? expectations by caller of synchronous operation)
2584 * o if another vap is already running when a request is made
2585 * to SCAN then an operating channel has been chosen; bypass
2586 * the scan and just join the channel
2587 *
2588 * Note that the state change call is done through the iv_newstate
2589 * method pointer so any driver routine gets invoked. The driver
2590 * will normally call back into operating mode-specific
2591 * ieee80211_newstate routines (below) unless it needs to completely
2592 * bypass the state machine (e.g. because the firmware has it's
2593 * own idea how things should work). Bypassing the net80211 layer
2594 * is usually a mistake and indicates lack of proper integration
2595 * with the net80211 layer.
2596 */
2597int
2599 enum ieee80211_state nstate, int arg)
2600{
2601 struct ieee80211com *ic = vap->iv_ic;
2602 struct ieee80211vap *vp;
2603 enum ieee80211_state ostate;
2604 int nrunning, nscanning;
2605
2607
2609 if (vap->iv_nstate == IEEE80211_S_INIT ||
2610 ((vap->iv_state == IEEE80211_S_INIT ||
2612 vap->iv_nstate == IEEE80211_S_SCAN &&
2613 nstate > IEEE80211_S_SCAN)) {
2614 /*
2615 * XXX The vap is being stopped/started,
2616 * do not allow any other state changes
2617 * until this is completed.
2618 */
2620 "%s: %s -> %s (%s) transition discarded\n",
2621 __func__,
2623 ieee80211_state_name[nstate],
2625 return -1;
2626 } else if (vap->iv_state != vap->iv_nstate) {
2627#if 0
2628 /* Warn if the previous state hasn't completed. */
2630 "%s: pending %s -> %s transition lost\n", __func__,
2633#else
2634 /* XXX temporarily enable to identify issues */
2635 if_printf(vap->iv_ifp,
2636 "%s: pending %s -> %s transition lost\n",
2637 __func__, ieee80211_state_name[vap->iv_state],
2639#endif
2640 }
2641 }
2642
2643 nrunning = nscanning = 0;
2644 /* XXX can track this state instead of calculating */
2645 TAILQ_FOREACH(vp, &ic->ic_vaps, iv_next) {
2646 if (vp != vap) {
2647 if (vp->iv_state >= IEEE80211_S_RUN)
2648 nrunning++;
2649 /* XXX doesn't handle bg scan */
2650 /* NB: CAC+AUTH+ASSOC treated like SCAN */
2651 else if (vp->iv_state > IEEE80211_S_INIT)
2652 nscanning++;
2653 }
2654 }
2655 ostate = vap->iv_state;
2657 "%s: %s -> %s (arg %d) (nrunning %d nscanning %d)\n", __func__,
2658 ieee80211_state_name[ostate], ieee80211_state_name[nstate], arg,
2659 nrunning, nscanning);
2660 switch (nstate) {
2661 case IEEE80211_S_SCAN:
2662 if (ostate == IEEE80211_S_INIT) {
2663 /*
2664 * INIT -> SCAN happens on initial bringup.
2665 */
2666 KASSERT(!(nscanning && nrunning),
2667 ("%d scanning and %d running", nscanning, nrunning));
2668 if (nscanning) {
2669 /*
2670 * Someone is scanning, defer our state
2671 * change until the work has completed.
2672 */
2674 "%s: defer %s -> %s\n",
2675 __func__, ieee80211_state_name[ostate],
2676 ieee80211_state_name[nstate]);
2678 return 0;
2679 }
2680 if (nrunning) {
2681 /*
2682 * Someone is operating; just join the channel
2683 * they have chosen.
2684 */
2685 /* XXX kill arg? */
2686 /* XXX check each opmode, adhoc? */
2687 if (vap->iv_opmode == IEEE80211_M_STA)
2688 nstate = IEEE80211_S_SCAN;
2689 else
2690 nstate = IEEE80211_S_RUN;
2691#ifdef IEEE80211_DEBUG
2692 if (nstate != IEEE80211_S_SCAN) {
2695 "%s: override, now %s -> %s\n",
2696 __func__,
2697 ieee80211_state_name[ostate],
2698 ieee80211_state_name[nstate]);
2699 }
2700#endif
2701 }
2702 }
2703 break;
2704 case IEEE80211_S_RUN:
2705 if (vap->iv_opmode == IEEE80211_M_WDS &&
2707 nscanning) {
2708 /*
2709 * Legacy WDS with someone else scanning; don't
2710 * go online until that completes as we should
2711 * follow the other vap to the channel they choose.
2712 */
2714 "%s: defer %s -> %s (legacy WDS)\n", __func__,
2715 ieee80211_state_name[ostate],
2716 ieee80211_state_name[nstate]);
2718 return 0;
2719 }
2720 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
2724 /*
2725 * This is a DFS channel, transition to CAC state
2726 * instead of RUN. This allows us to initiate
2727 * Channel Availability Check (CAC) as specified
2728 * by 11h/DFS.
2729 */
2730 nstate = IEEE80211_S_CAC;
2732 "%s: override %s -> %s (DFS)\n", __func__,
2733 ieee80211_state_name[ostate],
2734 ieee80211_state_name[nstate]);
2735 }
2736 break;
2737 case IEEE80211_S_INIT:
2738 /* cancel any scan in progress */
2740 if (ostate == IEEE80211_S_INIT ) {
2741 /* XXX don't believe this */
2742 /* INIT -> INIT. nothing to do */
2743 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANWAIT;
2744 }
2745 /* fall thru... */
2746 default:
2747 break;
2748 }
2749 /* defer the state change to a thread */
2750 vap->iv_nstate = nstate;
2751 vap->iv_nstate_arg = arg;
2754 return EINPROGRESS;
2755}
2756
2757int
2759 enum ieee80211_state nstate, int arg)
2760{
2761 struct ieee80211com *ic = vap->iv_ic;
2762 int rc;
2763
2764 IEEE80211_LOCK(ic);
2765 rc = ieee80211_new_state_locked(vap, nstate, arg);
2766 IEEE80211_UNLOCK(ic);
2767 return rc;
2768}
ieee80211_phymode
Definition: _ieee80211.h:61
@ IEEE80211_MODE_11NG
Definition: _ieee80211.h:71
@ IEEE80211_MODE_TURBO_A
Definition: _ieee80211.h:67
@ IEEE80211_MODE_FH
Definition: _ieee80211.h:66
@ IEEE80211_MODE_11NA
Definition: _ieee80211.h:70
@ IEEE80211_MODE_11G
Definition: _ieee80211.h:65
@ IEEE80211_MODE_HALF
Definition: _ieee80211.h:72
@ IEEE80211_MODE_STURBO_A
Definition: _ieee80211.h:69
@ IEEE80211_MODE_VHT_2GHZ
Definition: _ieee80211.h:74
@ IEEE80211_MODE_TURBO_G
Definition: _ieee80211.h:68
@ IEEE80211_MODE_AUTO
Definition: _ieee80211.h:62
@ IEEE80211_MODE_QUARTER
Definition: _ieee80211.h:73
@ IEEE80211_MODE_11B
Definition: _ieee80211.h:64
@ IEEE80211_MODE_VHT_5GHZ
Definition: _ieee80211.h:75
@ IEEE80211_MODE_11A
Definition: _ieee80211.h:63
#define IEEE80211_C_SHSLOT
Definition: _ieee80211.h:484
#define IEEE80211_IS_CHAN_HT(_c)
Definition: _ieee80211.h:291
#define IEEE80211_IS_CHAN_NOADHOC(_c)
Definition: _ieee80211.h:309
#define IEEE80211_IS_CHAN_DFS(_c)
Definition: _ieee80211.h:307
#define IEEE80211_IS_CHAN_CACDONE(_c)
Definition: _ieee80211.h:355
@ IEEE80211_PROT_CTSONLY
Definition: _ieee80211.h:101
#define IEEE80211_C_WME
Definition: _ieee80211.h:497
#define IEEE80211_IS_CHAN_A(_c)
Definition: _ieee80211.h:245
#define IEEE80211_OPMODE_MAX
Definition: _ieee80211.h:94
@ IEEE80211_ROAMING_MANUAL
Definition: _ieee80211.h:134
@ IEEE80211_ROAMING_AUTO
Definition: _ieee80211.h:133
@ IEEE80211_AUTH_SHARED
Definition: _ieee80211.h:115
@ IEEE80211_AUTH_OPEN
Definition: _ieee80211.h:114
@ IEEE80211_AUTH_AUTO
Definition: _ieee80211.h:117
#define IEEE80211_CHAN_ANYC
Definition: _ieee80211.h:165
@ IEEE80211_M_HOSTAP
Definition: _ieee80211.h:90
@ IEEE80211_M_MBSS
Definition: _ieee80211.h:92
@ IEEE80211_M_STA
Definition: _ieee80211.h:87
@ IEEE80211_M_WDS
Definition: _ieee80211.h:88
@ IEEE80211_M_IBSS
Definition: _ieee80211.h:86
@ IEEE80211_M_MONITOR
Definition: _ieee80211.h:91
#define IEEE80211_C_SHPREAMBLE
Definition: _ieee80211.h:485
#define IEEE80211_MODE_MAX
Definition: _ieee80211.h:77
#define IEEE80211_IS_CHAN_ANYG(_c)
Definition: _ieee80211.h:253
#define IEEE80211_IS_CHAN_NOHOSTAP(_c)
Definition: _ieee80211.h:311
#define IEEE80211_RATE_MCS
Definition: _ieee80211.h:403
int ic_printf(struct ieee80211com *ic, const char *fmt,...)
Definition: ieee80211.c:278
const struct ieee80211_rateset * ieee80211_get_suprates(struct ieee80211com *ic, const struct ieee80211_channel *c)
Definition: ieee80211.c:2016
enum ieee80211_phymode ieee80211_chan2mode(const struct ieee80211_channel *chan)
Definition: ieee80211.c:2302
const struct ieee80211_htrateset * ieee80211_get_suphtrates(struct ieee80211com *ic, const struct ieee80211_channel *c)
Definition: ieee80211.c:2024
#define IEEE80211_FC0_TYPE_MASK
Definition: ieee80211.h:118
#define IEEE80211_WEP_KIDLEN
Definition: ieee80211.h:1332
#define IEEE80211_WEP_IVLEN
Definition: ieee80211.h:1331
#define WME_AC_BE
Definition: ieee80211.h:1207
#define WME_NUM_AC
Definition: ieee80211.h:299
#define IEEE80211_HTINFO_OPMODE_MIXED
Definition: ieee80211.h:727
#define WME_AC_VI
Definition: ieee80211.h:1209
#define IEEE80211_FC1_PROTECTED
Definition: ieee80211.h:195
#define IEEE80211_FC1_DIR_DSTODS
Definition: ieee80211.h:186
#define IEEE80211_RATE_VAL
Definition: ieee80211.h:1146
#define IEEE80211_FC0_TYPE_MGT
Definition: ieee80211.h:120
#define WME_AC_BK
Definition: ieee80211.h:1208
#define IEEE80211_RATE_BASIC
Definition: ieee80211.h:1145
#define IEEE80211_FC0_TYPE_DATA
Definition: ieee80211.h:122
#define IEEE80211_HTINFO_NONHT_PRESENT
Definition: ieee80211.h:730
#define WME_QOSINFO_COUNT
Definition: ieee80211.h:336
#define IEEE80211_QOS_HAS_SEQ(wh)
Definition: ieee80211.h:244
#define IEEE80211_FC1_DIR_NODS
Definition: ieee80211.h:183
#define IEEE80211_FC1_DIR_MASK
Definition: ieee80211.h:182
#define IEEE80211_HTINFO_OPMODE_PURE
Definition: ieee80211.h:724
#define IEEE80211_FC1_DIR_FROMDS
Definition: ieee80211.h:185
#define IEEE80211_FC1_DIR_TODS
Definition: ieee80211.h:184
#define IEEE80211_NWID_LEN
Definition: ieee80211.h:219
@ IEEE80211_REASON_MESH_MAX_PEERS
Definition: ieee80211.h:1286
@ IEEE80211_REASON_MESH_INVALID_GTK
Definition: ieee80211.h:1291
@ IEEE80211_REASON_AUTH_LEAVE
Definition: ieee80211.h:1255
@ IEEE80211_REASON_TIMEOUT
Definition: ieee80211.h:1283
@ IEEE80211_REASON_AKMP_INVALID
Definition: ieee80211.h:1271
@ IEEE80211_REASON_IE_INVALID
Definition: ieee80211.h:1264
@ IEEE80211_REASON_DISASSOC_PWRCAP_BAD
Definition: ieee80211.h:1262
@ IEEE80211_REASON_MESH_CHAN_SWITCH_UNSPEC
Definition: ieee80211.h:1299
@ IEEE80211_REASON_MIC_FAILURE
Definition: ieee80211.h:1265
@ IEEE80211_REASON_GROUP_KEY_UPDATE_TIMEOUT
Definition: ieee80211.h:1267
@ IEEE80211_REASON_4WAY_HANDSHAKE_TIMEOUT
Definition: ieee80211.h:1266
@ IEEE80211_REASON_MESH_PERR_NO_PROXY
Definition: ieee80211.h:1294
@ IEEE80211_REASON_MESH_INCONS_PARAMS
Definition: ieee80211.h:1292
@ IEEE80211_REASON_IE_IN_4WAY_DIFFERS
Definition: ieee80211.h:1268
@ IEEE80211_REASON_UNSPECIFIED_QOS
Definition: ieee80211.h:1276
@ IEEE80211_REASON_OUTSIDE_TXOP
Definition: ieee80211.h:1279
@ IEEE80211_REASON_LEAVING_QBSS
Definition: ieee80211.h:1280
@ IEEE80211_REASON_INSUFFICIENT_BW
Definition: ieee80211.h:1277
@ IEEE80211_REASON_UNSUPP_RSN_IE_VERSION
Definition: ieee80211.h:1272
@ IEEE80211_REASON_MESH_CPVIOLATION
Definition: ieee80211.h:1287
@ IEEE80211_REASON_MESH_CONFIRM_TIMEOUT
Definition: ieee80211.h:1290
@ IEEE80211_REASON_MESH_PERR_NO_FI
Definition: ieee80211.h:1295
@ IEEE80211_REASON_SETUP_NEEDED
Definition: ieee80211.h:1282
@ IEEE80211_REASON_BAD_MECHANISM
Definition: ieee80211.h:1281
@ IEEE80211_REASON_ASSOC_NOT_AUTHED
Definition: ieee80211.h:1261
@ IEEE80211_REASON_NOT_AUTHED
Definition: ieee80211.h:1258
@ IEEE80211_REASON_802_1X_AUTH_FAILED
Definition: ieee80211.h:1274
@ IEEE80211_REASON_MESH_INVALID_SECURITY
Definition: ieee80211.h:1293
@ IEEE80211_REASON_MESH_MAX_RETRIES
Definition: ieee80211.h:1289
@ IEEE80211_REASON_MESH_CLOSE_RCVD
Definition: ieee80211.h:1288
@ IEEE80211_REASON_ASSOC_TOOMANY
Definition: ieee80211.h:1257
@ IEEE80211_REASON_MESH_CHAN_SWITCH_REG
Definition: ieee80211.h:1298
@ IEEE80211_REASON_NOT_ASSOCED
Definition: ieee80211.h:1259
@ IEEE80211_REASON_GROUP_CIPHER_INVALID
Definition: ieee80211.h:1269
@ IEEE80211_REASON_MESH_PERR_DEST_UNREACH
Definition: ieee80211.h:1296
@ IEEE80211_REASON_MESH_MAC_ALRDY_EXISTS_MBSS
Definition: ieee80211.h:1297
@ IEEE80211_REASON_TOOMANY_FRAMES
Definition: ieee80211.h:1278
@ IEEE80211_REASON_UNSPECIFIED
Definition: ieee80211.h:1253
@ IEEE80211_REASON_AUTH_EXPIRE
Definition: ieee80211.h:1254
@ IEEE80211_REASON_PAIRWISE_CIPHER_INVALID
Definition: ieee80211.h:1270
@ IEEE80211_REASON_DISASSOC_SUPCHAN_BAD
Definition: ieee80211.h:1263
@ IEEE80211_REASON_ASSOC_LEAVE
Definition: ieee80211.h:1260
@ IEEE80211_REASON_PEER_LINK_CANCELED
Definition: ieee80211.h:1285
@ IEEE80211_REASON_INVALID_RSN_IE_CAP
Definition: ieee80211.h:1273
@ IEEE80211_REASON_ASSOC_EXPIRE
Definition: ieee80211.h:1256
@ IEEE80211_REASON_CIPHER_SUITE_REJECTED
Definition: ieee80211.h:1275
#define IEEE80211_RV(v)
Definition: ieee80211.h:1147
#define IEEE80211_WEP_EXTIVLEN
Definition: ieee80211.h:1347
#define IEEE80211_HTINFO_OPMODE
Definition: ieee80211.h:722
#define IEEE80211_HTINFO_OPMODE_HT20PR
Definition: ieee80211.h:726
#define IEEE80211_QOS_TID
Definition: ieee80211.h:234
#define WME_AC_VO
Definition: ieee80211.h:1210
#define IEEE80211_QOS_ACKPOLICY
Definition: ieee80211.h:228
#define IEEE80211_HTINFO_OPMODE_PROTOPT
Definition: ieee80211.h:725
#define IEEE80211_WEP_EXTIV
Definition: ieee80211.h:1346
void ieee80211_adhoc_attach(struct ieee80211com *ic)
void ieee80211_adhoc_detach(struct ieee80211com *ic)
void ieee80211_notify_csa(struct ieee80211com *ic, const struct ieee80211_channel *c, int mode, int count)
void ieee80211_notify_ifnet_change(struct ieee80211vap *vap)
const char * ieee80211_get_vap_ifname(struct ieee80211vap *vap)
void ieee80211_load_module(const char *modname)
#define IFNET_IS_UP_RUNNING(_ifp)
#define IEEE80211_UNLOCK(_ic)
#define IEEE80211_LOCK_ASSERT(_ic)
#define IEEE80211_LOCK(_ic)
#define IEEE80211_LOCK_OBJ(_ic)
void ieee80211_hostap_attach(struct ieee80211com *ic)
void ieee80211_hostap_detach(struct ieee80211com *ic)
void ieee80211_htinfo_notify(struct ieee80211vap *vap)
void ieee80211_deliver_data(struct ieee80211vap *vap, struct ieee80211_node *ni, struct mbuf *m)
void ieee80211_mesh_detach(struct ieee80211com *ic)
void ieee80211_mesh_attach(struct ieee80211com *ic)
void ieee80211_monitor_detach(struct ieee80211com *ic)
void ieee80211_monitor_attach(struct ieee80211com *ic)
void ieee80211_setcurchan(struct ieee80211com *ic, struct ieee80211_channel *c)
void ieee80211_notify_erp_locked(struct ieee80211com *ic)
#define IEEE80211_NODE_QOS
int ieee80211_send_mgmt(struct ieee80211_node *ni, int type, int arg)
static const struct phyParamType phyParamForAC_BK[IEEE80211_MODE_MAX]
void ieee80211_proto_vattach(struct ieee80211vap *vap)
static void setbasicrates(struct ieee80211_rateset *rs, enum ieee80211_phymode mode, int add)
const struct ieee80211_authenticator * ieee80211_authenticator_get(int auth)
void ieee80211_restart_all(struct ieee80211com *ic)
static void ieee80211_start_reset_chan(struct ieee80211vap *vap)
void ieee80211_stop_locked(struct ieee80211vap *vap)
static const struct phyParamType phyParamForAC_VO[IEEE80211_MODE_MAX]
void ieee80211_addbasicrates(struct ieee80211_rateset *rs, enum ieee80211_phymode mode)
const char * ieee80211_wme_acnames[]
void ieee80211_start_locked(struct ieee80211vap *vap)
const char * ieee80211_reason_to_string(uint16_t reason)
void ieee80211_swbmiss(void *arg)
static const struct phyParamType bssPhyParamForAC_VI[IEEE80211_MODE_MAX]
static void ieee80211_wme_initparams_locked(struct ieee80211vap *vap)
static void vap_update_ht_protmode(void *, int)
#define HIGH_PRI_SWITCH_THRESH
void ieee80211_csa_startswitch(struct ieee80211com *ic, struct ieee80211_channel *c, int mode, int count)
void ieee80211_vap_update_ht_protmode(struct ieee80211vap *vap)
static void restart_vaps(void *, int)
static const struct ieee80211_authenticator auth_internal
void ieee80211_setbasicrates(struct ieee80211_rateset *rs, enum ieee80211_phymode mode)
int ieee80211_wme_vap_ac_is_noack(struct ieee80211vap *vap, int ac)
static const struct phyParamType bssPhyParamForAC_BE[IEEE80211_MODE_MAX]
static const char * auth_modnames[IEEE80211_AUTH_MAX]
void ieee80211_suspend_all(struct ieee80211com *ic)
void ieee80211_proto_vdetach(struct ieee80211vap *vap)
static void vap_update_preamble(void *, int)
static const struct phyParamType phyParamForAC_VI[IEEE80211_MODE_MAX]
static void update_mcast(void *, int)
const char * mgt_subtype_name[]
static const struct ieee80211_aclator * acl
static const struct phyParamType phyParamForAC_BE[IEEE80211_MODE_MAX]
void ieee80211_aclator_register(const struct ieee80211_aclator *iac)
void ieee80211_vap_update_preamble(struct ieee80211vap *vap)
void ieee80211_print_essid(const uint8_t *essid, int len)
int ieee80211_iserp_rateset(const struct ieee80211_rateset *rs)
int ieee80211_new_state(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
const char * ieee80211_state_name[IEEE80211_S_MAX]
void ieee80211_authenticator_unregister(int type)
void ieee80211_csa_cancelswitch(struct ieee80211com *ic)
static void setwmeparams(struct ieee80211vap *vap, const char *type, int ac, struct wmeParams *wmep, const paramType *phy)
void ieee80211_stop(struct ieee80211vap *vap)
__FBSDID("$FreeBSD$")
static void markwaiting(struct ieee80211vap *vap0)
void ieee80211_aclator_unregister(const struct ieee80211_aclator *iac)
void ieee80211_stop_all(struct ieee80211com *ic)
void ieee80211_cac_completeswitch(struct ieee80211vap *vap0)
static __inline int findrix(const struct ieee80211_rateset *rs, int r)
void ieee80211_resume_all(struct ieee80211com *ic)
void ieee80211_start_all(struct ieee80211com *ic)
static const struct ieee80211_authenticator * authenticators[IEEE80211_AUTH_MAX]
void ieee80211_reset_erp(struct ieee80211com *ic)
void ieee80211_wme_updateparams(struct ieee80211vap *vap)
void ieee80211_csa_completeswitch(struct ieee80211com *ic)
int ieee80211_new_state_locked(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
void ieee80211_init(void *arg)
static void null_update_beacon(struct ieee80211vap *vap, int item)
void ieee80211_vap_update_erp_protmode(struct ieee80211vap *vap)
int ieee80211_fix_rate(struct ieee80211_node *ni, struct ieee80211_rateset *nrs, int flags)
static void vap_update_wme(void *, int)
const char * ctl_subtype_name[]
struct phyParamType paramType
static void ieee80211_auth_setup(void)
static void ieee80211_newstate_cb(void *, int)
static void vap_update_slot(void *, int)
void ieee80211_proto_attach(struct ieee80211com *ic)
static void beacon_miss(void *, int)
static void wakeupwaiting(struct ieee80211vap *vap0)
void ieee80211_vap_reset_erp(struct ieee80211vap *vap)
static void parent_updown(void *, int)
static void update_promisc(void *, int)
const struct ieee80211_aclator * ieee80211_aclator_get(const char *name)
static void _setifsparams(struct wmeParams *wmep, const paramType *phy)
static void csa_completeswitch(struct ieee80211com *ic)
void ieee80211_wme_vap_getparams(struct ieee80211vap *vap, struct chanAccParams *wp)
void ieee80211_vap_set_shortslottime(struct ieee80211vap *vap, int onoff)
#define IEEE80211_AUTH_MAX
SYSINIT(wlan_auth, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_auth_setup, NULL)
void ieee80211_wme_updateparams_locked(struct ieee80211vap *vap)
void ieee80211_wme_initparams(struct ieee80211vap *vap)
const char * ieee80211_opmode_name[IEEE80211_OPMODE_MAX]
void ieee80211_dump_pkt(struct ieee80211com *ic, const uint8_t *buf, int len, int rate, int rssi)
static int ieee80211_start_check_reset_chan(struct ieee80211vap *vap)
static const struct phyParamType bssPhyParamForAC_VO[IEEE80211_MODE_MAX]
void ieee80211_proto_detach(struct ieee80211com *ic)
static int null_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, const struct ieee80211_bpf_params *params)
static void update_channel(void *, int)
void ieee80211_beacon_miss(struct ieee80211com *ic)
void ieee80211_authenticator_register(int type, const struct ieee80211_authenticator *auth)
static void vap_update_erp_protmode(void *, int)
static void update_chw(void *, int)
#define AGGRESSIVE_MODE_SWITCH_HYSTERESIS
#define FREEAPPIE(ie)
void ieee80211_wme_ic_getparams(struct ieee80211com *ic, struct chanAccParams *wp)
void ieee80211_waitfor_parent(struct ieee80211com *ic)
static void beacon_swmiss(void *, int)
#define IEEE80211_F_DODEL
#define IEEE80211_F_DONEGO
#define IEEE80211_F_DOBRS
#define IEEE80211_S_MAX
ieee80211_state
@ IEEE80211_S_CSA
@ IEEE80211_S_RUN
@ IEEE80211_S_SCAN
@ IEEE80211_S_INIT
@ IEEE80211_S_CAC
@ IEEE80211_S_ASSOC
#define IEEE80211_F_DOSORT
#define IEEE80211_F_DOFMCS
#define IEEE80211_F_JOIN
@ IEEE80211_BEACON_CSA
@ IEEE80211_BEACON_WME
static __inline const char * ieee80211_mgt_subtype_name(uint8_t subtype)
#define WME_F_AGGRMODE
#define IEEE80211_F_DOFRATE
void ieee80211_radiotap_chan_change(struct ieee80211com *ic)
void ieee80211_cancel_scan(struct ieee80211vap *vap)
void ieee80211_scan_flush(struct ieee80211vap *vap)
void ieee80211_sta_detach(struct ieee80211com *ic)
Definition: ieee80211_sta.c:89
void ieee80211_sta_attach(struct ieee80211com *ic)
Definition: ieee80211_sta.c:83
#define IEEE80211_FEXT_DFS
#define IEEE80211_MSG_STATE
static __inline int ieee80211_anyhdrspace(struct ieee80211com *ic, const void *data)
#define IEEE80211_TXMAX_DEFAULT
Definition: ieee80211_var.h:82
#define IEEE80211_MSG_XRATE
#define IEEE80211_F_SCAN
#define IEEE80211_F_WME
#define IEEE80211_FEXT_NONERP_PR
#define IEEE80211_RTS_DEFAULT
Definition: ieee80211_var.h:84
#define IEEE80211_F_USEBARKER
#define IEEE80211_F_SHPREAMBLE
#define IEEE80211_F_BURST
#define IEEE80211_FEXT_WDSLEGACY
#define IEEE80211_FIXED_RATE_NONE
Definition: ieee80211_var.h:81
#define IEEE80211_BMISS_MAX
Definition: ieee80211_var.h:66
#define IEEE80211_FEXT_REINIT
#define IEEE80211_MSG_11N
#define IEEE80211_F_CSAPENDING
#define IEEE80211_FEXT_STATEWAIT
#define IEEE80211_FRAG_DEFAULT
Definition: ieee80211_var.h:85
#define IEEE80211_FHT_NONHT_PR
#define IEEE80211_MSG_DEBUG
#define IEEE80211_NOTE(_vap, _m, _ni, _fmt,...)
#define IEEE80211_MSG_WME
#define IEEE80211_F_USEPROT
static __inline void ieee80211_runtask(struct ieee80211com *ic, struct task *task)
#define IEEE80211_DPRINTF(_vap, _m, _fmt,...)
#define IEEE80211_F_SHSLOT
#define IEEE80211_FEXT_RESUME
#define IEEE80211_FEXT_SCANWAIT
static __inline void ieee80211_beacon_notify(struct ieee80211vap *vap, int what)
static __inline void ieee80211_draintask(struct ieee80211com *ic, struct task *task)
void ieee80211_wds_attach(struct ieee80211com *ic)
Definition: ieee80211_wds.c:75
void ieee80211_wds_detach(struct ieee80211com *ic)
Definition: ieee80211_wds.c:81
struct wmeParams cap_wmeParams[WME_NUM_AC]
const char * iac_name
void(* iac_detach)(struct ieee80211vap *)
void(* ia_detach)(struct ieee80211vap *)
uint8_t i_addr1[IEEE80211_ADDR_LEN]
Definition: ieee80211.h:70
uint8_t i_addr2[IEEE80211_ADDR_LEN]
Definition: ieee80211.h:71
uint8_t i_fc[2]
Definition: ieee80211.h:68
uint8_t i_addr3[IEEE80211_ADDR_LEN]
Definition: ieee80211.h:72
struct ieee80211com * ni_ic
struct ieee80211vap * ni_vap
uint16_t ni_intval
struct ieee80211_channel * ni_chan
uint8_t i_qos[2]
Definition: ieee80211.h:85
uint8_t rs_rates[IEEE80211_RATE_MAXSIZE]
Definition: _ieee80211.h:387
int(* wme_update)(struct ieee80211com *)
struct chanAccParams wme_wmeChanParams
struct chanAccParams wme_chanParams
struct chanAccParams wme_bssChanParams
struct chanAccParams wme_wmeBssChanParams
struct ieee80211_channel * ic_bsschan
struct ieee80211_channel * ic_csa_newchan
enum ieee80211_opmode ic_opmode
const char * ic_name
uint32_t ic_flags_ext
void(* ic_update_promisc)(struct ieee80211com *)
int(* ic_raw_xmit)(struct ieee80211_node *, struct mbuf *, const struct ieee80211_bpf_params *)
struct task ic_restart_task
uint32_t ic_flags
ieee80211vap_attach ic_vattach[IEEE80211_OPMODE_MAX]
void(* ic_update_mcast)(struct ieee80211com *)
struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX]
struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX]
struct task ic_parent_task
struct taskqueue * ic_tq
struct task ic_mcast_task
uint8_t ic_curhtprotmode
void(* ic_parent)(struct ieee80211com *)
struct task ic_chw_task
struct ieee80211_wme_state ic_wme
int(* ic_send_mgmt)(struct ieee80211_node *, int, int)
uint8_t ic_modecaps[IEEE80211_MODE_BYTES]
void(* ic_update_chw)(struct ieee80211com *)
struct task ic_bmiss_task
struct task ic_chan_task
uint32_t ic_caps
uint32_t ic_flags_ht
void(* ic_set_channel)(struct ieee80211com *)
short ic_csa_count
struct task ic_promisc_task
uint8_t ic_nrunning
struct ieee80211_channel * ic_curchan
void(* ic_updateslot)(struct ieee80211com *)
struct ieee80211_appie * iv_appie_assocreq
struct ieee80211com * iv_ic
struct task iv_swbmiss_task
uint8_t iv_curhtprotmode
uint16_t iv_rtsthreshold
void(* iv_update_beacon)(struct ieee80211vap *, int)
uint16_t iv_nonerpsta
struct ieee80211_node * iv_bss
struct task iv_wme_task
enum ieee80211_roamingmode iv_roaming
enum ieee80211_opmode iv_opmode
uint16_t iv_swbmiss_count
enum ieee80211_protmode iv_protmode
uint16_t iv_fragthreshold
struct task iv_erp_protmode_task
uint32_t iv_flags_ht
uint16_t iv_sta_assoc
struct task iv_slot_task
struct ieee80211_appie * iv_appie_proberesp
struct ieee80211_appie * iv_appie_probereq
const struct ieee80211_authenticator * iv_auth
uint32_t iv_caps
uint32_t iv_flags
void(* iv_updateslot)(struct ieee80211vap *)
uint32_t iv_flags_ext
enum ieee80211_state iv_state
uint16_t iv_ht40_sta_assoc
enum ieee80211_state iv_nstate
void(* iv_opdetach)(struct ieee80211vap *)
void(* iv_erp_protmode_update)(struct ieee80211vap *)
struct ieee80211_txparam iv_txparms[IEEE80211_MODE_MAX]
struct task iv_preamble_task
struct ieee80211_appie * iv_appie_wpa
void(* iv_ht_protmode_update)(struct ieee80211vap *)
void(* iv_bmiss)(struct ieee80211vap *)
struct task iv_ht_protmode_task
struct ieee80211_appie * iv_appie_beacon
struct callout iv_swbmiss
int(* iv_wme_update)(struct ieee80211vap *, const struct wmeParams *wme_params)
struct ifnet * iv_ifp
struct callout iv_mgtsend
void(* iv_deliver_data)(struct ieee80211vap *, struct ieee80211_node *, struct mbuf *)
uint16_t iv_swbmiss_period
struct task iv_nstate_task
uint16_t iv_longslotsta
struct ieee80211_appie * iv_appie_assocresp
void(* iv_preamble_update)(struct ieee80211vap *)
uint16_t iv_ht_sta_assoc
int(* iv_newstate)(struct ieee80211vap *, enum ieee80211_state, int)
const struct ieee80211_aclator * iv_acl
uint16_t txopLimit
uint8_t wmep_noackPolicy
uint8_t wmep_acm
uint8_t wmep_logcwmax
uint8_t wmep_txopLimit
uint8_t wmep_aifsn
uint8_t wmep_logcwmin