1b032f27cSSam Leffler /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3fe267a55SPedro F. Giffuni * 4b032f27cSSam Leffler * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting 5b032f27cSSam Leffler * All rights reserved. 6b032f27cSSam Leffler * 7b032f27cSSam Leffler * Redistribution and use in source and binary forms, with or without 8b032f27cSSam Leffler * modification, are permitted provided that the following conditions 9b032f27cSSam Leffler * are met: 10b032f27cSSam Leffler * 1. Redistributions of source code must retain the above copyright 11b032f27cSSam Leffler * notice, this list of conditions and the following disclaimer. 12b032f27cSSam Leffler * 2. Redistributions in binary form must reproduce the above copyright 13b032f27cSSam Leffler * notice, this list of conditions and the following disclaimer in the 14b032f27cSSam Leffler * documentation and/or other materials provided with the distribution. 15b032f27cSSam Leffler * 16b032f27cSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17b032f27cSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18b032f27cSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19b032f27cSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20b032f27cSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21b032f27cSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22b032f27cSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23b032f27cSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24b032f27cSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25b032f27cSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26b032f27cSSam Leffler */ 27b032f27cSSam Leffler 28b032f27cSSam Leffler #include <sys/cdefs.h> 29b032f27cSSam Leffler #ifdef __FreeBSD__ 30b032f27cSSam Leffler __FBSDID("$FreeBSD$"); 31b032f27cSSam Leffler #endif 32b032f27cSSam Leffler 33b032f27cSSam Leffler /* 34b032f27cSSam Leffler * IEEE 802.11 HOSTAP mode support. 35b032f27cSSam Leffler */ 36b032f27cSSam Leffler #include "opt_inet.h" 37b032f27cSSam Leffler #include "opt_wlan.h" 38b032f27cSSam Leffler 39b032f27cSSam Leffler #include <sys/param.h> 40b032f27cSSam Leffler #include <sys/systm.h> 41b032f27cSSam Leffler #include <sys/mbuf.h> 42b032f27cSSam Leffler #include <sys/malloc.h> 43b032f27cSSam Leffler #include <sys/kernel.h> 44b032f27cSSam Leffler 45b032f27cSSam Leffler #include <sys/socket.h> 46b032f27cSSam Leffler #include <sys/sockio.h> 47b032f27cSSam Leffler #include <sys/endian.h> 48b032f27cSSam Leffler #include <sys/errno.h> 49b032f27cSSam Leffler #include <sys/proc.h> 50b032f27cSSam Leffler #include <sys/sysctl.h> 51b032f27cSSam Leffler 52b032f27cSSam Leffler #include <net/if.h> 5376039bc8SGleb Smirnoff #include <net/if_var.h> 54b032f27cSSam Leffler #include <net/if_media.h> 55b032f27cSSam Leffler #include <net/if_llc.h> 563d0d5b21SJustin Hibbits #include <net/if_private.h> 57b032f27cSSam Leffler #include <net/ethernet.h> 58b032f27cSSam Leffler 59b032f27cSSam Leffler #include <net/bpf.h> 60b032f27cSSam Leffler 61b032f27cSSam Leffler #include <net80211/ieee80211_var.h> 62b032f27cSSam Leffler #include <net80211/ieee80211_hostap.h> 63b032f27cSSam Leffler #include <net80211/ieee80211_input.h> 64616190d0SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG 65616190d0SSam Leffler #include <net80211/ieee80211_superg.h> 66616190d0SSam Leffler #endif 67b032f27cSSam Leffler #include <net80211/ieee80211_wds.h> 6851172f62SAdrian Chadd #include <net80211/ieee80211_vht.h> 698379e8dbSAdrian Chadd #include <net80211/ieee80211_sta.h> /* for parse_wmeie */ 70b032f27cSSam Leffler 71b032f27cSSam Leffler #define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) 72b032f27cSSam Leffler 73b032f27cSSam Leffler static void hostap_vattach(struct ieee80211vap *); 74b032f27cSSam Leffler static int hostap_newstate(struct ieee80211vap *, enum ieee80211_state, int); 75b032f27cSSam Leffler static int hostap_input(struct ieee80211_node *ni, struct mbuf *m, 76c79f192cSAdrian Chadd const struct ieee80211_rx_stats *, 775463c4a4SSam Leffler int rssi, int nf); 78b032f27cSSam Leffler static void hostap_deliver_data(struct ieee80211vap *, 79b032f27cSSam Leffler struct ieee80211_node *, struct mbuf *); 80b032f27cSSam Leffler static void hostap_recv_mgmt(struct ieee80211_node *, struct mbuf *, 81c79f192cSAdrian Chadd int subtype, const struct ieee80211_rx_stats *rxs, int rssi, int nf); 8249eae5f7SSam Leffler static void hostap_recv_ctl(struct ieee80211_node *, struct mbuf *, int); 83b032f27cSSam Leffler 84b032f27cSSam Leffler void 85b032f27cSSam Leffler ieee80211_hostap_attach(struct ieee80211com *ic) 86b032f27cSSam Leffler { 87b032f27cSSam Leffler ic->ic_vattach[IEEE80211_M_HOSTAP] = hostap_vattach; 88b032f27cSSam Leffler } 89b032f27cSSam Leffler 90b032f27cSSam Leffler void 91b032f27cSSam Leffler ieee80211_hostap_detach(struct ieee80211com *ic) 92b032f27cSSam Leffler { 93b032f27cSSam Leffler } 94b032f27cSSam Leffler 95b032f27cSSam Leffler static void 96b032f27cSSam Leffler hostap_vdetach(struct ieee80211vap *vap) 97b032f27cSSam Leffler { 98b032f27cSSam Leffler } 99b032f27cSSam Leffler 100b032f27cSSam Leffler static void 101b032f27cSSam Leffler hostap_vattach(struct ieee80211vap *vap) 102b032f27cSSam Leffler { 103b032f27cSSam Leffler vap->iv_newstate = hostap_newstate; 104b032f27cSSam Leffler vap->iv_input = hostap_input; 105b032f27cSSam Leffler vap->iv_recv_mgmt = hostap_recv_mgmt; 10649eae5f7SSam Leffler vap->iv_recv_ctl = hostap_recv_ctl; 107b032f27cSSam Leffler vap->iv_opdetach = hostap_vdetach; 108b032f27cSSam Leffler vap->iv_deliver_data = hostap_deliver_data; 109e7f0d7cfSAdrian Chadd vap->iv_recv_pspoll = ieee80211_recv_pspoll; 110b032f27cSSam Leffler } 111b032f27cSSam Leffler 112b032f27cSSam Leffler static void 113b032f27cSSam Leffler sta_disassoc(void *arg, struct ieee80211_node *ni) 114b032f27cSSam Leffler { 115b032f27cSSam Leffler 1167db788c6SAndriy Voskoboinyk if (ni->ni_associd != 0) { 117b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DISASSOC, 118b032f27cSSam Leffler IEEE80211_REASON_ASSOC_LEAVE); 119b032f27cSSam Leffler ieee80211_node_leave(ni); 120b032f27cSSam Leffler } 121b032f27cSSam Leffler } 122b032f27cSSam Leffler 1234e150988SSam Leffler static void 1244e150988SSam Leffler sta_csa(void *arg, struct ieee80211_node *ni) 1254e150988SSam Leffler { 1267db788c6SAndriy Voskoboinyk struct ieee80211vap *vap = ni->ni_vap; 1274e150988SSam Leffler 1287db788c6SAndriy Voskoboinyk if (ni->ni_associd != 0) 1294e150988SSam Leffler if (ni->ni_inact > vap->iv_inact_init) { 1304e150988SSam Leffler ni->ni_inact = vap->iv_inact_init; 1314e150988SSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni, 1324e150988SSam Leffler "%s: inact %u", __func__, ni->ni_inact); 1334e150988SSam Leffler } 1344e150988SSam Leffler } 1354e150988SSam Leffler 1367131987dSSam Leffler static void 1377131987dSSam Leffler sta_drop(void *arg, struct ieee80211_node *ni) 1387131987dSSam Leffler { 1397131987dSSam Leffler 1407db788c6SAndriy Voskoboinyk if (ni->ni_associd != 0) 1417131987dSSam Leffler ieee80211_node_leave(ni); 1427131987dSSam Leffler } 1437131987dSSam Leffler 1447131987dSSam Leffler /* 1457131987dSSam Leffler * Does a channel change require associated stations to re-associate 1467131987dSSam Leffler * so protocol state is correct. This is used when doing CSA across 1477131987dSSam Leffler * bands or similar (e.g. HT -> legacy). 1487131987dSSam Leffler */ 1497131987dSSam Leffler static int 1507131987dSSam Leffler isbandchange(struct ieee80211com *ic) 1517131987dSSam Leffler { 1527131987dSSam Leffler return ((ic->ic_bsschan->ic_flags ^ ic->ic_csa_newchan->ic_flags) & 1537131987dSSam Leffler (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_HALF | 1547131987dSSam Leffler IEEE80211_CHAN_QUARTER | IEEE80211_CHAN_HT)) != 0; 1557131987dSSam Leffler } 1567131987dSSam Leffler 157b032f27cSSam Leffler /* 158b032f27cSSam Leffler * IEEE80211_M_HOSTAP vap state machine handler. 159b032f27cSSam Leffler */ 160b032f27cSSam Leffler static int 161b032f27cSSam Leffler hostap_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 162b032f27cSSam Leffler { 163b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic; 164b032f27cSSam Leffler enum ieee80211_state ostate; 165b032f27cSSam Leffler 166b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(ic); 167b032f27cSSam Leffler 168b032f27cSSam Leffler ostate = vap->iv_state; 169b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n", 170b032f27cSSam Leffler __func__, ieee80211_state_name[ostate], 171b032f27cSSam Leffler ieee80211_state_name[nstate], arg); 172b032f27cSSam Leffler vap->iv_state = nstate; /* state transition */ 173b032f27cSSam Leffler if (ostate != IEEE80211_S_SCAN) 174b032f27cSSam Leffler ieee80211_cancel_scan(vap); /* background scan */ 175b032f27cSSam Leffler switch (nstate) { 176b032f27cSSam Leffler case IEEE80211_S_INIT: 177b032f27cSSam Leffler switch (ostate) { 178b032f27cSSam Leffler case IEEE80211_S_SCAN: 179b032f27cSSam Leffler ieee80211_cancel_scan(vap); 180b032f27cSSam Leffler break; 181b032f27cSSam Leffler case IEEE80211_S_CAC: 182b032f27cSSam Leffler ieee80211_dfs_cac_stop(vap); 183b032f27cSSam Leffler break; 184b032f27cSSam Leffler case IEEE80211_S_RUN: 1857db788c6SAndriy Voskoboinyk ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, 1867db788c6SAndriy Voskoboinyk sta_disassoc, NULL); 187b032f27cSSam Leffler break; 188b032f27cSSam Leffler default: 189b032f27cSSam Leffler break; 190b032f27cSSam Leffler } 191b032f27cSSam Leffler if (ostate != IEEE80211_S_INIT) { 192b032f27cSSam Leffler /* NB: optimize INIT -> INIT case */ 193b032f27cSSam Leffler ieee80211_reset_bss(vap); 194b032f27cSSam Leffler } 195b032f27cSSam Leffler if (vap->iv_auth->ia_detach != NULL) 196b032f27cSSam Leffler vap->iv_auth->ia_detach(vap); 197b032f27cSSam Leffler break; 198b032f27cSSam Leffler case IEEE80211_S_SCAN: 199b032f27cSSam Leffler switch (ostate) { 200b032f27cSSam Leffler case IEEE80211_S_CSA: 201b032f27cSSam Leffler case IEEE80211_S_RUN: 2027db788c6SAndriy Voskoboinyk ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, 2037db788c6SAndriy Voskoboinyk sta_disassoc, NULL); 204b032f27cSSam Leffler /* 205b032f27cSSam Leffler * Clear overlapping BSS state; the beacon frame 206b032f27cSSam Leffler * will be reconstructed on transition to the RUN 207b032f27cSSam Leffler * state and the timeout routines check if the flag 208b032f27cSSam Leffler * is set before doing anything so this is sufficient. 209b032f27cSSam Leffler */ 210f1481c8dSAdrian Chadd vap->iv_flags_ext &= ~IEEE80211_FEXT_NONERP_PR; 211f1481c8dSAdrian Chadd vap->iv_flags_ht &= ~IEEE80211_FHT_NONHT_PR; 212f1481c8dSAdrian Chadd /* XXX TODO: schedule deferred update? */ 213b032f27cSSam Leffler /* fall thru... */ 214b032f27cSSam Leffler case IEEE80211_S_CAC: 215b032f27cSSam Leffler /* 216b032f27cSSam Leffler * NB: We may get here because of a manual channel 217b032f27cSSam Leffler * change in which case we need to stop CAC 218b032f27cSSam Leffler * XXX no need to stop if ostate RUN but it's ok 219b032f27cSSam Leffler */ 220b032f27cSSam Leffler ieee80211_dfs_cac_stop(vap); 221b032f27cSSam Leffler /* fall thru... */ 222b032f27cSSam Leffler case IEEE80211_S_INIT: 223b032f27cSSam Leffler if (vap->iv_des_chan != IEEE80211_CHAN_ANYC && 224b032f27cSSam Leffler !IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan)) { 225b032f27cSSam Leffler /* 226b032f27cSSam Leffler * Already have a channel; bypass the 227b032f27cSSam Leffler * scan and startup immediately. 228b032f27cSSam Leffler * ieee80211_create_ibss will call back to 229b032f27cSSam Leffler * move us to RUN state. 230b032f27cSSam Leffler */ 231b032f27cSSam Leffler ieee80211_create_ibss(vap, vap->iv_des_chan); 232b032f27cSSam Leffler break; 233b032f27cSSam Leffler } 234b032f27cSSam Leffler /* 235b032f27cSSam Leffler * Initiate a scan. We can come here as a result 236b032f27cSSam Leffler * of an IEEE80211_IOC_SCAN_REQ too in which case 237b032f27cSSam Leffler * the vap will be marked with IEEE80211_FEXT_SCANREQ 238b032f27cSSam Leffler * and the scan request parameters will be present 239b032f27cSSam Leffler * in iv_scanreq. Otherwise we do the default. 240b032f27cSSam Leffler */ 241b032f27cSSam Leffler if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) { 242b032f27cSSam Leffler ieee80211_check_scan(vap, 243b032f27cSSam Leffler vap->iv_scanreq_flags, 244b032f27cSSam Leffler vap->iv_scanreq_duration, 245b032f27cSSam Leffler vap->iv_scanreq_mindwell, 246b032f27cSSam Leffler vap->iv_scanreq_maxdwell, 247b032f27cSSam Leffler vap->iv_scanreq_nssid, vap->iv_scanreq_ssid); 248b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ; 249b032f27cSSam Leffler } else 250b032f27cSSam Leffler ieee80211_check_scan_current(vap); 251b032f27cSSam Leffler break; 252b032f27cSSam Leffler case IEEE80211_S_SCAN: 253b032f27cSSam Leffler /* 254b032f27cSSam Leffler * A state change requires a reset; scan. 255b032f27cSSam Leffler */ 256b032f27cSSam Leffler ieee80211_check_scan_current(vap); 257b032f27cSSam Leffler break; 258b032f27cSSam Leffler default: 259b032f27cSSam Leffler break; 260b032f27cSSam Leffler } 261b032f27cSSam Leffler break; 262b032f27cSSam Leffler case IEEE80211_S_CAC: 263b032f27cSSam Leffler /* 264b032f27cSSam Leffler * Start CAC on a DFS channel. We come here when starting 265b032f27cSSam Leffler * a bss on a DFS channel (see ieee80211_create_ibss). 266b032f27cSSam Leffler */ 267b032f27cSSam Leffler ieee80211_dfs_cac_start(vap); 268b032f27cSSam Leffler break; 269b032f27cSSam Leffler case IEEE80211_S_RUN: 270b032f27cSSam Leffler if (vap->iv_flags & IEEE80211_F_WPA) { 271b032f27cSSam Leffler /* XXX validate prerequisites */ 272b032f27cSSam Leffler } 273b032f27cSSam Leffler switch (ostate) { 274b032f27cSSam Leffler case IEEE80211_S_INIT: 275b032f27cSSam Leffler /* 276b032f27cSSam Leffler * Already have a channel; bypass the 277b032f27cSSam Leffler * scan and startup immediately. 278b032f27cSSam Leffler * Note that ieee80211_create_ibss will call 279b032f27cSSam Leffler * back to do a RUN->RUN state change. 280b032f27cSSam Leffler */ 281b032f27cSSam Leffler ieee80211_create_ibss(vap, 282b032f27cSSam Leffler ieee80211_ht_adjust_channel(ic, 2832bfc8a91SSam Leffler ic->ic_curchan, vap->iv_flags_ht)); 284b032f27cSSam Leffler /* NB: iv_bss is changed on return */ 285b032f27cSSam Leffler break; 286b032f27cSSam Leffler case IEEE80211_S_CAC: 287b032f27cSSam Leffler /* 288b032f27cSSam Leffler * NB: This is the normal state change when CAC 289b032f27cSSam Leffler * expires and no radar was detected; no need to 290b032f27cSSam Leffler * clear the CAC timer as it's already expired. 291b032f27cSSam Leffler */ 292b032f27cSSam Leffler /* fall thru... */ 293b032f27cSSam Leffler case IEEE80211_S_CSA: 294b032f27cSSam Leffler /* 2954e150988SSam Leffler * Shorten inactivity timer of associated stations 2964e150988SSam Leffler * to weed out sta's that don't follow a CSA. 2974e150988SSam Leffler */ 2987db788c6SAndriy Voskoboinyk ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, 2997db788c6SAndriy Voskoboinyk sta_csa, NULL); 3004e150988SSam Leffler /* 301b032f27cSSam Leffler * Update bss node channel to reflect where 302b032f27cSSam Leffler * we landed after CSA. 303b032f27cSSam Leffler */ 304b032f27cSSam Leffler ieee80211_node_set_chan(vap->iv_bss, 305b032f27cSSam Leffler ieee80211_ht_adjust_channel(ic, ic->ic_curchan, 306b032f27cSSam Leffler ieee80211_htchanflags(vap->iv_bss->ni_chan))); 307b032f27cSSam Leffler /* XXX bypass debug msgs */ 308b032f27cSSam Leffler break; 309b032f27cSSam Leffler case IEEE80211_S_SCAN: 310b032f27cSSam Leffler case IEEE80211_S_RUN: 311b032f27cSSam Leffler #ifdef IEEE80211_DEBUG 312b032f27cSSam Leffler if (ieee80211_msg_debug(vap)) { 313b032f27cSSam Leffler struct ieee80211_node *ni = vap->iv_bss; 314b032f27cSSam Leffler ieee80211_note(vap, 315b032f27cSSam Leffler "synchronized with %s ssid ", 316b032f27cSSam Leffler ether_sprintf(ni->ni_bssid)); 317b032f27cSSam Leffler ieee80211_print_essid(ni->ni_essid, 318b032f27cSSam Leffler ni->ni_esslen); 319b032f27cSSam Leffler /* XXX MCS/HT */ 320b032f27cSSam Leffler printf(" channel %d start %uMb\n", 321b032f27cSSam Leffler ieee80211_chan2ieee(ic, ic->ic_curchan), 322b032f27cSSam Leffler IEEE80211_RATE2MBS(ni->ni_txrate)); 323b032f27cSSam Leffler } 324b032f27cSSam Leffler #endif 325b032f27cSSam Leffler break; 326b032f27cSSam Leffler default: 327b032f27cSSam Leffler break; 328b032f27cSSam Leffler } 329b032f27cSSam Leffler /* 330b032f27cSSam Leffler * Start/stop the authenticator. We delay until here 331b032f27cSSam Leffler * to allow configuration to happen out of order. 332b032f27cSSam Leffler */ 333b032f27cSSam Leffler if (vap->iv_auth->ia_attach != NULL) { 334b032f27cSSam Leffler /* XXX check failure */ 335b032f27cSSam Leffler vap->iv_auth->ia_attach(vap); 336b032f27cSSam Leffler } else if (vap->iv_auth->ia_detach != NULL) { 337b032f27cSSam Leffler vap->iv_auth->ia_detach(vap); 338b032f27cSSam Leffler } 339b032f27cSSam Leffler ieee80211_node_authorize(vap->iv_bss); 340b032f27cSSam Leffler break; 3417131987dSSam Leffler case IEEE80211_S_CSA: 3427131987dSSam Leffler if (ostate == IEEE80211_S_RUN && isbandchange(ic)) { 3437131987dSSam Leffler /* 3447131987dSSam Leffler * On a ``band change'' silently drop associated 3457131987dSSam Leffler * stations as they must re-associate before they 3467131987dSSam Leffler * can pass traffic (as otherwise protocol state 3477131987dSSam Leffler * such as capabilities and the negotiated rate 3487131987dSSam Leffler * set may/will be wrong). 3497131987dSSam Leffler */ 3507db788c6SAndriy Voskoboinyk ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, 3517db788c6SAndriy Voskoboinyk sta_drop, NULL); 3527131987dSSam Leffler } 3537131987dSSam Leffler break; 354b032f27cSSam Leffler default: 355b032f27cSSam Leffler break; 356b032f27cSSam Leffler } 357b032f27cSSam Leffler return 0; 358b032f27cSSam Leffler } 359b032f27cSSam Leffler 360b032f27cSSam Leffler static void 361b032f27cSSam Leffler hostap_deliver_data(struct ieee80211vap *vap, 362b032f27cSSam Leffler struct ieee80211_node *ni, struct mbuf *m) 363b032f27cSSam Leffler { 364b032f27cSSam Leffler struct ether_header *eh = mtod(m, struct ether_header *); 365b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 366b032f27cSSam Leffler 367e1cfcbcbSSam Leffler /* clear driver/net80211 flags before passing up */ 36886bd0491SAndre Oppermann m->m_flags &= ~(M_MCAST | M_BCAST); 36986bd0491SAndre Oppermann m_clrprotoflags(m); 370e1cfcbcbSSam Leffler 371b032f27cSSam Leffler KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP, 372b032f27cSSam Leffler ("gack, opmode %d", vap->iv_opmode)); 373b032f27cSSam Leffler /* 374b032f27cSSam Leffler * Do accounting. 375b032f27cSSam Leffler */ 376dea45121SGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); 377b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_data); 378b032f27cSSam Leffler IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len); 379b032f27cSSam Leffler if (ETHER_IS_MULTICAST(eh->ether_dhost)) { 380b032f27cSSam Leffler m->m_flags |= M_MCAST; /* XXX M_BCAST? */ 381b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_mcast); 382b032f27cSSam Leffler } else 383b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_ucast); 384b032f27cSSam Leffler 385b032f27cSSam Leffler /* perform as a bridge within the AP */ 386b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_NOBRIDGE) == 0) { 387b032f27cSSam Leffler struct mbuf *mcopy = NULL; 388b032f27cSSam Leffler 389b032f27cSSam Leffler if (m->m_flags & M_MCAST) { 390bd29f817SBjoern A. Zeeb mcopy = m_dup(m, IEEE80211_M_NOWAIT); 391b032f27cSSam Leffler if (mcopy == NULL) 392dea45121SGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); 393b032f27cSSam Leffler else 394b032f27cSSam Leffler mcopy->m_flags |= M_MCAST; 395b032f27cSSam Leffler } else { 396b032f27cSSam Leffler /* 397b032f27cSSam Leffler * Check if the destination is associated with the 398b032f27cSSam Leffler * same vap and authorized to receive traffic. 399b032f27cSSam Leffler * Beware of traffic destined for the vap itself; 400b032f27cSSam Leffler * sending it will not work; just let it be delivered 401b032f27cSSam Leffler * normally. 402b032f27cSSam Leffler */ 403b032f27cSSam Leffler struct ieee80211_node *sta = ieee80211_find_vap_node( 404b032f27cSSam Leffler &vap->iv_ic->ic_sta, vap, eh->ether_dhost); 405b032f27cSSam Leffler if (sta != NULL) { 406b032f27cSSam Leffler if (ieee80211_node_is_authorized(sta)) { 407b032f27cSSam Leffler /* 408b032f27cSSam Leffler * Beware of sending to ourself; this 409b032f27cSSam Leffler * needs to happen via the normal 410b032f27cSSam Leffler * input path. 411b032f27cSSam Leffler */ 412b032f27cSSam Leffler if (sta != vap->iv_bss) { 413b032f27cSSam Leffler mcopy = m; 414b032f27cSSam Leffler m = NULL; 415b032f27cSSam Leffler } 416b032f27cSSam Leffler } else { 417b032f27cSSam Leffler vap->iv_stats.is_rx_unauth++; 418b032f27cSSam Leffler IEEE80211_NODE_STAT(sta, rx_unauth); 419b032f27cSSam Leffler } 420b032f27cSSam Leffler ieee80211_free_node(sta); 421b032f27cSSam Leffler } 422b032f27cSSam Leffler } 4234d4d5e25SAndriy Voskoboinyk if (mcopy != NULL) 4244d4d5e25SAndriy Voskoboinyk (void) ieee80211_vap_xmitpkt(vap, mcopy); 425b032f27cSSam Leffler } 426b032f27cSSam Leffler if (m != NULL) { 427b032f27cSSam Leffler /* 428b032f27cSSam Leffler * Mark frame as coming from vap's interface. 429b032f27cSSam Leffler */ 430b032f27cSSam Leffler m->m_pkthdr.rcvif = ifp; 431b032f27cSSam Leffler if (m->m_flags & M_MCAST) { 432b032f27cSSam Leffler /* 433b032f27cSSam Leffler * Spam DWDS vap's w/ multicast traffic. 434b032f27cSSam Leffler */ 435b032f27cSSam Leffler /* XXX only if dwds in use? */ 436b032f27cSSam Leffler ieee80211_dwds_mcast(vap, m); 437b032f27cSSam Leffler } 438b032f27cSSam Leffler if (ni->ni_vlan != 0) { 439b032f27cSSam Leffler /* attach vlan tag */ 440b032f27cSSam Leffler m->m_pkthdr.ether_vtag = ni->ni_vlan; 441b032f27cSSam Leffler m->m_flags |= M_VLANTAG; 442b032f27cSSam Leffler } 443b032f27cSSam Leffler ifp->if_input(ifp, m); 444b032f27cSSam Leffler } 445b032f27cSSam Leffler } 446b032f27cSSam Leffler 447b032f27cSSam Leffler /* 448b032f27cSSam Leffler * Decide if a received management frame should be 449b032f27cSSam Leffler * printed when debugging is enabled. This filters some 450b032f27cSSam Leffler * of the less interesting frames that come frequently 451b032f27cSSam Leffler * (e.g. beacons). 452b032f27cSSam Leffler */ 453b032f27cSSam Leffler static __inline int 454b032f27cSSam Leffler doprint(struct ieee80211vap *vap, int subtype) 455b032f27cSSam Leffler { 456b032f27cSSam Leffler switch (subtype) { 457b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_BEACON: 458b032f27cSSam Leffler return (vap->iv_ic->ic_flags & IEEE80211_F_SCAN); 459b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 460b032f27cSSam Leffler return 0; 461b032f27cSSam Leffler } 462b032f27cSSam Leffler return 1; 463b032f27cSSam Leffler } 464b032f27cSSam Leffler 465b032f27cSSam Leffler /* 466b032f27cSSam Leffler * Process a received frame. The node associated with the sender 467b032f27cSSam Leffler * should be supplied. If nothing was found in the node table then 468b032f27cSSam Leffler * the caller is assumed to supply a reference to iv_bss instead. 469b032f27cSSam Leffler * The RSSI and a timestamp are also supplied. The RSSI data is used 470b032f27cSSam Leffler * during AP scanning to select a AP to associate with; it can have 471b032f27cSSam Leffler * any units so long as values have consistent units and higher values 472b032f27cSSam Leffler * mean ``better signal''. The receive timestamp is currently not used 473b032f27cSSam Leffler * by the 802.11 layer. 474b032f27cSSam Leffler */ 475b032f27cSSam Leffler static int 476c79f192cSAdrian Chadd hostap_input(struct ieee80211_node *ni, struct mbuf *m, 477c79f192cSAdrian Chadd const struct ieee80211_rx_stats *rxs, int rssi, int nf) 478b032f27cSSam Leffler { 479b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 480b032f27cSSam Leffler struct ieee80211com *ic = ni->ni_ic; 481b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 482b032f27cSSam Leffler struct ieee80211_frame *wh; 483b032f27cSSam Leffler struct ieee80211_key *key; 484b032f27cSSam Leffler struct ether_header *eh; 4852b80a340SRui Paulo int hdrspace, need_tap = 1; /* mbuf need to be tapped. */ 486b032f27cSSam Leffler uint8_t dir, type, subtype, qos; 487b032f27cSSam Leffler uint8_t *bssid; 488fe75b452SAdrian Chadd int is_hw_decrypted = 0; 489fe75b452SAdrian Chadd int has_decrypted = 0; 490fe75b452SAdrian Chadd 491fe75b452SAdrian Chadd /* 492fe75b452SAdrian Chadd * Some devices do hardware decryption all the way through 493fe75b452SAdrian Chadd * to pretending the frame wasn't encrypted in the first place. 494fe75b452SAdrian Chadd * So, tag it appropriately so it isn't discarded inappropriately. 495fe75b452SAdrian Chadd */ 496fe75b452SAdrian Chadd if ((rxs != NULL) && (rxs->c_pktflags & IEEE80211_RX_F_DECRYPTED)) 497fe75b452SAdrian Chadd is_hw_decrypted = 1; 498b032f27cSSam Leffler 49945f856e3SSam Leffler if (m->m_flags & M_AMPDU_MPDU) { 500b032f27cSSam Leffler /* 501b032f27cSSam Leffler * Fastpath for A-MPDU reorder q resubmission. Frames 50245f856e3SSam Leffler * w/ M_AMPDU_MPDU marked have already passed through 50345f856e3SSam Leffler * here but were received out of order and been held on 50445f856e3SSam Leffler * the reorder queue. When resubmitted they are marked 50545f856e3SSam Leffler * with the M_AMPDU_MPDU flag and we can bypass most of 50645f856e3SSam Leffler * the normal processing. 507b032f27cSSam Leffler */ 508b032f27cSSam Leffler wh = mtod(m, struct ieee80211_frame *); 509b032f27cSSam Leffler type = IEEE80211_FC0_TYPE_DATA; 510b032f27cSSam Leffler dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK; 511c9b7e9dfSBjoern A. Zeeb subtype = IEEE80211_FC0_SUBTYPE_QOS_DATA; 512b032f27cSSam Leffler hdrspace = ieee80211_hdrspace(ic, wh); /* XXX optimize? */ 513b032f27cSSam Leffler goto resubmit_ampdu; 514b032f27cSSam Leffler } 515b032f27cSSam Leffler 516b032f27cSSam Leffler KASSERT(ni != NULL, ("null node")); 517b032f27cSSam Leffler ni->ni_inact = ni->ni_inact_reload; 518b032f27cSSam Leffler 519b032f27cSSam Leffler type = -1; /* undefined */ 520b032f27cSSam Leffler 521b032f27cSSam Leffler if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) { 522b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 523b032f27cSSam Leffler ni->ni_macaddr, NULL, 524b032f27cSSam Leffler "too short (1): len %u", m->m_pkthdr.len); 525b032f27cSSam Leffler vap->iv_stats.is_rx_tooshort++; 526b032f27cSSam Leffler goto out; 527b032f27cSSam Leffler } 528b032f27cSSam Leffler /* 529b032f27cSSam Leffler * Bit of a cheat here, we use a pointer for a 3-address 530b032f27cSSam Leffler * frame format but don't reference fields past outside 531b032f27cSSam Leffler * ieee80211_frame_min w/o first validating the data is 532b032f27cSSam Leffler * present. 533b032f27cSSam Leffler */ 534b032f27cSSam Leffler wh = mtod(m, struct ieee80211_frame *); 535b032f27cSSam Leffler 536b032f27cSSam Leffler if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) != 537b032f27cSSam Leffler IEEE80211_FC0_VERSION_0) { 538b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 539dc7bf546SSam Leffler ni->ni_macaddr, NULL, "wrong version, fc %02x:%02x", 540dc7bf546SSam Leffler wh->i_fc[0], wh->i_fc[1]); 541b032f27cSSam Leffler vap->iv_stats.is_rx_badversion++; 542b032f27cSSam Leffler goto err; 543b032f27cSSam Leffler } 544b032f27cSSam Leffler 545b032f27cSSam Leffler dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK; 546b032f27cSSam Leffler type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK; 547b032f27cSSam Leffler subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK; 548b032f27cSSam Leffler if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) { 549b032f27cSSam Leffler if (dir != IEEE80211_FC1_DIR_NODS) 550b032f27cSSam Leffler bssid = wh->i_addr1; 551b032f27cSSam Leffler else if (type == IEEE80211_FC0_TYPE_CTL) 552b032f27cSSam Leffler bssid = wh->i_addr1; 553b032f27cSSam Leffler else { 554b032f27cSSam Leffler if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) { 555b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, 556b032f27cSSam Leffler IEEE80211_MSG_ANY, ni->ni_macaddr, 557b032f27cSSam Leffler NULL, "too short (2): len %u", 558b032f27cSSam Leffler m->m_pkthdr.len); 559b032f27cSSam Leffler vap->iv_stats.is_rx_tooshort++; 560b032f27cSSam Leffler goto out; 561b032f27cSSam Leffler } 562b032f27cSSam Leffler bssid = wh->i_addr3; 563b032f27cSSam Leffler } 564b032f27cSSam Leffler /* 565b032f27cSSam Leffler * Validate the bssid. 566b032f27cSSam Leffler */ 567b032f27cSSam Leffler if (!(type == IEEE80211_FC0_TYPE_MGT && 568b032f27cSSam Leffler subtype == IEEE80211_FC0_SUBTYPE_BEACON) && 569b032f27cSSam Leffler !IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) && 570b032f27cSSam Leffler !IEEE80211_ADDR_EQ(bssid, ifp->if_broadcastaddr)) { 571b032f27cSSam Leffler /* not interested in */ 572b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 573b032f27cSSam Leffler bssid, NULL, "%s", "not to bss"); 574b032f27cSSam Leffler vap->iv_stats.is_rx_wrongbss++; 575b032f27cSSam Leffler goto out; 576b032f27cSSam Leffler } 577b032f27cSSam Leffler 578b032f27cSSam Leffler IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi); 5795463c4a4SSam Leffler ni->ni_noise = nf; 580c3ebe019SAdrian Chadd if (IEEE80211_HAS_SEQ(type, subtype)) { 581b032f27cSSam Leffler uint8_t tid = ieee80211_gettid(wh); 582b032f27cSSam Leffler if (IEEE80211_QOS_HAS_SEQ(wh) && 583b032f27cSSam Leffler TID_TO_WME_AC(tid) >= WME_AC_VI) 584b032f27cSSam Leffler ic->ic_wme.wme_hipri_traffic++; 58585c4e670SAdrian Chadd if (! ieee80211_check_rxseq(ni, wh, bssid, rxs)) 586b032f27cSSam Leffler goto out; 587b032f27cSSam Leffler } 588b032f27cSSam Leffler } 589b032f27cSSam Leffler 590b032f27cSSam Leffler switch (type) { 591b032f27cSSam Leffler case IEEE80211_FC0_TYPE_DATA: 592b032f27cSSam Leffler hdrspace = ieee80211_hdrspace(ic, wh); 593b032f27cSSam Leffler if (m->m_len < hdrspace && 594b032f27cSSam Leffler (m = m_pullup(m, hdrspace)) == NULL) { 595b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 596b032f27cSSam Leffler ni->ni_macaddr, NULL, 597b032f27cSSam Leffler "data too short: expecting %u", hdrspace); 598b032f27cSSam Leffler vap->iv_stats.is_rx_tooshort++; 599b032f27cSSam Leffler goto out; /* XXX */ 600b032f27cSSam Leffler } 601b032f27cSSam Leffler if (!(dir == IEEE80211_FC1_DIR_TODS || 602b032f27cSSam Leffler (dir == IEEE80211_FC1_DIR_DSTODS && 603b032f27cSSam Leffler (vap->iv_flags & IEEE80211_F_DWDS)))) { 604b032f27cSSam Leffler if (dir != IEEE80211_FC1_DIR_DSTODS) { 605b032f27cSSam Leffler IEEE80211_DISCARD(vap, 606b032f27cSSam Leffler IEEE80211_MSG_INPUT, wh, "data", 607b032f27cSSam Leffler "incorrect dir 0x%x", dir); 608b032f27cSSam Leffler } else { 609b032f27cSSam Leffler IEEE80211_DISCARD(vap, 610b032f27cSSam Leffler IEEE80211_MSG_INPUT | 611b032f27cSSam Leffler IEEE80211_MSG_WDS, wh, 612b032f27cSSam Leffler "4-address data", 613b032f27cSSam Leffler "%s", "DWDS not enabled"); 614b032f27cSSam Leffler } 615b032f27cSSam Leffler vap->iv_stats.is_rx_wrongdir++; 616b032f27cSSam Leffler goto out; 617b032f27cSSam Leffler } 618b032f27cSSam Leffler /* check if source STA is associated */ 619b032f27cSSam Leffler if (ni == vap->iv_bss) { 620b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 621b032f27cSSam Leffler wh, "data", "%s", "unknown src"); 622b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, 623b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_DEAUTH, 624b032f27cSSam Leffler IEEE80211_REASON_NOT_AUTHED); 625b032f27cSSam Leffler vap->iv_stats.is_rx_notassoc++; 626b032f27cSSam Leffler goto err; 627b032f27cSSam Leffler } 628b032f27cSSam Leffler if (ni->ni_associd == 0) { 629b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 630b032f27cSSam Leffler wh, "data", "%s", "unassoc src"); 631b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, 632b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_DISASSOC, 633b032f27cSSam Leffler IEEE80211_REASON_NOT_ASSOCED); 634b032f27cSSam Leffler vap->iv_stats.is_rx_notassoc++; 635b032f27cSSam Leffler goto err; 636b032f27cSSam Leffler } 637b032f27cSSam Leffler 638b032f27cSSam Leffler /* 639b032f27cSSam Leffler * Check for power save state change. 640b032f27cSSam Leffler * XXX out-of-order A-MPDU frames? 641b032f27cSSam Leffler */ 642b032f27cSSam Leffler if (((wh->i_fc[1] & IEEE80211_FC1_PWR_MGT) ^ 643b032f27cSSam Leffler (ni->ni_flags & IEEE80211_NODE_PWR_MGT))) 644e7f0d7cfSAdrian Chadd vap->iv_node_ps(ni, 645b032f27cSSam Leffler wh->i_fc[1] & IEEE80211_FC1_PWR_MGT); 646b032f27cSSam Leffler /* 647b032f27cSSam Leffler * For 4-address packets handle WDS discovery 648b032f27cSSam Leffler * notifications. Once a WDS link is setup frames 649b032f27cSSam Leffler * are just delivered to the WDS vap (see below). 650b032f27cSSam Leffler */ 651b032f27cSSam Leffler if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap == NULL) { 652b032f27cSSam Leffler if (!ieee80211_node_is_authorized(ni)) { 653b032f27cSSam Leffler IEEE80211_DISCARD(vap, 654b032f27cSSam Leffler IEEE80211_MSG_INPUT | 655b032f27cSSam Leffler IEEE80211_MSG_WDS, wh, 656b032f27cSSam Leffler "4-address data", 657b032f27cSSam Leffler "%s", "unauthorized port"); 658b032f27cSSam Leffler vap->iv_stats.is_rx_unauth++; 659b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_unauth); 660b032f27cSSam Leffler goto err; 661b032f27cSSam Leffler } 662b032f27cSSam Leffler ieee80211_dwds_discover(ni, m); 663b032f27cSSam Leffler return type; 664b032f27cSSam Leffler } 665b032f27cSSam Leffler 666b032f27cSSam Leffler /* 66745f856e3SSam Leffler * Handle A-MPDU re-ordering. If the frame is to be 66845f856e3SSam Leffler * processed directly then ieee80211_ampdu_reorder 669b032f27cSSam Leffler * will return 0; otherwise it has consumed the mbuf 670b032f27cSSam Leffler * and we should do nothing more with it. 671b032f27cSSam Leffler */ 67245f856e3SSam Leffler if ((m->m_flags & M_AMPDU) && 67385c4e670SAdrian Chadd ieee80211_ampdu_reorder(ni, m, rxs) != 0) { 674b032f27cSSam Leffler m = NULL; 675b032f27cSSam Leffler goto out; 676b032f27cSSam Leffler } 677b032f27cSSam Leffler resubmit_ampdu: 678b032f27cSSam Leffler 679b032f27cSSam Leffler /* 680b032f27cSSam Leffler * Handle privacy requirements. Note that we 681b032f27cSSam Leffler * must not be preempted from here until after 682b032f27cSSam Leffler * we (potentially) call ieee80211_crypto_demic; 683b032f27cSSam Leffler * otherwise we may violate assumptions in the 684b032f27cSSam Leffler * crypto cipher modules used to do delayed update 685b032f27cSSam Leffler * of replay sequence numbers. 686b032f27cSSam Leffler */ 6872889cbe2SAdrian Chadd if (is_hw_decrypted || IEEE80211_IS_PROTECTED(wh)) { 688b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) { 689b032f27cSSam Leffler /* 690b032f27cSSam Leffler * Discard encrypted frames when privacy is off. 691b032f27cSSam Leffler */ 692b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 693b032f27cSSam Leffler wh, "WEP", "%s", "PRIVACY off"); 694b032f27cSSam Leffler vap->iv_stats.is_rx_noprivacy++; 695b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_noprivacy); 696b032f27cSSam Leffler goto out; 697b032f27cSSam Leffler } 698fe75b452SAdrian Chadd if (ieee80211_crypto_decap(ni, m, hdrspace, &key) == 0) { 699b032f27cSSam Leffler /* NB: stats+msgs handled in crypto_decap */ 700b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_wepfail); 701b032f27cSSam Leffler goto out; 702b032f27cSSam Leffler } 703b032f27cSSam Leffler wh = mtod(m, struct ieee80211_frame *); 7045945b5f5SKevin Lo wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; 705fe75b452SAdrian Chadd has_decrypted = 1; 706b032f27cSSam Leffler } else { 707b032f27cSSam Leffler /* XXX M_WEP and IEEE80211_F_PRIVACY */ 708b032f27cSSam Leffler key = NULL; 709b032f27cSSam Leffler } 710b032f27cSSam Leffler 711b032f27cSSam Leffler /* 712b032f27cSSam Leffler * Save QoS bits for use below--before we strip the header. 713b032f27cSSam Leffler */ 714c9b7e9dfSBjoern A. Zeeb if (subtype == IEEE80211_FC0_SUBTYPE_QOS_DATA) 715f3f08e16SAndriy Voskoboinyk qos = ieee80211_getqos(wh)[0]; 716f3f08e16SAndriy Voskoboinyk else 717b032f27cSSam Leffler qos = 0; 718b032f27cSSam Leffler 719b032f27cSSam Leffler /* 720b032f27cSSam Leffler * Next up, any fragmentation. 721b032f27cSSam Leffler */ 722b032f27cSSam Leffler if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { 72311572d7dSMathy Vanhoef m = ieee80211_defrag(ni, m, hdrspace, has_decrypted); 724b032f27cSSam Leffler if (m == NULL) { 725b032f27cSSam Leffler /* Fragment dropped or frame not complete yet */ 726b032f27cSSam Leffler goto out; 727b032f27cSSam Leffler } 728b032f27cSSam Leffler } 729b032f27cSSam Leffler wh = NULL; /* no longer valid, catch any uses */ 730b032f27cSSam Leffler 731b032f27cSSam Leffler /* 732b032f27cSSam Leffler * Next strip any MSDU crypto bits. 733b032f27cSSam Leffler */ 734b032f27cSSam Leffler if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) { 735b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 736b032f27cSSam Leffler ni->ni_macaddr, "data", "%s", "demic error"); 737b032f27cSSam Leffler vap->iv_stats.is_rx_demicfail++; 738b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_demicfail); 739b032f27cSSam Leffler goto out; 740b032f27cSSam Leffler } 741b032f27cSSam Leffler /* copy to listener after decrypt */ 7425463c4a4SSam Leffler if (ieee80211_radiotap_active_vap(vap)) 7435463c4a4SSam Leffler ieee80211_radiotap_rx(vap, m); 744b032f27cSSam Leffler need_tap = 0; 745b032f27cSSam Leffler /* 746b032f27cSSam Leffler * Finally, strip the 802.11 header. 747b032f27cSSam Leffler */ 748f024bdf1SMathy Vanhoef m = ieee80211_decap(vap, m, hdrspace, qos); 749b032f27cSSam Leffler if (m == NULL) { 750b032f27cSSam Leffler /* XXX mask bit to check for both */ 751b032f27cSSam Leffler /* don't count Null data frames as errors */ 752b032f27cSSam Leffler if (subtype == IEEE80211_FC0_SUBTYPE_NODATA || 753b032f27cSSam Leffler subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) 754b032f27cSSam Leffler goto out; 755b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 756b032f27cSSam Leffler ni->ni_macaddr, "data", "%s", "decap error"); 757b032f27cSSam Leffler vap->iv_stats.is_rx_decap++; 758b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_decap); 759b032f27cSSam Leffler goto err; 760b032f27cSSam Leffler } 761ffc19cf5SMathy Vanhoef if (!(qos & IEEE80211_QOS_AMSDU)) 762b032f27cSSam Leffler eh = mtod(m, struct ether_header *); 763ffc19cf5SMathy Vanhoef else 764ffc19cf5SMathy Vanhoef eh = NULL; 765b032f27cSSam Leffler if (!ieee80211_node_is_authorized(ni)) { 766b032f27cSSam Leffler /* 767b032f27cSSam Leffler * Deny any non-PAE frames received prior to 768b032f27cSSam Leffler * authorization. For open/shared-key 769b032f27cSSam Leffler * authentication the port is mark authorized 770b032f27cSSam Leffler * after authentication completes. For 802.1x 771b032f27cSSam Leffler * the port is not marked authorized by the 772b032f27cSSam Leffler * authenticator until the handshake has completed. 773b032f27cSSam Leffler */ 774ffc19cf5SMathy Vanhoef if (eh == NULL || 775ffc19cf5SMathy Vanhoef eh->ether_type != htons(ETHERTYPE_PAE)) { 776b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 777ffc19cf5SMathy Vanhoef ni->ni_macaddr, "data", "unauthorized or " 778ffc19cf5SMathy Vanhoef "unknown port: ether type 0x%x len %u", 779ffc19cf5SMathy Vanhoef eh == NULL ? -1 : eh->ether_type, 780ffc19cf5SMathy Vanhoef m->m_pkthdr.len); 781b032f27cSSam Leffler vap->iv_stats.is_rx_unauth++; 782b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_unauth); 783b032f27cSSam Leffler goto err; 784b032f27cSSam Leffler } 785b032f27cSSam Leffler } else { 786b032f27cSSam Leffler /* 787b032f27cSSam Leffler * When denying unencrypted frames, discard 788b032f27cSSam Leffler * any non-PAE frames received without encryption. 789b032f27cSSam Leffler */ 790b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_DROPUNENC) && 791fe75b452SAdrian Chadd ((has_decrypted == 0) && (m->m_flags & M_WEP) == 0) && 792fe75b452SAdrian Chadd (is_hw_decrypted == 0) && 793ffc19cf5SMathy Vanhoef (eh == NULL || 794ffc19cf5SMathy Vanhoef eh->ether_type != htons(ETHERTYPE_PAE))) { 795b032f27cSSam Leffler /* 796b032f27cSSam Leffler * Drop unencrypted frames. 797b032f27cSSam Leffler */ 798b032f27cSSam Leffler vap->iv_stats.is_rx_unencrypted++; 799b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_unencrypted); 800b032f27cSSam Leffler goto out; 801b032f27cSSam Leffler } 802b032f27cSSam Leffler } 803b032f27cSSam Leffler /* XXX require HT? */ 804b032f27cSSam Leffler if (qos & IEEE80211_QOS_AMSDU) { 805b032f27cSSam Leffler m = ieee80211_decap_amsdu(ni, m); 806b032f27cSSam Leffler if (m == NULL) 807b032f27cSSam Leffler return IEEE80211_FC0_TYPE_DATA; 808616190d0SSam Leffler } else { 809616190d0SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG 810616190d0SSam Leffler m = ieee80211_decap_fastframe(vap, ni, m); 811b032f27cSSam Leffler if (m == NULL) 812b032f27cSSam Leffler return IEEE80211_FC0_TYPE_DATA; 813616190d0SSam Leffler #endif 814b032f27cSSam Leffler } 815b032f27cSSam Leffler if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap != NULL) 816b032f27cSSam Leffler ieee80211_deliver_data(ni->ni_wdsvap, ni, m); 817b032f27cSSam Leffler else 818b032f27cSSam Leffler hostap_deliver_data(vap, ni, m); 819b032f27cSSam Leffler return IEEE80211_FC0_TYPE_DATA; 820b032f27cSSam Leffler 821b032f27cSSam Leffler case IEEE80211_FC0_TYPE_MGT: 822b032f27cSSam Leffler vap->iv_stats.is_rx_mgmt++; 823b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_mgmt); 824b032f27cSSam Leffler if (dir != IEEE80211_FC1_DIR_NODS) { 825b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 826b032f27cSSam Leffler wh, "mgt", "incorrect dir 0x%x", dir); 827b032f27cSSam Leffler vap->iv_stats.is_rx_wrongdir++; 828b032f27cSSam Leffler goto err; 829b032f27cSSam Leffler } 830b032f27cSSam Leffler if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) { 831b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 832b032f27cSSam Leffler ni->ni_macaddr, "mgt", "too short: len %u", 833b032f27cSSam Leffler m->m_pkthdr.len); 834b032f27cSSam Leffler vap->iv_stats.is_rx_tooshort++; 835b032f27cSSam Leffler goto out; 836b032f27cSSam Leffler } 837b032f27cSSam Leffler if (IEEE80211_IS_MULTICAST(wh->i_addr2)) { 838b032f27cSSam Leffler /* ensure return frames are unicast */ 839b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 840b032f27cSSam Leffler wh, NULL, "source is multicast: %s", 841b032f27cSSam Leffler ether_sprintf(wh->i_addr2)); 842b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */ 843b032f27cSSam Leffler goto out; 844b032f27cSSam Leffler } 845b032f27cSSam Leffler #ifdef IEEE80211_DEBUG 846b032f27cSSam Leffler if ((ieee80211_msg_debug(vap) && doprint(vap, subtype)) || 847b032f27cSSam Leffler ieee80211_msg_dumppkts(vap)) { 848b032f27cSSam Leffler if_printf(ifp, "received %s from %s rssi %d\n", 8494357a5d1SAndriy Voskoboinyk ieee80211_mgt_subtype_name(subtype), 850b032f27cSSam Leffler ether_sprintf(wh->i_addr2), rssi); 851b032f27cSSam Leffler } 852b032f27cSSam Leffler #endif 8532889cbe2SAdrian Chadd if (IEEE80211_IS_PROTECTED(wh)) { 854b032f27cSSam Leffler if (subtype != IEEE80211_FC0_SUBTYPE_AUTH) { 855b032f27cSSam Leffler /* 856b032f27cSSam Leffler * Only shared key auth frames with a challenge 857b032f27cSSam Leffler * should be encrypted, discard all others. 858b032f27cSSam Leffler */ 859b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 860b032f27cSSam Leffler wh, NULL, 861b032f27cSSam Leffler "%s", "WEP set but not permitted"); 862b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; /* XXX */ 863b032f27cSSam Leffler goto out; 864b032f27cSSam Leffler } 865b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) { 866b032f27cSSam Leffler /* 867b032f27cSSam Leffler * Discard encrypted frames when privacy is off. 868b032f27cSSam Leffler */ 869b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 870b032f27cSSam Leffler wh, NULL, "%s", "WEP set but PRIVACY off"); 871b032f27cSSam Leffler vap->iv_stats.is_rx_noprivacy++; 872b032f27cSSam Leffler goto out; 873b032f27cSSam Leffler } 874b032f27cSSam Leffler hdrspace = ieee80211_hdrspace(ic, wh); 875fe75b452SAdrian Chadd if (ieee80211_crypto_decap(ni, m, hdrspace, &key) == 0) { 876b032f27cSSam Leffler /* NB: stats+msgs handled in crypto_decap */ 877b032f27cSSam Leffler goto out; 878b032f27cSSam Leffler } 879b032f27cSSam Leffler wh = mtod(m, struct ieee80211_frame *); 8805945b5f5SKevin Lo wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; 881fe75b452SAdrian Chadd has_decrypted = 1; 882b032f27cSSam Leffler } 8834e87d54aSRui Paulo /* 8844e87d54aSRui Paulo * Pass the packet to radiotap before calling iv_recv_mgmt(). 8854e87d54aSRui Paulo * Otherwise iv_recv_mgmt() might pass another packet to 8864e87d54aSRui Paulo * radiotap, resulting in out of order packet captures. 8874e87d54aSRui Paulo */ 888323f12abSRui Paulo if (ieee80211_radiotap_active_vap(vap)) 889323f12abSRui Paulo ieee80211_radiotap_rx(vap, m); 890323f12abSRui Paulo need_tap = 0; 891c79f192cSAdrian Chadd vap->iv_recv_mgmt(ni, m, subtype, rxs, rssi, nf); 8928bbd3e41SSam Leffler goto out; 893b032f27cSSam Leffler 894b032f27cSSam Leffler case IEEE80211_FC0_TYPE_CTL: 895b032f27cSSam Leffler vap->iv_stats.is_rx_ctl++; 896b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_ctrl); 89749eae5f7SSam Leffler vap->iv_recv_ctl(ni, m, subtype); 898b032f27cSSam Leffler goto out; 899b032f27cSSam Leffler default: 900b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 901b032f27cSSam Leffler wh, "bad", "frame type 0x%x", type); 902b032f27cSSam Leffler /* should not come here */ 903b032f27cSSam Leffler break; 904b032f27cSSam Leffler } 905b032f27cSSam Leffler err: 906dea45121SGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); 907b032f27cSSam Leffler out: 908b032f27cSSam Leffler if (m != NULL) { 909a6c3cf3eSSam Leffler if (need_tap && ieee80211_radiotap_active_vap(vap)) 9105463c4a4SSam Leffler ieee80211_radiotap_rx(vap, m); 911b032f27cSSam Leffler m_freem(m); 912b032f27cSSam Leffler } 913b032f27cSSam Leffler return type; 914b032f27cSSam Leffler } 915b032f27cSSam Leffler 916b032f27cSSam Leffler static void 917b032f27cSSam Leffler hostap_auth_open(struct ieee80211_node *ni, struct ieee80211_frame *wh, 9185463c4a4SSam Leffler int rssi, int nf, uint16_t seq, uint16_t status) 919b032f27cSSam Leffler { 920b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 921b032f27cSSam Leffler 922b032f27cSSam Leffler KASSERT(vap->iv_state == IEEE80211_S_RUN, ("state %d", vap->iv_state)); 923b032f27cSSam Leffler 924b032f27cSSam Leffler if (ni->ni_authmode == IEEE80211_AUTH_SHARED) { 925b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 926b032f27cSSam Leffler ni->ni_macaddr, "open auth", 927b032f27cSSam Leffler "bad sta auth mode %u", ni->ni_authmode); 928b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; /* XXX */ 929b032f27cSSam Leffler /* 930b032f27cSSam Leffler * Clear any challenge text that may be there if 931b032f27cSSam Leffler * a previous shared key auth failed and then an 932b032f27cSSam Leffler * open auth is attempted. 933b032f27cSSam Leffler */ 934b032f27cSSam Leffler if (ni->ni_challenge != NULL) { 935b9b53389SAdrian Chadd IEEE80211_FREE(ni->ni_challenge, M_80211_NODE); 936b032f27cSSam Leffler ni->ni_challenge = NULL; 937b032f27cSSam Leffler } 938b032f27cSSam Leffler /* XXX hack to workaround calling convention */ 939b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, 940b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_AUTH, 941b032f27cSSam Leffler (seq + 1) | (IEEE80211_STATUS_ALG<<16)); 942b032f27cSSam Leffler return; 943b032f27cSSam Leffler } 944b032f27cSSam Leffler if (seq != IEEE80211_AUTH_OPEN_REQUEST) { 945b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; 946b032f27cSSam Leffler return; 947b032f27cSSam Leffler } 948b032f27cSSam Leffler /* always accept open authentication requests */ 949b032f27cSSam Leffler if (ni == vap->iv_bss) { 950b032f27cSSam Leffler ni = ieee80211_dup_bss(vap, wh->i_addr2); 951b032f27cSSam Leffler if (ni == NULL) 952b032f27cSSam Leffler return; 953b032f27cSSam Leffler } else if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0) 954b032f27cSSam Leffler (void) ieee80211_ref_node(ni); 955b032f27cSSam Leffler /* 956b032f27cSSam Leffler * Mark the node as referenced to reflect that it's 957b032f27cSSam Leffler * reference count has been bumped to insure it remains 958b032f27cSSam Leffler * after the transaction completes. 959b032f27cSSam Leffler */ 960b032f27cSSam Leffler ni->ni_flags |= IEEE80211_NODE_AREF; 9611b999d64SSam Leffler /* 96212c290feSSam Leffler * Mark the node as requiring a valid association id 9631b999d64SSam Leffler * before outbound traffic is permitted. 9641b999d64SSam Leffler */ 9651b999d64SSam Leffler ni->ni_flags |= IEEE80211_NODE_ASSOCID; 966b032f27cSSam Leffler 967b032f27cSSam Leffler if (vap->iv_acl != NULL && 968b032f27cSSam Leffler vap->iv_acl->iac_getpolicy(vap) == IEEE80211_MACCMD_POLICY_RADIUS) { 969b032f27cSSam Leffler /* 970b032f27cSSam Leffler * When the ACL policy is set to RADIUS we defer the 971b032f27cSSam Leffler * authorization to a user agent. Dispatch an event, 972b032f27cSSam Leffler * a subsequent MLME call will decide the fate of the 973b032f27cSSam Leffler * station. If the user agent is not present then the 974b032f27cSSam Leffler * node will be reclaimed due to inactivity. 975b032f27cSSam Leffler */ 976b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, 977b032f27cSSam Leffler IEEE80211_MSG_AUTH | IEEE80211_MSG_ACL, ni->ni_macaddr, 978b032f27cSSam Leffler "%s", "station authentication defered (radius acl)"); 979b032f27cSSam Leffler ieee80211_notify_node_auth(ni); 980b032f27cSSam Leffler } else { 981b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, seq + 1); 982b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, 983b032f27cSSam Leffler IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, ni->ni_macaddr, 984b032f27cSSam Leffler "%s", "station authenticated (open)"); 985b032f27cSSam Leffler /* 986b032f27cSSam Leffler * When 802.1x is not in use mark the port 987b032f27cSSam Leffler * authorized at this point so traffic can flow. 988b032f27cSSam Leffler */ 989b032f27cSSam Leffler if (ni->ni_authmode != IEEE80211_AUTH_8021X) 990b032f27cSSam Leffler ieee80211_node_authorize(ni); 991b032f27cSSam Leffler } 992b032f27cSSam Leffler } 993b032f27cSSam Leffler 994b032f27cSSam Leffler static void 995b032f27cSSam Leffler hostap_auth_shared(struct ieee80211_node *ni, struct ieee80211_frame *wh, 9965463c4a4SSam Leffler uint8_t *frm, uint8_t *efrm, int rssi, int nf, 997b032f27cSSam Leffler uint16_t seq, uint16_t status) 998b032f27cSSam Leffler { 999b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 1000b032f27cSSam Leffler uint8_t *challenge; 100105ea7a3eSBjoern A. Zeeb int estatus; 1002b032f27cSSam Leffler 1003b032f27cSSam Leffler KASSERT(vap->iv_state == IEEE80211_S_RUN, ("state %d", vap->iv_state)); 1004b032f27cSSam Leffler 1005b032f27cSSam Leffler /* 1006b032f27cSSam Leffler * NB: this can happen as we allow pre-shared key 1007b032f27cSSam Leffler * authentication to be enabled w/o wep being turned 1008b032f27cSSam Leffler * on so that configuration of these can be done 1009b032f27cSSam Leffler * in any order. It may be better to enforce the 1010b032f27cSSam Leffler * ordering in which case this check would just be 1011b032f27cSSam Leffler * for sanity/consistency. 1012b032f27cSSam Leffler */ 1013b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) { 1014b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1015b032f27cSSam Leffler ni->ni_macaddr, "shared key auth", 1016b032f27cSSam Leffler "%s", " PRIVACY is disabled"); 1017b032f27cSSam Leffler estatus = IEEE80211_STATUS_ALG; 1018b032f27cSSam Leffler goto bad; 1019b032f27cSSam Leffler } 1020b032f27cSSam Leffler /* 1021b032f27cSSam Leffler * Pre-shared key authentication is evil; accept 1022b032f27cSSam Leffler * it only if explicitly configured (it is supported 1023b032f27cSSam Leffler * mainly for compatibility with clients like Mac OS X). 1024b032f27cSSam Leffler */ 1025b032f27cSSam Leffler if (ni->ni_authmode != IEEE80211_AUTH_AUTO && 1026b032f27cSSam Leffler ni->ni_authmode != IEEE80211_AUTH_SHARED) { 1027b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1028b032f27cSSam Leffler ni->ni_macaddr, "shared key auth", 1029b032f27cSSam Leffler "bad sta auth mode %u", ni->ni_authmode); 1030b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; /* XXX maybe a unique error? */ 1031b032f27cSSam Leffler estatus = IEEE80211_STATUS_ALG; 1032b032f27cSSam Leffler goto bad; 1033b032f27cSSam Leffler } 1034b032f27cSSam Leffler 1035b032f27cSSam Leffler challenge = NULL; 1036b032f27cSSam Leffler if (frm + 1 < efrm) { 1037b032f27cSSam Leffler if ((frm[1] + 2) > (efrm - frm)) { 1038b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1039b032f27cSSam Leffler ni->ni_macaddr, "shared key auth", 1040b032f27cSSam Leffler "ie %d/%d too long", 1041b032f27cSSam Leffler frm[0], (frm[1] + 2) - (efrm - frm)); 1042b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; 1043b032f27cSSam Leffler estatus = IEEE80211_STATUS_CHALLENGE; 1044b032f27cSSam Leffler goto bad; 1045b032f27cSSam Leffler } 1046b032f27cSSam Leffler if (*frm == IEEE80211_ELEMID_CHALLENGE) 1047b032f27cSSam Leffler challenge = frm; 1048b032f27cSSam Leffler frm += frm[1] + 2; 1049b032f27cSSam Leffler } 1050b032f27cSSam Leffler switch (seq) { 1051b032f27cSSam Leffler case IEEE80211_AUTH_SHARED_CHALLENGE: 1052b032f27cSSam Leffler case IEEE80211_AUTH_SHARED_RESPONSE: 1053b032f27cSSam Leffler if (challenge == NULL) { 1054b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1055b032f27cSSam Leffler ni->ni_macaddr, "shared key auth", 1056b032f27cSSam Leffler "%s", "no challenge"); 1057b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; 1058b032f27cSSam Leffler estatus = IEEE80211_STATUS_CHALLENGE; 1059b032f27cSSam Leffler goto bad; 1060b032f27cSSam Leffler } 1061b032f27cSSam Leffler if (challenge[1] != IEEE80211_CHALLENGE_LEN) { 1062b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1063b032f27cSSam Leffler ni->ni_macaddr, "shared key auth", 1064b032f27cSSam Leffler "bad challenge len %d", challenge[1]); 1065b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; 1066b032f27cSSam Leffler estatus = IEEE80211_STATUS_CHALLENGE; 1067b032f27cSSam Leffler goto bad; 1068b032f27cSSam Leffler } 1069b032f27cSSam Leffler default: 1070b032f27cSSam Leffler break; 1071b032f27cSSam Leffler } 1072b032f27cSSam Leffler switch (seq) { 1073b032f27cSSam Leffler case IEEE80211_AUTH_SHARED_REQUEST: 107405ea7a3eSBjoern A. Zeeb { 107505ea7a3eSBjoern A. Zeeb #ifdef IEEE80211_DEBUG 107605ea7a3eSBjoern A. Zeeb bool allocbs; 107705ea7a3eSBjoern A. Zeeb #endif 107805ea7a3eSBjoern A. Zeeb 1079b032f27cSSam Leffler if (ni == vap->iv_bss) { 1080b032f27cSSam Leffler ni = ieee80211_dup_bss(vap, wh->i_addr2); 1081b032f27cSSam Leffler if (ni == NULL) { 1082b032f27cSSam Leffler /* NB: no way to return an error */ 1083b032f27cSSam Leffler return; 1084b032f27cSSam Leffler } 108505ea7a3eSBjoern A. Zeeb #ifdef IEEE80211_DEBUG 1086b032f27cSSam Leffler allocbs = 1; 108705ea7a3eSBjoern A. Zeeb #endif 1088b032f27cSSam Leffler } else { 1089b032f27cSSam Leffler if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0) 1090b032f27cSSam Leffler (void) ieee80211_ref_node(ni); 109105ea7a3eSBjoern A. Zeeb #ifdef IEEE80211_DEBUG 1092b032f27cSSam Leffler allocbs = 0; 109305ea7a3eSBjoern A. Zeeb #endif 1094b032f27cSSam Leffler } 1095b032f27cSSam Leffler /* 1096b032f27cSSam Leffler * Mark the node as referenced to reflect that it's 1097b032f27cSSam Leffler * reference count has been bumped to insure it remains 1098b032f27cSSam Leffler * after the transaction completes. 1099b032f27cSSam Leffler */ 1100b032f27cSSam Leffler ni->ni_flags |= IEEE80211_NODE_AREF; 11011b999d64SSam Leffler /* 11026dbbec93SAndriy Voskoboinyk * Mark the node as requiring a valid association id 11031b999d64SSam Leffler * before outbound traffic is permitted. 11041b999d64SSam Leffler */ 11051b999d64SSam Leffler ni->ni_flags |= IEEE80211_NODE_ASSOCID; 1106b032f27cSSam Leffler IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi); 11075463c4a4SSam Leffler ni->ni_noise = nf; 1108b032f27cSSam Leffler if (!ieee80211_alloc_challenge(ni)) { 1109b032f27cSSam Leffler /* NB: don't return error so they rexmit */ 1110b032f27cSSam Leffler return; 1111b032f27cSSam Leffler } 1112af7d9f8eSBjoern A. Zeeb net80211_get_random_bytes(ni->ni_challenge, 1113b032f27cSSam Leffler IEEE80211_CHALLENGE_LEN); 1114b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, 1115b032f27cSSam Leffler ni, "shared key %sauth request", allocbs ? "" : "re"); 1116b032f27cSSam Leffler /* 1117b032f27cSSam Leffler * When the ACL policy is set to RADIUS we defer the 1118b032f27cSSam Leffler * authorization to a user agent. Dispatch an event, 1119b032f27cSSam Leffler * a subsequent MLME call will decide the fate of the 1120b032f27cSSam Leffler * station. If the user agent is not present then the 1121b032f27cSSam Leffler * node will be reclaimed due to inactivity. 1122b032f27cSSam Leffler */ 1123b032f27cSSam Leffler if (vap->iv_acl != NULL && 1124b032f27cSSam Leffler vap->iv_acl->iac_getpolicy(vap) == IEEE80211_MACCMD_POLICY_RADIUS) { 1125b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, 1126b032f27cSSam Leffler IEEE80211_MSG_AUTH | IEEE80211_MSG_ACL, 1127b032f27cSSam Leffler ni->ni_macaddr, 1128b032f27cSSam Leffler "%s", "station authentication defered (radius acl)"); 1129b032f27cSSam Leffler ieee80211_notify_node_auth(ni); 1130b032f27cSSam Leffler return; 1131b032f27cSSam Leffler } 1132b032f27cSSam Leffler break; 113305ea7a3eSBjoern A. Zeeb } 1134b032f27cSSam Leffler case IEEE80211_AUTH_SHARED_RESPONSE: 1135b032f27cSSam Leffler if (ni == vap->iv_bss) { 1136b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1137b032f27cSSam Leffler ni->ni_macaddr, "shared key response", 1138b032f27cSSam Leffler "%s", "unknown station"); 1139b032f27cSSam Leffler /* NB: don't send a response */ 1140b032f27cSSam Leffler return; 1141b032f27cSSam Leffler } 1142b032f27cSSam Leffler if (ni->ni_challenge == NULL) { 1143b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1144b032f27cSSam Leffler ni->ni_macaddr, "shared key response", 1145b032f27cSSam Leffler "%s", "no challenge recorded"); 1146b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; 1147b032f27cSSam Leffler estatus = IEEE80211_STATUS_CHALLENGE; 1148b032f27cSSam Leffler goto bad; 1149b032f27cSSam Leffler } 1150b032f27cSSam Leffler if (memcmp(ni->ni_challenge, &challenge[2], 1151b032f27cSSam Leffler challenge[1]) != 0) { 1152b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1153b032f27cSSam Leffler ni->ni_macaddr, "shared key response", 1154b032f27cSSam Leffler "%s", "challenge mismatch"); 1155b032f27cSSam Leffler vap->iv_stats.is_rx_auth_fail++; 1156b032f27cSSam Leffler estatus = IEEE80211_STATUS_CHALLENGE; 1157b032f27cSSam Leffler goto bad; 1158b032f27cSSam Leffler } 1159b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, 1160b032f27cSSam Leffler ni, "%s", "station authenticated (shared key)"); 1161b032f27cSSam Leffler ieee80211_node_authorize(ni); 1162b032f27cSSam Leffler break; 1163b032f27cSSam Leffler default: 1164b032f27cSSam Leffler IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH, 1165b032f27cSSam Leffler ni->ni_macaddr, "shared key auth", 1166b032f27cSSam Leffler "bad seq %d", seq); 1167b032f27cSSam Leffler vap->iv_stats.is_rx_bad_auth++; 1168b032f27cSSam Leffler estatus = IEEE80211_STATUS_SEQUENCE; 1169b032f27cSSam Leffler goto bad; 1170b032f27cSSam Leffler } 1171b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, seq + 1); 1172b032f27cSSam Leffler return; 1173b032f27cSSam Leffler bad: 1174b032f27cSSam Leffler /* 1175b032f27cSSam Leffler * Send an error response; but only when operating as an AP. 1176b032f27cSSam Leffler */ 1177b032f27cSSam Leffler /* XXX hack to workaround calling convention */ 1178b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, 1179b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_AUTH, 1180b032f27cSSam Leffler (seq + 1) | (estatus<<16)); 1181b032f27cSSam Leffler } 1182b032f27cSSam Leffler 1183b032f27cSSam Leffler /* 1184b032f27cSSam Leffler * Convert a WPA cipher selector OUI to an internal 1185b032f27cSSam Leffler * cipher algorithm. Where appropriate we also 1186b032f27cSSam Leffler * record any key length. 1187b032f27cSSam Leffler */ 1188b032f27cSSam Leffler static int 118995d9a127SAndriy Voskoboinyk wpa_cipher(const uint8_t *sel, uint8_t *keylen, uint8_t *cipher) 1190b032f27cSSam Leffler { 1191b032f27cSSam Leffler #define WPA_SEL(x) (((x)<<24)|WPA_OUI) 119231021a2bSAndriy Voskoboinyk uint32_t w = le32dec(sel); 1193b032f27cSSam Leffler 1194b032f27cSSam Leffler switch (w) { 1195b032f27cSSam Leffler case WPA_SEL(WPA_CSE_NULL): 119695d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_NONE; 119795d9a127SAndriy Voskoboinyk break; 1198b032f27cSSam Leffler case WPA_SEL(WPA_CSE_WEP40): 1199b032f27cSSam Leffler if (keylen) 1200b032f27cSSam Leffler *keylen = 40 / NBBY; 120195d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_WEP; 120295d9a127SAndriy Voskoboinyk break; 1203b032f27cSSam Leffler case WPA_SEL(WPA_CSE_WEP104): 1204b032f27cSSam Leffler if (keylen) 1205b032f27cSSam Leffler *keylen = 104 / NBBY; 120695d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_WEP; 120795d9a127SAndriy Voskoboinyk break; 1208b032f27cSSam Leffler case WPA_SEL(WPA_CSE_TKIP): 120995d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_TKIP; 121095d9a127SAndriy Voskoboinyk break; 1211b032f27cSSam Leffler case WPA_SEL(WPA_CSE_CCMP): 121295d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_AES_CCM; 121395d9a127SAndriy Voskoboinyk break; 121495d9a127SAndriy Voskoboinyk default: 121595d9a127SAndriy Voskoboinyk return (EINVAL); 1216b032f27cSSam Leffler } 121795d9a127SAndriy Voskoboinyk 121895d9a127SAndriy Voskoboinyk return (0); 1219b032f27cSSam Leffler #undef WPA_SEL 1220b032f27cSSam Leffler } 1221b032f27cSSam Leffler 1222b032f27cSSam Leffler /* 1223b032f27cSSam Leffler * Convert a WPA key management/authentication algorithm 1224b032f27cSSam Leffler * to an internal code. 1225b032f27cSSam Leffler */ 1226b032f27cSSam Leffler static int 1227b032f27cSSam Leffler wpa_keymgmt(const uint8_t *sel) 1228b032f27cSSam Leffler { 1229b032f27cSSam Leffler #define WPA_SEL(x) (((x)<<24)|WPA_OUI) 123031021a2bSAndriy Voskoboinyk uint32_t w = le32dec(sel); 1231b032f27cSSam Leffler 1232b032f27cSSam Leffler switch (w) { 1233b032f27cSSam Leffler case WPA_SEL(WPA_ASE_8021X_UNSPEC): 1234b032f27cSSam Leffler return WPA_ASE_8021X_UNSPEC; 1235b032f27cSSam Leffler case WPA_SEL(WPA_ASE_8021X_PSK): 1236b032f27cSSam Leffler return WPA_ASE_8021X_PSK; 1237b032f27cSSam Leffler case WPA_SEL(WPA_ASE_NONE): 1238b032f27cSSam Leffler return WPA_ASE_NONE; 1239b032f27cSSam Leffler } 1240b032f27cSSam Leffler return 0; /* NB: so is discarded */ 1241b032f27cSSam Leffler #undef WPA_SEL 1242b032f27cSSam Leffler } 1243b032f27cSSam Leffler 1244b032f27cSSam Leffler /* 1245b032f27cSSam Leffler * Parse a WPA information element to collect parameters. 1246b032f27cSSam Leffler * Note that we do not validate security parameters; that 1247b032f27cSSam Leffler * is handled by the authenticator; the parsing done here 1248b032f27cSSam Leffler * is just for internal use in making operational decisions. 1249b032f27cSSam Leffler */ 1250b032f27cSSam Leffler static int 1251b032f27cSSam Leffler ieee80211_parse_wpa(struct ieee80211vap *vap, const uint8_t *frm, 1252b032f27cSSam Leffler struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh) 1253b032f27cSSam Leffler { 1254b032f27cSSam Leffler uint8_t len = frm[1]; 1255b032f27cSSam Leffler uint32_t w; 125695d9a127SAndriy Voskoboinyk int error, n; 1257b032f27cSSam Leffler 1258b032f27cSSam Leffler /* 1259b032f27cSSam Leffler * Check the length once for fixed parts: OUI, type, 1260b032f27cSSam Leffler * version, mcast cipher, and 2 selector counts. 1261b032f27cSSam Leffler * Other, variable-length data, must be checked separately. 1262b032f27cSSam Leffler */ 1263b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_WPA1) == 0) { 1264b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1265b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1266b032f27cSSam Leffler wh, "WPA", "not WPA, flags 0x%x", vap->iv_flags); 1267b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1268b032f27cSSam Leffler } 1269b032f27cSSam Leffler if (len < 14) { 1270b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1271b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1272b032f27cSSam Leffler wh, "WPA", "too short, len %u", len); 1273b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1274b032f27cSSam Leffler } 1275b032f27cSSam Leffler frm += 6, len -= 4; /* NB: len is payload only */ 1276f59310a1SRui Paulo /* NB: iswpaoui already validated the OUI and type */ 127731021a2bSAndriy Voskoboinyk w = le16dec(frm); 1278b032f27cSSam Leffler if (w != WPA_VERSION) { 1279b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1280b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1281b032f27cSSam Leffler wh, "WPA", "bad version %u", w); 1282b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1283b032f27cSSam Leffler } 1284b032f27cSSam Leffler frm += 2, len -= 2; 1285b032f27cSSam Leffler 1286b032f27cSSam Leffler memset(rsn, 0, sizeof(*rsn)); 1287b032f27cSSam Leffler 1288b032f27cSSam Leffler /* multicast/group cipher */ 128995d9a127SAndriy Voskoboinyk error = wpa_cipher(frm, &rsn->rsn_mcastkeylen, &rsn->rsn_mcastcipher); 129095d9a127SAndriy Voskoboinyk if (error != 0) { 129195d9a127SAndriy Voskoboinyk IEEE80211_DISCARD_IE(vap, 129295d9a127SAndriy Voskoboinyk IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 129395d9a127SAndriy Voskoboinyk wh, "WPA", "unknown mcast cipher suite %08X", 129495d9a127SAndriy Voskoboinyk le32dec(frm)); 129595d9a127SAndriy Voskoboinyk return IEEE80211_REASON_GROUP_CIPHER_INVALID; 129695d9a127SAndriy Voskoboinyk } 1297b032f27cSSam Leffler frm += 4, len -= 4; 1298b032f27cSSam Leffler 1299b032f27cSSam Leffler /* unicast ciphers */ 130031021a2bSAndriy Voskoboinyk n = le16dec(frm); 1301b032f27cSSam Leffler frm += 2, len -= 2; 1302b032f27cSSam Leffler if (len < n*4+2) { 1303b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1304b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1305b032f27cSSam Leffler wh, "WPA", "ucast cipher data too short; len %u, n %u", 1306b032f27cSSam Leffler len, n); 1307b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1308b032f27cSSam Leffler } 1309b032f27cSSam Leffler w = 0; 1310b032f27cSSam Leffler for (; n > 0; n--) { 131195d9a127SAndriy Voskoboinyk uint8_t cipher; 131295d9a127SAndriy Voskoboinyk 131395d9a127SAndriy Voskoboinyk error = wpa_cipher(frm, &rsn->rsn_ucastkeylen, &cipher); 131495d9a127SAndriy Voskoboinyk if (error == 0) 131595d9a127SAndriy Voskoboinyk w |= 1 << cipher; 131695d9a127SAndriy Voskoboinyk 1317b032f27cSSam Leffler frm += 4, len -= 4; 1318b032f27cSSam Leffler } 131995d9a127SAndriy Voskoboinyk if (w == 0) { 132095d9a127SAndriy Voskoboinyk IEEE80211_DISCARD_IE(vap, 132195d9a127SAndriy Voskoboinyk IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 132295d9a127SAndriy Voskoboinyk wh, "WPA", "no usable pairwise cipher suite found (w=%d)", 132395d9a127SAndriy Voskoboinyk w); 132495d9a127SAndriy Voskoboinyk return IEEE80211_REASON_PAIRWISE_CIPHER_INVALID; 132595d9a127SAndriy Voskoboinyk } 132695d9a127SAndriy Voskoboinyk /* XXX other? */ 132795d9a127SAndriy Voskoboinyk if (w & (1 << IEEE80211_CIPHER_AES_CCM)) 1328b032f27cSSam Leffler rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 132995d9a127SAndriy Voskoboinyk else 133095d9a127SAndriy Voskoboinyk rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 1331b032f27cSSam Leffler 1332b032f27cSSam Leffler /* key management algorithms */ 133331021a2bSAndriy Voskoboinyk n = le16dec(frm); 1334b032f27cSSam Leffler frm += 2, len -= 2; 1335b032f27cSSam Leffler if (len < n*4) { 1336b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1337b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1338b032f27cSSam Leffler wh, "WPA", "key mgmt alg data too short; len %u, n %u", 1339b032f27cSSam Leffler len, n); 1340b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1341b032f27cSSam Leffler } 1342b032f27cSSam Leffler w = 0; 1343b032f27cSSam Leffler for (; n > 0; n--) { 1344b032f27cSSam Leffler w |= wpa_keymgmt(frm); 1345b032f27cSSam Leffler frm += 4, len -= 4; 1346b032f27cSSam Leffler } 1347b032f27cSSam Leffler if (w & WPA_ASE_8021X_UNSPEC) 1348b032f27cSSam Leffler rsn->rsn_keymgmt = WPA_ASE_8021X_UNSPEC; 1349b032f27cSSam Leffler else 1350b032f27cSSam Leffler rsn->rsn_keymgmt = WPA_ASE_8021X_PSK; 1351b032f27cSSam Leffler 1352b032f27cSSam Leffler if (len > 2) /* optional capabilities */ 135331021a2bSAndriy Voskoboinyk rsn->rsn_caps = le16dec(frm); 1354b032f27cSSam Leffler 1355b032f27cSSam Leffler return 0; 1356b032f27cSSam Leffler } 1357b032f27cSSam Leffler 1358b032f27cSSam Leffler /* 1359b032f27cSSam Leffler * Convert an RSN cipher selector OUI to an internal 1360b032f27cSSam Leffler * cipher algorithm. Where appropriate we also 1361b032f27cSSam Leffler * record any key length. 1362b032f27cSSam Leffler */ 1363b032f27cSSam Leffler static int 136495d9a127SAndriy Voskoboinyk rsn_cipher(const uint8_t *sel, uint8_t *keylen, uint8_t *cipher) 1365b032f27cSSam Leffler { 1366b032f27cSSam Leffler #define RSN_SEL(x) (((x)<<24)|RSN_OUI) 136731021a2bSAndriy Voskoboinyk uint32_t w = le32dec(sel); 1368b032f27cSSam Leffler 1369b032f27cSSam Leffler switch (w) { 1370b032f27cSSam Leffler case RSN_SEL(RSN_CSE_NULL): 137195d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_NONE; 137295d9a127SAndriy Voskoboinyk break; 1373b032f27cSSam Leffler case RSN_SEL(RSN_CSE_WEP40): 1374b032f27cSSam Leffler if (keylen) 1375b032f27cSSam Leffler *keylen = 40 / NBBY; 137695d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_WEP; 137795d9a127SAndriy Voskoboinyk break; 1378b032f27cSSam Leffler case RSN_SEL(RSN_CSE_WEP104): 1379b032f27cSSam Leffler if (keylen) 1380b032f27cSSam Leffler *keylen = 104 / NBBY; 138195d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_WEP; 138295d9a127SAndriy Voskoboinyk break; 1383b032f27cSSam Leffler case RSN_SEL(RSN_CSE_TKIP): 138495d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_TKIP; 138595d9a127SAndriy Voskoboinyk break; 1386b032f27cSSam Leffler case RSN_SEL(RSN_CSE_CCMP): 138795d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_AES_CCM; 138895d9a127SAndriy Voskoboinyk break; 1389b032f27cSSam Leffler case RSN_SEL(RSN_CSE_WRAP): 139095d9a127SAndriy Voskoboinyk *cipher = IEEE80211_CIPHER_AES_OCB; 139195d9a127SAndriy Voskoboinyk break; 139295d9a127SAndriy Voskoboinyk default: 139395d9a127SAndriy Voskoboinyk return (EINVAL); 1394b032f27cSSam Leffler } 139595d9a127SAndriy Voskoboinyk 139695d9a127SAndriy Voskoboinyk return (0); 1397b032f27cSSam Leffler #undef WPA_SEL 1398b032f27cSSam Leffler } 1399b032f27cSSam Leffler 1400b032f27cSSam Leffler /* 1401b032f27cSSam Leffler * Convert an RSN key management/authentication algorithm 1402b032f27cSSam Leffler * to an internal code. 1403b032f27cSSam Leffler */ 1404b032f27cSSam Leffler static int 1405b032f27cSSam Leffler rsn_keymgmt(const uint8_t *sel) 1406b032f27cSSam Leffler { 1407b032f27cSSam Leffler #define RSN_SEL(x) (((x)<<24)|RSN_OUI) 140831021a2bSAndriy Voskoboinyk uint32_t w = le32dec(sel); 1409b032f27cSSam Leffler 1410b032f27cSSam Leffler switch (w) { 1411b032f27cSSam Leffler case RSN_SEL(RSN_ASE_8021X_UNSPEC): 1412b032f27cSSam Leffler return RSN_ASE_8021X_UNSPEC; 1413b032f27cSSam Leffler case RSN_SEL(RSN_ASE_8021X_PSK): 1414b032f27cSSam Leffler return RSN_ASE_8021X_PSK; 1415b032f27cSSam Leffler case RSN_SEL(RSN_ASE_NONE): 1416b032f27cSSam Leffler return RSN_ASE_NONE; 1417b032f27cSSam Leffler } 1418b032f27cSSam Leffler return 0; /* NB: so is discarded */ 1419b032f27cSSam Leffler #undef RSN_SEL 1420b032f27cSSam Leffler } 1421b032f27cSSam Leffler 1422b032f27cSSam Leffler /* 1423b032f27cSSam Leffler * Parse a WPA/RSN information element to collect parameters 1424b032f27cSSam Leffler * and validate the parameters against what has been 1425b032f27cSSam Leffler * configured for the system. 1426b032f27cSSam Leffler */ 1427b032f27cSSam Leffler static int 1428b032f27cSSam Leffler ieee80211_parse_rsn(struct ieee80211vap *vap, const uint8_t *frm, 1429b032f27cSSam Leffler struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh) 1430b032f27cSSam Leffler { 1431b032f27cSSam Leffler uint8_t len = frm[1]; 1432b032f27cSSam Leffler uint32_t w; 143395d9a127SAndriy Voskoboinyk int error, n; 1434b032f27cSSam Leffler 1435b032f27cSSam Leffler /* 1436b032f27cSSam Leffler * Check the length once for fixed parts: 1437b032f27cSSam Leffler * version, mcast cipher, and 2 selector counts. 1438b032f27cSSam Leffler * Other, variable-length data, must be checked separately. 1439b032f27cSSam Leffler */ 1440b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_WPA2) == 0) { 1441b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1442b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1443b032f27cSSam Leffler wh, "WPA", "not RSN, flags 0x%x", vap->iv_flags); 1444b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1445b032f27cSSam Leffler } 144695d9a127SAndriy Voskoboinyk /* XXX may be shorter */ 1447b032f27cSSam Leffler if (len < 10) { 1448b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1449b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1450b032f27cSSam Leffler wh, "RSN", "too short, len %u", len); 1451b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1452b032f27cSSam Leffler } 1453b032f27cSSam Leffler frm += 2; 145431021a2bSAndriy Voskoboinyk w = le16dec(frm); 1455b032f27cSSam Leffler if (w != RSN_VERSION) { 1456b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1457b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1458b032f27cSSam Leffler wh, "RSN", "bad version %u", w); 145995d9a127SAndriy Voskoboinyk return IEEE80211_REASON_UNSUPP_RSN_IE_VERSION; 1460b032f27cSSam Leffler } 1461b032f27cSSam Leffler frm += 2, len -= 2; 1462b032f27cSSam Leffler 1463b032f27cSSam Leffler memset(rsn, 0, sizeof(*rsn)); 1464b032f27cSSam Leffler 1465b032f27cSSam Leffler /* multicast/group cipher */ 146695d9a127SAndriy Voskoboinyk error = rsn_cipher(frm, &rsn->rsn_mcastkeylen, &rsn->rsn_mcastcipher); 146795d9a127SAndriy Voskoboinyk if (error != 0) { 146895d9a127SAndriy Voskoboinyk IEEE80211_DISCARD_IE(vap, 146995d9a127SAndriy Voskoboinyk IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 147095d9a127SAndriy Voskoboinyk wh, "RSN", "unknown mcast cipher suite %08X", 147195d9a127SAndriy Voskoboinyk le32dec(frm)); 147295d9a127SAndriy Voskoboinyk return IEEE80211_REASON_GROUP_CIPHER_INVALID; 147395d9a127SAndriy Voskoboinyk } 147495d9a127SAndriy Voskoboinyk if (rsn->rsn_mcastcipher == IEEE80211_CIPHER_NONE) { 147595d9a127SAndriy Voskoboinyk IEEE80211_DISCARD_IE(vap, 147695d9a127SAndriy Voskoboinyk IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 147795d9a127SAndriy Voskoboinyk wh, "RSN", "invalid mcast cipher suite %d", 147895d9a127SAndriy Voskoboinyk rsn->rsn_mcastcipher); 147995d9a127SAndriy Voskoboinyk return IEEE80211_REASON_GROUP_CIPHER_INVALID; 148095d9a127SAndriy Voskoboinyk } 1481b032f27cSSam Leffler frm += 4, len -= 4; 1482b032f27cSSam Leffler 1483b032f27cSSam Leffler /* unicast ciphers */ 148431021a2bSAndriy Voskoboinyk n = le16dec(frm); 1485b032f27cSSam Leffler frm += 2, len -= 2; 1486b032f27cSSam Leffler if (len < n*4+2) { 1487b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1488b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1489b032f27cSSam Leffler wh, "RSN", "ucast cipher data too short; len %u, n %u", 1490b032f27cSSam Leffler len, n); 1491b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1492b032f27cSSam Leffler } 1493b032f27cSSam Leffler w = 0; 149495d9a127SAndriy Voskoboinyk 1495b032f27cSSam Leffler for (; n > 0; n--) { 149695d9a127SAndriy Voskoboinyk uint8_t cipher; 149795d9a127SAndriy Voskoboinyk 149895d9a127SAndriy Voskoboinyk error = rsn_cipher(frm, &rsn->rsn_ucastkeylen, &cipher); 149995d9a127SAndriy Voskoboinyk if (error == 0) 150095d9a127SAndriy Voskoboinyk w |= 1 << cipher; 150195d9a127SAndriy Voskoboinyk 1502b032f27cSSam Leffler frm += 4, len -= 4; 1503b032f27cSSam Leffler } 150495d9a127SAndriy Voskoboinyk if (w & (1 << IEEE80211_CIPHER_AES_CCM)) 1505b032f27cSSam Leffler rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM; 150695d9a127SAndriy Voskoboinyk else if (w & (1 << IEEE80211_CIPHER_AES_OCB)) 150795d9a127SAndriy Voskoboinyk rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_OCB; 150895d9a127SAndriy Voskoboinyk else if (w & (1 << IEEE80211_CIPHER_TKIP)) 150995d9a127SAndriy Voskoboinyk rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP; 151095d9a127SAndriy Voskoboinyk else if ((w & (1 << IEEE80211_CIPHER_NONE)) && 151195d9a127SAndriy Voskoboinyk (rsn->rsn_mcastcipher == IEEE80211_CIPHER_WEP || 151295d9a127SAndriy Voskoboinyk rsn->rsn_mcastcipher == IEEE80211_CIPHER_TKIP)) 151395d9a127SAndriy Voskoboinyk rsn->rsn_ucastcipher = IEEE80211_CIPHER_NONE; 151495d9a127SAndriy Voskoboinyk else { 151595d9a127SAndriy Voskoboinyk IEEE80211_DISCARD_IE(vap, 151695d9a127SAndriy Voskoboinyk IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 151795d9a127SAndriy Voskoboinyk wh, "RSN", "no usable pairwise cipher suite found (w=%d)", 151895d9a127SAndriy Voskoboinyk w); 151995d9a127SAndriy Voskoboinyk return IEEE80211_REASON_PAIRWISE_CIPHER_INVALID; 152095d9a127SAndriy Voskoboinyk } 1521b032f27cSSam Leffler 1522b032f27cSSam Leffler /* key management algorithms */ 152331021a2bSAndriy Voskoboinyk n = le16dec(frm); 1524b032f27cSSam Leffler frm += 2, len -= 2; 1525b032f27cSSam Leffler if (len < n*4) { 1526b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, 1527b032f27cSSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA, 1528b032f27cSSam Leffler wh, "RSN", "key mgmt alg data too short; len %u, n %u", 1529b032f27cSSam Leffler len, n); 1530b032f27cSSam Leffler return IEEE80211_REASON_IE_INVALID; 1531b032f27cSSam Leffler } 1532b032f27cSSam Leffler w = 0; 1533b032f27cSSam Leffler for (; n > 0; n--) { 1534b032f27cSSam Leffler w |= rsn_keymgmt(frm); 1535b032f27cSSam Leffler frm += 4, len -= 4; 1536b032f27cSSam Leffler } 1537b032f27cSSam Leffler if (w & RSN_ASE_8021X_UNSPEC) 1538b032f27cSSam Leffler rsn->rsn_keymgmt = RSN_ASE_8021X_UNSPEC; 1539b032f27cSSam Leffler else 1540b032f27cSSam Leffler rsn->rsn_keymgmt = RSN_ASE_8021X_PSK; 1541b032f27cSSam Leffler 1542b032f27cSSam Leffler /* optional RSN capabilities */ 1543b032f27cSSam Leffler if (len > 2) 154431021a2bSAndriy Voskoboinyk rsn->rsn_caps = le16dec(frm); 1545b032f27cSSam Leffler /* XXXPMKID */ 1546b032f27cSSam Leffler 1547b032f27cSSam Leffler return 0; 1548b032f27cSSam Leffler } 1549b032f27cSSam Leffler 1550b032f27cSSam Leffler /* 1551a4641f4eSPedro F. Giffuni * WPA/802.11i association request processing. 1552b032f27cSSam Leffler */ 1553b032f27cSSam Leffler static int 1554b032f27cSSam Leffler wpa_assocreq(struct ieee80211_node *ni, struct ieee80211_rsnparms *rsnparms, 1555b032f27cSSam Leffler const struct ieee80211_frame *wh, const uint8_t *wpa, 1556b032f27cSSam Leffler const uint8_t *rsn, uint16_t capinfo) 1557b032f27cSSam Leffler { 1558b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 1559b032f27cSSam Leffler uint8_t reason; 1560b032f27cSSam Leffler int badwparsn; 1561b032f27cSSam Leffler 1562b032f27cSSam Leffler ni->ni_flags &= ~(IEEE80211_NODE_WPS|IEEE80211_NODE_TSN); 1563b032f27cSSam Leffler if (wpa == NULL && rsn == NULL) { 1564b032f27cSSam Leffler if (vap->iv_flags_ext & IEEE80211_FEXT_WPS) { 1565b032f27cSSam Leffler /* 1566b032f27cSSam Leffler * W-Fi Protected Setup (WPS) permits 1567b032f27cSSam Leffler * clients to associate and pass EAPOL frames 1568b032f27cSSam Leffler * to establish initial credentials. 1569b032f27cSSam Leffler */ 1570b032f27cSSam Leffler ni->ni_flags |= IEEE80211_NODE_WPS; 1571b032f27cSSam Leffler return 1; 1572b032f27cSSam Leffler } 1573b032f27cSSam Leffler if ((vap->iv_flags_ext & IEEE80211_FEXT_TSN) && 1574b032f27cSSam Leffler (capinfo & IEEE80211_CAPINFO_PRIVACY)) { 1575b032f27cSSam Leffler /* 1576b032f27cSSam Leffler * Transitional Security Network. Permits clients 1577b032f27cSSam Leffler * to associate and use WEP while WPA is configured. 1578b032f27cSSam Leffler */ 1579b032f27cSSam Leffler ni->ni_flags |= IEEE80211_NODE_TSN; 1580b032f27cSSam Leffler return 1; 1581b032f27cSSam Leffler } 1582b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, 1583b032f27cSSam Leffler wh, NULL, "%s", "no WPA/RSN IE in association request"); 1584b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_badwpaie++; 1585b032f27cSSam Leffler reason = IEEE80211_REASON_IE_INVALID; 1586b032f27cSSam Leffler goto bad; 1587b032f27cSSam Leffler } 1588b032f27cSSam Leffler /* assert right association security credentials */ 1589b032f27cSSam Leffler badwparsn = 0; /* NB: to silence compiler */ 1590b032f27cSSam Leffler switch (vap->iv_flags & IEEE80211_F_WPA) { 1591b032f27cSSam Leffler case IEEE80211_F_WPA1: 1592b032f27cSSam Leffler badwparsn = (wpa == NULL); 1593b032f27cSSam Leffler break; 1594b032f27cSSam Leffler case IEEE80211_F_WPA2: 1595b032f27cSSam Leffler badwparsn = (rsn == NULL); 1596b032f27cSSam Leffler break; 1597b032f27cSSam Leffler case IEEE80211_F_WPA1|IEEE80211_F_WPA2: 1598b032f27cSSam Leffler badwparsn = (wpa == NULL && rsn == NULL); 1599b032f27cSSam Leffler break; 1600b032f27cSSam Leffler } 1601b032f27cSSam Leffler if (badwparsn) { 1602b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, 1603b032f27cSSam Leffler wh, NULL, 1604b032f27cSSam Leffler "%s", "missing WPA/RSN IE in association request"); 1605b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_badwpaie++; 1606b032f27cSSam Leffler reason = IEEE80211_REASON_IE_INVALID; 1607b032f27cSSam Leffler goto bad; 1608b032f27cSSam Leffler } 1609b032f27cSSam Leffler /* 1610b032f27cSSam Leffler * Parse WPA/RSN information element. 1611b032f27cSSam Leffler */ 1612b032f27cSSam Leffler if (wpa != NULL) 1613b032f27cSSam Leffler reason = ieee80211_parse_wpa(vap, wpa, rsnparms, wh); 1614b032f27cSSam Leffler else 1615b032f27cSSam Leffler reason = ieee80211_parse_rsn(vap, rsn, rsnparms, wh); 1616b032f27cSSam Leffler if (reason != 0) { 161795d9a127SAndriy Voskoboinyk /* XXX wpa->rsn fallback? */ 1618b032f27cSSam Leffler /* XXX distinguish WPA/RSN? */ 1619b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_badwpaie++; 1620b032f27cSSam Leffler goto bad; 1621b032f27cSSam Leffler } 1622b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, ni, 1623b032f27cSSam Leffler "%s ie: mc %u/%u uc %u/%u key %u caps 0x%x", 1624b032f27cSSam Leffler wpa != NULL ? "WPA" : "RSN", 1625b032f27cSSam Leffler rsnparms->rsn_mcastcipher, rsnparms->rsn_mcastkeylen, 1626b032f27cSSam Leffler rsnparms->rsn_ucastcipher, rsnparms->rsn_ucastkeylen, 1627b032f27cSSam Leffler rsnparms->rsn_keymgmt, rsnparms->rsn_caps); 1628b032f27cSSam Leffler 1629b032f27cSSam Leffler return 1; 1630b032f27cSSam Leffler bad: 1631b032f27cSSam Leffler ieee80211_node_deauth(ni, reason); 1632b032f27cSSam Leffler return 0; 1633b032f27cSSam Leffler } 1634b032f27cSSam Leffler 1635b032f27cSSam Leffler /* XXX find a better place for definition */ 1636b032f27cSSam Leffler struct l2_update_frame { 1637b032f27cSSam Leffler struct ether_header eh; 1638b032f27cSSam Leffler uint8_t dsap; 1639b032f27cSSam Leffler uint8_t ssap; 1640b032f27cSSam Leffler uint8_t control; 1641b032f27cSSam Leffler uint8_t xid[3]; 1642b032f27cSSam Leffler } __packed; 1643b032f27cSSam Leffler 1644b032f27cSSam Leffler /* 1645b032f27cSSam Leffler * Deliver a TGf L2UF frame on behalf of a station. 1646b032f27cSSam Leffler * This primes any bridge when the station is roaming 1647b032f27cSSam Leffler * between ap's on the same wired network. 1648b032f27cSSam Leffler */ 1649b032f27cSSam Leffler static void 1650b032f27cSSam Leffler ieee80211_deliver_l2uf(struct ieee80211_node *ni) 1651b032f27cSSam Leffler { 1652b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 1653b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp; 1654b032f27cSSam Leffler struct mbuf *m; 1655b032f27cSSam Leffler struct l2_update_frame *l2uf; 1656b032f27cSSam Leffler struct ether_header *eh; 1657b032f27cSSam Leffler 1658bd29f817SBjoern A. Zeeb m = m_gethdr(IEEE80211_M_NOWAIT, MT_DATA); 1659b032f27cSSam Leffler if (m == NULL) { 1660b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni, 1661b032f27cSSam Leffler "%s", "no mbuf for l2uf frame"); 1662b032f27cSSam Leffler vap->iv_stats.is_rx_nobuf++; /* XXX not right */ 1663b032f27cSSam Leffler return; 1664b032f27cSSam Leffler } 1665b032f27cSSam Leffler l2uf = mtod(m, struct l2_update_frame *); 1666b032f27cSSam Leffler eh = &l2uf->eh; 1667b032f27cSSam Leffler /* dst: Broadcast address */ 1668b032f27cSSam Leffler IEEE80211_ADDR_COPY(eh->ether_dhost, ifp->if_broadcastaddr); 1669b032f27cSSam Leffler /* src: associated STA */ 1670b032f27cSSam Leffler IEEE80211_ADDR_COPY(eh->ether_shost, ni->ni_macaddr); 1671b032f27cSSam Leffler eh->ether_type = htons(sizeof(*l2uf) - sizeof(*eh)); 1672b032f27cSSam Leffler 1673b032f27cSSam Leffler l2uf->dsap = 0; 1674b032f27cSSam Leffler l2uf->ssap = 0; 1675b032f27cSSam Leffler l2uf->control = 0xf5; 1676b032f27cSSam Leffler l2uf->xid[0] = 0x81; 1677b032f27cSSam Leffler l2uf->xid[1] = 0x80; 1678b032f27cSSam Leffler l2uf->xid[2] = 0x00; 1679b032f27cSSam Leffler 1680b032f27cSSam Leffler m->m_pkthdr.len = m->m_len = sizeof(*l2uf); 1681b032f27cSSam Leffler hostap_deliver_data(vap, ni, m); 1682b032f27cSSam Leffler } 1683b032f27cSSam Leffler 1684b032f27cSSam Leffler static void 1685b032f27cSSam Leffler ratesetmismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 1686b032f27cSSam Leffler int reassoc, int resp, const char *tag, int rate) 1687b032f27cSSam Leffler { 1688b032f27cSSam Leffler IEEE80211_NOTE_MAC(ni->ni_vap, IEEE80211_MSG_ANY, wh->i_addr2, 1689b032f27cSSam Leffler "deny %s request, %s rate set mismatch, rate/MCS %d", 1690b032f27cSSam Leffler reassoc ? "reassoc" : "assoc", tag, rate & IEEE80211_RATE_VAL); 1691b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_BASIC_RATE); 1692b032f27cSSam Leffler ieee80211_node_leave(ni); 1693b032f27cSSam Leffler } 1694b032f27cSSam Leffler 1695b032f27cSSam Leffler static void 1696b032f27cSSam Leffler capinfomismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 1697b032f27cSSam Leffler int reassoc, int resp, const char *tag, int capinfo) 1698b032f27cSSam Leffler { 1699b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 1700b032f27cSSam Leffler 1701b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, wh->i_addr2, 1702b032f27cSSam Leffler "deny %s request, %s mismatch 0x%x", 1703b032f27cSSam Leffler reassoc ? "reassoc" : "assoc", tag, capinfo); 1704b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_CAPINFO); 1705b032f27cSSam Leffler ieee80211_node_leave(ni); 1706b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_capmismatch++; 1707b032f27cSSam Leffler } 1708b032f27cSSam Leffler 1709b032f27cSSam Leffler static void 1710b032f27cSSam Leffler htcapmismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 1711b032f27cSSam Leffler int reassoc, int resp) 1712b032f27cSSam Leffler { 1713b032f27cSSam Leffler IEEE80211_NOTE_MAC(ni->ni_vap, IEEE80211_MSG_ANY, wh->i_addr2, 1714b032f27cSSam Leffler "deny %s request, %s missing HT ie", reassoc ? "reassoc" : "assoc"); 1715b032f27cSSam Leffler /* XXX no better code */ 1716b8ee2a22SSam Leffler IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_MISSING_HT_CAPS); 1717b032f27cSSam Leffler ieee80211_node_leave(ni); 1718b032f27cSSam Leffler } 1719b032f27cSSam Leffler 1720b032f27cSSam Leffler static void 1721b032f27cSSam Leffler authalgreject(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 1722b032f27cSSam Leffler int algo, int seq, int status) 1723b032f27cSSam Leffler { 1724b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 1725b032f27cSSam Leffler 1726b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 1727b032f27cSSam Leffler wh, NULL, "unsupported alg %d", algo); 1728b032f27cSSam Leffler vap->iv_stats.is_rx_auth_unsupported++; 1729b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, IEEE80211_FC0_SUBTYPE_AUTH, 1730b032f27cSSam Leffler seq | (status << 16)); 1731b032f27cSSam Leffler } 1732b032f27cSSam Leffler 1733b032f27cSSam Leffler static __inline int 1734b032f27cSSam Leffler ishtmixed(const uint8_t *ie) 1735b032f27cSSam Leffler { 1736b032f27cSSam Leffler const struct ieee80211_ie_htinfo *ht = 1737b032f27cSSam Leffler (const struct ieee80211_ie_htinfo *) ie; 1738b032f27cSSam Leffler return (ht->hi_byte2 & IEEE80211_HTINFO_OPMODE) == 1739b032f27cSSam Leffler IEEE80211_HTINFO_OPMODE_MIXED; 1740b032f27cSSam Leffler } 1741b032f27cSSam Leffler 1742b032f27cSSam Leffler static int 1743b032f27cSSam Leffler is11bclient(const uint8_t *rates, const uint8_t *xrates) 1744b032f27cSSam Leffler { 1745b032f27cSSam Leffler static const uint32_t brates = (1<<2*1)|(1<<2*2)|(1<<11)|(1<<2*11); 1746b032f27cSSam Leffler int i; 1747b032f27cSSam Leffler 1748b032f27cSSam Leffler /* NB: the 11b clients we care about will not have xrates */ 1749b032f27cSSam Leffler if (xrates != NULL || rates == NULL) 1750b032f27cSSam Leffler return 0; 1751b032f27cSSam Leffler for (i = 0; i < rates[1]; i++) { 1752b032f27cSSam Leffler int r = rates[2+i] & IEEE80211_RATE_VAL; 1753b032f27cSSam Leffler if (r > 2*11 || ((1<<r) & brates) == 0) 1754b032f27cSSam Leffler return 0; 1755b032f27cSSam Leffler } 1756b032f27cSSam Leffler return 1; 1757b032f27cSSam Leffler } 1758b032f27cSSam Leffler 1759b032f27cSSam Leffler static void 1760b032f27cSSam Leffler hostap_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, 1761c79f192cSAdrian Chadd int subtype, const struct ieee80211_rx_stats *rxs, int rssi, int nf) 1762b032f27cSSam Leffler { 1763b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 1764b032f27cSSam Leffler struct ieee80211com *ic = ni->ni_ic; 1765b032f27cSSam Leffler struct ieee80211_frame *wh; 1766b032f27cSSam Leffler uint8_t *frm, *efrm, *sfrm; 1767b032f27cSSam Leffler uint8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath, *htcap; 176851172f62SAdrian Chadd uint8_t *vhtcap, *vhtinfo; 1769b032f27cSSam Leffler int reassoc, resp; 1770b032f27cSSam Leffler uint8_t rate; 1771b032f27cSSam Leffler 1772b032f27cSSam Leffler wh = mtod(m0, struct ieee80211_frame *); 1773b032f27cSSam Leffler frm = (uint8_t *)&wh[1]; 1774b032f27cSSam Leffler efrm = mtod(m0, uint8_t *) + m0->m_len; 1775b032f27cSSam Leffler switch (subtype) { 1776b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 1777b032f27cSSam Leffler /* 1778b032f27cSSam Leffler * We process beacon/probe response frames when scanning; 1779b032f27cSSam Leffler * otherwise we check beacon frames for overlapping non-ERP 1780b032f27cSSam Leffler * BSS in 11g and/or overlapping legacy BSS when in HT. 1781b032f27cSSam Leffler */ 17824ba33fd1SAndriy Voskoboinyk if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) { 1783b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; 1784b032f27cSSam Leffler return; 1785b032f27cSSam Leffler } 17864ba33fd1SAndriy Voskoboinyk /* FALLTHROUGH */ 17874ba33fd1SAndriy Voskoboinyk case IEEE80211_FC0_SUBTYPE_BEACON: { 17884ba33fd1SAndriy Voskoboinyk struct ieee80211_scanparams scan; 17894ba33fd1SAndriy Voskoboinyk 1790b032f27cSSam Leffler /* NB: accept off-channel frames */ 1791c79f192cSAdrian Chadd /* XXX TODO: use rxstatus to determine off-channel details */ 1792c79f192cSAdrian Chadd if (ieee80211_parse_beacon(ni, m0, ic->ic_curchan, &scan) &~ IEEE80211_BPARSE_OFFCHAN) 1793b032f27cSSam Leffler return; 1794b032f27cSSam Leffler /* 1795b032f27cSSam Leffler * Count frame now that we know it's to be processed. 1796b032f27cSSam Leffler */ 1797b032f27cSSam Leffler if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) { 1798b032f27cSSam Leffler vap->iv_stats.is_rx_beacon++; /* XXX remove */ 1799b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_beacons); 1800b032f27cSSam Leffler } else 1801b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_proberesp); 1802b032f27cSSam Leffler /* 1803b032f27cSSam Leffler * If scanning, just pass information to the scan module. 1804b032f27cSSam Leffler */ 1805b032f27cSSam Leffler if (ic->ic_flags & IEEE80211_F_SCAN) { 1806b032f27cSSam Leffler if (scan.status == 0 && /* NB: on channel */ 1807b032f27cSSam Leffler (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN)) { 1808b032f27cSSam Leffler /* 1809b032f27cSSam Leffler * Actively scanning a channel marked passive; 1810b032f27cSSam Leffler * send a probe request now that we know there 1811b032f27cSSam Leffler * is 802.11 traffic present. 1812b032f27cSSam Leffler * 1813b032f27cSSam Leffler * XXX check if the beacon we recv'd gives 1814b032f27cSSam Leffler * us what we need and suppress the probe req 1815b032f27cSSam Leffler */ 1816b032f27cSSam Leffler ieee80211_probe_curchan(vap, 1); 1817b032f27cSSam Leffler ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN; 1818b032f27cSSam Leffler } 18192808a02bSAdrian Chadd ieee80211_add_scan(vap, ic->ic_curchan, &scan, wh, 18202808a02bSAdrian Chadd subtype, rssi, nf); 1821b032f27cSSam Leffler return; 1822b032f27cSSam Leffler } 1823b032f27cSSam Leffler /* 1824b032f27cSSam Leffler * Check beacon for overlapping bss w/ non ERP stations. 1825b032f27cSSam Leffler * If we detect one and protection is configured but not 1826b032f27cSSam Leffler * enabled, enable it and start a timer that'll bring us 1827b032f27cSSam Leffler * out if we stop seeing the bss. 1828b032f27cSSam Leffler */ 1829b032f27cSSam Leffler if (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) && 1830b032f27cSSam Leffler scan.status == 0 && /* NB: on-channel */ 1831b032f27cSSam Leffler ((scan.erp & 0x100) == 0 || /* NB: no ERP, 11b sta*/ 1832b032f27cSSam Leffler (scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) { 1833f1481c8dSAdrian Chadd vap->iv_lastnonerp = ticks; 1834f1481c8dSAdrian Chadd vap->iv_flags_ext |= IEEE80211_FEXT_NONERP_PR; 1835f1481c8dSAdrian Chadd /* 1836f1481c8dSAdrian Chadd * XXX TODO: this may need to check all VAPs? 1837f1481c8dSAdrian Chadd */ 1838f1481c8dSAdrian Chadd if (vap->iv_protmode != IEEE80211_PROT_NONE && 1839f1481c8dSAdrian Chadd (vap->iv_flags & IEEE80211_F_USEPROT) == 0) { 1840b032f27cSSam Leffler IEEE80211_NOTE_FRAME(vap, 1841b032f27cSSam Leffler IEEE80211_MSG_ASSOC, wh, 1842b032f27cSSam Leffler "non-ERP present on channel %d " 1843b032f27cSSam Leffler "(saw erp 0x%x from channel %d), " 1844b032f27cSSam Leffler "enable use of protection", 1845b032f27cSSam Leffler ic->ic_curchan->ic_ieee, 1846b032f27cSSam Leffler scan.erp, scan.chan); 1847f1481c8dSAdrian Chadd vap->iv_flags |= IEEE80211_F_USEPROT; 1848f1481c8dSAdrian Chadd ieee80211_vap_update_erp_protmode(vap); 1849b032f27cSSam Leffler } 1850b032f27cSSam Leffler } 1851b032f27cSSam Leffler /* 1852b032f27cSSam Leffler * Check beacon for non-HT station on HT channel 1853b032f27cSSam Leffler * and update HT BSS occupancy as appropriate. 1854b032f27cSSam Leffler */ 1855b032f27cSSam Leffler if (IEEE80211_IS_CHAN_HT(ic->ic_curchan)) { 1856b032f27cSSam Leffler if (scan.status & IEEE80211_BPARSE_OFFCHAN) { 1857b032f27cSSam Leffler /* 1858b032f27cSSam Leffler * Off control channel; only check frames 1859b032f27cSSam Leffler * that come in the extension channel when 1860b032f27cSSam Leffler * operating w/ HT40. 1861b032f27cSSam Leffler */ 1862b032f27cSSam Leffler if (!IEEE80211_IS_CHAN_HT40(ic->ic_curchan)) 1863b032f27cSSam Leffler break; 1864b032f27cSSam Leffler if (scan.chan != ic->ic_curchan->ic_extieee) 1865b032f27cSSam Leffler break; 1866b032f27cSSam Leffler } 1867b032f27cSSam Leffler if (scan.htinfo == NULL) { 1868f1481c8dSAdrian Chadd ieee80211_htprot_update(vap, 1869b032f27cSSam Leffler IEEE80211_HTINFO_OPMODE_PROTOPT | 1870b032f27cSSam Leffler IEEE80211_HTINFO_NONHT_PRESENT); 1871b032f27cSSam Leffler } else if (ishtmixed(scan.htinfo)) { 1872b032f27cSSam Leffler /* XXX? take NONHT_PRESENT from beacon? */ 1873f1481c8dSAdrian Chadd ieee80211_htprot_update(vap, 1874b032f27cSSam Leffler IEEE80211_HTINFO_OPMODE_MIXED | 1875b032f27cSSam Leffler IEEE80211_HTINFO_NONHT_PRESENT); 1876b032f27cSSam Leffler } 1877b032f27cSSam Leffler } 1878b032f27cSSam Leffler break; 1879b032f27cSSam Leffler } 1880b032f27cSSam Leffler 1881b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 1882b032f27cSSam Leffler if (vap->iv_state != IEEE80211_S_RUN) { 1883b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; 1884b032f27cSSam Leffler return; 1885b032f27cSSam Leffler } 1886b032f27cSSam Leffler /* 1887957458a8SAdrian Chadd * Consult the ACL policy module if setup. 1888957458a8SAdrian Chadd */ 18895a8801b0SBernhard Schmidt if (vap->iv_acl != NULL && !vap->iv_acl->iac_check(vap, wh)) { 1890957458a8SAdrian Chadd IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL, 1891957458a8SAdrian Chadd wh, NULL, "%s", "disallowed by ACL"); 1892957458a8SAdrian Chadd vap->iv_stats.is_rx_acl++; 1893957458a8SAdrian Chadd return; 1894957458a8SAdrian Chadd } 1895957458a8SAdrian Chadd /* 1896b032f27cSSam Leffler * prreq frame format 1897b032f27cSSam Leffler * [tlv] ssid 1898b032f27cSSam Leffler * [tlv] supported rates 1899b032f27cSSam Leffler * [tlv] extended supported rates 1900b032f27cSSam Leffler */ 1901b032f27cSSam Leffler ssid = rates = xrates = NULL; 1902b032f27cSSam Leffler while (efrm - frm > 1) { 1903b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return); 1904b032f27cSSam Leffler switch (*frm) { 1905b032f27cSSam Leffler case IEEE80211_ELEMID_SSID: 1906b032f27cSSam Leffler ssid = frm; 1907b032f27cSSam Leffler break; 1908b032f27cSSam Leffler case IEEE80211_ELEMID_RATES: 1909b032f27cSSam Leffler rates = frm; 1910b032f27cSSam Leffler break; 1911b032f27cSSam Leffler case IEEE80211_ELEMID_XRATES: 1912b032f27cSSam Leffler xrates = frm; 1913b032f27cSSam Leffler break; 1914b032f27cSSam Leffler } 1915b032f27cSSam Leffler frm += frm[1] + 2; 1916b032f27cSSam Leffler } 1917b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return); 1918b032f27cSSam Leffler if (xrates != NULL) 1919b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(xrates, 1920b032f27cSSam Leffler IEEE80211_RATE_MAXSIZE - rates[1], return); 1921b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return); 1922b032f27cSSam Leffler IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return); 1923b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_HIDESSID) && ssid[1] == 0) { 1924b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 1925b032f27cSSam Leffler wh, NULL, 1926b032f27cSSam Leffler "%s", "no ssid with ssid suppression enabled"); 1927b032f27cSSam Leffler vap->iv_stats.is_rx_ssidmismatch++; /*XXX*/ 1928b032f27cSSam Leffler return; 1929b032f27cSSam Leffler } 1930b032f27cSSam Leffler 1931b032f27cSSam Leffler /* XXX find a better class or define it's own */ 1932b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2, 1933b032f27cSSam Leffler "%s", "recv probe req"); 1934b032f27cSSam Leffler /* 1935b032f27cSSam Leffler * Some legacy 11b clients cannot hack a complete 1936b032f27cSSam Leffler * probe response frame. When the request includes 1937b032f27cSSam Leffler * only a bare-bones rate set, communicate this to 1938b032f27cSSam Leffler * the transmit side. 1939b032f27cSSam Leffler */ 1940b032f27cSSam Leffler ieee80211_send_proberesp(vap, wh->i_addr2, 1941b032f27cSSam Leffler is11bclient(rates, xrates) ? IEEE80211_SEND_LEGACY_11B : 0); 1942b032f27cSSam Leffler break; 1943b032f27cSSam Leffler 1944b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_AUTH: { 1945b032f27cSSam Leffler uint16_t algo, seq, status; 1946b032f27cSSam Leffler 1947b032f27cSSam Leffler if (vap->iv_state != IEEE80211_S_RUN) { 1948b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; 1949b032f27cSSam Leffler return; 1950b032f27cSSam Leffler } 1951b032f27cSSam Leffler if (!IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_bss->ni_bssid)) { 1952b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 1953b032f27cSSam Leffler wh, NULL, "%s", "wrong bssid"); 1954b032f27cSSam Leffler vap->iv_stats.is_rx_wrongbss++; /*XXX unique stat?*/ 1955b032f27cSSam Leffler return; 1956b032f27cSSam Leffler } 1957b032f27cSSam Leffler /* 1958b032f27cSSam Leffler * auth frame format 1959b032f27cSSam Leffler * [2] algorithm 1960b032f27cSSam Leffler * [2] sequence 1961b032f27cSSam Leffler * [2] status 1962b032f27cSSam Leffler * [tlv*] challenge 1963b032f27cSSam Leffler */ 1964b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, 6, return); 1965b032f27cSSam Leffler algo = le16toh(*(uint16_t *)frm); 1966b032f27cSSam Leffler seq = le16toh(*(uint16_t *)(frm + 2)); 1967b032f27cSSam Leffler status = le16toh(*(uint16_t *)(frm + 4)); 1968b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_AUTH, wh->i_addr2, 1969b032f27cSSam Leffler "recv auth frame with algorithm %d seq %d", algo, seq); 1970b032f27cSSam Leffler /* 1971b032f27cSSam Leffler * Consult the ACL policy module if setup. 1972b032f27cSSam Leffler */ 19735a8801b0SBernhard Schmidt if (vap->iv_acl != NULL && !vap->iv_acl->iac_check(vap, wh)) { 1974b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL, 1975b032f27cSSam Leffler wh, NULL, "%s", "disallowed by ACL"); 1976b032f27cSSam Leffler vap->iv_stats.is_rx_acl++; 1977b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, 1978b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_AUTH, 1979b032f27cSSam Leffler (seq+1) | (IEEE80211_STATUS_UNSPECIFIED<<16)); 1980b032f27cSSam Leffler return; 1981b032f27cSSam Leffler } 1982b032f27cSSam Leffler if (vap->iv_flags & IEEE80211_F_COUNTERM) { 1983b032f27cSSam Leffler IEEE80211_DISCARD(vap, 1984b032f27cSSam Leffler IEEE80211_MSG_AUTH | IEEE80211_MSG_CRYPTO, 1985b032f27cSSam Leffler wh, NULL, "%s", "TKIP countermeasures enabled"); 1986b032f27cSSam Leffler vap->iv_stats.is_rx_auth_countermeasures++; 1987b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, 1988b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_AUTH, 1989b032f27cSSam Leffler IEEE80211_REASON_MIC_FAILURE); 1990b032f27cSSam Leffler return; 1991b032f27cSSam Leffler } 1992b032f27cSSam Leffler if (algo == IEEE80211_AUTH_ALG_SHARED) 19935463c4a4SSam Leffler hostap_auth_shared(ni, wh, frm + 6, efrm, rssi, nf, 1994b032f27cSSam Leffler seq, status); 19955463c4a4SSam Leffler else if (algo == IEEE80211_AUTH_ALG_OPEN) 19965463c4a4SSam Leffler hostap_auth_open(ni, wh, rssi, nf, seq, status); 1997b032f27cSSam Leffler else if (algo == IEEE80211_AUTH_ALG_LEAP) { 1998b032f27cSSam Leffler authalgreject(ni, wh, algo, 1999b032f27cSSam Leffler seq+1, IEEE80211_STATUS_ALG); 2000b032f27cSSam Leffler return; 2001b032f27cSSam Leffler } else { 2002b032f27cSSam Leffler /* 2003b032f27cSSam Leffler * We assume that an unknown algorithm is the result 2004b032f27cSSam Leffler * of a decryption failure on a shared key auth frame; 2005b032f27cSSam Leffler * return a status code appropriate for that instead 2006b032f27cSSam Leffler * of IEEE80211_STATUS_ALG. 2007b032f27cSSam Leffler * 2008b032f27cSSam Leffler * NB: a seq# of 4 is intentional; the decrypted 2009b032f27cSSam Leffler * frame likely has a bogus seq value. 2010b032f27cSSam Leffler */ 2011b032f27cSSam Leffler authalgreject(ni, wh, algo, 2012b032f27cSSam Leffler 4, IEEE80211_STATUS_CHALLENGE); 2013b032f27cSSam Leffler return; 2014b032f27cSSam Leffler } 2015b032f27cSSam Leffler break; 2016b032f27cSSam Leffler } 2017b032f27cSSam Leffler 2018b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 2019b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: { 2020b032f27cSSam Leffler uint16_t capinfo, lintval; 2021b032f27cSSam Leffler struct ieee80211_rsnparms rsnparms; 2022b032f27cSSam Leffler 2023b032f27cSSam Leffler if (vap->iv_state != IEEE80211_S_RUN) { 2024b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; 2025b032f27cSSam Leffler return; 2026b032f27cSSam Leffler } 2027b032f27cSSam Leffler if (!IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_bss->ni_bssid)) { 2028b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 2029b032f27cSSam Leffler wh, NULL, "%s", "wrong bssid"); 2030b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_bss++; 2031b032f27cSSam Leffler return; 2032b032f27cSSam Leffler } 2033b032f27cSSam Leffler if (subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) { 2034b032f27cSSam Leffler reassoc = 1; 2035b032f27cSSam Leffler resp = IEEE80211_FC0_SUBTYPE_REASSOC_RESP; 2036b032f27cSSam Leffler } else { 2037b032f27cSSam Leffler reassoc = 0; 2038b032f27cSSam Leffler resp = IEEE80211_FC0_SUBTYPE_ASSOC_RESP; 2039b032f27cSSam Leffler } 2040b032f27cSSam Leffler if (ni == vap->iv_bss) { 2041b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, wh->i_addr2, 2042b032f27cSSam Leffler "deny %s request, sta not authenticated", 2043b032f27cSSam Leffler reassoc ? "reassoc" : "assoc"); 2044b032f27cSSam Leffler ieee80211_send_error(ni, wh->i_addr2, 2045b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_DEAUTH, 2046b032f27cSSam Leffler IEEE80211_REASON_ASSOC_NOT_AUTHED); 2047b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_notauth++; 2048b032f27cSSam Leffler return; 2049b032f27cSSam Leffler } 2050b032f27cSSam Leffler 2051b032f27cSSam Leffler /* 2052b032f27cSSam Leffler * asreq frame format 2053b032f27cSSam Leffler * [2] capability information 2054b032f27cSSam Leffler * [2] listen interval 2055b032f27cSSam Leffler * [6*] current AP address (reassoc only) 2056b032f27cSSam Leffler * [tlv] ssid 2057b032f27cSSam Leffler * [tlv] supported rates 2058b032f27cSSam Leffler * [tlv] extended supported rates 2059b032f27cSSam Leffler * [tlv] WPA or RSN 2060b032f27cSSam Leffler * [tlv] HT capabilities 2061b032f27cSSam Leffler * [tlv] Atheros capabilities 2062b032f27cSSam Leffler */ 2063b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, (reassoc ? 10 : 4), return); 2064b032f27cSSam Leffler capinfo = le16toh(*(uint16_t *)frm); frm += 2; 2065b032f27cSSam Leffler lintval = le16toh(*(uint16_t *)frm); frm += 2; 2066b032f27cSSam Leffler if (reassoc) 2067b032f27cSSam Leffler frm += 6; /* ignore current AP info */ 2068b032f27cSSam Leffler ssid = rates = xrates = wpa = rsn = wme = ath = htcap = NULL; 206951172f62SAdrian Chadd vhtcap = vhtinfo = NULL; 2070b032f27cSSam Leffler sfrm = frm; 2071b032f27cSSam Leffler while (efrm - frm > 1) { 2072b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return); 2073b032f27cSSam Leffler switch (*frm) { 2074b032f27cSSam Leffler case IEEE80211_ELEMID_SSID: 2075b032f27cSSam Leffler ssid = frm; 2076b032f27cSSam Leffler break; 2077b032f27cSSam Leffler case IEEE80211_ELEMID_RATES: 2078b032f27cSSam Leffler rates = frm; 2079b032f27cSSam Leffler break; 2080b032f27cSSam Leffler case IEEE80211_ELEMID_XRATES: 2081b032f27cSSam Leffler xrates = frm; 2082b032f27cSSam Leffler break; 2083b032f27cSSam Leffler case IEEE80211_ELEMID_RSN: 2084b032f27cSSam Leffler rsn = frm; 2085b032f27cSSam Leffler break; 2086b032f27cSSam Leffler case IEEE80211_ELEMID_HTCAP: 2087b032f27cSSam Leffler htcap = frm; 2088b032f27cSSam Leffler break; 208951172f62SAdrian Chadd case IEEE80211_ELEMID_VHT_CAP: 209051172f62SAdrian Chadd vhtcap = frm; 209151172f62SAdrian Chadd break; 209251172f62SAdrian Chadd case IEEE80211_ELEMID_VHT_OPMODE: 209351172f62SAdrian Chadd vhtinfo = frm; 209451172f62SAdrian Chadd break; 2095b032f27cSSam Leffler case IEEE80211_ELEMID_VENDOR: 2096b032f27cSSam Leffler if (iswpaoui(frm)) 2097b032f27cSSam Leffler wpa = frm; 2098b032f27cSSam Leffler else if (iswmeinfo(frm)) 2099b032f27cSSam Leffler wme = frm; 2100616190d0SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG 2101b032f27cSSam Leffler else if (isatherosoui(frm)) 2102b032f27cSSam Leffler ath = frm; 2103616190d0SSam Leffler #endif 21042bfc8a91SSam Leffler else if (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) { 2105b032f27cSSam Leffler if (ishtcapoui(frm) && htcap == NULL) 2106b032f27cSSam Leffler htcap = frm; 2107b032f27cSSam Leffler } 2108b032f27cSSam Leffler break; 2109b032f27cSSam Leffler } 2110b032f27cSSam Leffler frm += frm[1] + 2; 2111b032f27cSSam Leffler } 2112b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return); 2113b032f27cSSam Leffler if (xrates != NULL) 2114b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(xrates, 2115b032f27cSSam Leffler IEEE80211_RATE_MAXSIZE - rates[1], return); 2116b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return); 2117b032f27cSSam Leffler IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return); 2118b032f27cSSam Leffler if (htcap != NULL) { 2119b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(htcap[1], 2120b032f27cSSam Leffler htcap[0] == IEEE80211_ELEMID_VENDOR ? 2121b032f27cSSam Leffler 4 + sizeof(struct ieee80211_ie_htcap)-2 : 2122b032f27cSSam Leffler sizeof(struct ieee80211_ie_htcap)-2, 2123b032f27cSSam Leffler return); /* XXX just NULL out? */ 2124b032f27cSSam Leffler } 2125b032f27cSSam Leffler 212646788bb1SAdrian Chadd /* Validate VHT IEs */ 212746788bb1SAdrian Chadd if (vhtcap != NULL) { 212846788bb1SAdrian Chadd IEEE80211_VERIFY_LENGTH(vhtcap[1], 212946788bb1SAdrian Chadd sizeof(struct ieee80211_ie_vhtcap) - 2, 213046788bb1SAdrian Chadd return); 213146788bb1SAdrian Chadd } 213246788bb1SAdrian Chadd if (vhtinfo != NULL) { 213346788bb1SAdrian Chadd IEEE80211_VERIFY_LENGTH(vhtinfo[1], 213446788bb1SAdrian Chadd sizeof(struct ieee80211_ie_vht_operation) - 2, 213546788bb1SAdrian Chadd return); 213646788bb1SAdrian Chadd } 21377f19273cSAdrian Chadd 2138b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_WPA) && 2139b032f27cSSam Leffler !wpa_assocreq(ni, &rsnparms, wh, wpa, rsn, capinfo)) 2140b032f27cSSam Leffler return; 2141b032f27cSSam Leffler /* discard challenge after association */ 2142b032f27cSSam Leffler if (ni->ni_challenge != NULL) { 2143b9b53389SAdrian Chadd IEEE80211_FREE(ni->ni_challenge, M_80211_NODE); 2144b032f27cSSam Leffler ni->ni_challenge = NULL; 2145b032f27cSSam Leffler } 2146b032f27cSSam Leffler /* NB: 802.11 spec says to ignore station's privacy bit */ 2147b032f27cSSam Leffler if ((capinfo & IEEE80211_CAPINFO_ESS) == 0) { 2148b032f27cSSam Leffler capinfomismatch(ni, wh, reassoc, resp, 2149b032f27cSSam Leffler "capability", capinfo); 2150b032f27cSSam Leffler return; 2151b032f27cSSam Leffler } 2152b032f27cSSam Leffler /* 2153b032f27cSSam Leffler * Disallow re-associate w/ invalid slot time setting. 2154b032f27cSSam Leffler */ 2155b032f27cSSam Leffler if (ni->ni_associd != 0 && 2156b032f27cSSam Leffler IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) && 2157b032f27cSSam Leffler ((ni->ni_capinfo ^ capinfo) & IEEE80211_CAPINFO_SHORT_SLOTTIME)) { 2158b032f27cSSam Leffler capinfomismatch(ni, wh, reassoc, resp, 2159b032f27cSSam Leffler "slot time", capinfo); 2160b032f27cSSam Leffler return; 2161b032f27cSSam Leffler } 2162b032f27cSSam Leffler rate = ieee80211_setup_rates(ni, rates, xrates, 2163b032f27cSSam Leffler IEEE80211_F_DOSORT | IEEE80211_F_DOFRATE | 2164b032f27cSSam Leffler IEEE80211_F_DONEGO | IEEE80211_F_DODEL); 2165b032f27cSSam Leffler if (rate & IEEE80211_RATE_BASIC) { 2166b032f27cSSam Leffler ratesetmismatch(ni, wh, reassoc, resp, "legacy", rate); 2167b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_norate++; 2168b032f27cSSam Leffler return; 2169b032f27cSSam Leffler } 2170b032f27cSSam Leffler /* 2171b032f27cSSam Leffler * If constrained to 11g-only stations reject an 2172b032f27cSSam Leffler * 11b-only station. We cheat a bit here by looking 2173b032f27cSSam Leffler * at the max negotiated xmit rate and assuming anyone 2174b032f27cSSam Leffler * with a best rate <24Mb/s is an 11b station. 2175b032f27cSSam Leffler */ 2176b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_PUREG) && rate < 48) { 2177b032f27cSSam Leffler ratesetmismatch(ni, wh, reassoc, resp, "11g", rate); 2178b032f27cSSam Leffler vap->iv_stats.is_rx_assoc_norate++; 2179b032f27cSSam Leffler return; 2180b032f27cSSam Leffler } 218151172f62SAdrian Chadd 2182b032f27cSSam Leffler /* 2183b032f27cSSam Leffler * Do HT rate set handling and setup HT node state. 2184b032f27cSSam Leffler */ 2185b032f27cSSam Leffler ni->ni_chan = vap->iv_bss->ni_chan; 218651172f62SAdrian Chadd 218751172f62SAdrian Chadd /* VHT */ 218820235662SAdrian Chadd if (IEEE80211_IS_CHAN_VHT(ni->ni_chan) && 21897f19273cSAdrian Chadd vhtcap != NULL && 219020235662SAdrian Chadd vhtinfo != NULL) { 219151172f62SAdrian Chadd /* XXX TODO; see below */ 219251172f62SAdrian Chadd printf("%s: VHT TODO!\n", __func__); 219351172f62SAdrian Chadd ieee80211_vht_node_init(ni); 219451172f62SAdrian Chadd ieee80211_vht_update_cap(ni, vhtcap, vhtinfo); 219551172f62SAdrian Chadd } else if (ni->ni_flags & IEEE80211_NODE_VHT) 219651172f62SAdrian Chadd ieee80211_vht_node_cleanup(ni); 219751172f62SAdrian Chadd 219851172f62SAdrian Chadd /* HT */ 2199b032f27cSSam Leffler if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) { 2200b032f27cSSam Leffler rate = ieee80211_setup_htrates(ni, htcap, 2201b032f27cSSam Leffler IEEE80211_F_DOFMCS | IEEE80211_F_DONEGO | 2202b032f27cSSam Leffler IEEE80211_F_DOBRS); 2203b032f27cSSam Leffler if (rate & IEEE80211_RATE_BASIC) { 2204b032f27cSSam Leffler ratesetmismatch(ni, wh, reassoc, resp, 2205b032f27cSSam Leffler "HT", rate); 2206b032f27cSSam Leffler vap->iv_stats.is_ht_assoc_norate++; 2207b032f27cSSam Leffler return; 2208b032f27cSSam Leffler } 2209fdabd982SSam Leffler ieee80211_ht_node_init(ni); 2210fdabd982SSam Leffler ieee80211_ht_updatehtcap(ni, htcap); 2211b032f27cSSam Leffler } else if (ni->ni_flags & IEEE80211_NODE_HT) 2212b032f27cSSam Leffler ieee80211_ht_node_cleanup(ni); 221351172f62SAdrian Chadd 221451172f62SAdrian Chadd /* Finally - this will use HT/VHT info to change node channel */ 221551172f62SAdrian Chadd if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) { 221651172f62SAdrian Chadd ieee80211_ht_updatehtcap_final(ni); 221751172f62SAdrian Chadd } 221851172f62SAdrian Chadd 2219339ccfb3SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG 22200e6cbef2SAdrian Chadd /* Always do ff node cleanup; for A-MSDU */ 2221339ccfb3SSam Leffler ieee80211_ff_node_cleanup(ni); 2222339ccfb3SSam Leffler #endif 2223b032f27cSSam Leffler /* 2224b032f27cSSam Leffler * Allow AMPDU operation only with unencrypted traffic 2225b032f27cSSam Leffler * or AES-CCM; the 11n spec only specifies these ciphers 2226b032f27cSSam Leffler * so permitting any others is undefined and can lead 2227b032f27cSSam Leffler * to interoperability problems. 2228b032f27cSSam Leffler */ 2229b032f27cSSam Leffler if ((ni->ni_flags & IEEE80211_NODE_HT) && 2230b032f27cSSam Leffler (((vap->iv_flags & IEEE80211_F_WPA) && 2231b032f27cSSam Leffler rsnparms.rsn_ucastcipher != IEEE80211_CIPHER_AES_CCM) || 2232b032f27cSSam Leffler (vap->iv_flags & (IEEE80211_F_WPA|IEEE80211_F_PRIVACY)) == IEEE80211_F_PRIVACY)) { 2233b032f27cSSam Leffler IEEE80211_NOTE(vap, 2234b032f27cSSam Leffler IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni, 2235b032f27cSSam Leffler "disallow HT use because WEP or TKIP requested, " 2236b032f27cSSam Leffler "capinfo 0x%x ucastcipher %d", capinfo, 2237b032f27cSSam Leffler rsnparms.rsn_ucastcipher); 2238b032f27cSSam Leffler ieee80211_ht_node_cleanup(ni); 22390e6cbef2SAdrian Chadd #ifdef IEEE80211_SUPPORT_SUPERG 22400e6cbef2SAdrian Chadd /* Always do ff node cleanup; for A-MSDU */ 22410e6cbef2SAdrian Chadd ieee80211_ff_node_cleanup(ni); 22420e6cbef2SAdrian Chadd #endif 2243b032f27cSSam Leffler vap->iv_stats.is_ht_assoc_downgrade++; 2244b032f27cSSam Leffler } 2245b032f27cSSam Leffler /* 2246b032f27cSSam Leffler * If constrained to 11n-only stations reject legacy stations. 2247b032f27cSSam Leffler */ 22482bfc8a91SSam Leffler if ((vap->iv_flags_ht & IEEE80211_FHT_PUREN) && 2249b032f27cSSam Leffler (ni->ni_flags & IEEE80211_NODE_HT) == 0) { 2250b032f27cSSam Leffler htcapmismatch(ni, wh, reassoc, resp); 2251b032f27cSSam Leffler vap->iv_stats.is_ht_assoc_nohtcap++; 2252b032f27cSSam Leffler return; 2253b032f27cSSam Leffler } 2254b032f27cSSam Leffler IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi); 22555463c4a4SSam Leffler ni->ni_noise = nf; 2256b032f27cSSam Leffler ni->ni_intval = lintval; 2257b032f27cSSam Leffler ni->ni_capinfo = capinfo; 2258b032f27cSSam Leffler ni->ni_fhdwell = vap->iv_bss->ni_fhdwell; 2259b032f27cSSam Leffler ni->ni_fhindex = vap->iv_bss->ni_fhindex; 2260b032f27cSSam Leffler /* 2261b032f27cSSam Leffler * Store the IEs. 2262b032f27cSSam Leffler * XXX maybe better to just expand 2263b032f27cSSam Leffler */ 2264b032f27cSSam Leffler if (ieee80211_ies_init(&ni->ni_ies, sfrm, efrm - sfrm)) { 2265b032f27cSSam Leffler #define setie(_ie, _off) ieee80211_ies_setie(ni->ni_ies, _ie, _off) 2266b032f27cSSam Leffler if (wpa != NULL) 2267b032f27cSSam Leffler setie(wpa_ie, wpa - sfrm); 2268b032f27cSSam Leffler if (rsn != NULL) 2269b032f27cSSam Leffler setie(rsn_ie, rsn - sfrm); 2270b032f27cSSam Leffler if (htcap != NULL) 2271b032f27cSSam Leffler setie(htcap_ie, htcap - sfrm); 2272b032f27cSSam Leffler if (wme != NULL) { 2273b032f27cSSam Leffler setie(wme_ie, wme - sfrm); 2274b032f27cSSam Leffler /* 2275b032f27cSSam Leffler * Mark node as capable of QoS. 2276b032f27cSSam Leffler */ 2277b032f27cSSam Leffler ni->ni_flags |= IEEE80211_NODE_QOS; 22788379e8dbSAdrian Chadd if (ieee80211_parse_wmeie(wme, wh, ni) > 0) { 22798379e8dbSAdrian Chadd if (ni->ni_uapsd != 0) 22808379e8dbSAdrian Chadd ni->ni_flags |= 22818379e8dbSAdrian Chadd IEEE80211_NODE_UAPSD; 22828379e8dbSAdrian Chadd else 22838379e8dbSAdrian Chadd ni->ni_flags &= 22848379e8dbSAdrian Chadd ~IEEE80211_NODE_UAPSD; 22858379e8dbSAdrian Chadd } 2286b032f27cSSam Leffler } else 22878379e8dbSAdrian Chadd ni->ni_flags &= 22888379e8dbSAdrian Chadd ~(IEEE80211_NODE_QOS | 22898379e8dbSAdrian Chadd IEEE80211_NODE_UAPSD); 2290616190d0SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG 2291b032f27cSSam Leffler if (ath != NULL) { 2292b032f27cSSam Leffler setie(ath_ie, ath - sfrm); 2293b032f27cSSam Leffler /* 2294b032f27cSSam Leffler * Parse ATH station parameters. 2295b032f27cSSam Leffler */ 2296b032f27cSSam Leffler ieee80211_parse_ath(ni, ni->ni_ies.ath_ie); 2297b032f27cSSam Leffler } else 2298616190d0SSam Leffler #endif 2299b032f27cSSam Leffler ni->ni_ath_flags = 0; 2300b032f27cSSam Leffler #undef setie 2301b032f27cSSam Leffler } else { 2302b032f27cSSam Leffler ni->ni_flags &= ~IEEE80211_NODE_QOS; 23038379e8dbSAdrian Chadd ni->ni_flags &= ~IEEE80211_NODE_UAPSD; 2304b032f27cSSam Leffler ni->ni_ath_flags = 0; 2305b032f27cSSam Leffler } 2306b032f27cSSam Leffler ieee80211_node_join(ni, resp); 2307b032f27cSSam Leffler ieee80211_deliver_l2uf(ni); 2308b032f27cSSam Leffler break; 2309b032f27cSSam Leffler } 2310b032f27cSSam Leffler 2311b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_DEAUTH: 2312b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_DISASSOC: { 231305ea7a3eSBjoern A. Zeeb #ifdef IEEE80211_DEBUG 2314b032f27cSSam Leffler uint16_t reason; 231505ea7a3eSBjoern A. Zeeb #endif 2316b032f27cSSam Leffler 2317b032f27cSSam Leffler if (vap->iv_state != IEEE80211_S_RUN || 2318b032f27cSSam Leffler /* NB: can happen when in promiscuous mode */ 2319b032f27cSSam Leffler !IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr)) { 2320b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; 2321b032f27cSSam Leffler break; 2322b032f27cSSam Leffler } 2323b032f27cSSam Leffler /* 2324b032f27cSSam Leffler * deauth/disassoc frame format 2325b032f27cSSam Leffler * [2] reason 2326b032f27cSSam Leffler */ 2327b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, 2, return); 232805ea7a3eSBjoern A. Zeeb #ifdef IEEE80211_DEBUG 2329b032f27cSSam Leffler reason = le16toh(*(uint16_t *)frm); 233005ea7a3eSBjoern A. Zeeb #endif 2331b032f27cSSam Leffler if (subtype == IEEE80211_FC0_SUBTYPE_DEAUTH) { 2332b032f27cSSam Leffler vap->iv_stats.is_rx_deauth++; 2333b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_deauth); 2334b032f27cSSam Leffler } else { 2335b032f27cSSam Leffler vap->iv_stats.is_rx_disassoc++; 2336b032f27cSSam Leffler IEEE80211_NODE_STAT(ni, rx_disassoc); 2337b032f27cSSam Leffler } 2338b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni, 2339d72d72d3SAndriy Voskoboinyk "recv %s (reason: %d (%s))", 23404357a5d1SAndriy Voskoboinyk ieee80211_mgt_subtype_name(subtype), 2341d72d72d3SAndriy Voskoboinyk reason, ieee80211_reason_to_string(reason)); 2342b032f27cSSam Leffler if (ni != vap->iv_bss) 2343b032f27cSSam Leffler ieee80211_node_leave(ni); 2344b032f27cSSam Leffler break; 2345b032f27cSSam Leffler } 2346b032f27cSSam Leffler 2347b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ACTION: 234896283082SBernhard Schmidt case IEEE80211_FC0_SUBTYPE_ACTION_NOACK: 2349893c4d6eSBernhard Schmidt if (ni == vap->iv_bss) { 2350893c4d6eSBernhard Schmidt IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 2351893c4d6eSBernhard Schmidt wh, NULL, "%s", "unknown node"); 2352893c4d6eSBernhard Schmidt vap->iv_stats.is_rx_mgtdiscard++; 2353893c4d6eSBernhard Schmidt } else if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1) && 2354893c4d6eSBernhard Schmidt !IEEE80211_IS_MULTICAST(wh->i_addr1)) { 2355893c4d6eSBernhard Schmidt IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 2356893c4d6eSBernhard Schmidt wh, NULL, "%s", "not for us"); 2357893c4d6eSBernhard Schmidt vap->iv_stats.is_rx_mgtdiscard++; 2358893c4d6eSBernhard Schmidt } else if (vap->iv_state != IEEE80211_S_RUN) { 235996283082SBernhard Schmidt IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 236096283082SBernhard Schmidt wh, NULL, "wrong state %s", 236196283082SBernhard Schmidt ieee80211_state_name[vap->iv_state]); 2362b032f27cSSam Leffler vap->iv_stats.is_rx_mgtdiscard++; 2363893c4d6eSBernhard Schmidt } else { 2364893c4d6eSBernhard Schmidt if (ieee80211_parse_action(ni, m0) == 0) 2365893c4d6eSBernhard Schmidt (void)ic->ic_recv_action(ni, wh, frm, efrm); 236696283082SBernhard Schmidt } 2367b032f27cSSam Leffler break; 2368b032f27cSSam Leffler 2369b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 2370b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: 2371665d5ae9SAndriy Voskoboinyk case IEEE80211_FC0_SUBTYPE_TIMING_ADV: 237296283082SBernhard Schmidt case IEEE80211_FC0_SUBTYPE_ATIM: 237396283082SBernhard Schmidt IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 237496283082SBernhard Schmidt wh, NULL, "%s", "not handled"); 237596283082SBernhard Schmidt vap->iv_stats.is_rx_mgtdiscard++; 237696283082SBernhard Schmidt break; 237796283082SBernhard Schmidt 2378b032f27cSSam Leffler default: 2379b032f27cSSam Leffler IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 2380b032f27cSSam Leffler wh, "mgt", "subtype 0x%x not handled", subtype); 2381b032f27cSSam Leffler vap->iv_stats.is_rx_badsubtype++; 2382b032f27cSSam Leffler break; 2383b032f27cSSam Leffler } 2384b032f27cSSam Leffler } 2385b032f27cSSam Leffler 238649eae5f7SSam Leffler static void 238749eae5f7SSam Leffler hostap_recv_ctl(struct ieee80211_node *ni, struct mbuf *m, int subtype) 238849eae5f7SSam Leffler { 238949eae5f7SSam Leffler switch (subtype) { 239049eae5f7SSam Leffler case IEEE80211_FC0_SUBTYPE_PS_POLL: 2391e7f0d7cfSAdrian Chadd ni->ni_vap->iv_recv_pspoll(ni, m); 239249eae5f7SSam Leffler break; 239349eae5f7SSam Leffler case IEEE80211_FC0_SUBTYPE_BAR: 239449eae5f7SSam Leffler ieee80211_recv_bar(ni, m); 239549eae5f7SSam Leffler break; 239649eae5f7SSam Leffler } 239749eae5f7SSam Leffler } 239849eae5f7SSam Leffler 2399b032f27cSSam Leffler /* 2400b032f27cSSam Leffler * Process a received ps-poll frame. 2401b032f27cSSam Leffler */ 2402e7f0d7cfSAdrian Chadd void 2403e7f0d7cfSAdrian Chadd ieee80211_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m0) 2404b032f27cSSam Leffler { 2405b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap; 24065cda6006SAdrian Chadd struct ieee80211com *ic = vap->iv_ic; 2407b032f27cSSam Leffler struct ieee80211_frame_min *wh; 2408b032f27cSSam Leffler struct mbuf *m; 2409b032f27cSSam Leffler uint16_t aid; 2410b032f27cSSam Leffler int qlen; 2411b032f27cSSam Leffler 2412b032f27cSSam Leffler wh = mtod(m0, struct ieee80211_frame_min *); 2413b032f27cSSam Leffler if (ni->ni_associd == 0) { 2414b032f27cSSam Leffler IEEE80211_DISCARD(vap, 2415b032f27cSSam Leffler IEEE80211_MSG_POWER | IEEE80211_MSG_DEBUG, 2416b032f27cSSam Leffler (struct ieee80211_frame *) wh, NULL, 2417b032f27cSSam Leffler "%s", "unassociated station"); 2418b032f27cSSam Leffler vap->iv_stats.is_ps_unassoc++; 2419b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH, 2420b032f27cSSam Leffler IEEE80211_REASON_NOT_ASSOCED); 2421b032f27cSSam Leffler return; 2422b032f27cSSam Leffler } 2423b032f27cSSam Leffler 2424b032f27cSSam Leffler aid = le16toh(*(uint16_t *)wh->i_dur); 2425b032f27cSSam Leffler if (aid != ni->ni_associd) { 2426b032f27cSSam Leffler IEEE80211_DISCARD(vap, 2427b032f27cSSam Leffler IEEE80211_MSG_POWER | IEEE80211_MSG_DEBUG, 2428b032f27cSSam Leffler (struct ieee80211_frame *) wh, NULL, 2429b032f27cSSam Leffler "aid mismatch: sta aid 0x%x poll aid 0x%x", 2430b032f27cSSam Leffler ni->ni_associd, aid); 2431b032f27cSSam Leffler vap->iv_stats.is_ps_badaid++; 2432693e3122SSam Leffler /* 2433693e3122SSam Leffler * NB: We used to deauth the station but it turns out 2434693e3122SSam Leffler * the Blackberry Curve 8230 (and perhaps other devices) 2435693e3122SSam Leffler * sometimes send the wrong AID when WME is negotiated. 2436693e3122SSam Leffler * Being more lenient here seems ok as we already check 2437693e3122SSam Leffler * the station is associated and we only return frames 2438693e3122SSam Leffler * queued for the station (i.e. we don't use the AID). 2439693e3122SSam Leffler */ 2440b032f27cSSam Leffler return; 2441b032f27cSSam Leffler } 2442b032f27cSSam Leffler 2443b032f27cSSam Leffler /* Okay, take the first queued packet and put it out... */ 244463092fceSSam Leffler m = ieee80211_node_psq_dequeue(ni, &qlen); 2445b032f27cSSam Leffler if (m == NULL) { 2446b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_POWER, wh->i_addr2, 2447b032f27cSSam Leffler "%s", "recv ps-poll, but queue empty"); 2448b032f27cSSam Leffler ieee80211_send_nulldata(ieee80211_ref_node(ni)); 2449b032f27cSSam Leffler vap->iv_stats.is_ps_qempty++; /* XXX node stat */ 2450b032f27cSSam Leffler if (vap->iv_set_tim != NULL) 2451b032f27cSSam Leffler vap->iv_set_tim(ni, 0); /* just in case */ 2452b032f27cSSam Leffler return; 2453b032f27cSSam Leffler } 2454b032f27cSSam Leffler /* 2455b032f27cSSam Leffler * If there are more packets, set the more packets bit 2456b032f27cSSam Leffler * in the packet dispatched to the station; otherwise 2457b032f27cSSam Leffler * turn off the TIM bit. 2458b032f27cSSam Leffler */ 2459b032f27cSSam Leffler if (qlen != 0) { 2460b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, 2461b032f27cSSam Leffler "recv ps-poll, send packet, %u still queued", qlen); 2462b032f27cSSam Leffler m->m_flags |= M_MORE_DATA; 2463b032f27cSSam Leffler } else { 2464b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni, 2465b032f27cSSam Leffler "%s", "recv ps-poll, send packet, queue empty"); 2466b032f27cSSam Leffler if (vap->iv_set_tim != NULL) 2467b032f27cSSam Leffler vap->iv_set_tim(ni, 0); 2468b032f27cSSam Leffler } 2469b032f27cSSam Leffler m->m_flags |= M_PWR_SAV; /* bypass PS handling */ 247063092fceSSam Leffler 24717ea3aadaSAdrian Chadd /* 24725cda6006SAdrian Chadd * Do the right thing; if it's an encap'ed frame then 2473d3a4ade3SAdrian Chadd * call ieee80211_parent_xmitpkt() else 2474e7495198SAdrian Chadd * call ieee80211_vap_xmitpkt(). 24757ea3aadaSAdrian Chadd */ 24765cda6006SAdrian Chadd if (m->m_flags & M_ENCAP) { 2477d3a4ade3SAdrian Chadd (void) ieee80211_parent_xmitpkt(ic, m); 24785cda6006SAdrian Chadd } else { 2479e7495198SAdrian Chadd (void) ieee80211_vap_xmitpkt(vap, m); 24807ea3aadaSAdrian Chadd } 2481b032f27cSSam Leffler } 2482