132176cfdSRui Paulo /*-
232176cfdSRui Paulo * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
332176cfdSRui Paulo * All rights reserved.
432176cfdSRui Paulo *
532176cfdSRui Paulo * Redistribution and use in source and binary forms, with or without
632176cfdSRui Paulo * modification, are permitted provided that the following conditions
732176cfdSRui Paulo * are met:
832176cfdSRui Paulo * 1. Redistributions of source code must retain the above copyright
932176cfdSRui Paulo * notice, this list of conditions and the following disclaimer.
1032176cfdSRui Paulo * 2. Redistributions in binary form must reproduce the above copyright
1132176cfdSRui Paulo * notice, this list of conditions and the following disclaimer in the
1232176cfdSRui Paulo * documentation and/or other materials provided with the distribution.
1332176cfdSRui Paulo *
1432176cfdSRui Paulo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1532176cfdSRui Paulo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1632176cfdSRui Paulo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1732176cfdSRui Paulo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1832176cfdSRui Paulo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1932176cfdSRui Paulo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2032176cfdSRui Paulo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2132176cfdSRui Paulo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2232176cfdSRui Paulo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2332176cfdSRui Paulo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2432176cfdSRui Paulo */
2532176cfdSRui Paulo
26085ff963SMatthew Dillon #include <sys/cdefs.h>
27085ff963SMatthew Dillon #ifdef __FreeBSD__
28085ff963SMatthew Dillon __FBSDID("$FreeBSD$");
29085ff963SMatthew Dillon #endif
30085ff963SMatthew Dillon
3132176cfdSRui Paulo /*
3232176cfdSRui Paulo * IEEE 802.11 WDS mode support.
3332176cfdSRui Paulo */
3432176cfdSRui Paulo #include "opt_inet.h"
3532176cfdSRui Paulo #include "opt_wlan.h"
3632176cfdSRui Paulo
3732176cfdSRui Paulo #include <sys/param.h>
3832176cfdSRui Paulo #include <sys/systm.h>
3932176cfdSRui Paulo #include <sys/mbuf.h>
4032176cfdSRui Paulo #include <sys/malloc.h>
4132176cfdSRui Paulo #include <sys/kernel.h>
4232176cfdSRui Paulo
4332176cfdSRui Paulo #include <sys/socket.h>
4432176cfdSRui Paulo #include <sys/sockio.h>
4532176cfdSRui Paulo #include <sys/endian.h>
4632176cfdSRui Paulo #include <sys/errno.h>
4732176cfdSRui Paulo #include <sys/proc.h>
4832176cfdSRui Paulo #include <sys/sysctl.h>
4932176cfdSRui Paulo
5032176cfdSRui Paulo #include <net/if.h>
51085ff963SMatthew Dillon #include <net/if_var.h>
5232176cfdSRui Paulo #include <net/if_media.h>
5332176cfdSRui Paulo #include <net/if_llc.h>
5432176cfdSRui Paulo #include <net/ethernet.h>
5532176cfdSRui Paulo
5632176cfdSRui Paulo #include <net/bpf.h>
5732176cfdSRui Paulo
5832176cfdSRui Paulo #include <netproto/802_11/ieee80211_var.h>
5932176cfdSRui Paulo #include <netproto/802_11/ieee80211_wds.h>
6032176cfdSRui Paulo #include <netproto/802_11/ieee80211_input.h>
6132176cfdSRui Paulo #ifdef IEEE80211_SUPPORT_SUPERG
6232176cfdSRui Paulo #include <netproto/802_11/ieee80211_superg.h>
6332176cfdSRui Paulo #endif
6432176cfdSRui Paulo
6532176cfdSRui Paulo static void wds_vattach(struct ieee80211vap *);
6632176cfdSRui Paulo static int wds_newstate(struct ieee80211vap *, enum ieee80211_state, int);
674f898719SImre Vadász static int wds_input(struct ieee80211_node *ni, struct mbuf *m,
684f898719SImre Vadász const struct ieee80211_rx_stats *rxs, int, int);
694f898719SImre Vadász static void wds_recv_mgmt(struct ieee80211_node *, struct mbuf *, int subtype,
704f898719SImre Vadász const struct ieee80211_rx_stats *, int, int);
7132176cfdSRui Paulo
7232176cfdSRui Paulo void
ieee80211_wds_attach(struct ieee80211com * ic)7332176cfdSRui Paulo ieee80211_wds_attach(struct ieee80211com *ic)
7432176cfdSRui Paulo {
7532176cfdSRui Paulo ic->ic_vattach[IEEE80211_M_WDS] = wds_vattach;
7632176cfdSRui Paulo }
7732176cfdSRui Paulo
7832176cfdSRui Paulo void
ieee80211_wds_detach(struct ieee80211com * ic)7932176cfdSRui Paulo ieee80211_wds_detach(struct ieee80211com *ic)
8032176cfdSRui Paulo {
8132176cfdSRui Paulo }
8232176cfdSRui Paulo
8332176cfdSRui Paulo static void
wds_vdetach(struct ieee80211vap * vap)8432176cfdSRui Paulo wds_vdetach(struct ieee80211vap *vap)
8532176cfdSRui Paulo {
8632176cfdSRui Paulo if (vap->iv_bss != NULL) {
8732176cfdSRui Paulo /* XXX locking? */
8832176cfdSRui Paulo if (vap->iv_bss->ni_wdsvap == vap)
8932176cfdSRui Paulo vap->iv_bss->ni_wdsvap = NULL;
9032176cfdSRui Paulo }
9132176cfdSRui Paulo }
9232176cfdSRui Paulo
9332176cfdSRui Paulo static void
wds_vattach(struct ieee80211vap * vap)9432176cfdSRui Paulo wds_vattach(struct ieee80211vap *vap)
9532176cfdSRui Paulo {
9632176cfdSRui Paulo vap->iv_newstate = wds_newstate;
9732176cfdSRui Paulo vap->iv_input = wds_input;
9832176cfdSRui Paulo vap->iv_recv_mgmt = wds_recv_mgmt;
9932176cfdSRui Paulo vap->iv_opdetach = wds_vdetach;
10032176cfdSRui Paulo }
10132176cfdSRui Paulo
10232176cfdSRui Paulo static void
wds_flush(struct ieee80211_node * ni)10332176cfdSRui Paulo wds_flush(struct ieee80211_node *ni)
10432176cfdSRui Paulo {
10532176cfdSRui Paulo struct ieee80211com *ic = ni->ni_ic;
10632176cfdSRui Paulo struct mbuf *m, *next;
10732176cfdSRui Paulo int8_t rssi, nf;
10832176cfdSRui Paulo
10932176cfdSRui Paulo m = ieee80211_ageq_remove(&ic->ic_stageq,
11032176cfdSRui Paulo (void *)(uintptr_t) ieee80211_mac_hash(ic, ni->ni_macaddr));
11132176cfdSRui Paulo if (m == NULL)
11232176cfdSRui Paulo return;
11332176cfdSRui Paulo
11432176cfdSRui Paulo IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_WDS, ni,
11532176cfdSRui Paulo "%s", "flush wds queue");
11632176cfdSRui Paulo ic->ic_node_getsignal(ni, &rssi, &nf);
11732176cfdSRui Paulo for (; m != NULL; m = next) {
11832176cfdSRui Paulo next = m->m_nextpkt;
11932176cfdSRui Paulo m->m_nextpkt = NULL;
12032176cfdSRui Paulo ieee80211_input(ni, m, rssi, nf);
12132176cfdSRui Paulo }
12232176cfdSRui Paulo }
12332176cfdSRui Paulo
12432176cfdSRui Paulo static int
ieee80211_create_wds(struct ieee80211vap * vap,struct ieee80211_channel * chan)12532176cfdSRui Paulo ieee80211_create_wds(struct ieee80211vap *vap, struct ieee80211_channel *chan)
12632176cfdSRui Paulo {
12732176cfdSRui Paulo struct ieee80211com *ic = vap->iv_ic;
128085ff963SMatthew Dillon struct ieee80211_node_table *nt = &ic->ic_sta;
12932176cfdSRui Paulo struct ieee80211_node *ni, *obss;
13032176cfdSRui Paulo
13132176cfdSRui Paulo IEEE80211_DPRINTF(vap, IEEE80211_MSG_WDS,
1321e290df3SAntonio Huete Jimenez "%s: creating link to %s on channel %u\n", __func__,
133085ff963SMatthew Dillon ether_sprintf(vap->iv_des_bssid), ieee80211_chan2ieee(ic, chan));
13432176cfdSRui Paulo
13532176cfdSRui Paulo /* NB: vap create must specify the bssid for the link */
13632176cfdSRui Paulo KASSERT(vap->iv_flags & IEEE80211_F_DESBSSID, ("no bssid"));
13732176cfdSRui Paulo /* NB: we should only be called on RUN transition */
13832176cfdSRui Paulo KASSERT(vap->iv_state == IEEE80211_S_RUN, ("!RUN state"));
13932176cfdSRui Paulo
14032176cfdSRui Paulo if ((vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0) {
14132176cfdSRui Paulo /*
14232176cfdSRui Paulo * Dynamic/non-legacy WDS. Reference the associated
14332176cfdSRui Paulo * station specified by the desired bssid setup at vap
14432176cfdSRui Paulo * create. Point ni_wdsvap at the WDS vap so 4-address
14532176cfdSRui Paulo * frames received through the associated AP vap will
14632176cfdSRui Paulo * be dispatched upward (e.g. to a bridge) as though
14732176cfdSRui Paulo * they arrived on the WDS vap.
14832176cfdSRui Paulo */
149085ff963SMatthew Dillon IEEE80211_NODE_LOCK(nt);
15032176cfdSRui Paulo obss = NULL;
15132176cfdSRui Paulo ni = ieee80211_find_node_locked(&ic->ic_sta, vap->iv_des_bssid);
15232176cfdSRui Paulo if (ni == NULL) {
15332176cfdSRui Paulo /*
15432176cfdSRui Paulo * Node went away before we could hookup. This
15532176cfdSRui Paulo * should be ok; no traffic will flow and a leave
15632176cfdSRui Paulo * event will be dispatched that should cause
15732176cfdSRui Paulo * the vap to be destroyed.
15832176cfdSRui Paulo */
15932176cfdSRui Paulo IEEE80211_DPRINTF(vap, IEEE80211_MSG_WDS,
1601e290df3SAntonio Huete Jimenez "%s: station %s went away\n",
161085ff963SMatthew Dillon __func__, ether_sprintf(vap->iv_des_bssid));
16232176cfdSRui Paulo /* XXX stat? */
16332176cfdSRui Paulo } else if (ni->ni_wdsvap != NULL) {
16432176cfdSRui Paulo /*
16532176cfdSRui Paulo * Node already setup with a WDS vap; we cannot
16632176cfdSRui Paulo * allow multiple references so disallow. If
16732176cfdSRui Paulo * ni_wdsvap points at us that's ok; we should
16832176cfdSRui Paulo * do nothing anyway.
16932176cfdSRui Paulo */
17032176cfdSRui Paulo /* XXX printf instead? */
17132176cfdSRui Paulo IEEE80211_DPRINTF(vap, IEEE80211_MSG_WDS,
1721e290df3SAntonio Huete Jimenez "%s: station %s in use with %s\n",
173085ff963SMatthew Dillon __func__, ether_sprintf(vap->iv_des_bssid),
17432176cfdSRui Paulo ni->ni_wdsvap->iv_ifp->if_xname);
17532176cfdSRui Paulo /* XXX stat? */
17632176cfdSRui Paulo } else {
17732176cfdSRui Paulo /*
17832176cfdSRui Paulo * Committed to new node, setup state.
17932176cfdSRui Paulo */
18032176cfdSRui Paulo obss = vap->iv_bss;
18132176cfdSRui Paulo vap->iv_bss = ni;
18232176cfdSRui Paulo ni->ni_wdsvap = vap;
18332176cfdSRui Paulo }
184085ff963SMatthew Dillon IEEE80211_NODE_UNLOCK(nt);
18532176cfdSRui Paulo if (obss != NULL) {
18632176cfdSRui Paulo /* NB: deferred to avoid recursive lock */
18732176cfdSRui Paulo ieee80211_free_node(obss);
18832176cfdSRui Paulo }
18932176cfdSRui Paulo } else {
19032176cfdSRui Paulo /*
19132176cfdSRui Paulo * Legacy WDS vap setup.
19232176cfdSRui Paulo */
19332176cfdSRui Paulo /*
19432176cfdSRui Paulo * The far end does not associate so we just create
19532176cfdSRui Paulo * create a new node and install it as the vap's
19632176cfdSRui Paulo * bss node. We must simulate an association and
19732176cfdSRui Paulo * authorize the port for traffic to flow.
19832176cfdSRui Paulo * XXX check if node already in sta table?
19932176cfdSRui Paulo */
20032176cfdSRui Paulo ni = ieee80211_node_create_wds(vap, vap->iv_des_bssid, chan);
20132176cfdSRui Paulo if (ni != NULL) {
20232176cfdSRui Paulo obss = vap->iv_bss;
20332176cfdSRui Paulo vap->iv_bss = ieee80211_ref_node(ni);
20432176cfdSRui Paulo ni->ni_flags |= IEEE80211_NODE_AREF;
20532176cfdSRui Paulo if (obss != NULL)
20632176cfdSRui Paulo ieee80211_free_node(obss);
20732176cfdSRui Paulo /* give driver a chance to setup state like ni_txrate */
20832176cfdSRui Paulo if (ic->ic_newassoc != NULL)
20932176cfdSRui Paulo ic->ic_newassoc(ni, 1);
21032176cfdSRui Paulo /* tell the authenticator about new station */
21132176cfdSRui Paulo if (vap->iv_auth->ia_node_join != NULL)
21232176cfdSRui Paulo vap->iv_auth->ia_node_join(ni);
21332176cfdSRui Paulo if (ni->ni_authmode != IEEE80211_AUTH_8021X)
21432176cfdSRui Paulo ieee80211_node_authorize(ni);
21532176cfdSRui Paulo
21632176cfdSRui Paulo ieee80211_notify_node_join(ni, 1 /*newassoc*/);
21732176cfdSRui Paulo /* XXX inject l2uf frame */
21832176cfdSRui Paulo }
21932176cfdSRui Paulo }
22032176cfdSRui Paulo
22132176cfdSRui Paulo /*
22232176cfdSRui Paulo * Flush any pending frames now that were setup.
22332176cfdSRui Paulo */
22432176cfdSRui Paulo if (ni != NULL)
22532176cfdSRui Paulo wds_flush(ni);
22632176cfdSRui Paulo return (ni == NULL ? ENOENT : 0);
22732176cfdSRui Paulo }
22832176cfdSRui Paulo
22932176cfdSRui Paulo /*
23032176cfdSRui Paulo * Propagate multicast frames of an ap vap to all DWDS links.
23132176cfdSRui Paulo * The caller is assumed to have verified this frame is multicast.
23232176cfdSRui Paulo */
23332176cfdSRui Paulo void
ieee80211_dwds_mcast(struct ieee80211vap * vap0,struct mbuf * m)23432176cfdSRui Paulo ieee80211_dwds_mcast(struct ieee80211vap *vap0, struct mbuf *m)
23532176cfdSRui Paulo {
23632176cfdSRui Paulo struct ieee80211com *ic = vap0->iv_ic;
23732176cfdSRui Paulo const struct ether_header *eh = mtod(m, const struct ether_header *);
23832176cfdSRui Paulo struct ieee80211_node *ni;
23932176cfdSRui Paulo struct ieee80211vap *vap;
24032176cfdSRui Paulo struct ifnet *ifp;
24132176cfdSRui Paulo struct mbuf *mcopy;
24232176cfdSRui Paulo int err;
24332176cfdSRui Paulo
24432176cfdSRui Paulo KASSERT(ETHER_IS_MULTICAST(eh->ether_dhost),
245085ff963SMatthew Dillon ("%s not mcast", ether_sprintf(eh->ether_dhost)));
24632176cfdSRui Paulo
24732176cfdSRui Paulo /* XXX locking */
24832176cfdSRui Paulo TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
24932176cfdSRui Paulo /* only DWDS vaps are interesting */
25032176cfdSRui Paulo if (vap->iv_opmode != IEEE80211_M_WDS ||
25132176cfdSRui Paulo (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY))
25232176cfdSRui Paulo continue;
25332176cfdSRui Paulo /* if it came in this interface, don't send it back out */
25432176cfdSRui Paulo ifp = vap->iv_ifp;
25532176cfdSRui Paulo if (ifp == m->m_pkthdr.rcvif)
25632176cfdSRui Paulo continue;
25732176cfdSRui Paulo /*
25832176cfdSRui Paulo * Duplicate the frame and send it.
25932176cfdSRui Paulo */
260b5523eacSSascha Wildner mcopy = m_copypacket(m, M_NOWAIT);
26132176cfdSRui Paulo if (mcopy == NULL) {
262*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
26332176cfdSRui Paulo /* XXX stat + msg */
26432176cfdSRui Paulo continue;
26532176cfdSRui Paulo }
26632176cfdSRui Paulo ni = ieee80211_find_txnode(vap, eh->ether_dhost);
26732176cfdSRui Paulo if (ni == NULL) {
26832176cfdSRui Paulo /* NB: ieee80211_find_txnode does stat+msg */
269*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
27032176cfdSRui Paulo m_freem(mcopy);
27132176cfdSRui Paulo continue;
27232176cfdSRui Paulo }
27332176cfdSRui Paulo /* calculate priority so drivers can find the tx queue */
27432176cfdSRui Paulo if (ieee80211_classify(ni, mcopy)) {
27532176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap,
27632176cfdSRui Paulo IEEE80211_MSG_OUTPUT | IEEE80211_MSG_WDS,
27732176cfdSRui Paulo eh->ether_dhost, NULL,
27832176cfdSRui Paulo "%s", "classification failure");
27932176cfdSRui Paulo vap->iv_stats.is_tx_classify++;
280*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
28132176cfdSRui Paulo m_freem(mcopy);
28232176cfdSRui Paulo ieee80211_free_node(ni);
28332176cfdSRui Paulo continue;
28432176cfdSRui Paulo }
28532176cfdSRui Paulo
28632176cfdSRui Paulo BPF_MTAP(ifp, m); /* 802.3 tx */
28732176cfdSRui Paulo
28832176cfdSRui Paulo /*
28932176cfdSRui Paulo * Encapsulate the packet in prep for transmission.
29032176cfdSRui Paulo */
291*4f655ef5SMatthew Dillon IEEE80211_TX_LOCK(ic);
29232176cfdSRui Paulo mcopy = ieee80211_encap(vap, ni, mcopy);
29332176cfdSRui Paulo if (mcopy == NULL) {
29432176cfdSRui Paulo /* NB: stat+msg handled in ieee80211_encap */
295*4f655ef5SMatthew Dillon IEEE80211_TX_UNLOCK(ic);
29632176cfdSRui Paulo ieee80211_free_node(ni);
29732176cfdSRui Paulo continue;
29832176cfdSRui Paulo }
29932176cfdSRui Paulo mcopy->m_flags |= M_MCAST;
30032176cfdSRui Paulo mcopy->m_pkthdr.rcvif = (void *) ni;
30132176cfdSRui Paulo
302085ff963SMatthew Dillon err = ieee80211_parent_xmitpkt(ic, mcopy);
303*4f655ef5SMatthew Dillon IEEE80211_TX_UNLOCK(ic);
304*4f655ef5SMatthew Dillon if (!err) {
305*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
306*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_OMCASTS, 1);
307*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_OBYTES,
308*4f655ef5SMatthew Dillon m->m_pkthdr.len);
3094f898719SImre Vadász }
31032176cfdSRui Paulo }
31132176cfdSRui Paulo }
31232176cfdSRui Paulo
31332176cfdSRui Paulo /*
31432176cfdSRui Paulo * Handle DWDS discovery on receipt of a 4-address frame in
31532176cfdSRui Paulo * ap mode. Queue the frame and post an event for someone
31632176cfdSRui Paulo * to plumb the necessary WDS vap for this station. Frames
31732176cfdSRui Paulo * received prior to the vap set running will then be reprocessed
31832176cfdSRui Paulo * as if they were just received.
31932176cfdSRui Paulo */
32032176cfdSRui Paulo void
ieee80211_dwds_discover(struct ieee80211_node * ni,struct mbuf * m)32132176cfdSRui Paulo ieee80211_dwds_discover(struct ieee80211_node *ni, struct mbuf *m)
32232176cfdSRui Paulo {
32332176cfdSRui Paulo struct ieee80211com *ic = ni->ni_ic;
32432176cfdSRui Paulo
32532176cfdSRui Paulo /*
32632176cfdSRui Paulo * Save the frame with an aging interval 4 times
32732176cfdSRui Paulo * the listen interval specified by the station.
32832176cfdSRui Paulo * Frames that sit around too long are reclaimed
32932176cfdSRui Paulo * using this information.
33032176cfdSRui Paulo * XXX handle overflow?
33132176cfdSRui Paulo * XXX per/vap beacon interval?
33232176cfdSRui Paulo */
33332176cfdSRui Paulo m->m_pkthdr.rcvif = (void *)(uintptr_t)
33432176cfdSRui Paulo ieee80211_mac_hash(ic, ni->ni_macaddr);
33532176cfdSRui Paulo (void) ieee80211_ageq_append(&ic->ic_stageq, m,
33632176cfdSRui Paulo ((ni->ni_intval * ic->ic_lintval) << 2) / 1024);
33732176cfdSRui Paulo ieee80211_notify_wds_discover(ni);
33832176cfdSRui Paulo }
33932176cfdSRui Paulo
34032176cfdSRui Paulo /*
34132176cfdSRui Paulo * IEEE80211_M_WDS vap state machine handler.
34232176cfdSRui Paulo */
34332176cfdSRui Paulo static int
wds_newstate(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)34432176cfdSRui Paulo wds_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
34532176cfdSRui Paulo {
34632176cfdSRui Paulo struct ieee80211com *ic = vap->iv_ic;
347085ff963SMatthew Dillon struct ieee80211_node *ni;
34832176cfdSRui Paulo enum ieee80211_state ostate;
34932176cfdSRui Paulo int error;
35032176cfdSRui Paulo
351085ff963SMatthew Dillon IEEE80211_LOCK_ASSERT(ic);
352085ff963SMatthew Dillon
35332176cfdSRui Paulo ostate = vap->iv_state;
35432176cfdSRui Paulo IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s\n", __func__,
35532176cfdSRui Paulo ieee80211_state_name[ostate], ieee80211_state_name[nstate]);
35632176cfdSRui Paulo vap->iv_state = nstate; /* state transition */
357085ff963SMatthew Dillon callout_stop(&vap->iv_mgtsend); /* XXX callout_drain */
35832176cfdSRui Paulo if (ostate != IEEE80211_S_SCAN)
35932176cfdSRui Paulo ieee80211_cancel_scan(vap); /* background scan */
360085ff963SMatthew Dillon ni = vap->iv_bss; /* NB: no reference held */
36132176cfdSRui Paulo error = 0;
36232176cfdSRui Paulo switch (nstate) {
36332176cfdSRui Paulo case IEEE80211_S_INIT:
36432176cfdSRui Paulo switch (ostate) {
36532176cfdSRui Paulo case IEEE80211_S_SCAN:
36632176cfdSRui Paulo ieee80211_cancel_scan(vap);
36732176cfdSRui Paulo break;
36832176cfdSRui Paulo default:
36932176cfdSRui Paulo break;
37032176cfdSRui Paulo }
37132176cfdSRui Paulo if (ostate != IEEE80211_S_INIT) {
37232176cfdSRui Paulo /* NB: optimize INIT -> INIT case */
37332176cfdSRui Paulo ieee80211_reset_bss(vap);
37432176cfdSRui Paulo }
37532176cfdSRui Paulo break;
37632176cfdSRui Paulo case IEEE80211_S_SCAN:
37732176cfdSRui Paulo switch (ostate) {
37832176cfdSRui Paulo case IEEE80211_S_INIT:
37932176cfdSRui Paulo ieee80211_check_scan_current(vap);
38032176cfdSRui Paulo break;
38132176cfdSRui Paulo default:
38232176cfdSRui Paulo break;
38332176cfdSRui Paulo }
38432176cfdSRui Paulo break;
38532176cfdSRui Paulo case IEEE80211_S_RUN:
38632176cfdSRui Paulo if (ostate == IEEE80211_S_INIT) {
38732176cfdSRui Paulo /*
38832176cfdSRui Paulo * Already have a channel; bypass the scan
38932176cfdSRui Paulo * and startup immediately.
39032176cfdSRui Paulo */
39132176cfdSRui Paulo error = ieee80211_create_wds(vap, ic->ic_curchan);
39232176cfdSRui Paulo }
39332176cfdSRui Paulo break;
39432176cfdSRui Paulo default:
39532176cfdSRui Paulo break;
39632176cfdSRui Paulo }
39732176cfdSRui Paulo return error;
39832176cfdSRui Paulo }
39932176cfdSRui Paulo
40032176cfdSRui Paulo /*
40132176cfdSRui Paulo * Process a received frame. The node associated with the sender
40232176cfdSRui Paulo * should be supplied. If nothing was found in the node table then
40332176cfdSRui Paulo * the caller is assumed to supply a reference to iv_bss instead.
40432176cfdSRui Paulo * The RSSI and a timestamp are also supplied. The RSSI data is used
40532176cfdSRui Paulo * during AP scanning to select a AP to associate with; it can have
40632176cfdSRui Paulo * any units so long as values have consistent units and higher values
40732176cfdSRui Paulo * mean ``better signal''. The receive timestamp is currently not used
40832176cfdSRui Paulo * by the 802.11 layer.
40932176cfdSRui Paulo */
41032176cfdSRui Paulo static int
wds_input(struct ieee80211_node * ni,struct mbuf * m,const struct ieee80211_rx_stats * rxs,int rssi,int nf)4114f898719SImre Vadász wds_input(struct ieee80211_node *ni, struct mbuf *m,
4124f898719SImre Vadász const struct ieee80211_rx_stats *rxs, int rssi, int nf)
41332176cfdSRui Paulo {
41432176cfdSRui Paulo struct ieee80211vap *vap = ni->ni_vap;
41532176cfdSRui Paulo struct ieee80211com *ic = ni->ni_ic;
41632176cfdSRui Paulo struct ifnet *ifp = vap->iv_ifp;
41732176cfdSRui Paulo struct ieee80211_frame *wh;
41832176cfdSRui Paulo struct ieee80211_key *key;
41932176cfdSRui Paulo struct ether_header *eh;
42032176cfdSRui Paulo int hdrspace, need_tap = 1; /* mbuf need to be tapped. */
42132176cfdSRui Paulo uint8_t dir, type, subtype, qos;
422085ff963SMatthew Dillon
42332176cfdSRui Paulo if (m->m_flags & M_AMPDU_MPDU) {
42432176cfdSRui Paulo /*
42532176cfdSRui Paulo * Fastpath for A-MPDU reorder q resubmission. Frames
42632176cfdSRui Paulo * w/ M_AMPDU_MPDU marked have already passed through
42732176cfdSRui Paulo * here but were received out of order and been held on
42832176cfdSRui Paulo * the reorder queue. When resubmitted they are marked
42932176cfdSRui Paulo * with the M_AMPDU_MPDU flag and we can bypass most of
43032176cfdSRui Paulo * the normal processing.
43132176cfdSRui Paulo */
43232176cfdSRui Paulo wh = mtod(m, struct ieee80211_frame *);
43332176cfdSRui Paulo type = IEEE80211_FC0_TYPE_DATA;
43432176cfdSRui Paulo dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
43532176cfdSRui Paulo subtype = IEEE80211_FC0_SUBTYPE_QOS;
43632176cfdSRui Paulo hdrspace = ieee80211_hdrspace(ic, wh); /* XXX optimize? */
43732176cfdSRui Paulo goto resubmit_ampdu;
43832176cfdSRui Paulo }
43932176cfdSRui Paulo
44032176cfdSRui Paulo KASSERT(ni != NULL, ("null node"));
44132176cfdSRui Paulo
44232176cfdSRui Paulo type = -1; /* undefined */
44332176cfdSRui Paulo
44432176cfdSRui Paulo if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
44532176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
44632176cfdSRui Paulo ni->ni_macaddr, NULL,
44732176cfdSRui Paulo "too short (1): len %u", m->m_pkthdr.len);
44832176cfdSRui Paulo vap->iv_stats.is_rx_tooshort++;
44932176cfdSRui Paulo goto out;
45032176cfdSRui Paulo }
45132176cfdSRui Paulo /*
45232176cfdSRui Paulo * Bit of a cheat here, we use a pointer for a 3-address
45332176cfdSRui Paulo * frame format but don't reference fields past outside
45432176cfdSRui Paulo * ieee80211_frame_min w/o first validating the data is
45532176cfdSRui Paulo * present.
45632176cfdSRui Paulo */
45732176cfdSRui Paulo wh = mtod(m, struct ieee80211_frame *);
45832176cfdSRui Paulo
459085ff963SMatthew Dillon if (!IEEE80211_IS_MULTICAST(wh->i_addr1))
460085ff963SMatthew Dillon ni->ni_inact = ni->ni_inact_reload;
461085ff963SMatthew Dillon
46232176cfdSRui Paulo if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
46332176cfdSRui Paulo IEEE80211_FC0_VERSION_0) {
46432176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
46532176cfdSRui Paulo ni->ni_macaddr, NULL, "wrong version, fc %02x:%02x",
46632176cfdSRui Paulo wh->i_fc[0], wh->i_fc[1]);
46732176cfdSRui Paulo vap->iv_stats.is_rx_badversion++;
46832176cfdSRui Paulo goto err;
46932176cfdSRui Paulo }
47032176cfdSRui Paulo
47132176cfdSRui Paulo dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
47232176cfdSRui Paulo type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
47332176cfdSRui Paulo subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
47432176cfdSRui Paulo
47532176cfdSRui Paulo /* NB: WDS vap's do not scan */
47632176cfdSRui Paulo if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_addr4)) {
47732176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap,
47832176cfdSRui Paulo IEEE80211_MSG_ANY, ni->ni_macaddr, NULL,
47932176cfdSRui Paulo "too short (3): len %u", m->m_pkthdr.len);
48032176cfdSRui Paulo vap->iv_stats.is_rx_tooshort++;
48132176cfdSRui Paulo goto out;
48232176cfdSRui Paulo }
48332176cfdSRui Paulo /* NB: the TA is implicitly verified by finding the wds peer node */
48432176cfdSRui Paulo if (!IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr) &&
48532176cfdSRui Paulo !IEEE80211_ADDR_EQ(wh->i_addr1, ifp->if_broadcastaddr)) {
48632176cfdSRui Paulo /* not interested in */
48732176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
48832176cfdSRui Paulo wh->i_addr1, NULL, "%s", "not to bss");
48932176cfdSRui Paulo vap->iv_stats.is_rx_wrongbss++;
49032176cfdSRui Paulo goto out;
49132176cfdSRui Paulo }
49232176cfdSRui Paulo IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
49332176cfdSRui Paulo ni->ni_noise = nf;
4944f898719SImre Vadász if (IEEE80211_HAS_SEQ(type, subtype)) {
49532176cfdSRui Paulo uint8_t tid = ieee80211_gettid(wh);
49632176cfdSRui Paulo if (IEEE80211_QOS_HAS_SEQ(wh) &&
49732176cfdSRui Paulo TID_TO_WME_AC(tid) >= WME_AC_VI)
49832176cfdSRui Paulo ic->ic_wme.wme_hipri_traffic++;
499*4f655ef5SMatthew Dillon if (! ieee80211_check_rxseq(ni, wh, wh->i_addr1))
50032176cfdSRui Paulo goto out;
50132176cfdSRui Paulo }
50232176cfdSRui Paulo switch (type) {
50332176cfdSRui Paulo case IEEE80211_FC0_TYPE_DATA:
50432176cfdSRui Paulo hdrspace = ieee80211_hdrspace(ic, wh);
50532176cfdSRui Paulo if (m->m_len < hdrspace &&
50632176cfdSRui Paulo (m = m_pullup(m, hdrspace)) == NULL) {
50732176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
50832176cfdSRui Paulo ni->ni_macaddr, NULL,
50932176cfdSRui Paulo "data too short: expecting %u", hdrspace);
51032176cfdSRui Paulo vap->iv_stats.is_rx_tooshort++;
51132176cfdSRui Paulo goto out; /* XXX */
51232176cfdSRui Paulo }
51332176cfdSRui Paulo if (dir != IEEE80211_FC1_DIR_DSTODS) {
51432176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
51532176cfdSRui Paulo wh, "data", "incorrect dir 0x%x", dir);
51632176cfdSRui Paulo vap->iv_stats.is_rx_wrongdir++;
51732176cfdSRui Paulo goto out;
51832176cfdSRui Paulo }
51932176cfdSRui Paulo /*
52032176cfdSRui Paulo * Only legacy WDS traffic should take this path.
52132176cfdSRui Paulo */
52232176cfdSRui Paulo if ((vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0) {
52332176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
52432176cfdSRui Paulo wh, "data", "%s", "not legacy wds");
52532176cfdSRui Paulo vap->iv_stats.is_rx_wrongdir++;/*XXX*/
52632176cfdSRui Paulo goto out;
52732176cfdSRui Paulo }
52832176cfdSRui Paulo /*
52932176cfdSRui Paulo * Handle A-MPDU re-ordering. If the frame is to be
53032176cfdSRui Paulo * processed directly then ieee80211_ampdu_reorder
53132176cfdSRui Paulo * will return 0; otherwise it has consumed the mbuf
53232176cfdSRui Paulo * and we should do nothing more with it.
53332176cfdSRui Paulo */
53432176cfdSRui Paulo if ((m->m_flags & M_AMPDU) &&
53532176cfdSRui Paulo ieee80211_ampdu_reorder(ni, m) != 0) {
53632176cfdSRui Paulo m = NULL;
53732176cfdSRui Paulo goto out;
53832176cfdSRui Paulo }
53932176cfdSRui Paulo resubmit_ampdu:
54032176cfdSRui Paulo
54132176cfdSRui Paulo /*
54232176cfdSRui Paulo * Handle privacy requirements. Note that we
54332176cfdSRui Paulo * must not be preempted from here until after
54432176cfdSRui Paulo * we (potentially) call ieee80211_crypto_demic;
54532176cfdSRui Paulo * otherwise we may violate assumptions in the
54632176cfdSRui Paulo * crypto cipher modules used to do delayed update
54732176cfdSRui Paulo * of replay sequence numbers.
54832176cfdSRui Paulo */
549085ff963SMatthew Dillon if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
55032176cfdSRui Paulo if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
55132176cfdSRui Paulo /*
55232176cfdSRui Paulo * Discard encrypted frames when privacy is off.
55332176cfdSRui Paulo */
55432176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
55532176cfdSRui Paulo wh, "WEP", "%s", "PRIVACY off");
55632176cfdSRui Paulo vap->iv_stats.is_rx_noprivacy++;
55732176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_noprivacy);
55832176cfdSRui Paulo goto out;
55932176cfdSRui Paulo }
56032176cfdSRui Paulo key = ieee80211_crypto_decap(ni, m, hdrspace);
56132176cfdSRui Paulo if (key == NULL) {
56232176cfdSRui Paulo /* NB: stats+msgs handled in crypto_decap */
56332176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_wepfail);
56432176cfdSRui Paulo goto out;
56532176cfdSRui Paulo }
56632176cfdSRui Paulo wh = mtod(m, struct ieee80211_frame *);
567085ff963SMatthew Dillon wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED;
56832176cfdSRui Paulo } else {
56932176cfdSRui Paulo /* XXX M_WEP and IEEE80211_F_PRIVACY */
57032176cfdSRui Paulo key = NULL;
57132176cfdSRui Paulo }
57232176cfdSRui Paulo
57332176cfdSRui Paulo /*
57432176cfdSRui Paulo * Save QoS bits for use below--before we strip the header.
57532176cfdSRui Paulo */
57632176cfdSRui Paulo if (subtype == IEEE80211_FC0_SUBTYPE_QOS) {
57732176cfdSRui Paulo qos = (dir == IEEE80211_FC1_DIR_DSTODS) ?
57832176cfdSRui Paulo ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] :
57932176cfdSRui Paulo ((struct ieee80211_qosframe *)wh)->i_qos[0];
58032176cfdSRui Paulo } else
58132176cfdSRui Paulo qos = 0;
58232176cfdSRui Paulo
58332176cfdSRui Paulo /*
58432176cfdSRui Paulo * Next up, any fragmentation.
58532176cfdSRui Paulo */
58632176cfdSRui Paulo if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
58732176cfdSRui Paulo m = ieee80211_defrag(ni, m, hdrspace);
58832176cfdSRui Paulo if (m == NULL) {
58932176cfdSRui Paulo /* Fragment dropped or frame not complete yet */
59032176cfdSRui Paulo goto out;
59132176cfdSRui Paulo }
59232176cfdSRui Paulo }
59332176cfdSRui Paulo wh = NULL; /* no longer valid, catch any uses */
59432176cfdSRui Paulo
59532176cfdSRui Paulo /*
59632176cfdSRui Paulo * Next strip any MSDU crypto bits.
59732176cfdSRui Paulo */
59832176cfdSRui Paulo if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) {
59932176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
60032176cfdSRui Paulo ni->ni_macaddr, "data", "%s", "demic error");
60132176cfdSRui Paulo vap->iv_stats.is_rx_demicfail++;
60232176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_demicfail);
60332176cfdSRui Paulo goto out;
60432176cfdSRui Paulo }
60532176cfdSRui Paulo
60632176cfdSRui Paulo /* copy to listener after decrypt */
60732176cfdSRui Paulo if (ieee80211_radiotap_active_vap(vap))
60832176cfdSRui Paulo ieee80211_radiotap_rx(vap, m);
60932176cfdSRui Paulo need_tap = 0;
61032176cfdSRui Paulo
61132176cfdSRui Paulo /*
61232176cfdSRui Paulo * Finally, strip the 802.11 header.
61332176cfdSRui Paulo */
61432176cfdSRui Paulo m = ieee80211_decap(vap, m, hdrspace);
61532176cfdSRui Paulo if (m == NULL) {
61632176cfdSRui Paulo /* XXX mask bit to check for both */
61732176cfdSRui Paulo /* don't count Null data frames as errors */
61832176cfdSRui Paulo if (subtype == IEEE80211_FC0_SUBTYPE_NODATA ||
61932176cfdSRui Paulo subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL)
62032176cfdSRui Paulo goto out;
62132176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
62232176cfdSRui Paulo ni->ni_macaddr, "data", "%s", "decap error");
62332176cfdSRui Paulo vap->iv_stats.is_rx_decap++;
62432176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_decap);
62532176cfdSRui Paulo goto err;
62632176cfdSRui Paulo }
62732176cfdSRui Paulo eh = mtod(m, struct ether_header *);
62832176cfdSRui Paulo if (!ieee80211_node_is_authorized(ni)) {
62932176cfdSRui Paulo /*
63032176cfdSRui Paulo * Deny any non-PAE frames received prior to
63132176cfdSRui Paulo * authorization. For open/shared-key
63232176cfdSRui Paulo * authentication the port is mark authorized
63332176cfdSRui Paulo * after authentication completes. For 802.1x
63432176cfdSRui Paulo * the port is not marked authorized by the
63532176cfdSRui Paulo * authenticator until the handshake has completed.
63632176cfdSRui Paulo */
63732176cfdSRui Paulo if (eh->ether_type != htons(ETHERTYPE_PAE)) {
63832176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
63932176cfdSRui Paulo eh->ether_shost, "data",
64032176cfdSRui Paulo "unauthorized port: ether type 0x%x len %u",
64132176cfdSRui Paulo eh->ether_type, m->m_pkthdr.len);
64232176cfdSRui Paulo vap->iv_stats.is_rx_unauth++;
64332176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_unauth);
64432176cfdSRui Paulo goto err;
64532176cfdSRui Paulo }
64632176cfdSRui Paulo } else {
64732176cfdSRui Paulo /*
64832176cfdSRui Paulo * When denying unencrypted frames, discard
64932176cfdSRui Paulo * any non-PAE frames received without encryption.
65032176cfdSRui Paulo */
65132176cfdSRui Paulo if ((vap->iv_flags & IEEE80211_F_DROPUNENC) &&
65232176cfdSRui Paulo (key == NULL && (m->m_flags & M_WEP) == 0) &&
65332176cfdSRui Paulo eh->ether_type != htons(ETHERTYPE_PAE)) {
65432176cfdSRui Paulo /*
65532176cfdSRui Paulo * Drop unencrypted frames.
65632176cfdSRui Paulo */
65732176cfdSRui Paulo vap->iv_stats.is_rx_unencrypted++;
65832176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_unencrypted);
65932176cfdSRui Paulo goto out;
66032176cfdSRui Paulo }
66132176cfdSRui Paulo }
66232176cfdSRui Paulo /* XXX require HT? */
66332176cfdSRui Paulo if (qos & IEEE80211_QOS_AMSDU) {
66432176cfdSRui Paulo m = ieee80211_decap_amsdu(ni, m);
66532176cfdSRui Paulo if (m == NULL)
66632176cfdSRui Paulo return IEEE80211_FC0_TYPE_DATA;
66732176cfdSRui Paulo } else {
66832176cfdSRui Paulo #ifdef IEEE80211_SUPPORT_SUPERG
66932176cfdSRui Paulo m = ieee80211_decap_fastframe(vap, ni, m);
67032176cfdSRui Paulo if (m == NULL)
67132176cfdSRui Paulo return IEEE80211_FC0_TYPE_DATA;
67232176cfdSRui Paulo #endif
67332176cfdSRui Paulo }
67432176cfdSRui Paulo ieee80211_deliver_data(vap, ni, m);
67532176cfdSRui Paulo return IEEE80211_FC0_TYPE_DATA;
67632176cfdSRui Paulo
67732176cfdSRui Paulo case IEEE80211_FC0_TYPE_MGT:
67832176cfdSRui Paulo vap->iv_stats.is_rx_mgmt++;
67932176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_mgmt);
68032176cfdSRui Paulo if (dir != IEEE80211_FC1_DIR_NODS) {
68132176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
68232176cfdSRui Paulo wh, "data", "incorrect dir 0x%x", dir);
68332176cfdSRui Paulo vap->iv_stats.is_rx_wrongdir++;
68432176cfdSRui Paulo goto err;
68532176cfdSRui Paulo }
68632176cfdSRui Paulo if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
68732176cfdSRui Paulo IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
68832176cfdSRui Paulo ni->ni_macaddr, "mgt", "too short: len %u",
68932176cfdSRui Paulo m->m_pkthdr.len);
69032176cfdSRui Paulo vap->iv_stats.is_rx_tooshort++;
69132176cfdSRui Paulo goto out;
69232176cfdSRui Paulo }
69332176cfdSRui Paulo #ifdef IEEE80211_DEBUG
69432176cfdSRui Paulo if (ieee80211_msg_debug(vap) || ieee80211_msg_dumppkts(vap)) {
6951e290df3SAntonio Huete Jimenez if_printf(ifp, "received %s from %s rssi %d\n",
696*4f655ef5SMatthew Dillon ieee80211_mgt_subtype_name(subtype),
697085ff963SMatthew Dillon ether_sprintf(wh->i_addr2), rssi);
69832176cfdSRui Paulo }
69932176cfdSRui Paulo #endif
700085ff963SMatthew Dillon if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
70132176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
70232176cfdSRui Paulo wh, NULL, "%s", "WEP set but not permitted");
70332176cfdSRui Paulo vap->iv_stats.is_rx_mgtdiscard++; /* XXX */
70432176cfdSRui Paulo goto out;
70532176cfdSRui Paulo }
7064f898719SImre Vadász vap->iv_recv_mgmt(ni, m, subtype, rxs, rssi, nf);
70732176cfdSRui Paulo goto out;
70832176cfdSRui Paulo
70932176cfdSRui Paulo case IEEE80211_FC0_TYPE_CTL:
71032176cfdSRui Paulo vap->iv_stats.is_rx_ctl++;
71132176cfdSRui Paulo IEEE80211_NODE_STAT(ni, rx_ctrl);
71232176cfdSRui Paulo goto out;
71332176cfdSRui Paulo
71432176cfdSRui Paulo default:
71532176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
71632176cfdSRui Paulo wh, "bad", "frame type 0x%x", type);
71732176cfdSRui Paulo /* should not come here */
71832176cfdSRui Paulo break;
71932176cfdSRui Paulo }
72032176cfdSRui Paulo err:
721*4f655ef5SMatthew Dillon if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
72232176cfdSRui Paulo out:
72332176cfdSRui Paulo if (m != NULL) {
72432176cfdSRui Paulo if (need_tap && ieee80211_radiotap_active_vap(vap))
72532176cfdSRui Paulo ieee80211_radiotap_rx(vap, m);
72632176cfdSRui Paulo m_freem(m);
72732176cfdSRui Paulo }
72832176cfdSRui Paulo return type;
72932176cfdSRui Paulo }
73032176cfdSRui Paulo
73132176cfdSRui Paulo static void
wds_recv_mgmt(struct ieee80211_node * ni,struct mbuf * m0,int subtype,const struct ieee80211_rx_stats * rxs,int rssi,int nf)7324f898719SImre Vadász wds_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, int subtype,
7334f898719SImre Vadász const struct ieee80211_rx_stats *rxs, int rssi, int nf)
73432176cfdSRui Paulo {
73532176cfdSRui Paulo struct ieee80211vap *vap = ni->ni_vap;
73632176cfdSRui Paulo struct ieee80211com *ic = ni->ni_ic;
73732176cfdSRui Paulo struct ieee80211_frame *wh;
73832176cfdSRui Paulo u_int8_t *frm, *efrm;
73932176cfdSRui Paulo
74032176cfdSRui Paulo wh = mtod(m0, struct ieee80211_frame *);
74132176cfdSRui Paulo frm = (u_int8_t *)&wh[1];
74232176cfdSRui Paulo efrm = mtod(m0, u_int8_t *) + m0->m_len;
74332176cfdSRui Paulo switch (subtype) {
744085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_ACTION:
745085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_ACTION_NOACK:
746085ff963SMatthew Dillon if (ni == vap->iv_bss) {
747085ff963SMatthew Dillon IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
748085ff963SMatthew Dillon wh, NULL, "%s", "unknown node");
749085ff963SMatthew Dillon vap->iv_stats.is_rx_mgtdiscard++;
750085ff963SMatthew Dillon } else if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1)) {
751085ff963SMatthew Dillon /* NB: not interested in multicast frames. */
752085ff963SMatthew Dillon IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
753085ff963SMatthew Dillon wh, NULL, "%s", "not for us");
754085ff963SMatthew Dillon vap->iv_stats.is_rx_mgtdiscard++;
755085ff963SMatthew Dillon } else if (vap->iv_state != IEEE80211_S_RUN) {
756085ff963SMatthew Dillon IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
757085ff963SMatthew Dillon wh, NULL, "wrong state %s",
758085ff963SMatthew Dillon ieee80211_state_name[vap->iv_state]);
759085ff963SMatthew Dillon vap->iv_stats.is_rx_mgtdiscard++;
760085ff963SMatthew Dillon } else {
761085ff963SMatthew Dillon if (ieee80211_parse_action(ni, m0) == 0)
762085ff963SMatthew Dillon (void)ic->ic_recv_action(ni, wh, frm, efrm);
763085ff963SMatthew Dillon }
764085ff963SMatthew Dillon break;
765085ff963SMatthew Dillon
766085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
767085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
768085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
769085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
770085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
77132176cfdSRui Paulo case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
772*4f655ef5SMatthew Dillon case IEEE80211_FC0_SUBTYPE_TIMING_ADV:
77332176cfdSRui Paulo case IEEE80211_FC0_SUBTYPE_BEACON:
774085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_ATIM:
77532176cfdSRui Paulo case IEEE80211_FC0_SUBTYPE_DISASSOC:
776085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_AUTH:
777085ff963SMatthew Dillon case IEEE80211_FC0_SUBTYPE_DEAUTH:
778085ff963SMatthew Dillon IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
779085ff963SMatthew Dillon wh, NULL, "%s", "not handled");
78032176cfdSRui Paulo vap->iv_stats.is_rx_mgtdiscard++;
78132176cfdSRui Paulo break;
782085ff963SMatthew Dillon
78332176cfdSRui Paulo default:
78432176cfdSRui Paulo IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
78532176cfdSRui Paulo wh, "mgt", "subtype 0x%x not handled", subtype);
78632176cfdSRui Paulo vap->iv_stats.is_rx_badsubtype++;
78732176cfdSRui Paulo break;
78832176cfdSRui Paulo }
78932176cfdSRui Paulo }
790