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 WDS 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_wds.h>
59 #include <net80211/ieee80211_input.h>
60 #ifdef IEEE80211_SUPPORT_SUPERG
61 #include <net80211/ieee80211_superg.h>
64 static void wds_vattach(struct ieee80211vap *);
65 static int wds_newstate(struct ieee80211vap *, enum ieee80211_state, int);
66 static int wds_input(struct ieee80211_node *ni, struct mbuf *m,
67 int rssi, int noise, uint32_t rstamp);
68 static void wds_recv_mgmt(struct ieee80211_node *, struct mbuf *,
69 int subtype, int rssi, int noise, u_int32_t rstamp);
72 ieee80211_wds_attach(struct ieee80211com *ic)
74 ic->ic_vattach[IEEE80211_M_WDS] = wds_vattach;
78 ieee80211_wds_detach(struct ieee80211com *ic)
83 wds_vdetach(struct ieee80211vap *vap)
85 if (vap->iv_bss != NULL) {
87 if (vap->iv_bss->ni_wdsvap == vap)
88 vap->iv_bss->ni_wdsvap = NULL;
93 wds_vattach(struct ieee80211vap *vap)
95 vap->iv_newstate = wds_newstate;
96 vap->iv_input = wds_input;
97 vap->iv_recv_mgmt = wds_recv_mgmt;
98 vap->iv_opdetach = wds_vdetach;
102 ieee80211_create_wds(struct ieee80211vap *vap, struct ieee80211_channel *chan)
104 struct ieee80211com *ic = vap->iv_ic;
105 struct ieee80211_node_table *nt = &ic->ic_sta;
106 struct ieee80211_node *ni, *obss;
108 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WDS,
109 "%s: creating link to %s on channel %u\n", __func__,
110 ether_sprintf(vap->iv_des_bssid), ieee80211_chan2ieee(ic, chan));
112 /* NB: vap create must specify the bssid for the link */
113 KASSERT(vap->iv_flags & IEEE80211_F_DESBSSID, ("no bssid"));
114 /* NB: we should only be called on RUN transition */
115 KASSERT(vap->iv_state == IEEE80211_S_RUN, ("!RUN state"));
117 if ((vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0) {
119 * Dynamic/non-legacy WDS. Reference the associated
120 * station specified by the desired bssid setup at vap
121 * create. Point ni_wdsvap at the WDS vap so 4-address
122 * frames received through the associated AP vap will
123 * be dispatched upward (e.g. to a bridge) as though
124 * they arrived on the WDS vap.
126 IEEE80211_NODE_LOCK(nt);
128 ni = ieee80211_find_node_locked(&ic->ic_sta, vap->iv_des_bssid);
131 * Node went away before we could hookup. This
132 * should be ok; no traffic will flow and a leave
133 * event will be dispatched that should cause
134 * the vap to be destroyed.
136 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WDS,
137 "%s: station %s went away\n",
138 __func__, ether_sprintf(vap->iv_des_bssid));
140 } else if (ni->ni_wdsvap != NULL) {
142 * Node already setup with a WDS vap; we cannot
143 * allow multiple references so disallow. If
144 * ni_wdsvap points at us that's ok; we should
147 /* XXX printf instead? */
148 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WDS,
149 "%s: station %s in use with %s\n",
150 __func__, ether_sprintf(vap->iv_des_bssid),
151 ni->ni_wdsvap->iv_ifp->if_xname);
155 * Committed to new node, setup state.
161 IEEE80211_NODE_UNLOCK(nt);
163 /* NB: deferred to avoid recursive lock */
164 ieee80211_free_node(obss);
168 * Legacy WDS vap setup.
171 * The far end does not associate so we just create
172 * create a new node and install it as the vap's
173 * bss node. We must simulate an association and
174 * authorize the port for traffic to flow.
175 * XXX check if node already in sta table?
177 ni = ieee80211_node_create_wds(vap, vap->iv_des_bssid, chan);
180 vap->iv_bss = ieee80211_ref_node(ni);
181 ni->ni_flags |= IEEE80211_NODE_AREF;
183 ieee80211_free_node(obss);
184 /* give driver a chance to setup state like ni_txrate */
185 if (ic->ic_newassoc != NULL)
186 ic->ic_newassoc(ni, 1);
187 /* tell the authenticator about new station */
188 if (vap->iv_auth->ia_node_join != NULL)
189 vap->iv_auth->ia_node_join(ni);
190 if (ni->ni_authmode != IEEE80211_AUTH_8021X)
191 ieee80211_node_authorize(ni);
193 ieee80211_notify_node_join(ni, 1 /*newassoc*/);
194 /* XXX inject l2uf frame */
199 * Flush pending frames now that were setup.
201 if (ni != NULL && IEEE80211_NODE_WDSQ_QLEN(ni) != 0) {
204 IEEE80211_NOTE(vap, IEEE80211_MSG_WDS, ni,
205 "flush wds queue, %u packets queued",
206 IEEE80211_NODE_WDSQ_QLEN(ni));
207 ic->ic_node_getsignal(ni, &rssi, &noise);
211 IEEE80211_NODE_WDSQ_LOCK(ni);
212 _IEEE80211_NODE_WDSQ_DEQUEUE_HEAD(ni, m);
213 IEEE80211_NODE_WDSQ_UNLOCK(ni);
216 /* XXX cheat and re-use last rstamp */
217 ieee80211_input(ni, m, rssi, noise, ni->ni_rstamp);
220 return (ni == NULL ? ENOENT : 0);
224 * Propagate multicast frames of an ap vap to all DWDS links.
225 * The caller is assumed to have verified this frame is multicast.
228 ieee80211_dwds_mcast(struct ieee80211vap *vap0, struct mbuf *m)
230 struct ieee80211com *ic = vap0->iv_ic;
231 struct ifnet *parent = ic->ic_ifp;
232 const struct ether_header *eh = mtod(m, const struct ether_header *);
233 struct ieee80211_node *ni;
234 struct ieee80211vap *vap;
239 KASSERT(ETHER_IS_MULTICAST(eh->ether_dhost),
240 ("%s not mcast", ether_sprintf(eh->ether_dhost)));
243 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
244 /* only DWDS vaps are interesting */
245 if (vap->iv_opmode != IEEE80211_M_WDS ||
246 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY))
248 /* if it came in this interface, don't send it back out */
250 if (ifp == m->m_pkthdr.rcvif)
253 * Duplicate the frame and send it.
255 mcopy = m_copypacket(m, M_DONTWAIT);
261 ni = ieee80211_find_txnode(vap, eh->ether_dhost);
263 /* NB: ieee80211_find_txnode does stat+msg */
268 /* calculate priority so drivers can find the tx queue */
269 if (ieee80211_classify(ni, mcopy)) {
270 IEEE80211_DISCARD_MAC(vap,
271 IEEE80211_MSG_OUTPUT | IEEE80211_MSG_WDS,
272 eh->ether_dhost, NULL,
273 "%s", "classification failure");
274 vap->iv_stats.is_tx_classify++;
277 ieee80211_free_node(ni);
281 * Encapsulate the packet in prep for transmission.
283 mcopy = ieee80211_encap(vap, ni, mcopy);
285 /* NB: stat+msg handled in ieee80211_encap */
286 ieee80211_free_node(ni);
289 mcopy->m_flags |= M_MCAST;
290 mcopy->m_pkthdr.rcvif = (void *) ni;
292 err = parent->if_transmit(parent, mcopy);
294 /* NB: IFQ_HANDOFF reclaims mbuf */
296 ieee80211_free_node(ni);
303 * Handle DWDS discovery on receipt of a 4-address frame in
304 * ap mode. Queue the frame and post an event for someone
305 * to plumb the necessary WDS vap for this station. Frames
306 * received prior to the vap set running will then be reprocessed
307 * as if they were just received.
310 ieee80211_dwds_discover(struct ieee80211_node *ni, struct mbuf *m)
312 struct ieee80211vap *vap = ni->ni_vap;
313 struct ieee80211com *ic = ni->ni_ic;
316 IEEE80211_NODE_WDSQ_LOCK(ni);
317 if (!_IF_QFULL(&ni->ni_wdsq)) {
319 * Tag the frame with it's expiry time and insert
320 * it in the queue. The aging interval is 4 times
321 * the listen interval specified by the station.
322 * Frames that sit around too long are reclaimed
323 * using this information.
325 /* XXX handle overflow? */
326 /* XXX per/vap beacon interval? */
328 age = ((ni->ni_intval * ic->ic_lintval) << 2) / 1024;
329 _IEEE80211_NODE_WDSQ_ENQUEUE(ni, m, qlen, age);
330 IEEE80211_NODE_WDSQ_UNLOCK(ni);
332 IEEE80211_NOTE(vap, IEEE80211_MSG_WDS, ni,
333 "save frame, %u now queued", qlen);
335 vap->iv_stats.is_dwds_qdrop++;
336 _IF_DROP(&ni->ni_wdsq);
337 IEEE80211_NODE_WDSQ_UNLOCK(ni);
339 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT | IEEE80211_MSG_WDS,
340 mtod(m, struct ieee80211_frame *), "wds data",
341 "pending q overflow, drops %d (len %d)",
342 ni->ni_wdsq.ifq_drops, ni->ni_wdsq.ifq_len);
344 #ifdef IEEE80211_DEBUG
345 if (ieee80211_msg_dumppkts(vap))
346 ieee80211_dump_pkt(ic, mtod(m, caddr_t),
352 ieee80211_notify_wds_discover(ni);
356 * Age frames on the WDS pending queue. The aging interval is
357 * 4 times the listen interval specified by the station. This
358 * number is factored into the age calculations when the frame
359 * is placed on the queue. We store ages as time differences
360 * so we can check and/or adjust only the head of the list.
361 * If a frame's age exceeds the threshold then discard it.
362 * The number of frames discarded is returned to the caller.
365 ieee80211_node_wdsq_age(struct ieee80211_node *ni)
367 #ifdef IEEE80211_DEBUG
368 struct ieee80211vap *vap = ni->ni_vap;
373 IEEE80211_NODE_WDSQ_LOCK(ni);
374 while (_IF_POLL(&ni->ni_wdsq, m) != NULL &&
375 M_AGE_GET(m) < IEEE80211_INACT_WAIT) {
376 IEEE80211_NOTE(vap, IEEE80211_MSG_WDS, ni,
377 "discard frame, age %u", M_AGE_GET(m));
379 /* XXX could be optimized */
380 _IEEE80211_NODE_WDSQ_DEQUEUE_HEAD(ni, m);
385 M_AGE_SUB(m, IEEE80211_INACT_WAIT);
386 IEEE80211_NODE_WDSQ_UNLOCK(ni);
388 IEEE80211_NOTE(vap, IEEE80211_MSG_WDS, ni,
389 "discard %u frames for age", discard);
391 IEEE80211_NODE_STAT_ADD(ni, wds_discard, discard);
397 * IEEE80211_M_WDS vap state machine handler.
400 wds_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
402 struct ieee80211com *ic = vap->iv_ic;
403 struct ieee80211_node *ni;
404 enum ieee80211_state ostate;
407 IEEE80211_LOCK_ASSERT(ic);
409 ostate = vap->iv_state;
410 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s\n", __func__,
411 ieee80211_state_name[ostate], ieee80211_state_name[nstate]);
412 vap->iv_state = nstate; /* state transition */
413 callout_stop(&vap->iv_mgtsend); /* XXX callout_drain */
414 if (ostate != IEEE80211_S_SCAN)
415 ieee80211_cancel_scan(vap); /* background scan */
416 ni = vap->iv_bss; /* NB: no reference held */
419 case IEEE80211_S_INIT:
421 case IEEE80211_S_SCAN:
422 ieee80211_cancel_scan(vap);
427 if (ostate != IEEE80211_S_INIT) {
428 /* NB: optimize INIT -> INIT case */
429 ieee80211_reset_bss(vap);
432 case IEEE80211_S_SCAN:
434 case IEEE80211_S_INIT:
435 ieee80211_check_scan_current(vap);
441 case IEEE80211_S_RUN:
442 if (ostate == IEEE80211_S_INIT) {
444 * Already have a channel; bypass the scan
445 * and startup immediately.
447 error = ieee80211_create_wds(vap, ic->ic_curchan);
457 * Process a received frame. The node associated with the sender
458 * should be supplied. If nothing was found in the node table then
459 * the caller is assumed to supply a reference to iv_bss instead.
460 * The RSSI and a timestamp are also supplied. The RSSI data is used
461 * during AP scanning to select a AP to associate with; it can have
462 * any units so long as values have consistent units and higher values
463 * mean ``better signal''. The receive timestamp is currently not used
464 * by the 802.11 layer.
467 wds_input(struct ieee80211_node *ni, struct mbuf *m,
468 int rssi, int noise, uint32_t rstamp)
470 #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
471 #define HAS_SEQ(type) ((type & 0x4) == 0)
472 struct ieee80211vap *vap = ni->ni_vap;
473 struct ieee80211com *ic = ni->ni_ic;
474 struct ifnet *ifp = vap->iv_ifp;
475 struct ieee80211_frame *wh;
476 struct ieee80211_key *key;
477 struct ether_header *eh;
478 int hdrspace, need_tap;
479 uint8_t dir, type, subtype, qos;
482 if (m->m_flags & M_AMPDU_MPDU) {
484 * Fastpath for A-MPDU reorder q resubmission. Frames
485 * w/ M_AMPDU_MPDU marked have already passed through
486 * here but were received out of order and been held on
487 * the reorder queue. When resubmitted they are marked
488 * with the M_AMPDU_MPDU flag and we can bypass most of
489 * the normal processing.
491 wh = mtod(m, struct ieee80211_frame *);
492 type = IEEE80211_FC0_TYPE_DATA;
493 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
494 subtype = IEEE80211_FC0_SUBTYPE_QOS;
495 hdrspace = ieee80211_hdrspace(ic, wh); /* XXX optimize? */
499 KASSERT(ni != NULL, ("null node"));
501 need_tap = 1; /* mbuf need to be tapped. */
502 type = -1; /* undefined */
504 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
505 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
506 ni->ni_macaddr, NULL,
507 "too short (1): len %u", m->m_pkthdr.len);
508 vap->iv_stats.is_rx_tooshort++;
512 * Bit of a cheat here, we use a pointer for a 3-address
513 * frame format but don't reference fields past outside
514 * ieee80211_frame_min w/o first validating the data is
517 wh = mtod(m, struct ieee80211_frame *);
519 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
520 IEEE80211_FC0_VERSION_0) {
521 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
522 ni->ni_macaddr, NULL, "wrong version %x", wh->i_fc[0]);
523 vap->iv_stats.is_rx_badversion++;
527 dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
528 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
529 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
531 /* NB: WDS vap's do not scan */
532 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_addr4)) {
533 IEEE80211_DISCARD_MAC(vap,
534 IEEE80211_MSG_ANY, ni->ni_macaddr, NULL,
535 "too short (3): len %u", m->m_pkthdr.len);
536 vap->iv_stats.is_rx_tooshort++;
539 /* NB: the TA is implicitly verified by finding the wds peer node */
540 if (!IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr) &&
541 !IEEE80211_ADDR_EQ(wh->i_addr1, ifp->if_broadcastaddr)) {
542 /* not interested in */
543 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
544 wh->i_addr1, NULL, "%s", "not to bss");
545 vap->iv_stats.is_rx_wrongbss++;
548 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
549 ni->ni_noise = noise;
550 ni->ni_rstamp = rstamp;
552 uint8_t tid = ieee80211_gettid(wh);
553 if (IEEE80211_QOS_HAS_SEQ(wh) &&
554 TID_TO_WME_AC(tid) >= WME_AC_VI)
555 ic->ic_wme.wme_hipri_traffic++;
556 rxseq = le16toh(*(uint16_t *)wh->i_seq);
557 if ((ni->ni_flags & IEEE80211_NODE_HT) == 0 &&
558 (wh->i_fc[1] & IEEE80211_FC1_RETRY) &&
559 SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) {
560 /* duplicate, discard */
561 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
562 wh->i_addr1, "duplicate",
563 "seqno <%u,%u> fragno <%u,%u> tid %u",
564 rxseq >> IEEE80211_SEQ_SEQ_SHIFT,
565 ni->ni_rxseqs[tid] >> IEEE80211_SEQ_SEQ_SHIFT,
566 rxseq & IEEE80211_SEQ_FRAG_MASK,
567 ni->ni_rxseqs[tid] & IEEE80211_SEQ_FRAG_MASK,
569 vap->iv_stats.is_rx_dup++;
570 IEEE80211_NODE_STAT(ni, rx_dup);
573 ni->ni_rxseqs[tid] = rxseq;
576 case IEEE80211_FC0_TYPE_DATA:
577 hdrspace = ieee80211_hdrspace(ic, wh);
578 if (m->m_len < hdrspace &&
579 (m = m_pullup(m, hdrspace)) == NULL) {
580 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
581 ni->ni_macaddr, NULL,
582 "data too short: expecting %u", hdrspace);
583 vap->iv_stats.is_rx_tooshort++;
586 if (dir != IEEE80211_FC1_DIR_DSTODS) {
587 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
588 wh, "data", "incorrect dir 0x%x", dir);
589 vap->iv_stats.is_rx_wrongdir++;
593 * Only legacy WDS traffic should take this path.
595 if ((vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0) {
596 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
597 wh, "data", "%s", "not legacy wds");
598 vap->iv_stats.is_rx_wrongdir++;/*XXX*/
601 if (!IEEE80211_IS_MULTICAST(wh->i_addr1))
602 ni->ni_inact = ni->ni_inact_reload;
604 * Handle A-MPDU re-ordering. If the frame is to be
605 * processed directly then ieee80211_ampdu_reorder
606 * will return 0; otherwise it has consumed the mbuf
607 * and we should do nothing more with it.
609 if ((m->m_flags & M_AMPDU) &&
610 ieee80211_ampdu_reorder(ni, m) != 0) {
617 * Handle privacy requirements. Note that we
618 * must not be preempted from here until after
619 * we (potentially) call ieee80211_crypto_demic;
620 * otherwise we may violate assumptions in the
621 * crypto cipher modules used to do delayed update
622 * of replay sequence numbers.
624 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
625 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
627 * Discard encrypted frames when privacy is off.
629 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
630 wh, "WEP", "%s", "PRIVACY off");
631 vap->iv_stats.is_rx_noprivacy++;
632 IEEE80211_NODE_STAT(ni, rx_noprivacy);
635 key = ieee80211_crypto_decap(ni, m, hdrspace);
637 /* NB: stats+msgs handled in crypto_decap */
638 IEEE80211_NODE_STAT(ni, rx_wepfail);
641 wh = mtod(m, struct ieee80211_frame *);
642 wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
644 /* XXX M_WEP and IEEE80211_F_PRIVACY */
649 * Save QoS bits for use below--before we strip the header.
651 if (subtype == IEEE80211_FC0_SUBTYPE_QOS) {
652 qos = (dir == IEEE80211_FC1_DIR_DSTODS) ?
653 ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] :
654 ((struct ieee80211_qosframe *)wh)->i_qos[0];
659 * Next up, any fragmentation.
661 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
662 m = ieee80211_defrag(ni, m, hdrspace);
664 /* Fragment dropped or frame not complete yet */
668 wh = NULL; /* no longer valid, catch any uses */
671 * Next strip any MSDU crypto bits.
673 if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) {
674 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
675 ni->ni_macaddr, "data", "%s", "demic error");
676 vap->iv_stats.is_rx_demicfail++;
677 IEEE80211_NODE_STAT(ni, rx_demicfail);
681 /* copy to listener after decrypt */
682 if (bpf_peers_present(vap->iv_rawbpf))
683 bpf_mtap(vap->iv_rawbpf, m);
687 * Finally, strip the 802.11 header.
689 m = ieee80211_decap(vap, m, hdrspace);
691 /* XXX mask bit to check for both */
692 /* don't count Null data frames as errors */
693 if (subtype == IEEE80211_FC0_SUBTYPE_NODATA ||
694 subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL)
696 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
697 ni->ni_macaddr, "data", "%s", "decap error");
698 vap->iv_stats.is_rx_decap++;
699 IEEE80211_NODE_STAT(ni, rx_decap);
702 eh = mtod(m, struct ether_header *);
703 if (!ieee80211_node_is_authorized(ni)) {
705 * Deny any non-PAE frames received prior to
706 * authorization. For open/shared-key
707 * authentication the port is mark authorized
708 * after authentication completes. For 802.1x
709 * the port is not marked authorized by the
710 * authenticator until the handshake has completed.
712 if (eh->ether_type != htons(ETHERTYPE_PAE)) {
713 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
714 eh->ether_shost, "data",
715 "unauthorized port: ether type 0x%x len %u",
716 eh->ether_type, m->m_pkthdr.len);
717 vap->iv_stats.is_rx_unauth++;
718 IEEE80211_NODE_STAT(ni, rx_unauth);
723 * When denying unencrypted frames, discard
724 * any non-PAE frames received without encryption.
726 if ((vap->iv_flags & IEEE80211_F_DROPUNENC) &&
727 (key == NULL && (m->m_flags & M_WEP) == 0) &&
728 eh->ether_type != htons(ETHERTYPE_PAE)) {
730 * Drop unencrypted frames.
732 vap->iv_stats.is_rx_unencrypted++;
733 IEEE80211_NODE_STAT(ni, rx_unencrypted);
737 /* XXX require HT? */
738 if (qos & IEEE80211_QOS_AMSDU) {
739 m = ieee80211_decap_amsdu(ni, m);
741 return IEEE80211_FC0_TYPE_DATA;
743 #ifdef IEEE80211_SUPPORT_SUPERG
744 m = ieee80211_decap_fastframe(vap, ni, m);
746 return IEEE80211_FC0_TYPE_DATA;
749 ieee80211_deliver_data(vap, ni, m);
750 return IEEE80211_FC0_TYPE_DATA;
752 case IEEE80211_FC0_TYPE_MGT:
753 vap->iv_stats.is_rx_mgmt++;
754 IEEE80211_NODE_STAT(ni, rx_mgmt);
755 if (dir != IEEE80211_FC1_DIR_NODS) {
756 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
757 wh, "data", "incorrect dir 0x%x", dir);
758 vap->iv_stats.is_rx_wrongdir++;
761 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
762 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
763 ni->ni_macaddr, "mgt", "too short: len %u",
765 vap->iv_stats.is_rx_tooshort++;
768 #ifdef IEEE80211_DEBUG
769 if (ieee80211_msg_debug(vap) || ieee80211_msg_dumppkts(vap)) {
770 if_printf(ifp, "received %s from %s rssi %d\n",
771 ieee80211_mgt_subtype_name[subtype >>
772 IEEE80211_FC0_SUBTYPE_SHIFT],
773 ether_sprintf(wh->i_addr2), rssi);
776 if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
777 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
778 wh, NULL, "%s", "WEP set but not permitted");
779 vap->iv_stats.is_rx_mgtdiscard++; /* XXX */
782 if (bpf_peers_present(vap->iv_rawbpf))
783 bpf_mtap(vap->iv_rawbpf, m);
784 vap->iv_recv_mgmt(ni, m, subtype, rssi, noise, rstamp);
786 return IEEE80211_FC0_TYPE_MGT;
788 case IEEE80211_FC0_TYPE_CTL:
789 vap->iv_stats.is_rx_ctl++;
790 IEEE80211_NODE_STAT(ni, rx_ctrl);
793 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
794 wh, "bad", "frame type 0x%x", type);
795 /* should not come here */
802 if (bpf_peers_present(vap->iv_rawbpf) && need_tap)
803 bpf_mtap(vap->iv_rawbpf, m);
811 wds_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
812 int subtype, int rssi, int noise, u_int32_t rstamp)
814 struct ieee80211vap *vap = ni->ni_vap;
815 struct ieee80211com *ic = ni->ni_ic;
816 struct ieee80211_frame *wh;
817 u_int8_t *frm, *efrm;
819 wh = mtod(m0, struct ieee80211_frame *);
820 frm = (u_int8_t *)&wh[1];
821 efrm = mtod(m0, u_int8_t *) + m0->m_len;
823 case IEEE80211_FC0_SUBTYPE_DEAUTH:
824 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
825 case IEEE80211_FC0_SUBTYPE_BEACON:
826 case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
827 case IEEE80211_FC0_SUBTYPE_AUTH:
828 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
829 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
830 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
831 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
832 case IEEE80211_FC0_SUBTYPE_DISASSOC:
833 vap->iv_stats.is_rx_mgtdiscard++;
835 case IEEE80211_FC0_SUBTYPE_ACTION:
836 if (vap->iv_state != IEEE80211_S_RUN ||
837 IEEE80211_IS_MULTICAST(wh->i_addr1)) {
838 vap->iv_stats.is_rx_mgtdiscard++;
841 ni->ni_inact = ni->ni_inact_reload;
842 if (ieee80211_parse_action(ni, m0) == 0)
843 ic->ic_recv_action(ni, frm, efrm);
846 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
847 wh, "mgt", "subtype 0x%x not handled", subtype);
848 vap->iv_stats.is_rx_badsubtype++;