2 * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 * IEEE 802.11 HOSTAP mode support.
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/kernel.h>
43 #include <sys/socket.h>
44 #include <sys/sockio.h>
45 #include <sys/endian.h>
46 #include <sys/errno.h>
48 #include <sys/sysctl.h>
51 #include <net/if_media.h>
52 #include <net/if_llc.h>
53 #include <net/ethernet.h>
57 #include <net80211/ieee80211_var.h>
58 #include <net80211/ieee80211_hostap.h>
59 #include <net80211/ieee80211_input.h>
60 #include <net80211/ieee80211_wds.h>
62 #define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2)
64 static void hostap_vattach(struct ieee80211vap *);
65 static int hostap_newstate(struct ieee80211vap *, enum ieee80211_state, int);
66 static int hostap_input(struct ieee80211_node *ni, struct mbuf *m,
67 int rssi, int noise, uint32_t rstamp);
68 static void hostap_deliver_data(struct ieee80211vap *,
69 struct ieee80211_node *, struct mbuf *);
70 static void hostap_recv_mgmt(struct ieee80211_node *, struct mbuf *,
71 int subtype, int rssi, int noise, uint32_t rstamp);
72 static void hostap_recv_pspoll(struct ieee80211_node *, struct mbuf *);
75 ieee80211_hostap_attach(struct ieee80211com *ic)
77 ic->ic_vattach[IEEE80211_M_HOSTAP] = hostap_vattach;
81 ieee80211_hostap_detach(struct ieee80211com *ic)
86 hostap_vdetach(struct ieee80211vap *vap)
91 hostap_vattach(struct ieee80211vap *vap)
93 vap->iv_newstate = hostap_newstate;
94 vap->iv_input = hostap_input;
95 vap->iv_recv_mgmt = hostap_recv_mgmt;
96 vap->iv_opdetach = hostap_vdetach;
97 vap->iv_deliver_data = hostap_deliver_data;
101 sta_disassoc(void *arg, struct ieee80211_node *ni)
103 struct ieee80211vap *vap = arg;
105 if (ni->ni_vap == vap && ni->ni_associd != 0) {
106 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DISASSOC,
107 IEEE80211_REASON_ASSOC_LEAVE);
108 ieee80211_node_leave(ni);
113 * IEEE80211_M_HOSTAP vap state machine handler.
116 hostap_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
118 struct ieee80211com *ic = vap->iv_ic;
119 enum ieee80211_state ostate;
121 IEEE80211_LOCK_ASSERT(ic);
123 ostate = vap->iv_state;
124 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",
125 __func__, ieee80211_state_name[ostate],
126 ieee80211_state_name[nstate], arg);
127 vap->iv_state = nstate; /* state transition */
128 if (ostate != IEEE80211_S_SCAN)
129 ieee80211_cancel_scan(vap); /* background scan */
131 case IEEE80211_S_INIT:
133 case IEEE80211_S_SCAN:
134 ieee80211_cancel_scan(vap);
136 case IEEE80211_S_CAC:
137 ieee80211_dfs_cac_stop(vap);
139 case IEEE80211_S_RUN:
140 ieee80211_iterate_nodes(&ic->ic_sta, sta_disassoc, vap);
145 if (ostate != IEEE80211_S_INIT) {
146 /* NB: optimize INIT -> INIT case */
147 ieee80211_reset_bss(vap);
149 if (vap->iv_auth->ia_detach != NULL)
150 vap->iv_auth->ia_detach(vap);
152 case IEEE80211_S_SCAN:
154 case IEEE80211_S_CSA:
155 case IEEE80211_S_RUN:
156 ieee80211_iterate_nodes(&ic->ic_sta, sta_disassoc, vap);
158 * Clear overlapping BSS state; the beacon frame
159 * will be reconstructed on transition to the RUN
160 * state and the timeout routines check if the flag
161 * is set before doing anything so this is sufficient.
163 ic->ic_flags_ext &= ~IEEE80211_FEXT_NONERP_PR;
164 ic->ic_flags_ext &= ~IEEE80211_FEXT_NONHT_PR;
166 case IEEE80211_S_CAC:
168 * NB: We may get here because of a manual channel
169 * change in which case we need to stop CAC
170 * XXX no need to stop if ostate RUN but it's ok
172 ieee80211_dfs_cac_stop(vap);
174 case IEEE80211_S_INIT:
175 if (vap->iv_des_chan != IEEE80211_CHAN_ANYC &&
176 !IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan)) {
178 * Already have a channel; bypass the
179 * scan and startup immediately.
180 * ieee80211_create_ibss will call back to
181 * move us to RUN state.
183 ieee80211_create_ibss(vap, vap->iv_des_chan);
187 * Initiate a scan. We can come here as a result
188 * of an IEEE80211_IOC_SCAN_REQ too in which case
189 * the vap will be marked with IEEE80211_FEXT_SCANREQ
190 * and the scan request parameters will be present
191 * in iv_scanreq. Otherwise we do the default.
193 if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
194 ieee80211_check_scan(vap,
195 vap->iv_scanreq_flags,
196 vap->iv_scanreq_duration,
197 vap->iv_scanreq_mindwell,
198 vap->iv_scanreq_maxdwell,
199 vap->iv_scanreq_nssid, vap->iv_scanreq_ssid);
200 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
202 ieee80211_check_scan_current(vap);
204 case IEEE80211_S_SCAN:
206 * A state change requires a reset; scan.
208 ieee80211_check_scan_current(vap);
214 case IEEE80211_S_CAC:
216 * Start CAC on a DFS channel. We come here when starting
217 * a bss on a DFS channel (see ieee80211_create_ibss).
219 ieee80211_dfs_cac_start(vap);
221 case IEEE80211_S_RUN:
222 if (vap->iv_flags & IEEE80211_F_WPA) {
223 /* XXX validate prerequisites */
226 case IEEE80211_S_INIT:
228 * Already have a channel; bypass the
229 * scan and startup immediately.
230 * Note that ieee80211_create_ibss will call
231 * back to do a RUN->RUN state change.
233 ieee80211_create_ibss(vap,
234 ieee80211_ht_adjust_channel(ic,
235 ic->ic_curchan, vap->iv_flags_ext));
236 /* NB: iv_bss is changed on return */
238 case IEEE80211_S_CAC:
240 * NB: This is the normal state change when CAC
241 * expires and no radar was detected; no need to
242 * clear the CAC timer as it's already expired.
245 case IEEE80211_S_CSA:
247 * Update bss node channel to reflect where
248 * we landed after CSA.
250 ieee80211_node_set_chan(vap->iv_bss,
251 ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
252 ieee80211_htchanflags(vap->iv_bss->ni_chan)));
253 /* XXX bypass debug msgs */
255 case IEEE80211_S_SCAN:
256 case IEEE80211_S_RUN:
257 #ifdef IEEE80211_DEBUG
258 if (ieee80211_msg_debug(vap)) {
259 struct ieee80211_node *ni = vap->iv_bss;
261 "synchronized with %s ssid ",
262 ether_sprintf(ni->ni_bssid));
263 ieee80211_print_essid(ni->ni_essid,
266 printf(" channel %d start %uMb\n",
267 ieee80211_chan2ieee(ic, ic->ic_curchan),
268 IEEE80211_RATE2MBS(ni->ni_txrate));
276 * Start/stop the authenticator. We delay until here
277 * to allow configuration to happen out of order.
279 if (vap->iv_auth->ia_attach != NULL) {
280 /* XXX check failure */
281 vap->iv_auth->ia_attach(vap);
282 } else if (vap->iv_auth->ia_detach != NULL) {
283 vap->iv_auth->ia_detach(vap);
285 ieee80211_node_authorize(vap->iv_bss);
294 hostap_deliver_data(struct ieee80211vap *vap,
295 struct ieee80211_node *ni, struct mbuf *m)
297 struct ether_header *eh = mtod(m, struct ether_header *);
298 struct ifnet *ifp = vap->iv_ifp;
300 KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP,
301 ("gack, opmode %d", vap->iv_opmode));
306 IEEE80211_NODE_STAT(ni, rx_data);
307 IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
308 if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
309 m->m_flags |= M_MCAST; /* XXX M_BCAST? */
310 IEEE80211_NODE_STAT(ni, rx_mcast);
312 IEEE80211_NODE_STAT(ni, rx_ucast);
314 /* clear driver/net80211 flags before passing up */
315 m->m_flags &= ~M_80211_RX;
317 /* perform as a bridge within the AP */
318 if ((vap->iv_flags & IEEE80211_F_NOBRIDGE) == 0) {
319 struct mbuf *mcopy = NULL;
321 if (m->m_flags & M_MCAST) {
322 mcopy = m_copypacket(m, M_DONTWAIT);
326 mcopy->m_flags |= M_MCAST;
329 * Check if the destination is associated with the
330 * same vap and authorized to receive traffic.
331 * Beware of traffic destined for the vap itself;
332 * sending it will not work; just let it be delivered
335 struct ieee80211_node *sta = ieee80211_find_vap_node(
336 &vap->iv_ic->ic_sta, vap, eh->ether_dhost);
338 if (ieee80211_node_is_authorized(sta)) {
340 * Beware of sending to ourself; this
341 * needs to happen via the normal
344 if (sta != vap->iv_bss) {
349 vap->iv_stats.is_rx_unauth++;
350 IEEE80211_NODE_STAT(sta, rx_unauth);
352 ieee80211_free_node(sta);
357 len = mcopy->m_pkthdr.len;
358 IFQ_HANDOFF(ifp, mcopy, err);
360 /* NB: IFQ_HANDOFF reclaims mcopy */
368 * Mark frame as coming from vap's interface.
370 m->m_pkthdr.rcvif = ifp;
371 if (m->m_flags & M_MCAST) {
373 * Spam DWDS vap's w/ multicast traffic.
375 /* XXX only if dwds in use? */
376 ieee80211_dwds_mcast(vap, m);
378 if (ni->ni_vlan != 0) {
379 /* attach vlan tag */
380 m->m_pkthdr.ether_vtag = ni->ni_vlan;
381 m->m_flags |= M_VLANTAG;
383 ifp->if_input(ifp, m);
388 * Decide if a received management frame should be
389 * printed when debugging is enabled. This filters some
390 * of the less interesting frames that come frequently
394 doprint(struct ieee80211vap *vap, int subtype)
397 case IEEE80211_FC0_SUBTYPE_BEACON:
398 return (vap->iv_ic->ic_flags & IEEE80211_F_SCAN);
399 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
406 * Process a received frame. The node associated with the sender
407 * should be supplied. If nothing was found in the node table then
408 * the caller is assumed to supply a reference to iv_bss instead.
409 * The RSSI and a timestamp are also supplied. The RSSI data is used
410 * during AP scanning to select a AP to associate with; it can have
411 * any units so long as values have consistent units and higher values
412 * mean ``better signal''. The receive timestamp is currently not used
413 * by the 802.11 layer.
416 hostap_input(struct ieee80211_node *ni, struct mbuf *m,
417 int rssi, int noise, uint32_t rstamp)
419 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
420 #define HAS_SEQ(type) ((type & 0x4) == 0)
421 struct ieee80211vap *vap = ni->ni_vap;
422 struct ieee80211com *ic = ni->ni_ic;
423 struct ifnet *ifp = vap->iv_ifp;
424 struct ieee80211_frame *wh;
425 struct ieee80211_key *key;
426 struct ether_header *eh;
427 int hdrspace, need_tap;
428 uint8_t dir, type, subtype, qos;
432 if (m->m_flags & M_AMPDU_MPDU) {
434 * Fastpath for A-MPDU reorder q resubmission. Frames
435 * w/ M_AMPDU_MPDU marked have already passed through
436 * here but were received out of order and been held on
437 * the reorder queue. When resubmitted they are marked
438 * with the M_AMPDU_MPDU flag and we can bypass most of
439 * the normal processing.
441 wh = mtod(m, struct ieee80211_frame *);
442 type = IEEE80211_FC0_TYPE_DATA;
443 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
444 subtype = IEEE80211_FC0_SUBTYPE_QOS;
445 hdrspace = ieee80211_hdrspace(ic, wh); /* XXX optimize? */
449 KASSERT(ni != NULL, ("null node"));
450 ni->ni_inact = ni->ni_inact_reload;
452 need_tap = 1; /* mbuf need to be tapped. */
453 type = -1; /* undefined */
455 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
456 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
457 ni->ni_macaddr, NULL,
458 "too short (1): len %u", m->m_pkthdr.len);
459 vap->iv_stats.is_rx_tooshort++;
463 * Bit of a cheat here, we use a pointer for a 3-address
464 * frame format but don't reference fields past outside
465 * ieee80211_frame_min w/o first validating the data is
468 wh = mtod(m, struct ieee80211_frame *);
470 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
471 IEEE80211_FC0_VERSION_0) {
472 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
473 ni->ni_macaddr, NULL, "wrong version %x", wh->i_fc[0]);
474 vap->iv_stats.is_rx_badversion++;
478 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
479 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
480 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
481 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
482 if (dir != IEEE80211_FC1_DIR_NODS)
484 else if (type == IEEE80211_FC0_TYPE_CTL)
487 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
488 IEEE80211_DISCARD_MAC(vap,
489 IEEE80211_MSG_ANY, ni->ni_macaddr,
490 NULL, "too short (2): len %u",
492 vap->iv_stats.is_rx_tooshort++;
498 * Validate the bssid.
500 if (!(type == IEEE80211_FC0_TYPE_MGT &&
501 subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
502 !IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) &&
503 !IEEE80211_ADDR_EQ(bssid, ifp->if_broadcastaddr)) {
504 /* not interested in */
505 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
506 bssid, NULL, "%s", "not to bss");
507 vap->iv_stats.is_rx_wrongbss++;
511 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
512 ni->ni_noise = noise;
513 ni->ni_rstamp = rstamp;
515 uint8_t tid = ieee80211_gettid(wh);
516 if (IEEE80211_QOS_HAS_SEQ(wh) &&
517 TID_TO_WME_AC(tid) >= WME_AC_VI)
518 ic->ic_wme.wme_hipri_traffic++;
519 rxseq = le16toh(*(uint16_t *)wh->i_seq);
520 if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
521 (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
522 SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
523 /* duplicate, discard */
524 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
526 "seqno <%u,%u> fragno <%u,%u> tid %u",
527 rxseq >> IEEE80211_SEQ_SEQ_SHIFT,
528 ni->ni_rxseqs[tid] >>
529 IEEE80211_SEQ_SEQ_SHIFT,
530 rxseq & IEEE80211_SEQ_FRAG_MASK,
532 IEEE80211_SEQ_FRAG_MASK,
534 vap->iv_stats.is_rx_dup++;
535 IEEE80211_NODE_STAT(ni, rx_dup);
538 ni->ni_rxseqs[tid] = rxseq;
543 case IEEE80211_FC0_TYPE_DATA:
544 hdrspace = ieee80211_hdrspace(ic, wh);
545 if (m->m_len < hdrspace &&
546 (m = m_pullup(m, hdrspace)) == NULL) {
547 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
548 ni->ni_macaddr, NULL,
549 "data too short: expecting %u", hdrspace);
550 vap->iv_stats.is_rx_tooshort++;
553 if (!(dir == IEEE80211_FC1_DIR_TODS ||
554 (dir == IEEE80211_FC1_DIR_DSTODS &&
555 (vap->iv_flags & IEEE80211_F_DWDS)))) {
556 if (dir != IEEE80211_FC1_DIR_DSTODS) {
557 IEEE80211_DISCARD(vap,
558 IEEE80211_MSG_INPUT, wh, "data",
559 "incorrect dir 0x%x", dir);
561 IEEE80211_DISCARD(vap,
562 IEEE80211_MSG_INPUT |
563 IEEE80211_MSG_WDS, wh,
565 "%s", "DWDS not enabled");
567 vap->iv_stats.is_rx_wrongdir++;
570 /* check if source STA is associated */
571 if (ni == vap->iv_bss) {
572 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
573 wh, "data", "%s", "unknown src");
574 ieee80211_send_error(ni, wh->i_addr2,
575 IEEE80211_FC0_SUBTYPE_DEAUTH,
576 IEEE80211_REASON_NOT_AUTHED);
577 vap->iv_stats.is_rx_notassoc++;
580 if (ni->ni_associd == 0) {
581 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
582 wh, "data", "%s", "unassoc src");
583 IEEE80211_SEND_MGMT(ni,
584 IEEE80211_FC0_SUBTYPE_DISASSOC,
585 IEEE80211_REASON_NOT_ASSOCED);
586 vap->iv_stats.is_rx_notassoc++;
591 * Check for power save state change.
592 * XXX out-of-order A-MPDU frames?
594 if (((wh->i_fc[1] & IEEE80211_FC1_PWR_MGT) ^
595 (ni->ni_flags & IEEE80211_NODE_PWR_MGT)))
596 ieee80211_node_pwrsave(ni,
597 wh->i_fc[1] & IEEE80211_FC1_PWR_MGT);
599 * For 4-address packets handle WDS discovery
600 * notifications. Once a WDS link is setup frames
601 * are just delivered to the WDS vap (see below).
603 if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap == NULL) {
604 if (!ieee80211_node_is_authorized(ni)) {
605 IEEE80211_DISCARD(vap,
606 IEEE80211_MSG_INPUT |
607 IEEE80211_MSG_WDS, wh,
609 "%s", "unauthorized port");
610 vap->iv_stats.is_rx_unauth++;
611 IEEE80211_NODE_STAT(ni, rx_unauth);
614 ieee80211_dwds_discover(ni, m);
619 * Handle A-MPDU re-ordering. If the frame is to be
620 * processed directly then ieee80211_ampdu_reorder
621 * will return 0; otherwise it has consumed the mbuf
622 * and we should do nothing more with it.
624 if ((m->m_flags & M_AMPDU) &&
625 ieee80211_ampdu_reorder(ni, m) != 0) {
632 * Handle privacy requirements. Note that we
633 * must not be preempted from here until after
634 * we (potentially) call ieee80211_crypto_demic;
635 * otherwise we may violate assumptions in the
636 * crypto cipher modules used to do delayed update
637 * of replay sequence numbers.
639 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
640 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
642 * Discard encrypted frames when privacy is off.
644 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
645 wh, "WEP", "%s", "PRIVACY off");
646 vap->iv_stats.is_rx_noprivacy++;
647 IEEE80211_NODE_STAT(ni, rx_noprivacy);
650 key = ieee80211_crypto_decap(ni, m, hdrspace);
652 /* NB: stats+msgs handled in crypto_decap */
653 IEEE80211_NODE_STAT(ni, rx_wepfail);
656 wh = mtod(m, struct ieee80211_frame *);
657 wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
659 /* XXX M_WEP and IEEE80211_F_PRIVACY */
664 * Save QoS bits for use below--before we strip the header.
666 if (subtype == IEEE80211_FC0_SUBTYPE_QOS) {
667 qos = (dir == IEEE80211_FC1_DIR_DSTODS) ?
668 ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] :
669 ((struct ieee80211_qosframe *)wh)->i_qos[0];
674 * Next up, any fragmentation.
676 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
677 m = ieee80211_defrag(ni, m, hdrspace);
679 /* Fragment dropped or frame not complete yet */
683 wh = NULL; /* no longer valid, catch any uses */
686 * Next strip any MSDU crypto bits.
688 if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) {
689 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
690 ni->ni_macaddr, "data", "%s", "demic error");
691 vap->iv_stats.is_rx_demicfail++;
692 IEEE80211_NODE_STAT(ni, rx_demicfail);
695 /* copy to listener after decrypt */
696 if (bpf_peers_present(vap->iv_rawbpf))
697 bpf_mtap(vap->iv_rawbpf, m);
700 * Finally, strip the 802.11 header.
702 m = ieee80211_decap(vap, m, hdrspace);
704 /* XXX mask bit to check for both */
705 /* don't count Null data frames as errors */
706 if (subtype == IEEE80211_FC0_SUBTYPE_NODATA ||
707 subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL)
709 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
710 ni->ni_macaddr, "data", "%s", "decap error");
711 vap->iv_stats.is_rx_decap++;
712 IEEE80211_NODE_STAT(ni, rx_decap);
715 eh = mtod(m, struct ether_header *);
716 if (!ieee80211_node_is_authorized(ni)) {
718 * Deny any non-PAE frames received prior to
719 * authorization. For open/shared-key
720 * authentication the port is mark authorized
721 * after authentication completes. For 802.1x
722 * the port is not marked authorized by the
723 * authenticator until the handshake has completed.
725 if (eh->ether_type != htons(ETHERTYPE_PAE)) {
726 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
727 eh->ether_shost, "data",
728 "unauthorized port: ether type 0x%x len %u",
729 eh->ether_type, m->m_pkthdr.len);
730 vap->iv_stats.is_rx_unauth++;
731 IEEE80211_NODE_STAT(ni, rx_unauth);
736 * When denying unencrypted frames, discard
737 * any non-PAE frames received without encryption.
739 if ((vap->iv_flags & IEEE80211_F_DROPUNENC) &&
740 (key == NULL && (m->m_flags & M_WEP) == 0) &&
741 eh->ether_type != htons(ETHERTYPE_PAE)) {
743 * Drop unencrypted frames.
745 vap->iv_stats.is_rx_unencrypted++;
746 IEEE80211_NODE_STAT(ni, rx_unencrypted);
750 /* XXX require HT? */
751 if (qos & IEEE80211_QOS_AMSDU) {
752 m = ieee80211_decap_amsdu(ni, m);
754 return IEEE80211_FC0_TYPE_DATA;
755 } else if ((ni->ni_ath_flags & IEEE80211_NODE_FF) &&
756 #define FF_LLC_SIZE (sizeof(struct ether_header) + sizeof(struct llc))
757 m->m_pkthdr.len >= 3*FF_LLC_SIZE) {
761 * Check for fast-frame tunnel encapsulation.
763 if (m->m_len < FF_LLC_SIZE &&
764 (m = m_pullup(m, FF_LLC_SIZE)) == NULL) {
765 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
766 ni->ni_macaddr, "fast-frame",
767 "%s", "m_pullup(llc) failed");
768 vap->iv_stats.is_rx_tooshort++;
769 return IEEE80211_FC0_TYPE_DATA;
771 llc = (struct llc *)(mtod(m, uint8_t *) +
772 sizeof(struct ether_header));
773 if (llc->llc_snap.ether_type == htons(ATH_FF_ETH_TYPE)) {
774 m_adj(m, FF_LLC_SIZE);
775 m = ieee80211_decap_fastframe(ni, m);
777 return IEEE80211_FC0_TYPE_DATA;
781 if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap != NULL)
782 ieee80211_deliver_data(ni->ni_wdsvap, ni, m);
784 hostap_deliver_data(vap, ni, m);
785 return IEEE80211_FC0_TYPE_DATA;
787 case IEEE80211_FC0_TYPE_MGT:
788 vap->iv_stats.is_rx_mgmt++;
789 IEEE80211_NODE_STAT(ni, rx_mgmt);
790 if (dir != IEEE80211_FC1_DIR_NODS) {
791 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
792 wh, "mgt", "incorrect dir 0x%x", dir);
793 vap->iv_stats.is_rx_wrongdir++;
796 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
797 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
798 ni->ni_macaddr, "mgt", "too short: len %u",
800 vap->iv_stats.is_rx_tooshort++;
803 if (IEEE80211_IS_MULTICAST(wh->i_addr2)) {
804 /* ensure return frames are unicast */
805 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
806 wh, NULL, "source is multicast: %s",
807 ether_sprintf(wh->i_addr2));
808 vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */
811 #ifdef IEEE80211_DEBUG
812 if ((ieee80211_msg_debug(vap) && doprint(vap, subtype)) ||
813 ieee80211_msg_dumppkts(vap)) {
814 if_printf(ifp, "received %s from %s rssi %d\n",
815 ieee80211_mgt_subtype_name[subtype >>
816 IEEE80211_FC0_SUBTYPE_SHIFT],
817 ether_sprintf(wh->i_addr2), rssi);
820 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
821 if (subtype != IEEE80211_FC0_SUBTYPE_AUTH) {
823 * Only shared key auth frames with a challenge
824 * should be encrypted, discard all others.
826 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
828 "%s", "WEP set but not permitted");
829 vap->iv_stats.is_rx_mgtdiscard++; /* XXX */
832 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
834 * Discard encrypted frames when privacy is off.
836 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
837 wh, NULL, "%s", "WEP set but PRIVACY off");
838 vap->iv_stats.is_rx_noprivacy++;
841 hdrspace = ieee80211_hdrspace(ic, wh);
842 key = ieee80211_crypto_decap(ni, m, hdrspace);
844 /* NB: stats+msgs handled in crypto_decap */
847 wh = mtod(m, struct ieee80211_frame *);
848 wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
850 if (bpf_peers_present(vap->iv_rawbpf))
851 bpf_mtap(vap->iv_rawbpf, m);
852 vap->iv_recv_mgmt(ni, m, subtype, rssi, noise, rstamp);
854 return IEEE80211_FC0_TYPE_MGT;
856 case IEEE80211_FC0_TYPE_CTL:
857 vap->iv_stats.is_rx_ctl++;
858 IEEE80211_NODE_STAT(ni, rx_ctrl);
860 case IEEE80211_FC0_SUBTYPE_PS_POLL:
861 hostap_recv_pspoll(ni, m);
863 case IEEE80211_FC0_SUBTYPE_BAR:
864 ieee80211_recv_bar(ni, m);
869 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
870 wh, "bad", "frame type 0x%x", type);
871 /* should not come here */
878 if (bpf_peers_present(vap->iv_rawbpf) && need_tap)
879 bpf_mtap(vap->iv_rawbpf, m);
887 hostap_auth_open(struct ieee80211_node *ni, struct ieee80211_frame *wh,
888 int rssi, int noise, uint32_t rstamp, uint16_t seq, uint16_t status)
890 struct ieee80211vap *vap = ni->ni_vap;
892 KASSERT(vap->iv_state == IEEE80211_S_RUN, ("state %d", vap->iv_state));
894 if (ni->ni_authmode == IEEE80211_AUTH_SHARED) {
895 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
896 ni->ni_macaddr, "open auth",
897 "bad sta auth mode %u", ni->ni_authmode);
898 vap->iv_stats.is_rx_bad_auth++; /* XXX */
900 * Clear any challenge text that may be there if
901 * a previous shared key auth failed and then an
902 * open auth is attempted.
904 if (ni->ni_challenge != NULL) {
905 FREE(ni->ni_challenge, M_80211_NODE);
906 ni->ni_challenge = NULL;
908 /* XXX hack to workaround calling convention */
909 ieee80211_send_error(ni, wh->i_addr2,
910 IEEE80211_FC0_SUBTYPE_AUTH,
911 (seq + 1) | (IEEE80211_STATUS_ALG<<16));
914 if (seq != IEEE80211_AUTH_OPEN_REQUEST) {
915 vap->iv_stats.is_rx_bad_auth++;
918 /* always accept open authentication requests */
919 if (ni == vap->iv_bss) {
920 ni = ieee80211_dup_bss(vap, wh->i_addr2);
923 } else if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0)
924 (void) ieee80211_ref_node(ni);
926 * Mark the node as referenced to reflect that it's
927 * reference count has been bumped to insure it remains
928 * after the transaction completes.
930 ni->ni_flags |= IEEE80211_NODE_AREF;
932 if (vap->iv_acl != NULL &&
933 vap->iv_acl->iac_getpolicy(vap) == IEEE80211_MACCMD_POLICY_RADIUS) {
935 * When the ACL policy is set to RADIUS we defer the
936 * authorization to a user agent. Dispatch an event,
937 * a subsequent MLME call will decide the fate of the
938 * station. If the user agent is not present then the
939 * node will be reclaimed due to inactivity.
941 IEEE80211_NOTE_MAC(vap,
942 IEEE80211_MSG_AUTH | IEEE80211_MSG_ACL, ni->ni_macaddr,
943 "%s", "station authentication defered (radius acl)");
944 ieee80211_notify_node_auth(ni);
946 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, seq + 1);
947 IEEE80211_NOTE_MAC(vap,
948 IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, ni->ni_macaddr,
949 "%s", "station authenticated (open)");
951 * When 802.1x is not in use mark the port
952 * authorized at this point so traffic can flow.
954 if (ni->ni_authmode != IEEE80211_AUTH_8021X)
955 ieee80211_node_authorize(ni);
960 hostap_auth_shared(struct ieee80211_node *ni, struct ieee80211_frame *wh,
961 uint8_t *frm, uint8_t *efrm, int rssi, int noise, uint32_t rstamp,
962 uint16_t seq, uint16_t status)
964 struct ieee80211vap *vap = ni->ni_vap;
966 int allocbs, estatus;
968 KASSERT(vap->iv_state == IEEE80211_S_RUN, ("state %d", vap->iv_state));
971 * NB: this can happen as we allow pre-shared key
972 * authentication to be enabled w/o wep being turned
973 * on so that configuration of these can be done
974 * in any order. It may be better to enforce the
975 * ordering in which case this check would just be
976 * for sanity/consistency.
978 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
979 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
980 ni->ni_macaddr, "shared key auth",
981 "%s", " PRIVACY is disabled");
982 estatus = IEEE80211_STATUS_ALG;
986 * Pre-shared key authentication is evil; accept
987 * it only if explicitly configured (it is supported
988 * mainly for compatibility with clients like Mac OS X).
990 if (ni->ni_authmode != IEEE80211_AUTH_AUTO &&
991 ni->ni_authmode != IEEE80211_AUTH_SHARED) {
992 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
993 ni->ni_macaddr, "shared key auth",
994 "bad sta auth mode %u", ni->ni_authmode);
995 vap->iv_stats.is_rx_bad_auth++; /* XXX maybe a unique error? */
996 estatus = IEEE80211_STATUS_ALG;
1001 if (frm + 1 < efrm) {
1002 if ((frm[1] + 2) > (efrm - frm)) {
1003 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1004 ni->ni_macaddr, "shared key auth",
1005 "ie %d/%d too long",
1006 frm[0], (frm[1] + 2) - (efrm - frm));
1007 vap->iv_stats.is_rx_bad_auth++;
1008 estatus = IEEE80211_STATUS_CHALLENGE;
1011 if (*frm == IEEE80211_ELEMID_CHALLENGE)
1016 case IEEE80211_AUTH_SHARED_CHALLENGE:
1017 case IEEE80211_AUTH_SHARED_RESPONSE:
1018 if (challenge == NULL) {
1019 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1020 ni->ni_macaddr, "shared key auth",
1021 "%s", "no challenge");
1022 vap->iv_stats.is_rx_bad_auth++;
1023 estatus = IEEE80211_STATUS_CHALLENGE;
1026 if (challenge[1] != IEEE80211_CHALLENGE_LEN) {
1027 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1028 ni->ni_macaddr, "shared key auth",
1029 "bad challenge len %d", challenge[1]);
1030 vap->iv_stats.is_rx_bad_auth++;
1031 estatus = IEEE80211_STATUS_CHALLENGE;
1038 case IEEE80211_AUTH_SHARED_REQUEST:
1039 if (ni == vap->iv_bss) {
1040 ni = ieee80211_dup_bss(vap, wh->i_addr2);
1042 /* NB: no way to return an error */
1047 if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0)
1048 (void) ieee80211_ref_node(ni);
1052 * Mark the node as referenced to reflect that it's
1053 * reference count has been bumped to insure it remains
1054 * after the transaction completes.
1056 ni->ni_flags |= IEEE80211_NODE_AREF;
1057 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
1058 ni->ni_noise = noise;
1059 ni->ni_rstamp = rstamp;
1060 if (!ieee80211_alloc_challenge(ni)) {
1061 /* NB: don't return error so they rexmit */
1064 get_random_bytes(ni->ni_challenge,
1065 IEEE80211_CHALLENGE_LEN);
1066 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH,
1067 ni, "shared key %sauth request", allocbs ? "" : "re");
1069 * When the ACL policy is set to RADIUS we defer the
1070 * authorization to a user agent. Dispatch an event,
1071 * a subsequent MLME call will decide the fate of the
1072 * station. If the user agent is not present then the
1073 * node will be reclaimed due to inactivity.
1075 if (vap->iv_acl != NULL &&
1076 vap->iv_acl->iac_getpolicy(vap) == IEEE80211_MACCMD_POLICY_RADIUS) {
1077 IEEE80211_NOTE_MAC(vap,
1078 IEEE80211_MSG_AUTH | IEEE80211_MSG_ACL,
1080 "%s", "station authentication defered (radius acl)");
1081 ieee80211_notify_node_auth(ni);
1085 case IEEE80211_AUTH_SHARED_RESPONSE:
1086 if (ni == vap->iv_bss) {
1087 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1088 ni->ni_macaddr, "shared key response",
1089 "%s", "unknown station");
1090 /* NB: don't send a response */
1093 if (ni->ni_challenge == NULL) {
1094 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1095 ni->ni_macaddr, "shared key response",
1096 "%s", "no challenge recorded");
1097 vap->iv_stats.is_rx_bad_auth++;
1098 estatus = IEEE80211_STATUS_CHALLENGE;
1101 if (memcmp(ni->ni_challenge, &challenge[2],
1102 challenge[1]) != 0) {
1103 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1104 ni->ni_macaddr, "shared key response",
1105 "%s", "challenge mismatch");
1106 vap->iv_stats.is_rx_auth_fail++;
1107 estatus = IEEE80211_STATUS_CHALLENGE;
1110 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH,
1111 ni, "%s", "station authenticated (shared key)");
1112 ieee80211_node_authorize(ni);
1115 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1116 ni->ni_macaddr, "shared key auth",
1118 vap->iv_stats.is_rx_bad_auth++;
1119 estatus = IEEE80211_STATUS_SEQUENCE;
1122 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, seq + 1);
1126 * Send an error response; but only when operating as an AP.
1128 /* XXX hack to workaround calling convention */
1129 ieee80211_send_error(ni, wh->i_addr2,
1130 IEEE80211_FC0_SUBTYPE_AUTH,
1131 (seq + 1) | (estatus<<16));
1135 * Convert a WPA cipher selector OUI to an internal
1136 * cipher algorithm. Where appropriate we also
1137 * record any key length.
1140 wpa_cipher(const uint8_t *sel, uint8_t *keylen)
1142 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
1143 uint32_t w = LE_READ_4(sel);
1146 case WPA_SEL(WPA_CSE_NULL):
1147 return IEEE80211_CIPHER_NONE;
1148 case WPA_SEL(WPA_CSE_WEP40):
1150 *keylen = 40 / NBBY;
1151 return IEEE80211_CIPHER_WEP;
1152 case WPA_SEL(WPA_CSE_WEP104):
1154 *keylen = 104 / NBBY;
1155 return IEEE80211_CIPHER_WEP;
1156 case WPA_SEL(WPA_CSE_TKIP):
1157 return IEEE80211_CIPHER_TKIP;
1158 case WPA_SEL(WPA_CSE_CCMP):
1159 return IEEE80211_CIPHER_AES_CCM;
1161 return 32; /* NB: so 1<< is discarded */
1166 * Convert a WPA key management/authentication algorithm
1167 * to an internal code.
1170 wpa_keymgmt(const uint8_t *sel)
1172 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
1173 uint32_t w = LE_READ_4(sel);
1176 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
1177 return WPA_ASE_8021X_UNSPEC;
1178 case WPA_SEL(WPA_ASE_8021X_PSK):
1179 return WPA_ASE_8021X_PSK;
1180 case WPA_SEL(WPA_ASE_NONE):
1181 return WPA_ASE_NONE;
1183 return 0; /* NB: so is discarded */
1188 * Parse a WPA information element to collect parameters.
1189 * Note that we do not validate security parameters; that
1190 * is handled by the authenticator; the parsing done here
1191 * is just for internal use in making operational decisions.
1194 ieee80211_parse_wpa(struct ieee80211vap *vap, const uint8_t *frm,
1195 struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh)
1197 uint8_t len = frm[1];
1202 * Check the length once for fixed parts: OUI, type,
1203 * version, mcast cipher, and 2 selector counts.
1204 * Other, variable-length data, must be checked separately.
1206 if ((vap->iv_flags & IEEE80211_F_WPA1) == 0) {
1207 IEEE80211_DISCARD_IE(vap,
1208 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1209 wh, "WPA", "not WPA, flags 0x%x", vap->iv_flags);
1210 return IEEE80211_REASON_IE_INVALID;
1213 IEEE80211_DISCARD_IE(vap,
1214 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1215 wh, "WPA", "too short, len %u", len);
1216 return IEEE80211_REASON_IE_INVALID;
1218 frm += 6, len -= 4; /* NB: len is payload only */
1219 /* NB: iswapoui already validated the OUI and type */
1221 if (w != WPA_VERSION) {
1222 IEEE80211_DISCARD_IE(vap,
1223 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1224 wh, "WPA", "bad version %u", w);
1225 return IEEE80211_REASON_IE_INVALID;
1229 memset(rsn, 0, sizeof(*rsn));
1231 /* multicast/group cipher */
1232 rsn->rsn_mcastcipher = wpa_cipher(frm, &rsn->rsn_mcastkeylen);
1235 /* unicast ciphers */
1239 IEEE80211_DISCARD_IE(vap,
1240 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1241 wh, "WPA", "ucast cipher data too short; len %u, n %u",
1243 return IEEE80211_REASON_IE_INVALID;
1246 for (; n > 0; n--) {
1247 w |= 1<<wpa_cipher(frm, &rsn->rsn_ucastkeylen);
1250 if (w & (1<<IEEE80211_CIPHER_TKIP))
1251 rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP;
1253 rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM;
1255 /* key management algorithms */
1259 IEEE80211_DISCARD_IE(vap,
1260 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1261 wh, "WPA", "key mgmt alg data too short; len %u, n %u",
1263 return IEEE80211_REASON_IE_INVALID;
1266 for (; n > 0; n--) {
1267 w |= wpa_keymgmt(frm);
1270 if (w & WPA_ASE_8021X_UNSPEC)
1271 rsn->rsn_keymgmt = WPA_ASE_8021X_UNSPEC;
1273 rsn->rsn_keymgmt = WPA_ASE_8021X_PSK;
1275 if (len > 2) /* optional capabilities */
1276 rsn->rsn_caps = LE_READ_2(frm);
1282 * Convert an RSN cipher selector OUI to an internal
1283 * cipher algorithm. Where appropriate we also
1284 * record any key length.
1287 rsn_cipher(const uint8_t *sel, uint8_t *keylen)
1289 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
1290 uint32_t w = LE_READ_4(sel);
1293 case RSN_SEL(RSN_CSE_NULL):
1294 return IEEE80211_CIPHER_NONE;
1295 case RSN_SEL(RSN_CSE_WEP40):
1297 *keylen = 40 / NBBY;
1298 return IEEE80211_CIPHER_WEP;
1299 case RSN_SEL(RSN_CSE_WEP104):
1301 *keylen = 104 / NBBY;
1302 return IEEE80211_CIPHER_WEP;
1303 case RSN_SEL(RSN_CSE_TKIP):
1304 return IEEE80211_CIPHER_TKIP;
1305 case RSN_SEL(RSN_CSE_CCMP):
1306 return IEEE80211_CIPHER_AES_CCM;
1307 case RSN_SEL(RSN_CSE_WRAP):
1308 return IEEE80211_CIPHER_AES_OCB;
1310 return 32; /* NB: so 1<< is discarded */
1315 * Convert an RSN key management/authentication algorithm
1316 * to an internal code.
1319 rsn_keymgmt(const uint8_t *sel)
1321 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
1322 uint32_t w = LE_READ_4(sel);
1325 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
1326 return RSN_ASE_8021X_UNSPEC;
1327 case RSN_SEL(RSN_ASE_8021X_PSK):
1328 return RSN_ASE_8021X_PSK;
1329 case RSN_SEL(RSN_ASE_NONE):
1330 return RSN_ASE_NONE;
1332 return 0; /* NB: so is discarded */
1337 * Parse a WPA/RSN information element to collect parameters
1338 * and validate the parameters against what has been
1339 * configured for the system.
1342 ieee80211_parse_rsn(struct ieee80211vap *vap, const uint8_t *frm,
1343 struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh)
1345 uint8_t len = frm[1];
1350 * Check the length once for fixed parts:
1351 * version, mcast cipher, and 2 selector counts.
1352 * Other, variable-length data, must be checked separately.
1354 if ((vap->iv_flags & IEEE80211_F_WPA2) == 0) {
1355 IEEE80211_DISCARD_IE(vap,
1356 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1357 wh, "WPA", "not RSN, flags 0x%x", vap->iv_flags);
1358 return IEEE80211_REASON_IE_INVALID;
1361 IEEE80211_DISCARD_IE(vap,
1362 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1363 wh, "RSN", "too short, len %u", len);
1364 return IEEE80211_REASON_IE_INVALID;
1368 if (w != RSN_VERSION) {
1369 IEEE80211_DISCARD_IE(vap,
1370 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1371 wh, "RSN", "bad version %u", w);
1372 return IEEE80211_REASON_IE_INVALID;
1376 memset(rsn, 0, sizeof(*rsn));
1378 /* multicast/group cipher */
1379 rsn->rsn_mcastcipher = rsn_cipher(frm, &rsn->rsn_mcastkeylen);
1382 /* unicast ciphers */
1386 IEEE80211_DISCARD_IE(vap,
1387 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1388 wh, "RSN", "ucast cipher data too short; len %u, n %u",
1390 return IEEE80211_REASON_IE_INVALID;
1393 for (; n > 0; n--) {
1394 w |= 1<<rsn_cipher(frm, &rsn->rsn_ucastkeylen);
1397 if (w & (1<<IEEE80211_CIPHER_TKIP))
1398 rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP;
1400 rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM;
1402 /* key management algorithms */
1406 IEEE80211_DISCARD_IE(vap,
1407 IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1408 wh, "RSN", "key mgmt alg data too short; len %u, n %u",
1410 return IEEE80211_REASON_IE_INVALID;
1413 for (; n > 0; n--) {
1414 w |= rsn_keymgmt(frm);
1417 if (w & RSN_ASE_8021X_UNSPEC)
1418 rsn->rsn_keymgmt = RSN_ASE_8021X_UNSPEC;
1420 rsn->rsn_keymgmt = RSN_ASE_8021X_PSK;
1422 /* optional RSN capabilities */
1424 rsn->rsn_caps = LE_READ_2(frm);
1431 * WPA/802.11i assocation request processing.
1434 wpa_assocreq(struct ieee80211_node *ni, struct ieee80211_rsnparms *rsnparms,
1435 const struct ieee80211_frame *wh, const uint8_t *wpa,
1436 const uint8_t *rsn, uint16_t capinfo)
1438 struct ieee80211vap *vap = ni->ni_vap;
1442 ni->ni_flags &= ~(IEEE80211_NODE_WPS|IEEE80211_NODE_TSN);
1443 if (wpa == NULL && rsn == NULL) {
1444 if (vap->iv_flags_ext & IEEE80211_FEXT_WPS) {
1446 * W-Fi Protected Setup (WPS) permits
1447 * clients to associate and pass EAPOL frames
1448 * to establish initial credentials.
1450 ni->ni_flags |= IEEE80211_NODE_WPS;
1453 if ((vap->iv_flags_ext & IEEE80211_FEXT_TSN) &&
1454 (capinfo & IEEE80211_CAPINFO_PRIVACY)) {
1456 * Transitional Security Network. Permits clients
1457 * to associate and use WEP while WPA is configured.
1459 ni->ni_flags |= IEEE80211_NODE_TSN;
1462 IEEE80211_DISCARD(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA,
1463 wh, NULL, "%s", "no WPA/RSN IE in association request");
1464 vap->iv_stats.is_rx_assoc_badwpaie++;
1465 reason = IEEE80211_REASON_IE_INVALID;
1468 /* assert right association security credentials */
1469 badwparsn = 0; /* NB: to silence compiler */
1470 switch (vap->iv_flags & IEEE80211_F_WPA) {
1471 case IEEE80211_F_WPA1:
1472 badwparsn = (wpa == NULL);
1474 case IEEE80211_F_WPA2:
1475 badwparsn = (rsn == NULL);
1477 case IEEE80211_F_WPA1|IEEE80211_F_WPA2:
1478 badwparsn = (wpa == NULL && rsn == NULL);
1482 IEEE80211_DISCARD(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA,
1484 "%s", "missing WPA/RSN IE in association request");
1485 vap->iv_stats.is_rx_assoc_badwpaie++;
1486 reason = IEEE80211_REASON_IE_INVALID;
1490 * Parse WPA/RSN information element.
1493 reason = ieee80211_parse_wpa(vap, wpa, rsnparms, wh);
1495 reason = ieee80211_parse_rsn(vap, rsn, rsnparms, wh);
1497 /* XXX distinguish WPA/RSN? */
1498 vap->iv_stats.is_rx_assoc_badwpaie++;
1501 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, ni,
1502 "%s ie: mc %u/%u uc %u/%u key %u caps 0x%x",
1503 wpa != NULL ? "WPA" : "RSN",
1504 rsnparms->rsn_mcastcipher, rsnparms->rsn_mcastkeylen,
1505 rsnparms->rsn_ucastcipher, rsnparms->rsn_ucastkeylen,
1506 rsnparms->rsn_keymgmt, rsnparms->rsn_caps);
1510 ieee80211_node_deauth(ni, reason);
1514 /* XXX find a better place for definition */
1515 struct l2_update_frame {
1516 struct ether_header eh;
1524 * Deliver a TGf L2UF frame on behalf of a station.
1525 * This primes any bridge when the station is roaming
1526 * between ap's on the same wired network.
1529 ieee80211_deliver_l2uf(struct ieee80211_node *ni)
1531 struct ieee80211vap *vap = ni->ni_vap;
1532 struct ifnet *ifp = vap->iv_ifp;
1534 struct l2_update_frame *l2uf;
1535 struct ether_header *eh;
1537 m = m_gethdr(M_NOWAIT, MT_DATA);
1539 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
1540 "%s", "no mbuf for l2uf frame");
1541 vap->iv_stats.is_rx_nobuf++; /* XXX not right */
1544 l2uf = mtod(m, struct l2_update_frame *);
1546 /* dst: Broadcast address */
1547 IEEE80211_ADDR_COPY(eh->ether_dhost, ifp->if_broadcastaddr);
1548 /* src: associated STA */
1549 IEEE80211_ADDR_COPY(eh->ether_shost, ni->ni_macaddr);
1550 eh->ether_type = htons(sizeof(*l2uf) - sizeof(*eh));
1554 l2uf->control = 0xf5;
1555 l2uf->xid[0] = 0x81;
1556 l2uf->xid[1] = 0x80;
1557 l2uf->xid[2] = 0x00;
1559 m->m_pkthdr.len = m->m_len = sizeof(*l2uf);
1560 hostap_deliver_data(vap, ni, m);
1564 ratesetmismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1565 int reassoc, int resp, const char *tag, int rate)
1567 IEEE80211_NOTE_MAC(ni->ni_vap, IEEE80211_MSG_ANY, wh->i_addr2,
1568 "deny %s request, %s rate set mismatch, rate/MCS %d",
1569 reassoc ? "reassoc" : "assoc", tag, rate & IEEE80211_RATE_VAL);
1570 IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_BASIC_RATE);
1571 ieee80211_node_leave(ni);
1575 capinfomismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1576 int reassoc, int resp, const char *tag, int capinfo)
1578 struct ieee80211vap *vap = ni->ni_vap;
1580 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, wh->i_addr2,
1581 "deny %s request, %s mismatch 0x%x",
1582 reassoc ? "reassoc" : "assoc", tag, capinfo);
1583 IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_CAPINFO);
1584 ieee80211_node_leave(ni);
1585 vap->iv_stats.is_rx_assoc_capmismatch++;
1589 htcapmismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1590 int reassoc, int resp)
1592 IEEE80211_NOTE_MAC(ni->ni_vap, IEEE80211_MSG_ANY, wh->i_addr2,
1593 "deny %s request, %s missing HT ie", reassoc ? "reassoc" : "assoc");
1594 /* XXX no better code */
1595 IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_OTHER);
1596 ieee80211_node_leave(ni);
1600 authalgreject(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1601 int algo, int seq, int status)
1603 struct ieee80211vap *vap = ni->ni_vap;
1605 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1606 wh, NULL, "unsupported alg %d", algo);
1607 vap->iv_stats.is_rx_auth_unsupported++;
1608 ieee80211_send_error(ni, wh->i_addr2, IEEE80211_FC0_SUBTYPE_AUTH,
1609 seq | (status << 16));
1613 ishtmixed(const uint8_t *ie)
1615 const struct ieee80211_ie_htinfo *ht =
1616 (const struct ieee80211_ie_htinfo *) ie;
1617 return (ht->hi_byte2 & IEEE80211_HTINFO_OPMODE) ==
1618 IEEE80211_HTINFO_OPMODE_MIXED;
1622 is11bclient(const uint8_t *rates, const uint8_t *xrates)
1624 static const uint32_t brates = (1<<2*1)|(1<<2*2)|(1<<11)|(1<<2*11);
1627 /* NB: the 11b clients we care about will not have xrates */
1628 if (xrates != NULL || rates == NULL)
1630 for (i = 0; i < rates[1]; i++) {
1631 int r = rates[2+i] & IEEE80211_RATE_VAL;
1632 if (r > 2*11 || ((1<<r) & brates) == 0)
1639 hostap_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
1640 int subtype, int rssi, int noise, uint32_t rstamp)
1642 struct ieee80211vap *vap = ni->ni_vap;
1643 struct ieee80211com *ic = ni->ni_ic;
1644 struct ieee80211_frame *wh;
1645 uint8_t *frm, *efrm, *sfrm;
1646 uint8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath, *htcap;
1650 wh = mtod(m0, struct ieee80211_frame *);
1651 frm = (uint8_t *)&wh[1];
1652 efrm = mtod(m0, uint8_t *) + m0->m_len;
1654 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
1655 case IEEE80211_FC0_SUBTYPE_BEACON: {
1656 struct ieee80211_scanparams scan;
1658 * We process beacon/probe response frames when scanning;
1659 * otherwise we check beacon frames for overlapping non-ERP
1660 * BSS in 11g and/or overlapping legacy BSS when in HT.
1662 if ((ic->ic_flags & IEEE80211_F_SCAN) == 0 &&
1663 subtype == IEEE80211_FC0_SUBTYPE_PROBE_RESP) {
1664 vap->iv_stats.is_rx_mgtdiscard++;
1667 /* NB: accept off-channel frames */
1668 if (ieee80211_parse_beacon(ni, m0, &scan) &~ IEEE80211_BPARSE_OFFCHAN)
1671 * Count frame now that we know it's to be processed.
1673 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) {
1674 vap->iv_stats.is_rx_beacon++; /* XXX remove */
1675 IEEE80211_NODE_STAT(ni, rx_beacons);
1677 IEEE80211_NODE_STAT(ni, rx_proberesp);
1679 * If scanning, just pass information to the scan module.
1681 if (ic->ic_flags & IEEE80211_F_SCAN) {
1682 if (scan.status == 0 && /* NB: on channel */
1683 (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN)) {
1685 * Actively scanning a channel marked passive;
1686 * send a probe request now that we know there
1687 * is 802.11 traffic present.
1689 * XXX check if the beacon we recv'd gives
1690 * us what we need and suppress the probe req
1692 ieee80211_probe_curchan(vap, 1);
1693 ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN;
1695 ieee80211_add_scan(vap, &scan, wh,
1696 subtype, rssi, noise, rstamp);
1700 * Check beacon for overlapping bss w/ non ERP stations.
1701 * If we detect one and protection is configured but not
1702 * enabled, enable it and start a timer that'll bring us
1703 * out if we stop seeing the bss.
1705 if (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
1706 scan.status == 0 && /* NB: on-channel */
1707 ((scan.erp & 0x100) == 0 || /* NB: no ERP, 11b sta*/
1708 (scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) {
1709 ic->ic_lastnonerp = ticks;
1710 ic->ic_flags_ext |= IEEE80211_FEXT_NONERP_PR;
1711 if (ic->ic_protmode != IEEE80211_PROT_NONE &&
1712 (ic->ic_flags & IEEE80211_F_USEPROT) == 0) {
1713 IEEE80211_NOTE_FRAME(vap,
1714 IEEE80211_MSG_ASSOC, wh,
1715 "non-ERP present on channel %d "
1716 "(saw erp 0x%x from channel %d), "
1717 "enable use of protection",
1718 ic->ic_curchan->ic_ieee,
1719 scan.erp, scan.chan);
1720 ic->ic_flags |= IEEE80211_F_USEPROT;
1721 ieee80211_notify_erp(ic);
1725 * Check beacon for non-HT station on HT channel
1726 * and update HT BSS occupancy as appropriate.
1728 if (IEEE80211_IS_CHAN_HT(ic->ic_curchan)) {
1729 if (scan.status & IEEE80211_BPARSE_OFFCHAN) {
1731 * Off control channel; only check frames
1732 * that come in the extension channel when
1733 * operating w/ HT40.
1735 if (!IEEE80211_IS_CHAN_HT40(ic->ic_curchan))
1737 if (scan.chan != ic->ic_curchan->ic_extieee)
1740 if (scan.htinfo == NULL) {
1741 ieee80211_htprot_update(ic,
1742 IEEE80211_HTINFO_OPMODE_PROTOPT |
1743 IEEE80211_HTINFO_NONHT_PRESENT);
1744 } else if (ishtmixed(scan.htinfo)) {
1745 /* XXX? take NONHT_PRESENT from beacon? */
1746 ieee80211_htprot_update(ic,
1747 IEEE80211_HTINFO_OPMODE_MIXED |
1748 IEEE80211_HTINFO_NONHT_PRESENT);
1754 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
1755 if (vap->iv_state != IEEE80211_S_RUN) {
1756 vap->iv_stats.is_rx_mgtdiscard++;
1760 * prreq frame format
1762 * [tlv] supported rates
1763 * [tlv] extended supported rates
1765 ssid = rates = xrates = NULL;
1767 while (efrm - frm > 1) {
1768 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return);
1770 case IEEE80211_ELEMID_SSID:
1773 case IEEE80211_ELEMID_RATES:
1776 case IEEE80211_ELEMID_XRATES:
1782 IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return);
1784 IEEE80211_VERIFY_ELEMENT(xrates,
1785 IEEE80211_RATE_MAXSIZE - rates[1], return);
1786 IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return);
1787 IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return);
1788 if ((vap->iv_flags & IEEE80211_F_HIDESSID) && ssid[1] == 0) {
1789 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1791 "%s", "no ssid with ssid suppression enabled");
1792 vap->iv_stats.is_rx_ssidmismatch++; /*XXX*/
1796 /* XXX find a better class or define it's own */
1797 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2,
1798 "%s", "recv probe req");
1800 * Some legacy 11b clients cannot hack a complete
1801 * probe response frame. When the request includes
1802 * only a bare-bones rate set, communicate this to
1803 * the transmit side.
1805 ieee80211_send_proberesp(vap, wh->i_addr2,
1806 is11bclient(rates, xrates) ? IEEE80211_SEND_LEGACY_11B : 0);
1809 case IEEE80211_FC0_SUBTYPE_AUTH: {
1810 uint16_t algo, seq, status;
1812 if (vap->iv_state != IEEE80211_S_RUN) {
1813 vap->iv_stats.is_rx_mgtdiscard++;
1816 if (!IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_bss->ni_bssid)) {
1817 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1818 wh, NULL, "%s", "wrong bssid");
1819 vap->iv_stats.is_rx_wrongbss++; /*XXX unique stat?*/
1829 IEEE80211_VERIFY_LENGTH(efrm - frm, 6, return);
1830 algo = le16toh(*(uint16_t *)frm);
1831 seq = le16toh(*(uint16_t *)(frm + 2));
1832 status = le16toh(*(uint16_t *)(frm + 4));
1833 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_AUTH, wh->i_addr2,
1834 "recv auth frame with algorithm %d seq %d", algo, seq);
1836 * Consult the ACL policy module if setup.
1838 if (vap->iv_acl != NULL &&
1839 !vap->iv_acl->iac_check(vap, wh->i_addr2)) {
1840 IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1841 wh, NULL, "%s", "disallowed by ACL");
1842 vap->iv_stats.is_rx_acl++;
1843 ieee80211_send_error(ni, wh->i_addr2,
1844 IEEE80211_FC0_SUBTYPE_AUTH,
1845 (seq+1) | (IEEE80211_STATUS_UNSPECIFIED<<16));
1848 if (vap->iv_flags & IEEE80211_F_COUNTERM) {
1849 IEEE80211_DISCARD(vap,
1850 IEEE80211_MSG_AUTH | IEEE80211_MSG_CRYPTO,
1851 wh, NULL, "%s", "TKIP countermeasures enabled");
1852 vap->iv_stats.is_rx_auth_countermeasures++;
1853 ieee80211_send_error(ni, wh->i_addr2,
1854 IEEE80211_FC0_SUBTYPE_AUTH,
1855 IEEE80211_REASON_MIC_FAILURE);
1858 if (algo == IEEE80211_AUTH_ALG_SHARED)
1859 hostap_auth_shared(ni, wh, frm + 6, efrm, rssi,
1860 noise, rstamp, seq, status);
1861 else if (algo == IEEE80211_AUTH_ALG_OPEN)
1862 hostap_auth_open(ni, wh, rssi, noise, rstamp,
1864 else if (algo == IEEE80211_AUTH_ALG_LEAP) {
1865 authalgreject(ni, wh, algo,
1866 seq+1, IEEE80211_STATUS_ALG);
1870 * We assume that an unknown algorithm is the result
1871 * of a decryption failure on a shared key auth frame;
1872 * return a status code appropriate for that instead
1873 * of IEEE80211_STATUS_ALG.
1875 * NB: a seq# of 4 is intentional; the decrypted
1876 * frame likely has a bogus seq value.
1878 authalgreject(ni, wh, algo,
1879 4, IEEE80211_STATUS_CHALLENGE);
1885 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
1886 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: {
1887 uint16_t capinfo, lintval;
1888 struct ieee80211_rsnparms rsnparms;
1890 if (vap->iv_state != IEEE80211_S_RUN) {
1891 vap->iv_stats.is_rx_mgtdiscard++;
1894 if (!IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_bss->ni_bssid)) {
1895 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1896 wh, NULL, "%s", "wrong bssid");
1897 vap->iv_stats.is_rx_assoc_bss++;
1900 if (subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) {
1902 resp = IEEE80211_FC0_SUBTYPE_REASSOC_RESP;
1905 resp = IEEE80211_FC0_SUBTYPE_ASSOC_RESP;
1907 if (ni == vap->iv_bss) {
1908 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, wh->i_addr2,
1909 "deny %s request, sta not authenticated",
1910 reassoc ? "reassoc" : "assoc");
1911 ieee80211_send_error(ni, wh->i_addr2,
1912 IEEE80211_FC0_SUBTYPE_DEAUTH,
1913 IEEE80211_REASON_ASSOC_NOT_AUTHED);
1914 vap->iv_stats.is_rx_assoc_notauth++;
1919 * asreq frame format
1920 * [2] capability information
1921 * [2] listen interval
1922 * [6*] current AP address (reassoc only)
1924 * [tlv] supported rates
1925 * [tlv] extended supported rates
1927 * [tlv] HT capabilities
1928 * [tlv] Atheros capabilities
1930 IEEE80211_VERIFY_LENGTH(efrm - frm, (reassoc ? 10 : 4), return);
1931 capinfo = le16toh(*(uint16_t *)frm); frm += 2;
1932 lintval = le16toh(*(uint16_t *)frm); frm += 2;
1934 frm += 6; /* ignore current AP info */
1935 ssid = rates = xrates = wpa = rsn = wme = ath = htcap = NULL;
1937 while (efrm - frm > 1) {
1938 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return);
1940 case IEEE80211_ELEMID_SSID:
1943 case IEEE80211_ELEMID_RATES:
1946 case IEEE80211_ELEMID_XRATES:
1949 case IEEE80211_ELEMID_RSN:
1952 case IEEE80211_ELEMID_HTCAP:
1955 case IEEE80211_ELEMID_VENDOR:
1958 else if (iswmeinfo(frm))
1960 else if (isatherosoui(frm))
1962 else if (vap->iv_flags_ext & IEEE80211_FEXT_HTCOMPAT) {
1963 if (ishtcapoui(frm) && htcap == NULL)
1970 IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return);
1972 IEEE80211_VERIFY_ELEMENT(xrates,
1973 IEEE80211_RATE_MAXSIZE - rates[1], return);
1974 IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return);
1975 IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return);
1976 if (htcap != NULL) {
1977 IEEE80211_VERIFY_LENGTH(htcap[1],
1978 htcap[0] == IEEE80211_ELEMID_VENDOR ?
1979 4 + sizeof(struct ieee80211_ie_htcap)-2 :
1980 sizeof(struct ieee80211_ie_htcap)-2,
1981 return); /* XXX just NULL out? */
1984 if ((vap->iv_flags & IEEE80211_F_WPA) &&
1985 !wpa_assocreq(ni, &rsnparms, wh, wpa, rsn, capinfo))
1987 /* discard challenge after association */
1988 if (ni->ni_challenge != NULL) {
1989 FREE(ni->ni_challenge, M_80211_NODE);
1990 ni->ni_challenge = NULL;
1992 /* NB: 802.11 spec says to ignore station's privacy bit */
1993 if ((capinfo & IEEE80211_CAPINFO_ESS) == 0) {
1994 capinfomismatch(ni, wh, reassoc, resp,
1995 "capability", capinfo);
1999 * Disallow re-associate w/ invalid slot time setting.
2001 if (ni->ni_associd != 0 &&
2002 IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2003 ((ni->ni_capinfo ^ capinfo) & IEEE80211_CAPINFO_SHORT_SLOTTIME)) {
2004 capinfomismatch(ni, wh, reassoc, resp,
2005 "slot time", capinfo);
2008 rate = ieee80211_setup_rates(ni, rates, xrates,
2009 IEEE80211_F_DOSORT | IEEE80211_F_DOFRATE |
2010 IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
2011 if (rate & IEEE80211_RATE_BASIC) {
2012 ratesetmismatch(ni, wh, reassoc, resp, "legacy", rate);
2013 vap->iv_stats.is_rx_assoc_norate++;
2017 * If constrained to 11g-only stations reject an
2018 * 11b-only station. We cheat a bit here by looking
2019 * at the max negotiated xmit rate and assuming anyone
2020 * with a best rate <24Mb/s is an 11b station.
2022 if ((vap->iv_flags & IEEE80211_F_PUREG) && rate < 48) {
2023 ratesetmismatch(ni, wh, reassoc, resp, "11g", rate);
2024 vap->iv_stats.is_rx_assoc_norate++;
2028 * Do HT rate set handling and setup HT node state.
2030 ni->ni_chan = vap->iv_bss->ni_chan;
2031 if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) {
2032 rate = ieee80211_setup_htrates(ni, htcap,
2033 IEEE80211_F_DOFMCS | IEEE80211_F_DONEGO |
2035 if (rate & IEEE80211_RATE_BASIC) {
2036 ratesetmismatch(ni, wh, reassoc, resp,
2038 vap->iv_stats.is_ht_assoc_norate++;
2041 ieee80211_ht_node_init(ni, htcap);
2042 } else if (ni->ni_flags & IEEE80211_NODE_HT)
2043 ieee80211_ht_node_cleanup(ni);
2045 * Allow AMPDU operation only with unencrypted traffic
2046 * or AES-CCM; the 11n spec only specifies these ciphers
2047 * so permitting any others is undefined and can lead
2048 * to interoperability problems.
2050 if ((ni->ni_flags & IEEE80211_NODE_HT) &&
2051 (((vap->iv_flags & IEEE80211_F_WPA) &&
2052 rsnparms.rsn_ucastcipher != IEEE80211_CIPHER_AES_CCM) ||
2053 (vap->iv_flags & (IEEE80211_F_WPA|IEEE80211_F_PRIVACY)) == IEEE80211_F_PRIVACY)) {
2055 IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
2056 "disallow HT use because WEP or TKIP requested, "
2057 "capinfo 0x%x ucastcipher %d", capinfo,
2058 rsnparms.rsn_ucastcipher);
2059 ieee80211_ht_node_cleanup(ni);
2060 vap->iv_stats.is_ht_assoc_downgrade++;
2063 * If constrained to 11n-only stations reject legacy stations.
2065 if ((vap->iv_flags_ext & IEEE80211_FEXT_PUREN) &&
2066 (ni->ni_flags & IEEE80211_NODE_HT) == 0) {
2067 htcapmismatch(ni, wh, reassoc, resp);
2068 vap->iv_stats.is_ht_assoc_nohtcap++;
2071 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
2072 ni->ni_noise = noise;
2073 ni->ni_rstamp = rstamp;
2074 ni->ni_intval = lintval;
2075 ni->ni_capinfo = capinfo;
2076 ni->ni_fhdwell = vap->iv_bss->ni_fhdwell;
2077 ni->ni_fhindex = vap->iv_bss->ni_fhindex;
2080 * XXX maybe better to just expand
2082 if (ieee80211_ies_init(&ni->ni_ies, sfrm, efrm - sfrm)) {
2083 #define setie(_ie, _off) ieee80211_ies_setie(ni->ni_ies, _ie, _off)
2085 setie(wpa_ie, wpa - sfrm);
2087 setie(rsn_ie, rsn - sfrm);
2089 setie(htcap_ie, htcap - sfrm);
2091 setie(wme_ie, wme - sfrm);
2093 * Mark node as capable of QoS.
2095 ni->ni_flags |= IEEE80211_NODE_QOS;
2097 ni->ni_flags &= ~IEEE80211_NODE_QOS;
2099 setie(ath_ie, ath - sfrm);
2101 * Parse ATH station parameters.
2103 ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
2105 ni->ni_ath_flags = 0;
2108 ni->ni_flags &= ~IEEE80211_NODE_QOS;
2109 ni->ni_ath_flags = 0;
2111 ieee80211_node_join(ni, resp);
2112 ieee80211_deliver_l2uf(ni);
2116 case IEEE80211_FC0_SUBTYPE_DEAUTH:
2117 case IEEE80211_FC0_SUBTYPE_DISASSOC: {
2120 if (vap->iv_state != IEEE80211_S_RUN ||
2121 /* NB: can happen when in promiscuous mode */
2122 !IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr)) {
2123 vap->iv_stats.is_rx_mgtdiscard++;
2127 * deauth/disassoc frame format
2130 IEEE80211_VERIFY_LENGTH(efrm - frm, 2, return);
2131 reason = le16toh(*(uint16_t *)frm);
2132 if (subtype == IEEE80211_FC0_SUBTYPE_DEAUTH) {
2133 vap->iv_stats.is_rx_deauth++;
2134 IEEE80211_NODE_STAT(ni, rx_deauth);
2136 vap->iv_stats.is_rx_disassoc++;
2137 IEEE80211_NODE_STAT(ni, rx_disassoc);
2139 IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni,
2140 "recv %s (reason %d)", ieee80211_mgt_subtype_name[subtype >>
2141 IEEE80211_FC0_SUBTYPE_SHIFT], reason);
2142 if (ni != vap->iv_bss)
2143 ieee80211_node_leave(ni);
2147 case IEEE80211_FC0_SUBTYPE_ACTION:
2148 if (vap->iv_state == IEEE80211_S_RUN) {
2149 if (ieee80211_parse_action(ni, m0) == 0)
2150 ic->ic_recv_action(ni, frm, efrm);
2152 vap->iv_stats.is_rx_mgtdiscard++;
2155 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2156 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2158 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
2159 wh, "mgt", "subtype 0x%x not handled", subtype);
2160 vap->iv_stats.is_rx_badsubtype++;
2166 * Process a received ps-poll frame.
2169 hostap_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m0)
2171 struct ieee80211vap *vap = ni->ni_vap;
2172 struct ieee80211_frame_min *wh;
2173 struct ifnet *ifp = vap->iv_ifp;
2178 wh = mtod(m0, struct ieee80211_frame_min *);
2179 if (ni->ni_associd == 0) {
2180 IEEE80211_DISCARD(vap,
2181 IEEE80211_MSG_POWER | IEEE80211_MSG_DEBUG,
2182 (struct ieee80211_frame *) wh, NULL,
2183 "%s", "unassociated station");
2184 vap->iv_stats.is_ps_unassoc++;
2185 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH,
2186 IEEE80211_REASON_NOT_ASSOCED);
2190 aid = le16toh(*(uint16_t *)wh->i_dur);
2191 if (aid != ni->ni_associd) {
2192 IEEE80211_DISCARD(vap,
2193 IEEE80211_MSG_POWER | IEEE80211_MSG_DEBUG,
2194 (struct ieee80211_frame *) wh, NULL,
2195 "aid mismatch: sta aid 0x%x poll aid 0x%x",
2196 ni->ni_associd, aid);
2197 vap->iv_stats.is_ps_badaid++;
2199 * NB: We used to deauth the station but it turns out
2200 * the Blackberry Curve 8230 (and perhaps other devices)
2201 * sometimes send the wrong AID when WME is negotiated.
2202 * Being more lenient here seems ok as we already check
2203 * the station is associated and we only return frames
2204 * queued for the station (i.e. we don't use the AID).
2209 /* Okay, take the first queued packet and put it out... */
2210 IEEE80211_NODE_SAVEQ_DEQUEUE(ni, m, qlen);
2212 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_POWER, wh->i_addr2,
2213 "%s", "recv ps-poll, but queue empty");
2214 ieee80211_send_nulldata(ieee80211_ref_node(ni));
2215 vap->iv_stats.is_ps_qempty++; /* XXX node stat */
2216 if (vap->iv_set_tim != NULL)
2217 vap->iv_set_tim(ni, 0); /* just in case */
2221 * If there are more packets, set the more packets bit
2222 * in the packet dispatched to the station; otherwise
2223 * turn off the TIM bit.
2226 IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
2227 "recv ps-poll, send packet, %u still queued", qlen);
2228 m->m_flags |= M_MORE_DATA;
2230 IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
2231 "%s", "recv ps-poll, send packet, queue empty");
2232 if (vap->iv_set_tim != NULL)
2233 vap->iv_set_tim(ni, 0);
2235 m->m_flags |= M_PWR_SAV; /* bypass PS handling */
2236 IF_ENQUEUE(&ifp->if_snd, m);