xref: /freebsd/sys/net80211/ieee80211_input.c (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
11a1e1d21SSam Leffler /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni  *
47535e66aSSam Leffler  * Copyright (c) 2001 Atsushi Onoe
510ad9a77SSam Leffler  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
61a1e1d21SSam Leffler  * All rights reserved.
71a1e1d21SSam Leffler  *
81a1e1d21SSam Leffler  * Redistribution and use in source and binary forms, with or without
91a1e1d21SSam Leffler  * modification, are permitted provided that the following conditions
101a1e1d21SSam Leffler  * are met:
111a1e1d21SSam Leffler  * 1. Redistributions of source code must retain the above copyright
127535e66aSSam Leffler  *    notice, this list of conditions and the following disclaimer.
137535e66aSSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
147535e66aSSam Leffler  *    notice, this list of conditions and the following disclaimer in the
157535e66aSSam Leffler  *    documentation and/or other materials provided with the distribution.
161a1e1d21SSam Leffler  *
177535e66aSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
187535e66aSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
197535e66aSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
207535e66aSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
217535e66aSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
227535e66aSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237535e66aSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247535e66aSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257535e66aSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
267535e66aSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271a1e1d21SSam Leffler  */
281a1e1d21SSam Leffler 
291a1e1d21SSam Leffler #include <sys/cdefs.h>
301a1e1d21SSam Leffler __FBSDID("$FreeBSD$");
311a1e1d21SSam Leffler 
32b032f27cSSam Leffler #include "opt_wlan.h"
33b032f27cSSam Leffler 
341a1e1d21SSam Leffler #include <sys/param.h>
351a1e1d21SSam Leffler #include <sys/systm.h>
361a1e1d21SSam Leffler #include <sys/mbuf.h>
371a1e1d21SSam Leffler #include <sys/malloc.h>
381a1e1d21SSam Leffler #include <sys/endian.h>
39a0cc3f85SSam Leffler #include <sys/kernel.h>
401a1e1d21SSam Leffler 
418a1b9b6aSSam Leffler #include <sys/socket.h>
421a1e1d21SSam Leffler 
431a1e1d21SSam Leffler #include <net/ethernet.h>
44b032f27cSSam Leffler #include <net/if.h>
4576039bc8SGleb Smirnoff #include <net/if_var.h>
461a1e1d21SSam Leffler #include <net/if_llc.h>
47b032f27cSSam Leffler #include <net/if_media.h>
483d0d5b21SJustin Hibbits #include <net/if_private.h>
498a1b9b6aSSam Leffler #include <net/if_vlan_var.h>
501a1e1d21SSam Leffler 
511a1e1d21SSam Leffler #include <net80211/ieee80211_var.h>
52b032f27cSSam Leffler #include <net80211/ieee80211_input.h>
5359aa14a9SRui Paulo #ifdef IEEE80211_SUPPORT_MESH
5459aa14a9SRui Paulo #include <net80211/ieee80211_mesh.h>
5559aa14a9SRui Paulo #endif
561a1e1d21SSam Leffler 
571a1e1d21SSam Leffler #include <net/bpf.h>
581a1e1d21SSam Leffler 
59b032f27cSSam Leffler #ifdef INET
60b032f27cSSam Leffler #include <netinet/in.h>
61b032f27cSSam Leffler #include <net/ethernet.h>
628a1b9b6aSSam Leffler #endif
631a1e1d21SSam Leffler 
64864ab114SAdrian Chadd static void
65864ab114SAdrian Chadd ieee80211_process_mimo(struct ieee80211_node *ni, struct ieee80211_rx_stats *rx)
66864ab114SAdrian Chadd {
67864ab114SAdrian Chadd 	int i;
68864ab114SAdrian Chadd 
69864ab114SAdrian Chadd 	/* Verify the required MIMO bits are set */
70864ab114SAdrian Chadd 	if ((rx->r_flags & (IEEE80211_R_C_CHAIN | IEEE80211_R_C_NF | IEEE80211_R_C_RSSI)) !=
71864ab114SAdrian Chadd 	    (IEEE80211_R_C_CHAIN | IEEE80211_R_C_NF | IEEE80211_R_C_RSSI))
72864ab114SAdrian Chadd 		return;
73864ab114SAdrian Chadd 
74864ab114SAdrian Chadd 	/* XXX This assumes the MIMO radios have both ctl and ext chains */
75864ab114SAdrian Chadd 	for (i = 0; i < MIN(rx->c_chain, IEEE80211_MAX_CHAINS); i++) {
76864ab114SAdrian Chadd 		IEEE80211_RSSI_LPF(ni->ni_mimo_rssi_ctl[i], rx->c_rssi_ctl[i]);
77864ab114SAdrian Chadd 		IEEE80211_RSSI_LPF(ni->ni_mimo_rssi_ext[i], rx->c_rssi_ext[i]);
78864ab114SAdrian Chadd 	}
79864ab114SAdrian Chadd 
80864ab114SAdrian Chadd 	/* XXX This also assumes the MIMO radios have both ctl and ext chains */
81864ab114SAdrian Chadd 	for(i = 0; i < MIN(rx->c_chain, IEEE80211_MAX_CHAINS); i++) {
82864ab114SAdrian Chadd 		ni->ni_mimo_noise_ctl[i] = rx->c_nf_ctl[i];
83864ab114SAdrian Chadd 		ni->ni_mimo_noise_ext[i] = rx->c_nf_ext[i];
84864ab114SAdrian Chadd 	}
85864ab114SAdrian Chadd 	ni->ni_mimo_chains = rx->c_chain;
86864ab114SAdrian Chadd }
87864ab114SAdrian Chadd 
88864ab114SAdrian Chadd int
89bdc7291eSAndriy Voskoboinyk ieee80211_input_mimo(struct ieee80211_node *ni, struct mbuf *m)
90864ab114SAdrian Chadd {
91b86fd7bcSAdrian Chadd 	struct ieee80211_rx_stats rxs;
92b86fd7bcSAdrian Chadd 
93bdc7291eSAndriy Voskoboinyk 	/* try to read stats from mbuf */
94b86fd7bcSAdrian Chadd 	bzero(&rxs, sizeof(rxs));
95bdc7291eSAndriy Voskoboinyk 	if (ieee80211_get_rx_params(m, &rxs) != 0)
96bdc7291eSAndriy Voskoboinyk 		return (-1);
97b86fd7bcSAdrian Chadd 
98864ab114SAdrian Chadd 	/* XXX should assert IEEE80211_R_NF and IEEE80211_R_RSSI are set */
99b86fd7bcSAdrian Chadd 	ieee80211_process_mimo(ni, &rxs);
100b86fd7bcSAdrian Chadd 
101c79f192cSAdrian Chadd 	//return ieee80211_input(ni, m, rx->rssi, rx->nf);
102e97796e2SAdrian Chadd 	return ni->ni_vap->iv_input(ni, m, &rxs, rxs.c_rssi, rxs.c_nf);
103864ab114SAdrian Chadd }
104864ab114SAdrian Chadd 
105b032f27cSSam Leffler int
1065463c4a4SSam Leffler ieee80211_input_all(struct ieee80211com *ic, struct mbuf *m, int rssi, int nf)
107b032f27cSSam Leffler {
108864ab114SAdrian Chadd 	struct ieee80211_rx_stats rx;
109864ab114SAdrian Chadd 
110864ab114SAdrian Chadd 	rx.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI;
111e97796e2SAdrian Chadd 	rx.c_nf = nf;
112e97796e2SAdrian Chadd 	rx.c_rssi = rssi;
113bdc7291eSAndriy Voskoboinyk 
114bdc7291eSAndriy Voskoboinyk 	if (!ieee80211_add_rx_params(m, &rx))
115bdc7291eSAndriy Voskoboinyk 		return (-1);
116bdc7291eSAndriy Voskoboinyk 
117bdc7291eSAndriy Voskoboinyk 	return ieee80211_input_mimo_all(ic, m);
118864ab114SAdrian Chadd }
119864ab114SAdrian Chadd 
120864ab114SAdrian Chadd int
121bdc7291eSAndriy Voskoboinyk ieee80211_input_mimo_all(struct ieee80211com *ic, struct mbuf *m)
122864ab114SAdrian Chadd {
123b032f27cSSam Leffler 	struct ieee80211vap *vap;
124b032f27cSSam Leffler 	int type = -1;
125b032f27cSSam Leffler 
126e1cfcbcbSSam Leffler 	m->m_flags |= M_BCAST;		/* NB: mark for bpf tap'ing */
127e1cfcbcbSSam Leffler 
128b032f27cSSam Leffler 	/* XXX locking */
129b032f27cSSam Leffler 	TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
130b032f27cSSam Leffler 		struct ieee80211_node *ni;
131b032f27cSSam Leffler 		struct mbuf *mcopy;
132b032f27cSSam Leffler 
133c3655fa4SSam Leffler 		/* NB: could check for IFF_UP but this is cheaper */
134c3655fa4SSam Leffler 		if (vap->iv_state == IEEE80211_S_INIT)
135c3655fa4SSam Leffler 			continue;
136b032f27cSSam Leffler 		/*
137b032f27cSSam Leffler 		 * WDS vap's only receive directed traffic from the
138b032f27cSSam Leffler 		 * station at the ``far end''.  That traffic should
139b032f27cSSam Leffler 		 * be passed through the AP vap the station is associated
140b032f27cSSam Leffler 		 * to--so don't spam them with mcast frames.
141b032f27cSSam Leffler 		 */
142b032f27cSSam Leffler 		if (vap->iv_opmode == IEEE80211_M_WDS)
143b032f27cSSam Leffler 			continue;
144b032f27cSSam Leffler 		if (TAILQ_NEXT(vap, iv_next) != NULL) {
145b032f27cSSam Leffler 			/*
146b032f27cSSam Leffler 			 * Packet contents are changed by ieee80211_decap
147b032f27cSSam Leffler 			 * so do a deep copy of the packet.
148bdc7291eSAndriy Voskoboinyk 			 * NB: tags are copied too.
149b032f27cSSam Leffler 			 */
150bd29f817SBjoern A. Zeeb 			mcopy = m_dup(m, IEEE80211_M_NOWAIT);
151b032f27cSSam Leffler 			if (mcopy == NULL) {
152b032f27cSSam Leffler 				/* XXX stat+msg */
153b032f27cSSam Leffler 				continue;
1548a1b9b6aSSam Leffler 			}
155b032f27cSSam Leffler 		} else {
156b032f27cSSam Leffler 			mcopy = m;
157b032f27cSSam Leffler 			m = NULL;
1588a1b9b6aSSam Leffler 		}
159b032f27cSSam Leffler 		ni = ieee80211_ref_node(vap->iv_bss);
160bdc7291eSAndriy Voskoboinyk 		type = ieee80211_input_mimo(ni, mcopy);
161b032f27cSSam Leffler 		ieee80211_free_node(ni);
1621a1e1d21SSam Leffler 	}
163b032f27cSSam Leffler 	if (m != NULL)			/* no vaps, reclaim mbuf */
1641a1e1d21SSam Leffler 		m_freem(m);
1651f298879SSam Leffler 	return type;
1661a1e1d21SSam Leffler }
1671a1e1d21SSam Leffler 
1688a1b9b6aSSam Leffler /*
169df0d214aSRui Paulo  * This function reassembles fragments.
170b032f27cSSam Leffler  *
171b032f27cSSam Leffler  * XXX should handle 3 concurrent reassemblies per-spec.
1728a1b9b6aSSam Leffler  */
173b032f27cSSam Leffler struct mbuf *
17411572d7dSMathy Vanhoef ieee80211_defrag(struct ieee80211_node *ni, struct mbuf *m, int hdrspace,
17511572d7dSMathy Vanhoef 	int has_decrypted)
1761a1e1d21SSam Leffler {
177b032f27cSSam Leffler 	struct ieee80211vap *vap = ni->ni_vap;
1788a1b9b6aSSam Leffler 	struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
1798a1b9b6aSSam Leffler 	struct ieee80211_frame *lwh;
18068e8e04eSSam Leffler 	uint16_t rxseq;
18168e8e04eSSam Leffler 	uint8_t fragno;
18268e8e04eSSam Leffler 	uint8_t more_frag = wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG;
1838a1b9b6aSSam Leffler 	struct mbuf *mfrag;
1848a1b9b6aSSam Leffler 
1858a1b9b6aSSam Leffler 	KASSERT(!IEEE80211_IS_MULTICAST(wh->i_addr1), ("multicast fragm?"));
1868a1b9b6aSSam Leffler 
18768e8e04eSSam Leffler 	rxseq = le16toh(*(uint16_t *)wh->i_seq);
1888a1b9b6aSSam Leffler 	fragno = rxseq & IEEE80211_SEQ_FRAG_MASK;
1898a1b9b6aSSam Leffler 
1908a1b9b6aSSam Leffler 	/* Quick way out, if there's nothing to defragment */
1918a1b9b6aSSam Leffler 	if (!more_frag && fragno == 0 && ni->ni_rxfrag[0] == NULL)
1928a1b9b6aSSam Leffler 		return m;
1938a1b9b6aSSam Leffler 
19411572d7dSMathy Vanhoef 	/* Temporarily set flag to remember if fragment was encrypted. */
19511572d7dSMathy Vanhoef 	/* XXX use a non-packet altering storage for this in the future. */
19611572d7dSMathy Vanhoef 	if (has_decrypted)
19711572d7dSMathy Vanhoef 		wh->i_fc[1] |= IEEE80211_FC1_PROTECTED;
19811572d7dSMathy Vanhoef 
1998a1b9b6aSSam Leffler 	/*
2008a1b9b6aSSam Leffler 	 * Remove frag to insure it doesn't get reaped by timer.
2018a1b9b6aSSam Leffler 	 */
2028a1b9b6aSSam Leffler 	if (ni->ni_table == NULL) {
2038a1b9b6aSSam Leffler 		/*
2048a1b9b6aSSam Leffler 		 * Should never happen.  If the node is orphaned (not in
2058a1b9b6aSSam Leffler 		 * the table) then input packets should not reach here.
2068a1b9b6aSSam Leffler 		 * Otherwise, a concurrent request that yanks the table
2078a1b9b6aSSam Leffler 		 * should be blocked by other interlocking and/or by first
2088a1b9b6aSSam Leffler 		 * shutting the driver down.  Regardless, be defensive
2098a1b9b6aSSam Leffler 		 * here and just bail
2108a1b9b6aSSam Leffler 		 */
2118a1b9b6aSSam Leffler 		/* XXX need msg+stat */
2128a1b9b6aSSam Leffler 		m_freem(m);
2138a1b9b6aSSam Leffler 		return NULL;
2148a1b9b6aSSam Leffler 	}
2158a1b9b6aSSam Leffler 	IEEE80211_NODE_LOCK(ni->ni_table);
2168a1b9b6aSSam Leffler 	mfrag = ni->ni_rxfrag[0];
2178a1b9b6aSSam Leffler 	ni->ni_rxfrag[0] = NULL;
2188a1b9b6aSSam Leffler 	IEEE80211_NODE_UNLOCK(ni->ni_table);
2198a1b9b6aSSam Leffler 
2208a1b9b6aSSam Leffler 	/*
2218a1b9b6aSSam Leffler 	 * Validate new fragment is in order and
2228a1b9b6aSSam Leffler 	 * related to the previous ones.
2238a1b9b6aSSam Leffler 	 */
2248a1b9b6aSSam Leffler 	if (mfrag != NULL) {
22568e8e04eSSam Leffler 		uint16_t last_rxseq;
2268a1b9b6aSSam Leffler 
2278a1b9b6aSSam Leffler 		lwh = mtod(mfrag, struct ieee80211_frame *);
22868e8e04eSSam Leffler 		last_rxseq = le16toh(*(uint16_t *)lwh->i_seq);
22911572d7dSMathy Vanhoef 		/*
23011572d7dSMathy Vanhoef 		 * NB: check seq # and frag together. Also check that both
23111572d7dSMathy Vanhoef 		 * fragments are plaintext or that both are encrypted.
23211572d7dSMathy Vanhoef 		 */
2338722deefSAndriy Voskoboinyk 		if (rxseq == last_rxseq+1 &&
2348722deefSAndriy Voskoboinyk 		    IEEE80211_ADDR_EQ(wh->i_addr1, lwh->i_addr1) &&
23511572d7dSMathy Vanhoef 		    IEEE80211_ADDR_EQ(wh->i_addr2, lwh->i_addr2) &&
23611572d7dSMathy Vanhoef 		    !((wh->i_fc[1] ^ lwh->i_fc[1]) & IEEE80211_FC1_PROTECTED)) {
2378722deefSAndriy Voskoboinyk 			/* XXX clear MORE_FRAG bit? */
2388722deefSAndriy Voskoboinyk 			/* track last seqnum and fragno */
2398722deefSAndriy Voskoboinyk 			*(uint16_t *) lwh->i_seq = *(uint16_t *) wh->i_seq;
2408722deefSAndriy Voskoboinyk 
2418722deefSAndriy Voskoboinyk 			m_adj(m, hdrspace);		/* strip header */
2428722deefSAndriy Voskoboinyk 			m_catpkt(mfrag, m);		/* concatenate */
2438722deefSAndriy Voskoboinyk 		} else {
2448a1b9b6aSSam Leffler 			/*
2458a1b9b6aSSam Leffler 			 * Unrelated fragment or no space for it,
2468a1b9b6aSSam Leffler 			 * clear current fragments.
2478a1b9b6aSSam Leffler 			 */
2488a1b9b6aSSam Leffler 			m_freem(mfrag);
2498a1b9b6aSSam Leffler 			mfrag = NULL;
2508a1b9b6aSSam Leffler 		}
2518a1b9b6aSSam Leffler 	}
2528a1b9b6aSSam Leffler 
2538a1b9b6aSSam Leffler  	if (mfrag == NULL) {
2548a1b9b6aSSam Leffler 		if (fragno != 0) {		/* !first fragment, discard */
255b032f27cSSam Leffler 			vap->iv_stats.is_rx_defrag++;
2568a1b9b6aSSam Leffler 			IEEE80211_NODE_STAT(ni, rx_defrag);
2578a1b9b6aSSam Leffler 			m_freem(m);
2588a1b9b6aSSam Leffler 			return NULL;
2598a1b9b6aSSam Leffler 		}
2608a1b9b6aSSam Leffler 		mfrag = m;
2618a1b9b6aSSam Leffler 	}
2628a1b9b6aSSam Leffler 	if (more_frag) {			/* more to come, save */
263a0cc3f85SSam Leffler 		ni->ni_rxfragstamp = ticks;
2648a1b9b6aSSam Leffler 		ni->ni_rxfrag[0] = mfrag;
2658a1b9b6aSSam Leffler 		mfrag = NULL;
2668a1b9b6aSSam Leffler 	}
26711572d7dSMathy Vanhoef 	/* Remember to clear protected flag that was temporarily set. */
26811572d7dSMathy Vanhoef 	if (mfrag != NULL) {
26911572d7dSMathy Vanhoef 		wh = mtod(mfrag, struct ieee80211_frame *);
27011572d7dSMathy Vanhoef 		wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED;
27111572d7dSMathy Vanhoef 	}
2728a1b9b6aSSam Leffler 	return mfrag;
2738a1b9b6aSSam Leffler }
2748a1b9b6aSSam Leffler 
27568e8e04eSSam Leffler void
276b032f27cSSam Leffler ieee80211_deliver_data(struct ieee80211vap *vap,
2771bd482efSSam Leffler 	struct ieee80211_node *ni, struct mbuf *m)
2781bd482efSSam Leffler {
2791bd482efSSam Leffler 	struct ether_header *eh = mtod(m, struct ether_header *);
280b032f27cSSam Leffler 	struct ifnet *ifp = vap->iv_ifp;
2811bd482efSSam Leffler 
282e1cfcbcbSSam Leffler 	/* clear driver/net80211 flags before passing up */
28386bd0491SAndre Oppermann 	m->m_flags &= ~(M_MCAST | M_BCAST);
28486bd0491SAndre Oppermann 	m_clrprotoflags(m);
285e1cfcbcbSSam Leffler 
286b032f27cSSam Leffler 	/* NB: see hostap_deliver_data, this path doesn't handle hostap */
287b032f27cSSam Leffler 	KASSERT(vap->iv_opmode != IEEE80211_M_HOSTAP, ("gack, hostap"));
28806efa2f0SSam Leffler 	/*
28906efa2f0SSam Leffler 	 * Do accounting.
29006efa2f0SSam Leffler 	 */
291dea45121SGleb Smirnoff 	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
29206efa2f0SSam Leffler 	IEEE80211_NODE_STAT(ni, rx_data);
29306efa2f0SSam Leffler 	IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
29406efa2f0SSam Leffler 	if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
295eb81dc79SAdrian Chadd 		if (ETHER_IS_BROADCAST(eh->ether_dhost))
296eb81dc79SAdrian Chadd 			m->m_flags |= M_BCAST;
297eb81dc79SAdrian Chadd 		else
298eb81dc79SAdrian Chadd 			m->m_flags |= M_MCAST;
29906efa2f0SSam Leffler 		IEEE80211_NODE_STAT(ni, rx_mcast);
30006efa2f0SSam Leffler 	} else
30106efa2f0SSam Leffler 		IEEE80211_NODE_STAT(ni, rx_ucast);
302b032f27cSSam Leffler 	m->m_pkthdr.rcvif = ifp;
30306efa2f0SSam Leffler 
3041bd482efSSam Leffler 	if (ni->ni_vlan != 0) {
3051bd482efSSam Leffler 		/* attach vlan tag */
30678ba57b9SAndre Oppermann 		m->m_pkthdr.ether_vtag = ni->ni_vlan;
30778ba57b9SAndre Oppermann 		m->m_flags |= M_VLANTAG;
3081bd482efSSam Leffler 	}
309b032f27cSSam Leffler 	ifp->if_input(ifp, m);
3101bd482efSSam Leffler }
3111bd482efSSam Leffler 
312b032f27cSSam Leffler struct mbuf *
313f024bdf1SMathy Vanhoef ieee80211_decap(struct ieee80211vap *vap, struct mbuf *m, int hdrlen,
314f024bdf1SMathy Vanhoef 	uint8_t qos)
3158a1b9b6aSSam Leffler {
31659aa14a9SRui Paulo 	struct ieee80211_qosframe_addr4 wh;
3171a1e1d21SSam Leffler 	struct ether_header *eh;
3181a1e1d21SSam Leffler 	struct llc *llc;
3191a1e1d21SSam Leffler 
320c104cff2SRui Paulo 	KASSERT(hdrlen <= sizeof(wh),
321c104cff2SRui Paulo 	    ("hdrlen %d > max %zd", hdrlen, sizeof(wh)));
322c104cff2SRui Paulo 
3232cc12adeSSam Leffler 	if (m->m_len < hdrlen + sizeof(*llc) &&
3242cc12adeSSam Leffler 	    (m = m_pullup(m, hdrlen + sizeof(*llc))) == NULL) {
325c104cff2SRui Paulo 		vap->iv_stats.is_rx_tooshort++;
326c104cff2SRui Paulo 		/* XXX msg */
3271a1e1d21SSam Leffler 		return NULL;
3281a1e1d21SSam Leffler 	}
3292cc12adeSSam Leffler 	memcpy(&wh, mtod(m, caddr_t), hdrlen);
3302cc12adeSSam Leffler 	llc = (struct llc *)(mtod(m, caddr_t) + hdrlen);
3311a1e1d21SSam Leffler 	if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP &&
3321a1e1d21SSam Leffler 	    llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 &&
3336bbdc701SSam Leffler 	    llc->llc_snap.org_code[1] == 0 && llc->llc_snap.org_code[2] == 0 &&
3346bbdc701SSam Leffler 	    /* NB: preserve AppleTalk frames that have a native SNAP hdr */
3356bbdc701SSam Leffler 	    !(llc->llc_snap.ether_type == htons(ETHERTYPE_AARP) ||
336f024bdf1SMathy Vanhoef 	      llc->llc_snap.ether_type == htons(ETHERTYPE_IPX)) &&
337f024bdf1SMathy Vanhoef 	    /* Do not want to touch A-MSDU frames. */
338f024bdf1SMathy Vanhoef 	    !(qos & IEEE80211_QOS_AMSDU)) {
339ab96db10SSam Leffler 		m_adj(m, hdrlen + sizeof(struct llc) - sizeof(*eh));
3401a1e1d21SSam Leffler 		llc = NULL;
3411a1e1d21SSam Leffler 	} else {
3422cc12adeSSam Leffler 		m_adj(m, hdrlen - sizeof(*eh));
3431a1e1d21SSam Leffler 	}
3441a1e1d21SSam Leffler 	eh = mtod(m, struct ether_header *);
3451a1e1d21SSam Leffler 	switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) {
3461a1e1d21SSam Leffler 	case IEEE80211_FC1_DIR_NODS:
3471a1e1d21SSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
3481a1e1d21SSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr2);
3491a1e1d21SSam Leffler 		break;
3501a1e1d21SSam Leffler 	case IEEE80211_FC1_DIR_TODS:
3511a1e1d21SSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr3);
3521a1e1d21SSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr2);
3531a1e1d21SSam Leffler 		break;
3541a1e1d21SSam Leffler 	case IEEE80211_FC1_DIR_FROMDS:
3551a1e1d21SSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
3561a1e1d21SSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr3);
3571a1e1d21SSam Leffler 		break;
3581a1e1d21SSam Leffler 	case IEEE80211_FC1_DIR_DSTODS:
3592cc12adeSSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr3);
3602cc12adeSSam Leffler 		IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr4);
3612cc12adeSSam Leffler 		break;
3621a1e1d21SSam Leffler 	}
36323f4fd6dSGleb Smirnoff #ifndef __NO_STRICT_ALIGNMENT
36468e8e04eSSam Leffler 	if (!ALIGNED_POINTER(mtod(m, caddr_t) + sizeof(*eh), uint32_t)) {
365519f677aSSam Leffler 		m = ieee80211_realign(vap, m, sizeof(*eh));
366519f677aSSam Leffler 		if (m == NULL)
3671a1e1d21SSam Leffler 			return NULL;
3681a1e1d21SSam Leffler 	}
36923f4fd6dSGleb Smirnoff #endif /* !__NO_STRICT_ALIGNMENT */
3701a1e1d21SSam Leffler 	if (llc != NULL) {
3711a1e1d21SSam Leffler 		eh = mtod(m, struct ether_header *);
3721a1e1d21SSam Leffler 		eh->ether_type = htons(m->m_pkthdr.len - sizeof(*eh));
3731a1e1d21SSam Leffler 	}
3741a1e1d21SSam Leffler 	return m;
3751a1e1d21SSam Leffler }
3761a1e1d21SSam Leffler 
3771a1e1d21SSam Leffler /*
37868e8e04eSSam Leffler  * Decap a frame encapsulated in a fast-frame/A-MSDU.
37968e8e04eSSam Leffler  */
38068e8e04eSSam Leffler struct mbuf *
38168e8e04eSSam Leffler ieee80211_decap1(struct mbuf *m, int *framelen)
38268e8e04eSSam Leffler {
38368e8e04eSSam Leffler #define	FF_LLC_SIZE	(sizeof(struct ether_header) + sizeof(struct llc))
38468e8e04eSSam Leffler 	struct ether_header *eh;
38568e8e04eSSam Leffler 	struct llc *llc;
386f024bdf1SMathy Vanhoef 	const uint8_t llc_hdr_mac[ETHER_ADDR_LEN] = {
387f024bdf1SMathy Vanhoef 		/* MAC address matching the 802.2 LLC header */
388f024bdf1SMathy Vanhoef 		LLC_SNAP_LSAP, LLC_SNAP_LSAP, LLC_UI, 0, 0, 0
389f024bdf1SMathy Vanhoef 	};
39068e8e04eSSam Leffler 
39168e8e04eSSam Leffler 	/*
39268e8e04eSSam Leffler 	 * The frame has an 802.3 header followed by an 802.2
39368e8e04eSSam Leffler 	 * LLC header.  The encapsulated frame length is in the
39468e8e04eSSam Leffler 	 * first header type field; save that and overwrite it
39568e8e04eSSam Leffler 	 * with the true type field found in the second.  Then
39668e8e04eSSam Leffler 	 * copy the 802.3 header up to where it belongs and
39768e8e04eSSam Leffler 	 * adjust the mbuf contents to remove the void.
39868e8e04eSSam Leffler 	 */
39968e8e04eSSam Leffler 	if (m->m_len < FF_LLC_SIZE && (m = m_pullup(m, FF_LLC_SIZE)) == NULL)
40068e8e04eSSam Leffler 		return NULL;
40168e8e04eSSam Leffler 	eh = mtod(m, struct ether_header *);	/* 802.3 header is first */
402f024bdf1SMathy Vanhoef 
403f024bdf1SMathy Vanhoef 	/*
404f024bdf1SMathy Vanhoef 	 * Detect possible attack where a single 802.11 frame is processed
405f024bdf1SMathy Vanhoef 	 * as an A-MSDU frame due to an adversary setting the A-MSDU present
406f024bdf1SMathy Vanhoef 	 * bit in the 802.11 QoS header. [FragAttacks]
407f024bdf1SMathy Vanhoef 	 */
408f024bdf1SMathy Vanhoef 	if (memcmp(eh->ether_dhost, llc_hdr_mac, ETHER_ADDR_LEN) == 0)
409f024bdf1SMathy Vanhoef 		return NULL;
410f024bdf1SMathy Vanhoef 
41168e8e04eSSam Leffler 	llc = (struct llc *)&eh[1];		/* 802.2 header follows */
41268e8e04eSSam Leffler 	*framelen = ntohs(eh->ether_type)	/* encap'd frame size */
41368e8e04eSSam Leffler 		  + sizeof(struct ether_header) - sizeof(struct llc);
41468e8e04eSSam Leffler 	eh->ether_type = llc->llc_un.type_snap.ether_type;
41568e8e04eSSam Leffler 	ovbcopy(eh, mtod(m, uint8_t *) + sizeof(struct llc),
41668e8e04eSSam Leffler 		sizeof(struct ether_header));
41768e8e04eSSam Leffler 	m_adj(m, sizeof(struct llc));
41868e8e04eSSam Leffler 	return m;
41968e8e04eSSam Leffler #undef FF_LLC_SIZE
42068e8e04eSSam Leffler }
42168e8e04eSSam Leffler 
42268e8e04eSSam Leffler /*
4231a1e1d21SSam Leffler  * Install received rate set information in the node's state block.
4241a1e1d21SSam Leffler  */
4257d77cd53SSam Leffler int
4267d77cd53SSam Leffler ieee80211_setup_rates(struct ieee80211_node *ni,
42768e8e04eSSam Leffler 	const uint8_t *rates, const uint8_t *xrates, int flags)
4281a1e1d21SSam Leffler {
429b032f27cSSam Leffler 	struct ieee80211vap *vap = ni->ni_vap;
4301a1e1d21SSam Leffler 	struct ieee80211_rateset *rs = &ni->ni_rates;
4311a1e1d21SSam Leffler 
4321a1e1d21SSam Leffler 	memset(rs, 0, sizeof(*rs));
4331a1e1d21SSam Leffler 	rs->rs_nrates = rates[1];
4341a1e1d21SSam Leffler 	memcpy(rs->rs_rates, rates + 2, rs->rs_nrates);
4351a1e1d21SSam Leffler 	if (xrates != NULL) {
43668e8e04eSSam Leffler 		uint8_t nxrates;
4371a1e1d21SSam Leffler 		/*
4381a1e1d21SSam Leffler 		 * Tack on 11g extended supported rate element.
4391a1e1d21SSam Leffler 		 */
4401a1e1d21SSam Leffler 		nxrates = xrates[1];
4411a1e1d21SSam Leffler 		if (rs->rs_nrates + nxrates > IEEE80211_RATE_MAXSIZE) {
4421a1e1d21SSam Leffler 			nxrates = IEEE80211_RATE_MAXSIZE - rs->rs_nrates;
443b032f27cSSam Leffler 			IEEE80211_NOTE(vap, IEEE80211_MSG_XRATE, ni,
444b032f27cSSam Leffler 			    "extended rate set too large; only using "
445b032f27cSSam Leffler 			    "%u of %u rates", nxrates, xrates[1]);
446b032f27cSSam Leffler 			vap->iv_stats.is_rx_rstoobig++;
4471a1e1d21SSam Leffler 		}
4481a1e1d21SSam Leffler 		memcpy(rs->rs_rates + rs->rs_nrates, xrates+2, nxrates);
4491a1e1d21SSam Leffler 		rs->rs_nrates += nxrates;
4501a1e1d21SSam Leffler 	}
45170e28b9aSSam Leffler 	return ieee80211_fix_rate(ni, rs, flags);
4521a1e1d21SSam Leffler }
4531a1e1d21SSam Leffler 
45484eb84c4SSam Leffler /*
45584eb84c4SSam Leffler  * Send a management frame error response to the specified
45684eb84c4SSam Leffler  * station.  If ni is associated with the station then use
45784eb84c4SSam Leffler  * it; otherwise allocate a temporary node suitable for
45884eb84c4SSam Leffler  * transmitting the frame and then free the reference so
45984eb84c4SSam Leffler  * it will go away as soon as the frame has been transmitted.
46084eb84c4SSam Leffler  */
461b032f27cSSam Leffler void
462b032f27cSSam Leffler ieee80211_send_error(struct ieee80211_node *ni,
463b032f27cSSam Leffler 	const uint8_t mac[IEEE80211_ADDR_LEN], int subtype, int arg)
46484eb84c4SSam Leffler {
465b032f27cSSam Leffler 	struct ieee80211vap *vap = ni->ni_vap;
46684eb84c4SSam Leffler 	int istmp;
46784eb84c4SSam Leffler 
468b032f27cSSam Leffler 	if (ni == vap->iv_bss) {
469b032f27cSSam Leffler 		if (vap->iv_state != IEEE80211_S_RUN) {
470b032f27cSSam Leffler 			/*
471b032f27cSSam Leffler 			 * XXX hack until we get rid of this routine.
472b032f27cSSam Leffler 			 * We can be called prior to the vap reaching
473b032f27cSSam Leffler 			 * run state under certain conditions in which
474b032f27cSSam Leffler 			 * case iv_bss->ni_chan will not be setup.
475b032f27cSSam Leffler 			 * Check for this explicitly and and just ignore
476b032f27cSSam Leffler 			 * the request.
477b032f27cSSam Leffler 			 */
478b032f27cSSam Leffler 			return;
479b032f27cSSam Leffler 		}
480b032f27cSSam Leffler 		ni = ieee80211_tmp_node(vap, mac);
48184eb84c4SSam Leffler 		if (ni == NULL) {
48284eb84c4SSam Leffler 			/* XXX msg */
48384eb84c4SSam Leffler 			return;
48484eb84c4SSam Leffler 		}
48584eb84c4SSam Leffler 		istmp = 1;
48684eb84c4SSam Leffler 	} else
48784eb84c4SSam Leffler 		istmp = 0;
488b032f27cSSam Leffler 	IEEE80211_SEND_MGMT(ni, subtype, arg);
48984eb84c4SSam Leffler 	if (istmp)
49084eb84c4SSam Leffler 		ieee80211_free_node(ni);
49184eb84c4SSam Leffler }
49284eb84c4SSam Leffler 
493b032f27cSSam Leffler int
494b032f27cSSam Leffler ieee80211_alloc_challenge(struct ieee80211_node *ni)
4958a1b9b6aSSam Leffler {
4968a1b9b6aSSam Leffler 	if (ni->ni_challenge == NULL)
497b9b53389SAdrian Chadd 		ni->ni_challenge = (uint32_t *)
498b9b53389SAdrian Chadd 		    IEEE80211_MALLOC(IEEE80211_CHALLENGE_LEN,
499b9b53389SAdrian Chadd 		      M_80211_NODE, IEEE80211_M_NOWAIT);
5008a1b9b6aSSam Leffler 	if (ni->ni_challenge == NULL) {
501b032f27cSSam Leffler 		IEEE80211_NOTE(ni->ni_vap,
502b032f27cSSam Leffler 		    IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, ni,
503b032f27cSSam Leffler 		    "%s", "shared key challenge alloc failed");
5048a1b9b6aSSam Leffler 		/* XXX statistic */
5058a1b9b6aSSam Leffler 	}
5068a1b9b6aSSam Leffler 	return (ni->ni_challenge != NULL);
5078a1b9b6aSSam Leffler }
5088a1b9b6aSSam Leffler 
50966ef3969SSam Leffler /*
510b032f27cSSam Leffler  * Parse a Beacon or ProbeResponse frame and return the
511b032f27cSSam Leffler  * useful information in an ieee80211_scanparams structure.
512b032f27cSSam Leffler  * Status is set to 0 if no problems were found; otherwise
513b032f27cSSam Leffler  * a bitmask of IEEE80211_BPARSE_* items is returned that
514b032f27cSSam Leffler  * describes the problems detected.
51566ef3969SSam Leffler  */
516b032f27cSSam Leffler int
517b032f27cSSam Leffler ieee80211_parse_beacon(struct ieee80211_node *ni, struct mbuf *m,
518c79f192cSAdrian Chadd 	struct ieee80211_channel *rxchan, struct ieee80211_scanparams *scan)
51966ef3969SSam Leffler {
520b032f27cSSam Leffler 	struct ieee80211vap *vap = ni->ni_vap;
52166ef3969SSam Leffler 	struct ieee80211com *ic = ni->ni_ic;
5221a1e1d21SSam Leffler 	struct ieee80211_frame *wh;
52368e8e04eSSam Leffler 	uint8_t *frm, *efrm;
5241a1e1d21SSam Leffler 
525b032f27cSSam Leffler 	wh = mtod(m, struct ieee80211_frame *);
52668e8e04eSSam Leffler 	frm = (uint8_t *)&wh[1];
527b032f27cSSam Leffler 	efrm = mtod(m, uint8_t *) + m->m_len;
528b032f27cSSam Leffler 	scan->status = 0;
5291a1e1d21SSam Leffler 	/*
5301a1e1d21SSam Leffler 	 * beacon/probe response frame format
53151172f62SAdrian Chadd 	 *
53251172f62SAdrian Chadd 	 * XXX Update from 802.11-2012 - eg where HT is
5331a1e1d21SSam Leffler 	 *	[8] time stamp
5341a1e1d21SSam Leffler 	 *	[2] beacon interval
5351a1e1d21SSam Leffler 	 *	[2] capability information
5361a1e1d21SSam Leffler 	 *	[tlv] ssid
5371a1e1d21SSam Leffler 	 *	[tlv] supported rates
5381a1e1d21SSam Leffler 	 *	[tlv] country information
539c70761e6SSam Leffler 	 *	[tlv] channel switch announcement (CSA)
5401a1e1d21SSam Leffler 	 *	[tlv] parameter set (FH/DS)
5411a1e1d21SSam Leffler 	 *	[tlv] erp information
5421a1e1d21SSam Leffler 	 *	[tlv] extended supported rates
5438a1b9b6aSSam Leffler 	 *	[tlv] WME
5448a1b9b6aSSam Leffler 	 *	[tlv] WPA or RSN
54568e8e04eSSam Leffler 	 *	[tlv] HT capabilities
54668e8e04eSSam Leffler 	 *	[tlv] HT information
54751172f62SAdrian Chadd 	 *	[tlv] VHT capabilities
54851172f62SAdrian Chadd 	 *	[tlv] VHT information
54968e8e04eSSam Leffler 	 *	[tlv] Atheros capabilities
55059aa14a9SRui Paulo 	 *	[tlv] Mesh ID
55159aa14a9SRui Paulo 	 *	[tlv] Mesh Configuration
5521a1e1d21SSam Leffler 	 */
553b032f27cSSam Leffler 	IEEE80211_VERIFY_LENGTH(efrm - frm, 12,
554b032f27cSSam Leffler 	    return (scan->status = IEEE80211_BPARSE_BADIELEN));
555b032f27cSSam Leffler 	memset(scan, 0, sizeof(*scan));
556b032f27cSSam Leffler 	scan->tstamp  = frm;				frm += 8;
557b032f27cSSam Leffler 	scan->bintval = le16toh(*(uint16_t *)frm);	frm += 2;
558b032f27cSSam Leffler 	scan->capinfo = le16toh(*(uint16_t *)frm);	frm += 2;
559c79f192cSAdrian Chadd 	scan->bchan = ieee80211_chan2ieee(ic, rxchan);
560b032f27cSSam Leffler 	scan->chan = scan->bchan;
561b032f27cSSam Leffler 	scan->ies = frm;
562b032f27cSSam Leffler 	scan->ies_len = efrm - frm;
563b5c99415SSam Leffler 
56470326a6eSSam Leffler 	while (efrm - frm > 1) {
565b032f27cSSam Leffler 		IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2,
566b032f27cSSam Leffler 		    return (scan->status = IEEE80211_BPARSE_BADIELEN));
5671a1e1d21SSam Leffler 		switch (*frm) {
5681a1e1d21SSam Leffler 		case IEEE80211_ELEMID_SSID:
569b032f27cSSam Leffler 			scan->ssid = frm;
5701a1e1d21SSam Leffler 			break;
5711a1e1d21SSam Leffler 		case IEEE80211_ELEMID_RATES:
572b032f27cSSam Leffler 			scan->rates = frm;
5731a1e1d21SSam Leffler 			break;
5741a1e1d21SSam Leffler 		case IEEE80211_ELEMID_COUNTRY:
575b032f27cSSam Leffler 			scan->country = frm;
5761a1e1d21SSam Leffler 			break;
577c70761e6SSam Leffler 		case IEEE80211_ELEMID_CSA:
578c70761e6SSam Leffler 			scan->csa = frm;
579c70761e6SSam Leffler 			break;
58032b0e64bSAdrian Chadd 		case IEEE80211_ELEMID_QUIET:
58132b0e64bSAdrian Chadd 			scan->quiet = frm;
58232b0e64bSAdrian Chadd 			break;
5831a1e1d21SSam Leffler 		case IEEE80211_ELEMID_FHPARMS:
5841a1e1d21SSam Leffler 			if (ic->ic_phytype == IEEE80211_T_FH) {
58531021a2bSAndriy Voskoboinyk 				scan->fhdwell = le16dec(&frm[2]);
586b032f27cSSam Leffler 				scan->chan = IEEE80211_FH_CHAN(frm[4], frm[5]);
587b032f27cSSam Leffler 				scan->fhindex = frm[6];
5881a1e1d21SSam Leffler 			}
5891a1e1d21SSam Leffler 			break;
5901a1e1d21SSam Leffler 		case IEEE80211_ELEMID_DSPARMS:
5911a1e1d21SSam Leffler 			/*
5921a1e1d21SSam Leffler 			 * XXX hack this since depending on phytype
5931a1e1d21SSam Leffler 			 * is problematic for multi-mode devices.
5941a1e1d21SSam Leffler 			 */
5951a1e1d21SSam Leffler 			if (ic->ic_phytype != IEEE80211_T_FH)
596b032f27cSSam Leffler 				scan->chan = frm[2];
5971a1e1d21SSam Leffler 			break;
5981a1e1d21SSam Leffler 		case IEEE80211_ELEMID_TIM:
5998a1b9b6aSSam Leffler 			/* XXX ATIM? */
600b032f27cSSam Leffler 			scan->tim = frm;
601b032f27cSSam Leffler 			scan->timoff = frm - mtod(m, uint8_t *);
6021a1e1d21SSam Leffler 			break;
6034bd067c5SSam Leffler 		case IEEE80211_ELEMID_IBSSPARMS:
604b032f27cSSam Leffler 		case IEEE80211_ELEMID_CFPARMS:
605643024a2SSam Leffler 		case IEEE80211_ELEMID_PWRCNSTR:
606523210fbSAdrian Chadd 		case IEEE80211_ELEMID_BSSLOAD:
607523210fbSAdrian Chadd 		case IEEE80211_ELEMID_APCHANREP:
608b032f27cSSam Leffler 			/* NB: avoid debugging complaints */
6094bd067c5SSam Leffler 			break;
6101a1e1d21SSam Leffler 		case IEEE80211_ELEMID_XRATES:
611b032f27cSSam Leffler 			scan->xrates = frm;
6121a1e1d21SSam Leffler 			break;
6131a1e1d21SSam Leffler 		case IEEE80211_ELEMID_ERP:
6141a1e1d21SSam Leffler 			if (frm[1] != 1) {
615b032f27cSSam Leffler 				IEEE80211_DISCARD_IE(vap,
6168a1b9b6aSSam Leffler 				    IEEE80211_MSG_ELEMID, wh, "ERP",
6178a1b9b6aSSam Leffler 				    "bad len %u", frm[1]);
618b032f27cSSam Leffler 				vap->iv_stats.is_rx_elem_toobig++;
6191a1e1d21SSam Leffler 				break;
6201a1e1d21SSam Leffler 			}
621b032f27cSSam Leffler 			scan->erp = frm[2] | 0x100;
6221a1e1d21SSam Leffler 			break;
62368e8e04eSSam Leffler 		case IEEE80211_ELEMID_HTCAP:
624b032f27cSSam Leffler 			scan->htcap = frm;
62568e8e04eSSam Leffler 			break;
62651172f62SAdrian Chadd 		case IEEE80211_ELEMID_VHT_CAP:
62751172f62SAdrian Chadd 			scan->vhtcap = frm;
62851172f62SAdrian Chadd 			break;
62951172f62SAdrian Chadd 		case IEEE80211_ELEMID_VHT_OPMODE:
63051172f62SAdrian Chadd 			scan->vhtopmode = frm;
63151172f62SAdrian Chadd 			break;
6328a1b9b6aSSam Leffler 		case IEEE80211_ELEMID_RSN:
633b032f27cSSam Leffler 			scan->rsn = frm;
63468e8e04eSSam Leffler 			break;
63568e8e04eSSam Leffler 		case IEEE80211_ELEMID_HTINFO:
636b032f27cSSam Leffler 			scan->htinfo = frm;
6378a1b9b6aSSam Leffler 			break;
638fbe007daSRui Paulo #ifdef IEEE80211_SUPPORT_MESH
63959aa14a9SRui Paulo 		case IEEE80211_ELEMID_MESHID:
64059aa14a9SRui Paulo 			scan->meshid = frm;
64159aa14a9SRui Paulo 			break;
64259aa14a9SRui Paulo 		case IEEE80211_ELEMID_MESHCONF:
64359aa14a9SRui Paulo 			scan->meshconf = frm;
64459aa14a9SRui Paulo 			break;
64559aa14a9SRui Paulo #endif
646f3e24d74SAdrian Chadd 		/* Extended capabilities; nothing handles it for now */
647f3e24d74SAdrian Chadd 		case IEEE80211_ELEMID_EXTCAP:
648f3e24d74SAdrian Chadd 			break;
6498a1b9b6aSSam Leffler 		case IEEE80211_ELEMID_VENDOR:
6508a1b9b6aSSam Leffler 			if (iswpaoui(frm))
651b032f27cSSam Leffler 				scan->wpa = frm;
6528a1b9b6aSSam Leffler 			else if (iswmeparam(frm) || iswmeinfo(frm))
653b032f27cSSam Leffler 				scan->wme = frm;
654616190d0SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG
65568e8e04eSSam Leffler 			else if (isatherosoui(frm))
656b032f27cSSam Leffler 				scan->ath = frm;
657616190d0SSam Leffler #endif
65810ad9a77SSam Leffler #ifdef IEEE80211_SUPPORT_TDMA
65910ad9a77SSam Leffler 			else if (istdmaoui(frm))
66010ad9a77SSam Leffler 				scan->tdma = frm;
66110ad9a77SSam Leffler #endif
6622bfc8a91SSam Leffler 			else if (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) {
66368e8e04eSSam Leffler 				/*
66468e8e04eSSam Leffler 				 * Accept pre-draft HT ie's if the
66568e8e04eSSam Leffler 				 * standard ones have not been seen.
66668e8e04eSSam Leffler 				 */
66768e8e04eSSam Leffler 				if (ishtcapoui(frm)) {
668b032f27cSSam Leffler 					if (scan->htcap == NULL)
669b032f27cSSam Leffler 						scan->htcap = frm;
67068e8e04eSSam Leffler 				} else if (ishtinfooui(frm)) {
671b032f27cSSam Leffler 					if (scan->htinfo == NULL)
672b032f27cSSam Leffler 						scan->htcap = frm;
67368e8e04eSSam Leffler 				}
67468e8e04eSSam Leffler 			}
6758a1b9b6aSSam Leffler 			break;
6761a1e1d21SSam Leffler 		default:
677b032f27cSSam Leffler 			IEEE80211_DISCARD_IE(vap, IEEE80211_MSG_ELEMID,
6788a1b9b6aSSam Leffler 			    wh, "unhandled",
6798a1b9b6aSSam Leffler 			    "id %u, len %u", *frm, frm[1]);
680b032f27cSSam Leffler 			vap->iv_stats.is_rx_elem_unknown++;
6811a1e1d21SSam Leffler 			break;
6821a1e1d21SSam Leffler 		}
6831a1e1d21SSam Leffler 		frm += frm[1] + 2;
6841a1e1d21SSam Leffler 	}
685b032f27cSSam Leffler 	IEEE80211_VERIFY_ELEMENT(scan->rates, IEEE80211_RATE_MAXSIZE,
686b032f27cSSam Leffler 	    scan->status |= IEEE80211_BPARSE_RATES_INVALID);
687b032f27cSSam Leffler 	if (scan->rates != NULL && scan->xrates != NULL) {
688b032f27cSSam Leffler 		/*
689b032f27cSSam Leffler 		 * NB: don't process XRATES if RATES is missing.  This
690b032f27cSSam Leffler 		 * avoids a potential null ptr deref and should be ok
691b032f27cSSam Leffler 		 * as the return code will already note RATES is missing
692b032f27cSSam Leffler 		 * (so callers shouldn't otherwise process the frame).
693b032f27cSSam Leffler 		 */
694b032f27cSSam Leffler 		IEEE80211_VERIFY_ELEMENT(scan->xrates,
695b032f27cSSam Leffler 		    IEEE80211_RATE_MAXSIZE - scan->rates[1],
696b032f27cSSam Leffler 		    scan->status |= IEEE80211_BPARSE_XRATES_INVALID);
697b032f27cSSam Leffler 	}
698b032f27cSSam Leffler 	IEEE80211_VERIFY_ELEMENT(scan->ssid, IEEE80211_NWID_LEN,
699b032f27cSSam Leffler 	    scan->status |= IEEE80211_BPARSE_SSID_INVALID);
700b032f27cSSam Leffler 	if (scan->chan != scan->bchan && ic->ic_phytype != IEEE80211_T_FH) {
7011a1e1d21SSam Leffler 		/*
7021a1e1d21SSam Leffler 		 * Frame was received on a channel different from the
7034844aa7dSAtsushi Onoe 		 * one indicated in the DS params element id;
7041a1e1d21SSam Leffler 		 * silently discard it.
7051a1e1d21SSam Leffler 		 *
7061a1e1d21SSam Leffler 		 * NB: this can happen due to signal leakage.
7074844aa7dSAtsushi Onoe 		 *     But we should take it for FH phy because
7084844aa7dSAtsushi Onoe 		 *     the rssi value should be correct even for
7094844aa7dSAtsushi Onoe 		 *     different hop pattern in FH.
7101a1e1d21SSam Leffler 		 */
711b032f27cSSam Leffler 		IEEE80211_DISCARD(vap,
712d365f9c7SSam Leffler 		    IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
713c79f192cSAdrian Chadd 		    wh, NULL, "for off-channel %u (bchan=%u)",
714c79f192cSAdrian Chadd 		    scan->chan, scan->bchan);
715b032f27cSSam Leffler 		vap->iv_stats.is_rx_chanmismatch++;
716b032f27cSSam Leffler 		scan->status |= IEEE80211_BPARSE_OFFCHAN;
717b5c99415SSam Leffler 	}
718b032f27cSSam Leffler 	if (!(IEEE80211_BINTVAL_MIN <= scan->bintval &&
719b032f27cSSam Leffler 	      scan->bintval <= IEEE80211_BINTVAL_MAX)) {
720b032f27cSSam Leffler 		IEEE80211_DISCARD(vap,
721b5c99415SSam Leffler 		    IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
722de681822SAdrian Chadd 		    wh, NULL, "bogus beacon interval (%d TU)",
723de681822SAdrian Chadd 		    (int) scan->bintval);
724b032f27cSSam Leffler 		vap->iv_stats.is_rx_badbintval++;
725b032f27cSSam Leffler 		scan->status |= IEEE80211_BPARSE_BINTVAL_INVALID;
726b032f27cSSam Leffler 	}
727b032f27cSSam Leffler 	if (scan->country != NULL) {
728b032f27cSSam Leffler 		/*
729b032f27cSSam Leffler 		 * Validate we have at least enough data to extract
730b032f27cSSam Leffler 		 * the country code.  Not sure if we should return an
731b032f27cSSam Leffler 		 * error instead of discarding the IE; consider this
732b032f27cSSam Leffler 		 * being lenient as we don't depend on the data for
733b032f27cSSam Leffler 		 * correct operation.
734b032f27cSSam Leffler 		 */
735b032f27cSSam Leffler 		IEEE80211_VERIFY_LENGTH(scan->country[1], 3 * sizeof(uint8_t),
736b032f27cSSam Leffler 		    scan->country = NULL);
737d365f9c7SSam Leffler 	}
738c70761e6SSam Leffler 	if (scan->csa != NULL) {
739c70761e6SSam Leffler 		/*
740c70761e6SSam Leffler 		 * Validate Channel Switch Announcement; this must
741c70761e6SSam Leffler 		 * be the correct length or we toss the frame.
742c70761e6SSam Leffler 		 */
743c70761e6SSam Leffler 		IEEE80211_VERIFY_LENGTH(scan->csa[1], 3 * sizeof(uint8_t),
744c70761e6SSam Leffler 		    scan->status |= IEEE80211_BPARSE_CSA_INVALID);
745c70761e6SSam Leffler 	}
746fb8c87b4SBjoern A. Zeeb #ifdef IEEE80211_SUPPORT_MESH
747fb8c87b4SBjoern A. Zeeb 	if (scan->meshid != NULL) {
748fb8c87b4SBjoern A. Zeeb 		IEEE80211_VERIFY_ELEMENT(scan->meshid, IEEE80211_MESHID_LEN,
74973547826SBjoern A. Zeeb 		    scan->status |= IEEE80211_BPARSE_MESHID_INVALID);
750fb8c87b4SBjoern A. Zeeb 	}
751fb8c87b4SBjoern A. Zeeb #endif
75268e8e04eSSam Leffler 	/*
75368e8e04eSSam Leffler 	 * Process HT ie's.  This is complicated by our
75468e8e04eSSam Leffler 	 * accepting both the standard ie's and the pre-draft
75568e8e04eSSam Leffler 	 * vendor OUI ie's that some vendors still use/require.
75668e8e04eSSam Leffler 	 */
757b032f27cSSam Leffler 	if (scan->htcap != NULL) {
758b032f27cSSam Leffler 		IEEE80211_VERIFY_LENGTH(scan->htcap[1],
759b032f27cSSam Leffler 		     scan->htcap[0] == IEEE80211_ELEMID_VENDOR ?
76068e8e04eSSam Leffler 			 4 + sizeof(struct ieee80211_ie_htcap)-2 :
76168e8e04eSSam Leffler 			 sizeof(struct ieee80211_ie_htcap)-2,
762b032f27cSSam Leffler 		     scan->htcap = NULL);
76368e8e04eSSam Leffler 	}
764b032f27cSSam Leffler 	if (scan->htinfo != NULL) {
765b032f27cSSam Leffler 		IEEE80211_VERIFY_LENGTH(scan->htinfo[1],
766b032f27cSSam Leffler 		     scan->htinfo[0] == IEEE80211_ELEMID_VENDOR ?
76768e8e04eSSam Leffler 			 4 + sizeof(struct ieee80211_ie_htinfo)-2 :
76868e8e04eSSam Leffler 			 sizeof(struct ieee80211_ie_htinfo)-2,
769b032f27cSSam Leffler 		     scan->htinfo = NULL);
770b032f27cSSam Leffler 	}
77151172f62SAdrian Chadd 
77251172f62SAdrian Chadd 	/* Process VHT IEs */
77351172f62SAdrian Chadd 	if (scan->vhtcap != NULL) {
77451172f62SAdrian Chadd 		IEEE80211_VERIFY_LENGTH(scan->vhtcap[1],
77551172f62SAdrian Chadd 		    sizeof(struct ieee80211_ie_vhtcap) - 2,
77651172f62SAdrian Chadd 		    scan->vhtcap = NULL);
77751172f62SAdrian Chadd 	}
77851172f62SAdrian Chadd 	if (scan->vhtopmode != NULL) {
77951172f62SAdrian Chadd 		IEEE80211_VERIFY_LENGTH(scan->vhtopmode[1],
78051172f62SAdrian Chadd 		    sizeof(struct ieee80211_ie_vht_operation) - 2,
78151172f62SAdrian Chadd 		    scan->vhtopmode = NULL);
78251172f62SAdrian Chadd 	}
78351172f62SAdrian Chadd 
784b032f27cSSam Leffler 	return scan->status;
78568e8e04eSSam Leffler }
7861a1e1d21SSam Leffler 
7871a1e1d21SSam Leffler /*
788b032f27cSSam Leffler  * Parse an Action frame.  Return 0 on success, non-zero on failure.
78944c72e42SSam Leffler  */
790b032f27cSSam Leffler int
791b032f27cSSam Leffler ieee80211_parse_action(struct ieee80211_node *ni, struct mbuf *m)
792b032f27cSSam Leffler {
793b032f27cSSam Leffler 	struct ieee80211vap *vap = ni->ni_vap;
79468e8e04eSSam Leffler 	const struct ieee80211_action *ia;
795b032f27cSSam Leffler 	struct ieee80211_frame *wh;
796b032f27cSSam Leffler 	uint8_t *frm, *efrm;
79768e8e04eSSam Leffler 
79868e8e04eSSam Leffler 	/*
79968e8e04eSSam Leffler 	 * action frame format:
80068e8e04eSSam Leffler 	 *	[1] category
80168e8e04eSSam Leffler 	 *	[1] action
80268e8e04eSSam Leffler 	 *	[tlv] parameters
80368e8e04eSSam Leffler 	 */
804b032f27cSSam Leffler 	wh = mtod(m, struct ieee80211_frame *);
805b032f27cSSam Leffler 	frm = (u_int8_t *)&wh[1];
806b032f27cSSam Leffler 	efrm = mtod(m, u_int8_t *) + m->m_len;
80768e8e04eSSam Leffler 	IEEE80211_VERIFY_LENGTH(efrm - frm,
808b032f27cSSam Leffler 		sizeof(struct ieee80211_action), return EINVAL);
80968e8e04eSSam Leffler 	ia = (const struct ieee80211_action *) frm;
81068e8e04eSSam Leffler 
811b032f27cSSam Leffler 	vap->iv_stats.is_rx_action++;
81268e8e04eSSam Leffler 	IEEE80211_NODE_STAT(ni, rx_action);
81368e8e04eSSam Leffler 
81468e8e04eSSam Leffler 	/* verify frame payloads but defer processing */
81568e8e04eSSam Leffler 	switch (ia->ia_category) {
81668e8e04eSSam Leffler 	case IEEE80211_ACTION_CAT_BA:
81768e8e04eSSam Leffler 		switch (ia->ia_action) {
81868e8e04eSSam Leffler 		case IEEE80211_ACTION_BA_ADDBA_REQUEST:
81968e8e04eSSam Leffler 			IEEE80211_VERIFY_LENGTH(efrm - frm,
82068e8e04eSSam Leffler 			    sizeof(struct ieee80211_action_ba_addbarequest),
821b032f27cSSam Leffler 			    return EINVAL);
82268e8e04eSSam Leffler 			break;
82368e8e04eSSam Leffler 		case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
82468e8e04eSSam Leffler 			IEEE80211_VERIFY_LENGTH(efrm - frm,
82568e8e04eSSam Leffler 			    sizeof(struct ieee80211_action_ba_addbaresponse),
826b032f27cSSam Leffler 			    return EINVAL);
82768e8e04eSSam Leffler 			break;
82868e8e04eSSam Leffler 		case IEEE80211_ACTION_BA_DELBA:
82968e8e04eSSam Leffler 			IEEE80211_VERIFY_LENGTH(efrm - frm,
83068e8e04eSSam Leffler 			    sizeof(struct ieee80211_action_ba_delba),
831b032f27cSSam Leffler 			    return EINVAL);
83268e8e04eSSam Leffler 			break;
83368e8e04eSSam Leffler 		}
83468e8e04eSSam Leffler 		break;
83568e8e04eSSam Leffler 	case IEEE80211_ACTION_CAT_HT:
83668e8e04eSSam Leffler 		switch (ia->ia_action) {
83768e8e04eSSam Leffler 		case IEEE80211_ACTION_HT_TXCHWIDTH:
83868e8e04eSSam Leffler 			IEEE80211_VERIFY_LENGTH(efrm - frm,
83968e8e04eSSam Leffler 			    sizeof(struct ieee80211_action_ht_txchwidth),
840b032f27cSSam Leffler 			    return EINVAL);
841b032f27cSSam Leffler 			break;
842b032f27cSSam Leffler 		case IEEE80211_ACTION_HT_MIMOPWRSAVE:
843b032f27cSSam Leffler 			IEEE80211_VERIFY_LENGTH(efrm - frm,
844b032f27cSSam Leffler 			    sizeof(struct ieee80211_action_ht_mimopowersave),
845b032f27cSSam Leffler 			    return EINVAL);
84668e8e04eSSam Leffler 			break;
84768e8e04eSSam Leffler 		}
84868e8e04eSSam Leffler 		break;
849dbab732dSGleb Smirnoff #ifdef IEEE80211_SUPPORT_MESH
850bdd2a076SAdrian Chadd 	case IEEE80211_ACTION_CAT_MESH:
851bdd2a076SAdrian Chadd 		switch (ia->ia_action) {
852bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_LMETRIC:
853bdd2a076SAdrian Chadd 			/*
854bdd2a076SAdrian Chadd 			 * XXX: verification is true only if we are using
855bdd2a076SAdrian Chadd 			 * Airtime link metric (default)
856bdd2a076SAdrian Chadd 			 */
857bdd2a076SAdrian Chadd 			IEEE80211_VERIFY_LENGTH(efrm - frm,
858bdd2a076SAdrian Chadd 			    sizeof(struct ieee80211_meshlmetric_ie),
859bdd2a076SAdrian Chadd 			    return EINVAL);
860bdd2a076SAdrian Chadd 			break;
861bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_HWMP:
862bdd2a076SAdrian Chadd 			/* verify something */
863bdd2a076SAdrian Chadd 			break;
864bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_GANN:
865c81ceff7SMonthadar Al Jaberi 			IEEE80211_VERIFY_LENGTH(efrm - frm,
866c81ceff7SMonthadar Al Jaberi 			    sizeof(struct ieee80211_meshgann_ie),
867c81ceff7SMonthadar Al Jaberi 			    return EINVAL);
868c81ceff7SMonthadar Al Jaberi 			break;
869bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_CC:
870bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_MCCA_SREQ:
871bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_MCCA_SREP:
872bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_MCCA_AREQ:
873bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_MCCA_ADVER:
874bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_MCCA_TRDOWN:
875bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_TBTT_REQ:
876bdd2a076SAdrian Chadd 		case IEEE80211_ACTION_MESH_TBTT_RES:
877bdd2a076SAdrian Chadd 			/* reject these early on, not implemented */
878bdd2a076SAdrian Chadd 			IEEE80211_DISCARD(vap,
879bdd2a076SAdrian Chadd 			    IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
880bdd2a076SAdrian Chadd 			    wh, NULL, "not implemented yet, act=0x%02X",
881bdd2a076SAdrian Chadd 			    ia->ia_action);
882bdd2a076SAdrian Chadd 			return EINVAL;
883bdd2a076SAdrian Chadd 		}
884bdd2a076SAdrian Chadd 		break;
885ebeaa1adSMonthadar Al Jaberi 	case IEEE80211_ACTION_CAT_SELF_PROT:
886ebeaa1adSMonthadar Al Jaberi 		/* If TA or RA group address discard silently */
887ebeaa1adSMonthadar Al Jaberi 		if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
888ebeaa1adSMonthadar Al Jaberi 			IEEE80211_IS_MULTICAST(wh->i_addr2))
889ebeaa1adSMonthadar Al Jaberi 			return EINVAL;
890ebeaa1adSMonthadar Al Jaberi 		/*
891ebeaa1adSMonthadar Al Jaberi 		 * XXX: Should we verify complete length now or it is
892ebeaa1adSMonthadar Al Jaberi 		 * to varying in sizes?
893ebeaa1adSMonthadar Al Jaberi 		 */
894ebeaa1adSMonthadar Al Jaberi 		switch (ia->ia_action) {
895ebeaa1adSMonthadar Al Jaberi 		case IEEE80211_ACTION_MESHPEERING_CONFIRM:
896ebeaa1adSMonthadar Al Jaberi 		case IEEE80211_ACTION_MESHPEERING_CLOSE:
897ebeaa1adSMonthadar Al Jaberi 			/* is not a peering candidate (yet) */
898ebeaa1adSMonthadar Al Jaberi 			if (ni == vap->iv_bss)
899ebeaa1adSMonthadar Al Jaberi 				return EINVAL;
900ebeaa1adSMonthadar Al Jaberi 			break;
901ebeaa1adSMonthadar Al Jaberi 		}
902ebeaa1adSMonthadar Al Jaberi 		break;
903dbab732dSGleb Smirnoff #endif
90451172f62SAdrian Chadd 	case IEEE80211_ACTION_CAT_VHT:
90551172f62SAdrian Chadd 		printf("%s: TODO: VHT handling!\n", __func__);
90651172f62SAdrian Chadd 		break;
90768e8e04eSSam Leffler 	}
908b032f27cSSam Leffler 	return 0;
9098a1b9b6aSSam Leffler }
9108a1b9b6aSSam Leffler 
9118a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG
9128a1b9b6aSSam Leffler /*
9138a1b9b6aSSam Leffler  * Debugging support.
9148a1b9b6aSSam Leffler  */
915b032f27cSSam Leffler void
916b032f27cSSam Leffler ieee80211_ssid_mismatch(struct ieee80211vap *vap, const char *tag,
917b032f27cSSam Leffler 	uint8_t mac[IEEE80211_ADDR_LEN], uint8_t *ssid)
918b032f27cSSam Leffler {
919b032f27cSSam Leffler 	printf("[%s] discard %s frame, ssid mismatch: ",
920b032f27cSSam Leffler 		ether_sprintf(mac), tag);
921b032f27cSSam Leffler 	ieee80211_print_essid(ssid + 2, ssid[1]);
922b032f27cSSam Leffler 	printf("\n");
923b032f27cSSam Leffler }
9248a1b9b6aSSam Leffler 
9258a1b9b6aSSam Leffler /*
9268a1b9b6aSSam Leffler  * Return the bssid of a frame.
9278a1b9b6aSSam Leffler  */
92868e8e04eSSam Leffler static const uint8_t *
929d2bc4bf6SRui Paulo ieee80211_getbssid(const struct ieee80211vap *vap,
930d2bc4bf6SRui Paulo 	const struct ieee80211_frame *wh)
9318a1b9b6aSSam Leffler {
932b032f27cSSam Leffler 	if (vap->iv_opmode == IEEE80211_M_STA)
9338a1b9b6aSSam Leffler 		return wh->i_addr2;
9348a1b9b6aSSam Leffler 	if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != IEEE80211_FC1_DIR_NODS)
9358a1b9b6aSSam Leffler 		return wh->i_addr1;
9368a1b9b6aSSam Leffler 	if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
9378a1b9b6aSSam Leffler 		return wh->i_addr1;
9388a1b9b6aSSam Leffler 	return wh->i_addr3;
9398a1b9b6aSSam Leffler }
9408a1b9b6aSSam Leffler 
941b032f27cSSam Leffler #include <machine/stdarg.h>
942b032f27cSSam Leffler 
943f6df3191SSam Leffler void
944d2bc4bf6SRui Paulo ieee80211_note(const struct ieee80211vap *vap, const char *fmt, ...)
945f6df3191SSam Leffler {
94604435a1bSBjoern A. Zeeb 	char buf[256];		/* XXX */
947f6df3191SSam Leffler 	va_list ap;
94804435a1bSBjoern A. Zeeb 	int len;
949f6df3191SSam Leffler 
950f6df3191SSam Leffler 	va_start(ap, fmt);
95104435a1bSBjoern A. Zeeb 	len = vsnprintf(buf, sizeof(buf), fmt, ap);
952f6df3191SSam Leffler 	va_end(ap);
953f6df3191SSam Leffler 
954b032f27cSSam Leffler 	if_printf(vap->iv_ifp, "%s", buf);	/* NB: no \n */
95504435a1bSBjoern A. Zeeb 
95604435a1bSBjoern A. Zeeb 	if (len >= sizeof(buf))
95704435a1bSBjoern A. Zeeb 		printf("%s: XXX buffer too small: len = %d\n", __func__, len);
958f6df3191SSam Leffler }
959f6df3191SSam Leffler 
960f6df3191SSam Leffler void
961d2bc4bf6SRui Paulo ieee80211_note_frame(const struct ieee80211vap *vap,
962f6df3191SSam Leffler 	const struct ieee80211_frame *wh,
963f6df3191SSam Leffler 	const char *fmt, ...)
964f6df3191SSam Leffler {
96504435a1bSBjoern A. Zeeb 	char buf[256];		/* XXX */
966f6df3191SSam Leffler 	va_list ap;
96704435a1bSBjoern A. Zeeb 	int len;
968f6df3191SSam Leffler 
969f6df3191SSam Leffler 	va_start(ap, fmt);
97004435a1bSBjoern A. Zeeb 	len = vsnprintf(buf, sizeof(buf), fmt, ap);
971f6df3191SSam Leffler 	va_end(ap);
972b032f27cSSam Leffler 	if_printf(vap->iv_ifp, "[%s] %s\n",
973b032f27cSSam Leffler 		ether_sprintf(ieee80211_getbssid(vap, wh)), buf);
97404435a1bSBjoern A. Zeeb 
97504435a1bSBjoern A. Zeeb 	if (len >= sizeof(buf))
97604435a1bSBjoern A. Zeeb 		printf("%s: XXX buffer too small: len = %d\n", __func__, len);
977f6df3191SSam Leffler }
978f6df3191SSam Leffler 
979f6df3191SSam Leffler void
980d2bc4bf6SRui Paulo ieee80211_note_mac(const struct ieee80211vap *vap,
98168e8e04eSSam Leffler 	const uint8_t mac[IEEE80211_ADDR_LEN],
982f6df3191SSam Leffler 	const char *fmt, ...)
983f6df3191SSam Leffler {
98404435a1bSBjoern A. Zeeb 	char buf[256];		/* XXX */
985f6df3191SSam Leffler 	va_list ap;
98604435a1bSBjoern A. Zeeb 	int len;
987f6df3191SSam Leffler 
988f6df3191SSam Leffler 	va_start(ap, fmt);
98904435a1bSBjoern A. Zeeb 	len = vsnprintf(buf, sizeof(buf), fmt, ap);
990f6df3191SSam Leffler 	va_end(ap);
991b032f27cSSam Leffler 	if_printf(vap->iv_ifp, "[%s] %s\n", ether_sprintf(mac), buf);
99204435a1bSBjoern A. Zeeb 
99304435a1bSBjoern A. Zeeb 	if (len >= sizeof(buf))
99404435a1bSBjoern A. Zeeb 		printf("%s: XXX buffer too small: len = %d\n", __func__, len);
995f6df3191SSam Leffler }
996f6df3191SSam Leffler 
997a000d7c2SSam Leffler void
998d2bc4bf6SRui Paulo ieee80211_discard_frame(const struct ieee80211vap *vap,
9998a1b9b6aSSam Leffler 	const struct ieee80211_frame *wh,
10008a1b9b6aSSam Leffler 	const char *type, const char *fmt, ...)
10018a1b9b6aSSam Leffler {
100204435a1bSBjoern A. Zeeb 	char buf[256];		/* XXX */
10038a1b9b6aSSam Leffler 	va_list ap;
100404435a1bSBjoern A. Zeeb 	int len;
10058a1b9b6aSSam Leffler 
10068a1b9b6aSSam Leffler 	va_start(ap, fmt);
100704435a1bSBjoern A. Zeeb 	len = vsnprintf(buf, sizeof(buf), fmt, ap);
10088a1b9b6aSSam Leffler 	va_end(ap);
100904435a1bSBjoern A. Zeeb 
101004435a1bSBjoern A. Zeeb 	if_printf(vap->iv_ifp, "[%s] discard %s frame, %s\n",
101104435a1bSBjoern A. Zeeb 	    ether_sprintf(ieee80211_getbssid(vap, wh)),
101204435a1bSBjoern A. Zeeb 	    type != NULL ? type : ieee80211_mgt_subtype_name(wh->i_fc[0]),
101304435a1bSBjoern A. Zeeb 	    buf);
101404435a1bSBjoern A. Zeeb 
101504435a1bSBjoern A. Zeeb 	if (len >= sizeof(buf))
101604435a1bSBjoern A. Zeeb 		printf("%s: XXX buffer too small: len = %d\n", __func__, len);
10178a1b9b6aSSam Leffler }
10188a1b9b6aSSam Leffler 
1019a000d7c2SSam Leffler void
1020d2bc4bf6SRui Paulo ieee80211_discard_ie(const struct ieee80211vap *vap,
10218a1b9b6aSSam Leffler 	const struct ieee80211_frame *wh,
10228a1b9b6aSSam Leffler 	const char *type, const char *fmt, ...)
10238a1b9b6aSSam Leffler {
102404435a1bSBjoern A. Zeeb 	char buf[256];		/* XXX */
10258a1b9b6aSSam Leffler 	va_list ap;
102604435a1bSBjoern A. Zeeb 	int len;
10278a1b9b6aSSam Leffler 
10288a1b9b6aSSam Leffler 	va_start(ap, fmt);
102904435a1bSBjoern A. Zeeb 	len = vsnprintf(buf, sizeof(buf), fmt, ap);
10308a1b9b6aSSam Leffler 	va_end(ap);
103104435a1bSBjoern A. Zeeb 
103204435a1bSBjoern A. Zeeb 	if_printf(vap->iv_ifp, "[%s] discard%s%s information element, %s\n",
103304435a1bSBjoern A. Zeeb 	    ether_sprintf(ieee80211_getbssid(vap, wh)),
103404435a1bSBjoern A. Zeeb 	    type != NULL ? " " : "", type != NULL ? type : "", buf);
103504435a1bSBjoern A. Zeeb 
103604435a1bSBjoern A. Zeeb 	if (len >= sizeof(buf))
103704435a1bSBjoern A. Zeeb 		printf("%s: XXX buffer too small: len = %d\n", __func__, len);
10388a1b9b6aSSam Leffler }
10398a1b9b6aSSam Leffler 
1040a000d7c2SSam Leffler void
1041d2bc4bf6SRui Paulo ieee80211_discard_mac(const struct ieee80211vap *vap,
104268e8e04eSSam Leffler 	const uint8_t mac[IEEE80211_ADDR_LEN],
10438a1b9b6aSSam Leffler 	const char *type, const char *fmt, ...)
10448a1b9b6aSSam Leffler {
104504435a1bSBjoern A. Zeeb 	char buf[256];		/* XXX */
10468a1b9b6aSSam Leffler 	va_list ap;
104704435a1bSBjoern A. Zeeb 	int len;
10488a1b9b6aSSam Leffler 
10498a1b9b6aSSam Leffler 	va_start(ap, fmt);
105004435a1bSBjoern A. Zeeb 	len = vsnprintf(buf, sizeof(buf), fmt, ap);
10518a1b9b6aSSam Leffler 	va_end(ap);
105204435a1bSBjoern A. Zeeb 
105304435a1bSBjoern A. Zeeb 	if_printf(vap->iv_ifp, "[%s] discard%s%s frame, %s\n",
105404435a1bSBjoern A. Zeeb 	    ether_sprintf(mac),
105504435a1bSBjoern A. Zeeb 	    type != NULL ? " " : "", type != NULL ? type : "", buf);
105604435a1bSBjoern A. Zeeb 
105704435a1bSBjoern A. Zeeb 	if (len >= sizeof(buf))
105804435a1bSBjoern A. Zeeb 		printf("%s: XXX buffer too small: len = %d\n", __func__, len);
10598a1b9b6aSSam Leffler }
10608a1b9b6aSSam Leffler #endif /* IEEE80211_DEBUG */
1061