11a1e1d21SSam Leffler /*-
24d846d26SWarner 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>
30b032f27cSSam Leffler #include "opt_wlan.h"
31b032f27cSSam Leffler
321a1e1d21SSam Leffler #include <sys/param.h>
331a1e1d21SSam Leffler #include <sys/systm.h>
341a1e1d21SSam Leffler #include <sys/mbuf.h>
351a1e1d21SSam Leffler #include <sys/malloc.h>
361a1e1d21SSam Leffler #include <sys/endian.h>
37a0cc3f85SSam Leffler #include <sys/kernel.h>
381a1e1d21SSam Leffler
398a1b9b6aSSam Leffler #include <sys/socket.h>
401a1e1d21SSam Leffler
411a1e1d21SSam Leffler #include <net/ethernet.h>
42b032f27cSSam Leffler #include <net/if.h>
4376039bc8SGleb Smirnoff #include <net/if_var.h>
441a1e1d21SSam Leffler #include <net/if_llc.h>
45b032f27cSSam Leffler #include <net/if_media.h>
463d0d5b21SJustin Hibbits #include <net/if_private.h>
478a1b9b6aSSam Leffler #include <net/if_vlan_var.h>
481a1e1d21SSam Leffler
491a1e1d21SSam Leffler #include <net80211/ieee80211_var.h>
50b032f27cSSam Leffler #include <net80211/ieee80211_input.h>
5159aa14a9SRui Paulo #ifdef IEEE80211_SUPPORT_MESH
5259aa14a9SRui Paulo #include <net80211/ieee80211_mesh.h>
5359aa14a9SRui Paulo #endif
541a1e1d21SSam Leffler
551a1e1d21SSam Leffler #include <net/bpf.h>
561a1e1d21SSam Leffler
57b032f27cSSam Leffler #ifdef INET
58b032f27cSSam Leffler #include <netinet/in.h>
59b032f27cSSam Leffler #include <net/ethernet.h>
608a1b9b6aSSam Leffler #endif
611a1e1d21SSam Leffler
62864ab114SAdrian Chadd static void
ieee80211_process_mimo(struct ieee80211_node * ni,struct ieee80211_rx_stats * rx)63864ab114SAdrian Chadd ieee80211_process_mimo(struct ieee80211_node *ni, struct ieee80211_rx_stats *rx)
64864ab114SAdrian Chadd {
65864ab114SAdrian Chadd int i;
66864ab114SAdrian Chadd
67864ab114SAdrian Chadd /* Verify the required MIMO bits are set */
68864ab114SAdrian Chadd if ((rx->r_flags & (IEEE80211_R_C_CHAIN | IEEE80211_R_C_NF | IEEE80211_R_C_RSSI)) !=
69864ab114SAdrian Chadd (IEEE80211_R_C_CHAIN | IEEE80211_R_C_NF | IEEE80211_R_C_RSSI))
70864ab114SAdrian Chadd return;
71864ab114SAdrian Chadd
72864ab114SAdrian Chadd /* XXX This assumes the MIMO radios have both ctl and ext chains */
73864ab114SAdrian Chadd for (i = 0; i < MIN(rx->c_chain, IEEE80211_MAX_CHAINS); i++) {
74864ab114SAdrian Chadd IEEE80211_RSSI_LPF(ni->ni_mimo_rssi_ctl[i], rx->c_rssi_ctl[i]);
75864ab114SAdrian Chadd IEEE80211_RSSI_LPF(ni->ni_mimo_rssi_ext[i], rx->c_rssi_ext[i]);
76864ab114SAdrian Chadd }
77864ab114SAdrian Chadd
78864ab114SAdrian Chadd /* XXX This also assumes the MIMO radios have both ctl and ext chains */
79864ab114SAdrian Chadd for(i = 0; i < MIN(rx->c_chain, IEEE80211_MAX_CHAINS); i++) {
80864ab114SAdrian Chadd ni->ni_mimo_noise_ctl[i] = rx->c_nf_ctl[i];
81864ab114SAdrian Chadd ni->ni_mimo_noise_ext[i] = rx->c_nf_ext[i];
82864ab114SAdrian Chadd }
83864ab114SAdrian Chadd ni->ni_mimo_chains = rx->c_chain;
84864ab114SAdrian Chadd }
85864ab114SAdrian Chadd
86864ab114SAdrian Chadd int
ieee80211_input_mimo(struct ieee80211_node * ni,struct mbuf * m)87bdc7291eSAndriy Voskoboinyk ieee80211_input_mimo(struct ieee80211_node *ni, struct mbuf *m)
88864ab114SAdrian Chadd {
89b86fd7bcSAdrian Chadd struct ieee80211_rx_stats rxs;
90b86fd7bcSAdrian Chadd
91bdc7291eSAndriy Voskoboinyk /* try to read stats from mbuf */
92b86fd7bcSAdrian Chadd bzero(&rxs, sizeof(rxs));
93bdc7291eSAndriy Voskoboinyk if (ieee80211_get_rx_params(m, &rxs) != 0)
94bdc7291eSAndriy Voskoboinyk return (-1);
95b86fd7bcSAdrian Chadd
96864ab114SAdrian Chadd /* XXX should assert IEEE80211_R_NF and IEEE80211_R_RSSI are set */
97b86fd7bcSAdrian Chadd ieee80211_process_mimo(ni, &rxs);
98b86fd7bcSAdrian Chadd
99c79f192cSAdrian Chadd //return ieee80211_input(ni, m, rx->rssi, rx->nf);
100e97796e2SAdrian Chadd return ni->ni_vap->iv_input(ni, m, &rxs, rxs.c_rssi, rxs.c_nf);
101864ab114SAdrian Chadd }
102864ab114SAdrian Chadd
103b032f27cSSam Leffler int
ieee80211_input_all(struct ieee80211com * ic,struct mbuf * m,int rssi,int nf)1045463c4a4SSam Leffler ieee80211_input_all(struct ieee80211com *ic, struct mbuf *m, int rssi, int nf)
105b032f27cSSam Leffler {
106864ab114SAdrian Chadd struct ieee80211_rx_stats rx;
107864ab114SAdrian Chadd
108864ab114SAdrian Chadd rx.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI;
109e97796e2SAdrian Chadd rx.c_nf = nf;
110e97796e2SAdrian Chadd rx.c_rssi = rssi;
111bdc7291eSAndriy Voskoboinyk
112bdc7291eSAndriy Voskoboinyk if (!ieee80211_add_rx_params(m, &rx))
113bdc7291eSAndriy Voskoboinyk return (-1);
114bdc7291eSAndriy Voskoboinyk
115bdc7291eSAndriy Voskoboinyk return ieee80211_input_mimo_all(ic, m);
116864ab114SAdrian Chadd }
117864ab114SAdrian Chadd
118864ab114SAdrian Chadd int
ieee80211_input_mimo_all(struct ieee80211com * ic,struct mbuf * m)119bdc7291eSAndriy Voskoboinyk ieee80211_input_mimo_all(struct ieee80211com *ic, struct mbuf *m)
120864ab114SAdrian Chadd {
121b032f27cSSam Leffler struct ieee80211vap *vap;
122b032f27cSSam Leffler int type = -1;
123b032f27cSSam Leffler
124e1cfcbcbSSam Leffler m->m_flags |= M_BCAST; /* NB: mark for bpf tap'ing */
125e1cfcbcbSSam Leffler
126b032f27cSSam Leffler /* XXX locking */
127b032f27cSSam Leffler TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
128b032f27cSSam Leffler struct ieee80211_node *ni;
129b032f27cSSam Leffler struct mbuf *mcopy;
130b032f27cSSam Leffler
131c3655fa4SSam Leffler /* NB: could check for IFF_UP but this is cheaper */
132c3655fa4SSam Leffler if (vap->iv_state == IEEE80211_S_INIT)
133c3655fa4SSam Leffler continue;
134b032f27cSSam Leffler /*
135b032f27cSSam Leffler * WDS vap's only receive directed traffic from the
136b032f27cSSam Leffler * station at the ``far end''. That traffic should
137b032f27cSSam Leffler * be passed through the AP vap the station is associated
138b032f27cSSam Leffler * to--so don't spam them with mcast frames.
139b032f27cSSam Leffler */
140b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_WDS)
141b032f27cSSam Leffler continue;
142b032f27cSSam Leffler if (TAILQ_NEXT(vap, iv_next) != NULL) {
143b032f27cSSam Leffler /*
144b032f27cSSam Leffler * Packet contents are changed by ieee80211_decap
145b032f27cSSam Leffler * so do a deep copy of the packet.
146bdc7291eSAndriy Voskoboinyk * NB: tags are copied too.
147b032f27cSSam Leffler */
148bd29f817SBjoern A. Zeeb mcopy = m_dup(m, IEEE80211_M_NOWAIT);
149b032f27cSSam Leffler if (mcopy == NULL) {
150b032f27cSSam Leffler /* XXX stat+msg */
151b032f27cSSam Leffler continue;
1528a1b9b6aSSam Leffler }
153b032f27cSSam Leffler } else {
154b032f27cSSam Leffler mcopy = m;
155b032f27cSSam Leffler m = NULL;
1568a1b9b6aSSam Leffler }
157b032f27cSSam Leffler ni = ieee80211_ref_node(vap->iv_bss);
158bdc7291eSAndriy Voskoboinyk type = ieee80211_input_mimo(ni, mcopy);
159b032f27cSSam Leffler ieee80211_free_node(ni);
1601a1e1d21SSam Leffler }
161b032f27cSSam Leffler if (m != NULL) /* no vaps, reclaim mbuf */
1621a1e1d21SSam Leffler m_freem(m);
1631f298879SSam Leffler return type;
1641a1e1d21SSam Leffler }
1651a1e1d21SSam Leffler
1668a1b9b6aSSam Leffler /*
167df0d214aSRui Paulo * This function reassembles fragments.
168b032f27cSSam Leffler *
169b032f27cSSam Leffler * XXX should handle 3 concurrent reassemblies per-spec.
1708a1b9b6aSSam Leffler */
171b032f27cSSam Leffler struct mbuf *
ieee80211_defrag(struct ieee80211_node * ni,struct mbuf * m,int hdrspace,int has_decrypted)17211572d7dSMathy Vanhoef ieee80211_defrag(struct ieee80211_node *ni, struct mbuf *m, int hdrspace,
17311572d7dSMathy Vanhoef int has_decrypted)
1741a1e1d21SSam Leffler {
175b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
1768a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
1778a1b9b6aSSam Leffler struct ieee80211_frame *lwh;
17868e8e04eSSam Leffler uint16_t rxseq;
17968e8e04eSSam Leffler uint8_t fragno;
18068e8e04eSSam Leffler uint8_t more_frag = wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG;
1818a1b9b6aSSam Leffler struct mbuf *mfrag;
1828a1b9b6aSSam Leffler
1838a1b9b6aSSam Leffler KASSERT(!IEEE80211_IS_MULTICAST(wh->i_addr1), ("multicast fragm?"));
1848a1b9b6aSSam Leffler
18568e8e04eSSam Leffler rxseq = le16toh(*(uint16_t *)wh->i_seq);
1868a1b9b6aSSam Leffler fragno = rxseq & IEEE80211_SEQ_FRAG_MASK;
1878a1b9b6aSSam Leffler
1888a1b9b6aSSam Leffler /* Quick way out, if there's nothing to defragment */
1898a1b9b6aSSam Leffler if (!more_frag && fragno == 0 && ni->ni_rxfrag[0] == NULL)
1908a1b9b6aSSam Leffler return m;
1918a1b9b6aSSam Leffler
19211572d7dSMathy Vanhoef /* Temporarily set flag to remember if fragment was encrypted. */
19311572d7dSMathy Vanhoef /* XXX use a non-packet altering storage for this in the future. */
19411572d7dSMathy Vanhoef if (has_decrypted)
19511572d7dSMathy Vanhoef wh->i_fc[1] |= IEEE80211_FC1_PROTECTED;
19611572d7dSMathy Vanhoef
1978a1b9b6aSSam Leffler /*
1988a1b9b6aSSam Leffler * Remove frag to insure it doesn't get reaped by timer.
1998a1b9b6aSSam Leffler */
2008a1b9b6aSSam Leffler if (ni->ni_table == NULL) {
2018a1b9b6aSSam Leffler /*
2028a1b9b6aSSam Leffler * Should never happen. If the node is orphaned (not in
2038a1b9b6aSSam Leffler * the table) then input packets should not reach here.
2048a1b9b6aSSam Leffler * Otherwise, a concurrent request that yanks the table
2058a1b9b6aSSam Leffler * should be blocked by other interlocking and/or by first
2068a1b9b6aSSam Leffler * shutting the driver down. Regardless, be defensive
2078a1b9b6aSSam Leffler * here and just bail
2088a1b9b6aSSam Leffler */
2098a1b9b6aSSam Leffler /* XXX need msg+stat */
2108a1b9b6aSSam Leffler m_freem(m);
2118a1b9b6aSSam Leffler return NULL;
2128a1b9b6aSSam Leffler }
2138a1b9b6aSSam Leffler IEEE80211_NODE_LOCK(ni->ni_table);
2148a1b9b6aSSam Leffler mfrag = ni->ni_rxfrag[0];
2158a1b9b6aSSam Leffler ni->ni_rxfrag[0] = NULL;
2168a1b9b6aSSam Leffler IEEE80211_NODE_UNLOCK(ni->ni_table);
2178a1b9b6aSSam Leffler
2188a1b9b6aSSam Leffler /*
2198a1b9b6aSSam Leffler * Validate new fragment is in order and
2208a1b9b6aSSam Leffler * related to the previous ones.
2218a1b9b6aSSam Leffler */
2228a1b9b6aSSam Leffler if (mfrag != NULL) {
22368e8e04eSSam Leffler uint16_t last_rxseq;
2248a1b9b6aSSam Leffler
2258a1b9b6aSSam Leffler lwh = mtod(mfrag, struct ieee80211_frame *);
22668e8e04eSSam Leffler last_rxseq = le16toh(*(uint16_t *)lwh->i_seq);
22711572d7dSMathy Vanhoef /*
22811572d7dSMathy Vanhoef * NB: check seq # and frag together. Also check that both
22911572d7dSMathy Vanhoef * fragments are plaintext or that both are encrypted.
23011572d7dSMathy Vanhoef */
2318722deefSAndriy Voskoboinyk if (rxseq == last_rxseq+1 &&
2328722deefSAndriy Voskoboinyk IEEE80211_ADDR_EQ(wh->i_addr1, lwh->i_addr1) &&
23311572d7dSMathy Vanhoef IEEE80211_ADDR_EQ(wh->i_addr2, lwh->i_addr2) &&
23411572d7dSMathy Vanhoef !((wh->i_fc[1] ^ lwh->i_fc[1]) & IEEE80211_FC1_PROTECTED)) {
2358722deefSAndriy Voskoboinyk /* XXX clear MORE_FRAG bit? */
2368722deefSAndriy Voskoboinyk /* track last seqnum and fragno */
2378722deefSAndriy Voskoboinyk *(uint16_t *) lwh->i_seq = *(uint16_t *) wh->i_seq;
2388722deefSAndriy Voskoboinyk
2398722deefSAndriy Voskoboinyk m_adj(m, hdrspace); /* strip header */
2408722deefSAndriy Voskoboinyk m_catpkt(mfrag, m); /* concatenate */
2418722deefSAndriy Voskoboinyk } else {
2428a1b9b6aSSam Leffler /*
2438a1b9b6aSSam Leffler * Unrelated fragment or no space for it,
2448a1b9b6aSSam Leffler * clear current fragments.
2458a1b9b6aSSam Leffler */
2468a1b9b6aSSam Leffler m_freem(mfrag);
2478a1b9b6aSSam Leffler mfrag = NULL;
2488a1b9b6aSSam Leffler }
2498a1b9b6aSSam Leffler }
2508a1b9b6aSSam Leffler
2518a1b9b6aSSam Leffler if (mfrag == NULL) {
2528a1b9b6aSSam Leffler if (fragno != 0) { /* !first fragment, discard */
253b032f27cSSam Leffler vap->iv_stats.is_rx_defrag++;
2548a1b9b6aSSam Leffler IEEE80211_NODE_STAT(ni, rx_defrag);
2558a1b9b6aSSam Leffler m_freem(m);
2568a1b9b6aSSam Leffler return NULL;
2578a1b9b6aSSam Leffler }
2588a1b9b6aSSam Leffler mfrag = m;
2598a1b9b6aSSam Leffler }
2608a1b9b6aSSam Leffler if (more_frag) { /* more to come, save */
261a0cc3f85SSam Leffler ni->ni_rxfragstamp = ticks;
2628a1b9b6aSSam Leffler ni->ni_rxfrag[0] = mfrag;
2638a1b9b6aSSam Leffler mfrag = NULL;
2648a1b9b6aSSam Leffler }
26511572d7dSMathy Vanhoef /* Remember to clear protected flag that was temporarily set. */
26611572d7dSMathy Vanhoef if (mfrag != NULL) {
26711572d7dSMathy Vanhoef wh = mtod(mfrag, struct ieee80211_frame *);
26811572d7dSMathy Vanhoef wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED;
26911572d7dSMathy Vanhoef }
2708a1b9b6aSSam Leffler return mfrag;
2718a1b9b6aSSam Leffler }
2728a1b9b6aSSam Leffler
27368e8e04eSSam Leffler void
ieee80211_deliver_data(struct ieee80211vap * vap,struct ieee80211_node * ni,struct mbuf * m)274b032f27cSSam Leffler ieee80211_deliver_data(struct ieee80211vap *vap,
2751bd482efSSam Leffler struct ieee80211_node *ni, struct mbuf *m)
2761bd482efSSam Leffler {
277de607e3cSBjoern A. Zeeb struct epoch_tracker et;
2781bd482efSSam Leffler struct ether_header *eh = mtod(m, struct ether_header *);
279b032f27cSSam Leffler struct ifnet *ifp = vap->iv_ifp;
2801bd482efSSam Leffler
281e1cfcbcbSSam Leffler /* clear driver/net80211 flags before passing up */
28286bd0491SAndre Oppermann m->m_flags &= ~(M_MCAST | M_BCAST);
28386bd0491SAndre Oppermann m_clrprotoflags(m);
284e1cfcbcbSSam Leffler
285b032f27cSSam Leffler /* NB: see hostap_deliver_data, this path doesn't handle hostap */
286b032f27cSSam Leffler KASSERT(vap->iv_opmode != IEEE80211_M_HOSTAP, ("gack, hostap"));
28706efa2f0SSam Leffler /*
28806efa2f0SSam Leffler * Do accounting.
28906efa2f0SSam Leffler */
290dea45121SGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
29106efa2f0SSam Leffler IEEE80211_NODE_STAT(ni, rx_data);
29206efa2f0SSam Leffler IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
29306efa2f0SSam Leffler if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
294eb81dc79SAdrian Chadd if (ETHER_IS_BROADCAST(eh->ether_dhost))
295eb81dc79SAdrian Chadd m->m_flags |= M_BCAST;
296eb81dc79SAdrian Chadd else
297eb81dc79SAdrian Chadd m->m_flags |= M_MCAST;
29806efa2f0SSam Leffler IEEE80211_NODE_STAT(ni, rx_mcast);
29906efa2f0SSam Leffler } else
30006efa2f0SSam Leffler IEEE80211_NODE_STAT(ni, rx_ucast);
301b032f27cSSam Leffler m->m_pkthdr.rcvif = ifp;
30206efa2f0SSam Leffler
3031bd482efSSam Leffler if (ni->ni_vlan != 0) {
3041bd482efSSam Leffler /* attach vlan tag */
30578ba57b9SAndre Oppermann m->m_pkthdr.ether_vtag = ni->ni_vlan;
30678ba57b9SAndre Oppermann m->m_flags |= M_VLANTAG;
3071bd482efSSam Leffler }
308de607e3cSBjoern A. Zeeb NET_EPOCH_ENTER(et);
309b032f27cSSam Leffler ifp->if_input(ifp, m);
310de607e3cSBjoern A. Zeeb NET_EPOCH_EXIT(et);
3111bd482efSSam Leffler }
3121bd482efSSam Leffler
313b032f27cSSam Leffler struct mbuf *
ieee80211_decap(struct ieee80211vap * vap,struct mbuf * m,int hdrlen,uint8_t qos)314f024bdf1SMathy Vanhoef ieee80211_decap(struct ieee80211vap *vap, struct mbuf *m, int hdrlen,
315f024bdf1SMathy Vanhoef uint8_t qos)
3168a1b9b6aSSam Leffler {
31759aa14a9SRui Paulo struct ieee80211_qosframe_addr4 wh;
3181a1e1d21SSam Leffler struct ether_header *eh;
3191a1e1d21SSam Leffler struct llc *llc;
3201a1e1d21SSam Leffler
321c104cff2SRui Paulo KASSERT(hdrlen <= sizeof(wh),
322c104cff2SRui Paulo ("hdrlen %d > max %zd", hdrlen, sizeof(wh)));
323c104cff2SRui Paulo
3242cc12adeSSam Leffler if (m->m_len < hdrlen + sizeof(*llc) &&
3252cc12adeSSam Leffler (m = m_pullup(m, hdrlen + sizeof(*llc))) == NULL) {
326c104cff2SRui Paulo vap->iv_stats.is_rx_tooshort++;
327c104cff2SRui Paulo /* XXX msg */
3281a1e1d21SSam Leffler return NULL;
3291a1e1d21SSam Leffler }
3302cc12adeSSam Leffler memcpy(&wh, mtod(m, caddr_t), hdrlen);
3312cc12adeSSam Leffler llc = (struct llc *)(mtod(m, caddr_t) + hdrlen);
3321a1e1d21SSam Leffler if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP &&
3331a1e1d21SSam Leffler llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 &&
3346bbdc701SSam Leffler llc->llc_snap.org_code[1] == 0 && llc->llc_snap.org_code[2] == 0 &&
3356bbdc701SSam Leffler /* NB: preserve AppleTalk frames that have a native SNAP hdr */
3366bbdc701SSam Leffler !(llc->llc_snap.ether_type == htons(ETHERTYPE_AARP) ||
337f024bdf1SMathy Vanhoef llc->llc_snap.ether_type == htons(ETHERTYPE_IPX)) &&
338f024bdf1SMathy Vanhoef /* Do not want to touch A-MSDU frames. */
339f024bdf1SMathy Vanhoef !(qos & IEEE80211_QOS_AMSDU)) {
340ab96db10SSam Leffler m_adj(m, hdrlen + sizeof(struct llc) - sizeof(*eh));
3411a1e1d21SSam Leffler llc = NULL;
3421a1e1d21SSam Leffler } else {
3432cc12adeSSam Leffler m_adj(m, hdrlen - sizeof(*eh));
3441a1e1d21SSam Leffler }
3451a1e1d21SSam Leffler eh = mtod(m, struct ether_header *);
3461a1e1d21SSam Leffler switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) {
3471a1e1d21SSam Leffler case IEEE80211_FC1_DIR_NODS:
3481a1e1d21SSam Leffler IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
3491a1e1d21SSam Leffler IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr2);
3501a1e1d21SSam Leffler break;
3511a1e1d21SSam Leffler case IEEE80211_FC1_DIR_TODS:
3521a1e1d21SSam Leffler IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr3);
3531a1e1d21SSam Leffler IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr2);
3541a1e1d21SSam Leffler break;
3551a1e1d21SSam Leffler case IEEE80211_FC1_DIR_FROMDS:
3561a1e1d21SSam Leffler IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
3571a1e1d21SSam Leffler IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr3);
3581a1e1d21SSam Leffler break;
3591a1e1d21SSam Leffler case IEEE80211_FC1_DIR_DSTODS:
3602cc12adeSSam Leffler IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr3);
3612cc12adeSSam Leffler IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr4);
3622cc12adeSSam Leffler break;
3631a1e1d21SSam Leffler }
36423f4fd6dSGleb Smirnoff #ifndef __NO_STRICT_ALIGNMENT
36568e8e04eSSam Leffler if (!ALIGNED_POINTER(mtod(m, caddr_t) + sizeof(*eh), uint32_t)) {
366519f677aSSam Leffler m = ieee80211_realign(vap, m, sizeof(*eh));
367519f677aSSam Leffler if (m == NULL)
3681a1e1d21SSam Leffler return NULL;
3691a1e1d21SSam Leffler }
37023f4fd6dSGleb Smirnoff #endif /* !__NO_STRICT_ALIGNMENT */
3711a1e1d21SSam Leffler if (llc != NULL) {
3721a1e1d21SSam Leffler eh = mtod(m, struct ether_header *);
3731a1e1d21SSam Leffler eh->ether_type = htons(m->m_pkthdr.len - sizeof(*eh));
3741a1e1d21SSam Leffler }
3751a1e1d21SSam Leffler return m;
3761a1e1d21SSam Leffler }
3771a1e1d21SSam Leffler
3781a1e1d21SSam Leffler /*
37968e8e04eSSam Leffler * Decap a frame encapsulated in a fast-frame/A-MSDU.
38068e8e04eSSam Leffler */
38168e8e04eSSam Leffler struct mbuf *
ieee80211_decap1(struct mbuf * m,int * framelen)38268e8e04eSSam Leffler ieee80211_decap1(struct mbuf *m, int *framelen)
38368e8e04eSSam Leffler {
38468e8e04eSSam Leffler #define FF_LLC_SIZE (sizeof(struct ether_header) + sizeof(struct llc))
38568e8e04eSSam Leffler struct ether_header *eh;
38668e8e04eSSam Leffler struct llc *llc;
387f024bdf1SMathy Vanhoef const uint8_t llc_hdr_mac[ETHER_ADDR_LEN] = {
388f024bdf1SMathy Vanhoef /* MAC address matching the 802.2 LLC header */
389f024bdf1SMathy Vanhoef LLC_SNAP_LSAP, LLC_SNAP_LSAP, LLC_UI, 0, 0, 0
390f024bdf1SMathy Vanhoef };
39168e8e04eSSam Leffler
39268e8e04eSSam Leffler /*
39368e8e04eSSam Leffler * The frame has an 802.3 header followed by an 802.2
39468e8e04eSSam Leffler * LLC header. The encapsulated frame length is in the
39568e8e04eSSam Leffler * first header type field; save that and overwrite it
39668e8e04eSSam Leffler * with the true type field found in the second. Then
39768e8e04eSSam Leffler * copy the 802.3 header up to where it belongs and
39868e8e04eSSam Leffler * adjust the mbuf contents to remove the void.
39968e8e04eSSam Leffler */
40068e8e04eSSam Leffler if (m->m_len < FF_LLC_SIZE && (m = m_pullup(m, FF_LLC_SIZE)) == NULL)
40168e8e04eSSam Leffler return NULL;
40268e8e04eSSam Leffler eh = mtod(m, struct ether_header *); /* 802.3 header is first */
403f024bdf1SMathy Vanhoef
404f024bdf1SMathy Vanhoef /*
405f024bdf1SMathy Vanhoef * Detect possible attack where a single 802.11 frame is processed
406f024bdf1SMathy Vanhoef * as an A-MSDU frame due to an adversary setting the A-MSDU present
407f024bdf1SMathy Vanhoef * bit in the 802.11 QoS header. [FragAttacks]
408f024bdf1SMathy Vanhoef */
409f024bdf1SMathy Vanhoef if (memcmp(eh->ether_dhost, llc_hdr_mac, ETHER_ADDR_LEN) == 0)
410f024bdf1SMathy Vanhoef return NULL;
411f024bdf1SMathy Vanhoef
41268e8e04eSSam Leffler llc = (struct llc *)&eh[1]; /* 802.2 header follows */
41368e8e04eSSam Leffler *framelen = ntohs(eh->ether_type) /* encap'd frame size */
41468e8e04eSSam Leffler + sizeof(struct ether_header) - sizeof(struct llc);
41568e8e04eSSam Leffler eh->ether_type = llc->llc_un.type_snap.ether_type;
41668e8e04eSSam Leffler ovbcopy(eh, mtod(m, uint8_t *) + sizeof(struct llc),
41768e8e04eSSam Leffler sizeof(struct ether_header));
41868e8e04eSSam Leffler m_adj(m, sizeof(struct llc));
41968e8e04eSSam Leffler return m;
42068e8e04eSSam Leffler #undef FF_LLC_SIZE
42168e8e04eSSam Leffler }
42268e8e04eSSam Leffler
42368e8e04eSSam Leffler /*
4241a1e1d21SSam Leffler * Install received rate set information in the node's state block.
4251a1e1d21SSam Leffler */
4267d77cd53SSam Leffler int
ieee80211_setup_rates(struct ieee80211_node * ni,const uint8_t * rates,const uint8_t * xrates,int flags)4277d77cd53SSam Leffler ieee80211_setup_rates(struct ieee80211_node *ni,
42868e8e04eSSam Leffler const uint8_t *rates, const uint8_t *xrates, int flags)
4291a1e1d21SSam Leffler {
430b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
4311a1e1d21SSam Leffler struct ieee80211_rateset *rs = &ni->ni_rates;
4321a1e1d21SSam Leffler
4331a1e1d21SSam Leffler memset(rs, 0, sizeof(*rs));
4341a1e1d21SSam Leffler rs->rs_nrates = rates[1];
4351a1e1d21SSam Leffler memcpy(rs->rs_rates, rates + 2, rs->rs_nrates);
4361a1e1d21SSam Leffler if (xrates != NULL) {
43768e8e04eSSam Leffler uint8_t nxrates;
4381a1e1d21SSam Leffler /*
4391a1e1d21SSam Leffler * Tack on 11g extended supported rate element.
4401a1e1d21SSam Leffler */
4411a1e1d21SSam Leffler nxrates = xrates[1];
4421a1e1d21SSam Leffler if (rs->rs_nrates + nxrates > IEEE80211_RATE_MAXSIZE) {
4431a1e1d21SSam Leffler nxrates = IEEE80211_RATE_MAXSIZE - rs->rs_nrates;
444b032f27cSSam Leffler IEEE80211_NOTE(vap, IEEE80211_MSG_XRATE, ni,
445b032f27cSSam Leffler "extended rate set too large; only using "
446b032f27cSSam Leffler "%u of %u rates", nxrates, xrates[1]);
447b032f27cSSam Leffler vap->iv_stats.is_rx_rstoobig++;
4481a1e1d21SSam Leffler }
4491a1e1d21SSam Leffler memcpy(rs->rs_rates + rs->rs_nrates, xrates+2, nxrates);
4501a1e1d21SSam Leffler rs->rs_nrates += nxrates;
4511a1e1d21SSam Leffler }
45270e28b9aSSam Leffler return ieee80211_fix_rate(ni, rs, flags);
4531a1e1d21SSam Leffler }
4541a1e1d21SSam Leffler
45584eb84c4SSam Leffler /*
45684eb84c4SSam Leffler * Send a management frame error response to the specified
45784eb84c4SSam Leffler * station. If ni is associated with the station then use
45884eb84c4SSam Leffler * it; otherwise allocate a temporary node suitable for
45984eb84c4SSam Leffler * transmitting the frame and then free the reference so
46084eb84c4SSam Leffler * it will go away as soon as the frame has been transmitted.
46184eb84c4SSam Leffler */
462b032f27cSSam Leffler void
ieee80211_send_error(struct ieee80211_node * ni,const uint8_t mac[IEEE80211_ADDR_LEN],int subtype,int arg)463b032f27cSSam Leffler ieee80211_send_error(struct ieee80211_node *ni,
464b032f27cSSam Leffler const uint8_t mac[IEEE80211_ADDR_LEN], int subtype, int arg)
46584eb84c4SSam Leffler {
466b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
46784eb84c4SSam Leffler int istmp;
46884eb84c4SSam Leffler
469b032f27cSSam Leffler if (ni == vap->iv_bss) {
470b032f27cSSam Leffler if (vap->iv_state != IEEE80211_S_RUN) {
471b032f27cSSam Leffler /*
472b032f27cSSam Leffler * XXX hack until we get rid of this routine.
473b032f27cSSam Leffler * We can be called prior to the vap reaching
474b032f27cSSam Leffler * run state under certain conditions in which
475b032f27cSSam Leffler * case iv_bss->ni_chan will not be setup.
476b032f27cSSam Leffler * Check for this explicitly and and just ignore
477b032f27cSSam Leffler * the request.
478b032f27cSSam Leffler */
479b032f27cSSam Leffler return;
480b032f27cSSam Leffler }
481b032f27cSSam Leffler ni = ieee80211_tmp_node(vap, mac);
48284eb84c4SSam Leffler if (ni == NULL) {
48384eb84c4SSam Leffler /* XXX msg */
48484eb84c4SSam Leffler return;
48584eb84c4SSam Leffler }
48684eb84c4SSam Leffler istmp = 1;
48784eb84c4SSam Leffler } else
48884eb84c4SSam Leffler istmp = 0;
489b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, subtype, arg);
49084eb84c4SSam Leffler if (istmp)
49184eb84c4SSam Leffler ieee80211_free_node(ni);
49284eb84c4SSam Leffler }
49384eb84c4SSam Leffler
494b032f27cSSam Leffler int
ieee80211_alloc_challenge(struct ieee80211_node * ni)495b032f27cSSam Leffler ieee80211_alloc_challenge(struct ieee80211_node *ni)
4968a1b9b6aSSam Leffler {
4978a1b9b6aSSam Leffler if (ni->ni_challenge == NULL)
498b9b53389SAdrian Chadd ni->ni_challenge = (uint32_t *)
499b9b53389SAdrian Chadd IEEE80211_MALLOC(IEEE80211_CHALLENGE_LEN,
500b9b53389SAdrian Chadd M_80211_NODE, IEEE80211_M_NOWAIT);
5018a1b9b6aSSam Leffler if (ni->ni_challenge == NULL) {
502b032f27cSSam Leffler IEEE80211_NOTE(ni->ni_vap,
503b032f27cSSam Leffler IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, ni,
504b032f27cSSam Leffler "%s", "shared key challenge alloc failed");
5058a1b9b6aSSam Leffler /* XXX statistic */
5068a1b9b6aSSam Leffler }
5078a1b9b6aSSam Leffler return (ni->ni_challenge != NULL);
5088a1b9b6aSSam Leffler }
5098a1b9b6aSSam Leffler
51066ef3969SSam Leffler /*
511b032f27cSSam Leffler * Parse a Beacon or ProbeResponse frame and return the
512b032f27cSSam Leffler * useful information in an ieee80211_scanparams structure.
513b032f27cSSam Leffler * Status is set to 0 if no problems were found; otherwise
514b032f27cSSam Leffler * a bitmask of IEEE80211_BPARSE_* items is returned that
515b032f27cSSam Leffler * describes the problems detected.
51666ef3969SSam Leffler */
517b032f27cSSam Leffler int
ieee80211_parse_beacon(struct ieee80211_node * ni,struct mbuf * m,struct ieee80211_channel * rxchan,struct ieee80211_scanparams * scan)518b032f27cSSam Leffler ieee80211_parse_beacon(struct ieee80211_node *ni, struct mbuf *m,
519c79f192cSAdrian Chadd struct ieee80211_channel *rxchan, struct ieee80211_scanparams *scan)
52066ef3969SSam Leffler {
521b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
52266ef3969SSam Leffler struct ieee80211com *ic = ni->ni_ic;
5231a1e1d21SSam Leffler struct ieee80211_frame *wh;
52468e8e04eSSam Leffler uint8_t *frm, *efrm;
5251a1e1d21SSam Leffler
526b032f27cSSam Leffler wh = mtod(m, struct ieee80211_frame *);
52768e8e04eSSam Leffler frm = (uint8_t *)&wh[1];
528b032f27cSSam Leffler efrm = mtod(m, uint8_t *) + m->m_len;
529b032f27cSSam Leffler scan->status = 0;
5301a1e1d21SSam Leffler /*
5311a1e1d21SSam Leffler * beacon/probe response frame format
53251172f62SAdrian Chadd *
53351172f62SAdrian Chadd * XXX Update from 802.11-2012 - eg where HT is
5341a1e1d21SSam Leffler * [8] time stamp
5351a1e1d21SSam Leffler * [2] beacon interval
5361a1e1d21SSam Leffler * [2] capability information
5371a1e1d21SSam Leffler * [tlv] ssid
5381a1e1d21SSam Leffler * [tlv] supported rates
5391a1e1d21SSam Leffler * [tlv] country information
540c70761e6SSam Leffler * [tlv] channel switch announcement (CSA)
5411a1e1d21SSam Leffler * [tlv] parameter set (FH/DS)
5421a1e1d21SSam Leffler * [tlv] erp information
5431a1e1d21SSam Leffler * [tlv] extended supported rates
5448a1b9b6aSSam Leffler * [tlv] WME
5458a1b9b6aSSam Leffler * [tlv] WPA or RSN
54668e8e04eSSam Leffler * [tlv] HT capabilities
54768e8e04eSSam Leffler * [tlv] HT information
54851172f62SAdrian Chadd * [tlv] VHT capabilities
54951172f62SAdrian Chadd * [tlv] VHT information
55068e8e04eSSam Leffler * [tlv] Atheros capabilities
55159aa14a9SRui Paulo * [tlv] Mesh ID
55259aa14a9SRui Paulo * [tlv] Mesh Configuration
5531a1e1d21SSam Leffler */
554b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, 12,
555b032f27cSSam Leffler return (scan->status = IEEE80211_BPARSE_BADIELEN));
556b032f27cSSam Leffler memset(scan, 0, sizeof(*scan));
557b032f27cSSam Leffler scan->tstamp = frm; frm += 8;
558b032f27cSSam Leffler scan->bintval = le16toh(*(uint16_t *)frm); frm += 2;
559b032f27cSSam Leffler scan->capinfo = le16toh(*(uint16_t *)frm); frm += 2;
560c79f192cSAdrian Chadd scan->bchan = ieee80211_chan2ieee(ic, rxchan);
561b032f27cSSam Leffler scan->chan = scan->bchan;
562b032f27cSSam Leffler scan->ies = frm;
563b032f27cSSam Leffler scan->ies_len = efrm - frm;
564b5c99415SSam Leffler
56570326a6eSSam Leffler while (efrm - frm > 1) {
566b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2,
567b032f27cSSam Leffler return (scan->status = IEEE80211_BPARSE_BADIELEN));
5681a1e1d21SSam Leffler switch (*frm) {
5691a1e1d21SSam Leffler case IEEE80211_ELEMID_SSID:
570b032f27cSSam Leffler scan->ssid = frm;
5711a1e1d21SSam Leffler break;
5721a1e1d21SSam Leffler case IEEE80211_ELEMID_RATES:
573b032f27cSSam Leffler scan->rates = frm;
5741a1e1d21SSam Leffler break;
5751a1e1d21SSam Leffler case IEEE80211_ELEMID_COUNTRY:
576b032f27cSSam Leffler scan->country = frm;
5771a1e1d21SSam Leffler break;
578c70761e6SSam Leffler case IEEE80211_ELEMID_CSA:
579c70761e6SSam Leffler scan->csa = frm;
580c70761e6SSam Leffler break;
58132b0e64bSAdrian Chadd case IEEE80211_ELEMID_QUIET:
58232b0e64bSAdrian Chadd scan->quiet = frm;
58332b0e64bSAdrian Chadd break;
5841a1e1d21SSam Leffler case IEEE80211_ELEMID_FHPARMS:
5851a1e1d21SSam Leffler if (ic->ic_phytype == IEEE80211_T_FH) {
58631021a2bSAndriy Voskoboinyk scan->fhdwell = le16dec(&frm[2]);
587b032f27cSSam Leffler scan->chan = IEEE80211_FH_CHAN(frm[4], frm[5]);
588b032f27cSSam Leffler scan->fhindex = frm[6];
5891a1e1d21SSam Leffler }
5901a1e1d21SSam Leffler break;
5911a1e1d21SSam Leffler case IEEE80211_ELEMID_DSPARMS:
5921a1e1d21SSam Leffler /*
5931a1e1d21SSam Leffler * XXX hack this since depending on phytype
5941a1e1d21SSam Leffler * is problematic for multi-mode devices.
5951a1e1d21SSam Leffler */
5961a1e1d21SSam Leffler if (ic->ic_phytype != IEEE80211_T_FH)
597b032f27cSSam Leffler scan->chan = frm[2];
5981a1e1d21SSam Leffler break;
5991a1e1d21SSam Leffler case IEEE80211_ELEMID_TIM:
6008a1b9b6aSSam Leffler /* XXX ATIM? */
601b032f27cSSam Leffler scan->tim = frm;
602b032f27cSSam Leffler scan->timoff = frm - mtod(m, uint8_t *);
6031a1e1d21SSam Leffler break;
6044bd067c5SSam Leffler case IEEE80211_ELEMID_IBSSPARMS:
605b032f27cSSam Leffler case IEEE80211_ELEMID_CFPARMS:
606643024a2SSam Leffler case IEEE80211_ELEMID_PWRCNSTR:
607523210fbSAdrian Chadd case IEEE80211_ELEMID_BSSLOAD:
608523210fbSAdrian Chadd case IEEE80211_ELEMID_APCHANREP:
609b032f27cSSam Leffler /* NB: avoid debugging complaints */
6104bd067c5SSam Leffler break;
6111a1e1d21SSam Leffler case IEEE80211_ELEMID_XRATES:
612b032f27cSSam Leffler scan->xrates = frm;
6131a1e1d21SSam Leffler break;
6141a1e1d21SSam Leffler case IEEE80211_ELEMID_ERP:
6151a1e1d21SSam Leffler if (frm[1] != 1) {
616b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap,
6178a1b9b6aSSam Leffler IEEE80211_MSG_ELEMID, wh, "ERP",
6188a1b9b6aSSam Leffler "bad len %u", frm[1]);
619b032f27cSSam Leffler vap->iv_stats.is_rx_elem_toobig++;
6201a1e1d21SSam Leffler break;
6211a1e1d21SSam Leffler }
622b032f27cSSam Leffler scan->erp = frm[2] | 0x100;
6231a1e1d21SSam Leffler break;
62468e8e04eSSam Leffler case IEEE80211_ELEMID_HTCAP:
625b032f27cSSam Leffler scan->htcap = frm;
62668e8e04eSSam Leffler break;
62751172f62SAdrian Chadd case IEEE80211_ELEMID_VHT_CAP:
62851172f62SAdrian Chadd scan->vhtcap = frm;
62951172f62SAdrian Chadd break;
63051172f62SAdrian Chadd case IEEE80211_ELEMID_VHT_OPMODE:
63151172f62SAdrian Chadd scan->vhtopmode = frm;
63251172f62SAdrian Chadd break;
6338a1b9b6aSSam Leffler case IEEE80211_ELEMID_RSN:
634b032f27cSSam Leffler scan->rsn = frm;
63568e8e04eSSam Leffler break;
63668e8e04eSSam Leffler case IEEE80211_ELEMID_HTINFO:
637b032f27cSSam Leffler scan->htinfo = frm;
6388a1b9b6aSSam Leffler break;
639fbe007daSRui Paulo #ifdef IEEE80211_SUPPORT_MESH
64059aa14a9SRui Paulo case IEEE80211_ELEMID_MESHID:
64159aa14a9SRui Paulo scan->meshid = frm;
64259aa14a9SRui Paulo break;
64359aa14a9SRui Paulo case IEEE80211_ELEMID_MESHCONF:
64459aa14a9SRui Paulo scan->meshconf = frm;
64559aa14a9SRui Paulo break;
64659aa14a9SRui Paulo #endif
647f3e24d74SAdrian Chadd /* Extended capabilities; nothing handles it for now */
648f3e24d74SAdrian Chadd case IEEE80211_ELEMID_EXTCAP:
649f3e24d74SAdrian Chadd break;
6508a1b9b6aSSam Leffler case IEEE80211_ELEMID_VENDOR:
6518a1b9b6aSSam Leffler if (iswpaoui(frm))
652b032f27cSSam Leffler scan->wpa = frm;
6538a1b9b6aSSam Leffler else if (iswmeparam(frm) || iswmeinfo(frm))
654b032f27cSSam Leffler scan->wme = frm;
655616190d0SSam Leffler #ifdef IEEE80211_SUPPORT_SUPERG
65668e8e04eSSam Leffler else if (isatherosoui(frm))
657b032f27cSSam Leffler scan->ath = frm;
658616190d0SSam Leffler #endif
65910ad9a77SSam Leffler #ifdef IEEE80211_SUPPORT_TDMA
66010ad9a77SSam Leffler else if (istdmaoui(frm))
66110ad9a77SSam Leffler scan->tdma = frm;
66210ad9a77SSam Leffler #endif
6632bfc8a91SSam Leffler else if (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) {
66468e8e04eSSam Leffler /*
66568e8e04eSSam Leffler * Accept pre-draft HT ie's if the
66668e8e04eSSam Leffler * standard ones have not been seen.
66768e8e04eSSam Leffler */
66868e8e04eSSam Leffler if (ishtcapoui(frm)) {
669b032f27cSSam Leffler if (scan->htcap == NULL)
670b032f27cSSam Leffler scan->htcap = frm;
67168e8e04eSSam Leffler } else if (ishtinfooui(frm)) {
672b032f27cSSam Leffler if (scan->htinfo == NULL)
673b032f27cSSam Leffler scan->htcap = frm;
67468e8e04eSSam Leffler }
67568e8e04eSSam Leffler }
6768a1b9b6aSSam Leffler break;
6771a1e1d21SSam Leffler default:
678b032f27cSSam Leffler IEEE80211_DISCARD_IE(vap, IEEE80211_MSG_ELEMID,
6798a1b9b6aSSam Leffler wh, "unhandled",
6808a1b9b6aSSam Leffler "id %u, len %u", *frm, frm[1]);
681b032f27cSSam Leffler vap->iv_stats.is_rx_elem_unknown++;
6821a1e1d21SSam Leffler break;
6831a1e1d21SSam Leffler }
6841a1e1d21SSam Leffler frm += frm[1] + 2;
6851a1e1d21SSam Leffler }
686b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(scan->rates, IEEE80211_RATE_MAXSIZE,
687b032f27cSSam Leffler scan->status |= IEEE80211_BPARSE_RATES_INVALID);
688b032f27cSSam Leffler if (scan->rates != NULL && scan->xrates != NULL) {
689b032f27cSSam Leffler /*
690b032f27cSSam Leffler * NB: don't process XRATES if RATES is missing. This
691b032f27cSSam Leffler * avoids a potential null ptr deref and should be ok
692b032f27cSSam Leffler * as the return code will already note RATES is missing
693b032f27cSSam Leffler * (so callers shouldn't otherwise process the frame).
694b032f27cSSam Leffler */
695b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(scan->xrates,
696b032f27cSSam Leffler IEEE80211_RATE_MAXSIZE - scan->rates[1],
697b032f27cSSam Leffler scan->status |= IEEE80211_BPARSE_XRATES_INVALID);
698b032f27cSSam Leffler }
699b032f27cSSam Leffler IEEE80211_VERIFY_ELEMENT(scan->ssid, IEEE80211_NWID_LEN,
700b032f27cSSam Leffler scan->status |= IEEE80211_BPARSE_SSID_INVALID);
701b032f27cSSam Leffler if (scan->chan != scan->bchan && ic->ic_phytype != IEEE80211_T_FH) {
7021a1e1d21SSam Leffler /*
7031a1e1d21SSam Leffler * Frame was received on a channel different from the
7044844aa7dSAtsushi Onoe * one indicated in the DS params element id;
7051a1e1d21SSam Leffler * silently discard it.
7061a1e1d21SSam Leffler *
7071a1e1d21SSam Leffler * NB: this can happen due to signal leakage.
7084844aa7dSAtsushi Onoe * But we should take it for FH phy because
7094844aa7dSAtsushi Onoe * the rssi value should be correct even for
7104844aa7dSAtsushi Onoe * different hop pattern in FH.
7111a1e1d21SSam Leffler */
712b032f27cSSam Leffler IEEE80211_DISCARD(vap,
713d365f9c7SSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
714c79f192cSAdrian Chadd wh, NULL, "for off-channel %u (bchan=%u)",
715c79f192cSAdrian Chadd scan->chan, scan->bchan);
716b032f27cSSam Leffler vap->iv_stats.is_rx_chanmismatch++;
717b032f27cSSam Leffler scan->status |= IEEE80211_BPARSE_OFFCHAN;
718b5c99415SSam Leffler }
719b032f27cSSam Leffler if (!(IEEE80211_BINTVAL_MIN <= scan->bintval &&
720b032f27cSSam Leffler scan->bintval <= IEEE80211_BINTVAL_MAX)) {
721b032f27cSSam Leffler IEEE80211_DISCARD(vap,
722b5c99415SSam Leffler IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
723de681822SAdrian Chadd wh, NULL, "bogus beacon interval (%d TU)",
724de681822SAdrian Chadd (int) scan->bintval);
725b032f27cSSam Leffler vap->iv_stats.is_rx_badbintval++;
726b032f27cSSam Leffler scan->status |= IEEE80211_BPARSE_BINTVAL_INVALID;
727b032f27cSSam Leffler }
728b032f27cSSam Leffler if (scan->country != NULL) {
729b032f27cSSam Leffler /*
730b032f27cSSam Leffler * Validate we have at least enough data to extract
731b032f27cSSam Leffler * the country code. Not sure if we should return an
732b032f27cSSam Leffler * error instead of discarding the IE; consider this
733b032f27cSSam Leffler * being lenient as we don't depend on the data for
734b032f27cSSam Leffler * correct operation.
735b032f27cSSam Leffler */
736b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(scan->country[1], 3 * sizeof(uint8_t),
737b032f27cSSam Leffler scan->country = NULL);
738d365f9c7SSam Leffler }
739c70761e6SSam Leffler if (scan->csa != NULL) {
740c70761e6SSam Leffler /*
741c70761e6SSam Leffler * Validate Channel Switch Announcement; this must
742c70761e6SSam Leffler * be the correct length or we toss the frame.
743c70761e6SSam Leffler */
744c70761e6SSam Leffler IEEE80211_VERIFY_LENGTH(scan->csa[1], 3 * sizeof(uint8_t),
745c70761e6SSam Leffler scan->status |= IEEE80211_BPARSE_CSA_INVALID);
746c70761e6SSam Leffler }
747fb8c87b4SBjoern A. Zeeb #ifdef IEEE80211_SUPPORT_MESH
748fb8c87b4SBjoern A. Zeeb if (scan->meshid != NULL) {
749fb8c87b4SBjoern A. Zeeb IEEE80211_VERIFY_ELEMENT(scan->meshid, IEEE80211_MESHID_LEN,
75073547826SBjoern A. Zeeb scan->status |= IEEE80211_BPARSE_MESHID_INVALID);
751fb8c87b4SBjoern A. Zeeb }
752fb8c87b4SBjoern A. Zeeb #endif
75368e8e04eSSam Leffler /*
75468e8e04eSSam Leffler * Process HT ie's. This is complicated by our
75568e8e04eSSam Leffler * accepting both the standard ie's and the pre-draft
75668e8e04eSSam Leffler * vendor OUI ie's that some vendors still use/require.
75768e8e04eSSam Leffler */
758b032f27cSSam Leffler if (scan->htcap != NULL) {
759b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(scan->htcap[1],
760b032f27cSSam Leffler scan->htcap[0] == IEEE80211_ELEMID_VENDOR ?
76168e8e04eSSam Leffler 4 + sizeof(struct ieee80211_ie_htcap)-2 :
76268e8e04eSSam Leffler sizeof(struct ieee80211_ie_htcap)-2,
763b032f27cSSam Leffler scan->htcap = NULL);
76468e8e04eSSam Leffler }
765b032f27cSSam Leffler if (scan->htinfo != NULL) {
766b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(scan->htinfo[1],
767b032f27cSSam Leffler scan->htinfo[0] == IEEE80211_ELEMID_VENDOR ?
76868e8e04eSSam Leffler 4 + sizeof(struct ieee80211_ie_htinfo)-2 :
76968e8e04eSSam Leffler sizeof(struct ieee80211_ie_htinfo)-2,
770b032f27cSSam Leffler scan->htinfo = NULL);
771b032f27cSSam Leffler }
77251172f62SAdrian Chadd
77351172f62SAdrian Chadd /* Process VHT IEs */
77451172f62SAdrian Chadd if (scan->vhtcap != NULL) {
77551172f62SAdrian Chadd IEEE80211_VERIFY_LENGTH(scan->vhtcap[1],
776*e85eb4c8SBjoern A. Zeeb sizeof(struct ieee80211_vht_cap),
77751172f62SAdrian Chadd scan->vhtcap = NULL);
77851172f62SAdrian Chadd }
77951172f62SAdrian Chadd if (scan->vhtopmode != NULL) {
78051172f62SAdrian Chadd IEEE80211_VERIFY_LENGTH(scan->vhtopmode[1],
781*e85eb4c8SBjoern A. Zeeb sizeof(struct ieee80211_vht_operation),
78251172f62SAdrian Chadd scan->vhtopmode = NULL);
78351172f62SAdrian Chadd }
78451172f62SAdrian Chadd
785b032f27cSSam Leffler return scan->status;
78668e8e04eSSam Leffler }
7871a1e1d21SSam Leffler
7881a1e1d21SSam Leffler /*
789b032f27cSSam Leffler * Parse an Action frame. Return 0 on success, non-zero on failure.
79044c72e42SSam Leffler */
791b032f27cSSam Leffler int
ieee80211_parse_action(struct ieee80211_node * ni,struct mbuf * m)792b032f27cSSam Leffler ieee80211_parse_action(struct ieee80211_node *ni, struct mbuf *m)
793b032f27cSSam Leffler {
794b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
79568e8e04eSSam Leffler const struct ieee80211_action *ia;
796b032f27cSSam Leffler struct ieee80211_frame *wh;
797b032f27cSSam Leffler uint8_t *frm, *efrm;
79868e8e04eSSam Leffler
79968e8e04eSSam Leffler /*
80068e8e04eSSam Leffler * action frame format:
80168e8e04eSSam Leffler * [1] category
80268e8e04eSSam Leffler * [1] action
80368e8e04eSSam Leffler * [tlv] parameters
80468e8e04eSSam Leffler */
805b032f27cSSam Leffler wh = mtod(m, struct ieee80211_frame *);
806b032f27cSSam Leffler frm = (u_int8_t *)&wh[1];
807b032f27cSSam Leffler efrm = mtod(m, u_int8_t *) + m->m_len;
80868e8e04eSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm,
809b032f27cSSam Leffler sizeof(struct ieee80211_action), return EINVAL);
81068e8e04eSSam Leffler ia = (const struct ieee80211_action *) frm;
81168e8e04eSSam Leffler
812b032f27cSSam Leffler vap->iv_stats.is_rx_action++;
81368e8e04eSSam Leffler IEEE80211_NODE_STAT(ni, rx_action);
81468e8e04eSSam Leffler
81568e8e04eSSam Leffler /* verify frame payloads but defer processing */
81668e8e04eSSam Leffler switch (ia->ia_category) {
81768e8e04eSSam Leffler case IEEE80211_ACTION_CAT_BA:
81868e8e04eSSam Leffler switch (ia->ia_action) {
81968e8e04eSSam Leffler case IEEE80211_ACTION_BA_ADDBA_REQUEST:
82068e8e04eSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm,
82168e8e04eSSam Leffler sizeof(struct ieee80211_action_ba_addbarequest),
822b032f27cSSam Leffler return EINVAL);
82368e8e04eSSam Leffler break;
82468e8e04eSSam Leffler case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
82568e8e04eSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm,
82668e8e04eSSam Leffler sizeof(struct ieee80211_action_ba_addbaresponse),
827b032f27cSSam Leffler return EINVAL);
82868e8e04eSSam Leffler break;
82968e8e04eSSam Leffler case IEEE80211_ACTION_BA_DELBA:
83068e8e04eSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm,
83168e8e04eSSam Leffler sizeof(struct ieee80211_action_ba_delba),
832b032f27cSSam Leffler return EINVAL);
83368e8e04eSSam Leffler break;
83468e8e04eSSam Leffler }
83568e8e04eSSam Leffler break;
83668e8e04eSSam Leffler case IEEE80211_ACTION_CAT_HT:
83768e8e04eSSam Leffler switch (ia->ia_action) {
83868e8e04eSSam Leffler case IEEE80211_ACTION_HT_TXCHWIDTH:
83968e8e04eSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm,
84068e8e04eSSam Leffler sizeof(struct ieee80211_action_ht_txchwidth),
841b032f27cSSam Leffler return EINVAL);
842b032f27cSSam Leffler break;
843b032f27cSSam Leffler case IEEE80211_ACTION_HT_MIMOPWRSAVE:
844b032f27cSSam Leffler IEEE80211_VERIFY_LENGTH(efrm - frm,
845b032f27cSSam Leffler sizeof(struct ieee80211_action_ht_mimopowersave),
846b032f27cSSam Leffler return EINVAL);
84768e8e04eSSam Leffler break;
84868e8e04eSSam Leffler }
84968e8e04eSSam Leffler break;
850dbab732dSGleb Smirnoff #ifdef IEEE80211_SUPPORT_MESH
851bdd2a076SAdrian Chadd case IEEE80211_ACTION_CAT_MESH:
852bdd2a076SAdrian Chadd switch (ia->ia_action) {
853bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_LMETRIC:
854bdd2a076SAdrian Chadd /*
855bdd2a076SAdrian Chadd * XXX: verification is true only if we are using
856bdd2a076SAdrian Chadd * Airtime link metric (default)
857bdd2a076SAdrian Chadd */
858bdd2a076SAdrian Chadd IEEE80211_VERIFY_LENGTH(efrm - frm,
859bdd2a076SAdrian Chadd sizeof(struct ieee80211_meshlmetric_ie),
860bdd2a076SAdrian Chadd return EINVAL);
861bdd2a076SAdrian Chadd break;
862bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_HWMP:
863bdd2a076SAdrian Chadd /* verify something */
864bdd2a076SAdrian Chadd break;
865bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_GANN:
866c81ceff7SMonthadar Al Jaberi IEEE80211_VERIFY_LENGTH(efrm - frm,
867c81ceff7SMonthadar Al Jaberi sizeof(struct ieee80211_meshgann_ie),
868c81ceff7SMonthadar Al Jaberi return EINVAL);
869c81ceff7SMonthadar Al Jaberi break;
870bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_CC:
871bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_MCCA_SREQ:
872bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_MCCA_SREP:
873bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_MCCA_AREQ:
874bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_MCCA_ADVER:
875bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_MCCA_TRDOWN:
876bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_TBTT_REQ:
877bdd2a076SAdrian Chadd case IEEE80211_ACTION_MESH_TBTT_RES:
878bdd2a076SAdrian Chadd /* reject these early on, not implemented */
879bdd2a076SAdrian Chadd IEEE80211_DISCARD(vap,
880bdd2a076SAdrian Chadd IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
881bdd2a076SAdrian Chadd wh, NULL, "not implemented yet, act=0x%02X",
882bdd2a076SAdrian Chadd ia->ia_action);
883bdd2a076SAdrian Chadd return EINVAL;
884bdd2a076SAdrian Chadd }
885bdd2a076SAdrian Chadd break;
886ebeaa1adSMonthadar Al Jaberi case IEEE80211_ACTION_CAT_SELF_PROT:
887ebeaa1adSMonthadar Al Jaberi /* If TA or RA group address discard silently */
888ebeaa1adSMonthadar Al Jaberi if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
889ebeaa1adSMonthadar Al Jaberi IEEE80211_IS_MULTICAST(wh->i_addr2))
890ebeaa1adSMonthadar Al Jaberi return EINVAL;
891ebeaa1adSMonthadar Al Jaberi /*
892ebeaa1adSMonthadar Al Jaberi * XXX: Should we verify complete length now or it is
893ebeaa1adSMonthadar Al Jaberi * to varying in sizes?
894ebeaa1adSMonthadar Al Jaberi */
895ebeaa1adSMonthadar Al Jaberi switch (ia->ia_action) {
896ebeaa1adSMonthadar Al Jaberi case IEEE80211_ACTION_MESHPEERING_CONFIRM:
897ebeaa1adSMonthadar Al Jaberi case IEEE80211_ACTION_MESHPEERING_CLOSE:
898ebeaa1adSMonthadar Al Jaberi /* is not a peering candidate (yet) */
899ebeaa1adSMonthadar Al Jaberi if (ni == vap->iv_bss)
900ebeaa1adSMonthadar Al Jaberi return EINVAL;
901ebeaa1adSMonthadar Al Jaberi break;
902ebeaa1adSMonthadar Al Jaberi }
903ebeaa1adSMonthadar Al Jaberi break;
904dbab732dSGleb Smirnoff #endif
90551172f62SAdrian Chadd case IEEE80211_ACTION_CAT_VHT:
90651172f62SAdrian Chadd printf("%s: TODO: VHT handling!\n", __func__);
90751172f62SAdrian Chadd break;
90868e8e04eSSam Leffler }
909b032f27cSSam Leffler return 0;
9108a1b9b6aSSam Leffler }
9118a1b9b6aSSam Leffler
9128a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG
9138a1b9b6aSSam Leffler /*
9148a1b9b6aSSam Leffler * Debugging support.
9158a1b9b6aSSam Leffler */
916b032f27cSSam Leffler void
ieee80211_ssid_mismatch(struct ieee80211vap * vap,const char * tag,uint8_t mac[IEEE80211_ADDR_LEN],uint8_t * ssid)917b032f27cSSam Leffler ieee80211_ssid_mismatch(struct ieee80211vap *vap, const char *tag,
918b032f27cSSam Leffler uint8_t mac[IEEE80211_ADDR_LEN], uint8_t *ssid)
919b032f27cSSam Leffler {
920b032f27cSSam Leffler printf("[%s] discard %s frame, ssid mismatch: ",
921b032f27cSSam Leffler ether_sprintf(mac), tag);
922b032f27cSSam Leffler ieee80211_print_essid(ssid + 2, ssid[1]);
923b032f27cSSam Leffler printf("\n");
924b032f27cSSam Leffler }
9258a1b9b6aSSam Leffler
9268a1b9b6aSSam Leffler /*
9278a1b9b6aSSam Leffler * Return the bssid of a frame.
9288a1b9b6aSSam Leffler */
92968e8e04eSSam Leffler static const uint8_t *
ieee80211_getbssid(const struct ieee80211vap * vap,const struct ieee80211_frame * wh)930d2bc4bf6SRui Paulo ieee80211_getbssid(const struct ieee80211vap *vap,
931d2bc4bf6SRui Paulo const struct ieee80211_frame *wh)
9328a1b9b6aSSam Leffler {
933b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA)
9348a1b9b6aSSam Leffler return wh->i_addr2;
9358a1b9b6aSSam Leffler if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != IEEE80211_FC1_DIR_NODS)
9368a1b9b6aSSam Leffler return wh->i_addr1;
9378a1b9b6aSSam Leffler if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
9388a1b9b6aSSam Leffler return wh->i_addr1;
9398a1b9b6aSSam Leffler return wh->i_addr3;
9408a1b9b6aSSam Leffler }
9418a1b9b6aSSam Leffler
942b032f27cSSam Leffler #include <machine/stdarg.h>
943b032f27cSSam Leffler
944f6df3191SSam Leffler void
ieee80211_note(const struct ieee80211vap * vap,const char * fmt,...)945d2bc4bf6SRui Paulo ieee80211_note(const struct ieee80211vap *vap, const char *fmt, ...)
946f6df3191SSam Leffler {
94704435a1bSBjoern A. Zeeb char buf[256]; /* XXX */
948f6df3191SSam Leffler va_list ap;
94904435a1bSBjoern A. Zeeb int len;
950f6df3191SSam Leffler
951f6df3191SSam Leffler va_start(ap, fmt);
95204435a1bSBjoern A. Zeeb len = vsnprintf(buf, sizeof(buf), fmt, ap);
953f6df3191SSam Leffler va_end(ap);
954f6df3191SSam Leffler
955b032f27cSSam Leffler if_printf(vap->iv_ifp, "%s", buf); /* NB: no \n */
95604435a1bSBjoern A. Zeeb
95704435a1bSBjoern A. Zeeb if (len >= sizeof(buf))
95804435a1bSBjoern A. Zeeb printf("%s: XXX buffer too small: len = %d\n", __func__, len);
959f6df3191SSam Leffler }
960f6df3191SSam Leffler
961f6df3191SSam Leffler void
ieee80211_note_frame(const struct ieee80211vap * vap,const struct ieee80211_frame * wh,const char * fmt,...)962d2bc4bf6SRui Paulo ieee80211_note_frame(const struct ieee80211vap *vap,
963f6df3191SSam Leffler const struct ieee80211_frame *wh,
964f6df3191SSam Leffler const char *fmt, ...)
965f6df3191SSam Leffler {
96604435a1bSBjoern A. Zeeb char buf[256]; /* XXX */
967f6df3191SSam Leffler va_list ap;
96804435a1bSBjoern A. Zeeb int len;
969f6df3191SSam Leffler
970f6df3191SSam Leffler va_start(ap, fmt);
97104435a1bSBjoern A. Zeeb len = vsnprintf(buf, sizeof(buf), fmt, ap);
972f6df3191SSam Leffler va_end(ap);
973b032f27cSSam Leffler if_printf(vap->iv_ifp, "[%s] %s\n",
974b032f27cSSam Leffler ether_sprintf(ieee80211_getbssid(vap, wh)), buf);
97504435a1bSBjoern A. Zeeb
97604435a1bSBjoern A. Zeeb if (len >= sizeof(buf))
97704435a1bSBjoern A. Zeeb printf("%s: XXX buffer too small: len = %d\n", __func__, len);
978f6df3191SSam Leffler }
979f6df3191SSam Leffler
980f6df3191SSam Leffler void
ieee80211_note_mac(const struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],const char * fmt,...)981d2bc4bf6SRui Paulo ieee80211_note_mac(const struct ieee80211vap *vap,
98268e8e04eSSam Leffler const uint8_t mac[IEEE80211_ADDR_LEN],
983f6df3191SSam Leffler const char *fmt, ...)
984f6df3191SSam Leffler {
98504435a1bSBjoern A. Zeeb char buf[256]; /* XXX */
986f6df3191SSam Leffler va_list ap;
98704435a1bSBjoern A. Zeeb int len;
988f6df3191SSam Leffler
989f6df3191SSam Leffler va_start(ap, fmt);
99004435a1bSBjoern A. Zeeb len = vsnprintf(buf, sizeof(buf), fmt, ap);
991f6df3191SSam Leffler va_end(ap);
992b032f27cSSam Leffler if_printf(vap->iv_ifp, "[%s] %s\n", ether_sprintf(mac), buf);
99304435a1bSBjoern A. Zeeb
99404435a1bSBjoern A. Zeeb if (len >= sizeof(buf))
99504435a1bSBjoern A. Zeeb printf("%s: XXX buffer too small: len = %d\n", __func__, len);
996f6df3191SSam Leffler }
997f6df3191SSam Leffler
998a000d7c2SSam Leffler void
ieee80211_discard_frame(const struct ieee80211vap * vap,const struct ieee80211_frame * wh,const char * type,const char * fmt,...)999d2bc4bf6SRui Paulo ieee80211_discard_frame(const struct ieee80211vap *vap,
10008a1b9b6aSSam Leffler const struct ieee80211_frame *wh,
10018a1b9b6aSSam Leffler const char *type, const char *fmt, ...)
10028a1b9b6aSSam Leffler {
100304435a1bSBjoern A. Zeeb char buf[256]; /* XXX */
10048a1b9b6aSSam Leffler va_list ap;
100504435a1bSBjoern A. Zeeb int len;
10068a1b9b6aSSam Leffler
10078a1b9b6aSSam Leffler va_start(ap, fmt);
100804435a1bSBjoern A. Zeeb len = vsnprintf(buf, sizeof(buf), fmt, ap);
10098a1b9b6aSSam Leffler va_end(ap);
101004435a1bSBjoern A. Zeeb
101104435a1bSBjoern A. Zeeb if_printf(vap->iv_ifp, "[%s] discard %s frame, %s\n",
101204435a1bSBjoern A. Zeeb ether_sprintf(ieee80211_getbssid(vap, wh)),
101304435a1bSBjoern A. Zeeb type != NULL ? type : ieee80211_mgt_subtype_name(wh->i_fc[0]),
101404435a1bSBjoern A. Zeeb buf);
101504435a1bSBjoern A. Zeeb
101604435a1bSBjoern A. Zeeb if (len >= sizeof(buf))
101704435a1bSBjoern A. Zeeb printf("%s: XXX buffer too small: len = %d\n", __func__, len);
10188a1b9b6aSSam Leffler }
10198a1b9b6aSSam Leffler
1020a000d7c2SSam Leffler void
ieee80211_discard_ie(const struct ieee80211vap * vap,const struct ieee80211_frame * wh,const char * type,const char * fmt,...)1021d2bc4bf6SRui Paulo ieee80211_discard_ie(const struct ieee80211vap *vap,
10228a1b9b6aSSam Leffler const struct ieee80211_frame *wh,
10238a1b9b6aSSam Leffler const char *type, const char *fmt, ...)
10248a1b9b6aSSam Leffler {
102504435a1bSBjoern A. Zeeb char buf[256]; /* XXX */
10268a1b9b6aSSam Leffler va_list ap;
102704435a1bSBjoern A. Zeeb int len;
10288a1b9b6aSSam Leffler
10298a1b9b6aSSam Leffler va_start(ap, fmt);
103004435a1bSBjoern A. Zeeb len = vsnprintf(buf, sizeof(buf), fmt, ap);
10318a1b9b6aSSam Leffler va_end(ap);
103204435a1bSBjoern A. Zeeb
103304435a1bSBjoern A. Zeeb if_printf(vap->iv_ifp, "[%s] discard%s%s information element, %s\n",
103404435a1bSBjoern A. Zeeb ether_sprintf(ieee80211_getbssid(vap, wh)),
103504435a1bSBjoern A. Zeeb type != NULL ? " " : "", type != NULL ? type : "", buf);
103604435a1bSBjoern A. Zeeb
103704435a1bSBjoern A. Zeeb if (len >= sizeof(buf))
103804435a1bSBjoern A. Zeeb printf("%s: XXX buffer too small: len = %d\n", __func__, len);
10398a1b9b6aSSam Leffler }
10408a1b9b6aSSam Leffler
1041a000d7c2SSam Leffler void
ieee80211_discard_mac(const struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],const char * type,const char * fmt,...)1042d2bc4bf6SRui Paulo ieee80211_discard_mac(const struct ieee80211vap *vap,
104368e8e04eSSam Leffler const uint8_t mac[IEEE80211_ADDR_LEN],
10448a1b9b6aSSam Leffler const char *type, const char *fmt, ...)
10458a1b9b6aSSam Leffler {
104604435a1bSBjoern A. Zeeb char buf[256]; /* XXX */
10478a1b9b6aSSam Leffler va_list ap;
104804435a1bSBjoern A. Zeeb int len;
10498a1b9b6aSSam Leffler
10508a1b9b6aSSam Leffler va_start(ap, fmt);
105104435a1bSBjoern A. Zeeb len = vsnprintf(buf, sizeof(buf), fmt, ap);
10528a1b9b6aSSam Leffler va_end(ap);
105304435a1bSBjoern A. Zeeb
105404435a1bSBjoern A. Zeeb if_printf(vap->iv_ifp, "[%s] discard%s%s frame, %s\n",
105504435a1bSBjoern A. Zeeb ether_sprintf(mac),
105604435a1bSBjoern A. Zeeb type != NULL ? " " : "", type != NULL ? type : "", buf);
105704435a1bSBjoern A. Zeeb
105804435a1bSBjoern A. Zeeb if (len >= sizeof(buf))
105904435a1bSBjoern A. Zeeb printf("%s: XXX buffer too small: len = %d\n", __func__, len);
10608a1b9b6aSSam Leffler }
10618a1b9b6aSSam Leffler #endif /* IEEE80211_DEBUG */
1062