11a1e1d21SSam Leffler /*- 27535e66aSSam Leffler * Copyright (c) 2001 Atsushi Onoe 3b032f27cSSam Leffler * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 41a1e1d21SSam Leffler * All rights reserved. 51a1e1d21SSam Leffler * 61a1e1d21SSam Leffler * Redistribution and use in source and binary forms, with or without 71a1e1d21SSam Leffler * modification, are permitted provided that the following conditions 81a1e1d21SSam Leffler * are met: 91a1e1d21SSam Leffler * 1. Redistributions of source code must retain the above copyright 107535e66aSSam Leffler * notice, this list of conditions and the following disclaimer. 117535e66aSSam Leffler * 2. Redistributions in binary form must reproduce the above copyright 127535e66aSSam Leffler * notice, this list of conditions and the following disclaimer in the 137535e66aSSam Leffler * documentation and/or other materials provided with the distribution. 141a1e1d21SSam Leffler * 157535e66aSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 167535e66aSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 177535e66aSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 187535e66aSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 197535e66aSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 207535e66aSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 217535e66aSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 227535e66aSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 237535e66aSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 247535e66aSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 251a1e1d21SSam Leffler */ 261a1e1d21SSam Leffler 271a1e1d21SSam Leffler #include <sys/cdefs.h> 281a1e1d21SSam Leffler __FBSDID("$FreeBSD$"); 291a1e1d21SSam Leffler 301a1e1d21SSam Leffler /* 311a1e1d21SSam Leffler * IEEE 802.11 protocol support. 321a1e1d21SSam Leffler */ 331a1e1d21SSam Leffler 341a1e1d21SSam Leffler #include "opt_inet.h" 35b032f27cSSam Leffler #include "opt_wlan.h" 361a1e1d21SSam Leffler 371a1e1d21SSam Leffler #include <sys/param.h> 381a1e1d21SSam Leffler #include <sys/kernel.h> 398a1b9b6aSSam Leffler #include <sys/systm.h> 40b032f27cSSam Leffler #include <sys/taskqueue.h> 411a1e1d21SSam Leffler 428a1b9b6aSSam Leffler #include <sys/socket.h> 43b032f27cSSam Leffler #include <sys/sockio.h> 441a1e1d21SSam Leffler 451a1e1d21SSam Leffler #include <net/if.h> 461a1e1d21SSam Leffler #include <net/if_media.h> 478a1b9b6aSSam Leffler #include <net/ethernet.h> /* XXX for ether_sprintf */ 481a1e1d21SSam Leffler 491a1e1d21SSam Leffler #include <net80211/ieee80211_var.h> 50b032f27cSSam Leffler #include <net80211/ieee80211_adhoc.h> 51b032f27cSSam Leffler #include <net80211/ieee80211_sta.h> 52b032f27cSSam Leffler #include <net80211/ieee80211_hostap.h> 53b032f27cSSam Leffler #include <net80211/ieee80211_wds.h> 54b032f27cSSam Leffler #include <net80211/ieee80211_monitor.h> 55b032f27cSSam Leffler #include <net80211/ieee80211_input.h> 561a1e1d21SSam Leffler 578a1b9b6aSSam Leffler /* XXX tunables */ 588a1b9b6aSSam Leffler #define AGGRESSIVE_MODE_SWITCH_HYSTERESIS 3 /* pkts / 100ms */ 598a1b9b6aSSam Leffler #define HIGH_PRI_SWITCH_THRESH 10 /* pkts / 100ms */ 601a1e1d21SSam Leffler 611a1e1d21SSam Leffler const char *ieee80211_mgt_subtype_name[] = { 621a1e1d21SSam Leffler "assoc_req", "assoc_resp", "reassoc_req", "reassoc_resp", 631a1e1d21SSam Leffler "probe_req", "probe_resp", "reserved#6", "reserved#7", 641a1e1d21SSam Leffler "beacon", "atim", "disassoc", "auth", 652949b58fSSam Leffler "deauth", "action", "reserved#14", "reserved#15" 661a1e1d21SSam Leffler }; 678a1b9b6aSSam Leffler const char *ieee80211_ctl_subtype_name[] = { 688a1b9b6aSSam Leffler "reserved#0", "reserved#1", "reserved#2", "reserved#3", 698a1b9b6aSSam Leffler "reserved#3", "reserved#5", "reserved#6", "reserved#7", 708a1b9b6aSSam Leffler "reserved#8", "reserved#9", "ps_poll", "rts", 718a1b9b6aSSam Leffler "cts", "ack", "cf_end", "cf_end_ack" 728a1b9b6aSSam Leffler }; 7349aa47d6SSam Leffler const char *ieee80211_opmode_name[IEEE80211_OPMODE_MAX] = { 7449aa47d6SSam Leffler "IBSS", /* IEEE80211_M_IBSS */ 7549aa47d6SSam Leffler "STA", /* IEEE80211_M_STA */ 76b032f27cSSam Leffler "WDS", /* IEEE80211_M_WDS */ 7749aa47d6SSam Leffler "AHDEMO", /* IEEE80211_M_AHDEMO */ 7849aa47d6SSam Leffler "HOSTAP", /* IEEE80211_M_HOSTAP */ 7949aa47d6SSam Leffler "MONITOR" /* IEEE80211_M_MONITOR */ 8049aa47d6SSam Leffler }; 81a11c9a5cSSam Leffler const char *ieee80211_state_name[IEEE80211_S_MAX] = { 82a11c9a5cSSam Leffler "INIT", /* IEEE80211_S_INIT */ 83a11c9a5cSSam Leffler "SCAN", /* IEEE80211_S_SCAN */ 84a11c9a5cSSam Leffler "AUTH", /* IEEE80211_S_AUTH */ 85a11c9a5cSSam Leffler "ASSOC", /* IEEE80211_S_ASSOC */ 8614fb6b8fSSam Leffler "CAC", /* IEEE80211_S_CAC */ 8714fb6b8fSSam Leffler "RUN", /* IEEE80211_S_RUN */ 8814fb6b8fSSam Leffler "CSA", /* IEEE80211_S_CSA */ 8914fb6b8fSSam Leffler "SLEEP", /* IEEE80211_S_SLEEP */ 90a11c9a5cSSam Leffler }; 918a1b9b6aSSam Leffler const char *ieee80211_wme_acnames[] = { 928a1b9b6aSSam Leffler "WME_AC_BE", 938a1b9b6aSSam Leffler "WME_AC_BK", 948a1b9b6aSSam Leffler "WME_AC_VI", 958a1b9b6aSSam Leffler "WME_AC_VO", 968a1b9b6aSSam Leffler "WME_UPSD", 978a1b9b6aSSam Leffler }; 98a11c9a5cSSam Leffler 99b032f27cSSam Leffler static void parent_updown(void *, int); 100b032f27cSSam Leffler static int ieee80211_new_state_locked(struct ieee80211vap *, 101b032f27cSSam Leffler enum ieee80211_state, int); 1021a1e1d21SSam Leffler 103b032f27cSSam Leffler static int 104b032f27cSSam Leffler null_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 105b032f27cSSam Leffler const struct ieee80211_bpf_params *params) 106b105a069SSam Leffler { 107b032f27cSSam Leffler struct ifnet *ifp = ni->ni_ic->ic_ifp; 108b032f27cSSam Leffler 109b032f27cSSam Leffler if_printf(ifp, "missing ic_raw_xmit callback, drop frame\n"); 110b032f27cSSam Leffler m_freem(m); 111b032f27cSSam Leffler return ENETDOWN; 112b105a069SSam Leffler } 113b105a069SSam Leffler 1141a1e1d21SSam Leffler void 1158a1b9b6aSSam Leffler ieee80211_proto_attach(struct ieee80211com *ic) 1161a1e1d21SSam Leffler { 1178a1b9b6aSSam Leffler struct ifnet *ifp = ic->ic_ifp; 1181a1e1d21SSam Leffler 119b032f27cSSam Leffler /* override the 802.3 setting */ 120b032f27cSSam Leffler ifp->if_hdrlen = ic->ic_headroom 121b032f27cSSam Leffler + sizeof(struct ieee80211_qosframe_addr4) 122b032f27cSSam Leffler + IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN 123b032f27cSSam Leffler + IEEE80211_WEP_EXTIVLEN; 124b032f27cSSam Leffler /* XXX no way to recalculate on ifdetach */ 125b032f27cSSam Leffler if (ALIGN(ifp->if_hdrlen) > max_linkhdr) { 126b032f27cSSam Leffler /* XXX sanity check... */ 127b032f27cSSam Leffler max_linkhdr = ALIGN(ifp->if_hdrlen); 128b032f27cSSam Leffler max_hdr = max_linkhdr + max_protohdr; 129b032f27cSSam Leffler max_datalen = MHLEN - max_hdr; 130b032f27cSSam Leffler } 1312e79ca97SSam Leffler ic->ic_protmode = IEEE80211_PROT_CTSONLY; 132b032f27cSSam Leffler 133b032f27cSSam Leffler TASK_INIT(&ic->ic_parent_task, 0, parent_updown, ifp); 1348a1b9b6aSSam Leffler 1358a1b9b6aSSam Leffler ic->ic_wme.wme_hipri_switch_hysteresis = 1368a1b9b6aSSam Leffler AGGRESSIVE_MODE_SWITCH_HYSTERESIS; 1371a1e1d21SSam Leffler 1381a1e1d21SSam Leffler /* initialize management frame handlers */ 1391a1e1d21SSam Leffler ic->ic_send_mgmt = ieee80211_send_mgmt; 140b032f27cSSam Leffler ic->ic_raw_xmit = null_raw_xmit; 141b032f27cSSam Leffler 142b032f27cSSam Leffler ieee80211_adhoc_attach(ic); 143b032f27cSSam Leffler ieee80211_sta_attach(ic); 144b032f27cSSam Leffler ieee80211_wds_attach(ic); 145b032f27cSSam Leffler ieee80211_hostap_attach(ic); 146b032f27cSSam Leffler ieee80211_monitor_attach(ic); 1471a1e1d21SSam Leffler } 1481a1e1d21SSam Leffler 1491a1e1d21SSam Leffler void 1508a1b9b6aSSam Leffler ieee80211_proto_detach(struct ieee80211com *ic) 1511a1e1d21SSam Leffler { 152b032f27cSSam Leffler ieee80211_monitor_detach(ic); 153b032f27cSSam Leffler ieee80211_hostap_detach(ic); 154b032f27cSSam Leffler ieee80211_wds_detach(ic); 155b032f27cSSam Leffler ieee80211_adhoc_detach(ic); 156b032f27cSSam Leffler ieee80211_sta_detach(ic); 157b032f27cSSam Leffler } 1588a1b9b6aSSam Leffler 159b032f27cSSam Leffler static void 160b032f27cSSam Leffler null_update_beacon(struct ieee80211vap *vap, int item) 161b032f27cSSam Leffler { 162b032f27cSSam Leffler } 163b032f27cSSam Leffler 164b032f27cSSam Leffler void 165b032f27cSSam Leffler ieee80211_proto_vattach(struct ieee80211vap *vap) 166b032f27cSSam Leffler { 167b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 168b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 169b032f27cSSam Leffler int i; 170b032f27cSSam Leffler 171b032f27cSSam Leffler /* override the 802.3 setting */ 172b032f27cSSam Leffler ifp->if_hdrlen = ic->ic_ifp->if_hdrlen; 173b032f27cSSam Leffler 174b032f27cSSam Leffler vap->iv_rtsthreshold = IEEE80211_RTS_DEFAULT; 175b032f27cSSam Leffler vap->iv_fragthreshold = IEEE80211_FRAG_DEFAULT; 176b032f27cSSam Leffler vap->iv_bmiss_max = IEEE80211_BMISS_MAX; 177b032f27cSSam Leffler callout_init(&vap->iv_swbmiss, CALLOUT_MPSAFE); 178b032f27cSSam Leffler callout_init(&vap->iv_mgtsend, CALLOUT_MPSAFE); 179b032f27cSSam Leffler /* 180b032f27cSSam Leffler * Install default tx rate handling: no fixed rate, lowest 181b032f27cSSam Leffler * supported rate for mgmt and multicast frames. Default 182b032f27cSSam Leffler * max retry count. These settings can be changed by the 183b032f27cSSam Leffler * driver and/or user applications. 184b032f27cSSam Leffler */ 185047db6b3SSam Leffler for (i = IEEE80211_MODE_11A; i < IEEE80211_MODE_MAX; i++) { 186b032f27cSSam Leffler const struct ieee80211_rateset *rs = &ic->ic_sup_rates[i]; 187b032f27cSSam Leffler 188b032f27cSSam Leffler vap->iv_txparms[i].ucastrate = IEEE80211_FIXED_RATE_NONE; 189047db6b3SSam Leffler if (i == IEEE80211_MODE_11NA || i == IEEE80211_MODE_11NG) { 190047db6b3SSam Leffler vap->iv_txparms[i].mgmtrate = 0 | IEEE80211_RATE_MCS; 191047db6b3SSam Leffler vap->iv_txparms[i].mcastrate = 0 | IEEE80211_RATE_MCS; 192047db6b3SSam Leffler } else { 193b032f27cSSam Leffler vap->iv_txparms[i].mgmtrate = 194b032f27cSSam Leffler rs->rs_rates[0] & IEEE80211_RATE_VAL; 195b032f27cSSam Leffler vap->iv_txparms[i].mcastrate = 196b032f27cSSam Leffler rs->rs_rates[0] & IEEE80211_RATE_VAL; 197b032f27cSSam Leffler } 198b032f27cSSam Leffler vap->iv_txparms[i].maxretry = IEEE80211_TXMAX_DEFAULT; 199b032f27cSSam Leffler } 200b032f27cSSam Leffler vap->iv_roaming = IEEE80211_ROAMING_AUTO; 201b032f27cSSam Leffler 202b032f27cSSam Leffler vap->iv_update_beacon = null_update_beacon; 203b032f27cSSam Leffler vap->iv_deliver_data = ieee80211_deliver_data; 204b032f27cSSam Leffler 205b032f27cSSam Leffler /* attach support for operating mode */ 206b032f27cSSam Leffler ic->ic_vattach[vap->iv_opmode](vap); 207b032f27cSSam Leffler } 208b032f27cSSam Leffler 209b032f27cSSam Leffler void 210b032f27cSSam Leffler ieee80211_proto_vdetach(struct ieee80211vap *vap) 211b032f27cSSam Leffler { 212b032f27cSSam Leffler #define FREEAPPIE(ie) do { \ 213b032f27cSSam Leffler if (ie != NULL) \ 214e2126decSSam Leffler free(ie, M_80211_NODE_IE); \ 215b032f27cSSam Leffler } while (0) 216b032f27cSSam Leffler /* 217b032f27cSSam Leffler * Detach operating mode module. 218b032f27cSSam Leffler */ 219b032f27cSSam Leffler if (vap->iv_opdetach != NULL) 220b032f27cSSam Leffler vap->iv_opdetach(vap); 2218a1b9b6aSSam Leffler /* 2228a1b9b6aSSam Leffler * This should not be needed as we detach when reseting 2238a1b9b6aSSam Leffler * the state but be conservative here since the 2248a1b9b6aSSam Leffler * authenticator may do things like spawn kernel threads. 2258a1b9b6aSSam Leffler */ 226b032f27cSSam Leffler if (vap->iv_auth->ia_detach != NULL) 227b032f27cSSam Leffler vap->iv_auth->ia_detach(vap); 2288a1b9b6aSSam Leffler /* 2298a1b9b6aSSam Leffler * Detach any ACL'ator. 2308a1b9b6aSSam Leffler */ 231b032f27cSSam Leffler if (vap->iv_acl != NULL) 232b032f27cSSam Leffler vap->iv_acl->iac_detach(vap); 233b032f27cSSam Leffler 234b032f27cSSam Leffler FREEAPPIE(vap->iv_appie_beacon); 235b032f27cSSam Leffler FREEAPPIE(vap->iv_appie_probereq); 236b032f27cSSam Leffler FREEAPPIE(vap->iv_appie_proberesp); 237b032f27cSSam Leffler FREEAPPIE(vap->iv_appie_assocreq); 238b032f27cSSam Leffler FREEAPPIE(vap->iv_appie_assocresp); 239b032f27cSSam Leffler FREEAPPIE(vap->iv_appie_wpa); 240b032f27cSSam Leffler #undef FREEAPPIE 2418a1b9b6aSSam Leffler } 2428a1b9b6aSSam Leffler 2438a1b9b6aSSam Leffler /* 2448a1b9b6aSSam Leffler * Simple-minded authenticator module support. 2458a1b9b6aSSam Leffler */ 2468a1b9b6aSSam Leffler 2478a1b9b6aSSam Leffler #define IEEE80211_AUTH_MAX (IEEE80211_AUTH_WPA+1) 2488a1b9b6aSSam Leffler /* XXX well-known names */ 2498a1b9b6aSSam Leffler static const char *auth_modnames[IEEE80211_AUTH_MAX] = { 2508a1b9b6aSSam Leffler "wlan_internal", /* IEEE80211_AUTH_NONE */ 2518a1b9b6aSSam Leffler "wlan_internal", /* IEEE80211_AUTH_OPEN */ 2528a1b9b6aSSam Leffler "wlan_internal", /* IEEE80211_AUTH_SHARED */ 2538a1b9b6aSSam Leffler "wlan_xauth", /* IEEE80211_AUTH_8021X */ 2548a1b9b6aSSam Leffler "wlan_internal", /* IEEE80211_AUTH_AUTO */ 2558a1b9b6aSSam Leffler "wlan_xauth", /* IEEE80211_AUTH_WPA */ 2568a1b9b6aSSam Leffler }; 2578a1b9b6aSSam Leffler static const struct ieee80211_authenticator *authenticators[IEEE80211_AUTH_MAX]; 2588a1b9b6aSSam Leffler 2598a1b9b6aSSam Leffler static const struct ieee80211_authenticator auth_internal = { 2608a1b9b6aSSam Leffler .ia_name = "wlan_internal", 2618a1b9b6aSSam Leffler .ia_attach = NULL, 2628a1b9b6aSSam Leffler .ia_detach = NULL, 2638a1b9b6aSSam Leffler .ia_node_join = NULL, 2648a1b9b6aSSam Leffler .ia_node_leave = NULL, 2658a1b9b6aSSam Leffler }; 2668a1b9b6aSSam Leffler 2678a1b9b6aSSam Leffler /* 2688a1b9b6aSSam Leffler * Setup internal authenticators once; they are never unregistered. 2698a1b9b6aSSam Leffler */ 2708a1b9b6aSSam Leffler static void 2718a1b9b6aSSam Leffler ieee80211_auth_setup(void) 2728a1b9b6aSSam Leffler { 2738a1b9b6aSSam Leffler ieee80211_authenticator_register(IEEE80211_AUTH_OPEN, &auth_internal); 2748a1b9b6aSSam Leffler ieee80211_authenticator_register(IEEE80211_AUTH_SHARED, &auth_internal); 2758a1b9b6aSSam Leffler ieee80211_authenticator_register(IEEE80211_AUTH_AUTO, &auth_internal); 2768a1b9b6aSSam Leffler } 2778a1b9b6aSSam Leffler SYSINIT(wlan_auth, SI_SUB_DRIVERS, SI_ORDER_FIRST, ieee80211_auth_setup, NULL); 2788a1b9b6aSSam Leffler 2798a1b9b6aSSam Leffler const struct ieee80211_authenticator * 2808a1b9b6aSSam Leffler ieee80211_authenticator_get(int auth) 2818a1b9b6aSSam Leffler { 2828a1b9b6aSSam Leffler if (auth >= IEEE80211_AUTH_MAX) 2838a1b9b6aSSam Leffler return NULL; 2848a1b9b6aSSam Leffler if (authenticators[auth] == NULL) 2858a1b9b6aSSam Leffler ieee80211_load_module(auth_modnames[auth]); 2868a1b9b6aSSam Leffler return authenticators[auth]; 2871a1e1d21SSam Leffler } 2881a1e1d21SSam Leffler 2891a1e1d21SSam Leffler void 2908a1b9b6aSSam Leffler ieee80211_authenticator_register(int type, 2918a1b9b6aSSam Leffler const struct ieee80211_authenticator *auth) 2921a1e1d21SSam Leffler { 2938a1b9b6aSSam Leffler if (type >= IEEE80211_AUTH_MAX) 2948a1b9b6aSSam Leffler return; 2958a1b9b6aSSam Leffler authenticators[type] = auth; 2968a1b9b6aSSam Leffler } 2978a1b9b6aSSam Leffler 2988a1b9b6aSSam Leffler void 2998a1b9b6aSSam Leffler ieee80211_authenticator_unregister(int type) 3008a1b9b6aSSam Leffler { 3018a1b9b6aSSam Leffler 3028a1b9b6aSSam Leffler if (type >= IEEE80211_AUTH_MAX) 3038a1b9b6aSSam Leffler return; 3048a1b9b6aSSam Leffler authenticators[type] = NULL; 3058a1b9b6aSSam Leffler } 3068a1b9b6aSSam Leffler 3078a1b9b6aSSam Leffler /* 3088a1b9b6aSSam Leffler * Very simple-minded ACL module support. 3098a1b9b6aSSam Leffler */ 3108a1b9b6aSSam Leffler /* XXX just one for now */ 3118a1b9b6aSSam Leffler static const struct ieee80211_aclator *acl = NULL; 3128a1b9b6aSSam Leffler 3138a1b9b6aSSam Leffler void 3148a1b9b6aSSam Leffler ieee80211_aclator_register(const struct ieee80211_aclator *iac) 3158a1b9b6aSSam Leffler { 3168a1b9b6aSSam Leffler printf("wlan: %s acl policy registered\n", iac->iac_name); 3178a1b9b6aSSam Leffler acl = iac; 3188a1b9b6aSSam Leffler } 3198a1b9b6aSSam Leffler 3208a1b9b6aSSam Leffler void 3218a1b9b6aSSam Leffler ieee80211_aclator_unregister(const struct ieee80211_aclator *iac) 3228a1b9b6aSSam Leffler { 3238a1b9b6aSSam Leffler if (acl == iac) 3248a1b9b6aSSam Leffler acl = NULL; 3258a1b9b6aSSam Leffler printf("wlan: %s acl policy unregistered\n", iac->iac_name); 3268a1b9b6aSSam Leffler } 3278a1b9b6aSSam Leffler 3288a1b9b6aSSam Leffler const struct ieee80211_aclator * 3298a1b9b6aSSam Leffler ieee80211_aclator_get(const char *name) 3308a1b9b6aSSam Leffler { 3318a1b9b6aSSam Leffler if (acl == NULL) 3328a1b9b6aSSam Leffler ieee80211_load_module("wlan_acl"); 3338a1b9b6aSSam Leffler return acl != NULL && strcmp(acl->iac_name, name) == 0 ? acl : NULL; 3348a1b9b6aSSam Leffler } 3358a1b9b6aSSam Leffler 3368a1b9b6aSSam Leffler void 33768e8e04eSSam Leffler ieee80211_print_essid(const uint8_t *essid, int len) 3388a1b9b6aSSam Leffler { 33968e8e04eSSam Leffler const uint8_t *p; 3401a1e1d21SSam Leffler int i; 3411a1e1d21SSam Leffler 3421a1e1d21SSam Leffler if (len > IEEE80211_NWID_LEN) 3431a1e1d21SSam Leffler len = IEEE80211_NWID_LEN; 3441a1e1d21SSam Leffler /* determine printable or not */ 3451a1e1d21SSam Leffler for (i = 0, p = essid; i < len; i++, p++) { 3461a1e1d21SSam Leffler if (*p < ' ' || *p > 0x7e) 3471a1e1d21SSam Leffler break; 3481a1e1d21SSam Leffler } 3491a1e1d21SSam Leffler if (i == len) { 3501a1e1d21SSam Leffler printf("\""); 3511a1e1d21SSam Leffler for (i = 0, p = essid; i < len; i++, p++) 3521a1e1d21SSam Leffler printf("%c", *p); 3531a1e1d21SSam Leffler printf("\""); 3541a1e1d21SSam Leffler } else { 3551a1e1d21SSam Leffler printf("0x"); 3561a1e1d21SSam Leffler for (i = 0, p = essid; i < len; i++, p++) 3571a1e1d21SSam Leffler printf("%02x", *p); 3581a1e1d21SSam Leffler } 3591a1e1d21SSam Leffler } 3601a1e1d21SSam Leffler 3611a1e1d21SSam Leffler void 36268e8e04eSSam Leffler ieee80211_dump_pkt(struct ieee80211com *ic, 36368e8e04eSSam Leffler const uint8_t *buf, int len, int rate, int rssi) 3641a1e1d21SSam Leffler { 3658a1b9b6aSSam Leffler const struct ieee80211_frame *wh; 3661a1e1d21SSam Leffler int i; 3671a1e1d21SSam Leffler 3688a1b9b6aSSam Leffler wh = (const struct ieee80211_frame *)buf; 3691a1e1d21SSam Leffler switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) { 3701a1e1d21SSam Leffler case IEEE80211_FC1_DIR_NODS: 3711a1e1d21SSam Leffler printf("NODS %s", ether_sprintf(wh->i_addr2)); 3721a1e1d21SSam Leffler printf("->%s", ether_sprintf(wh->i_addr1)); 3731a1e1d21SSam Leffler printf("(%s)", ether_sprintf(wh->i_addr3)); 3741a1e1d21SSam Leffler break; 3751a1e1d21SSam Leffler case IEEE80211_FC1_DIR_TODS: 3761a1e1d21SSam Leffler printf("TODS %s", ether_sprintf(wh->i_addr2)); 3771a1e1d21SSam Leffler printf("->%s", ether_sprintf(wh->i_addr3)); 3781a1e1d21SSam Leffler printf("(%s)", ether_sprintf(wh->i_addr1)); 3791a1e1d21SSam Leffler break; 3801a1e1d21SSam Leffler case IEEE80211_FC1_DIR_FROMDS: 3811a1e1d21SSam Leffler printf("FRDS %s", ether_sprintf(wh->i_addr3)); 3821a1e1d21SSam Leffler printf("->%s", ether_sprintf(wh->i_addr1)); 3831a1e1d21SSam Leffler printf("(%s)", ether_sprintf(wh->i_addr2)); 3841a1e1d21SSam Leffler break; 3851a1e1d21SSam Leffler case IEEE80211_FC1_DIR_DSTODS: 38668e8e04eSSam Leffler printf("DSDS %s", ether_sprintf((const uint8_t *)&wh[1])); 3871a1e1d21SSam Leffler printf("->%s", ether_sprintf(wh->i_addr3)); 3881a1e1d21SSam Leffler printf("(%s", ether_sprintf(wh->i_addr2)); 3891a1e1d21SSam Leffler printf("->%s)", ether_sprintf(wh->i_addr1)); 3901a1e1d21SSam Leffler break; 3911a1e1d21SSam Leffler } 3921a1e1d21SSam Leffler switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) { 3931a1e1d21SSam Leffler case IEEE80211_FC0_TYPE_DATA: 3941a1e1d21SSam Leffler printf(" data"); 3951a1e1d21SSam Leffler break; 3961a1e1d21SSam Leffler case IEEE80211_FC0_TYPE_MGT: 3971a1e1d21SSam Leffler printf(" %s", ieee80211_mgt_subtype_name[ 3981a1e1d21SSam Leffler (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) 3991a1e1d21SSam Leffler >> IEEE80211_FC0_SUBTYPE_SHIFT]); 4001a1e1d21SSam Leffler break; 4011a1e1d21SSam Leffler default: 4021a1e1d21SSam Leffler printf(" type#%d", wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK); 4031a1e1d21SSam Leffler break; 4041a1e1d21SSam Leffler } 40568e8e04eSSam Leffler if (IEEE80211_QOS_HAS_SEQ(wh)) { 40668e8e04eSSam Leffler const struct ieee80211_qosframe *qwh = 40768e8e04eSSam Leffler (const struct ieee80211_qosframe *)buf; 40868e8e04eSSam Leffler printf(" QoS [TID %u%s]", qwh->i_qos[0] & IEEE80211_QOS_TID, 40968e8e04eSSam Leffler qwh->i_qos[0] & IEEE80211_QOS_ACKPOLICY ? " ACM" : ""); 41068e8e04eSSam Leffler } 4118a1b9b6aSSam Leffler if (wh->i_fc[1] & IEEE80211_FC1_WEP) { 41268e8e04eSSam Leffler int off; 41368e8e04eSSam Leffler 41468e8e04eSSam Leffler off = ieee80211_anyhdrspace(ic, wh); 41568e8e04eSSam Leffler printf(" WEP [IV %.02x %.02x %.02x", 41668e8e04eSSam Leffler buf[off+0], buf[off+1], buf[off+2]); 41768e8e04eSSam Leffler if (buf[off+IEEE80211_WEP_IVLEN] & IEEE80211_WEP_EXTIV) 41868e8e04eSSam Leffler printf(" %.02x %.02x %.02x", 41968e8e04eSSam Leffler buf[off+4], buf[off+5], buf[off+6]); 42068e8e04eSSam Leffler printf(" KID %u]", buf[off+IEEE80211_WEP_IVLEN] >> 6); 4218a1b9b6aSSam Leffler } 4221a1e1d21SSam Leffler if (rate >= 0) 4231a1e1d21SSam Leffler printf(" %dM", rate / 2); 4241a1e1d21SSam Leffler if (rssi >= 0) 4251a1e1d21SSam Leffler printf(" +%d", rssi); 4261a1e1d21SSam Leffler printf("\n"); 4271a1e1d21SSam Leffler if (len > 0) { 4281a1e1d21SSam Leffler for (i = 0; i < len; i++) { 4291a1e1d21SSam Leffler if ((i & 1) == 0) 4301a1e1d21SSam Leffler printf(" "); 4311a1e1d21SSam Leffler printf("%02x", buf[i]); 4321a1e1d21SSam Leffler } 4331a1e1d21SSam Leffler printf("\n"); 4341a1e1d21SSam Leffler } 4351a1e1d21SSam Leffler } 4361a1e1d21SSam Leffler 43779edaebfSSam Leffler static __inline int 43879edaebfSSam Leffler findrix(const struct ieee80211_rateset *rs, int r) 43979edaebfSSam Leffler { 44079edaebfSSam Leffler int i; 44179edaebfSSam Leffler 44279edaebfSSam Leffler for (i = 0; i < rs->rs_nrates; i++) 44379edaebfSSam Leffler if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == r) 44479edaebfSSam Leffler return i; 44579edaebfSSam Leffler return -1; 44679edaebfSSam Leffler } 44779edaebfSSam Leffler 4481a1e1d21SSam Leffler int 44970e28b9aSSam Leffler ieee80211_fix_rate(struct ieee80211_node *ni, 45070e28b9aSSam Leffler struct ieee80211_rateset *nrs, int flags) 4511a1e1d21SSam Leffler { 4521a1e1d21SSam Leffler #define RV(v) ((v) & IEEE80211_RATE_VAL) 453b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 4547d77cd53SSam Leffler struct ieee80211com *ic = ni->ni_ic; 45579edaebfSSam Leffler int i, j, rix, error; 456b032f27cSSam Leffler int okrate, badrate, fixedrate, ucastrate; 45741b3c790SSam Leffler const struct ieee80211_rateset *srs; 45868e8e04eSSam Leffler uint8_t r; 4591a1e1d21SSam Leffler 4601a1e1d21SSam Leffler error = 0; 46168e8e04eSSam Leffler okrate = badrate = 0; 462b032f27cSSam Leffler ucastrate = vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)].ucastrate; 463b032f27cSSam Leffler if (ucastrate != IEEE80211_FIXED_RATE_NONE) { 464b032f27cSSam Leffler /* 465b032f27cSSam Leffler * Workaround awkwardness with fixed rate. We are called 466b032f27cSSam Leffler * to check both the legacy rate set and the HT rate set 467b032f27cSSam Leffler * but we must apply any legacy fixed rate check only to the 468b032f27cSSam Leffler * legacy rate set and vice versa. We cannot tell what type 469b032f27cSSam Leffler * of rate set we've been given (legacy or HT) but we can 470b032f27cSSam Leffler * distinguish the fixed rate type (MCS have 0x80 set). 471b032f27cSSam Leffler * So to deal with this the caller communicates whether to 472b032f27cSSam Leffler * check MCS or legacy rate using the flags and we use the 473b032f27cSSam Leffler * type of any fixed rate to avoid applying an MCS to a 474b032f27cSSam Leffler * legacy rate and vice versa. 475b032f27cSSam Leffler */ 476b032f27cSSam Leffler if (ucastrate & 0x80) { 477b032f27cSSam Leffler if (flags & IEEE80211_F_DOFRATE) 478b032f27cSSam Leffler flags &= ~IEEE80211_F_DOFRATE; 479b032f27cSSam Leffler } else if ((ucastrate & 0x80) == 0) { 480b032f27cSSam Leffler if (flags & IEEE80211_F_DOFMCS) 481b032f27cSSam Leffler flags &= ~IEEE80211_F_DOFMCS; 482b032f27cSSam Leffler } 483b032f27cSSam Leffler /* NB: required to make MCS match below work */ 484b032f27cSSam Leffler ucastrate &= IEEE80211_RATE_VAL; 485b032f27cSSam Leffler } 48668e8e04eSSam Leffler fixedrate = IEEE80211_FIXED_RATE_NONE; 487b032f27cSSam Leffler /* 488b032f27cSSam Leffler * XXX we are called to process both MCS and legacy rates; 489b032f27cSSam Leffler * we must use the appropriate basic rate set or chaos will 490b032f27cSSam Leffler * ensue; for now callers that want MCS must supply 491b032f27cSSam Leffler * IEEE80211_F_DOBRS; at some point we'll need to split this 492b032f27cSSam Leffler * function so there are two variants, one for MCS and one 493b032f27cSSam Leffler * for legacy rates. 494b032f27cSSam Leffler */ 495b032f27cSSam Leffler if (flags & IEEE80211_F_DOBRS) 496b032f27cSSam Leffler srs = (const struct ieee80211_rateset *) 497b032f27cSSam Leffler ieee80211_get_suphtrates(ic, ni->ni_chan); 498b032f27cSSam Leffler else 49941b3c790SSam Leffler srs = ieee80211_get_suprates(ic, ni->ni_chan); 500ef39d4beSSam Leffler for (i = 0; i < nrs->rs_nrates; ) { 5011a1e1d21SSam Leffler if (flags & IEEE80211_F_DOSORT) { 5021a1e1d21SSam Leffler /* 5031a1e1d21SSam Leffler * Sort rates. 5041a1e1d21SSam Leffler */ 5051a1e1d21SSam Leffler for (j = i + 1; j < nrs->rs_nrates; j++) { 5061a1e1d21SSam Leffler if (RV(nrs->rs_rates[i]) > RV(nrs->rs_rates[j])) { 5071a1e1d21SSam Leffler r = nrs->rs_rates[i]; 5081a1e1d21SSam Leffler nrs->rs_rates[i] = nrs->rs_rates[j]; 5091a1e1d21SSam Leffler nrs->rs_rates[j] = r; 5101a1e1d21SSam Leffler } 5111a1e1d21SSam Leffler } 5121a1e1d21SSam Leffler } 5131a1e1d21SSam Leffler r = nrs->rs_rates[i] & IEEE80211_RATE_VAL; 5141a1e1d21SSam Leffler badrate = r; 5151a1e1d21SSam Leffler /* 51668e8e04eSSam Leffler * Check for fixed rate. 5171a1e1d21SSam Leffler */ 518b032f27cSSam Leffler if (r == ucastrate) 5198a1b9b6aSSam Leffler fixedrate = r; 5201a1e1d21SSam Leffler /* 5211a1e1d21SSam Leffler * Check against supported rates. 5221a1e1d21SSam Leffler */ 52379edaebfSSam Leffler rix = findrix(srs, r); 52479edaebfSSam Leffler if (flags & IEEE80211_F_DONEGO) { 52579edaebfSSam Leffler if (rix < 0) { 526ef39d4beSSam Leffler /* 527ef39d4beSSam Leffler * A rate in the node's rate set is not 528ef39d4beSSam Leffler * supported. If this is a basic rate and we 52979edaebfSSam Leffler * are operating as a STA then this is an error. 530ef39d4beSSam Leffler * Otherwise we just discard/ignore the rate. 531ef39d4beSSam Leffler */ 53279edaebfSSam Leffler if ((flags & IEEE80211_F_JOIN) && 533ef39d4beSSam Leffler (nrs->rs_rates[i] & IEEE80211_RATE_BASIC)) 5341a1e1d21SSam Leffler error++; 53579edaebfSSam Leffler } else if ((flags & IEEE80211_F_JOIN) == 0) { 53679edaebfSSam Leffler /* 53779edaebfSSam Leffler * Overwrite with the supported rate 53879edaebfSSam Leffler * value so any basic rate bit is set. 53979edaebfSSam Leffler */ 54079edaebfSSam Leffler nrs->rs_rates[i] = srs->rs_rates[rix]; 5411a1e1d21SSam Leffler } 5421a1e1d21SSam Leffler } 54379edaebfSSam Leffler if ((flags & IEEE80211_F_DODEL) && rix < 0) { 5441a1e1d21SSam Leffler /* 5451a1e1d21SSam Leffler * Delete unacceptable rates. 5461a1e1d21SSam Leffler */ 5471a1e1d21SSam Leffler nrs->rs_nrates--; 5481a1e1d21SSam Leffler for (j = i; j < nrs->rs_nrates; j++) 5491a1e1d21SSam Leffler nrs->rs_rates[j] = nrs->rs_rates[j + 1]; 5501a1e1d21SSam Leffler nrs->rs_rates[j] = 0; 5511a1e1d21SSam Leffler continue; 5521a1e1d21SSam Leffler } 55379edaebfSSam Leffler if (rix >= 0) 5541a1e1d21SSam Leffler okrate = nrs->rs_rates[i]; 5551a1e1d21SSam Leffler i++; 5561a1e1d21SSam Leffler } 5578a1b9b6aSSam Leffler if (okrate == 0 || error != 0 || 558b032f27cSSam Leffler ((flags & (IEEE80211_F_DOFRATE|IEEE80211_F_DOFMCS)) && 559b032f27cSSam Leffler fixedrate != ucastrate)) { 560b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_XRATE | IEEE80211_MSG_11N, ni, 561b032f27cSSam Leffler "%s: flags 0x%x okrate %d error %d fixedrate 0x%x " 562b032f27cSSam Leffler "ucastrate %x\n", __func__, fixedrate, ucastrate, flags); 5631a1e1d21SSam Leffler return badrate | IEEE80211_RATE_BASIC; 564b032f27cSSam Leffler } else 5651a1e1d21SSam Leffler return RV(okrate); 5661a1e1d21SSam Leffler #undef RV 5671a1e1d21SSam Leffler } 5681a1e1d21SSam Leffler 5698a1b9b6aSSam Leffler /* 5708a1b9b6aSSam Leffler * Reset 11g-related state. 5718a1b9b6aSSam Leffler */ 5728a1b9b6aSSam Leffler void 5738a1b9b6aSSam Leffler ieee80211_reset_erp(struct ieee80211com *ic) 5741a1e1d21SSam Leffler { 5758a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_USEPROT; 5768a1b9b6aSSam Leffler ic->ic_nonerpsta = 0; 5778a1b9b6aSSam Leffler ic->ic_longslotsta = 0; 5788a1b9b6aSSam Leffler /* 5798a1b9b6aSSam Leffler * Short slot time is enabled only when operating in 11g 5808a1b9b6aSSam Leffler * and not in an IBSS. We must also honor whether or not 5818a1b9b6aSSam Leffler * the driver is capable of doing it. 5828a1b9b6aSSam Leffler */ 5838a1b9b6aSSam Leffler ieee80211_set_shortslottime(ic, 58468e8e04eSSam Leffler IEEE80211_IS_CHAN_A(ic->ic_curchan) || 58568e8e04eSSam Leffler IEEE80211_IS_CHAN_HT(ic->ic_curchan) || 58668e8e04eSSam Leffler (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) && 5878a1b9b6aSSam Leffler ic->ic_opmode == IEEE80211_M_HOSTAP && 5888a1b9b6aSSam Leffler (ic->ic_caps & IEEE80211_C_SHSLOT))); 5898a1b9b6aSSam Leffler /* 5908a1b9b6aSSam Leffler * Set short preamble and ERP barker-preamble flags. 5918a1b9b6aSSam Leffler */ 59268e8e04eSSam Leffler if (IEEE80211_IS_CHAN_A(ic->ic_curchan) || 5938a1b9b6aSSam Leffler (ic->ic_caps & IEEE80211_C_SHPREAMBLE)) { 5948a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_SHPREAMBLE; 5958a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_USEBARKER; 5968a1b9b6aSSam Leffler } else { 5978a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE; 5988a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_USEBARKER; 5998a1b9b6aSSam Leffler } 6008a1b9b6aSSam Leffler } 6018a1b9b6aSSam Leffler 6028a1b9b6aSSam Leffler /* 6038a1b9b6aSSam Leffler * Set the short slot time state and notify the driver. 6048a1b9b6aSSam Leffler */ 6058a1b9b6aSSam Leffler void 6068a1b9b6aSSam Leffler ieee80211_set_shortslottime(struct ieee80211com *ic, int onoff) 6078a1b9b6aSSam Leffler { 6088a1b9b6aSSam Leffler if (onoff) 6098a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_SHSLOT; 6108a1b9b6aSSam Leffler else 6118a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_SHSLOT; 6128a1b9b6aSSam Leffler /* notify driver */ 6138a1b9b6aSSam Leffler if (ic->ic_updateslot != NULL) 6148a1b9b6aSSam Leffler ic->ic_updateslot(ic->ic_ifp); 6158a1b9b6aSSam Leffler } 6168a1b9b6aSSam Leffler 6178a1b9b6aSSam Leffler /* 6188a1b9b6aSSam Leffler * Check if the specified rate set supports ERP. 6198a1b9b6aSSam Leffler * NB: the rate set is assumed to be sorted. 6208a1b9b6aSSam Leffler */ 6218a1b9b6aSSam Leffler int 622b032f27cSSam Leffler ieee80211_iserp_rateset(const struct ieee80211_rateset *rs) 6238a1b9b6aSSam Leffler { 6248a1b9b6aSSam Leffler #define N(a) (sizeof(a) / sizeof(a[0])) 6258a1b9b6aSSam Leffler static const int rates[] = { 2, 4, 11, 22, 12, 24, 48 }; 6268a1b9b6aSSam Leffler int i, j; 6278a1b9b6aSSam Leffler 6288a1b9b6aSSam Leffler if (rs->rs_nrates < N(rates)) 6298a1b9b6aSSam Leffler return 0; 6308a1b9b6aSSam Leffler for (i = 0; i < N(rates); i++) { 6318a1b9b6aSSam Leffler for (j = 0; j < rs->rs_nrates; j++) { 6328a1b9b6aSSam Leffler int r = rs->rs_rates[j] & IEEE80211_RATE_VAL; 6338a1b9b6aSSam Leffler if (rates[i] == r) 6348a1b9b6aSSam Leffler goto next; 6358a1b9b6aSSam Leffler if (r > rates[i]) 6368a1b9b6aSSam Leffler return 0; 6378a1b9b6aSSam Leffler } 6388a1b9b6aSSam Leffler return 0; 6398a1b9b6aSSam Leffler next: 6408a1b9b6aSSam Leffler ; 6418a1b9b6aSSam Leffler } 6428a1b9b6aSSam Leffler return 1; 6438a1b9b6aSSam Leffler #undef N 6448a1b9b6aSSam Leffler } 6458a1b9b6aSSam Leffler 6468a1b9b6aSSam Leffler /* 647b032f27cSSam Leffler * Mark the basic rates for the rate table based on the 6488a1b9b6aSSam Leffler * operating mode. For real 11g we mark all the 11b rates 6498a1b9b6aSSam Leffler * and 6, 12, and 24 OFDM. For 11b compatibility we mark only 6508a1b9b6aSSam Leffler * 11b rates. There's also a pseudo 11a-mode used to mark only 6518a1b9b6aSSam Leffler * the basic OFDM rates. 6528a1b9b6aSSam Leffler */ 653b032f27cSSam Leffler static void 654b032f27cSSam Leffler setbasicrates(struct ieee80211_rateset *rs, 655b032f27cSSam Leffler enum ieee80211_phymode mode, int add) 6568a1b9b6aSSam Leffler { 65768e8e04eSSam Leffler static const struct ieee80211_rateset basic[IEEE80211_MODE_MAX] = { 658be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 3, { 12, 24, 48 } }, 659be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 2, { 2, 4 } }, 660be0df3e7SSam Leffler /* NB: mixed b/g */ 661be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 4, { 2, 4, 11, 22 } }, 662be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A] = { 3, { 12, 24, 48 } }, 663be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G] = { 4, { 2, 4, 11, 22 } }, 664be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A] = { 3, { 12, 24, 48 } }, 665be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 3, { 12, 24, 48 } }, 666be0df3e7SSam Leffler /* NB: mixed b/g */ 667be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 4, { 2, 4, 11, 22 } }, 6688a1b9b6aSSam Leffler }; 6698a1b9b6aSSam Leffler int i, j; 6708a1b9b6aSSam Leffler 6718a1b9b6aSSam Leffler for (i = 0; i < rs->rs_nrates; i++) { 672b032f27cSSam Leffler if (!add) 6738a1b9b6aSSam Leffler rs->rs_rates[i] &= IEEE80211_RATE_VAL; 6748a1b9b6aSSam Leffler for (j = 0; j < basic[mode].rs_nrates; j++) 6758a1b9b6aSSam Leffler if (basic[mode].rs_rates[j] == rs->rs_rates[i]) { 6768a1b9b6aSSam Leffler rs->rs_rates[i] |= IEEE80211_RATE_BASIC; 6778a1b9b6aSSam Leffler break; 6788a1b9b6aSSam Leffler } 6798a1b9b6aSSam Leffler } 6808a1b9b6aSSam Leffler } 6818a1b9b6aSSam Leffler 6828a1b9b6aSSam Leffler /* 683b032f27cSSam Leffler * Set the basic rates in a rate set. 684b032f27cSSam Leffler */ 685b032f27cSSam Leffler void 686b032f27cSSam Leffler ieee80211_setbasicrates(struct ieee80211_rateset *rs, 687b032f27cSSam Leffler enum ieee80211_phymode mode) 688b032f27cSSam Leffler { 689b032f27cSSam Leffler setbasicrates(rs, mode, 0); 690b032f27cSSam Leffler } 691b032f27cSSam Leffler 692b032f27cSSam Leffler /* 693b032f27cSSam Leffler * Add basic rates to a rate set. 694b032f27cSSam Leffler */ 695b032f27cSSam Leffler void 696b032f27cSSam Leffler ieee80211_addbasicrates(struct ieee80211_rateset *rs, 697b032f27cSSam Leffler enum ieee80211_phymode mode) 698b032f27cSSam Leffler { 699b032f27cSSam Leffler setbasicrates(rs, mode, 1); 700b032f27cSSam Leffler } 701b032f27cSSam Leffler 702b032f27cSSam Leffler /* 703b032f27cSSam Leffler * WME protocol support. 704b032f27cSSam Leffler * 705b032f27cSSam Leffler * The default 11a/b/g/n parameters come from the WiFi Alliance WMM 706b032f27cSSam Leffler * System Interopability Test Plan (v1.4, Appendix F) and the 802.11n 707b032f27cSSam Leffler * Draft 2.0 Test Plan (Appendix D). 708b032f27cSSam Leffler * 709b032f27cSSam Leffler * Static/Dynamic Turbo mode settings come from Atheros. 7108a1b9b6aSSam Leffler */ 7118a1b9b6aSSam Leffler typedef struct phyParamType { 71268e8e04eSSam Leffler uint8_t aifsn; 71368e8e04eSSam Leffler uint8_t logcwmin; 71468e8e04eSSam Leffler uint8_t logcwmax; 71568e8e04eSSam Leffler uint16_t txopLimit; 71668e8e04eSSam Leffler uint8_t acm; 7178a1b9b6aSSam Leffler } paramType; 7188a1b9b6aSSam Leffler 7198a1b9b6aSSam Leffler static const struct phyParamType phyParamForAC_BE[IEEE80211_MODE_MAX] = { 720be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 3, 4, 6, 0, 0 }, 721be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 3, 4, 6, 0, 0 }, 722be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 3, 4, 6, 0, 0 }, 723be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 3, 4, 6, 0, 0 }, 724be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 3, 4, 6, 0, 0 }, 725be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 2, 3, 5, 0, 0 }, 726be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 2, 3, 5, 0, 0 }, 727be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 2, 3, 5, 0, 0 }, 728be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 3, 4, 6, 0, 0 }, 729be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 3, 4, 6, 0, 0 }, 7308a1b9b6aSSam Leffler }; 7318a1b9b6aSSam Leffler static const struct phyParamType phyParamForAC_BK[IEEE80211_MODE_MAX] = { 732be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 7, 4, 10, 0, 0 }, 733be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 7, 4, 10, 0, 0 }, 734be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 7, 4, 10, 0, 0 }, 735be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 7, 4, 10, 0, 0 }, 736be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 7, 4, 10, 0, 0 }, 737be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 7, 3, 10, 0, 0 }, 738be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 7, 3, 10, 0, 0 }, 739be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 7, 3, 10, 0, 0 }, 740be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 7, 4, 10, 0, 0 }, 741be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 7, 4, 10, 0, 0 }, 7428a1b9b6aSSam Leffler }; 7438a1b9b6aSSam Leffler static const struct phyParamType phyParamForAC_VI[IEEE80211_MODE_MAX] = { 744be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 1, 3, 4, 94, 0 }, 745be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 1, 3, 4, 94, 0 }, 746be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 1, 3, 4, 188, 0 }, 747be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 1, 3, 4, 94, 0 }, 748be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 1, 3, 4, 188, 0 }, 749be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 1, 2, 3, 94, 0 }, 750be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 1, 2, 3, 94, 0 }, 751be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 1, 2, 3, 94, 0 }, 752be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 1, 3, 4, 94, 0 }, 753be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 1, 3, 4, 94, 0 }, 7548a1b9b6aSSam Leffler }; 7558a1b9b6aSSam Leffler static const struct phyParamType phyParamForAC_VO[IEEE80211_MODE_MAX] = { 756be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 1, 2, 3, 47, 0 }, 757be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 1, 2, 3, 47, 0 }, 758be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 1, 2, 3, 102, 0 }, 759be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 1, 2, 3, 47, 0 }, 760be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 1, 2, 3, 102, 0 }, 761be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 1, 2, 2, 47, 0 }, 762be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 1, 2, 2, 47, 0 }, 763be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 1, 2, 2, 47, 0 }, 764be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 1, 2, 3, 47, 0 }, 765be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 1, 2, 3, 47, 0 }, 7668a1b9b6aSSam Leffler }; 7678a1b9b6aSSam Leffler 7688a1b9b6aSSam Leffler static const struct phyParamType bssPhyParamForAC_BE[IEEE80211_MODE_MAX] = { 769be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 3, 4, 10, 0, 0 }, 770be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 3, 4, 10, 0, 0 }, 771be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 3, 4, 10, 0, 0 }, 772be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 3, 4, 10, 0, 0 }, 773be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 3, 4, 10, 0, 0 }, 774be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 2, 3, 10, 0, 0 }, 775be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 2, 3, 10, 0, 0 }, 776be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 2, 3, 10, 0, 0 }, 777be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 3, 4, 10, 0, 0 }, 778be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 3, 4, 10, 0, 0 }, 7798a1b9b6aSSam Leffler }; 7808a1b9b6aSSam Leffler static const struct phyParamType bssPhyParamForAC_VI[IEEE80211_MODE_MAX] = { 781be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 2, 3, 4, 94, 0 }, 782be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 2, 3, 4, 94, 0 }, 783be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 2, 3, 4, 188, 0 }, 784be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 2, 3, 4, 94, 0 }, 785be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 2, 3, 4, 188, 0 }, 786be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 2, 2, 3, 94, 0 }, 787be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 2, 2, 3, 94, 0 }, 788be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 2, 2, 3, 94, 0 }, 789be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 2, 3, 4, 94, 0 }, 790be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 2, 3, 4, 94, 0 }, 7918a1b9b6aSSam Leffler }; 7928a1b9b6aSSam Leffler static const struct phyParamType bssPhyParamForAC_VO[IEEE80211_MODE_MAX] = { 793be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 2, 2, 3, 47, 0 }, 794be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 2, 2, 3, 47, 0 }, 795be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 2, 2, 3, 102, 0 }, 796be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 2, 2, 3, 47, 0 }, 797be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 2, 2, 3, 102, 0 }, 798be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A]= { 1, 2, 2, 47, 0 }, 799be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G]= { 1, 2, 2, 47, 0 }, 800be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A]={ 1, 2, 2, 47, 0 }, 801be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 2, 2, 3, 47, 0 }, 802be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 2, 2, 3, 47, 0 }, 8038a1b9b6aSSam Leffler }; 8048a1b9b6aSSam Leffler 805b032f27cSSam Leffler static void 806b032f27cSSam Leffler ieee80211_wme_initparams_locked(struct ieee80211vap *vap) 8078a1b9b6aSSam Leffler { 808b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 8098a1b9b6aSSam Leffler struct ieee80211_wme_state *wme = &ic->ic_wme; 8108a1b9b6aSSam Leffler const paramType *pPhyParam, *pBssPhyParam; 8118a1b9b6aSSam Leffler struct wmeParams *wmep; 81268e8e04eSSam Leffler enum ieee80211_phymode mode; 8138a1b9b6aSSam Leffler int i; 8148a1b9b6aSSam Leffler 815b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 816b032f27cSSam Leffler 8178a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_WME) == 0) 8188a1b9b6aSSam Leffler return; 8198a1b9b6aSSam Leffler 82068e8e04eSSam Leffler /* 82168e8e04eSSam Leffler * Select mode; we can be called early in which case we 82268e8e04eSSam Leffler * always use auto mode. We know we'll be called when 82368e8e04eSSam Leffler * entering the RUN state with bsschan setup properly 82468e8e04eSSam Leffler * so state will eventually get set correctly 82568e8e04eSSam Leffler */ 82668e8e04eSSam Leffler if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 82768e8e04eSSam Leffler mode = ieee80211_chan2mode(ic->ic_bsschan); 82868e8e04eSSam Leffler else 82968e8e04eSSam Leffler mode = IEEE80211_MODE_AUTO; 8308a1b9b6aSSam Leffler for (i = 0; i < WME_NUM_AC; i++) { 8318a1b9b6aSSam Leffler switch (i) { 8328a1b9b6aSSam Leffler case WME_AC_BK: 83368e8e04eSSam Leffler pPhyParam = &phyParamForAC_BK[mode]; 83468e8e04eSSam Leffler pBssPhyParam = &phyParamForAC_BK[mode]; 8358a1b9b6aSSam Leffler break; 8368a1b9b6aSSam Leffler case WME_AC_VI: 83768e8e04eSSam Leffler pPhyParam = &phyParamForAC_VI[mode]; 83868e8e04eSSam Leffler pBssPhyParam = &bssPhyParamForAC_VI[mode]; 8398a1b9b6aSSam Leffler break; 8408a1b9b6aSSam Leffler case WME_AC_VO: 84168e8e04eSSam Leffler pPhyParam = &phyParamForAC_VO[mode]; 84268e8e04eSSam Leffler pBssPhyParam = &bssPhyParamForAC_VO[mode]; 8438a1b9b6aSSam Leffler break; 8448a1b9b6aSSam Leffler case WME_AC_BE: 8458a1b9b6aSSam Leffler default: 84668e8e04eSSam Leffler pPhyParam = &phyParamForAC_BE[mode]; 84768e8e04eSSam Leffler pBssPhyParam = &bssPhyParamForAC_BE[mode]; 8488a1b9b6aSSam Leffler break; 8498a1b9b6aSSam Leffler } 8508a1b9b6aSSam Leffler 8518a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[i]; 8528a1b9b6aSSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 8538a1b9b6aSSam Leffler wmep->wmep_acm = pPhyParam->acm; 8548a1b9b6aSSam Leffler wmep->wmep_aifsn = pPhyParam->aifsn; 8558a1b9b6aSSam Leffler wmep->wmep_logcwmin = pPhyParam->logcwmin; 8568a1b9b6aSSam Leffler wmep->wmep_logcwmax = pPhyParam->logcwmax; 8578a1b9b6aSSam Leffler wmep->wmep_txopLimit = pPhyParam->txopLimit; 8588a1b9b6aSSam Leffler } else { 8598a1b9b6aSSam Leffler wmep->wmep_acm = pBssPhyParam->acm; 8608a1b9b6aSSam Leffler wmep->wmep_aifsn = pBssPhyParam->aifsn; 8618a1b9b6aSSam Leffler wmep->wmep_logcwmin = pBssPhyParam->logcwmin; 8628a1b9b6aSSam Leffler wmep->wmep_logcwmax = pBssPhyParam->logcwmax; 8638a1b9b6aSSam Leffler wmep->wmep_txopLimit = pBssPhyParam->txopLimit; 8648a1b9b6aSSam Leffler 8658a1b9b6aSSam Leffler } 866b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME, 8678a1b9b6aSSam Leffler "%s: %s chan [acm %u aifsn %u log2(cwmin) %u " 8688a1b9b6aSSam Leffler "log2(cwmax) %u txpoLimit %u]\n", __func__ 8698a1b9b6aSSam Leffler , ieee80211_wme_acnames[i] 8708a1b9b6aSSam Leffler , wmep->wmep_acm 8718a1b9b6aSSam Leffler , wmep->wmep_aifsn 8728a1b9b6aSSam Leffler , wmep->wmep_logcwmin 8738a1b9b6aSSam Leffler , wmep->wmep_logcwmax 8748a1b9b6aSSam Leffler , wmep->wmep_txopLimit 8758a1b9b6aSSam Leffler ); 8768a1b9b6aSSam Leffler 8778a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[i]; 8788a1b9b6aSSam Leffler wmep->wmep_acm = pBssPhyParam->acm; 8798a1b9b6aSSam Leffler wmep->wmep_aifsn = pBssPhyParam->aifsn; 8808a1b9b6aSSam Leffler wmep->wmep_logcwmin = pBssPhyParam->logcwmin; 8818a1b9b6aSSam Leffler wmep->wmep_logcwmax = pBssPhyParam->logcwmax; 8828a1b9b6aSSam Leffler wmep->wmep_txopLimit = pBssPhyParam->txopLimit; 883b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME, 8848a1b9b6aSSam Leffler "%s: %s bss [acm %u aifsn %u log2(cwmin) %u " 8858a1b9b6aSSam Leffler "log2(cwmax) %u txpoLimit %u]\n", __func__ 8868a1b9b6aSSam Leffler , ieee80211_wme_acnames[i] 8878a1b9b6aSSam Leffler , wmep->wmep_acm 8888a1b9b6aSSam Leffler , wmep->wmep_aifsn 8898a1b9b6aSSam Leffler , wmep->wmep_logcwmin 8908a1b9b6aSSam Leffler , wmep->wmep_logcwmax 8918a1b9b6aSSam Leffler , wmep->wmep_txopLimit 8928a1b9b6aSSam Leffler ); 8938a1b9b6aSSam Leffler } 8948a1b9b6aSSam Leffler /* NB: check ic_bss to avoid NULL deref on initial attach */ 895b032f27cSSam Leffler if (vap->iv_bss != NULL) { 8968a1b9b6aSSam Leffler /* 8978a1b9b6aSSam Leffler * Calculate agressive mode switching threshold based 8988a1b9b6aSSam Leffler * on beacon interval. This doesn't need locking since 8998a1b9b6aSSam Leffler * we're only called before entering the RUN state at 9008a1b9b6aSSam Leffler * which point we start sending beacon frames. 9018a1b9b6aSSam Leffler */ 9028a1b9b6aSSam Leffler wme->wme_hipri_switch_thresh = 903b032f27cSSam Leffler (HIGH_PRI_SWITCH_THRESH * vap->iv_bss->ni_intval) / 100; 904b032f27cSSam Leffler ieee80211_wme_updateparams(vap); 9058a1b9b6aSSam Leffler } 9068a1b9b6aSSam Leffler } 9078a1b9b6aSSam Leffler 908b032f27cSSam Leffler void 909b032f27cSSam Leffler ieee80211_wme_initparams(struct ieee80211vap *vap) 910b032f27cSSam Leffler { 911b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 912b032f27cSSam Leffler 913b032f27cSSam Leffler IEEE80211_LOCK(ic); 914b032f27cSSam Leffler ieee80211_wme_initparams_locked(vap); 915b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 916b032f27cSSam Leffler } 917b032f27cSSam Leffler 9188a1b9b6aSSam Leffler /* 9198a1b9b6aSSam Leffler * Update WME parameters for ourself and the BSS. 9208a1b9b6aSSam Leffler */ 9218a1b9b6aSSam Leffler void 922b032f27cSSam Leffler ieee80211_wme_updateparams_locked(struct ieee80211vap *vap) 9238a1b9b6aSSam Leffler { 9248a1b9b6aSSam Leffler static const paramType phyParam[IEEE80211_MODE_MAX] = { 925be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = { 2, 4, 10, 64, 0 }, 926be0df3e7SSam Leffler [IEEE80211_MODE_11A] = { 2, 4, 10, 64, 0 }, 927be0df3e7SSam Leffler [IEEE80211_MODE_11B] = { 2, 5, 10, 64, 0 }, 928be0df3e7SSam Leffler [IEEE80211_MODE_11G] = { 2, 4, 10, 64, 0 }, 929be0df3e7SSam Leffler [IEEE80211_MODE_FH] = { 2, 5, 10, 64, 0 }, 930be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A] = { 1, 3, 10, 64, 0 }, 931be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G] = { 1, 3, 10, 64, 0 }, 932be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A] = { 1, 3, 10, 64, 0 }, 933be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/ 934be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = { 2, 4, 10, 64, 0 }, /* XXXcheck*/ 9358a1b9b6aSSam Leffler }; 936b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 9378a1b9b6aSSam Leffler struct ieee80211_wme_state *wme = &ic->ic_wme; 9388a1b9b6aSSam Leffler const struct wmeParams *wmep; 9398a1b9b6aSSam Leffler struct wmeParams *chanp, *bssp; 94068e8e04eSSam Leffler enum ieee80211_phymode mode; 9418a1b9b6aSSam Leffler int i; 9428a1b9b6aSSam Leffler 9438a1b9b6aSSam Leffler /* set up the channel access parameters for the physical device */ 9448a1b9b6aSSam Leffler for (i = 0; i < WME_NUM_AC; i++) { 9458a1b9b6aSSam Leffler chanp = &wme->wme_chanParams.cap_wmeParams[i]; 9468a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[i]; 9478a1b9b6aSSam Leffler chanp->wmep_aifsn = wmep->wmep_aifsn; 9488a1b9b6aSSam Leffler chanp->wmep_logcwmin = wmep->wmep_logcwmin; 9498a1b9b6aSSam Leffler chanp->wmep_logcwmax = wmep->wmep_logcwmax; 9508a1b9b6aSSam Leffler chanp->wmep_txopLimit = wmep->wmep_txopLimit; 9518a1b9b6aSSam Leffler 9528a1b9b6aSSam Leffler chanp = &wme->wme_bssChanParams.cap_wmeParams[i]; 9538a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[i]; 9548a1b9b6aSSam Leffler chanp->wmep_aifsn = wmep->wmep_aifsn; 9558a1b9b6aSSam Leffler chanp->wmep_logcwmin = wmep->wmep_logcwmin; 9568a1b9b6aSSam Leffler chanp->wmep_logcwmax = wmep->wmep_logcwmax; 9578a1b9b6aSSam Leffler chanp->wmep_txopLimit = wmep->wmep_txopLimit; 9588a1b9b6aSSam Leffler } 9598a1b9b6aSSam Leffler 9608a1b9b6aSSam Leffler /* 96168e8e04eSSam Leffler * Select mode; we can be called early in which case we 96268e8e04eSSam Leffler * always use auto mode. We know we'll be called when 96368e8e04eSSam Leffler * entering the RUN state with bsschan setup properly 96468e8e04eSSam Leffler * so state will eventually get set correctly 96568e8e04eSSam Leffler */ 96668e8e04eSSam Leffler if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) 96768e8e04eSSam Leffler mode = ieee80211_chan2mode(ic->ic_bsschan); 96868e8e04eSSam Leffler else 96968e8e04eSSam Leffler mode = IEEE80211_MODE_AUTO; 97068e8e04eSSam Leffler 97168e8e04eSSam Leffler /* 9728a1b9b6aSSam Leffler * This implements agressive mode as found in certain 9738a1b9b6aSSam Leffler * vendors' AP's. When there is significant high 9748a1b9b6aSSam Leffler * priority (VI/VO) traffic in the BSS throttle back BE 9758a1b9b6aSSam Leffler * traffic by using conservative parameters. Otherwise 9768a1b9b6aSSam Leffler * BE uses agressive params to optimize performance of 9778a1b9b6aSSam Leffler * legacy/non-QoS traffic. 9788a1b9b6aSSam Leffler */ 979b032f27cSSam Leffler if ((vap->iv_opmode == IEEE80211_M_HOSTAP && 980ad262427SSam Leffler (wme->wme_flags & WME_F_AGGRMODE) != 0) || 981b032f27cSSam Leffler (vap->iv_opmode == IEEE80211_M_STA && 982b032f27cSSam Leffler (vap->iv_bss->ni_flags & IEEE80211_NODE_QOS) == 0) || 983b032f27cSSam Leffler (vap->iv_flags & IEEE80211_F_WME) == 0) { 9848a1b9b6aSSam Leffler chanp = &wme->wme_chanParams.cap_wmeParams[WME_AC_BE]; 9858a1b9b6aSSam Leffler bssp = &wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE]; 9868a1b9b6aSSam Leffler 98768e8e04eSSam Leffler chanp->wmep_aifsn = bssp->wmep_aifsn = phyParam[mode].aifsn; 9888a1b9b6aSSam Leffler chanp->wmep_logcwmin = bssp->wmep_logcwmin = 98968e8e04eSSam Leffler phyParam[mode].logcwmin; 9908a1b9b6aSSam Leffler chanp->wmep_logcwmax = bssp->wmep_logcwmax = 99168e8e04eSSam Leffler phyParam[mode].logcwmax; 9928a1b9b6aSSam Leffler chanp->wmep_txopLimit = bssp->wmep_txopLimit = 993b032f27cSSam Leffler (vap->iv_flags & IEEE80211_F_BURST) ? 99468e8e04eSSam Leffler phyParam[mode].txopLimit : 0; 995b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME, 9968a1b9b6aSSam Leffler "%s: %s [acm %u aifsn %u log2(cwmin) %u " 9978a1b9b6aSSam Leffler "log2(cwmax) %u txpoLimit %u]\n", __func__ 9988a1b9b6aSSam Leffler , ieee80211_wme_acnames[WME_AC_BE] 9998a1b9b6aSSam Leffler , chanp->wmep_acm 10008a1b9b6aSSam Leffler , chanp->wmep_aifsn 10018a1b9b6aSSam Leffler , chanp->wmep_logcwmin 10028a1b9b6aSSam Leffler , chanp->wmep_logcwmax 10038a1b9b6aSSam Leffler , chanp->wmep_txopLimit 10048a1b9b6aSSam Leffler ); 10058a1b9b6aSSam Leffler } 10068a1b9b6aSSam Leffler 1007b032f27cSSam Leffler /* XXX multi-bss */ 1008b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP && 1009ad262427SSam Leffler ic->ic_sta_assoc < 2 && (wme->wme_flags & WME_F_AGGRMODE) != 0) { 101068e8e04eSSam Leffler static const uint8_t logCwMin[IEEE80211_MODE_MAX] = { 1011be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = 3, 1012be0df3e7SSam Leffler [IEEE80211_MODE_11A] = 3, 1013be0df3e7SSam Leffler [IEEE80211_MODE_11B] = 4, 1014be0df3e7SSam Leffler [IEEE80211_MODE_11G] = 3, 1015be0df3e7SSam Leffler [IEEE80211_MODE_FH] = 4, 1016be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A] = 3, 1017be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G] = 3, 1018be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A] = 3, 1019be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = 3, 1020be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = 3, 10218a1b9b6aSSam Leffler }; 10228a1b9b6aSSam Leffler chanp = &wme->wme_chanParams.cap_wmeParams[WME_AC_BE]; 10238a1b9b6aSSam Leffler bssp = &wme->wme_bssChanParams.cap_wmeParams[WME_AC_BE]; 10248a1b9b6aSSam Leffler 102568e8e04eSSam Leffler chanp->wmep_logcwmin = bssp->wmep_logcwmin = logCwMin[mode]; 1026b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME, 10278a1b9b6aSSam Leffler "%s: %s log2(cwmin) %u\n", __func__ 10288a1b9b6aSSam Leffler , ieee80211_wme_acnames[WME_AC_BE] 10298a1b9b6aSSam Leffler , chanp->wmep_logcwmin 10308a1b9b6aSSam Leffler ); 10318a1b9b6aSSam Leffler } 1032b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP) { /* XXX ibss? */ 10338a1b9b6aSSam Leffler /* 10348a1b9b6aSSam Leffler * Arrange for a beacon update and bump the parameter 10358a1b9b6aSSam Leffler * set number so associated stations load the new values. 10368a1b9b6aSSam Leffler */ 10378a1b9b6aSSam Leffler wme->wme_bssChanParams.cap_info = 10388a1b9b6aSSam Leffler (wme->wme_bssChanParams.cap_info+1) & WME_QOSINFO_COUNT; 1039b032f27cSSam Leffler ieee80211_beacon_notify(vap, IEEE80211_BEACON_WME); 10408a1b9b6aSSam Leffler } 10418a1b9b6aSSam Leffler 10428a1b9b6aSSam Leffler wme->wme_update(ic); 10438a1b9b6aSSam Leffler 1044b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME, 10458a1b9b6aSSam Leffler "%s: WME params updated, cap_info 0x%x\n", __func__, 1046b032f27cSSam Leffler vap->iv_opmode == IEEE80211_M_STA ? 10478a1b9b6aSSam Leffler wme->wme_wmeChanParams.cap_info : 10488a1b9b6aSSam Leffler wme->wme_bssChanParams.cap_info); 10498a1b9b6aSSam Leffler } 10508a1b9b6aSSam Leffler 10518a1b9b6aSSam Leffler void 1052b032f27cSSam Leffler ieee80211_wme_updateparams(struct ieee80211vap *vap) 10538a1b9b6aSSam Leffler { 1054b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 10558a1b9b6aSSam Leffler 10568a1b9b6aSSam Leffler if (ic->ic_caps & IEEE80211_C_WME) { 1057b032f27cSSam Leffler IEEE80211_LOCK(ic); 1058b032f27cSSam Leffler ieee80211_wme_updateparams_locked(vap); 1059b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 10608a1b9b6aSSam Leffler } 10618a1b9b6aSSam Leffler } 10628a1b9b6aSSam Leffler 1063b032f27cSSam Leffler static void 1064b032f27cSSam Leffler parent_updown(void *arg, int npending) 106568e8e04eSSam Leffler { 1066b032f27cSSam Leffler struct ifnet *parent = arg; 106768e8e04eSSam Leffler 1068b032f27cSSam Leffler parent->if_ioctl(parent, SIOCSIFFLAGS, NULL); 1069b032f27cSSam Leffler } 107068e8e04eSSam Leffler 107168e8e04eSSam Leffler /* 1072ae55932eSAndrew Thompson * Block until the parent is in a known state. This is 1073ae55932eSAndrew Thompson * used after any operations that dispatch a task (e.g. 1074ae55932eSAndrew Thompson * to auto-configure the parent device up/down). 1075ae55932eSAndrew Thompson */ 1076ae55932eSAndrew Thompson void 1077ae55932eSAndrew Thompson ieee80211_waitfor_parent(struct ieee80211com *ic) 1078ae55932eSAndrew Thompson { 1079ae55932eSAndrew Thompson taskqueue_drain(taskqueue_thread, &ic->ic_parent_task); 1080ae55932eSAndrew Thompson } 1081ae55932eSAndrew Thompson 1082ae55932eSAndrew Thompson /* 1083b032f27cSSam Leffler * Start a vap running. If this is the first vap to be 1084b032f27cSSam Leffler * set running on the underlying device then we 1085b032f27cSSam Leffler * automatically bring the device up. 108668e8e04eSSam Leffler */ 1087b032f27cSSam Leffler void 1088b032f27cSSam Leffler ieee80211_start_locked(struct ieee80211vap *vap) 1089b032f27cSSam Leffler { 1090b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 1091b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1092b032f27cSSam Leffler struct ifnet *parent = ic->ic_ifp; 1093b032f27cSSam Leffler 1094b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1095b032f27cSSam Leffler 1096b032f27cSSam Leffler IEEE80211_DPRINTF(vap, 1097b032f27cSSam Leffler IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG, 1098b032f27cSSam Leffler "start running, %d vaps running\n", ic->ic_nrunning); 1099b032f27cSSam Leffler 1100b032f27cSSam Leffler if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { 1101b032f27cSSam Leffler /* 1102b032f27cSSam Leffler * Mark us running. Note that it's ok to do this first; 1103b032f27cSSam Leffler * if we need to bring the parent device up we defer that 1104b032f27cSSam Leffler * to avoid dropping the com lock. We expect the device 1105b032f27cSSam Leffler * to respond to being marked up by calling back into us 1106b032f27cSSam Leffler * through ieee80211_start_all at which point we'll come 1107b032f27cSSam Leffler * back in here and complete the work. 1108b032f27cSSam Leffler */ 1109b032f27cSSam Leffler ifp->if_drv_flags |= IFF_DRV_RUNNING; 1110b032f27cSSam Leffler /* 1111b032f27cSSam Leffler * We are not running; if this we are the first vap 1112b032f27cSSam Leffler * to be brought up auto-up the parent if necessary. 1113b032f27cSSam Leffler */ 1114b032f27cSSam Leffler if (ic->ic_nrunning++ == 0 && 1115b032f27cSSam Leffler (parent->if_drv_flags & IFF_DRV_RUNNING) == 0) { 1116b032f27cSSam Leffler IEEE80211_DPRINTF(vap, 1117b032f27cSSam Leffler IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG, 1118b032f27cSSam Leffler "%s: up parent %s\n", __func__, parent->if_xname); 1119b032f27cSSam Leffler parent->if_flags |= IFF_UP; 1120b032f27cSSam Leffler taskqueue_enqueue(taskqueue_thread, &ic->ic_parent_task); 1121b032f27cSSam Leffler return; 1122b032f27cSSam Leffler } 1123b032f27cSSam Leffler } 1124b032f27cSSam Leffler /* 1125b032f27cSSam Leffler * If the parent is up and running, then kick the 1126b032f27cSSam Leffler * 802.11 state machine as appropriate. 1127b032f27cSSam Leffler */ 1128b032f27cSSam Leffler if ((parent->if_drv_flags & IFF_DRV_RUNNING) && 1129b032f27cSSam Leffler vap->iv_roaming != IEEE80211_ROAMING_MANUAL) { 1130b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA) { 1131b032f27cSSam Leffler #if 0 1132b032f27cSSam Leffler /* XXX bypasses scan too easily; disable for now */ 1133b032f27cSSam Leffler /* 1134b032f27cSSam Leffler * Try to be intelligent about clocking the state 1135b032f27cSSam Leffler * machine. If we're currently in RUN state then 1136b032f27cSSam Leffler * we should be able to apply any new state/parameters 1137b032f27cSSam Leffler * simply by re-associating. Otherwise we need to 1138b032f27cSSam Leffler * re-scan to select an appropriate ap. 1139b032f27cSSam Leffler */ 1140b032f27cSSam Leffler if (vap->iv_state >= IEEE80211_S_RUN) 1141b032f27cSSam Leffler ieee80211_new_state_locked(vap, 1142b032f27cSSam Leffler IEEE80211_S_ASSOC, 1); 1143b032f27cSSam Leffler else 1144b032f27cSSam Leffler #endif 1145b032f27cSSam Leffler ieee80211_new_state_locked(vap, 1146b032f27cSSam Leffler IEEE80211_S_SCAN, 0); 114768e8e04eSSam Leffler } else { 114868e8e04eSSam Leffler /* 1149b032f27cSSam Leffler * For monitor+wds mode there's nothing to do but 1150b032f27cSSam Leffler * start running. Otherwise if this is the first 115168e8e04eSSam Leffler * vap to be brought up, start a scan which may be 115268e8e04eSSam Leffler * preempted if the station is locked to a particular 115368e8e04eSSam Leffler * channel. 115468e8e04eSSam Leffler */ 1155b032f27cSSam Leffler /* XXX needed? */ 1156b032f27cSSam Leffler ieee80211_new_state_locked(vap, IEEE80211_S_INIT, 0); 1157b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_MONITOR || 1158b032f27cSSam Leffler vap->iv_opmode == IEEE80211_M_WDS) 1159b032f27cSSam Leffler ieee80211_new_state_locked(vap, 1160b032f27cSSam Leffler IEEE80211_S_RUN, -1); 1161b032f27cSSam Leffler else 1162b032f27cSSam Leffler ieee80211_new_state_locked(vap, 1163b032f27cSSam Leffler IEEE80211_S_SCAN, 0); 116468e8e04eSSam Leffler } 116568e8e04eSSam Leffler } 1166b032f27cSSam Leffler } 1167b032f27cSSam Leffler 1168b032f27cSSam Leffler /* 1169b032f27cSSam Leffler * Start a single vap. 1170b032f27cSSam Leffler */ 1171b032f27cSSam Leffler void 1172b032f27cSSam Leffler ieee80211_init(void *arg) 1173b032f27cSSam Leffler { 1174b032f27cSSam Leffler struct ieee80211vap *vap = arg; 1175b032f27cSSam Leffler 1176b032f27cSSam Leffler /* 1177b032f27cSSam Leffler * This routine is publicly accessible through the vap's 1178b032f27cSSam Leffler * if_init method so guard against calls during detach. 1179b032f27cSSam Leffler * ieee80211_vap_detach null's the backpointer before 1180b032f27cSSam Leffler * tearing down state to signal any callback should be 1181b032f27cSSam Leffler * rejected/ignored. 1182b032f27cSSam Leffler */ 1183b032f27cSSam Leffler if (vap != NULL) { 1184b032f27cSSam Leffler IEEE80211_DPRINTF(vap, 1185b032f27cSSam Leffler IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG, 1186b032f27cSSam Leffler "%s\n", __func__); 1187b032f27cSSam Leffler 1188b032f27cSSam Leffler IEEE80211_LOCK(vap->iv_ic); 1189b032f27cSSam Leffler ieee80211_start_locked(vap); 1190b032f27cSSam Leffler IEEE80211_UNLOCK(vap->iv_ic); 1191b032f27cSSam Leffler } 1192b032f27cSSam Leffler } 1193b032f27cSSam Leffler 1194b032f27cSSam Leffler /* 1195b032f27cSSam Leffler * Start all runnable vap's on a device. 1196b032f27cSSam Leffler */ 1197b032f27cSSam Leffler void 1198b032f27cSSam Leffler ieee80211_start_all(struct ieee80211com *ic) 1199b032f27cSSam Leffler { 1200b032f27cSSam Leffler struct ieee80211vap *vap; 1201b032f27cSSam Leffler 1202b032f27cSSam Leffler IEEE80211_LOCK(ic); 1203b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 1204b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 1205b032f27cSSam Leffler if (IFNET_IS_UP_RUNNING(ifp)) /* NB: avoid recursion */ 1206b032f27cSSam Leffler ieee80211_start_locked(vap); 1207b032f27cSSam Leffler } 1208b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 1209b032f27cSSam Leffler } 1210b032f27cSSam Leffler 1211b032f27cSSam Leffler /* 1212b032f27cSSam Leffler * Stop a vap. We force it down using the state machine 1213b032f27cSSam Leffler * then mark it's ifnet not running. If this is the last 1214b032f27cSSam Leffler * vap running on the underlying device then we close it 1215b032f27cSSam Leffler * too to insure it will be properly initialized when the 1216b032f27cSSam Leffler * next vap is brought up. 1217b032f27cSSam Leffler */ 1218b032f27cSSam Leffler void 1219b032f27cSSam Leffler ieee80211_stop_locked(struct ieee80211vap *vap) 1220b032f27cSSam Leffler { 1221b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1222b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 1223b032f27cSSam Leffler struct ifnet *parent = ic->ic_ifp; 1224b032f27cSSam Leffler 1225b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1226b032f27cSSam Leffler 1227b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG, 1228b032f27cSSam Leffler "stop running, %d vaps running\n", ic->ic_nrunning); 1229b032f27cSSam Leffler 1230b032f27cSSam Leffler ieee80211_new_state_locked(vap, IEEE80211_S_INIT, -1); 1231b032f27cSSam Leffler if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 1232b032f27cSSam Leffler ifp->if_drv_flags &= ~IFF_DRV_RUNNING; /* mark us stopped */ 1233b032f27cSSam Leffler if (--ic->ic_nrunning == 0 && 1234b032f27cSSam Leffler (parent->if_drv_flags & IFF_DRV_RUNNING)) { 1235b032f27cSSam Leffler IEEE80211_DPRINTF(vap, 1236b032f27cSSam Leffler IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG, 1237b032f27cSSam Leffler "down parent %s\n", parent->if_xname); 1238b032f27cSSam Leffler parent->if_flags &= ~IFF_UP; 1239b032f27cSSam Leffler taskqueue_enqueue(taskqueue_thread, &ic->ic_parent_task); 1240b032f27cSSam Leffler } 1241b032f27cSSam Leffler } 1242b032f27cSSam Leffler } 1243b032f27cSSam Leffler 1244b032f27cSSam Leffler void 1245b032f27cSSam Leffler ieee80211_stop(struct ieee80211vap *vap) 1246b032f27cSSam Leffler { 1247b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1248b032f27cSSam Leffler 1249b032f27cSSam Leffler IEEE80211_LOCK(ic); 1250b032f27cSSam Leffler ieee80211_stop_locked(vap); 1251b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 1252b032f27cSSam Leffler } 1253b032f27cSSam Leffler 1254b032f27cSSam Leffler /* 1255b032f27cSSam Leffler * Stop all vap's running on a device. 1256b032f27cSSam Leffler */ 1257b032f27cSSam Leffler void 1258b032f27cSSam Leffler ieee80211_stop_all(struct ieee80211com *ic) 1259b032f27cSSam Leffler { 1260b032f27cSSam Leffler struct ieee80211vap *vap; 1261b032f27cSSam Leffler 1262b032f27cSSam Leffler IEEE80211_LOCK(ic); 1263b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 1264b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 1265b032f27cSSam Leffler if (IFNET_IS_UP_RUNNING(ifp)) /* NB: avoid recursion */ 1266b032f27cSSam Leffler ieee80211_stop_locked(vap); 1267b032f27cSSam Leffler } 1268b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 1269ae55932eSAndrew Thompson 1270ae55932eSAndrew Thompson ieee80211_waitfor_parent(ic); 127168e8e04eSSam Leffler } 127268e8e04eSSam Leffler 127368e8e04eSSam Leffler /* 12746076cbacSSam Leffler * Stop all vap's running on a device and arrange 12756076cbacSSam Leffler * for those that were running to be resumed. 12766076cbacSSam Leffler */ 12776076cbacSSam Leffler void 12786076cbacSSam Leffler ieee80211_suspend_all(struct ieee80211com *ic) 12796076cbacSSam Leffler { 12806076cbacSSam Leffler struct ieee80211vap *vap; 12816076cbacSSam Leffler 12826076cbacSSam Leffler IEEE80211_LOCK(ic); 12836076cbacSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 12846076cbacSSam Leffler struct ifnet *ifp = vap->iv_ifp; 12856076cbacSSam Leffler if (IFNET_IS_UP_RUNNING(ifp)) { /* NB: avoid recursion */ 12866076cbacSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_RESUME; 12876076cbacSSam Leffler ieee80211_stop_locked(vap); 12886076cbacSSam Leffler } 12896076cbacSSam Leffler } 12906076cbacSSam Leffler IEEE80211_UNLOCK(ic); 1291ae55932eSAndrew Thompson 1292ae55932eSAndrew Thompson ieee80211_waitfor_parent(ic); 12936076cbacSSam Leffler } 12946076cbacSSam Leffler 12956076cbacSSam Leffler /* 12966076cbacSSam Leffler * Start all vap's marked for resume. 12976076cbacSSam Leffler */ 12986076cbacSSam Leffler void 12996076cbacSSam Leffler ieee80211_resume_all(struct ieee80211com *ic) 13006076cbacSSam Leffler { 13016076cbacSSam Leffler struct ieee80211vap *vap; 13026076cbacSSam Leffler 13036076cbacSSam Leffler IEEE80211_LOCK(ic); 13046076cbacSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 13056076cbacSSam Leffler struct ifnet *ifp = vap->iv_ifp; 13066076cbacSSam Leffler if (!IFNET_IS_UP_RUNNING(ifp) && 13076076cbacSSam Leffler (vap->iv_flags_ext & IEEE80211_FEXT_RESUME)) { 13086076cbacSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_RESUME; 13096076cbacSSam Leffler ieee80211_start_locked(vap); 13106076cbacSSam Leffler } 13116076cbacSSam Leffler } 13126076cbacSSam Leffler IEEE80211_UNLOCK(ic); 13136076cbacSSam Leffler } 13146076cbacSSam Leffler 13156076cbacSSam Leffler /* 131668e8e04eSSam Leffler * Switch between turbo and non-turbo operating modes. 131768e8e04eSSam Leffler * Use the specified channel flags to locate the new 131868e8e04eSSam Leffler * channel, update 802.11 state, and then call back into 131968e8e04eSSam Leffler * the driver to effect the change. 132068e8e04eSSam Leffler */ 132168e8e04eSSam Leffler void 1322b032f27cSSam Leffler ieee80211_dturbo_switch(struct ieee80211vap *vap, int newflags) 132368e8e04eSSam Leffler { 1324b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 132568e8e04eSSam Leffler struct ieee80211_channel *chan; 132668e8e04eSSam Leffler 132768e8e04eSSam Leffler chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags); 132868e8e04eSSam Leffler if (chan == NULL) { /* XXX should not happen */ 1329b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 133068e8e04eSSam Leffler "%s: no channel with freq %u flags 0x%x\n", 133168e8e04eSSam Leffler __func__, ic->ic_bsschan->ic_freq, newflags); 133268e8e04eSSam Leffler return; 133368e8e04eSSam Leffler } 133468e8e04eSSam Leffler 1335b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 133668e8e04eSSam Leffler "%s: %s -> %s (freq %u flags 0x%x)\n", __func__, 133768e8e04eSSam Leffler ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)], 133868e8e04eSSam Leffler ieee80211_phymode_name[ieee80211_chan2mode(chan)], 133968e8e04eSSam Leffler chan->ic_freq, chan->ic_flags); 134068e8e04eSSam Leffler 134168e8e04eSSam Leffler ic->ic_bsschan = chan; 134268e8e04eSSam Leffler ic->ic_prevchan = ic->ic_curchan; 134368e8e04eSSam Leffler ic->ic_curchan = chan; 134468e8e04eSSam Leffler ic->ic_set_channel(ic); 134568e8e04eSSam Leffler /* NB: do not need to reset ERP state 'cuz we're in sta mode */ 134668e8e04eSSam Leffler } 134768e8e04eSSam Leffler 1348e701e041SSam Leffler void 1349e701e041SSam Leffler ieee80211_beacon_miss(struct ieee80211com *ic) 1350e701e041SSam Leffler { 1351b032f27cSSam Leffler struct ieee80211vap *vap; 1352e701e041SSam Leffler 1353b032f27cSSam Leffler if (ic->ic_flags & IEEE80211_F_SCAN) 1354e701e041SSam Leffler return; 1355b032f27cSSam Leffler /* XXX locking */ 1356b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 1357e701e041SSam Leffler /* 1358b032f27cSSam Leffler * We only pass events through for sta vap's in RUN state; 1359b032f27cSSam Leffler * may be too restrictive but for now this saves all the 1360b032f27cSSam Leffler * handlers duplicating these checks. 1361e701e041SSam Leffler */ 1362b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA && 1363b032f27cSSam Leffler vap->iv_state == IEEE80211_S_RUN && 1364b032f27cSSam Leffler vap->iv_bmiss != NULL) 1365b032f27cSSam Leffler vap->iv_bmiss(vap); 1366e701e041SSam Leffler } 136768e8e04eSSam Leffler } 1368e701e041SSam Leffler 1369e99662a6SSam Leffler /* 1370e99662a6SSam Leffler * Software beacon miss handling. Check if any beacons 1371e99662a6SSam Leffler * were received in the last period. If not post a 1372e99662a6SSam Leffler * beacon miss; otherwise reset the counter. 1373e99662a6SSam Leffler */ 1374b032f27cSSam Leffler void 1375e99662a6SSam Leffler ieee80211_swbmiss(void *arg) 1376e99662a6SSam Leffler { 1377b032f27cSSam Leffler struct ieee80211vap *vap = arg; 1378c448998dSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1379e99662a6SSam Leffler 1380c448998dSSam Leffler /* XXX sleep state? */ 1381c448998dSSam Leffler KASSERT(vap->iv_state == IEEE80211_S_RUN, 1382c448998dSSam Leffler ("wrong state %d", vap->iv_state)); 1383c448998dSSam Leffler 1384c448998dSSam Leffler if (ic->ic_flags & IEEE80211_F_SCAN) { 1385c448998dSSam Leffler /* 1386c448998dSSam Leffler * If scanning just ignore and reset state. If we get a 1387c448998dSSam Leffler * bmiss after coming out of scan because we haven't had 1388c448998dSSam Leffler * time to receive a beacon then we should probe the AP 1389c448998dSSam Leffler * before posting a real bmiss (unless iv_bmiss_max has 1390c448998dSSam Leffler * been artifiically lowered). A cleaner solution might 1391c448998dSSam Leffler * be to disable the timer on scan start/end but to handle 1392c448998dSSam Leffler * case of multiple sta vap's we'd need to disable the 1393c448998dSSam Leffler * timers of all affected vap's. 1394c448998dSSam Leffler */ 1395c448998dSSam Leffler vap->iv_swbmiss_count = 0; 1396c448998dSSam Leffler } else if (vap->iv_swbmiss_count == 0) { 1397b032f27cSSam Leffler if (vap->iv_bmiss != NULL) 1398b032f27cSSam Leffler vap->iv_bmiss(vap); 1399b032f27cSSam Leffler if (vap->iv_bmiss_count == 0) /* don't re-arm timer */ 1400e99662a6SSam Leffler return; 1401e99662a6SSam Leffler } else 1402b032f27cSSam Leffler vap->iv_swbmiss_count = 0; 1403b032f27cSSam Leffler callout_reset(&vap->iv_swbmiss, vap->iv_swbmiss_period, 1404b032f27cSSam Leffler ieee80211_swbmiss, vap); 14057edb8cf9SSam Leffler } 14067edb8cf9SSam Leffler 140768e8e04eSSam Leffler /* 1408b032f27cSSam Leffler * Start an 802.11h channel switch. We record the parameters, 1409b032f27cSSam Leffler * mark the operation pending, notify each vap through the 1410b032f27cSSam Leffler * beacon update mechanism so it can update the beacon frame 1411b032f27cSSam Leffler * contents, and then switch vap's to CSA state to block outbound 1412b032f27cSSam Leffler * traffic. Devices that handle CSA directly can use the state 1413b032f27cSSam Leffler * switch to do the right thing so long as they call 1414b032f27cSSam Leffler * ieee80211_csa_completeswitch when it's time to complete the 1415b032f27cSSam Leffler * channel change. Devices that depend on the net80211 layer can 1416b032f27cSSam Leffler * use ieee80211_beacon_update to handle the countdown and the 1417b032f27cSSam Leffler * channel switch. 1418b032f27cSSam Leffler */ 1419b032f27cSSam Leffler void 1420b032f27cSSam Leffler ieee80211_csa_startswitch(struct ieee80211com *ic, 1421b032f27cSSam Leffler struct ieee80211_channel *c, int mode, int count) 1422b032f27cSSam Leffler { 1423b032f27cSSam Leffler struct ieee80211vap *vap; 1424b032f27cSSam Leffler 1425b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1426b032f27cSSam Leffler 1427b032f27cSSam Leffler ic->ic_csa_newchan = c; 1428b032f27cSSam Leffler ic->ic_csa_count = count; 1429b032f27cSSam Leffler /* XXX record mode? */ 1430b032f27cSSam Leffler ic->ic_flags |= IEEE80211_F_CSAPENDING; 1431b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 1432b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP || 1433b032f27cSSam Leffler vap->iv_opmode == IEEE80211_M_IBSS) 1434b032f27cSSam Leffler ieee80211_beacon_notify(vap, IEEE80211_BEACON_CSA); 1435b032f27cSSam Leffler /* switch to CSA state to block outbound traffic */ 1436b032f27cSSam Leffler if (vap->iv_state == IEEE80211_S_RUN) 1437b032f27cSSam Leffler ieee80211_new_state_locked(vap, IEEE80211_S_CSA, 0); 1438b032f27cSSam Leffler } 1439b032f27cSSam Leffler ieee80211_notify_csa(ic, c, mode, count); 1440b032f27cSSam Leffler } 1441b032f27cSSam Leffler 1442b032f27cSSam Leffler /* 1443b032f27cSSam Leffler * Complete an 802.11h channel switch started by ieee80211_csa_startswitch. 1444b032f27cSSam Leffler * We clear state and move all vap's in CSA state to RUN state 1445b032f27cSSam Leffler * so they can again transmit. 1446b032f27cSSam Leffler */ 1447b032f27cSSam Leffler void 1448b032f27cSSam Leffler ieee80211_csa_completeswitch(struct ieee80211com *ic) 1449b032f27cSSam Leffler { 1450b032f27cSSam Leffler struct ieee80211vap *vap; 1451b032f27cSSam Leffler 1452b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1453b032f27cSSam Leffler 1454b032f27cSSam Leffler KASSERT(ic->ic_flags & IEEE80211_F_CSAPENDING, ("csa not pending")); 1455b032f27cSSam Leffler 1456b032f27cSSam Leffler ieee80211_setcurchan(ic, ic->ic_csa_newchan); 1457b032f27cSSam Leffler ic->ic_csa_newchan = NULL; 1458b032f27cSSam Leffler ic->ic_flags &= ~IEEE80211_F_CSAPENDING; 1459b032f27cSSam Leffler 1460b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 1461b032f27cSSam Leffler if (vap->iv_state == IEEE80211_S_CSA) 1462b032f27cSSam Leffler ieee80211_new_state_locked(vap, IEEE80211_S_RUN, 0); 1463b032f27cSSam Leffler } 1464b032f27cSSam Leffler 1465b032f27cSSam Leffler /* 1466b032f27cSSam Leffler * Complete a DFS CAC started by ieee80211_dfs_cac_start. 1467b032f27cSSam Leffler * We clear state and move all vap's in CAC state to RUN state. 1468b032f27cSSam Leffler */ 1469b032f27cSSam Leffler void 1470b032f27cSSam Leffler ieee80211_cac_completeswitch(struct ieee80211vap *vap0) 1471b032f27cSSam Leffler { 1472b032f27cSSam Leffler struct ieee80211com *ic = vap0->iv_ic; 1473b032f27cSSam Leffler struct ieee80211vap *vap; 1474b032f27cSSam Leffler 1475b032f27cSSam Leffler IEEE80211_LOCK(ic); 1476b032f27cSSam Leffler /* 1477b032f27cSSam Leffler * Complete CAC state change for lead vap first; then 1478b032f27cSSam Leffler * clock all the other vap's waiting. 1479b032f27cSSam Leffler */ 1480b032f27cSSam Leffler KASSERT(vap0->iv_state == IEEE80211_S_CAC, 1481b032f27cSSam Leffler ("wrong state %d", vap0->iv_state)); 1482b032f27cSSam Leffler ieee80211_new_state_locked(vap0, IEEE80211_S_RUN, 0); 1483b032f27cSSam Leffler 1484b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) 1485b032f27cSSam Leffler if (vap->iv_state == IEEE80211_S_CAC) 1486b032f27cSSam Leffler ieee80211_new_state_locked(vap, IEEE80211_S_RUN, 0); 1487b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 1488b032f27cSSam Leffler } 1489b032f27cSSam Leffler 1490b032f27cSSam Leffler /* 1491b032f27cSSam Leffler * Force all vap's other than the specified vap to the INIT state 1492b032f27cSSam Leffler * and mark them as waiting for a scan to complete. These vaps 1493b032f27cSSam Leffler * will be brought up when the scan completes and the scanning vap 1494b032f27cSSam Leffler * reaches RUN state by wakeupwaiting. 1495b032f27cSSam Leffler * XXX if we do this in threads we can use sleep/wakeup. 149668e8e04eSSam Leffler */ 149768e8e04eSSam Leffler static void 1498b032f27cSSam Leffler markwaiting(struct ieee80211vap *vap0) 149968e8e04eSSam Leffler { 1500b032f27cSSam Leffler struct ieee80211com *ic = vap0->iv_ic; 1501b032f27cSSam Leffler struct ieee80211vap *vap; 1502b032f27cSSam Leffler 1503b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1504b032f27cSSam Leffler 1505b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 1506b032f27cSSam Leffler if (vap == vap0) 1507b032f27cSSam Leffler continue; 1508b032f27cSSam Leffler if (vap->iv_state != IEEE80211_S_INIT) { 1509b032f27cSSam Leffler vap->iv_newstate(vap, IEEE80211_S_INIT, 0); 1510b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_SCANWAIT; 1511b032f27cSSam Leffler } 151268e8e04eSSam Leffler } 151368e8e04eSSam Leffler } 151468e8e04eSSam Leffler 1515b032f27cSSam Leffler /* 1516b032f27cSSam Leffler * Wakeup all vap's waiting for a scan to complete. This is the 1517b032f27cSSam Leffler * companion to markwaiting (above) and is used to coordinate 1518b032f27cSSam Leffler * multiple vaps scanning. 1519b032f27cSSam Leffler */ 1520b032f27cSSam Leffler static void 1521b032f27cSSam Leffler wakeupwaiting(struct ieee80211vap *vap0) 1522b032f27cSSam Leffler { 1523b032f27cSSam Leffler struct ieee80211com *ic = vap0->iv_ic; 1524b032f27cSSam Leffler struct ieee80211vap *vap; 1525b032f27cSSam Leffler 1526b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1527b032f27cSSam Leffler 1528b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { 1529b032f27cSSam Leffler if (vap == vap0) 1530b032f27cSSam Leffler continue; 1531b032f27cSSam Leffler if (vap->iv_flags_ext & IEEE80211_FEXT_SCANWAIT) { 1532b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANWAIT; 1533b032f27cSSam Leffler /* NB: sta's cannot go INIT->RUN */ 1534b032f27cSSam Leffler vap->iv_newstate(vap, 1535b032f27cSSam Leffler vap->iv_opmode == IEEE80211_M_STA ? 1536b032f27cSSam Leffler IEEE80211_S_SCAN : IEEE80211_S_RUN, 0); 1537b032f27cSSam Leffler } 1538b032f27cSSam Leffler } 1539b032f27cSSam Leffler } 1540b032f27cSSam Leffler 1541b032f27cSSam Leffler /* 1542b032f27cSSam Leffler * Handle post state change work common to all operating modes. 1543b032f27cSSam Leffler */ 1544b032f27cSSam Leffler static void 1545b032f27cSSam Leffler ieee80211_newstate_cb(struct ieee80211vap *vap, 1546b032f27cSSam Leffler enum ieee80211_state nstate, int arg) 1547b032f27cSSam Leffler { 1548b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1549b032f27cSSam Leffler 1550b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1551b032f27cSSam Leffler 1552b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 1553b032f27cSSam Leffler "%s: %s arg %d\n", __func__, ieee80211_state_name[nstate], arg); 1554b032f27cSSam Leffler 1555b032f27cSSam Leffler if (nstate == IEEE80211_S_RUN) { 1556b032f27cSSam Leffler /* 1557b032f27cSSam Leffler * OACTIVE may be set on the vap if the upper layer 1558b032f27cSSam Leffler * tried to transmit (e.g. IPv6 NDP) before we reach 1559b032f27cSSam Leffler * RUN state. Clear it and restart xmit. 1560b032f27cSSam Leffler * 1561b032f27cSSam Leffler * Note this can also happen as a result of SLEEP->RUN 1562b032f27cSSam Leffler * (i.e. coming out of power save mode). 1563b032f27cSSam Leffler */ 1564b032f27cSSam Leffler vap->iv_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 1565b032f27cSSam Leffler if_start(vap->iv_ifp); 1566b032f27cSSam Leffler 1567b032f27cSSam Leffler /* bring up any vaps waiting on us */ 1568b032f27cSSam Leffler wakeupwaiting(vap); 1569b032f27cSSam Leffler } else if (nstate == IEEE80211_S_INIT) { 1570b032f27cSSam Leffler /* 1571b032f27cSSam Leffler * Flush the scan cache if we did the last scan (XXX?) 1572b032f27cSSam Leffler * and flush any frames on send queues from this vap. 1573b032f27cSSam Leffler * Note the mgt q is used only for legacy drivers and 1574b032f27cSSam Leffler * will go away shortly. 1575b032f27cSSam Leffler */ 1576b032f27cSSam Leffler ieee80211_scan_flush(vap); 1577b032f27cSSam Leffler 1578b032f27cSSam Leffler /* XXX NB: cast for altq */ 1579b032f27cSSam Leffler ieee80211_flush_ifq((struct ifqueue *)&ic->ic_ifp->if_snd, vap); 1580b032f27cSSam Leffler } 1581b032f27cSSam Leffler vap->iv_newstate_cb = NULL; 1582b032f27cSSam Leffler } 1583b032f27cSSam Leffler 1584b032f27cSSam Leffler /* 1585b032f27cSSam Leffler * Public interface for initiating a state machine change. 1586b032f27cSSam Leffler * This routine single-threads the request and coordinates 1587b032f27cSSam Leffler * the scheduling of multiple vaps for the purpose of selecting 1588b032f27cSSam Leffler * an operating channel. Specifically the following scenarios 1589b032f27cSSam Leffler * are handled: 1590b032f27cSSam Leffler * o only one vap can be selecting a channel so on transition to 1591b032f27cSSam Leffler * SCAN state if another vap is already scanning then 1592b032f27cSSam Leffler * mark the caller for later processing and return without 1593b032f27cSSam Leffler * doing anything (XXX? expectations by caller of synchronous operation) 1594b032f27cSSam Leffler * o only one vap can be doing CAC of a channel so on transition to 1595b032f27cSSam Leffler * CAC state if another vap is already scanning for radar then 1596b032f27cSSam Leffler * mark the caller for later processing and return without 1597b032f27cSSam Leffler * doing anything (XXX? expectations by caller of synchronous operation) 1598b032f27cSSam Leffler * o if another vap is already running when a request is made 1599b032f27cSSam Leffler * to SCAN then an operating channel has been chosen; bypass 1600b032f27cSSam Leffler * the scan and just join the channel 1601b032f27cSSam Leffler * 1602b032f27cSSam Leffler * Note that the state change call is done through the iv_newstate 1603b032f27cSSam Leffler * method pointer so any driver routine gets invoked. The driver 1604b032f27cSSam Leffler * will normally call back into operating mode-specific 1605b032f27cSSam Leffler * ieee80211_newstate routines (below) unless it needs to completely 1606b032f27cSSam Leffler * bypass the state machine (e.g. because the firmware has it's 1607b032f27cSSam Leffler * own idea how things should work). Bypassing the net80211 layer 1608b032f27cSSam Leffler * is usually a mistake and indicates lack of proper integration 1609b032f27cSSam Leffler * with the net80211 layer. 1610b032f27cSSam Leffler */ 16118a1b9b6aSSam Leffler static int 1612b032f27cSSam Leffler ieee80211_new_state_locked(struct ieee80211vap *vap, 1613b032f27cSSam Leffler enum ieee80211_state nstate, int arg) 16148a1b9b6aSSam Leffler { 1615b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1616b032f27cSSam Leffler struct ieee80211vap *vp; 1617a11c9a5cSSam Leffler enum ieee80211_state ostate; 1618b032f27cSSam Leffler int nrunning, nscanning, rc; 16191a1e1d21SSam Leffler 1620b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 1621b032f27cSSam Leffler 1622b032f27cSSam Leffler nrunning = nscanning = 0; 1623b032f27cSSam Leffler /* XXX can track this state instead of calculating */ 1624b032f27cSSam Leffler TAILQ_FOREACH(vp, &ic->ic_vaps, iv_next) { 1625b032f27cSSam Leffler if (vp != vap) { 1626b032f27cSSam Leffler if (vp->iv_state >= IEEE80211_S_RUN) 1627b032f27cSSam Leffler nrunning++; 1628b032f27cSSam Leffler /* XXX doesn't handle bg scan */ 1629b032f27cSSam Leffler /* NB: CAC+AUTH+ASSOC treated like SCAN */ 1630b032f27cSSam Leffler else if (vp->iv_state > IEEE80211_S_INIT) 1631b032f27cSSam Leffler nscanning++; 1632b032f27cSSam Leffler } 1633b032f27cSSam Leffler } 1634b032f27cSSam Leffler ostate = vap->iv_state; 1635b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 1636b032f27cSSam Leffler "%s: %s -> %s (nrunning %d nscanning %d)\n", __func__, 1637b032f27cSSam Leffler ieee80211_state_name[ostate], ieee80211_state_name[nstate], 1638b032f27cSSam Leffler nrunning, nscanning); 16391a1e1d21SSam Leffler switch (nstate) { 16401a1e1d21SSam Leffler case IEEE80211_S_SCAN: 1641b032f27cSSam Leffler if (ostate == IEEE80211_S_INIT) { 16421a1e1d21SSam Leffler /* 1643b032f27cSSam Leffler * INIT -> SCAN happens on initial bringup. 16441a1e1d21SSam Leffler */ 1645b032f27cSSam Leffler KASSERT(!(nscanning && nrunning), 1646b032f27cSSam Leffler ("%d scanning and %d running", nscanning, nrunning)); 1647b032f27cSSam Leffler if (nscanning) { 164868e8e04eSSam Leffler /* 1649b032f27cSSam Leffler * Someone is scanning, defer our state 1650b032f27cSSam Leffler * change until the work has completed. 165168e8e04eSSam Leffler */ 1652b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 1653b032f27cSSam Leffler "%s: defer %s -> %s\n", 1654b032f27cSSam Leffler __func__, ieee80211_state_name[ostate], 1655b032f27cSSam Leffler ieee80211_state_name[nstate]); 1656b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_SCANWAIT; 1657b032f27cSSam Leffler rc = 0; 1658b032f27cSSam Leffler goto done; 165968e8e04eSSam Leffler } 1660b032f27cSSam Leffler if (nrunning) { 166168e8e04eSSam Leffler /* 1662b032f27cSSam Leffler * Someone is operating; just join the channel 1663b032f27cSSam Leffler * they have chosen. 166468e8e04eSSam Leffler */ 1665b032f27cSSam Leffler /* XXX kill arg? */ 1666b032f27cSSam Leffler /* XXX check each opmode, adhoc? */ 1667b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA) 1668b032f27cSSam Leffler nstate = IEEE80211_S_SCAN; 16691a1e1d21SSam Leffler else 1670b032f27cSSam Leffler nstate = IEEE80211_S_RUN; 1671b032f27cSSam Leffler #ifdef IEEE80211_DEBUG 1672b032f27cSSam Leffler if (nstate != IEEE80211_S_SCAN) { 1673b032f27cSSam Leffler IEEE80211_DPRINTF(vap, 1674b032f27cSSam Leffler IEEE80211_MSG_STATE, 1675b032f27cSSam Leffler "%s: override, now %s -> %s\n", 1676b032f27cSSam Leffler __func__, 1677b032f27cSSam Leffler ieee80211_state_name[ostate], 1678b032f27cSSam Leffler ieee80211_state_name[nstate]); 16791a1e1d21SSam Leffler } 16808a1b9b6aSSam Leffler #endif 168168e8e04eSSam Leffler } 1682b032f27cSSam Leffler } else { 1683b032f27cSSam Leffler /* 1684b032f27cSSam Leffler * SCAN was forced; e.g. on beacon miss. Force 1685b032f27cSSam Leffler * other running vap's to INIT state and mark 1686b032f27cSSam Leffler * them as waiting for the scan to complete. This 1687b032f27cSSam Leffler * insures they don't interfere with our scanning. 1688b032f27cSSam Leffler * 1689b032f27cSSam Leffler * XXX not always right, assumes ap follows sta 1690b032f27cSSam Leffler */ 1691b032f27cSSam Leffler markwaiting(vap); 1692b032f27cSSam Leffler } 16931a1e1d21SSam Leffler break; 1694b032f27cSSam Leffler case IEEE80211_S_RUN: 1695b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_WDS && 1696b032f27cSSam Leffler (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) && 1697b032f27cSSam Leffler nscanning) { 1698b032f27cSSam Leffler /* 1699b032f27cSSam Leffler * Legacy WDS with someone else scanning; don't 1700b032f27cSSam Leffler * go online until that completes as we should 1701b032f27cSSam Leffler * follow the other vap to the channel they choose. 1702b032f27cSSam Leffler */ 1703b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 1704b032f27cSSam Leffler "%s: defer %s -> %s (legacy WDS)\n", __func__, 1705b032f27cSSam Leffler ieee80211_state_name[ostate], 1706b032f27cSSam Leffler ieee80211_state_name[nstate]); 1707b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_SCANWAIT; 1708b032f27cSSam Leffler rc = 0; 1709b032f27cSSam Leffler goto done; 1710b032f27cSSam Leffler } 1711b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP && 1712b032f27cSSam Leffler IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) && 1713b032f27cSSam Leffler (vap->iv_flags_ext & IEEE80211_FEXT_DFS) && 1714b032f27cSSam Leffler !IEEE80211_IS_CHAN_CACDONE(ic->ic_bsschan)) { 1715b032f27cSSam Leffler /* 1716b032f27cSSam Leffler * This is a DFS channel, transition to CAC state 1717b032f27cSSam Leffler * instead of RUN. This allows us to initiate 1718b032f27cSSam Leffler * Channel Availability Check (CAC) as specified 1719b032f27cSSam Leffler * by 11h/DFS. 1720b032f27cSSam Leffler */ 1721b032f27cSSam Leffler nstate = IEEE80211_S_CAC; 1722b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 1723b032f27cSSam Leffler "%s: override %s -> %s (DFS)\n", __func__, 1724b032f27cSSam Leffler ieee80211_state_name[ostate], 1725b032f27cSSam Leffler ieee80211_state_name[nstate]); 1726b032f27cSSam Leffler } 1727b032f27cSSam Leffler break; 1728b032f27cSSam Leffler case IEEE80211_S_INIT: 1729b032f27cSSam Leffler if (ostate == IEEE80211_S_INIT ) { 1730b032f27cSSam Leffler /* XXX don't believe this */ 1731b032f27cSSam Leffler /* INIT -> INIT. nothing to do */ 1732b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANWAIT; 1733b032f27cSSam Leffler } 1734b032f27cSSam Leffler /* fall thru... */ 173514fb6b8fSSam Leffler default: 173614fb6b8fSSam Leffler break; 17371a1e1d21SSam Leffler } 1738b032f27cSSam Leffler /* XXX on transition RUN->CAC do we need to set nstate = iv_state? */ 1739b032f27cSSam Leffler if (ostate != nstate) { 1740e99662a6SSam Leffler /* 1741b032f27cSSam Leffler * Arrange for work to happen after state change completes. 1742b032f27cSSam Leffler * If this happens asynchronously the caller must arrange 1743b032f27cSSam Leffler * for the com lock to be held. 1744e99662a6SSam Leffler */ 1745b032f27cSSam Leffler vap->iv_newstate_cb = ieee80211_newstate_cb; 1746e99662a6SSam Leffler } 1747b032f27cSSam Leffler rc = vap->iv_newstate(vap, nstate, arg); 1748b032f27cSSam Leffler if (rc == 0 && vap->iv_newstate_cb != NULL) 1749b032f27cSSam Leffler vap->iv_newstate_cb(vap, nstate, arg); 1750b032f27cSSam Leffler done: 1751b032f27cSSam Leffler return rc; 17528a1b9b6aSSam Leffler } 1753b032f27cSSam Leffler 1754b032f27cSSam Leffler int 1755b032f27cSSam Leffler ieee80211_new_state(struct ieee80211vap *vap, 1756b032f27cSSam Leffler enum ieee80211_state nstate, int arg) 1757b032f27cSSam Leffler { 1758b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 1759b032f27cSSam Leffler int rc; 1760b032f27cSSam Leffler 1761b032f27cSSam Leffler IEEE80211_LOCK(ic); 1762b032f27cSSam Leffler rc = ieee80211_new_state_locked(vap, nstate, arg); 1763b032f27cSSam Leffler IEEE80211_UNLOCK(ic); 1764b032f27cSSam Leffler return rc; 17651a1e1d21SSam Leffler } 1766