1753c7e08SAugustin Cavalier /*-
286021fd4SAugustin Cavalier * SPDX-License-Identifier: BSD-2-Clause
38244a9baSAugustin Cavalier *
4753c7e08SAugustin Cavalier * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
5753c7e08SAugustin Cavalier * All rights reserved.
6753c7e08SAugustin Cavalier *
7753c7e08SAugustin Cavalier * Redistribution and use in source and binary forms, with or without
8753c7e08SAugustin Cavalier * modification, are permitted provided that the following conditions
9753c7e08SAugustin Cavalier * are met:
10753c7e08SAugustin Cavalier * 1. Redistributions of source code must retain the above copyright
11753c7e08SAugustin Cavalier * notice, this list of conditions and the following disclaimer.
12753c7e08SAugustin Cavalier * 2. Redistributions in binary form must reproduce the above copyright
13753c7e08SAugustin Cavalier * notice, this list of conditions and the following disclaimer in the
14753c7e08SAugustin Cavalier * documentation and/or other materials provided with the distribution.
15753c7e08SAugustin Cavalier *
16753c7e08SAugustin Cavalier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17753c7e08SAugustin Cavalier * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18753c7e08SAugustin Cavalier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19753c7e08SAugustin Cavalier * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20753c7e08SAugustin Cavalier * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21753c7e08SAugustin Cavalier * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22753c7e08SAugustin Cavalier * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23753c7e08SAugustin Cavalier * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24753c7e08SAugustin Cavalier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25753c7e08SAugustin Cavalier * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26753c7e08SAugustin Cavalier */
27753c7e08SAugustin Cavalier
28753c7e08SAugustin Cavalier /*
29753c7e08SAugustin Cavalier * IEEE 802.11 HOSTAP mode support.
30753c7e08SAugustin Cavalier */
31753c7e08SAugustin Cavalier #include "opt_inet.h"
32753c7e08SAugustin Cavalier #include "opt_wlan.h"
33753c7e08SAugustin Cavalier
34753c7e08SAugustin Cavalier #include <sys/param.h>
35753c7e08SAugustin Cavalier #include <sys/systm.h>
36753c7e08SAugustin Cavalier #include <sys/mbuf.h>
37753c7e08SAugustin Cavalier #include <sys/malloc.h>
38753c7e08SAugustin Cavalier #include <sys/kernel.h>
3986021fd4SAugustin Cavalier #include <sys/epoch.h>
40753c7e08SAugustin Cavalier
41753c7e08SAugustin Cavalier #include <sys/socket.h>
42753c7e08SAugustin Cavalier #include <sys/sockio.h>
43753c7e08SAugustin Cavalier #include <sys/endian.h>
44753c7e08SAugustin Cavalier #include <sys/errno.h>
45753c7e08SAugustin Cavalier #include <sys/proc.h>
46753c7e08SAugustin Cavalier #include <sys/sysctl.h>
47753c7e08SAugustin Cavalier
48753c7e08SAugustin Cavalier #include <net/if.h>
49753c7e08SAugustin Cavalier #include <net/if_var.h>
50753c7e08SAugustin Cavalier #include <net/if_media.h>
51753c7e08SAugustin Cavalier #include <net/if_llc.h>
5286021fd4SAugustin Cavalier #include <net/if_private.h>
53753c7e08SAugustin Cavalier #include <net/ethernet.h>
54753c7e08SAugustin Cavalier
55753c7e08SAugustin Cavalier #include <net/bpf.h>
56753c7e08SAugustin Cavalier
57753c7e08SAugustin Cavalier #include <net80211/ieee80211_var.h>
58753c7e08SAugustin Cavalier #include <net80211/ieee80211_hostap.h>
59753c7e08SAugustin Cavalier #include <net80211/ieee80211_input.h>
60753c7e08SAugustin Cavalier #ifdef IEEE80211_SUPPORT_SUPERG
61753c7e08SAugustin Cavalier #include <net80211/ieee80211_superg.h>
62753c7e08SAugustin Cavalier #endif
63753c7e08SAugustin Cavalier #include <net80211/ieee80211_wds.h>
648244a9baSAugustin Cavalier #include <net80211/ieee80211_vht.h>
655cad57c4SJérôme Duval #include <net80211/ieee80211_sta.h> /* for parse_wmeie */
66753c7e08SAugustin Cavalier
67753c7e08SAugustin Cavalier #define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2)
68753c7e08SAugustin Cavalier
69753c7e08SAugustin Cavalier static void hostap_vattach(struct ieee80211vap *);
70753c7e08SAugustin Cavalier static int hostap_newstate(struct ieee80211vap *, enum ieee80211_state, int);
71753c7e08SAugustin Cavalier static int hostap_input(struct ieee80211_node *ni, struct mbuf *m,
72753c7e08SAugustin Cavalier const struct ieee80211_rx_stats *,
73753c7e08SAugustin Cavalier int rssi, int nf);
74753c7e08SAugustin Cavalier static void hostap_deliver_data(struct ieee80211vap *,
75753c7e08SAugustin Cavalier struct ieee80211_node *, struct mbuf *);
76753c7e08SAugustin Cavalier static void hostap_recv_mgmt(struct ieee80211_node *, struct mbuf *,
77753c7e08SAugustin Cavalier int subtype, const struct ieee80211_rx_stats *rxs, int rssi, int nf);
78753c7e08SAugustin Cavalier static void hostap_recv_ctl(struct ieee80211_node *, struct mbuf *, int);
79753c7e08SAugustin Cavalier
80753c7e08SAugustin Cavalier void
ieee80211_hostap_attach(struct ieee80211com * ic)81753c7e08SAugustin Cavalier ieee80211_hostap_attach(struct ieee80211com *ic)
82753c7e08SAugustin Cavalier {
83753c7e08SAugustin Cavalier ic->ic_vattach[IEEE80211_M_HOSTAP] = hostap_vattach;
84753c7e08SAugustin Cavalier }
85753c7e08SAugustin Cavalier
86753c7e08SAugustin Cavalier void
ieee80211_hostap_detach(struct ieee80211com * ic)87753c7e08SAugustin Cavalier ieee80211_hostap_detach(struct ieee80211com *ic)
88753c7e08SAugustin Cavalier {
89753c7e08SAugustin Cavalier }
90753c7e08SAugustin Cavalier
91753c7e08SAugustin Cavalier static void
hostap_vdetach(struct ieee80211vap * vap)92753c7e08SAugustin Cavalier hostap_vdetach(struct ieee80211vap *vap)
93753c7e08SAugustin Cavalier {
94753c7e08SAugustin Cavalier }
95753c7e08SAugustin Cavalier
96753c7e08SAugustin Cavalier static void
hostap_vattach(struct ieee80211vap * vap)97753c7e08SAugustin Cavalier hostap_vattach(struct ieee80211vap *vap)
98753c7e08SAugustin Cavalier {
99753c7e08SAugustin Cavalier vap->iv_newstate = hostap_newstate;
100753c7e08SAugustin Cavalier vap->iv_input = hostap_input;
101753c7e08SAugustin Cavalier vap->iv_recv_mgmt = hostap_recv_mgmt;
102753c7e08SAugustin Cavalier vap->iv_recv_ctl = hostap_recv_ctl;
103753c7e08SAugustin Cavalier vap->iv_opdetach = hostap_vdetach;
104753c7e08SAugustin Cavalier vap->iv_deliver_data = hostap_deliver_data;
105753c7e08SAugustin Cavalier vap->iv_recv_pspoll = ieee80211_recv_pspoll;
106753c7e08SAugustin Cavalier }
107753c7e08SAugustin Cavalier
108753c7e08SAugustin Cavalier static void
sta_disassoc(void * arg,struct ieee80211_node * ni)109753c7e08SAugustin Cavalier sta_disassoc(void *arg, struct ieee80211_node *ni)
110753c7e08SAugustin Cavalier {
111753c7e08SAugustin Cavalier
1128244a9baSAugustin Cavalier if (ni->ni_associd != 0) {
113753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DISASSOC,
114753c7e08SAugustin Cavalier IEEE80211_REASON_ASSOC_LEAVE);
115753c7e08SAugustin Cavalier ieee80211_node_leave(ni);
116753c7e08SAugustin Cavalier }
117753c7e08SAugustin Cavalier }
118753c7e08SAugustin Cavalier
119753c7e08SAugustin Cavalier static void
sta_csa(void * arg,struct ieee80211_node * ni)120753c7e08SAugustin Cavalier sta_csa(void *arg, struct ieee80211_node *ni)
121753c7e08SAugustin Cavalier {
1228244a9baSAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
123753c7e08SAugustin Cavalier
1248244a9baSAugustin Cavalier if (ni->ni_associd != 0)
125753c7e08SAugustin Cavalier if (ni->ni_inact > vap->iv_inact_init) {
126753c7e08SAugustin Cavalier ni->ni_inact = vap->iv_inact_init;
127753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_INACT, ni,
128753c7e08SAugustin Cavalier "%s: inact %u", __func__, ni->ni_inact);
129753c7e08SAugustin Cavalier }
130753c7e08SAugustin Cavalier }
131753c7e08SAugustin Cavalier
132753c7e08SAugustin Cavalier static void
sta_drop(void * arg,struct ieee80211_node * ni)133753c7e08SAugustin Cavalier sta_drop(void *arg, struct ieee80211_node *ni)
134753c7e08SAugustin Cavalier {
135753c7e08SAugustin Cavalier
1368244a9baSAugustin Cavalier if (ni->ni_associd != 0)
137753c7e08SAugustin Cavalier ieee80211_node_leave(ni);
138753c7e08SAugustin Cavalier }
139753c7e08SAugustin Cavalier
140753c7e08SAugustin Cavalier /*
141753c7e08SAugustin Cavalier * Does a channel change require associated stations to re-associate
142753c7e08SAugustin Cavalier * so protocol state is correct. This is used when doing CSA across
143753c7e08SAugustin Cavalier * bands or similar (e.g. HT -> legacy).
144753c7e08SAugustin Cavalier */
145753c7e08SAugustin Cavalier static int
isbandchange(struct ieee80211com * ic)146753c7e08SAugustin Cavalier isbandchange(struct ieee80211com *ic)
147753c7e08SAugustin Cavalier {
148753c7e08SAugustin Cavalier return ((ic->ic_bsschan->ic_flags ^ ic->ic_csa_newchan->ic_flags) &
149753c7e08SAugustin Cavalier (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_HALF |
150753c7e08SAugustin Cavalier IEEE80211_CHAN_QUARTER | IEEE80211_CHAN_HT)) != 0;
151753c7e08SAugustin Cavalier }
152753c7e08SAugustin Cavalier
153753c7e08SAugustin Cavalier /*
154753c7e08SAugustin Cavalier * IEEE80211_M_HOSTAP vap state machine handler.
155753c7e08SAugustin Cavalier */
156753c7e08SAugustin Cavalier static int
hostap_newstate(struct ieee80211vap * vap,enum ieee80211_state nstate,int arg)157753c7e08SAugustin Cavalier hostap_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
158753c7e08SAugustin Cavalier {
159753c7e08SAugustin Cavalier struct ieee80211com *ic = vap->iv_ic;
160753c7e08SAugustin Cavalier enum ieee80211_state ostate;
161753c7e08SAugustin Cavalier
162753c7e08SAugustin Cavalier IEEE80211_LOCK_ASSERT(ic);
163753c7e08SAugustin Cavalier
164753c7e08SAugustin Cavalier ostate = vap->iv_state;
165753c7e08SAugustin Cavalier IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",
166753c7e08SAugustin Cavalier __func__, ieee80211_state_name[ostate],
167753c7e08SAugustin Cavalier ieee80211_state_name[nstate], arg);
168753c7e08SAugustin Cavalier vap->iv_state = nstate; /* state transition */
169753c7e08SAugustin Cavalier if (ostate != IEEE80211_S_SCAN)
170753c7e08SAugustin Cavalier ieee80211_cancel_scan(vap); /* background scan */
171753c7e08SAugustin Cavalier switch (nstate) {
172753c7e08SAugustin Cavalier case IEEE80211_S_INIT:
173753c7e08SAugustin Cavalier switch (ostate) {
174753c7e08SAugustin Cavalier case IEEE80211_S_SCAN:
175753c7e08SAugustin Cavalier ieee80211_cancel_scan(vap);
176753c7e08SAugustin Cavalier break;
177753c7e08SAugustin Cavalier case IEEE80211_S_CAC:
178753c7e08SAugustin Cavalier ieee80211_dfs_cac_stop(vap);
179753c7e08SAugustin Cavalier break;
180753c7e08SAugustin Cavalier case IEEE80211_S_RUN:
1818244a9baSAugustin Cavalier ieee80211_iterate_nodes_vap(&ic->ic_sta, vap,
1828244a9baSAugustin Cavalier sta_disassoc, NULL);
183753c7e08SAugustin Cavalier break;
184753c7e08SAugustin Cavalier default:
185753c7e08SAugustin Cavalier break;
186753c7e08SAugustin Cavalier }
187753c7e08SAugustin Cavalier if (ostate != IEEE80211_S_INIT) {
188753c7e08SAugustin Cavalier /* NB: optimize INIT -> INIT case */
189753c7e08SAugustin Cavalier ieee80211_reset_bss(vap);
190753c7e08SAugustin Cavalier }
191753c7e08SAugustin Cavalier if (vap->iv_auth->ia_detach != NULL)
192753c7e08SAugustin Cavalier vap->iv_auth->ia_detach(vap);
193753c7e08SAugustin Cavalier break;
194753c7e08SAugustin Cavalier case IEEE80211_S_SCAN:
195753c7e08SAugustin Cavalier switch (ostate) {
196753c7e08SAugustin Cavalier case IEEE80211_S_CSA:
197753c7e08SAugustin Cavalier case IEEE80211_S_RUN:
1988244a9baSAugustin Cavalier ieee80211_iterate_nodes_vap(&ic->ic_sta, vap,
1998244a9baSAugustin Cavalier sta_disassoc, NULL);
200753c7e08SAugustin Cavalier /*
201753c7e08SAugustin Cavalier * Clear overlapping BSS state; the beacon frame
202753c7e08SAugustin Cavalier * will be reconstructed on transition to the RUN
203753c7e08SAugustin Cavalier * state and the timeout routines check if the flag
204753c7e08SAugustin Cavalier * is set before doing anything so this is sufficient.
205753c7e08SAugustin Cavalier */
2065cad57c4SJérôme Duval vap->iv_flags_ext &= ~IEEE80211_FEXT_NONERP_PR;
2075cad57c4SJérôme Duval vap->iv_flags_ht &= ~IEEE80211_FHT_NONHT_PR;
2085cad57c4SJérôme Duval /* XXX TODO: schedule deferred update? */
209753c7e08SAugustin Cavalier /* fall thru... */
210753c7e08SAugustin Cavalier case IEEE80211_S_CAC:
211753c7e08SAugustin Cavalier /*
212753c7e08SAugustin Cavalier * NB: We may get here because of a manual channel
213753c7e08SAugustin Cavalier * change in which case we need to stop CAC
214753c7e08SAugustin Cavalier * XXX no need to stop if ostate RUN but it's ok
215753c7e08SAugustin Cavalier */
216753c7e08SAugustin Cavalier ieee80211_dfs_cac_stop(vap);
217753c7e08SAugustin Cavalier /* fall thru... */
218753c7e08SAugustin Cavalier case IEEE80211_S_INIT:
219753c7e08SAugustin Cavalier if (vap->iv_des_chan != IEEE80211_CHAN_ANYC &&
220753c7e08SAugustin Cavalier !IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan)) {
221753c7e08SAugustin Cavalier /*
222753c7e08SAugustin Cavalier * Already have a channel; bypass the
223753c7e08SAugustin Cavalier * scan and startup immediately.
224753c7e08SAugustin Cavalier * ieee80211_create_ibss will call back to
225753c7e08SAugustin Cavalier * move us to RUN state.
226753c7e08SAugustin Cavalier */
227753c7e08SAugustin Cavalier ieee80211_create_ibss(vap, vap->iv_des_chan);
228753c7e08SAugustin Cavalier break;
229753c7e08SAugustin Cavalier }
230753c7e08SAugustin Cavalier /*
231753c7e08SAugustin Cavalier * Initiate a scan. We can come here as a result
232753c7e08SAugustin Cavalier * of an IEEE80211_IOC_SCAN_REQ too in which case
233753c7e08SAugustin Cavalier * the vap will be marked with IEEE80211_FEXT_SCANREQ
234753c7e08SAugustin Cavalier * and the scan request parameters will be present
235753c7e08SAugustin Cavalier * in iv_scanreq. Otherwise we do the default.
236753c7e08SAugustin Cavalier */
237753c7e08SAugustin Cavalier if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
238753c7e08SAugustin Cavalier ieee80211_check_scan(vap,
239753c7e08SAugustin Cavalier vap->iv_scanreq_flags,
240753c7e08SAugustin Cavalier vap->iv_scanreq_duration,
241753c7e08SAugustin Cavalier vap->iv_scanreq_mindwell,
242753c7e08SAugustin Cavalier vap->iv_scanreq_maxdwell,
243753c7e08SAugustin Cavalier vap->iv_scanreq_nssid, vap->iv_scanreq_ssid);
244753c7e08SAugustin Cavalier vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
245753c7e08SAugustin Cavalier } else
246753c7e08SAugustin Cavalier ieee80211_check_scan_current(vap);
247753c7e08SAugustin Cavalier break;
248753c7e08SAugustin Cavalier case IEEE80211_S_SCAN:
249753c7e08SAugustin Cavalier /*
250753c7e08SAugustin Cavalier * A state change requires a reset; scan.
251753c7e08SAugustin Cavalier */
252753c7e08SAugustin Cavalier ieee80211_check_scan_current(vap);
253753c7e08SAugustin Cavalier break;
254753c7e08SAugustin Cavalier default:
255753c7e08SAugustin Cavalier break;
256753c7e08SAugustin Cavalier }
257753c7e08SAugustin Cavalier break;
258753c7e08SAugustin Cavalier case IEEE80211_S_CAC:
259753c7e08SAugustin Cavalier /*
260753c7e08SAugustin Cavalier * Start CAC on a DFS channel. We come here when starting
261753c7e08SAugustin Cavalier * a bss on a DFS channel (see ieee80211_create_ibss).
262753c7e08SAugustin Cavalier */
263753c7e08SAugustin Cavalier ieee80211_dfs_cac_start(vap);
264753c7e08SAugustin Cavalier break;
265753c7e08SAugustin Cavalier case IEEE80211_S_RUN:
266753c7e08SAugustin Cavalier if (vap->iv_flags & IEEE80211_F_WPA) {
267753c7e08SAugustin Cavalier /* XXX validate prerequisites */
268753c7e08SAugustin Cavalier }
269753c7e08SAugustin Cavalier switch (ostate) {
270753c7e08SAugustin Cavalier case IEEE80211_S_INIT:
271753c7e08SAugustin Cavalier /*
272753c7e08SAugustin Cavalier * Already have a channel; bypass the
273753c7e08SAugustin Cavalier * scan and startup immediately.
274753c7e08SAugustin Cavalier * Note that ieee80211_create_ibss will call
275753c7e08SAugustin Cavalier * back to do a RUN->RUN state change.
276753c7e08SAugustin Cavalier */
277753c7e08SAugustin Cavalier ieee80211_create_ibss(vap,
278753c7e08SAugustin Cavalier ieee80211_ht_adjust_channel(ic,
279753c7e08SAugustin Cavalier ic->ic_curchan, vap->iv_flags_ht));
280753c7e08SAugustin Cavalier /* NB: iv_bss is changed on return */
281753c7e08SAugustin Cavalier break;
282753c7e08SAugustin Cavalier case IEEE80211_S_CAC:
283753c7e08SAugustin Cavalier /*
284753c7e08SAugustin Cavalier * NB: This is the normal state change when CAC
285753c7e08SAugustin Cavalier * expires and no radar was detected; no need to
286753c7e08SAugustin Cavalier * clear the CAC timer as it's already expired.
287753c7e08SAugustin Cavalier */
288753c7e08SAugustin Cavalier /* fall thru... */
289753c7e08SAugustin Cavalier case IEEE80211_S_CSA:
290753c7e08SAugustin Cavalier /*
291753c7e08SAugustin Cavalier * Shorten inactivity timer of associated stations
292753c7e08SAugustin Cavalier * to weed out sta's that don't follow a CSA.
293753c7e08SAugustin Cavalier */
2948244a9baSAugustin Cavalier ieee80211_iterate_nodes_vap(&ic->ic_sta, vap,
2958244a9baSAugustin Cavalier sta_csa, NULL);
296753c7e08SAugustin Cavalier /*
297753c7e08SAugustin Cavalier * Update bss node channel to reflect where
298753c7e08SAugustin Cavalier * we landed after CSA.
299753c7e08SAugustin Cavalier */
300753c7e08SAugustin Cavalier ieee80211_node_set_chan(vap->iv_bss,
301753c7e08SAugustin Cavalier ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
302753c7e08SAugustin Cavalier ieee80211_htchanflags(vap->iv_bss->ni_chan)));
303753c7e08SAugustin Cavalier /* XXX bypass debug msgs */
304753c7e08SAugustin Cavalier break;
305753c7e08SAugustin Cavalier case IEEE80211_S_SCAN:
306753c7e08SAugustin Cavalier case IEEE80211_S_RUN:
307753c7e08SAugustin Cavalier #ifdef IEEE80211_DEBUG
308753c7e08SAugustin Cavalier if (ieee80211_msg_debug(vap)) {
309753c7e08SAugustin Cavalier struct ieee80211_node *ni = vap->iv_bss;
310753c7e08SAugustin Cavalier ieee80211_note(vap,
311753c7e08SAugustin Cavalier "synchronized with %s ssid ",
312753c7e08SAugustin Cavalier ether_sprintf(ni->ni_bssid));
313753c7e08SAugustin Cavalier ieee80211_print_essid(ni->ni_essid,
314753c7e08SAugustin Cavalier ni->ni_esslen);
315753c7e08SAugustin Cavalier /* XXX MCS/HT */
316753c7e08SAugustin Cavalier printf(" channel %d start %uMb\n",
317753c7e08SAugustin Cavalier ieee80211_chan2ieee(ic, ic->ic_curchan),
318753c7e08SAugustin Cavalier IEEE80211_RATE2MBS(ni->ni_txrate));
319753c7e08SAugustin Cavalier }
320753c7e08SAugustin Cavalier #endif
321753c7e08SAugustin Cavalier break;
322753c7e08SAugustin Cavalier default:
323753c7e08SAugustin Cavalier break;
324753c7e08SAugustin Cavalier }
325753c7e08SAugustin Cavalier /*
326753c7e08SAugustin Cavalier * Start/stop the authenticator. We delay until here
327753c7e08SAugustin Cavalier * to allow configuration to happen out of order.
328753c7e08SAugustin Cavalier */
329753c7e08SAugustin Cavalier if (vap->iv_auth->ia_attach != NULL) {
330753c7e08SAugustin Cavalier /* XXX check failure */
331753c7e08SAugustin Cavalier vap->iv_auth->ia_attach(vap);
332753c7e08SAugustin Cavalier } else if (vap->iv_auth->ia_detach != NULL) {
333753c7e08SAugustin Cavalier vap->iv_auth->ia_detach(vap);
334753c7e08SAugustin Cavalier }
335753c7e08SAugustin Cavalier ieee80211_node_authorize(vap->iv_bss);
336753c7e08SAugustin Cavalier break;
337753c7e08SAugustin Cavalier case IEEE80211_S_CSA:
338753c7e08SAugustin Cavalier if (ostate == IEEE80211_S_RUN && isbandchange(ic)) {
339753c7e08SAugustin Cavalier /*
340753c7e08SAugustin Cavalier * On a ``band change'' silently drop associated
341753c7e08SAugustin Cavalier * stations as they must re-associate before they
342753c7e08SAugustin Cavalier * can pass traffic (as otherwise protocol state
343753c7e08SAugustin Cavalier * such as capabilities and the negotiated rate
344753c7e08SAugustin Cavalier * set may/will be wrong).
345753c7e08SAugustin Cavalier */
3468244a9baSAugustin Cavalier ieee80211_iterate_nodes_vap(&ic->ic_sta, vap,
3478244a9baSAugustin Cavalier sta_drop, NULL);
348753c7e08SAugustin Cavalier }
349753c7e08SAugustin Cavalier break;
350753c7e08SAugustin Cavalier default:
351753c7e08SAugustin Cavalier break;
352753c7e08SAugustin Cavalier }
353753c7e08SAugustin Cavalier return 0;
354753c7e08SAugustin Cavalier }
355753c7e08SAugustin Cavalier
356753c7e08SAugustin Cavalier static void
hostap_deliver_data(struct ieee80211vap * vap,struct ieee80211_node * ni,struct mbuf * m)357753c7e08SAugustin Cavalier hostap_deliver_data(struct ieee80211vap *vap,
358753c7e08SAugustin Cavalier struct ieee80211_node *ni, struct mbuf *m)
359753c7e08SAugustin Cavalier {
360753c7e08SAugustin Cavalier struct ether_header *eh = mtod(m, struct ether_header *);
361753c7e08SAugustin Cavalier struct ifnet *ifp = vap->iv_ifp;
362753c7e08SAugustin Cavalier
363753c7e08SAugustin Cavalier /* clear driver/net80211 flags before passing up */
364753c7e08SAugustin Cavalier m->m_flags &= ~(M_MCAST | M_BCAST);
365753c7e08SAugustin Cavalier m_clrprotoflags(m);
366753c7e08SAugustin Cavalier
367753c7e08SAugustin Cavalier KASSERT(vap->iv_opmode == IEEE80211_M_HOSTAP,
368753c7e08SAugustin Cavalier ("gack, opmode %d", vap->iv_opmode));
369753c7e08SAugustin Cavalier /*
370753c7e08SAugustin Cavalier * Do accounting.
371753c7e08SAugustin Cavalier */
372753c7e08SAugustin Cavalier if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
373753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_data);
374753c7e08SAugustin Cavalier IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
375753c7e08SAugustin Cavalier if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
376753c7e08SAugustin Cavalier m->m_flags |= M_MCAST; /* XXX M_BCAST? */
377753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_mcast);
378753c7e08SAugustin Cavalier } else
379753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_ucast);
380753c7e08SAugustin Cavalier
381753c7e08SAugustin Cavalier /* perform as a bridge within the AP */
382753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_NOBRIDGE) == 0) {
383753c7e08SAugustin Cavalier struct mbuf *mcopy = NULL;
384753c7e08SAugustin Cavalier
385753c7e08SAugustin Cavalier if (m->m_flags & M_MCAST) {
38686021fd4SAugustin Cavalier mcopy = m_dup(m, IEEE80211_M_NOWAIT);
387753c7e08SAugustin Cavalier if (mcopy == NULL)
388753c7e08SAugustin Cavalier if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
389753c7e08SAugustin Cavalier else
390753c7e08SAugustin Cavalier mcopy->m_flags |= M_MCAST;
391753c7e08SAugustin Cavalier } else {
392753c7e08SAugustin Cavalier /*
393753c7e08SAugustin Cavalier * Check if the destination is associated with the
394753c7e08SAugustin Cavalier * same vap and authorized to receive traffic.
395753c7e08SAugustin Cavalier * Beware of traffic destined for the vap itself;
396753c7e08SAugustin Cavalier * sending it will not work; just let it be delivered
397753c7e08SAugustin Cavalier * normally.
398753c7e08SAugustin Cavalier */
399753c7e08SAugustin Cavalier struct ieee80211_node *sta = ieee80211_find_vap_node(
400753c7e08SAugustin Cavalier &vap->iv_ic->ic_sta, vap, eh->ether_dhost);
401753c7e08SAugustin Cavalier if (sta != NULL) {
402753c7e08SAugustin Cavalier if (ieee80211_node_is_authorized(sta)) {
403753c7e08SAugustin Cavalier /*
404753c7e08SAugustin Cavalier * Beware of sending to ourself; this
405753c7e08SAugustin Cavalier * needs to happen via the normal
406753c7e08SAugustin Cavalier * input path.
407753c7e08SAugustin Cavalier */
408753c7e08SAugustin Cavalier if (sta != vap->iv_bss) {
409753c7e08SAugustin Cavalier mcopy = m;
410753c7e08SAugustin Cavalier m = NULL;
411753c7e08SAugustin Cavalier }
412753c7e08SAugustin Cavalier } else {
413753c7e08SAugustin Cavalier vap->iv_stats.is_rx_unauth++;
414753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(sta, rx_unauth);
415753c7e08SAugustin Cavalier }
416753c7e08SAugustin Cavalier ieee80211_free_node(sta);
417753c7e08SAugustin Cavalier }
418753c7e08SAugustin Cavalier }
419753c7e08SAugustin Cavalier if (mcopy != NULL)
420753c7e08SAugustin Cavalier (void) ieee80211_vap_xmitpkt(vap, mcopy);
421753c7e08SAugustin Cavalier }
422753c7e08SAugustin Cavalier if (m != NULL) {
42386021fd4SAugustin Cavalier struct epoch_tracker et;
42486021fd4SAugustin Cavalier
425753c7e08SAugustin Cavalier /*
426753c7e08SAugustin Cavalier * Mark frame as coming from vap's interface.
427753c7e08SAugustin Cavalier */
428753c7e08SAugustin Cavalier m->m_pkthdr.rcvif = ifp;
429753c7e08SAugustin Cavalier if (m->m_flags & M_MCAST) {
430753c7e08SAugustin Cavalier /*
431753c7e08SAugustin Cavalier * Spam DWDS vap's w/ multicast traffic.
432753c7e08SAugustin Cavalier */
433753c7e08SAugustin Cavalier /* XXX only if dwds in use? */
434753c7e08SAugustin Cavalier ieee80211_dwds_mcast(vap, m);
435753c7e08SAugustin Cavalier }
436753c7e08SAugustin Cavalier if (ni->ni_vlan != 0) {
437753c7e08SAugustin Cavalier /* attach vlan tag */
438753c7e08SAugustin Cavalier m->m_pkthdr.ether_vtag = ni->ni_vlan;
439753c7e08SAugustin Cavalier m->m_flags |= M_VLANTAG;
440753c7e08SAugustin Cavalier }
44186021fd4SAugustin Cavalier NET_EPOCH_ENTER(et);
442753c7e08SAugustin Cavalier ifp->if_input(ifp, m);
44386021fd4SAugustin Cavalier NET_EPOCH_EXIT(et);
444753c7e08SAugustin Cavalier }
445753c7e08SAugustin Cavalier }
446753c7e08SAugustin Cavalier
447753c7e08SAugustin Cavalier /*
448753c7e08SAugustin Cavalier * Decide if a received management frame should be
449753c7e08SAugustin Cavalier * printed when debugging is enabled. This filters some
450753c7e08SAugustin Cavalier * of the less interesting frames that come frequently
451753c7e08SAugustin Cavalier * (e.g. beacons).
452753c7e08SAugustin Cavalier */
453753c7e08SAugustin Cavalier static __inline int
doprint(struct ieee80211vap * vap,int subtype)454753c7e08SAugustin Cavalier doprint(struct ieee80211vap *vap, int subtype)
455753c7e08SAugustin Cavalier {
456753c7e08SAugustin Cavalier switch (subtype) {
457753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_BEACON:
458753c7e08SAugustin Cavalier return (vap->iv_ic->ic_flags & IEEE80211_F_SCAN);
459753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
460753c7e08SAugustin Cavalier return 0;
461753c7e08SAugustin Cavalier }
462753c7e08SAugustin Cavalier return 1;
463753c7e08SAugustin Cavalier }
464753c7e08SAugustin Cavalier
465753c7e08SAugustin Cavalier /*
466753c7e08SAugustin Cavalier * Process a received frame. The node associated with the sender
467753c7e08SAugustin Cavalier * should be supplied. If nothing was found in the node table then
468753c7e08SAugustin Cavalier * the caller is assumed to supply a reference to iv_bss instead.
469753c7e08SAugustin Cavalier * The RSSI and a timestamp are also supplied. The RSSI data is used
470753c7e08SAugustin Cavalier * during AP scanning to select a AP to associate with; it can have
471753c7e08SAugustin Cavalier * any units so long as values have consistent units and higher values
472753c7e08SAugustin Cavalier * mean ``better signal''. The receive timestamp is currently not used
473753c7e08SAugustin Cavalier * by the 802.11 layer.
474753c7e08SAugustin Cavalier */
475753c7e08SAugustin Cavalier static int
hostap_input(struct ieee80211_node * ni,struct mbuf * m,const struct ieee80211_rx_stats * rxs,int rssi,int nf)476753c7e08SAugustin Cavalier hostap_input(struct ieee80211_node *ni, struct mbuf *m,
477753c7e08SAugustin Cavalier const struct ieee80211_rx_stats *rxs, int rssi, int nf)
478753c7e08SAugustin Cavalier {
479753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
480753c7e08SAugustin Cavalier struct ieee80211com *ic = ni->ni_ic;
481753c7e08SAugustin Cavalier struct ifnet *ifp = vap->iv_ifp;
482753c7e08SAugustin Cavalier struct ieee80211_frame *wh;
483753c7e08SAugustin Cavalier struct ieee80211_key *key;
484753c7e08SAugustin Cavalier struct ether_header *eh;
485753c7e08SAugustin Cavalier int hdrspace, need_tap = 1; /* mbuf need to be tapped. */
486753c7e08SAugustin Cavalier uint8_t dir, type, subtype, qos;
487753c7e08SAugustin Cavalier uint8_t *bssid;
4888244a9baSAugustin Cavalier int is_hw_decrypted = 0;
4898244a9baSAugustin Cavalier int has_decrypted = 0;
4908244a9baSAugustin Cavalier
4918244a9baSAugustin Cavalier /*
4928244a9baSAugustin Cavalier * Some devices do hardware decryption all the way through
4938244a9baSAugustin Cavalier * to pretending the frame wasn't encrypted in the first place.
4948244a9baSAugustin Cavalier * So, tag it appropriately so it isn't discarded inappropriately.
4958244a9baSAugustin Cavalier */
4968244a9baSAugustin Cavalier if ((rxs != NULL) && (rxs->c_pktflags & IEEE80211_RX_F_DECRYPTED))
4978244a9baSAugustin Cavalier is_hw_decrypted = 1;
498753c7e08SAugustin Cavalier
499753c7e08SAugustin Cavalier if (m->m_flags & M_AMPDU_MPDU) {
500753c7e08SAugustin Cavalier /*
501753c7e08SAugustin Cavalier * Fastpath for A-MPDU reorder q resubmission. Frames
502753c7e08SAugustin Cavalier * w/ M_AMPDU_MPDU marked have already passed through
503753c7e08SAugustin Cavalier * here but were received out of order and been held on
504753c7e08SAugustin Cavalier * the reorder queue. When resubmitted they are marked
505753c7e08SAugustin Cavalier * with the M_AMPDU_MPDU flag and we can bypass most of
506753c7e08SAugustin Cavalier * the normal processing.
507753c7e08SAugustin Cavalier */
508753c7e08SAugustin Cavalier wh = mtod(m, struct ieee80211_frame *);
509753c7e08SAugustin Cavalier type = IEEE80211_FC0_TYPE_DATA;
510753c7e08SAugustin Cavalier dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
51186021fd4SAugustin Cavalier subtype = IEEE80211_FC0_SUBTYPE_QOS_DATA;
512753c7e08SAugustin Cavalier hdrspace = ieee80211_hdrspace(ic, wh); /* XXX optimize? */
513753c7e08SAugustin Cavalier goto resubmit_ampdu;
514753c7e08SAugustin Cavalier }
515753c7e08SAugustin Cavalier
516753c7e08SAugustin Cavalier KASSERT(ni != NULL, ("null node"));
517753c7e08SAugustin Cavalier ni->ni_inact = ni->ni_inact_reload;
518753c7e08SAugustin Cavalier
519753c7e08SAugustin Cavalier type = -1; /* undefined */
520753c7e08SAugustin Cavalier
521753c7e08SAugustin Cavalier if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_min)) {
522753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
523753c7e08SAugustin Cavalier ni->ni_macaddr, NULL,
524753c7e08SAugustin Cavalier "too short (1): len %u", m->m_pkthdr.len);
525753c7e08SAugustin Cavalier vap->iv_stats.is_rx_tooshort++;
526753c7e08SAugustin Cavalier goto out;
527753c7e08SAugustin Cavalier }
528753c7e08SAugustin Cavalier /*
529753c7e08SAugustin Cavalier * Bit of a cheat here, we use a pointer for a 3-address
530753c7e08SAugustin Cavalier * frame format but don't reference fields past outside
531753c7e08SAugustin Cavalier * ieee80211_frame_min w/o first validating the data is
532753c7e08SAugustin Cavalier * present.
533753c7e08SAugustin Cavalier */
534753c7e08SAugustin Cavalier wh = mtod(m, struct ieee80211_frame *);
535753c7e08SAugustin Cavalier
536*da3ca318SAugustin Cavalier if (!IEEE80211_IS_FC0_CHECK_VER(wh, IEEE80211_FC0_VERSION_0)) {
537753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
538753c7e08SAugustin Cavalier ni->ni_macaddr, NULL, "wrong version, fc %02x:%02x",
539753c7e08SAugustin Cavalier wh->i_fc[0], wh->i_fc[1]);
540753c7e08SAugustin Cavalier vap->iv_stats.is_rx_badversion++;
541753c7e08SAugustin Cavalier goto err;
542753c7e08SAugustin Cavalier }
543753c7e08SAugustin Cavalier
544753c7e08SAugustin Cavalier dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
545753c7e08SAugustin Cavalier type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
546753c7e08SAugustin Cavalier subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
547753c7e08SAugustin Cavalier if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
548753c7e08SAugustin Cavalier if (dir != IEEE80211_FC1_DIR_NODS)
549753c7e08SAugustin Cavalier bssid = wh->i_addr1;
550753c7e08SAugustin Cavalier else if (type == IEEE80211_FC0_TYPE_CTL)
551753c7e08SAugustin Cavalier bssid = wh->i_addr1;
552753c7e08SAugustin Cavalier else {
553753c7e08SAugustin Cavalier if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
554753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap,
555753c7e08SAugustin Cavalier IEEE80211_MSG_ANY, ni->ni_macaddr,
556753c7e08SAugustin Cavalier NULL, "too short (2): len %u",
557753c7e08SAugustin Cavalier m->m_pkthdr.len);
558753c7e08SAugustin Cavalier vap->iv_stats.is_rx_tooshort++;
559753c7e08SAugustin Cavalier goto out;
560753c7e08SAugustin Cavalier }
561753c7e08SAugustin Cavalier bssid = wh->i_addr3;
562753c7e08SAugustin Cavalier }
563753c7e08SAugustin Cavalier /*
564753c7e08SAugustin Cavalier * Validate the bssid.
565753c7e08SAugustin Cavalier */
566753c7e08SAugustin Cavalier if (!(type == IEEE80211_FC0_TYPE_MGT &&
567753c7e08SAugustin Cavalier subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
568753c7e08SAugustin Cavalier !IEEE80211_ADDR_EQ(bssid, vap->iv_bss->ni_bssid) &&
569753c7e08SAugustin Cavalier !IEEE80211_ADDR_EQ(bssid, ifp->if_broadcastaddr)) {
570753c7e08SAugustin Cavalier /* not interested in */
571753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
572753c7e08SAugustin Cavalier bssid, NULL, "%s", "not to bss");
573753c7e08SAugustin Cavalier vap->iv_stats.is_rx_wrongbss++;
574753c7e08SAugustin Cavalier goto out;
575753c7e08SAugustin Cavalier }
576753c7e08SAugustin Cavalier
577753c7e08SAugustin Cavalier IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
578753c7e08SAugustin Cavalier ni->ni_noise = nf;
579753c7e08SAugustin Cavalier if (IEEE80211_HAS_SEQ(type, subtype)) {
580753c7e08SAugustin Cavalier uint8_t tid = ieee80211_gettid(wh);
581753c7e08SAugustin Cavalier if (IEEE80211_QOS_HAS_SEQ(wh) &&
582753c7e08SAugustin Cavalier TID_TO_WME_AC(tid) >= WME_AC_VI)
583753c7e08SAugustin Cavalier ic->ic_wme.wme_hipri_traffic++;
5848244a9baSAugustin Cavalier if (! ieee80211_check_rxseq(ni, wh, bssid, rxs))
585753c7e08SAugustin Cavalier goto out;
586753c7e08SAugustin Cavalier }
587753c7e08SAugustin Cavalier }
588753c7e08SAugustin Cavalier
589753c7e08SAugustin Cavalier switch (type) {
590753c7e08SAugustin Cavalier case IEEE80211_FC0_TYPE_DATA:
591753c7e08SAugustin Cavalier hdrspace = ieee80211_hdrspace(ic, wh);
592753c7e08SAugustin Cavalier if (m->m_len < hdrspace &&
593753c7e08SAugustin Cavalier (m = m_pullup(m, hdrspace)) == NULL) {
594753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
595753c7e08SAugustin Cavalier ni->ni_macaddr, NULL,
596753c7e08SAugustin Cavalier "data too short: expecting %u", hdrspace);
597753c7e08SAugustin Cavalier vap->iv_stats.is_rx_tooshort++;
598753c7e08SAugustin Cavalier goto out; /* XXX */
599753c7e08SAugustin Cavalier }
600753c7e08SAugustin Cavalier if (!(dir == IEEE80211_FC1_DIR_TODS ||
601753c7e08SAugustin Cavalier (dir == IEEE80211_FC1_DIR_DSTODS &&
602753c7e08SAugustin Cavalier (vap->iv_flags & IEEE80211_F_DWDS)))) {
603753c7e08SAugustin Cavalier if (dir != IEEE80211_FC1_DIR_DSTODS) {
604753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap,
605753c7e08SAugustin Cavalier IEEE80211_MSG_INPUT, wh, "data",
606753c7e08SAugustin Cavalier "incorrect dir 0x%x", dir);
607753c7e08SAugustin Cavalier } else {
608753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap,
609753c7e08SAugustin Cavalier IEEE80211_MSG_INPUT |
610753c7e08SAugustin Cavalier IEEE80211_MSG_WDS, wh,
611753c7e08SAugustin Cavalier "4-address data",
612753c7e08SAugustin Cavalier "%s", "DWDS not enabled");
613753c7e08SAugustin Cavalier }
614753c7e08SAugustin Cavalier vap->iv_stats.is_rx_wrongdir++;
615753c7e08SAugustin Cavalier goto out;
616753c7e08SAugustin Cavalier }
617753c7e08SAugustin Cavalier /* check if source STA is associated */
618753c7e08SAugustin Cavalier if (ni == vap->iv_bss) {
619753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
620753c7e08SAugustin Cavalier wh, "data", "%s", "unknown src");
621753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2,
622753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_DEAUTH,
623753c7e08SAugustin Cavalier IEEE80211_REASON_NOT_AUTHED);
624753c7e08SAugustin Cavalier vap->iv_stats.is_rx_notassoc++;
625753c7e08SAugustin Cavalier goto err;
626753c7e08SAugustin Cavalier }
627753c7e08SAugustin Cavalier if (ni->ni_associd == 0) {
628753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
629753c7e08SAugustin Cavalier wh, "data", "%s", "unassoc src");
630753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni,
631753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_DISASSOC,
632753c7e08SAugustin Cavalier IEEE80211_REASON_NOT_ASSOCED);
633753c7e08SAugustin Cavalier vap->iv_stats.is_rx_notassoc++;
634753c7e08SAugustin Cavalier goto err;
635753c7e08SAugustin Cavalier }
636753c7e08SAugustin Cavalier
637753c7e08SAugustin Cavalier /*
638753c7e08SAugustin Cavalier * Check for power save state change.
639753c7e08SAugustin Cavalier * XXX out-of-order A-MPDU frames?
640753c7e08SAugustin Cavalier */
641753c7e08SAugustin Cavalier if (((wh->i_fc[1] & IEEE80211_FC1_PWR_MGT) ^
642753c7e08SAugustin Cavalier (ni->ni_flags & IEEE80211_NODE_PWR_MGT)))
643753c7e08SAugustin Cavalier vap->iv_node_ps(ni,
644753c7e08SAugustin Cavalier wh->i_fc[1] & IEEE80211_FC1_PWR_MGT);
645753c7e08SAugustin Cavalier /*
646753c7e08SAugustin Cavalier * For 4-address packets handle WDS discovery
647753c7e08SAugustin Cavalier * notifications. Once a WDS link is setup frames
648753c7e08SAugustin Cavalier * are just delivered to the WDS vap (see below).
649753c7e08SAugustin Cavalier */
650753c7e08SAugustin Cavalier if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap == NULL) {
651753c7e08SAugustin Cavalier if (!ieee80211_node_is_authorized(ni)) {
652753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap,
653753c7e08SAugustin Cavalier IEEE80211_MSG_INPUT |
654753c7e08SAugustin Cavalier IEEE80211_MSG_WDS, wh,
655753c7e08SAugustin Cavalier "4-address data",
656753c7e08SAugustin Cavalier "%s", "unauthorized port");
657753c7e08SAugustin Cavalier vap->iv_stats.is_rx_unauth++;
658753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_unauth);
659753c7e08SAugustin Cavalier goto err;
660753c7e08SAugustin Cavalier }
661753c7e08SAugustin Cavalier ieee80211_dwds_discover(ni, m);
662753c7e08SAugustin Cavalier return type;
663753c7e08SAugustin Cavalier }
664753c7e08SAugustin Cavalier
665753c7e08SAugustin Cavalier /*
666753c7e08SAugustin Cavalier * Handle A-MPDU re-ordering. If the frame is to be
667753c7e08SAugustin Cavalier * processed directly then ieee80211_ampdu_reorder
668753c7e08SAugustin Cavalier * will return 0; otherwise it has consumed the mbuf
669753c7e08SAugustin Cavalier * and we should do nothing more with it.
670753c7e08SAugustin Cavalier */
671753c7e08SAugustin Cavalier if ((m->m_flags & M_AMPDU) &&
6728244a9baSAugustin Cavalier ieee80211_ampdu_reorder(ni, m, rxs) != 0) {
673753c7e08SAugustin Cavalier m = NULL;
674753c7e08SAugustin Cavalier goto out;
675753c7e08SAugustin Cavalier }
676753c7e08SAugustin Cavalier resubmit_ampdu:
677753c7e08SAugustin Cavalier
678753c7e08SAugustin Cavalier /*
679753c7e08SAugustin Cavalier * Handle privacy requirements. Note that we
680753c7e08SAugustin Cavalier * must not be preempted from here until after
681753c7e08SAugustin Cavalier * we (potentially) call ieee80211_crypto_demic;
682753c7e08SAugustin Cavalier * otherwise we may violate assumptions in the
683753c7e08SAugustin Cavalier * crypto cipher modules used to do delayed update
684753c7e08SAugustin Cavalier * of replay sequence numbers.
685753c7e08SAugustin Cavalier */
68686021fd4SAugustin Cavalier if (is_hw_decrypted || IEEE80211_IS_PROTECTED(wh)) {
687753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
688753c7e08SAugustin Cavalier /*
689753c7e08SAugustin Cavalier * Discard encrypted frames when privacy is off.
690753c7e08SAugustin Cavalier */
691753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
692753c7e08SAugustin Cavalier wh, "WEP", "%s", "PRIVACY off");
693753c7e08SAugustin Cavalier vap->iv_stats.is_rx_noprivacy++;
694753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_noprivacy);
695753c7e08SAugustin Cavalier goto out;
696753c7e08SAugustin Cavalier }
6978244a9baSAugustin Cavalier if (ieee80211_crypto_decap(ni, m, hdrspace, &key) == 0) {
698753c7e08SAugustin Cavalier /* NB: stats+msgs handled in crypto_decap */
699753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_wepfail);
700753c7e08SAugustin Cavalier goto out;
701753c7e08SAugustin Cavalier }
702753c7e08SAugustin Cavalier wh = mtod(m, struct ieee80211_frame *);
703753c7e08SAugustin Cavalier wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED;
7048244a9baSAugustin Cavalier has_decrypted = 1;
705753c7e08SAugustin Cavalier } else {
706753c7e08SAugustin Cavalier /* XXX M_WEP and IEEE80211_F_PRIVACY */
707753c7e08SAugustin Cavalier key = NULL;
708753c7e08SAugustin Cavalier }
709753c7e08SAugustin Cavalier
710753c7e08SAugustin Cavalier /*
711753c7e08SAugustin Cavalier * Save QoS bits for use below--before we strip the header.
712753c7e08SAugustin Cavalier */
71386021fd4SAugustin Cavalier if (subtype == IEEE80211_FC0_SUBTYPE_QOS_DATA)
7145cad57c4SJérôme Duval qos = ieee80211_getqos(wh)[0];
7155cad57c4SJérôme Duval else
716753c7e08SAugustin Cavalier qos = 0;
717753c7e08SAugustin Cavalier
718753c7e08SAugustin Cavalier /*
719753c7e08SAugustin Cavalier * Next up, any fragmentation.
720753c7e08SAugustin Cavalier */
721753c7e08SAugustin Cavalier if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
72286021fd4SAugustin Cavalier m = ieee80211_defrag(ni, m, hdrspace, has_decrypted);
723753c7e08SAugustin Cavalier if (m == NULL) {
724753c7e08SAugustin Cavalier /* Fragment dropped or frame not complete yet */
725753c7e08SAugustin Cavalier goto out;
726753c7e08SAugustin Cavalier }
727753c7e08SAugustin Cavalier }
728753c7e08SAugustin Cavalier wh = NULL; /* no longer valid, catch any uses */
729753c7e08SAugustin Cavalier
730753c7e08SAugustin Cavalier /*
731753c7e08SAugustin Cavalier * Next strip any MSDU crypto bits.
732753c7e08SAugustin Cavalier */
733753c7e08SAugustin Cavalier if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) {
734753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
735753c7e08SAugustin Cavalier ni->ni_macaddr, "data", "%s", "demic error");
736753c7e08SAugustin Cavalier vap->iv_stats.is_rx_demicfail++;
737753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_demicfail);
738753c7e08SAugustin Cavalier goto out;
739753c7e08SAugustin Cavalier }
740753c7e08SAugustin Cavalier /* copy to listener after decrypt */
741753c7e08SAugustin Cavalier if (ieee80211_radiotap_active_vap(vap))
742753c7e08SAugustin Cavalier ieee80211_radiotap_rx(vap, m);
743753c7e08SAugustin Cavalier need_tap = 0;
744753c7e08SAugustin Cavalier /*
745753c7e08SAugustin Cavalier * Finally, strip the 802.11 header.
746753c7e08SAugustin Cavalier */
74786021fd4SAugustin Cavalier m = ieee80211_decap(vap, m, hdrspace, qos);
748753c7e08SAugustin Cavalier if (m == NULL) {
749753c7e08SAugustin Cavalier /* XXX mask bit to check for both */
750753c7e08SAugustin Cavalier /* don't count Null data frames as errors */
751753c7e08SAugustin Cavalier if (subtype == IEEE80211_FC0_SUBTYPE_NODATA ||
752753c7e08SAugustin Cavalier subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL)
753753c7e08SAugustin Cavalier goto out;
754753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
755753c7e08SAugustin Cavalier ni->ni_macaddr, "data", "%s", "decap error");
756753c7e08SAugustin Cavalier vap->iv_stats.is_rx_decap++;
757753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_decap);
758753c7e08SAugustin Cavalier goto err;
759753c7e08SAugustin Cavalier }
76086021fd4SAugustin Cavalier if (!(qos & IEEE80211_QOS_AMSDU))
761753c7e08SAugustin Cavalier eh = mtod(m, struct ether_header *);
76286021fd4SAugustin Cavalier else
76386021fd4SAugustin Cavalier eh = NULL;
764753c7e08SAugustin Cavalier if (!ieee80211_node_is_authorized(ni)) {
765753c7e08SAugustin Cavalier /*
766753c7e08SAugustin Cavalier * Deny any non-PAE frames received prior to
767753c7e08SAugustin Cavalier * authorization. For open/shared-key
768753c7e08SAugustin Cavalier * authentication the port is mark authorized
769753c7e08SAugustin Cavalier * after authentication completes. For 802.1x
770753c7e08SAugustin Cavalier * the port is not marked authorized by the
771753c7e08SAugustin Cavalier * authenticator until the handshake has completed.
772753c7e08SAugustin Cavalier */
77386021fd4SAugustin Cavalier if (eh == NULL ||
77486021fd4SAugustin Cavalier eh->ether_type != htons(ETHERTYPE_PAE)) {
775753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
77686021fd4SAugustin Cavalier ni->ni_macaddr, "data", "unauthorized or "
77786021fd4SAugustin Cavalier "unknown port: ether type 0x%x len %u",
77886021fd4SAugustin Cavalier eh == NULL ? -1 : eh->ether_type,
77986021fd4SAugustin Cavalier m->m_pkthdr.len);
780753c7e08SAugustin Cavalier vap->iv_stats.is_rx_unauth++;
781753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_unauth);
782753c7e08SAugustin Cavalier goto err;
783753c7e08SAugustin Cavalier }
784753c7e08SAugustin Cavalier } else {
785753c7e08SAugustin Cavalier /*
786753c7e08SAugustin Cavalier * When denying unencrypted frames, discard
787753c7e08SAugustin Cavalier * any non-PAE frames received without encryption.
788753c7e08SAugustin Cavalier */
789753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_DROPUNENC) &&
7908244a9baSAugustin Cavalier ((has_decrypted == 0) && (m->m_flags & M_WEP) == 0) &&
7918244a9baSAugustin Cavalier (is_hw_decrypted == 0) &&
79286021fd4SAugustin Cavalier (eh == NULL ||
79386021fd4SAugustin Cavalier eh->ether_type != htons(ETHERTYPE_PAE))) {
794753c7e08SAugustin Cavalier /*
795753c7e08SAugustin Cavalier * Drop unencrypted frames.
796753c7e08SAugustin Cavalier */
797753c7e08SAugustin Cavalier vap->iv_stats.is_rx_unencrypted++;
798753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_unencrypted);
799753c7e08SAugustin Cavalier goto out;
800753c7e08SAugustin Cavalier }
801753c7e08SAugustin Cavalier }
802753c7e08SAugustin Cavalier /* XXX require HT? */
803753c7e08SAugustin Cavalier if (qos & IEEE80211_QOS_AMSDU) {
804753c7e08SAugustin Cavalier m = ieee80211_decap_amsdu(ni, m);
805753c7e08SAugustin Cavalier if (m == NULL)
806753c7e08SAugustin Cavalier return IEEE80211_FC0_TYPE_DATA;
807753c7e08SAugustin Cavalier } else {
808753c7e08SAugustin Cavalier #ifdef IEEE80211_SUPPORT_SUPERG
809753c7e08SAugustin Cavalier m = ieee80211_decap_fastframe(vap, ni, m);
810753c7e08SAugustin Cavalier if (m == NULL)
811753c7e08SAugustin Cavalier return IEEE80211_FC0_TYPE_DATA;
812753c7e08SAugustin Cavalier #endif
813753c7e08SAugustin Cavalier }
814753c7e08SAugustin Cavalier if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap != NULL)
815753c7e08SAugustin Cavalier ieee80211_deliver_data(ni->ni_wdsvap, ni, m);
816753c7e08SAugustin Cavalier else
817753c7e08SAugustin Cavalier hostap_deliver_data(vap, ni, m);
818753c7e08SAugustin Cavalier return IEEE80211_FC0_TYPE_DATA;
819753c7e08SAugustin Cavalier
820753c7e08SAugustin Cavalier case IEEE80211_FC0_TYPE_MGT:
821753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgmt++;
822753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_mgmt);
823753c7e08SAugustin Cavalier if (dir != IEEE80211_FC1_DIR_NODS) {
824753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
825753c7e08SAugustin Cavalier wh, "mgt", "incorrect dir 0x%x", dir);
826753c7e08SAugustin Cavalier vap->iv_stats.is_rx_wrongdir++;
827753c7e08SAugustin Cavalier goto err;
828753c7e08SAugustin Cavalier }
829753c7e08SAugustin Cavalier if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) {
830753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY,
831753c7e08SAugustin Cavalier ni->ni_macaddr, "mgt", "too short: len %u",
832753c7e08SAugustin Cavalier m->m_pkthdr.len);
833753c7e08SAugustin Cavalier vap->iv_stats.is_rx_tooshort++;
834753c7e08SAugustin Cavalier goto out;
835753c7e08SAugustin Cavalier }
836753c7e08SAugustin Cavalier if (IEEE80211_IS_MULTICAST(wh->i_addr2)) {
837753c7e08SAugustin Cavalier /* ensure return frames are unicast */
838753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
839753c7e08SAugustin Cavalier wh, NULL, "source is multicast: %s",
840753c7e08SAugustin Cavalier ether_sprintf(wh->i_addr2));
841753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */
842753c7e08SAugustin Cavalier goto out;
843753c7e08SAugustin Cavalier }
844753c7e08SAugustin Cavalier #ifdef IEEE80211_DEBUG
845753c7e08SAugustin Cavalier if ((ieee80211_msg_debug(vap) && doprint(vap, subtype)) ||
846753c7e08SAugustin Cavalier ieee80211_msg_dumppkts(vap)) {
847753c7e08SAugustin Cavalier if_printf(ifp, "received %s from %s rssi %d\n",
848753c7e08SAugustin Cavalier ieee80211_mgt_subtype_name(subtype),
849753c7e08SAugustin Cavalier ether_sprintf(wh->i_addr2), rssi);
850753c7e08SAugustin Cavalier }
851753c7e08SAugustin Cavalier #endif
85286021fd4SAugustin Cavalier if (IEEE80211_IS_PROTECTED(wh)) {
853753c7e08SAugustin Cavalier if (subtype != IEEE80211_FC0_SUBTYPE_AUTH) {
854753c7e08SAugustin Cavalier /*
855753c7e08SAugustin Cavalier * Only shared key auth frames with a challenge
856753c7e08SAugustin Cavalier * should be encrypted, discard all others.
857753c7e08SAugustin Cavalier */
858753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
859753c7e08SAugustin Cavalier wh, NULL,
860753c7e08SAugustin Cavalier "%s", "WEP set but not permitted");
861753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++; /* XXX */
862753c7e08SAugustin Cavalier goto out;
863753c7e08SAugustin Cavalier }
864753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
865753c7e08SAugustin Cavalier /*
866753c7e08SAugustin Cavalier * Discard encrypted frames when privacy is off.
867753c7e08SAugustin Cavalier */
868753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
869753c7e08SAugustin Cavalier wh, NULL, "%s", "WEP set but PRIVACY off");
870753c7e08SAugustin Cavalier vap->iv_stats.is_rx_noprivacy++;
871753c7e08SAugustin Cavalier goto out;
872753c7e08SAugustin Cavalier }
873753c7e08SAugustin Cavalier hdrspace = ieee80211_hdrspace(ic, wh);
8748244a9baSAugustin Cavalier if (ieee80211_crypto_decap(ni, m, hdrspace, &key) == 0) {
875753c7e08SAugustin Cavalier /* NB: stats+msgs handled in crypto_decap */
876753c7e08SAugustin Cavalier goto out;
877753c7e08SAugustin Cavalier }
878753c7e08SAugustin Cavalier wh = mtod(m, struct ieee80211_frame *);
879753c7e08SAugustin Cavalier wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED;
8808244a9baSAugustin Cavalier has_decrypted = 1;
881753c7e08SAugustin Cavalier }
882753c7e08SAugustin Cavalier /*
883753c7e08SAugustin Cavalier * Pass the packet to radiotap before calling iv_recv_mgmt().
884753c7e08SAugustin Cavalier * Otherwise iv_recv_mgmt() might pass another packet to
885753c7e08SAugustin Cavalier * radiotap, resulting in out of order packet captures.
886753c7e08SAugustin Cavalier */
887753c7e08SAugustin Cavalier if (ieee80211_radiotap_active_vap(vap))
888753c7e08SAugustin Cavalier ieee80211_radiotap_rx(vap, m);
889753c7e08SAugustin Cavalier need_tap = 0;
890753c7e08SAugustin Cavalier vap->iv_recv_mgmt(ni, m, subtype, rxs, rssi, nf);
891753c7e08SAugustin Cavalier goto out;
892753c7e08SAugustin Cavalier
893753c7e08SAugustin Cavalier case IEEE80211_FC0_TYPE_CTL:
894753c7e08SAugustin Cavalier vap->iv_stats.is_rx_ctl++;
895753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_ctrl);
896753c7e08SAugustin Cavalier vap->iv_recv_ctl(ni, m, subtype);
897753c7e08SAugustin Cavalier goto out;
898753c7e08SAugustin Cavalier default:
899753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
900753c7e08SAugustin Cavalier wh, "bad", "frame type 0x%x", type);
901753c7e08SAugustin Cavalier /* should not come here */
902753c7e08SAugustin Cavalier break;
903753c7e08SAugustin Cavalier }
904753c7e08SAugustin Cavalier err:
905753c7e08SAugustin Cavalier if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
906753c7e08SAugustin Cavalier out:
907753c7e08SAugustin Cavalier if (m != NULL) {
908753c7e08SAugustin Cavalier if (need_tap && ieee80211_radiotap_active_vap(vap))
909753c7e08SAugustin Cavalier ieee80211_radiotap_rx(vap, m);
910753c7e08SAugustin Cavalier m_freem(m);
911753c7e08SAugustin Cavalier }
912753c7e08SAugustin Cavalier return type;
913753c7e08SAugustin Cavalier }
914753c7e08SAugustin Cavalier
915753c7e08SAugustin Cavalier static void
hostap_auth_open(struct ieee80211_node * ni,struct ieee80211_frame * wh,int rssi,int nf,uint16_t seq,uint16_t status)916753c7e08SAugustin Cavalier hostap_auth_open(struct ieee80211_node *ni, struct ieee80211_frame *wh,
917753c7e08SAugustin Cavalier int rssi, int nf, uint16_t seq, uint16_t status)
918753c7e08SAugustin Cavalier {
919753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
920753c7e08SAugustin Cavalier
921753c7e08SAugustin Cavalier KASSERT(vap->iv_state == IEEE80211_S_RUN, ("state %d", vap->iv_state));
922753c7e08SAugustin Cavalier
923753c7e08SAugustin Cavalier if (ni->ni_authmode == IEEE80211_AUTH_SHARED) {
924753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
925753c7e08SAugustin Cavalier ni->ni_macaddr, "open auth",
926753c7e08SAugustin Cavalier "bad sta auth mode %u", ni->ni_authmode);
927753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++; /* XXX */
928753c7e08SAugustin Cavalier /*
929753c7e08SAugustin Cavalier * Clear any challenge text that may be there if
930753c7e08SAugustin Cavalier * a previous shared key auth failed and then an
931753c7e08SAugustin Cavalier * open auth is attempted.
932753c7e08SAugustin Cavalier */
933753c7e08SAugustin Cavalier if (ni->ni_challenge != NULL) {
934753c7e08SAugustin Cavalier IEEE80211_FREE(ni->ni_challenge, M_80211_NODE);
935753c7e08SAugustin Cavalier ni->ni_challenge = NULL;
936753c7e08SAugustin Cavalier }
937753c7e08SAugustin Cavalier /* XXX hack to workaround calling convention */
938753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2,
939753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_AUTH,
940753c7e08SAugustin Cavalier (seq + 1) | (IEEE80211_STATUS_ALG<<16));
941753c7e08SAugustin Cavalier return;
942753c7e08SAugustin Cavalier }
943753c7e08SAugustin Cavalier if (seq != IEEE80211_AUTH_OPEN_REQUEST) {
944753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++;
945753c7e08SAugustin Cavalier return;
946753c7e08SAugustin Cavalier }
947753c7e08SAugustin Cavalier /* always accept open authentication requests */
948753c7e08SAugustin Cavalier if (ni == vap->iv_bss) {
949753c7e08SAugustin Cavalier ni = ieee80211_dup_bss(vap, wh->i_addr2);
950753c7e08SAugustin Cavalier if (ni == NULL)
951753c7e08SAugustin Cavalier return;
952753c7e08SAugustin Cavalier } else if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0)
953753c7e08SAugustin Cavalier (void) ieee80211_ref_node(ni);
954753c7e08SAugustin Cavalier /*
955753c7e08SAugustin Cavalier * Mark the node as referenced to reflect that it's
956753c7e08SAugustin Cavalier * reference count has been bumped to insure it remains
957753c7e08SAugustin Cavalier * after the transaction completes.
958753c7e08SAugustin Cavalier */
959753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_AREF;
960753c7e08SAugustin Cavalier /*
961753c7e08SAugustin Cavalier * Mark the node as requiring a valid association id
962753c7e08SAugustin Cavalier * before outbound traffic is permitted.
963753c7e08SAugustin Cavalier */
964753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_ASSOCID;
965753c7e08SAugustin Cavalier
966753c7e08SAugustin Cavalier if (vap->iv_acl != NULL &&
967753c7e08SAugustin Cavalier vap->iv_acl->iac_getpolicy(vap) == IEEE80211_MACCMD_POLICY_RADIUS) {
968753c7e08SAugustin Cavalier /*
969753c7e08SAugustin Cavalier * When the ACL policy is set to RADIUS we defer the
970753c7e08SAugustin Cavalier * authorization to a user agent. Dispatch an event,
971753c7e08SAugustin Cavalier * a subsequent MLME call will decide the fate of the
972753c7e08SAugustin Cavalier * station. If the user agent is not present then the
973753c7e08SAugustin Cavalier * node will be reclaimed due to inactivity.
974753c7e08SAugustin Cavalier */
975753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap,
976753c7e08SAugustin Cavalier IEEE80211_MSG_AUTH | IEEE80211_MSG_ACL, ni->ni_macaddr,
97786021fd4SAugustin Cavalier "%s", "station authentication deferred (radius acl)");
978753c7e08SAugustin Cavalier ieee80211_notify_node_auth(ni);
979753c7e08SAugustin Cavalier } else {
980753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, seq + 1);
981753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap,
982753c7e08SAugustin Cavalier IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, ni->ni_macaddr,
983753c7e08SAugustin Cavalier "%s", "station authenticated (open)");
984753c7e08SAugustin Cavalier /*
985753c7e08SAugustin Cavalier * When 802.1x is not in use mark the port
986753c7e08SAugustin Cavalier * authorized at this point so traffic can flow.
987753c7e08SAugustin Cavalier */
988753c7e08SAugustin Cavalier if (ni->ni_authmode != IEEE80211_AUTH_8021X)
989753c7e08SAugustin Cavalier ieee80211_node_authorize(ni);
990753c7e08SAugustin Cavalier }
991753c7e08SAugustin Cavalier }
992753c7e08SAugustin Cavalier
993753c7e08SAugustin Cavalier static void
hostap_auth_shared(struct ieee80211_node * ni,struct ieee80211_frame * wh,uint8_t * frm,uint8_t * efrm,int rssi,int nf,uint16_t seq,uint16_t status)994753c7e08SAugustin Cavalier hostap_auth_shared(struct ieee80211_node *ni, struct ieee80211_frame *wh,
995753c7e08SAugustin Cavalier uint8_t *frm, uint8_t *efrm, int rssi, int nf,
996753c7e08SAugustin Cavalier uint16_t seq, uint16_t status)
997753c7e08SAugustin Cavalier {
998753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
999753c7e08SAugustin Cavalier uint8_t *challenge;
100086021fd4SAugustin Cavalier int estatus;
1001753c7e08SAugustin Cavalier
1002753c7e08SAugustin Cavalier KASSERT(vap->iv_state == IEEE80211_S_RUN, ("state %d", vap->iv_state));
1003753c7e08SAugustin Cavalier
1004753c7e08SAugustin Cavalier /*
1005753c7e08SAugustin Cavalier * NB: this can happen as we allow pre-shared key
1006753c7e08SAugustin Cavalier * authentication to be enabled w/o wep being turned
1007753c7e08SAugustin Cavalier * on so that configuration of these can be done
1008753c7e08SAugustin Cavalier * in any order. It may be better to enforce the
1009753c7e08SAugustin Cavalier * ordering in which case this check would just be
1010753c7e08SAugustin Cavalier * for sanity/consistency.
1011753c7e08SAugustin Cavalier */
1012753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) {
1013753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1014753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key auth",
1015753c7e08SAugustin Cavalier "%s", " PRIVACY is disabled");
1016753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_ALG;
1017753c7e08SAugustin Cavalier goto bad;
1018753c7e08SAugustin Cavalier }
1019753c7e08SAugustin Cavalier /*
1020753c7e08SAugustin Cavalier * Pre-shared key authentication is evil; accept
1021753c7e08SAugustin Cavalier * it only if explicitly configured (it is supported
1022753c7e08SAugustin Cavalier * mainly for compatibility with clients like Mac OS X).
1023753c7e08SAugustin Cavalier */
1024753c7e08SAugustin Cavalier if (ni->ni_authmode != IEEE80211_AUTH_AUTO &&
1025753c7e08SAugustin Cavalier ni->ni_authmode != IEEE80211_AUTH_SHARED) {
1026753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1027753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key auth",
1028753c7e08SAugustin Cavalier "bad sta auth mode %u", ni->ni_authmode);
1029753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++; /* XXX maybe a unique error? */
1030753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_ALG;
1031753c7e08SAugustin Cavalier goto bad;
1032753c7e08SAugustin Cavalier }
1033753c7e08SAugustin Cavalier
1034753c7e08SAugustin Cavalier challenge = NULL;
1035753c7e08SAugustin Cavalier if (frm + 1 < efrm) {
1036753c7e08SAugustin Cavalier if ((frm[1] + 2) > (efrm - frm)) {
1037753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1038753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key auth",
1039753c7e08SAugustin Cavalier "ie %d/%d too long",
1040753c7e08SAugustin Cavalier frm[0], (frm[1] + 2) - (efrm - frm));
1041753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++;
1042753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_CHALLENGE;
1043753c7e08SAugustin Cavalier goto bad;
1044753c7e08SAugustin Cavalier }
1045753c7e08SAugustin Cavalier if (*frm == IEEE80211_ELEMID_CHALLENGE)
1046753c7e08SAugustin Cavalier challenge = frm;
1047753c7e08SAugustin Cavalier frm += frm[1] + 2;
1048753c7e08SAugustin Cavalier }
1049753c7e08SAugustin Cavalier switch (seq) {
1050753c7e08SAugustin Cavalier case IEEE80211_AUTH_SHARED_CHALLENGE:
1051753c7e08SAugustin Cavalier case IEEE80211_AUTH_SHARED_RESPONSE:
1052753c7e08SAugustin Cavalier if (challenge == NULL) {
1053753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1054753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key auth",
1055753c7e08SAugustin Cavalier "%s", "no challenge");
1056753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++;
1057753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_CHALLENGE;
1058753c7e08SAugustin Cavalier goto bad;
1059753c7e08SAugustin Cavalier }
1060753c7e08SAugustin Cavalier if (challenge[1] != IEEE80211_CHALLENGE_LEN) {
1061753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1062753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key auth",
1063753c7e08SAugustin Cavalier "bad challenge len %d", challenge[1]);
1064753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++;
1065753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_CHALLENGE;
1066753c7e08SAugustin Cavalier goto bad;
1067753c7e08SAugustin Cavalier }
1068753c7e08SAugustin Cavalier default:
1069753c7e08SAugustin Cavalier break;
1070753c7e08SAugustin Cavalier }
1071753c7e08SAugustin Cavalier switch (seq) {
1072753c7e08SAugustin Cavalier case IEEE80211_AUTH_SHARED_REQUEST:
107386021fd4SAugustin Cavalier {
107486021fd4SAugustin Cavalier #ifdef IEEE80211_DEBUG
107586021fd4SAugustin Cavalier bool allocbs;
107686021fd4SAugustin Cavalier #endif
107786021fd4SAugustin Cavalier
1078753c7e08SAugustin Cavalier if (ni == vap->iv_bss) {
1079753c7e08SAugustin Cavalier ni = ieee80211_dup_bss(vap, wh->i_addr2);
1080753c7e08SAugustin Cavalier if (ni == NULL) {
1081753c7e08SAugustin Cavalier /* NB: no way to return an error */
1082753c7e08SAugustin Cavalier return;
1083753c7e08SAugustin Cavalier }
108486021fd4SAugustin Cavalier #ifdef IEEE80211_DEBUG
1085753c7e08SAugustin Cavalier allocbs = 1;
108686021fd4SAugustin Cavalier #endif
1087753c7e08SAugustin Cavalier } else {
1088753c7e08SAugustin Cavalier if ((ni->ni_flags & IEEE80211_NODE_AREF) == 0)
1089753c7e08SAugustin Cavalier (void) ieee80211_ref_node(ni);
109086021fd4SAugustin Cavalier #ifdef IEEE80211_DEBUG
1091753c7e08SAugustin Cavalier allocbs = 0;
109286021fd4SAugustin Cavalier #endif
1093753c7e08SAugustin Cavalier }
1094753c7e08SAugustin Cavalier /*
1095753c7e08SAugustin Cavalier * Mark the node as referenced to reflect that it's
1096753c7e08SAugustin Cavalier * reference count has been bumped to insure it remains
1097753c7e08SAugustin Cavalier * after the transaction completes.
1098753c7e08SAugustin Cavalier */
1099753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_AREF;
1100753c7e08SAugustin Cavalier /*
1101753c7e08SAugustin Cavalier * Mark the node as requiring a valid association id
1102753c7e08SAugustin Cavalier * before outbound traffic is permitted.
1103753c7e08SAugustin Cavalier */
1104753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_ASSOCID;
1105753c7e08SAugustin Cavalier IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
1106753c7e08SAugustin Cavalier ni->ni_noise = nf;
1107753c7e08SAugustin Cavalier if (!ieee80211_alloc_challenge(ni)) {
1108753c7e08SAugustin Cavalier /* NB: don't return error so they rexmit */
1109753c7e08SAugustin Cavalier return;
1110753c7e08SAugustin Cavalier }
111186021fd4SAugustin Cavalier net80211_get_random_bytes(ni->ni_challenge,
1112753c7e08SAugustin Cavalier IEEE80211_CHALLENGE_LEN);
1113753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH,
1114753c7e08SAugustin Cavalier ni, "shared key %sauth request", allocbs ? "" : "re");
1115753c7e08SAugustin Cavalier /*
1116753c7e08SAugustin Cavalier * When the ACL policy is set to RADIUS we defer the
1117753c7e08SAugustin Cavalier * authorization to a user agent. Dispatch an event,
1118753c7e08SAugustin Cavalier * a subsequent MLME call will decide the fate of the
1119753c7e08SAugustin Cavalier * station. If the user agent is not present then the
1120753c7e08SAugustin Cavalier * node will be reclaimed due to inactivity.
1121753c7e08SAugustin Cavalier */
1122753c7e08SAugustin Cavalier if (vap->iv_acl != NULL &&
1123753c7e08SAugustin Cavalier vap->iv_acl->iac_getpolicy(vap) == IEEE80211_MACCMD_POLICY_RADIUS) {
1124753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap,
1125753c7e08SAugustin Cavalier IEEE80211_MSG_AUTH | IEEE80211_MSG_ACL,
1126753c7e08SAugustin Cavalier ni->ni_macaddr,
112786021fd4SAugustin Cavalier "%s", "station authentication deferred (radius acl)");
1128753c7e08SAugustin Cavalier ieee80211_notify_node_auth(ni);
1129753c7e08SAugustin Cavalier return;
1130753c7e08SAugustin Cavalier }
1131753c7e08SAugustin Cavalier break;
113286021fd4SAugustin Cavalier }
1133753c7e08SAugustin Cavalier case IEEE80211_AUTH_SHARED_RESPONSE:
1134753c7e08SAugustin Cavalier if (ni == vap->iv_bss) {
1135753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1136753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key response",
1137753c7e08SAugustin Cavalier "%s", "unknown station");
1138753c7e08SAugustin Cavalier /* NB: don't send a response */
1139753c7e08SAugustin Cavalier return;
1140753c7e08SAugustin Cavalier }
1141753c7e08SAugustin Cavalier if (ni->ni_challenge == NULL) {
1142753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1143753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key response",
1144753c7e08SAugustin Cavalier "%s", "no challenge recorded");
1145753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++;
1146753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_CHALLENGE;
1147753c7e08SAugustin Cavalier goto bad;
1148753c7e08SAugustin Cavalier }
1149753c7e08SAugustin Cavalier if (memcmp(ni->ni_challenge, &challenge[2],
1150753c7e08SAugustin Cavalier challenge[1]) != 0) {
1151753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1152753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key response",
1153753c7e08SAugustin Cavalier "%s", "challenge mismatch");
1154753c7e08SAugustin Cavalier vap->iv_stats.is_rx_auth_fail++;
1155753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_CHALLENGE;
1156753c7e08SAugustin Cavalier goto bad;
1157753c7e08SAugustin Cavalier }
1158753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH,
1159753c7e08SAugustin Cavalier ni, "%s", "station authenticated (shared key)");
1160753c7e08SAugustin Cavalier ieee80211_node_authorize(ni);
1161753c7e08SAugustin Cavalier break;
1162753c7e08SAugustin Cavalier default:
1163753c7e08SAugustin Cavalier IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_AUTH,
1164753c7e08SAugustin Cavalier ni->ni_macaddr, "shared key auth",
1165753c7e08SAugustin Cavalier "bad seq %d", seq);
1166753c7e08SAugustin Cavalier vap->iv_stats.is_rx_bad_auth++;
1167753c7e08SAugustin Cavalier estatus = IEEE80211_STATUS_SEQUENCE;
1168753c7e08SAugustin Cavalier goto bad;
1169753c7e08SAugustin Cavalier }
1170753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_AUTH, seq + 1);
1171753c7e08SAugustin Cavalier return;
1172753c7e08SAugustin Cavalier bad:
1173753c7e08SAugustin Cavalier /*
1174753c7e08SAugustin Cavalier * Send an error response; but only when operating as an AP.
1175753c7e08SAugustin Cavalier */
1176753c7e08SAugustin Cavalier /* XXX hack to workaround calling convention */
1177753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2,
1178753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_AUTH,
1179753c7e08SAugustin Cavalier (seq + 1) | (estatus<<16));
1180753c7e08SAugustin Cavalier }
1181753c7e08SAugustin Cavalier
1182753c7e08SAugustin Cavalier /*
1183753c7e08SAugustin Cavalier * Convert a WPA cipher selector OUI to an internal
1184753c7e08SAugustin Cavalier * cipher algorithm. Where appropriate we also
1185753c7e08SAugustin Cavalier * record any key length.
1186753c7e08SAugustin Cavalier */
1187753c7e08SAugustin Cavalier static int
wpa_cipher(const uint8_t * sel,uint8_t * keylen,uint8_t * cipher)11888244a9baSAugustin Cavalier wpa_cipher(const uint8_t *sel, uint8_t *keylen, uint8_t *cipher)
1189753c7e08SAugustin Cavalier {
1190753c7e08SAugustin Cavalier #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
1191753c7e08SAugustin Cavalier uint32_t w = le32dec(sel);
1192753c7e08SAugustin Cavalier
1193753c7e08SAugustin Cavalier switch (w) {
1194753c7e08SAugustin Cavalier case WPA_SEL(WPA_CSE_NULL):
11958244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_NONE;
11968244a9baSAugustin Cavalier break;
1197753c7e08SAugustin Cavalier case WPA_SEL(WPA_CSE_WEP40):
1198753c7e08SAugustin Cavalier if (keylen)
1199753c7e08SAugustin Cavalier *keylen = 40 / NBBY;
12008244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_WEP;
12018244a9baSAugustin Cavalier break;
1202753c7e08SAugustin Cavalier case WPA_SEL(WPA_CSE_WEP104):
1203753c7e08SAugustin Cavalier if (keylen)
1204753c7e08SAugustin Cavalier *keylen = 104 / NBBY;
12058244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_WEP;
12068244a9baSAugustin Cavalier break;
1207753c7e08SAugustin Cavalier case WPA_SEL(WPA_CSE_TKIP):
12088244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_TKIP;
12098244a9baSAugustin Cavalier break;
1210753c7e08SAugustin Cavalier case WPA_SEL(WPA_CSE_CCMP):
12118244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_AES_CCM;
12128244a9baSAugustin Cavalier break;
12138244a9baSAugustin Cavalier default:
12148244a9baSAugustin Cavalier return (EINVAL);
1215753c7e08SAugustin Cavalier }
12168244a9baSAugustin Cavalier
12178244a9baSAugustin Cavalier return (0);
1218753c7e08SAugustin Cavalier #undef WPA_SEL
1219753c7e08SAugustin Cavalier }
1220753c7e08SAugustin Cavalier
1221753c7e08SAugustin Cavalier /*
1222753c7e08SAugustin Cavalier * Convert a WPA key management/authentication algorithm
1223753c7e08SAugustin Cavalier * to an internal code.
1224753c7e08SAugustin Cavalier */
1225753c7e08SAugustin Cavalier static int
wpa_keymgmt(const uint8_t * sel)1226753c7e08SAugustin Cavalier wpa_keymgmt(const uint8_t *sel)
1227753c7e08SAugustin Cavalier {
1228753c7e08SAugustin Cavalier #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
1229753c7e08SAugustin Cavalier uint32_t w = le32dec(sel);
1230753c7e08SAugustin Cavalier
1231753c7e08SAugustin Cavalier switch (w) {
1232753c7e08SAugustin Cavalier case WPA_SEL(WPA_ASE_8021X_UNSPEC):
1233753c7e08SAugustin Cavalier return WPA_ASE_8021X_UNSPEC;
1234753c7e08SAugustin Cavalier case WPA_SEL(WPA_ASE_8021X_PSK):
1235753c7e08SAugustin Cavalier return WPA_ASE_8021X_PSK;
1236753c7e08SAugustin Cavalier case WPA_SEL(WPA_ASE_NONE):
1237753c7e08SAugustin Cavalier return WPA_ASE_NONE;
1238753c7e08SAugustin Cavalier }
1239753c7e08SAugustin Cavalier return 0; /* NB: so is discarded */
1240753c7e08SAugustin Cavalier #undef WPA_SEL
1241753c7e08SAugustin Cavalier }
1242753c7e08SAugustin Cavalier
1243753c7e08SAugustin Cavalier /*
1244753c7e08SAugustin Cavalier * Parse a WPA information element to collect parameters.
1245753c7e08SAugustin Cavalier * Note that we do not validate security parameters; that
1246753c7e08SAugustin Cavalier * is handled by the authenticator; the parsing done here
1247753c7e08SAugustin Cavalier * is just for internal use in making operational decisions.
1248753c7e08SAugustin Cavalier */
1249753c7e08SAugustin Cavalier static int
ieee80211_parse_wpa(struct ieee80211vap * vap,const uint8_t * frm,struct ieee80211_rsnparms * rsn,const struct ieee80211_frame * wh)1250753c7e08SAugustin Cavalier ieee80211_parse_wpa(struct ieee80211vap *vap, const uint8_t *frm,
1251753c7e08SAugustin Cavalier struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh)
1252753c7e08SAugustin Cavalier {
1253753c7e08SAugustin Cavalier uint8_t len = frm[1];
1254753c7e08SAugustin Cavalier uint32_t w;
12558244a9baSAugustin Cavalier int error, n;
1256753c7e08SAugustin Cavalier
1257753c7e08SAugustin Cavalier /*
1258753c7e08SAugustin Cavalier * Check the length once for fixed parts: OUI, type,
1259753c7e08SAugustin Cavalier * version, mcast cipher, and 2 selector counts.
1260753c7e08SAugustin Cavalier * Other, variable-length data, must be checked separately.
1261753c7e08SAugustin Cavalier */
1262753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_WPA1) == 0) {
1263753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1264753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1265753c7e08SAugustin Cavalier wh, "WPA", "not WPA, flags 0x%x", vap->iv_flags);
1266753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1267753c7e08SAugustin Cavalier }
1268753c7e08SAugustin Cavalier if (len < 14) {
1269753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1270753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1271753c7e08SAugustin Cavalier wh, "WPA", "too short, len %u", len);
1272753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1273753c7e08SAugustin Cavalier }
1274753c7e08SAugustin Cavalier frm += 6, len -= 4; /* NB: len is payload only */
1275753c7e08SAugustin Cavalier /* NB: iswpaoui already validated the OUI and type */
1276753c7e08SAugustin Cavalier w = le16dec(frm);
1277753c7e08SAugustin Cavalier if (w != WPA_VERSION) {
1278753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1279753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1280753c7e08SAugustin Cavalier wh, "WPA", "bad version %u", w);
1281753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1282753c7e08SAugustin Cavalier }
1283753c7e08SAugustin Cavalier frm += 2, len -= 2;
1284753c7e08SAugustin Cavalier
1285753c7e08SAugustin Cavalier memset(rsn, 0, sizeof(*rsn));
1286753c7e08SAugustin Cavalier
1287753c7e08SAugustin Cavalier /* multicast/group cipher */
12888244a9baSAugustin Cavalier error = wpa_cipher(frm, &rsn->rsn_mcastkeylen, &rsn->rsn_mcastcipher);
12898244a9baSAugustin Cavalier if (error != 0) {
12908244a9baSAugustin Cavalier IEEE80211_DISCARD_IE(vap,
12918244a9baSAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
12928244a9baSAugustin Cavalier wh, "WPA", "unknown mcast cipher suite %08X",
12938244a9baSAugustin Cavalier le32dec(frm));
12948244a9baSAugustin Cavalier return IEEE80211_REASON_GROUP_CIPHER_INVALID;
12958244a9baSAugustin Cavalier }
1296753c7e08SAugustin Cavalier frm += 4, len -= 4;
1297753c7e08SAugustin Cavalier
1298753c7e08SAugustin Cavalier /* unicast ciphers */
1299753c7e08SAugustin Cavalier n = le16dec(frm);
1300753c7e08SAugustin Cavalier frm += 2, len -= 2;
1301753c7e08SAugustin Cavalier if (len < n*4+2) {
1302753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1303753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1304753c7e08SAugustin Cavalier wh, "WPA", "ucast cipher data too short; len %u, n %u",
1305753c7e08SAugustin Cavalier len, n);
1306753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1307753c7e08SAugustin Cavalier }
1308753c7e08SAugustin Cavalier w = 0;
1309753c7e08SAugustin Cavalier for (; n > 0; n--) {
13108244a9baSAugustin Cavalier uint8_t cipher;
13118244a9baSAugustin Cavalier
13128244a9baSAugustin Cavalier error = wpa_cipher(frm, &rsn->rsn_ucastkeylen, &cipher);
13138244a9baSAugustin Cavalier if (error == 0)
13148244a9baSAugustin Cavalier w |= 1 << cipher;
13158244a9baSAugustin Cavalier
1316753c7e08SAugustin Cavalier frm += 4, len -= 4;
1317753c7e08SAugustin Cavalier }
13188244a9baSAugustin Cavalier if (w == 0) {
13198244a9baSAugustin Cavalier IEEE80211_DISCARD_IE(vap,
13208244a9baSAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
13218244a9baSAugustin Cavalier wh, "WPA", "no usable pairwise cipher suite found (w=%d)",
13228244a9baSAugustin Cavalier w);
13238244a9baSAugustin Cavalier return IEEE80211_REASON_PAIRWISE_CIPHER_INVALID;
13248244a9baSAugustin Cavalier }
13258244a9baSAugustin Cavalier /* XXX other? */
13268244a9baSAugustin Cavalier if (w & (1 << IEEE80211_CIPHER_AES_CCM))
1327753c7e08SAugustin Cavalier rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM;
13288244a9baSAugustin Cavalier else
13298244a9baSAugustin Cavalier rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP;
1330753c7e08SAugustin Cavalier
1331753c7e08SAugustin Cavalier /* key management algorithms */
1332753c7e08SAugustin Cavalier n = le16dec(frm);
1333753c7e08SAugustin Cavalier frm += 2, len -= 2;
1334753c7e08SAugustin Cavalier if (len < n*4) {
1335753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1336753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1337753c7e08SAugustin Cavalier wh, "WPA", "key mgmt alg data too short; len %u, n %u",
1338753c7e08SAugustin Cavalier len, n);
1339753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1340753c7e08SAugustin Cavalier }
1341753c7e08SAugustin Cavalier w = 0;
1342753c7e08SAugustin Cavalier for (; n > 0; n--) {
1343753c7e08SAugustin Cavalier w |= wpa_keymgmt(frm);
1344753c7e08SAugustin Cavalier frm += 4, len -= 4;
1345753c7e08SAugustin Cavalier }
1346753c7e08SAugustin Cavalier if (w & WPA_ASE_8021X_UNSPEC)
1347753c7e08SAugustin Cavalier rsn->rsn_keymgmt = WPA_ASE_8021X_UNSPEC;
1348753c7e08SAugustin Cavalier else
1349753c7e08SAugustin Cavalier rsn->rsn_keymgmt = WPA_ASE_8021X_PSK;
1350753c7e08SAugustin Cavalier
1351753c7e08SAugustin Cavalier if (len > 2) /* optional capabilities */
1352753c7e08SAugustin Cavalier rsn->rsn_caps = le16dec(frm);
1353753c7e08SAugustin Cavalier
1354753c7e08SAugustin Cavalier return 0;
1355753c7e08SAugustin Cavalier }
1356753c7e08SAugustin Cavalier
1357753c7e08SAugustin Cavalier /*
1358753c7e08SAugustin Cavalier * Convert an RSN cipher selector OUI to an internal
1359753c7e08SAugustin Cavalier * cipher algorithm. Where appropriate we also
1360753c7e08SAugustin Cavalier * record any key length.
1361753c7e08SAugustin Cavalier */
1362753c7e08SAugustin Cavalier static int
rsn_cipher(const uint8_t * sel,uint8_t * keylen,uint8_t * cipher)13638244a9baSAugustin Cavalier rsn_cipher(const uint8_t *sel, uint8_t *keylen, uint8_t *cipher)
1364753c7e08SAugustin Cavalier {
1365753c7e08SAugustin Cavalier #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
1366753c7e08SAugustin Cavalier uint32_t w = le32dec(sel);
1367753c7e08SAugustin Cavalier
1368753c7e08SAugustin Cavalier switch (w) {
1369753c7e08SAugustin Cavalier case RSN_SEL(RSN_CSE_NULL):
13708244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_NONE;
13718244a9baSAugustin Cavalier break;
1372753c7e08SAugustin Cavalier case RSN_SEL(RSN_CSE_WEP40):
1373753c7e08SAugustin Cavalier if (keylen)
1374753c7e08SAugustin Cavalier *keylen = 40 / NBBY;
13758244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_WEP;
13768244a9baSAugustin Cavalier break;
1377753c7e08SAugustin Cavalier case RSN_SEL(RSN_CSE_WEP104):
1378753c7e08SAugustin Cavalier if (keylen)
1379753c7e08SAugustin Cavalier *keylen = 104 / NBBY;
13808244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_WEP;
13818244a9baSAugustin Cavalier break;
1382753c7e08SAugustin Cavalier case RSN_SEL(RSN_CSE_TKIP):
13838244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_TKIP;
13848244a9baSAugustin Cavalier break;
1385753c7e08SAugustin Cavalier case RSN_SEL(RSN_CSE_CCMP):
13868244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_AES_CCM;
13878244a9baSAugustin Cavalier break;
1388753c7e08SAugustin Cavalier case RSN_SEL(RSN_CSE_WRAP):
13898244a9baSAugustin Cavalier *cipher = IEEE80211_CIPHER_AES_OCB;
13908244a9baSAugustin Cavalier break;
13918244a9baSAugustin Cavalier default:
13928244a9baSAugustin Cavalier return (EINVAL);
1393753c7e08SAugustin Cavalier }
13948244a9baSAugustin Cavalier
13958244a9baSAugustin Cavalier return (0);
1396753c7e08SAugustin Cavalier #undef WPA_SEL
1397753c7e08SAugustin Cavalier }
1398753c7e08SAugustin Cavalier
1399753c7e08SAugustin Cavalier /*
1400753c7e08SAugustin Cavalier * Convert an RSN key management/authentication algorithm
1401753c7e08SAugustin Cavalier * to an internal code.
1402753c7e08SAugustin Cavalier */
1403753c7e08SAugustin Cavalier static int
rsn_keymgmt(const uint8_t * sel)1404753c7e08SAugustin Cavalier rsn_keymgmt(const uint8_t *sel)
1405753c7e08SAugustin Cavalier {
1406753c7e08SAugustin Cavalier #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
1407753c7e08SAugustin Cavalier uint32_t w = le32dec(sel);
1408753c7e08SAugustin Cavalier
1409753c7e08SAugustin Cavalier switch (w) {
1410753c7e08SAugustin Cavalier case RSN_SEL(RSN_ASE_8021X_UNSPEC):
1411753c7e08SAugustin Cavalier return RSN_ASE_8021X_UNSPEC;
1412753c7e08SAugustin Cavalier case RSN_SEL(RSN_ASE_8021X_PSK):
1413753c7e08SAugustin Cavalier return RSN_ASE_8021X_PSK;
1414753c7e08SAugustin Cavalier case RSN_SEL(RSN_ASE_NONE):
1415753c7e08SAugustin Cavalier return RSN_ASE_NONE;
1416753c7e08SAugustin Cavalier }
1417753c7e08SAugustin Cavalier return 0; /* NB: so is discarded */
1418753c7e08SAugustin Cavalier #undef RSN_SEL
1419753c7e08SAugustin Cavalier }
1420753c7e08SAugustin Cavalier
1421753c7e08SAugustin Cavalier /*
1422753c7e08SAugustin Cavalier * Parse a WPA/RSN information element to collect parameters
1423753c7e08SAugustin Cavalier * and validate the parameters against what has been
1424753c7e08SAugustin Cavalier * configured for the system.
1425753c7e08SAugustin Cavalier */
1426753c7e08SAugustin Cavalier static int
ieee80211_parse_rsn(struct ieee80211vap * vap,const uint8_t * frm,struct ieee80211_rsnparms * rsn,const struct ieee80211_frame * wh)1427753c7e08SAugustin Cavalier ieee80211_parse_rsn(struct ieee80211vap *vap, const uint8_t *frm,
1428753c7e08SAugustin Cavalier struct ieee80211_rsnparms *rsn, const struct ieee80211_frame *wh)
1429753c7e08SAugustin Cavalier {
1430753c7e08SAugustin Cavalier uint8_t len = frm[1];
1431753c7e08SAugustin Cavalier uint32_t w;
14328244a9baSAugustin Cavalier int error, n;
1433753c7e08SAugustin Cavalier
1434753c7e08SAugustin Cavalier /*
1435753c7e08SAugustin Cavalier * Check the length once for fixed parts:
1436753c7e08SAugustin Cavalier * version, mcast cipher, and 2 selector counts.
1437753c7e08SAugustin Cavalier * Other, variable-length data, must be checked separately.
1438753c7e08SAugustin Cavalier */
1439753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_WPA2) == 0) {
1440753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1441753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1442753c7e08SAugustin Cavalier wh, "WPA", "not RSN, flags 0x%x", vap->iv_flags);
1443753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1444753c7e08SAugustin Cavalier }
14458244a9baSAugustin Cavalier /* XXX may be shorter */
1446753c7e08SAugustin Cavalier if (len < 10) {
1447753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1448753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1449753c7e08SAugustin Cavalier wh, "RSN", "too short, len %u", len);
1450753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1451753c7e08SAugustin Cavalier }
1452753c7e08SAugustin Cavalier frm += 2;
1453753c7e08SAugustin Cavalier w = le16dec(frm);
1454753c7e08SAugustin Cavalier if (w != RSN_VERSION) {
1455753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1456753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1457753c7e08SAugustin Cavalier wh, "RSN", "bad version %u", w);
14588244a9baSAugustin Cavalier return IEEE80211_REASON_UNSUPP_RSN_IE_VERSION;
1459753c7e08SAugustin Cavalier }
1460753c7e08SAugustin Cavalier frm += 2, len -= 2;
1461753c7e08SAugustin Cavalier
1462753c7e08SAugustin Cavalier memset(rsn, 0, sizeof(*rsn));
1463753c7e08SAugustin Cavalier
1464753c7e08SAugustin Cavalier /* multicast/group cipher */
14658244a9baSAugustin Cavalier error = rsn_cipher(frm, &rsn->rsn_mcastkeylen, &rsn->rsn_mcastcipher);
14668244a9baSAugustin Cavalier if (error != 0) {
14678244a9baSAugustin Cavalier IEEE80211_DISCARD_IE(vap,
14688244a9baSAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
14698244a9baSAugustin Cavalier wh, "RSN", "unknown mcast cipher suite %08X",
14708244a9baSAugustin Cavalier le32dec(frm));
14718244a9baSAugustin Cavalier return IEEE80211_REASON_GROUP_CIPHER_INVALID;
14728244a9baSAugustin Cavalier }
14738244a9baSAugustin Cavalier if (rsn->rsn_mcastcipher == IEEE80211_CIPHER_NONE) {
14748244a9baSAugustin Cavalier IEEE80211_DISCARD_IE(vap,
14758244a9baSAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
14768244a9baSAugustin Cavalier wh, "RSN", "invalid mcast cipher suite %d",
14778244a9baSAugustin Cavalier rsn->rsn_mcastcipher);
14788244a9baSAugustin Cavalier return IEEE80211_REASON_GROUP_CIPHER_INVALID;
14798244a9baSAugustin Cavalier }
1480753c7e08SAugustin Cavalier frm += 4, len -= 4;
1481753c7e08SAugustin Cavalier
1482753c7e08SAugustin Cavalier /* unicast ciphers */
1483753c7e08SAugustin Cavalier n = le16dec(frm);
1484753c7e08SAugustin Cavalier frm += 2, len -= 2;
1485753c7e08SAugustin Cavalier if (len < n*4+2) {
1486753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1487753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1488753c7e08SAugustin Cavalier wh, "RSN", "ucast cipher data too short; len %u, n %u",
1489753c7e08SAugustin Cavalier len, n);
1490753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1491753c7e08SAugustin Cavalier }
1492753c7e08SAugustin Cavalier w = 0;
14938244a9baSAugustin Cavalier
1494753c7e08SAugustin Cavalier for (; n > 0; n--) {
14958244a9baSAugustin Cavalier uint8_t cipher;
14968244a9baSAugustin Cavalier
14978244a9baSAugustin Cavalier error = rsn_cipher(frm, &rsn->rsn_ucastkeylen, &cipher);
14988244a9baSAugustin Cavalier if (error == 0)
14998244a9baSAugustin Cavalier w |= 1 << cipher;
15008244a9baSAugustin Cavalier
1501753c7e08SAugustin Cavalier frm += 4, len -= 4;
1502753c7e08SAugustin Cavalier }
15038244a9baSAugustin Cavalier if (w & (1 << IEEE80211_CIPHER_AES_CCM))
1504753c7e08SAugustin Cavalier rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_CCM;
15058244a9baSAugustin Cavalier else if (w & (1 << IEEE80211_CIPHER_AES_OCB))
15068244a9baSAugustin Cavalier rsn->rsn_ucastcipher = IEEE80211_CIPHER_AES_OCB;
15078244a9baSAugustin Cavalier else if (w & (1 << IEEE80211_CIPHER_TKIP))
15088244a9baSAugustin Cavalier rsn->rsn_ucastcipher = IEEE80211_CIPHER_TKIP;
15098244a9baSAugustin Cavalier else if ((w & (1 << IEEE80211_CIPHER_NONE)) &&
15108244a9baSAugustin Cavalier (rsn->rsn_mcastcipher == IEEE80211_CIPHER_WEP ||
15118244a9baSAugustin Cavalier rsn->rsn_mcastcipher == IEEE80211_CIPHER_TKIP))
15128244a9baSAugustin Cavalier rsn->rsn_ucastcipher = IEEE80211_CIPHER_NONE;
15138244a9baSAugustin Cavalier else {
15148244a9baSAugustin Cavalier IEEE80211_DISCARD_IE(vap,
15158244a9baSAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
15168244a9baSAugustin Cavalier wh, "RSN", "no usable pairwise cipher suite found (w=%d)",
15178244a9baSAugustin Cavalier w);
15188244a9baSAugustin Cavalier return IEEE80211_REASON_PAIRWISE_CIPHER_INVALID;
15198244a9baSAugustin Cavalier }
1520753c7e08SAugustin Cavalier
1521753c7e08SAugustin Cavalier /* key management algorithms */
1522753c7e08SAugustin Cavalier n = le16dec(frm);
1523753c7e08SAugustin Cavalier frm += 2, len -= 2;
1524753c7e08SAugustin Cavalier if (len < n*4) {
1525753c7e08SAugustin Cavalier IEEE80211_DISCARD_IE(vap,
1526753c7e08SAugustin Cavalier IEEE80211_MSG_ELEMID | IEEE80211_MSG_WPA,
1527753c7e08SAugustin Cavalier wh, "RSN", "key mgmt alg data too short; len %u, n %u",
1528753c7e08SAugustin Cavalier len, n);
1529753c7e08SAugustin Cavalier return IEEE80211_REASON_IE_INVALID;
1530753c7e08SAugustin Cavalier }
1531753c7e08SAugustin Cavalier w = 0;
1532753c7e08SAugustin Cavalier for (; n > 0; n--) {
1533753c7e08SAugustin Cavalier w |= rsn_keymgmt(frm);
1534753c7e08SAugustin Cavalier frm += 4, len -= 4;
1535753c7e08SAugustin Cavalier }
1536753c7e08SAugustin Cavalier if (w & RSN_ASE_8021X_UNSPEC)
1537753c7e08SAugustin Cavalier rsn->rsn_keymgmt = RSN_ASE_8021X_UNSPEC;
1538753c7e08SAugustin Cavalier else
1539753c7e08SAugustin Cavalier rsn->rsn_keymgmt = RSN_ASE_8021X_PSK;
1540753c7e08SAugustin Cavalier
1541753c7e08SAugustin Cavalier /* optional RSN capabilities */
1542*da3ca318SAugustin Cavalier if (len >= 2) {
1543753c7e08SAugustin Cavalier rsn->rsn_caps = le16dec(frm);
1544*da3ca318SAugustin Cavalier frm += 2, len -= 2;
1545*da3ca318SAugustin Cavalier }
1546*da3ca318SAugustin Cavalier
1547*da3ca318SAugustin Cavalier /* XXX PMK Count / PMKID */
1548*da3ca318SAugustin Cavalier
1549*da3ca318SAugustin Cavalier /* XXX Group Cipher Management Suite */
1550753c7e08SAugustin Cavalier
1551753c7e08SAugustin Cavalier return 0;
1552753c7e08SAugustin Cavalier }
1553753c7e08SAugustin Cavalier
1554753c7e08SAugustin Cavalier /*
1555753c7e08SAugustin Cavalier * WPA/802.11i association request processing.
1556753c7e08SAugustin Cavalier */
1557753c7e08SAugustin Cavalier static int
wpa_assocreq(struct ieee80211_node * ni,struct ieee80211_rsnparms * rsnparms,const struct ieee80211_frame * wh,const uint8_t * wpa,const uint8_t * rsn,uint16_t capinfo)1558753c7e08SAugustin Cavalier wpa_assocreq(struct ieee80211_node *ni, struct ieee80211_rsnparms *rsnparms,
1559753c7e08SAugustin Cavalier const struct ieee80211_frame *wh, const uint8_t *wpa,
1560753c7e08SAugustin Cavalier const uint8_t *rsn, uint16_t capinfo)
1561753c7e08SAugustin Cavalier {
1562753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
1563753c7e08SAugustin Cavalier uint8_t reason;
1564753c7e08SAugustin Cavalier int badwparsn;
1565753c7e08SAugustin Cavalier
1566753c7e08SAugustin Cavalier ni->ni_flags &= ~(IEEE80211_NODE_WPS|IEEE80211_NODE_TSN);
1567753c7e08SAugustin Cavalier if (wpa == NULL && rsn == NULL) {
1568753c7e08SAugustin Cavalier if (vap->iv_flags_ext & IEEE80211_FEXT_WPS) {
1569753c7e08SAugustin Cavalier /*
1570753c7e08SAugustin Cavalier * W-Fi Protected Setup (WPS) permits
1571753c7e08SAugustin Cavalier * clients to associate and pass EAPOL frames
1572753c7e08SAugustin Cavalier * to establish initial credentials.
1573753c7e08SAugustin Cavalier */
1574753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_WPS;
1575753c7e08SAugustin Cavalier return 1;
1576753c7e08SAugustin Cavalier }
1577753c7e08SAugustin Cavalier if ((vap->iv_flags_ext & IEEE80211_FEXT_TSN) &&
1578753c7e08SAugustin Cavalier (capinfo & IEEE80211_CAPINFO_PRIVACY)) {
1579753c7e08SAugustin Cavalier /*
1580753c7e08SAugustin Cavalier * Transitional Security Network. Permits clients
1581753c7e08SAugustin Cavalier * to associate and use WEP while WPA is configured.
1582753c7e08SAugustin Cavalier */
1583753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_TSN;
1584753c7e08SAugustin Cavalier return 1;
1585753c7e08SAugustin Cavalier }
1586753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA,
1587753c7e08SAugustin Cavalier wh, NULL, "%s", "no WPA/RSN IE in association request");
1588753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_badwpaie++;
1589753c7e08SAugustin Cavalier reason = IEEE80211_REASON_IE_INVALID;
1590753c7e08SAugustin Cavalier goto bad;
1591753c7e08SAugustin Cavalier }
1592753c7e08SAugustin Cavalier /* assert right association security credentials */
1593753c7e08SAugustin Cavalier badwparsn = 0; /* NB: to silence compiler */
1594753c7e08SAugustin Cavalier switch (vap->iv_flags & IEEE80211_F_WPA) {
1595753c7e08SAugustin Cavalier case IEEE80211_F_WPA1:
1596753c7e08SAugustin Cavalier badwparsn = (wpa == NULL);
1597753c7e08SAugustin Cavalier break;
1598753c7e08SAugustin Cavalier case IEEE80211_F_WPA2:
1599753c7e08SAugustin Cavalier badwparsn = (rsn == NULL);
1600753c7e08SAugustin Cavalier break;
1601753c7e08SAugustin Cavalier case IEEE80211_F_WPA1|IEEE80211_F_WPA2:
1602753c7e08SAugustin Cavalier badwparsn = (wpa == NULL && rsn == NULL);
1603753c7e08SAugustin Cavalier break;
1604753c7e08SAugustin Cavalier }
1605753c7e08SAugustin Cavalier if (badwparsn) {
1606753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA,
1607753c7e08SAugustin Cavalier wh, NULL,
1608753c7e08SAugustin Cavalier "%s", "missing WPA/RSN IE in association request");
1609753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_badwpaie++;
1610753c7e08SAugustin Cavalier reason = IEEE80211_REASON_IE_INVALID;
1611753c7e08SAugustin Cavalier goto bad;
1612753c7e08SAugustin Cavalier }
1613753c7e08SAugustin Cavalier /*
1614753c7e08SAugustin Cavalier * Parse WPA/RSN information element.
1615753c7e08SAugustin Cavalier */
1616753c7e08SAugustin Cavalier if (wpa != NULL)
1617753c7e08SAugustin Cavalier reason = ieee80211_parse_wpa(vap, wpa, rsnparms, wh);
1618753c7e08SAugustin Cavalier else
1619753c7e08SAugustin Cavalier reason = ieee80211_parse_rsn(vap, rsn, rsnparms, wh);
1620753c7e08SAugustin Cavalier if (reason != 0) {
16218244a9baSAugustin Cavalier /* XXX wpa->rsn fallback? */
1622753c7e08SAugustin Cavalier /* XXX distinguish WPA/RSN? */
1623753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_badwpaie++;
1624753c7e08SAugustin Cavalier goto bad;
1625753c7e08SAugustin Cavalier }
1626753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC | IEEE80211_MSG_WPA, ni,
1627753c7e08SAugustin Cavalier "%s ie: mc %u/%u uc %u/%u key %u caps 0x%x",
1628753c7e08SAugustin Cavalier wpa != NULL ? "WPA" : "RSN",
1629753c7e08SAugustin Cavalier rsnparms->rsn_mcastcipher, rsnparms->rsn_mcastkeylen,
1630753c7e08SAugustin Cavalier rsnparms->rsn_ucastcipher, rsnparms->rsn_ucastkeylen,
1631753c7e08SAugustin Cavalier rsnparms->rsn_keymgmt, rsnparms->rsn_caps);
1632753c7e08SAugustin Cavalier
1633753c7e08SAugustin Cavalier return 1;
1634753c7e08SAugustin Cavalier bad:
1635753c7e08SAugustin Cavalier ieee80211_node_deauth(ni, reason);
1636753c7e08SAugustin Cavalier return 0;
1637753c7e08SAugustin Cavalier }
1638753c7e08SAugustin Cavalier
1639753c7e08SAugustin Cavalier /* XXX find a better place for definition */
1640753c7e08SAugustin Cavalier struct l2_update_frame {
1641753c7e08SAugustin Cavalier struct ether_header eh;
1642753c7e08SAugustin Cavalier uint8_t dsap;
1643753c7e08SAugustin Cavalier uint8_t ssap;
1644753c7e08SAugustin Cavalier uint8_t control;
1645753c7e08SAugustin Cavalier uint8_t xid[3];
1646753c7e08SAugustin Cavalier } __packed;
1647753c7e08SAugustin Cavalier
1648753c7e08SAugustin Cavalier /*
1649753c7e08SAugustin Cavalier * Deliver a TGf L2UF frame on behalf of a station.
1650753c7e08SAugustin Cavalier * This primes any bridge when the station is roaming
1651753c7e08SAugustin Cavalier * between ap's on the same wired network.
1652753c7e08SAugustin Cavalier */
1653753c7e08SAugustin Cavalier static void
ieee80211_deliver_l2uf(struct ieee80211_node * ni)1654753c7e08SAugustin Cavalier ieee80211_deliver_l2uf(struct ieee80211_node *ni)
1655753c7e08SAugustin Cavalier {
1656753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
1657753c7e08SAugustin Cavalier struct ifnet *ifp = vap->iv_ifp;
1658753c7e08SAugustin Cavalier struct mbuf *m;
1659753c7e08SAugustin Cavalier struct l2_update_frame *l2uf;
1660753c7e08SAugustin Cavalier struct ether_header *eh;
1661753c7e08SAugustin Cavalier
166286021fd4SAugustin Cavalier m = m_gethdr(IEEE80211_M_NOWAIT, MT_DATA);
1663753c7e08SAugustin Cavalier if (m == NULL) {
1664753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
1665753c7e08SAugustin Cavalier "%s", "no mbuf for l2uf frame");
1666753c7e08SAugustin Cavalier vap->iv_stats.is_rx_nobuf++; /* XXX not right */
1667753c7e08SAugustin Cavalier return;
1668753c7e08SAugustin Cavalier }
1669753c7e08SAugustin Cavalier l2uf = mtod(m, struct l2_update_frame *);
1670753c7e08SAugustin Cavalier eh = &l2uf->eh;
1671753c7e08SAugustin Cavalier /* dst: Broadcast address */
1672753c7e08SAugustin Cavalier IEEE80211_ADDR_COPY(eh->ether_dhost, ifp->if_broadcastaddr);
1673753c7e08SAugustin Cavalier /* src: associated STA */
1674753c7e08SAugustin Cavalier IEEE80211_ADDR_COPY(eh->ether_shost, ni->ni_macaddr);
1675753c7e08SAugustin Cavalier eh->ether_type = htons(sizeof(*l2uf) - sizeof(*eh));
1676753c7e08SAugustin Cavalier
1677753c7e08SAugustin Cavalier l2uf->dsap = 0;
1678753c7e08SAugustin Cavalier l2uf->ssap = 0;
1679753c7e08SAugustin Cavalier l2uf->control = 0xf5;
1680753c7e08SAugustin Cavalier l2uf->xid[0] = 0x81;
1681753c7e08SAugustin Cavalier l2uf->xid[1] = 0x80;
1682753c7e08SAugustin Cavalier l2uf->xid[2] = 0x00;
1683753c7e08SAugustin Cavalier
1684753c7e08SAugustin Cavalier m->m_pkthdr.len = m->m_len = sizeof(*l2uf);
1685753c7e08SAugustin Cavalier hostap_deliver_data(vap, ni, m);
1686753c7e08SAugustin Cavalier }
1687753c7e08SAugustin Cavalier
1688753c7e08SAugustin Cavalier static void
ratesetmismatch(struct ieee80211_node * ni,const struct ieee80211_frame * wh,int reassoc,int resp,const char * tag,int rate)1689753c7e08SAugustin Cavalier ratesetmismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1690753c7e08SAugustin Cavalier int reassoc, int resp, const char *tag, int rate)
1691753c7e08SAugustin Cavalier {
1692753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(ni->ni_vap, IEEE80211_MSG_ANY, wh->i_addr2,
1693753c7e08SAugustin Cavalier "deny %s request, %s rate set mismatch, rate/MCS %d",
1694753c7e08SAugustin Cavalier reassoc ? "reassoc" : "assoc", tag, rate & IEEE80211_RATE_VAL);
1695753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_BASIC_RATE);
1696753c7e08SAugustin Cavalier ieee80211_node_leave(ni);
1697753c7e08SAugustin Cavalier }
1698753c7e08SAugustin Cavalier
1699753c7e08SAugustin Cavalier static void
capinfomismatch(struct ieee80211_node * ni,const struct ieee80211_frame * wh,int reassoc,int resp,const char * tag,int capinfo)1700753c7e08SAugustin Cavalier capinfomismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1701753c7e08SAugustin Cavalier int reassoc, int resp, const char *tag, int capinfo)
1702753c7e08SAugustin Cavalier {
1703753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
1704753c7e08SAugustin Cavalier
1705753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, wh->i_addr2,
1706753c7e08SAugustin Cavalier "deny %s request, %s mismatch 0x%x",
1707753c7e08SAugustin Cavalier reassoc ? "reassoc" : "assoc", tag, capinfo);
1708753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_CAPINFO);
1709753c7e08SAugustin Cavalier ieee80211_node_leave(ni);
1710753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_capmismatch++;
1711753c7e08SAugustin Cavalier }
1712753c7e08SAugustin Cavalier
1713753c7e08SAugustin Cavalier static void
htcapmismatch(struct ieee80211_node * ni,const struct ieee80211_frame * wh,int reassoc,int resp)1714753c7e08SAugustin Cavalier htcapmismatch(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1715753c7e08SAugustin Cavalier int reassoc, int resp)
1716753c7e08SAugustin Cavalier {
1717753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(ni->ni_vap, IEEE80211_MSG_ANY, wh->i_addr2,
1718753c7e08SAugustin Cavalier "deny %s request, %s missing HT ie", reassoc ? "reassoc" : "assoc");
1719753c7e08SAugustin Cavalier /* XXX no better code */
1720753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, resp, IEEE80211_STATUS_MISSING_HT_CAPS);
1721753c7e08SAugustin Cavalier ieee80211_node_leave(ni);
1722753c7e08SAugustin Cavalier }
1723753c7e08SAugustin Cavalier
1724753c7e08SAugustin Cavalier static void
authalgreject(struct ieee80211_node * ni,const struct ieee80211_frame * wh,int algo,int seq,int status)1725753c7e08SAugustin Cavalier authalgreject(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
1726753c7e08SAugustin Cavalier int algo, int seq, int status)
1727753c7e08SAugustin Cavalier {
1728753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
1729753c7e08SAugustin Cavalier
1730753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1731753c7e08SAugustin Cavalier wh, NULL, "unsupported alg %d", algo);
1732753c7e08SAugustin Cavalier vap->iv_stats.is_rx_auth_unsupported++;
1733753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2, IEEE80211_FC0_SUBTYPE_AUTH,
1734753c7e08SAugustin Cavalier seq | (status << 16));
1735753c7e08SAugustin Cavalier }
1736753c7e08SAugustin Cavalier
1737753c7e08SAugustin Cavalier static __inline int
ishtmixed(const uint8_t * ie)1738753c7e08SAugustin Cavalier ishtmixed(const uint8_t *ie)
1739753c7e08SAugustin Cavalier {
1740753c7e08SAugustin Cavalier const struct ieee80211_ie_htinfo *ht =
1741753c7e08SAugustin Cavalier (const struct ieee80211_ie_htinfo *) ie;
1742753c7e08SAugustin Cavalier return (ht->hi_byte2 & IEEE80211_HTINFO_OPMODE) ==
1743753c7e08SAugustin Cavalier IEEE80211_HTINFO_OPMODE_MIXED;
1744753c7e08SAugustin Cavalier }
1745753c7e08SAugustin Cavalier
1746753c7e08SAugustin Cavalier static int
is11bclient(const uint8_t * rates,const uint8_t * xrates)1747753c7e08SAugustin Cavalier is11bclient(const uint8_t *rates, const uint8_t *xrates)
1748753c7e08SAugustin Cavalier {
1749753c7e08SAugustin Cavalier static const uint32_t brates = (1<<2*1)|(1<<2*2)|(1<<11)|(1<<2*11);
1750753c7e08SAugustin Cavalier int i;
1751753c7e08SAugustin Cavalier
1752753c7e08SAugustin Cavalier /* NB: the 11b clients we care about will not have xrates */
1753753c7e08SAugustin Cavalier if (xrates != NULL || rates == NULL)
1754753c7e08SAugustin Cavalier return 0;
1755753c7e08SAugustin Cavalier for (i = 0; i < rates[1]; i++) {
1756753c7e08SAugustin Cavalier int r = rates[2+i] & IEEE80211_RATE_VAL;
1757753c7e08SAugustin Cavalier if (r > 2*11 || ((1<<r) & brates) == 0)
1758753c7e08SAugustin Cavalier return 0;
1759753c7e08SAugustin Cavalier }
1760753c7e08SAugustin Cavalier return 1;
1761753c7e08SAugustin Cavalier }
1762753c7e08SAugustin Cavalier
1763753c7e08SAugustin Cavalier static void
hostap_recv_mgmt(struct ieee80211_node * ni,struct mbuf * m0,int subtype,const struct ieee80211_rx_stats * rxs,int rssi,int nf)1764753c7e08SAugustin Cavalier hostap_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
1765753c7e08SAugustin Cavalier int subtype, const struct ieee80211_rx_stats *rxs, int rssi, int nf)
1766753c7e08SAugustin Cavalier {
1767753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
1768753c7e08SAugustin Cavalier struct ieee80211com *ic = ni->ni_ic;
1769753c7e08SAugustin Cavalier struct ieee80211_frame *wh;
1770753c7e08SAugustin Cavalier uint8_t *frm, *efrm, *sfrm;
1771753c7e08SAugustin Cavalier uint8_t *ssid, *rates, *xrates, *wpa, *rsn, *wme, *ath, *htcap;
17728244a9baSAugustin Cavalier uint8_t *vhtcap, *vhtinfo;
1773753c7e08SAugustin Cavalier int reassoc, resp;
1774753c7e08SAugustin Cavalier uint8_t rate;
1775753c7e08SAugustin Cavalier
1776753c7e08SAugustin Cavalier wh = mtod(m0, struct ieee80211_frame *);
1777753c7e08SAugustin Cavalier frm = (uint8_t *)&wh[1];
1778753c7e08SAugustin Cavalier efrm = mtod(m0, uint8_t *) + m0->m_len;
1779753c7e08SAugustin Cavalier switch (subtype) {
1780753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
1781753c7e08SAugustin Cavalier /*
1782753c7e08SAugustin Cavalier * We process beacon/probe response frames when scanning;
1783753c7e08SAugustin Cavalier * otherwise we check beacon frames for overlapping non-ERP
1784753c7e08SAugustin Cavalier * BSS in 11g and/or overlapping legacy BSS when in HT.
1785753c7e08SAugustin Cavalier */
1786753c7e08SAugustin Cavalier if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
1787753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
1788753c7e08SAugustin Cavalier return;
1789753c7e08SAugustin Cavalier }
1790753c7e08SAugustin Cavalier /* FALLTHROUGH */
1791753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_BEACON: {
1792753c7e08SAugustin Cavalier struct ieee80211_scanparams scan;
1793753c7e08SAugustin Cavalier
1794753c7e08SAugustin Cavalier /* NB: accept off-channel frames */
1795753c7e08SAugustin Cavalier /* XXX TODO: use rxstatus to determine off-channel details */
1796753c7e08SAugustin Cavalier if (ieee80211_parse_beacon(ni, m0, ic->ic_curchan, &scan) &~ IEEE80211_BPARSE_OFFCHAN)
1797753c7e08SAugustin Cavalier return;
1798753c7e08SAugustin Cavalier /*
1799753c7e08SAugustin Cavalier * Count frame now that we know it's to be processed.
1800753c7e08SAugustin Cavalier */
1801753c7e08SAugustin Cavalier if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) {
1802753c7e08SAugustin Cavalier vap->iv_stats.is_rx_beacon++; /* XXX remove */
1803753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_beacons);
1804753c7e08SAugustin Cavalier } else
1805753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_proberesp);
1806753c7e08SAugustin Cavalier /*
1807753c7e08SAugustin Cavalier * If scanning, just pass information to the scan module.
1808753c7e08SAugustin Cavalier */
1809753c7e08SAugustin Cavalier if (ic->ic_flags & IEEE80211_F_SCAN) {
1810753c7e08SAugustin Cavalier if (scan.status == 0 && /* NB: on channel */
1811753c7e08SAugustin Cavalier (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN)) {
1812753c7e08SAugustin Cavalier /*
1813753c7e08SAugustin Cavalier * Actively scanning a channel marked passive;
1814753c7e08SAugustin Cavalier * send a probe request now that we know there
1815753c7e08SAugustin Cavalier * is 802.11 traffic present.
1816753c7e08SAugustin Cavalier *
1817753c7e08SAugustin Cavalier * XXX check if the beacon we recv'd gives
1818753c7e08SAugustin Cavalier * us what we need and suppress the probe req
1819753c7e08SAugustin Cavalier */
1820*da3ca318SAugustin Cavalier ieee80211_probe_curchan(vap, true);
1821753c7e08SAugustin Cavalier ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN;
1822753c7e08SAugustin Cavalier }
1823753c7e08SAugustin Cavalier ieee80211_add_scan(vap, ic->ic_curchan, &scan, wh,
1824753c7e08SAugustin Cavalier subtype, rssi, nf);
1825753c7e08SAugustin Cavalier return;
1826753c7e08SAugustin Cavalier }
1827753c7e08SAugustin Cavalier /*
1828753c7e08SAugustin Cavalier * Check beacon for overlapping bss w/ non ERP stations.
1829753c7e08SAugustin Cavalier * If we detect one and protection is configured but not
1830753c7e08SAugustin Cavalier * enabled, enable it and start a timer that'll bring us
1831753c7e08SAugustin Cavalier * out if we stop seeing the bss.
1832753c7e08SAugustin Cavalier */
1833753c7e08SAugustin Cavalier if (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
1834753c7e08SAugustin Cavalier scan.status == 0 && /* NB: on-channel */
1835753c7e08SAugustin Cavalier ((scan.erp & 0x100) == 0 || /* NB: no ERP, 11b sta*/
1836753c7e08SAugustin Cavalier (scan.erp & IEEE80211_ERP_NON_ERP_PRESENT))) {
18375cad57c4SJérôme Duval vap->iv_lastnonerp = ticks;
18385cad57c4SJérôme Duval vap->iv_flags_ext |= IEEE80211_FEXT_NONERP_PR;
18395cad57c4SJérôme Duval /*
18405cad57c4SJérôme Duval * XXX TODO: this may need to check all VAPs?
18415cad57c4SJérôme Duval */
18425cad57c4SJérôme Duval if (vap->iv_protmode != IEEE80211_PROT_NONE &&
18435cad57c4SJérôme Duval (vap->iv_flags & IEEE80211_F_USEPROT) == 0) {
1844753c7e08SAugustin Cavalier IEEE80211_NOTE_FRAME(vap,
1845753c7e08SAugustin Cavalier IEEE80211_MSG_ASSOC, wh,
1846753c7e08SAugustin Cavalier "non-ERP present on channel %d "
1847753c7e08SAugustin Cavalier "(saw erp 0x%x from channel %d), "
1848753c7e08SAugustin Cavalier "enable use of protection",
1849753c7e08SAugustin Cavalier ic->ic_curchan->ic_ieee,
1850753c7e08SAugustin Cavalier scan.erp, scan.chan);
18515cad57c4SJérôme Duval vap->iv_flags |= IEEE80211_F_USEPROT;
18525cad57c4SJérôme Duval ieee80211_vap_update_erp_protmode(vap);
1853753c7e08SAugustin Cavalier }
1854753c7e08SAugustin Cavalier }
1855753c7e08SAugustin Cavalier /*
1856753c7e08SAugustin Cavalier * Check beacon for non-HT station on HT channel
1857753c7e08SAugustin Cavalier * and update HT BSS occupancy as appropriate.
1858753c7e08SAugustin Cavalier */
1859753c7e08SAugustin Cavalier if (IEEE80211_IS_CHAN_HT(ic->ic_curchan)) {
1860753c7e08SAugustin Cavalier if (scan.status & IEEE80211_BPARSE_OFFCHAN) {
1861753c7e08SAugustin Cavalier /*
1862753c7e08SAugustin Cavalier * Off control channel; only check frames
1863753c7e08SAugustin Cavalier * that come in the extension channel when
1864753c7e08SAugustin Cavalier * operating w/ HT40.
1865753c7e08SAugustin Cavalier */
1866753c7e08SAugustin Cavalier if (!IEEE80211_IS_CHAN_HT40(ic->ic_curchan))
1867753c7e08SAugustin Cavalier break;
1868753c7e08SAugustin Cavalier if (scan.chan != ic->ic_curchan->ic_extieee)
1869753c7e08SAugustin Cavalier break;
1870753c7e08SAugustin Cavalier }
1871753c7e08SAugustin Cavalier if (scan.htinfo == NULL) {
18725cad57c4SJérôme Duval ieee80211_htprot_update(vap,
1873753c7e08SAugustin Cavalier IEEE80211_HTINFO_OPMODE_PROTOPT |
1874753c7e08SAugustin Cavalier IEEE80211_HTINFO_NONHT_PRESENT);
1875753c7e08SAugustin Cavalier } else if (ishtmixed(scan.htinfo)) {
1876753c7e08SAugustin Cavalier /* XXX? take NONHT_PRESENT from beacon? */
18775cad57c4SJérôme Duval ieee80211_htprot_update(vap,
1878753c7e08SAugustin Cavalier IEEE80211_HTINFO_OPMODE_MIXED |
1879753c7e08SAugustin Cavalier IEEE80211_HTINFO_NONHT_PRESENT);
1880753c7e08SAugustin Cavalier }
1881753c7e08SAugustin Cavalier }
1882753c7e08SAugustin Cavalier break;
1883753c7e08SAugustin Cavalier }
1884753c7e08SAugustin Cavalier
1885753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
1886753c7e08SAugustin Cavalier if (vap->iv_state != IEEE80211_S_RUN) {
1887753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
1888753c7e08SAugustin Cavalier return;
1889753c7e08SAugustin Cavalier }
1890753c7e08SAugustin Cavalier /*
1891753c7e08SAugustin Cavalier * Consult the ACL policy module if setup.
1892753c7e08SAugustin Cavalier */
1893753c7e08SAugustin Cavalier if (vap->iv_acl != NULL && !vap->iv_acl->iac_check(vap, wh)) {
1894753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1895753c7e08SAugustin Cavalier wh, NULL, "%s", "disallowed by ACL");
1896753c7e08SAugustin Cavalier vap->iv_stats.is_rx_acl++;
1897753c7e08SAugustin Cavalier return;
1898753c7e08SAugustin Cavalier }
1899753c7e08SAugustin Cavalier /*
1900753c7e08SAugustin Cavalier * prreq frame format
1901753c7e08SAugustin Cavalier * [tlv] ssid
1902753c7e08SAugustin Cavalier * [tlv] supported rates
1903753c7e08SAugustin Cavalier * [tlv] extended supported rates
1904753c7e08SAugustin Cavalier */
1905753c7e08SAugustin Cavalier ssid = rates = xrates = NULL;
1906753c7e08SAugustin Cavalier while (efrm - frm > 1) {
1907753c7e08SAugustin Cavalier IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return);
1908753c7e08SAugustin Cavalier switch (*frm) {
1909753c7e08SAugustin Cavalier case IEEE80211_ELEMID_SSID:
1910753c7e08SAugustin Cavalier ssid = frm;
1911753c7e08SAugustin Cavalier break;
1912753c7e08SAugustin Cavalier case IEEE80211_ELEMID_RATES:
1913753c7e08SAugustin Cavalier rates = frm;
1914753c7e08SAugustin Cavalier break;
1915753c7e08SAugustin Cavalier case IEEE80211_ELEMID_XRATES:
1916753c7e08SAugustin Cavalier xrates = frm;
1917753c7e08SAugustin Cavalier break;
1918753c7e08SAugustin Cavalier }
1919753c7e08SAugustin Cavalier frm += frm[1] + 2;
1920753c7e08SAugustin Cavalier }
1921753c7e08SAugustin Cavalier IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return);
1922753c7e08SAugustin Cavalier if (xrates != NULL)
1923753c7e08SAugustin Cavalier IEEE80211_VERIFY_ELEMENT(xrates,
1924753c7e08SAugustin Cavalier IEEE80211_RATE_MAXSIZE - rates[1], return);
1925753c7e08SAugustin Cavalier IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return);
1926753c7e08SAugustin Cavalier IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return);
1927753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_HIDESSID) && ssid[1] == 0) {
1928753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
1929753c7e08SAugustin Cavalier wh, NULL,
1930753c7e08SAugustin Cavalier "%s", "no ssid with ssid suppression enabled");
1931753c7e08SAugustin Cavalier vap->iv_stats.is_rx_ssidmismatch++; /*XXX*/
1932753c7e08SAugustin Cavalier return;
1933753c7e08SAugustin Cavalier }
1934753c7e08SAugustin Cavalier
1935753c7e08SAugustin Cavalier /* XXX find a better class or define it's own */
1936753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2,
1937753c7e08SAugustin Cavalier "%s", "recv probe req");
1938753c7e08SAugustin Cavalier /*
1939753c7e08SAugustin Cavalier * Some legacy 11b clients cannot hack a complete
1940753c7e08SAugustin Cavalier * probe response frame. When the request includes
1941753c7e08SAugustin Cavalier * only a bare-bones rate set, communicate this to
1942753c7e08SAugustin Cavalier * the transmit side.
1943753c7e08SAugustin Cavalier */
1944753c7e08SAugustin Cavalier ieee80211_send_proberesp(vap, wh->i_addr2,
1945753c7e08SAugustin Cavalier is11bclient(rates, xrates) ? IEEE80211_SEND_LEGACY_11B : 0);
1946753c7e08SAugustin Cavalier break;
1947753c7e08SAugustin Cavalier
1948753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_AUTH: {
1949753c7e08SAugustin Cavalier uint16_t algo, seq, status;
1950753c7e08SAugustin Cavalier
1951753c7e08SAugustin Cavalier if (vap->iv_state != IEEE80211_S_RUN) {
1952753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
1953753c7e08SAugustin Cavalier return;
1954753c7e08SAugustin Cavalier }
1955753c7e08SAugustin Cavalier if (!IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_bss->ni_bssid)) {
1956753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
1957753c7e08SAugustin Cavalier wh, NULL, "%s", "wrong bssid");
1958753c7e08SAugustin Cavalier vap->iv_stats.is_rx_wrongbss++; /*XXX unique stat?*/
1959753c7e08SAugustin Cavalier return;
1960753c7e08SAugustin Cavalier }
1961753c7e08SAugustin Cavalier /*
1962753c7e08SAugustin Cavalier * auth frame format
1963753c7e08SAugustin Cavalier * [2] algorithm
1964753c7e08SAugustin Cavalier * [2] sequence
1965753c7e08SAugustin Cavalier * [2] status
1966753c7e08SAugustin Cavalier * [tlv*] challenge
1967753c7e08SAugustin Cavalier */
1968753c7e08SAugustin Cavalier IEEE80211_VERIFY_LENGTH(efrm - frm, 6, return);
1969753c7e08SAugustin Cavalier algo = le16toh(*(uint16_t *)frm);
1970753c7e08SAugustin Cavalier seq = le16toh(*(uint16_t *)(frm + 2));
1971753c7e08SAugustin Cavalier status = le16toh(*(uint16_t *)(frm + 4));
1972753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_AUTH, wh->i_addr2,
1973753c7e08SAugustin Cavalier "recv auth frame with algorithm %d seq %d", algo, seq);
1974753c7e08SAugustin Cavalier /*
1975753c7e08SAugustin Cavalier * Consult the ACL policy module if setup.
1976753c7e08SAugustin Cavalier */
1977753c7e08SAugustin Cavalier if (vap->iv_acl != NULL && !vap->iv_acl->iac_check(vap, wh)) {
1978753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ACL,
1979753c7e08SAugustin Cavalier wh, NULL, "%s", "disallowed by ACL");
1980753c7e08SAugustin Cavalier vap->iv_stats.is_rx_acl++;
1981753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2,
1982753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_AUTH,
1983753c7e08SAugustin Cavalier (seq+1) | (IEEE80211_STATUS_UNSPECIFIED<<16));
1984753c7e08SAugustin Cavalier return;
1985753c7e08SAugustin Cavalier }
1986753c7e08SAugustin Cavalier if (vap->iv_flags & IEEE80211_F_COUNTERM) {
1987753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap,
1988753c7e08SAugustin Cavalier IEEE80211_MSG_AUTH | IEEE80211_MSG_CRYPTO,
1989753c7e08SAugustin Cavalier wh, NULL, "%s", "TKIP countermeasures enabled");
1990753c7e08SAugustin Cavalier vap->iv_stats.is_rx_auth_countermeasures++;
1991753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2,
1992753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_AUTH,
1993753c7e08SAugustin Cavalier IEEE80211_REASON_MIC_FAILURE);
1994753c7e08SAugustin Cavalier return;
1995753c7e08SAugustin Cavalier }
1996753c7e08SAugustin Cavalier if (algo == IEEE80211_AUTH_ALG_SHARED)
1997753c7e08SAugustin Cavalier hostap_auth_shared(ni, wh, frm + 6, efrm, rssi, nf,
1998753c7e08SAugustin Cavalier seq, status);
1999753c7e08SAugustin Cavalier else if (algo == IEEE80211_AUTH_ALG_OPEN)
2000753c7e08SAugustin Cavalier hostap_auth_open(ni, wh, rssi, nf, seq, status);
2001753c7e08SAugustin Cavalier else if (algo == IEEE80211_AUTH_ALG_LEAP) {
2002753c7e08SAugustin Cavalier authalgreject(ni, wh, algo,
2003753c7e08SAugustin Cavalier seq+1, IEEE80211_STATUS_ALG);
2004753c7e08SAugustin Cavalier return;
2005753c7e08SAugustin Cavalier } else {
2006753c7e08SAugustin Cavalier /*
2007753c7e08SAugustin Cavalier * We assume that an unknown algorithm is the result
2008753c7e08SAugustin Cavalier * of a decryption failure on a shared key auth frame;
2009753c7e08SAugustin Cavalier * return a status code appropriate for that instead
2010753c7e08SAugustin Cavalier * of IEEE80211_STATUS_ALG.
2011753c7e08SAugustin Cavalier *
2012753c7e08SAugustin Cavalier * NB: a seq# of 4 is intentional; the decrypted
2013753c7e08SAugustin Cavalier * frame likely has a bogus seq value.
2014753c7e08SAugustin Cavalier */
2015753c7e08SAugustin Cavalier authalgreject(ni, wh, algo,
2016753c7e08SAugustin Cavalier 4, IEEE80211_STATUS_CHALLENGE);
2017753c7e08SAugustin Cavalier return;
2018753c7e08SAugustin Cavalier }
2019753c7e08SAugustin Cavalier break;
2020753c7e08SAugustin Cavalier }
2021753c7e08SAugustin Cavalier
2022753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
2023753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: {
2024753c7e08SAugustin Cavalier uint16_t capinfo, lintval;
2025753c7e08SAugustin Cavalier struct ieee80211_rsnparms rsnparms;
2026753c7e08SAugustin Cavalier
2027753c7e08SAugustin Cavalier if (vap->iv_state != IEEE80211_S_RUN) {
2028753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
2029753c7e08SAugustin Cavalier return;
2030753c7e08SAugustin Cavalier }
2031753c7e08SAugustin Cavalier if (!IEEE80211_ADDR_EQ(wh->i_addr3, vap->iv_bss->ni_bssid)) {
2032753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
2033753c7e08SAugustin Cavalier wh, NULL, "%s", "wrong bssid");
2034753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_bss++;
2035753c7e08SAugustin Cavalier return;
2036753c7e08SAugustin Cavalier }
2037753c7e08SAugustin Cavalier if (subtype == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) {
2038753c7e08SAugustin Cavalier reassoc = 1;
2039753c7e08SAugustin Cavalier resp = IEEE80211_FC0_SUBTYPE_REASSOC_RESP;
2040753c7e08SAugustin Cavalier } else {
2041753c7e08SAugustin Cavalier reassoc = 0;
2042753c7e08SAugustin Cavalier resp = IEEE80211_FC0_SUBTYPE_ASSOC_RESP;
2043753c7e08SAugustin Cavalier }
2044753c7e08SAugustin Cavalier if (ni == vap->iv_bss) {
2045753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, wh->i_addr2,
2046753c7e08SAugustin Cavalier "deny %s request, sta not authenticated",
2047753c7e08SAugustin Cavalier reassoc ? "reassoc" : "assoc");
2048753c7e08SAugustin Cavalier ieee80211_send_error(ni, wh->i_addr2,
2049753c7e08SAugustin Cavalier IEEE80211_FC0_SUBTYPE_DEAUTH,
2050753c7e08SAugustin Cavalier IEEE80211_REASON_ASSOC_NOT_AUTHED);
2051753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_notauth++;
2052753c7e08SAugustin Cavalier return;
2053753c7e08SAugustin Cavalier }
2054753c7e08SAugustin Cavalier
2055753c7e08SAugustin Cavalier /*
2056753c7e08SAugustin Cavalier * asreq frame format
2057753c7e08SAugustin Cavalier * [2] capability information
2058753c7e08SAugustin Cavalier * [2] listen interval
2059753c7e08SAugustin Cavalier * [6*] current AP address (reassoc only)
2060753c7e08SAugustin Cavalier * [tlv] ssid
2061753c7e08SAugustin Cavalier * [tlv] supported rates
2062753c7e08SAugustin Cavalier * [tlv] extended supported rates
2063753c7e08SAugustin Cavalier * [tlv] WPA or RSN
2064753c7e08SAugustin Cavalier * [tlv] HT capabilities
2065753c7e08SAugustin Cavalier * [tlv] Atheros capabilities
2066753c7e08SAugustin Cavalier */
2067753c7e08SAugustin Cavalier IEEE80211_VERIFY_LENGTH(efrm - frm, (reassoc ? 10 : 4), return);
2068753c7e08SAugustin Cavalier capinfo = le16toh(*(uint16_t *)frm); frm += 2;
2069753c7e08SAugustin Cavalier lintval = le16toh(*(uint16_t *)frm); frm += 2;
2070753c7e08SAugustin Cavalier if (reassoc)
2071753c7e08SAugustin Cavalier frm += 6; /* ignore current AP info */
2072753c7e08SAugustin Cavalier ssid = rates = xrates = wpa = rsn = wme = ath = htcap = NULL;
20738244a9baSAugustin Cavalier vhtcap = vhtinfo = NULL;
2074753c7e08SAugustin Cavalier sfrm = frm;
2075753c7e08SAugustin Cavalier while (efrm - frm > 1) {
2076753c7e08SAugustin Cavalier IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return);
2077753c7e08SAugustin Cavalier switch (*frm) {
2078753c7e08SAugustin Cavalier case IEEE80211_ELEMID_SSID:
2079753c7e08SAugustin Cavalier ssid = frm;
2080753c7e08SAugustin Cavalier break;
2081753c7e08SAugustin Cavalier case IEEE80211_ELEMID_RATES:
2082753c7e08SAugustin Cavalier rates = frm;
2083753c7e08SAugustin Cavalier break;
2084753c7e08SAugustin Cavalier case IEEE80211_ELEMID_XRATES:
2085753c7e08SAugustin Cavalier xrates = frm;
2086753c7e08SAugustin Cavalier break;
2087753c7e08SAugustin Cavalier case IEEE80211_ELEMID_RSN:
2088753c7e08SAugustin Cavalier rsn = frm;
2089753c7e08SAugustin Cavalier break;
2090753c7e08SAugustin Cavalier case IEEE80211_ELEMID_HTCAP:
2091753c7e08SAugustin Cavalier htcap = frm;
2092753c7e08SAugustin Cavalier break;
20938244a9baSAugustin Cavalier case IEEE80211_ELEMID_VHT_CAP:
20948244a9baSAugustin Cavalier vhtcap = frm;
20958244a9baSAugustin Cavalier break;
20968244a9baSAugustin Cavalier case IEEE80211_ELEMID_VHT_OPMODE:
20978244a9baSAugustin Cavalier vhtinfo = frm;
20988244a9baSAugustin Cavalier break;
2099753c7e08SAugustin Cavalier case IEEE80211_ELEMID_VENDOR:
2100753c7e08SAugustin Cavalier if (iswpaoui(frm))
2101753c7e08SAugustin Cavalier wpa = frm;
2102753c7e08SAugustin Cavalier else if (iswmeinfo(frm))
2103753c7e08SAugustin Cavalier wme = frm;
2104753c7e08SAugustin Cavalier #ifdef IEEE80211_SUPPORT_SUPERG
2105753c7e08SAugustin Cavalier else if (isatherosoui(frm))
2106753c7e08SAugustin Cavalier ath = frm;
2107753c7e08SAugustin Cavalier #endif
2108753c7e08SAugustin Cavalier else if (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) {
2109753c7e08SAugustin Cavalier if (ishtcapoui(frm) && htcap == NULL)
2110753c7e08SAugustin Cavalier htcap = frm;
2111753c7e08SAugustin Cavalier }
2112753c7e08SAugustin Cavalier break;
2113753c7e08SAugustin Cavalier }
2114753c7e08SAugustin Cavalier frm += frm[1] + 2;
2115753c7e08SAugustin Cavalier }
2116753c7e08SAugustin Cavalier IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return);
2117753c7e08SAugustin Cavalier if (xrates != NULL)
2118753c7e08SAugustin Cavalier IEEE80211_VERIFY_ELEMENT(xrates,
2119753c7e08SAugustin Cavalier IEEE80211_RATE_MAXSIZE - rates[1], return);
2120753c7e08SAugustin Cavalier IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return);
2121753c7e08SAugustin Cavalier IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return);
2122753c7e08SAugustin Cavalier if (htcap != NULL) {
2123753c7e08SAugustin Cavalier IEEE80211_VERIFY_LENGTH(htcap[1],
2124753c7e08SAugustin Cavalier htcap[0] == IEEE80211_ELEMID_VENDOR ?
2125753c7e08SAugustin Cavalier 4 + sizeof(struct ieee80211_ie_htcap)-2 :
2126753c7e08SAugustin Cavalier sizeof(struct ieee80211_ie_htcap)-2,
2127753c7e08SAugustin Cavalier return); /* XXX just NULL out? */
2128753c7e08SAugustin Cavalier }
2129753c7e08SAugustin Cavalier
21308244a9baSAugustin Cavalier /* Validate VHT IEs */
21318244a9baSAugustin Cavalier if (vhtcap != NULL) {
21328244a9baSAugustin Cavalier IEEE80211_VERIFY_LENGTH(vhtcap[1],
213386021fd4SAugustin Cavalier sizeof(struct ieee80211_vht_cap),
21348244a9baSAugustin Cavalier return);
21358244a9baSAugustin Cavalier }
21368244a9baSAugustin Cavalier if (vhtinfo != NULL) {
21378244a9baSAugustin Cavalier IEEE80211_VERIFY_LENGTH(vhtinfo[1],
213886021fd4SAugustin Cavalier sizeof(struct ieee80211_vht_operation),
21398244a9baSAugustin Cavalier return);
21408244a9baSAugustin Cavalier }
21418244a9baSAugustin Cavalier
2142753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_WPA) &&
2143753c7e08SAugustin Cavalier !wpa_assocreq(ni, &rsnparms, wh, wpa, rsn, capinfo))
2144753c7e08SAugustin Cavalier return;
2145753c7e08SAugustin Cavalier /* discard challenge after association */
2146753c7e08SAugustin Cavalier if (ni->ni_challenge != NULL) {
2147753c7e08SAugustin Cavalier IEEE80211_FREE(ni->ni_challenge, M_80211_NODE);
2148753c7e08SAugustin Cavalier ni->ni_challenge = NULL;
2149753c7e08SAugustin Cavalier }
2150753c7e08SAugustin Cavalier /* NB: 802.11 spec says to ignore station's privacy bit */
2151753c7e08SAugustin Cavalier if ((capinfo & IEEE80211_CAPINFO_ESS) == 0) {
2152753c7e08SAugustin Cavalier capinfomismatch(ni, wh, reassoc, resp,
2153753c7e08SAugustin Cavalier "capability", capinfo);
2154753c7e08SAugustin Cavalier return;
2155753c7e08SAugustin Cavalier }
2156753c7e08SAugustin Cavalier /*
2157753c7e08SAugustin Cavalier * Disallow re-associate w/ invalid slot time setting.
2158753c7e08SAugustin Cavalier */
2159753c7e08SAugustin Cavalier if (ni->ni_associd != 0 &&
2160753c7e08SAugustin Cavalier IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan) &&
2161753c7e08SAugustin Cavalier ((ni->ni_capinfo ^ capinfo) & IEEE80211_CAPINFO_SHORT_SLOTTIME)) {
2162753c7e08SAugustin Cavalier capinfomismatch(ni, wh, reassoc, resp,
2163753c7e08SAugustin Cavalier "slot time", capinfo);
2164753c7e08SAugustin Cavalier return;
2165753c7e08SAugustin Cavalier }
2166753c7e08SAugustin Cavalier rate = ieee80211_setup_rates(ni, rates, xrates,
2167753c7e08SAugustin Cavalier IEEE80211_F_DOSORT | IEEE80211_F_DOFRATE |
2168753c7e08SAugustin Cavalier IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
2169753c7e08SAugustin Cavalier if (rate & IEEE80211_RATE_BASIC) {
2170753c7e08SAugustin Cavalier ratesetmismatch(ni, wh, reassoc, resp, "legacy", rate);
2171753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_norate++;
2172753c7e08SAugustin Cavalier return;
2173753c7e08SAugustin Cavalier }
2174753c7e08SAugustin Cavalier /*
2175753c7e08SAugustin Cavalier * If constrained to 11g-only stations reject an
2176753c7e08SAugustin Cavalier * 11b-only station. We cheat a bit here by looking
2177753c7e08SAugustin Cavalier * at the max negotiated xmit rate and assuming anyone
2178753c7e08SAugustin Cavalier * with a best rate <24Mb/s is an 11b station.
2179753c7e08SAugustin Cavalier */
2180753c7e08SAugustin Cavalier if ((vap->iv_flags & IEEE80211_F_PUREG) && rate < 48) {
2181753c7e08SAugustin Cavalier ratesetmismatch(ni, wh, reassoc, resp, "11g", rate);
2182753c7e08SAugustin Cavalier vap->iv_stats.is_rx_assoc_norate++;
2183753c7e08SAugustin Cavalier return;
2184753c7e08SAugustin Cavalier }
21858244a9baSAugustin Cavalier
2186753c7e08SAugustin Cavalier /*
2187753c7e08SAugustin Cavalier * Do HT rate set handling and setup HT node state.
2188753c7e08SAugustin Cavalier */
2189753c7e08SAugustin Cavalier ni->ni_chan = vap->iv_bss->ni_chan;
21908244a9baSAugustin Cavalier
21918244a9baSAugustin Cavalier /* VHT */
21928244a9baSAugustin Cavalier if (IEEE80211_IS_CHAN_VHT(ni->ni_chan) &&
21938244a9baSAugustin Cavalier vhtcap != NULL &&
21948244a9baSAugustin Cavalier vhtinfo != NULL) {
21958244a9baSAugustin Cavalier /* XXX TODO; see below */
21968244a9baSAugustin Cavalier printf("%s: VHT TODO!\n", __func__);
21978244a9baSAugustin Cavalier ieee80211_vht_node_init(ni);
21988244a9baSAugustin Cavalier ieee80211_vht_update_cap(ni, vhtcap, vhtinfo);
21998244a9baSAugustin Cavalier } else if (ni->ni_flags & IEEE80211_NODE_VHT)
22008244a9baSAugustin Cavalier ieee80211_vht_node_cleanup(ni);
22018244a9baSAugustin Cavalier
22028244a9baSAugustin Cavalier /* HT */
2203753c7e08SAugustin Cavalier if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) {
2204753c7e08SAugustin Cavalier rate = ieee80211_setup_htrates(ni, htcap,
2205753c7e08SAugustin Cavalier IEEE80211_F_DOFMCS | IEEE80211_F_DONEGO |
2206753c7e08SAugustin Cavalier IEEE80211_F_DOBRS);
2207753c7e08SAugustin Cavalier if (rate & IEEE80211_RATE_BASIC) {
2208753c7e08SAugustin Cavalier ratesetmismatch(ni, wh, reassoc, resp,
2209753c7e08SAugustin Cavalier "HT", rate);
2210753c7e08SAugustin Cavalier vap->iv_stats.is_ht_assoc_norate++;
2211753c7e08SAugustin Cavalier return;
2212753c7e08SAugustin Cavalier }
2213753c7e08SAugustin Cavalier ieee80211_ht_node_init(ni);
2214753c7e08SAugustin Cavalier ieee80211_ht_updatehtcap(ni, htcap);
2215753c7e08SAugustin Cavalier } else if (ni->ni_flags & IEEE80211_NODE_HT)
2216753c7e08SAugustin Cavalier ieee80211_ht_node_cleanup(ni);
22178244a9baSAugustin Cavalier
22188244a9baSAugustin Cavalier /* Finally - this will use HT/VHT info to change node channel */
22198244a9baSAugustin Cavalier if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && htcap != NULL) {
22208244a9baSAugustin Cavalier ieee80211_ht_updatehtcap_final(ni);
22218244a9baSAugustin Cavalier }
22228244a9baSAugustin Cavalier
2223753c7e08SAugustin Cavalier #ifdef IEEE80211_SUPPORT_SUPERG
2224753c7e08SAugustin Cavalier /* Always do ff node cleanup; for A-MSDU */
2225753c7e08SAugustin Cavalier ieee80211_ff_node_cleanup(ni);
2226753c7e08SAugustin Cavalier #endif
2227753c7e08SAugustin Cavalier /*
2228753c7e08SAugustin Cavalier * Allow AMPDU operation only with unencrypted traffic
2229753c7e08SAugustin Cavalier * or AES-CCM; the 11n spec only specifies these ciphers
2230753c7e08SAugustin Cavalier * so permitting any others is undefined and can lead
2231753c7e08SAugustin Cavalier * to interoperability problems.
2232753c7e08SAugustin Cavalier */
2233753c7e08SAugustin Cavalier if ((ni->ni_flags & IEEE80211_NODE_HT) &&
2234753c7e08SAugustin Cavalier (((vap->iv_flags & IEEE80211_F_WPA) &&
2235753c7e08SAugustin Cavalier rsnparms.rsn_ucastcipher != IEEE80211_CIPHER_AES_CCM) ||
2236753c7e08SAugustin Cavalier (vap->iv_flags & (IEEE80211_F_WPA|IEEE80211_F_PRIVACY)) == IEEE80211_F_PRIVACY)) {
2237753c7e08SAugustin Cavalier IEEE80211_NOTE(vap,
2238753c7e08SAugustin Cavalier IEEE80211_MSG_ASSOC | IEEE80211_MSG_11N, ni,
2239753c7e08SAugustin Cavalier "disallow HT use because WEP or TKIP requested, "
2240753c7e08SAugustin Cavalier "capinfo 0x%x ucastcipher %d", capinfo,
2241753c7e08SAugustin Cavalier rsnparms.rsn_ucastcipher);
2242753c7e08SAugustin Cavalier ieee80211_ht_node_cleanup(ni);
2243753c7e08SAugustin Cavalier #ifdef IEEE80211_SUPPORT_SUPERG
2244753c7e08SAugustin Cavalier /* Always do ff node cleanup; for A-MSDU */
2245753c7e08SAugustin Cavalier ieee80211_ff_node_cleanup(ni);
2246753c7e08SAugustin Cavalier #endif
2247753c7e08SAugustin Cavalier vap->iv_stats.is_ht_assoc_downgrade++;
2248753c7e08SAugustin Cavalier }
2249753c7e08SAugustin Cavalier /*
2250753c7e08SAugustin Cavalier * If constrained to 11n-only stations reject legacy stations.
2251753c7e08SAugustin Cavalier */
2252753c7e08SAugustin Cavalier if ((vap->iv_flags_ht & IEEE80211_FHT_PUREN) &&
2253753c7e08SAugustin Cavalier (ni->ni_flags & IEEE80211_NODE_HT) == 0) {
2254753c7e08SAugustin Cavalier htcapmismatch(ni, wh, reassoc, resp);
2255753c7e08SAugustin Cavalier vap->iv_stats.is_ht_assoc_nohtcap++;
2256753c7e08SAugustin Cavalier return;
2257753c7e08SAugustin Cavalier }
2258753c7e08SAugustin Cavalier IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi);
2259753c7e08SAugustin Cavalier ni->ni_noise = nf;
2260753c7e08SAugustin Cavalier ni->ni_intval = lintval;
2261753c7e08SAugustin Cavalier ni->ni_capinfo = capinfo;
2262753c7e08SAugustin Cavalier ni->ni_fhdwell = vap->iv_bss->ni_fhdwell;
2263753c7e08SAugustin Cavalier ni->ni_fhindex = vap->iv_bss->ni_fhindex;
2264753c7e08SAugustin Cavalier /*
2265753c7e08SAugustin Cavalier * Store the IEs.
2266753c7e08SAugustin Cavalier * XXX maybe better to just expand
2267753c7e08SAugustin Cavalier */
2268753c7e08SAugustin Cavalier if (ieee80211_ies_init(&ni->ni_ies, sfrm, efrm - sfrm)) {
2269753c7e08SAugustin Cavalier #define setie(_ie, _off) ieee80211_ies_setie(ni->ni_ies, _ie, _off)
2270753c7e08SAugustin Cavalier if (wpa != NULL)
2271753c7e08SAugustin Cavalier setie(wpa_ie, wpa - sfrm);
2272753c7e08SAugustin Cavalier if (rsn != NULL)
2273753c7e08SAugustin Cavalier setie(rsn_ie, rsn - sfrm);
2274753c7e08SAugustin Cavalier if (htcap != NULL)
2275753c7e08SAugustin Cavalier setie(htcap_ie, htcap - sfrm);
2276753c7e08SAugustin Cavalier if (wme != NULL) {
2277753c7e08SAugustin Cavalier setie(wme_ie, wme - sfrm);
2278753c7e08SAugustin Cavalier /*
2279753c7e08SAugustin Cavalier * Mark node as capable of QoS.
2280753c7e08SAugustin Cavalier */
2281753c7e08SAugustin Cavalier ni->ni_flags |= IEEE80211_NODE_QOS;
22825cad57c4SJérôme Duval if (ieee80211_parse_wmeie(wme, wh, ni) > 0) {
22835cad57c4SJérôme Duval if (ni->ni_uapsd != 0)
22845cad57c4SJérôme Duval ni->ni_flags |=
22855cad57c4SJérôme Duval IEEE80211_NODE_UAPSD;
22865cad57c4SJérôme Duval else
22875cad57c4SJérôme Duval ni->ni_flags &=
22885cad57c4SJérôme Duval ~IEEE80211_NODE_UAPSD;
22895cad57c4SJérôme Duval }
2290753c7e08SAugustin Cavalier } else
22915cad57c4SJérôme Duval ni->ni_flags &=
22925cad57c4SJérôme Duval ~(IEEE80211_NODE_QOS |
22935cad57c4SJérôme Duval IEEE80211_NODE_UAPSD);
2294753c7e08SAugustin Cavalier #ifdef IEEE80211_SUPPORT_SUPERG
2295753c7e08SAugustin Cavalier if (ath != NULL) {
2296753c7e08SAugustin Cavalier setie(ath_ie, ath - sfrm);
2297753c7e08SAugustin Cavalier /*
2298753c7e08SAugustin Cavalier * Parse ATH station parameters.
2299753c7e08SAugustin Cavalier */
2300753c7e08SAugustin Cavalier ieee80211_parse_ath(ni, ni->ni_ies.ath_ie);
2301753c7e08SAugustin Cavalier } else
2302753c7e08SAugustin Cavalier #endif
2303753c7e08SAugustin Cavalier ni->ni_ath_flags = 0;
2304753c7e08SAugustin Cavalier #undef setie
2305753c7e08SAugustin Cavalier } else {
2306753c7e08SAugustin Cavalier ni->ni_flags &= ~IEEE80211_NODE_QOS;
23075cad57c4SJérôme Duval ni->ni_flags &= ~IEEE80211_NODE_UAPSD;
2308753c7e08SAugustin Cavalier ni->ni_ath_flags = 0;
2309753c7e08SAugustin Cavalier }
2310753c7e08SAugustin Cavalier ieee80211_node_join(ni, resp);
2311753c7e08SAugustin Cavalier ieee80211_deliver_l2uf(ni);
2312753c7e08SAugustin Cavalier break;
2313753c7e08SAugustin Cavalier }
2314753c7e08SAugustin Cavalier
2315753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_DEAUTH:
2316753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_DISASSOC: {
231786021fd4SAugustin Cavalier #ifdef IEEE80211_DEBUG
2318753c7e08SAugustin Cavalier uint16_t reason;
231986021fd4SAugustin Cavalier #endif
2320753c7e08SAugustin Cavalier
2321753c7e08SAugustin Cavalier if (vap->iv_state != IEEE80211_S_RUN ||
2322753c7e08SAugustin Cavalier /* NB: can happen when in promiscuous mode */
2323753c7e08SAugustin Cavalier !IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr)) {
2324753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
2325753c7e08SAugustin Cavalier break;
2326753c7e08SAugustin Cavalier }
2327753c7e08SAugustin Cavalier /*
2328753c7e08SAugustin Cavalier * deauth/disassoc frame format
2329753c7e08SAugustin Cavalier * [2] reason
2330753c7e08SAugustin Cavalier */
2331753c7e08SAugustin Cavalier IEEE80211_VERIFY_LENGTH(efrm - frm, 2, return);
233286021fd4SAugustin Cavalier #ifdef IEEE80211_DEBUG
2333753c7e08SAugustin Cavalier reason = le16toh(*(uint16_t *)frm);
233486021fd4SAugustin Cavalier #endif
2335753c7e08SAugustin Cavalier if (subtype == IEEE80211_FC0_SUBTYPE_DEAUTH) {
2336753c7e08SAugustin Cavalier vap->iv_stats.is_rx_deauth++;
2337753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_deauth);
2338753c7e08SAugustin Cavalier } else {
2339753c7e08SAugustin Cavalier vap->iv_stats.is_rx_disassoc++;
2340753c7e08SAugustin Cavalier IEEE80211_NODE_STAT(ni, rx_disassoc);
2341753c7e08SAugustin Cavalier }
2342753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni,
2343753c7e08SAugustin Cavalier "recv %s (reason: %d (%s))",
2344753c7e08SAugustin Cavalier ieee80211_mgt_subtype_name(subtype),
2345753c7e08SAugustin Cavalier reason, ieee80211_reason_to_string(reason));
2346753c7e08SAugustin Cavalier if (ni != vap->iv_bss)
2347753c7e08SAugustin Cavalier ieee80211_node_leave(ni);
2348753c7e08SAugustin Cavalier break;
2349753c7e08SAugustin Cavalier }
2350753c7e08SAugustin Cavalier
2351753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_ACTION:
2352753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_ACTION_NOACK:
2353753c7e08SAugustin Cavalier if (ni == vap->iv_bss) {
2354753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
2355753c7e08SAugustin Cavalier wh, NULL, "%s", "unknown node");
2356753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
2357753c7e08SAugustin Cavalier } else if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1) &&
2358753c7e08SAugustin Cavalier !IEEE80211_IS_MULTICAST(wh->i_addr1)) {
2359753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
2360753c7e08SAugustin Cavalier wh, NULL, "%s", "not for us");
2361753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
2362753c7e08SAugustin Cavalier } else if (vap->iv_state != IEEE80211_S_RUN) {
2363753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
2364753c7e08SAugustin Cavalier wh, NULL, "wrong state %s",
2365753c7e08SAugustin Cavalier ieee80211_state_name[vap->iv_state]);
2366753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
2367753c7e08SAugustin Cavalier } else {
2368753c7e08SAugustin Cavalier if (ieee80211_parse_action(ni, m0) == 0)
2369753c7e08SAugustin Cavalier (void)ic->ic_recv_action(ni, wh, frm, efrm);
2370753c7e08SAugustin Cavalier }
2371753c7e08SAugustin Cavalier break;
2372753c7e08SAugustin Cavalier
2373753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2374753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2375753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_TIMING_ADV:
2376753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_ATIM:
2377753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
2378753c7e08SAugustin Cavalier wh, NULL, "%s", "not handled");
2379753c7e08SAugustin Cavalier vap->iv_stats.is_rx_mgtdiscard++;
2380753c7e08SAugustin Cavalier break;
2381753c7e08SAugustin Cavalier
2382753c7e08SAugustin Cavalier default:
2383753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
2384753c7e08SAugustin Cavalier wh, "mgt", "subtype 0x%x not handled", subtype);
2385753c7e08SAugustin Cavalier vap->iv_stats.is_rx_badsubtype++;
2386753c7e08SAugustin Cavalier break;
2387753c7e08SAugustin Cavalier }
2388753c7e08SAugustin Cavalier }
2389753c7e08SAugustin Cavalier
2390753c7e08SAugustin Cavalier static void
hostap_recv_ctl(struct ieee80211_node * ni,struct mbuf * m,int subtype)2391753c7e08SAugustin Cavalier hostap_recv_ctl(struct ieee80211_node *ni, struct mbuf *m, int subtype)
2392753c7e08SAugustin Cavalier {
2393753c7e08SAugustin Cavalier switch (subtype) {
2394753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_PS_POLL:
2395753c7e08SAugustin Cavalier ni->ni_vap->iv_recv_pspoll(ni, m);
2396753c7e08SAugustin Cavalier break;
2397753c7e08SAugustin Cavalier case IEEE80211_FC0_SUBTYPE_BAR:
2398753c7e08SAugustin Cavalier ieee80211_recv_bar(ni, m);
2399753c7e08SAugustin Cavalier break;
2400753c7e08SAugustin Cavalier }
2401753c7e08SAugustin Cavalier }
2402753c7e08SAugustin Cavalier
2403753c7e08SAugustin Cavalier /*
2404753c7e08SAugustin Cavalier * Process a received ps-poll frame.
2405753c7e08SAugustin Cavalier */
2406753c7e08SAugustin Cavalier void
ieee80211_recv_pspoll(struct ieee80211_node * ni,struct mbuf * m0)2407753c7e08SAugustin Cavalier ieee80211_recv_pspoll(struct ieee80211_node *ni, struct mbuf *m0)
2408753c7e08SAugustin Cavalier {
2409753c7e08SAugustin Cavalier struct ieee80211vap *vap = ni->ni_vap;
2410753c7e08SAugustin Cavalier struct ieee80211com *ic = vap->iv_ic;
2411753c7e08SAugustin Cavalier struct ieee80211_frame_min *wh;
2412753c7e08SAugustin Cavalier struct mbuf *m;
2413753c7e08SAugustin Cavalier uint16_t aid;
2414753c7e08SAugustin Cavalier int qlen;
2415753c7e08SAugustin Cavalier
2416753c7e08SAugustin Cavalier wh = mtod(m0, struct ieee80211_frame_min *);
2417753c7e08SAugustin Cavalier if (ni->ni_associd == 0) {
2418753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap,
2419753c7e08SAugustin Cavalier IEEE80211_MSG_POWER | IEEE80211_MSG_DEBUG,
2420753c7e08SAugustin Cavalier (struct ieee80211_frame *) wh, NULL,
2421753c7e08SAugustin Cavalier "%s", "unassociated station");
2422753c7e08SAugustin Cavalier vap->iv_stats.is_ps_unassoc++;
2423753c7e08SAugustin Cavalier IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH,
2424753c7e08SAugustin Cavalier IEEE80211_REASON_NOT_ASSOCED);
2425753c7e08SAugustin Cavalier return;
2426753c7e08SAugustin Cavalier }
2427753c7e08SAugustin Cavalier
2428753c7e08SAugustin Cavalier aid = le16toh(*(uint16_t *)wh->i_dur);
2429753c7e08SAugustin Cavalier if (aid != ni->ni_associd) {
2430753c7e08SAugustin Cavalier IEEE80211_DISCARD(vap,
2431753c7e08SAugustin Cavalier IEEE80211_MSG_POWER | IEEE80211_MSG_DEBUG,
2432753c7e08SAugustin Cavalier (struct ieee80211_frame *) wh, NULL,
2433753c7e08SAugustin Cavalier "aid mismatch: sta aid 0x%x poll aid 0x%x",
2434753c7e08SAugustin Cavalier ni->ni_associd, aid);
2435753c7e08SAugustin Cavalier vap->iv_stats.is_ps_badaid++;
2436753c7e08SAugustin Cavalier /*
2437753c7e08SAugustin Cavalier * NB: We used to deauth the station but it turns out
2438753c7e08SAugustin Cavalier * the Blackberry Curve 8230 (and perhaps other devices)
2439753c7e08SAugustin Cavalier * sometimes send the wrong AID when WME is negotiated.
2440753c7e08SAugustin Cavalier * Being more lenient here seems ok as we already check
2441753c7e08SAugustin Cavalier * the station is associated and we only return frames
2442753c7e08SAugustin Cavalier * queued for the station (i.e. we don't use the AID).
2443753c7e08SAugustin Cavalier */
2444753c7e08SAugustin Cavalier return;
2445753c7e08SAugustin Cavalier }
2446753c7e08SAugustin Cavalier
2447753c7e08SAugustin Cavalier /* Okay, take the first queued packet and put it out... */
2448753c7e08SAugustin Cavalier m = ieee80211_node_psq_dequeue(ni, &qlen);
2449753c7e08SAugustin Cavalier if (m == NULL) {
2450753c7e08SAugustin Cavalier IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_POWER, wh->i_addr2,
2451753c7e08SAugustin Cavalier "%s", "recv ps-poll, but queue empty");
2452753c7e08SAugustin Cavalier ieee80211_send_nulldata(ieee80211_ref_node(ni));
2453753c7e08SAugustin Cavalier vap->iv_stats.is_ps_qempty++; /* XXX node stat */
2454753c7e08SAugustin Cavalier if (vap->iv_set_tim != NULL)
2455753c7e08SAugustin Cavalier vap->iv_set_tim(ni, 0); /* just in case */
2456753c7e08SAugustin Cavalier return;
2457753c7e08SAugustin Cavalier }
2458753c7e08SAugustin Cavalier /*
2459753c7e08SAugustin Cavalier * If there are more packets, set the more packets bit
2460753c7e08SAugustin Cavalier * in the packet dispatched to the station; otherwise
2461753c7e08SAugustin Cavalier * turn off the TIM bit.
2462753c7e08SAugustin Cavalier */
2463753c7e08SAugustin Cavalier if (qlen != 0) {
2464753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
2465753c7e08SAugustin Cavalier "recv ps-poll, send packet, %u still queued", qlen);
2466753c7e08SAugustin Cavalier m->m_flags |= M_MORE_DATA;
2467753c7e08SAugustin Cavalier } else {
2468753c7e08SAugustin Cavalier IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
2469753c7e08SAugustin Cavalier "%s", "recv ps-poll, send packet, queue empty");
2470753c7e08SAugustin Cavalier if (vap->iv_set_tim != NULL)
2471753c7e08SAugustin Cavalier vap->iv_set_tim(ni, 0);
2472753c7e08SAugustin Cavalier }
2473753c7e08SAugustin Cavalier m->m_flags |= M_PWR_SAV; /* bypass PS handling */
2474753c7e08SAugustin Cavalier
2475753c7e08SAugustin Cavalier /*
2476753c7e08SAugustin Cavalier * Do the right thing; if it's an encap'ed frame then
2477753c7e08SAugustin Cavalier * call ieee80211_parent_xmitpkt() else
2478753c7e08SAugustin Cavalier * call ieee80211_vap_xmitpkt().
2479753c7e08SAugustin Cavalier */
2480753c7e08SAugustin Cavalier if (m->m_flags & M_ENCAP) {
2481753c7e08SAugustin Cavalier (void) ieee80211_parent_xmitpkt(ic, m);
2482753c7e08SAugustin Cavalier } else {
2483753c7e08SAugustin Cavalier (void) ieee80211_vap_xmitpkt(vap, m);
2484753c7e08SAugustin Cavalier }
2485753c7e08SAugustin Cavalier }
2486