ieee80211_netbsd.c revision 1.31.2.1 1 1.31.2.1 phil /*-
2 1.31.2.1 phil * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 1.31.2.1 phil *
4 1.31.2.1 phil * Copyright (c) 2003-2009 Sam Leffler, Errno Consulting
5 1.1 dyoung * All rights reserved.
6 1.1 dyoung *
7 1.1 dyoung * Redistribution and use in source and binary forms, with or without
8 1.1 dyoung * modification, are permitted provided that the following conditions
9 1.1 dyoung * are met:
10 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
11 1.1 dyoung * notice, this list of conditions and the following disclaimer.
12 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 dyoung * notice, this list of conditions and the following disclaimer in the
14 1.1 dyoung * documentation and/or other materials provided with the distribution.
15 1.1 dyoung *
16 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 dyoung * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 dyoung * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 dyoung * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 dyoung * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 dyoung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 dyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 dyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 dyoung * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 dyoung * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 dyoung */
27 1.1 dyoung
28 1.1 dyoung #include <sys/cdefs.h>
29 1.31.2.1 phil __FBSDID("$FreeBSD$");
30 1.1 dyoung
31 1.1 dyoung /*
32 1.31.2.1 phil * IEEE 802.11 support (FreeBSD-specific code)
33 1.1 dyoung */
34 1.31.2.1 phil #include "opt_wlan.h"
35 1.31.2.1 phil
36 1.1 dyoung #include <sys/param.h>
37 1.31.2.1 phil #include <sys/systm.h>
38 1.31.2.1 phil #include <sys/eventhandler.h>
39 1.1 dyoung #include <sys/kernel.h>
40 1.31.2.1 phil #include <sys/linker.h>
41 1.31.2.1 phil #include <sys/malloc.h>
42 1.31.2.1 phil #include <sys/mbuf.h>
43 1.31.2.1 phil #include <sys/module.h>
44 1.1 dyoung #include <sys/proc.h>
45 1.1 dyoung #include <sys/sysctl.h>
46 1.1 dyoung
47 1.1 dyoung #include <sys/socket.h>
48 1.1 dyoung
49 1.31.2.1 phil #include <net/bpf.h>
50 1.1 dyoung #include <net/if.h>
51 1.31.2.1 phil #include <net/if_var.h>
52 1.31.2.1 phil #include <net/if_dl.h>
53 1.31.2.1 phil #include <net/if_clone.h>
54 1.1 dyoung #include <net/if_media.h>
55 1.31.2.1 phil #include <net/if_types.h>
56 1.31.2.1 phil #include <net/ethernet.h>
57 1.1 dyoung #include <net/route.h>
58 1.31.2.1 phil #include <net/vnet.h>
59 1.1 dyoung
60 1.1 dyoung #include <net80211/ieee80211_var.h>
61 1.31.2.1 phil #include <net80211/ieee80211_input.h>
62 1.1 dyoung
63 1.31.2.1 phil SYSCTL_NODE(_net, OID_AUTO, wlan, CTLFLAG_RD, 0, "IEEE 80211 parameters");
64 1.26 pooka
65 1.1 dyoung #ifdef IEEE80211_DEBUG
66 1.31.2.1 phil static int ieee80211_debug = 0;
67 1.31.2.1 phil SYSCTL_INT(_net_wlan, OID_AUTO, debug, CTLFLAG_RW, &ieee80211_debug,
68 1.31.2.1 phil 0, "debugging printfs");
69 1.1 dyoung #endif
70 1.1 dyoung
71 1.31.2.1 phil static MALLOC_DEFINE(M_80211_COM, "80211com", "802.11 com state");
72 1.8 skrll
73 1.31.2.1 phil static const char wlanname[] = "wlan";
74 1.31.2.1 phil static struct if_clone *wlan_cloner;
75 1.8 skrll
76 1.12 yamt static int
77 1.31.2.1 phil wlan_clone_create(struct if_clone *ifc, int unit, caddr_t params)
78 1.8 skrll {
79 1.31.2.1 phil struct ieee80211_clone_params cp;
80 1.31.2.1 phil struct ieee80211vap *vap;
81 1.31.2.1 phil struct ieee80211com *ic;
82 1.31.2.1 phil int error;
83 1.8 skrll
84 1.31.2.1 phil error = copyin(params, &cp, sizeof(cp));
85 1.31.2.1 phil if (error)
86 1.31.2.1 phil return error;
87 1.31.2.1 phil ic = ieee80211_find_com(cp.icp_parent);
88 1.31.2.1 phil if (ic == NULL)
89 1.31.2.1 phil return ENXIO;
90 1.31.2.1 phil if (cp.icp_opmode >= IEEE80211_OPMODE_MAX) {
91 1.31.2.1 phil ic_printf(ic, "%s: invalid opmode %d\n", __func__,
92 1.31.2.1 phil cp.icp_opmode);
93 1.31.2.1 phil return EINVAL;
94 1.31.2.1 phil }
95 1.31.2.1 phil if ((ic->ic_caps & ieee80211_opcap[cp.icp_opmode]) == 0) {
96 1.31.2.1 phil ic_printf(ic, "%s mode not supported\n",
97 1.31.2.1 phil ieee80211_opmode_name[cp.icp_opmode]);
98 1.31.2.1 phil return EOPNOTSUPP;
99 1.31.2.1 phil }
100 1.31.2.1 phil if ((cp.icp_flags & IEEE80211_CLONE_TDMA) &&
101 1.31.2.1 phil #ifdef IEEE80211_SUPPORT_TDMA
102 1.31.2.1 phil (ic->ic_caps & IEEE80211_C_TDMA) == 0
103 1.31.2.1 phil #else
104 1.31.2.1 phil (1)
105 1.31.2.1 phil #endif
106 1.31.2.1 phil ) {
107 1.31.2.1 phil ic_printf(ic, "TDMA not supported\n");
108 1.31.2.1 phil return EOPNOTSUPP;
109 1.31.2.1 phil }
110 1.31.2.1 phil vap = ic->ic_vap_create(ic, wlanname, unit,
111 1.31.2.1 phil cp.icp_opmode, cp.icp_flags, cp.icp_bssid,
112 1.31.2.1 phil cp.icp_flags & IEEE80211_CLONE_MACADDR ?
113 1.31.2.1 phil cp.icp_macaddr : ic->ic_macaddr);
114 1.26 pooka
115 1.31.2.1 phil return (vap == NULL ? EIO : 0);
116 1.31.2.1 phil }
117 1.22 matt
118 1.31.2.1 phil static void
119 1.31.2.1 phil wlan_clone_destroy(struct ifnet *ifp)
120 1.31.2.1 phil {
121 1.31.2.1 phil struct ieee80211vap *vap = ifp->if_softc;
122 1.31.2.1 phil struct ieee80211com *ic = vap->iv_ic;
123 1.12 yamt
124 1.31.2.1 phil ic->ic_vap_delete(vap);
125 1.8 skrll }
126 1.8 skrll
127 1.10 thorpej void
128 1.31.2.1 phil ieee80211_vap_destroy(struct ieee80211vap *vap)
129 1.10 thorpej {
130 1.31.2.1 phil CURVNET_SET(vap->iv_ifp->if_vnet);
131 1.31.2.1 phil if_clone_destroyif(wlan_cloner, vap->iv_ifp);
132 1.31.2.1 phil CURVNET_RESTORE();
133 1.10 thorpej }
134 1.10 thorpej
135 1.31.2.1 phil int
136 1.31.2.1 phil ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS)
137 1.1 dyoung {
138 1.31.2.1 phil int msecs = ticks_to_msecs(*(int *)arg1);
139 1.2 dyoung int error, t;
140 1.30 maxv
141 1.31.2.1 phil error = sysctl_handle_int(oidp, &msecs, 0, req);
142 1.31.2.1 phil if (error || !req->newptr)
143 1.30 maxv return error;
144 1.31.2.1 phil t = msecs_to_ticks(msecs);
145 1.31.2.1 phil *(int *)arg1 = (t < 1) ? 1 : t;
146 1.30 maxv return 0;
147 1.1 dyoung }
148 1.1 dyoung
149 1.1 dyoung static int
150 1.31.2.1 phil ieee80211_sysctl_inact(SYSCTL_HANDLER_ARGS)
151 1.1 dyoung {
152 1.31.2.1 phil int inact = (*(int *)arg1) * IEEE80211_INACT_WAIT;
153 1.31.2.1 phil int error;
154 1.2 dyoung
155 1.31.2.1 phil error = sysctl_handle_int(oidp, &inact, 0, req);
156 1.31.2.1 phil if (error || !req->newptr)
157 1.31.2.1 phil return error;
158 1.31.2.1 phil *(int *)arg1 = inact / IEEE80211_INACT_WAIT;
159 1.31.2.1 phil return 0;
160 1.2 dyoung }
161 1.2 dyoung
162 1.31.2.1 phil static int
163 1.31.2.1 phil ieee80211_sysctl_parent(SYSCTL_HANDLER_ARGS)
164 1.2 dyoung {
165 1.31.2.1 phil struct ieee80211com *ic = arg1;
166 1.2 dyoung
167 1.31.2.1 phil return SYSCTL_OUT_STR(req, ic->ic_name);
168 1.1 dyoung }
169 1.1 dyoung
170 1.31.2.1 phil static int
171 1.31.2.1 phil ieee80211_sysctl_radar(SYSCTL_HANDLER_ARGS)
172 1.1 dyoung {
173 1.31.2.1 phil struct ieee80211com *ic = arg1;
174 1.31.2.1 phil int t = 0, error;
175 1.1 dyoung
176 1.31.2.1 phil error = sysctl_handle_int(oidp, &t, 0, req);
177 1.31.2.1 phil if (error || !req->newptr)
178 1.31.2.1 phil return error;
179 1.31.2.1 phil IEEE80211_LOCK(ic);
180 1.31.2.1 phil ieee80211_dfs_notify_radar(ic, ic->ic_curchan);
181 1.31.2.1 phil IEEE80211_UNLOCK(ic);
182 1.31.2.1 phil return 0;
183 1.2 dyoung }
184 1.2 dyoung
185 1.2 dyoung /*
186 1.31.2.1 phil * For now, just restart everything.
187 1.2 dyoung *
188 1.31.2.1 phil * Later on, it'd be nice to have a separate VAP restart to
189 1.31.2.1 phil * full-device restart.
190 1.30 maxv */
191 1.31.2.1 phil static int
192 1.31.2.1 phil ieee80211_sysctl_vap_restart(SYSCTL_HANDLER_ARGS)
193 1.2 dyoung {
194 1.31.2.1 phil struct ieee80211vap *vap = arg1;
195 1.31.2.1 phil int t = 0, error;
196 1.1 dyoung
197 1.31.2.1 phil error = sysctl_handle_int(oidp, &t, 0, req);
198 1.31.2.1 phil if (error || !req->newptr)
199 1.31.2.1 phil return error;
200 1.2 dyoung
201 1.31.2.1 phil ieee80211_restart_all(vap->iv_ic);
202 1.31.2.1 phil return 0;
203 1.2 dyoung }
204 1.2 dyoung
205 1.31.2.1 phil void
206 1.31.2.1 phil ieee80211_sysctl_attach(struct ieee80211com *ic)
207 1.31.2.1 phil {
208 1.2 dyoung }
209 1.2 dyoung
210 1.31.2.1 phil void
211 1.31.2.1 phil ieee80211_sysctl_detach(struct ieee80211com *ic)
212 1.2 dyoung {
213 1.2 dyoung }
214 1.2 dyoung
215 1.31.2.1 phil void
216 1.31.2.1 phil ieee80211_sysctl_vattach(struct ieee80211vap *vap)
217 1.2 dyoung {
218 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
219 1.31.2.1 phil struct sysctl_ctx_list *ctx;
220 1.31.2.1 phil struct sysctl_oid *oid;
221 1.31.2.1 phil char num[14]; /* sufficient for 32 bits */
222 1.31.2.1 phil
223 1.31.2.1 phil ctx = (struct sysctl_ctx_list *) IEEE80211_MALLOC(sizeof(struct sysctl_ctx_list),
224 1.31.2.1 phil M_DEVBUF, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
225 1.31.2.1 phil if (ctx == NULL) {
226 1.31.2.1 phil if_printf(ifp, "%s: cannot allocate sysctl context!\n",
227 1.31.2.1 phil __func__);
228 1.2 dyoung return;
229 1.31.2.1 phil }
230 1.31.2.1 phil sysctl_ctx_init(ctx);
231 1.31.2.1 phil snprintf(num, sizeof(num), "%u", ifp->if_dunit);
232 1.31.2.1 phil oid = SYSCTL_ADD_NODE(ctx, &SYSCTL_NODE_CHILDREN(_net, wlan),
233 1.31.2.1 phil OID_AUTO, num, CTLFLAG_RD, NULL, "");
234 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
235 1.31.2.1 phil "%parent", CTLTYPE_STRING | CTLFLAG_RD, vap->iv_ic, 0,
236 1.31.2.1 phil ieee80211_sysctl_parent, "A", "parent device");
237 1.31.2.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
238 1.31.2.1 phil "driver_caps", CTLFLAG_RW, &vap->iv_caps, 0,
239 1.31.2.1 phil "driver capabilities");
240 1.2 dyoung #ifdef IEEE80211_DEBUG
241 1.31.2.1 phil vap->iv_debug = ieee80211_debug;
242 1.31.2.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
243 1.31.2.1 phil "debug", CTLFLAG_RW, &vap->iv_debug, 0,
244 1.31.2.1 phil "control debugging printfs");
245 1.30 maxv #endif
246 1.31.2.1 phil SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
247 1.31.2.1 phil "bmiss_max", CTLFLAG_RW, &vap->iv_bmiss_max, 0,
248 1.31.2.1 phil "consecutive beacon misses before scanning");
249 1.31.2.1 phil /* XXX inherit from tunables */
250 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
251 1.31.2.1 phil "inact_run", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_run, 0,
252 1.31.2.1 phil ieee80211_sysctl_inact, "I",
253 1.31.2.1 phil "station inactivity timeout (sec)");
254 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
255 1.31.2.1 phil "inact_probe", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_probe, 0,
256 1.31.2.1 phil ieee80211_sysctl_inact, "I",
257 1.31.2.1 phil "station inactivity probe timeout (sec)");
258 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
259 1.31.2.1 phil "inact_auth", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_auth, 0,
260 1.31.2.1 phil ieee80211_sysctl_inact, "I",
261 1.31.2.1 phil "station authentication timeout (sec)");
262 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
263 1.31.2.1 phil "inact_init", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_init, 0,
264 1.31.2.1 phil ieee80211_sysctl_inact, "I",
265 1.31.2.1 phil "station initial state timeout (sec)");
266 1.31.2.1 phil if (vap->iv_htcaps & IEEE80211_HTC_HT) {
267 1.31.2.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
268 1.31.2.1 phil "ampdu_mintraffic_bk", CTLFLAG_RW,
269 1.31.2.1 phil &vap->iv_ampdu_mintraffic[WME_AC_BK], 0,
270 1.31.2.1 phil "BK traffic tx aggr threshold (pps)");
271 1.31.2.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
272 1.31.2.1 phil "ampdu_mintraffic_be", CTLFLAG_RW,
273 1.31.2.1 phil &vap->iv_ampdu_mintraffic[WME_AC_BE], 0,
274 1.31.2.1 phil "BE traffic tx aggr threshold (pps)");
275 1.31.2.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
276 1.31.2.1 phil "ampdu_mintraffic_vo", CTLFLAG_RW,
277 1.31.2.1 phil &vap->iv_ampdu_mintraffic[WME_AC_VO], 0,
278 1.31.2.1 phil "VO traffic tx aggr threshold (pps)");
279 1.31.2.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
280 1.31.2.1 phil "ampdu_mintraffic_vi", CTLFLAG_RW,
281 1.31.2.1 phil &vap->iv_ampdu_mintraffic[WME_AC_VI], 0,
282 1.31.2.1 phil "VI traffic tx aggr threshold (pps)");
283 1.31.2.1 phil }
284 1.31.2.1 phil
285 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
286 1.31.2.1 phil "force_restart", CTLTYPE_INT | CTLFLAG_RW, vap, 0,
287 1.31.2.1 phil ieee80211_sysctl_vap_restart, "I",
288 1.31.2.1 phil "force a VAP restart");
289 1.31.2.1 phil
290 1.31.2.1 phil if (vap->iv_caps & IEEE80211_C_DFS) {
291 1.31.2.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
292 1.31.2.1 phil "radar", CTLTYPE_INT | CTLFLAG_RW, vap->iv_ic, 0,
293 1.31.2.1 phil ieee80211_sysctl_radar, "I", "simulate radar event");
294 1.31.2.1 phil }
295 1.31.2.1 phil vap->iv_sysctl = ctx;
296 1.31.2.1 phil vap->iv_oid = oid;
297 1.31.2.1 phil }
298 1.2 dyoung
299 1.31.2.1 phil void
300 1.31.2.1 phil ieee80211_sysctl_vdetach(struct ieee80211vap *vap)
301 1.31.2.1 phil {
302 1.31.2.1 phil
303 1.31.2.1 phil if (vap->iv_sysctl != NULL) {
304 1.31.2.1 phil sysctl_ctx_free(vap->iv_sysctl);
305 1.31.2.1 phil IEEE80211_FREE(vap->iv_sysctl, M_DEVBUF);
306 1.31.2.1 phil vap->iv_sysctl = NULL;
307 1.31.2.1 phil }
308 1.1 dyoung }
309 1.1 dyoung
310 1.1 dyoung int
311 1.1 dyoung ieee80211_node_dectestref(struct ieee80211_node *ni)
312 1.1 dyoung {
313 1.31.2.1 phil /* XXX need equivalent of atomic_dec_and_test */
314 1.31.2.1 phil atomic_subtract_int(&ni->ni_refcnt, 1);
315 1.31.2.1 phil return atomic_cmpset_int(&ni->ni_refcnt, 0, 1);
316 1.2 dyoung }
317 1.2 dyoung
318 1.2 dyoung void
319 1.15 degroote ieee80211_drain_ifq(struct ifqueue *ifq)
320 1.15 degroote {
321 1.15 degroote struct ieee80211_node *ni;
322 1.15 degroote struct mbuf *m;
323 1.15 degroote
324 1.15 degroote for (;;) {
325 1.15 degroote IF_DEQUEUE(ifq, m);
326 1.15 degroote if (m == NULL)
327 1.15 degroote break;
328 1.15 degroote
329 1.31.2.1 phil ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
330 1.31.2.1 phil KASSERT(ni != NULL, ("frame w/o node"));
331 1.15 degroote ieee80211_free_node(ni);
332 1.31.2.1 phil m->m_pkthdr.rcvif = NULL;
333 1.15 degroote
334 1.15 degroote m_freem(m);
335 1.15 degroote }
336 1.15 degroote }
337 1.15 degroote
338 1.15 degroote void
339 1.31.2.1 phil ieee80211_flush_ifq(struct ifqueue *ifq, struct ieee80211vap *vap)
340 1.2 dyoung {
341 1.31.2.1 phil struct ieee80211_node *ni;
342 1.31.2.1 phil struct mbuf *m, **mprev;
343 1.2 dyoung
344 1.31.2.1 phil IF_LOCK(ifq);
345 1.31.2.1 phil mprev = &ifq->ifq_head;
346 1.31.2.1 phil while ((m = *mprev) != NULL) {
347 1.31.2.1 phil ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
348 1.31.2.1 phil if (ni != NULL && ni->ni_vap == vap) {
349 1.31.2.1 phil *mprev = m->m_nextpkt; /* remove from list */
350 1.31.2.1 phil ifq->ifq_len--;
351 1.2 dyoung
352 1.31.2.1 phil m_freem(m);
353 1.31.2.1 phil ieee80211_free_node(ni); /* reclaim ref */
354 1.31.2.1 phil } else
355 1.31.2.1 phil mprev = &m->m_nextpkt;
356 1.31.2.1 phil }
357 1.31.2.1 phil /* recalculate tail ptr */
358 1.31.2.1 phil m = ifq->ifq_head;
359 1.31.2.1 phil for (; m != NULL && m->m_nextpkt != NULL; m = m->m_nextpkt)
360 1.31.2.1 phil ;
361 1.31.2.1 phil ifq->ifq_tail = m;
362 1.31.2.1 phil IF_UNLOCK(ifq);
363 1.2 dyoung }
364 1.2 dyoung
365 1.1 dyoung /*
366 1.31.2.1 phil * As above, for mbufs allocated with m_gethdr/MGETHDR
367 1.31.2.1 phil * or initialized by M_COPY_PKTHDR.
368 1.31.2.1 phil */
369 1.31.2.1 phil #define MC_ALIGN(m, len) \
370 1.31.2.1 phil do { \
371 1.31.2.1 phil (m)->m_data += rounddown2(MCLBYTES - (len), sizeof(long)); \
372 1.31.2.1 phil } while (/* CONSTCOND */ 0)
373 1.31.2.1 phil
374 1.31.2.1 phil /*
375 1.1 dyoung * Allocate and setup a management frame of the specified
376 1.1 dyoung * size. We return the mbuf and a pointer to the start
377 1.1 dyoung * of the contiguous data area that's been reserved based
378 1.1 dyoung * on the packet length. The data area is forced to 32-bit
379 1.1 dyoung * alignment and the buffer length to a multiple of 4 bytes.
380 1.1 dyoung * This is done mainly so beacon frames (that require this)
381 1.1 dyoung * can use this interface too.
382 1.1 dyoung */
383 1.1 dyoung struct mbuf *
384 1.31.2.1 phil ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen)
385 1.1 dyoung {
386 1.1 dyoung struct mbuf *m;
387 1.1 dyoung u_int len;
388 1.1 dyoung
389 1.1 dyoung /*
390 1.1 dyoung * NB: we know the mbuf routines will align the data area
391 1.1 dyoung * so we don't need to do anything special.
392 1.1 dyoung */
393 1.31.2.1 phil len = roundup2(headroom + pktlen, 4);
394 1.31.2.1 phil KASSERT(len <= MCLBYTES, ("802.11 mgt frame too large: %u", len));
395 1.31.2.1 phil if (len < MINCLSIZE) {
396 1.31.2.1 phil m = m_gethdr(M_NOWAIT, MT_DATA);
397 1.1 dyoung /*
398 1.1 dyoung * Align the data in case additional headers are added.
399 1.1 dyoung * This should only happen when a WEP header is added
400 1.1 dyoung * which only happens for shared key authentication mgt
401 1.1 dyoung * frames which all fit in MHLEN.
402 1.1 dyoung */
403 1.1 dyoung if (m != NULL)
404 1.31.2.1 phil M_ALIGN(m, len);
405 1.30 maxv } else {
406 1.31.2.1 phil m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
407 1.31.2.1 phil if (m != NULL)
408 1.31.2.1 phil MC_ALIGN(m, len);
409 1.30 maxv }
410 1.1 dyoung if (m != NULL) {
411 1.31.2.1 phil m->m_data += headroom;
412 1.1 dyoung *frm = m->m_data;
413 1.1 dyoung }
414 1.1 dyoung return m;
415 1.1 dyoung }
416 1.1 dyoung
417 1.31.2.1 phil #ifndef __NO_STRICT_ALIGNMENT
418 1.31.2.1 phil /*
419 1.31.2.1 phil * Re-align the payload in the mbuf. This is mainly used (right now)
420 1.31.2.1 phil * to handle IP header alignment requirements on certain architectures.
421 1.31.2.1 phil */
422 1.31.2.1 phil struct mbuf *
423 1.31.2.1 phil ieee80211_realign(struct ieee80211vap *vap, struct mbuf *m, size_t align)
424 1.31.2.1 phil {
425 1.31.2.1 phil int pktlen, space;
426 1.31.2.1 phil struct mbuf *n;
427 1.31.2.1 phil
428 1.31.2.1 phil pktlen = m->m_pkthdr.len;
429 1.31.2.1 phil space = pktlen + align;
430 1.31.2.1 phil if (space < MINCLSIZE)
431 1.31.2.1 phil n = m_gethdr(M_NOWAIT, MT_DATA);
432 1.31.2.1 phil else {
433 1.31.2.1 phil n = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR,
434 1.31.2.1 phil space <= MCLBYTES ? MCLBYTES :
435 1.31.2.1 phil #if MJUMPAGESIZE != MCLBYTES
436 1.31.2.1 phil space <= MJUMPAGESIZE ? MJUMPAGESIZE :
437 1.31.2.1 phil #endif
438 1.31.2.1 phil space <= MJUM9BYTES ? MJUM9BYTES : MJUM16BYTES);
439 1.31.2.1 phil }
440 1.31.2.1 phil if (__predict_true(n != NULL)) {
441 1.31.2.1 phil m_move_pkthdr(n, m);
442 1.31.2.1 phil n->m_data = (caddr_t)(ALIGN(n->m_data + align) - align);
443 1.31.2.1 phil m_copydata(m, 0, pktlen, mtod(n, caddr_t));
444 1.31.2.1 phil n->m_len = pktlen;
445 1.31.2.1 phil } else {
446 1.31.2.1 phil IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
447 1.31.2.1 phil mtod(m, const struct ieee80211_frame *), NULL,
448 1.31.2.1 phil "%s", "no mbuf to realign");
449 1.31.2.1 phil vap->iv_stats.is_rx_badalign++;
450 1.31.2.1 phil }
451 1.31.2.1 phil m_freem(m);
452 1.31.2.1 phil return n;
453 1.31.2.1 phil }
454 1.31.2.1 phil #endif /* !__NO_STRICT_ALIGNMENT */
455 1.31.2.1 phil
456 1.31.2.1 phil int
457 1.31.2.1 phil ieee80211_add_callback(struct mbuf *m,
458 1.31.2.1 phil void (*func)(struct ieee80211_node *, void *, int), void *arg)
459 1.31.2.1 phil {
460 1.31.2.1 phil struct m_tag *mtag;
461 1.31.2.1 phil struct ieee80211_cb *cb;
462 1.31.2.1 phil
463 1.31.2.1 phil mtag = m_tag_alloc(MTAG_ABI_NET80211, NET80211_TAG_CALLBACK,
464 1.31.2.1 phil sizeof(struct ieee80211_cb), M_NOWAIT);
465 1.31.2.1 phil if (mtag == NULL)
466 1.31.2.1 phil return 0;
467 1.31.2.1 phil
468 1.31.2.1 phil cb = (struct ieee80211_cb *)(mtag+1);
469 1.31.2.1 phil cb->func = func;
470 1.31.2.1 phil cb->arg = arg;
471 1.31.2.1 phil m_tag_prepend(m, mtag);
472 1.31.2.1 phil m->m_flags |= M_TXCB;
473 1.31.2.1 phil return 1;
474 1.31.2.1 phil }
475 1.31.2.1 phil
476 1.31.2.1 phil int
477 1.31.2.1 phil ieee80211_add_xmit_params(struct mbuf *m,
478 1.31.2.1 phil const struct ieee80211_bpf_params *params)
479 1.31.2.1 phil {
480 1.31.2.1 phil struct m_tag *mtag;
481 1.31.2.1 phil struct ieee80211_tx_params *tx;
482 1.31.2.1 phil
483 1.31.2.1 phil mtag = m_tag_alloc(MTAG_ABI_NET80211, NET80211_TAG_XMIT_PARAMS,
484 1.31.2.1 phil sizeof(struct ieee80211_tx_params), M_NOWAIT);
485 1.31.2.1 phil if (mtag == NULL)
486 1.31.2.1 phil return (0);
487 1.31.2.1 phil
488 1.31.2.1 phil tx = (struct ieee80211_tx_params *)(mtag+1);
489 1.31.2.1 phil memcpy(&tx->params, params, sizeof(struct ieee80211_bpf_params));
490 1.31.2.1 phil m_tag_prepend(m, mtag);
491 1.31.2.1 phil return (1);
492 1.31.2.1 phil }
493 1.31.2.1 phil
494 1.31.2.1 phil int
495 1.31.2.1 phil ieee80211_get_xmit_params(struct mbuf *m,
496 1.31.2.1 phil struct ieee80211_bpf_params *params)
497 1.31.2.1 phil {
498 1.31.2.1 phil struct m_tag *mtag;
499 1.31.2.1 phil struct ieee80211_tx_params *tx;
500 1.31.2.1 phil
501 1.31.2.1 phil mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_XMIT_PARAMS,
502 1.31.2.1 phil NULL);
503 1.31.2.1 phil if (mtag == NULL)
504 1.31.2.1 phil return (-1);
505 1.31.2.1 phil tx = (struct ieee80211_tx_params *)(mtag + 1);
506 1.31.2.1 phil memcpy(params, &tx->params, sizeof(struct ieee80211_bpf_params));
507 1.31.2.1 phil return (0);
508 1.31.2.1 phil }
509 1.31.2.1 phil
510 1.1 dyoung void
511 1.31.2.1 phil ieee80211_process_callback(struct ieee80211_node *ni,
512 1.31.2.1 phil struct mbuf *m, int status)
513 1.31.2.1 phil {
514 1.31.2.1 phil struct m_tag *mtag;
515 1.31.2.1 phil
516 1.31.2.1 phil mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_CALLBACK, NULL);
517 1.31.2.1 phil if (mtag != NULL) {
518 1.31.2.1 phil struct ieee80211_cb *cb = (struct ieee80211_cb *)(mtag+1);
519 1.31.2.1 phil cb->func(ni, cb->arg, status);
520 1.31.2.1 phil }
521 1.31.2.1 phil }
522 1.31.2.1 phil
523 1.31.2.1 phil /*
524 1.31.2.1 phil * Add RX parameters to the given mbuf.
525 1.31.2.1 phil *
526 1.31.2.1 phil * Returns 1 if OK, 0 on error.
527 1.31.2.1 phil */
528 1.31.2.1 phil int
529 1.31.2.1 phil ieee80211_add_rx_params(struct mbuf *m, const struct ieee80211_rx_stats *rxs)
530 1.31.2.1 phil {
531 1.31.2.1 phil struct m_tag *mtag;
532 1.31.2.1 phil struct ieee80211_rx_params *rx;
533 1.31.2.1 phil
534 1.31.2.1 phil mtag = m_tag_alloc(MTAG_ABI_NET80211, NET80211_TAG_RECV_PARAMS,
535 1.31.2.1 phil sizeof(struct ieee80211_rx_stats), M_NOWAIT);
536 1.31.2.1 phil if (mtag == NULL)
537 1.31.2.1 phil return (0);
538 1.31.2.1 phil
539 1.31.2.1 phil rx = (struct ieee80211_rx_params *)(mtag + 1);
540 1.31.2.1 phil memcpy(&rx->params, rxs, sizeof(*rxs));
541 1.31.2.1 phil m_tag_prepend(m, mtag);
542 1.31.2.1 phil return (1);
543 1.31.2.1 phil }
544 1.31.2.1 phil
545 1.31.2.1 phil int
546 1.31.2.1 phil ieee80211_get_rx_params(struct mbuf *m, struct ieee80211_rx_stats *rxs)
547 1.31.2.1 phil {
548 1.31.2.1 phil struct m_tag *mtag;
549 1.31.2.1 phil struct ieee80211_rx_params *rx;
550 1.31.2.1 phil
551 1.31.2.1 phil mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_RECV_PARAMS,
552 1.31.2.1 phil NULL);
553 1.31.2.1 phil if (mtag == NULL)
554 1.31.2.1 phil return (-1);
555 1.31.2.1 phil rx = (struct ieee80211_rx_params *)(mtag + 1);
556 1.31.2.1 phil memcpy(rxs, &rx->params, sizeof(*rxs));
557 1.31.2.1 phil return (0);
558 1.31.2.1 phil }
559 1.31.2.1 phil
560 1.31.2.1 phil const struct ieee80211_rx_stats *
561 1.31.2.1 phil ieee80211_get_rx_params_ptr(struct mbuf *m)
562 1.31.2.1 phil {
563 1.31.2.1 phil struct m_tag *mtag;
564 1.31.2.1 phil struct ieee80211_rx_params *rx;
565 1.31.2.1 phil
566 1.31.2.1 phil mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_RECV_PARAMS,
567 1.31.2.1 phil NULL);
568 1.31.2.1 phil if (mtag == NULL)
569 1.31.2.1 phil return (NULL);
570 1.31.2.1 phil rx = (struct ieee80211_rx_params *)(mtag + 1);
571 1.31.2.1 phil return (&rx->params);
572 1.31.2.1 phil }
573 1.31.2.1 phil
574 1.31.2.1 phil
575 1.31.2.1 phil /*
576 1.31.2.1 phil * Add TOA parameters to the given mbuf.
577 1.31.2.1 phil */
578 1.31.2.1 phil int
579 1.31.2.1 phil ieee80211_add_toa_params(struct mbuf *m, const struct ieee80211_toa_params *p)
580 1.31.2.1 phil {
581 1.31.2.1 phil struct m_tag *mtag;
582 1.31.2.1 phil struct ieee80211_toa_params *rp;
583 1.31.2.1 phil
584 1.31.2.1 phil mtag = m_tag_alloc(MTAG_ABI_NET80211, NET80211_TAG_TOA_PARAMS,
585 1.31.2.1 phil sizeof(struct ieee80211_toa_params), M_NOWAIT);
586 1.31.2.1 phil if (mtag == NULL)
587 1.31.2.1 phil return (0);
588 1.31.2.1 phil
589 1.31.2.1 phil rp = (struct ieee80211_toa_params *)(mtag + 1);
590 1.31.2.1 phil memcpy(rp, p, sizeof(*rp));
591 1.31.2.1 phil m_tag_prepend(m, mtag);
592 1.31.2.1 phil return (1);
593 1.31.2.1 phil }
594 1.31.2.1 phil
595 1.31.2.1 phil int
596 1.31.2.1 phil ieee80211_get_toa_params(struct mbuf *m, struct ieee80211_toa_params *p)
597 1.31.2.1 phil {
598 1.31.2.1 phil struct m_tag *mtag;
599 1.31.2.1 phil struct ieee80211_toa_params *rp;
600 1.31.2.1 phil
601 1.31.2.1 phil mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_TOA_PARAMS,
602 1.31.2.1 phil NULL);
603 1.31.2.1 phil if (mtag == NULL)
604 1.31.2.1 phil return (0);
605 1.31.2.1 phil rp = (struct ieee80211_toa_params *)(mtag + 1);
606 1.31.2.1 phil if (p != NULL)
607 1.31.2.1 phil memcpy(p, rp, sizeof(*p));
608 1.31.2.1 phil return (1);
609 1.31.2.1 phil }
610 1.31.2.1 phil
611 1.31.2.1 phil /*
612 1.31.2.1 phil * Transmit a frame to the parent interface.
613 1.31.2.1 phil */
614 1.31.2.1 phil int
615 1.31.2.1 phil ieee80211_parent_xmitpkt(struct ieee80211com *ic, struct mbuf *m)
616 1.1 dyoung {
617 1.31.2.1 phil int error;
618 1.31.2.1 phil
619 1.31.2.1 phil /*
620 1.31.2.1 phil * Assert the IC TX lock is held - this enforces the
621 1.31.2.1 phil * processing -> queuing order is maintained
622 1.31.2.1 phil */
623 1.31.2.1 phil IEEE80211_TX_LOCK_ASSERT(ic);
624 1.31.2.1 phil error = ic->ic_transmit(ic, m);
625 1.31.2.1 phil if (error) {
626 1.31.2.1 phil struct ieee80211_node *ni;
627 1.31.2.1 phil
628 1.31.2.1 phil ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
629 1.31.2.1 phil
630 1.31.2.1 phil /* XXX number of fragments */
631 1.31.2.1 phil if_inc_counter(ni->ni_vap->iv_ifp, IFCOUNTER_OERRORS, 1);
632 1.31.2.1 phil ieee80211_free_node(ni);
633 1.31.2.1 phil ieee80211_free_mbuf(m);
634 1.31.2.1 phil }
635 1.31.2.1 phil return (error);
636 1.1 dyoung }
637 1.1 dyoung
638 1.31.2.1 phil /*
639 1.31.2.1 phil * Transmit a frame to the VAP interface.
640 1.31.2.1 phil */
641 1.31.2.1 phil int
642 1.31.2.1 phil ieee80211_vap_xmitpkt(struct ieee80211vap *vap, struct mbuf *m)
643 1.31.2.1 phil {
644 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
645 1.31.2.1 phil
646 1.31.2.1 phil /*
647 1.31.2.1 phil * When transmitting via the VAP, we shouldn't hold
648 1.31.2.1 phil * any IC TX lock as the VAP TX path will acquire it.
649 1.31.2.1 phil */
650 1.31.2.1 phil IEEE80211_TX_UNLOCK_ASSERT(vap->iv_ic);
651 1.31.2.1 phil
652 1.31.2.1 phil return (ifp->if_transmit(ifp, m));
653 1.31.2.1 phil
654 1.31.2.1 phil }
655 1.31.2.1 phil
656 1.31.2.1 phil #include <sys/libkern.h>
657 1.31.2.1 phil
658 1.1 dyoung void
659 1.31.2.1 phil get_random_bytes(void *p, size_t n)
660 1.1 dyoung {
661 1.31.2.1 phil uint8_t *dp = p;
662 1.1 dyoung
663 1.31.2.1 phil while (n > 0) {
664 1.31.2.1 phil uint32_t v = arc4random();
665 1.31.2.1 phil size_t nb = n > sizeof(uint32_t) ? sizeof(uint32_t) : n;
666 1.31.2.1 phil bcopy(&v, dp, n > sizeof(uint32_t) ? sizeof(uint32_t) : n);
667 1.31.2.1 phil dp += sizeof(uint32_t), n -= nb;
668 1.31.2.1 phil }
669 1.31.2.1 phil }
670 1.3 dyoung
671 1.31.2.1 phil /*
672 1.31.2.1 phil * Helper function for events that pass just a single mac address.
673 1.31.2.1 phil */
674 1.31.2.1 phil static void
675 1.31.2.1 phil notify_macaddr(struct ifnet *ifp, int op, const uint8_t mac[IEEE80211_ADDR_LEN])
676 1.31.2.1 phil {
677 1.31.2.1 phil struct ieee80211_join_event iev;
678 1.31.2.1 phil
679 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
680 1.7 dyoung memset(&iev, 0, sizeof(iev));
681 1.31.2.1 phil IEEE80211_ADDR_COPY(iev.iev_addr, mac);
682 1.31.2.1 phil rt_ieee80211msg(ifp, op, &iev, sizeof(iev));
683 1.31.2.1 phil CURVNET_RESTORE();
684 1.31.2.1 phil }
685 1.31.2.1 phil
686 1.31.2.1 phil void
687 1.31.2.1 phil ieee80211_notify_node_join(struct ieee80211_node *ni, int newassoc)
688 1.31.2.1 phil {
689 1.31.2.1 phil struct ieee80211vap *vap = ni->ni_vap;
690 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
691 1.31.2.1 phil
692 1.31.2.1 phil CURVNET_SET_QUIET(ifp->if_vnet);
693 1.31.2.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode join",
694 1.31.2.1 phil (ni == vap->iv_bss) ? "bss " : "");
695 1.31.2.1 phil
696 1.31.2.1 phil if (ni == vap->iv_bss) {
697 1.31.2.1 phil notify_macaddr(ifp, newassoc ?
698 1.31.2.1 phil RTM_IEEE80211_ASSOC : RTM_IEEE80211_REASSOC, ni->ni_bssid);
699 1.1 dyoung if_link_state_change(ifp, LINK_STATE_UP);
700 1.16 christos } else {
701 1.31.2.1 phil notify_macaddr(ifp, newassoc ?
702 1.31.2.1 phil RTM_IEEE80211_JOIN : RTM_IEEE80211_REJOIN, ni->ni_macaddr);
703 1.1 dyoung }
704 1.31.2.1 phil CURVNET_RESTORE();
705 1.1 dyoung }
706 1.1 dyoung
707 1.1 dyoung void
708 1.31.2.1 phil ieee80211_notify_node_leave(struct ieee80211_node *ni)
709 1.1 dyoung {
710 1.31.2.1 phil struct ieee80211vap *vap = ni->ni_vap;
711 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
712 1.1 dyoung
713 1.31.2.1 phil CURVNET_SET_QUIET(ifp->if_vnet);
714 1.31.2.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode leave",
715 1.31.2.1 phil (ni == vap->iv_bss) ? "bss " : "");
716 1.3 dyoung
717 1.31.2.1 phil if (ni == vap->iv_bss) {
718 1.1 dyoung rt_ieee80211msg(ifp, RTM_IEEE80211_DISASSOC, NULL, 0);
719 1.1 dyoung if_link_state_change(ifp, LINK_STATE_DOWN);
720 1.1 dyoung } else {
721 1.1 dyoung /* fire off wireless event station leaving */
722 1.31.2.1 phil notify_macaddr(ifp, RTM_IEEE80211_LEAVE, ni->ni_macaddr);
723 1.1 dyoung }
724 1.31.2.1 phil CURVNET_RESTORE();
725 1.1 dyoung }
726 1.1 dyoung
727 1.1 dyoung void
728 1.31.2.1 phil ieee80211_notify_scan_done(struct ieee80211vap *vap)
729 1.1 dyoung {
730 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
731 1.1 dyoung
732 1.31.2.1 phil IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s\n", "notify scan done");
733 1.1 dyoung
734 1.1 dyoung /* dispatch wireless event indicating scan completed */
735 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
736 1.1 dyoung rt_ieee80211msg(ifp, RTM_IEEE80211_SCAN, NULL, 0);
737 1.31.2.1 phil CURVNET_RESTORE();
738 1.1 dyoung }
739 1.1 dyoung
740 1.1 dyoung void
741 1.31.2.1 phil ieee80211_notify_replay_failure(struct ieee80211vap *vap,
742 1.1 dyoung const struct ieee80211_frame *wh, const struct ieee80211_key *k,
743 1.31.2.1 phil u_int64_t rsc, int tid)
744 1.1 dyoung {
745 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
746 1.1 dyoung
747 1.31.2.1 phil IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
748 1.31.2.1 phil "%s replay detected tid %d <rsc %ju, csc %ju, keyix %u rxkeyix %u>",
749 1.31.2.1 phil k->wk_cipher->ic_name, tid, (intmax_t) rsc,
750 1.31.2.1 phil (intmax_t) k->wk_keyrsc[tid],
751 1.8 skrll k->wk_keyix, k->wk_rxkeyix);
752 1.1 dyoung
753 1.1 dyoung if (ifp != NULL) { /* NB: for cipher test modules */
754 1.1 dyoung struct ieee80211_replay_event iev;
755 1.1 dyoung
756 1.1 dyoung IEEE80211_ADDR_COPY(iev.iev_dst, wh->i_addr1);
757 1.1 dyoung IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2);
758 1.1 dyoung iev.iev_cipher = k->wk_cipher->ic_cipher;
759 1.8 skrll if (k->wk_rxkeyix != IEEE80211_KEYIX_NONE)
760 1.8 skrll iev.iev_keyix = k->wk_rxkeyix;
761 1.8 skrll else
762 1.8 skrll iev.iev_keyix = k->wk_keyix;
763 1.31.2.1 phil iev.iev_keyrsc = k->wk_keyrsc[tid];
764 1.1 dyoung iev.iev_rsc = rsc;
765 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
766 1.1 dyoung rt_ieee80211msg(ifp, RTM_IEEE80211_REPLAY, &iev, sizeof(iev));
767 1.31.2.1 phil CURVNET_RESTORE();
768 1.1 dyoung }
769 1.1 dyoung }
770 1.1 dyoung
771 1.1 dyoung void
772 1.31.2.1 phil ieee80211_notify_michael_failure(struct ieee80211vap *vap,
773 1.1 dyoung const struct ieee80211_frame *wh, u_int keyix)
774 1.1 dyoung {
775 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
776 1.1 dyoung
777 1.31.2.1 phil IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
778 1.31.2.1 phil "michael MIC verification failed <keyix %u>", keyix);
779 1.31.2.1 phil vap->iv_stats.is_rx_tkipmic++;
780 1.1 dyoung
781 1.1 dyoung if (ifp != NULL) { /* NB: for cipher test modules */
782 1.1 dyoung struct ieee80211_michael_event iev;
783 1.1 dyoung
784 1.1 dyoung IEEE80211_ADDR_COPY(iev.iev_dst, wh->i_addr1);
785 1.1 dyoung IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2);
786 1.1 dyoung iev.iev_cipher = IEEE80211_CIPHER_TKIP;
787 1.1 dyoung iev.iev_keyix = keyix;
788 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
789 1.1 dyoung rt_ieee80211msg(ifp, RTM_IEEE80211_MICHAEL, &iev, sizeof(iev));
790 1.31.2.1 phil CURVNET_RESTORE();
791 1.1 dyoung }
792 1.1 dyoung }
793 1.1 dyoung
794 1.1 dyoung void
795 1.31.2.1 phil ieee80211_notify_wds_discover(struct ieee80211_node *ni)
796 1.1 dyoung {
797 1.31.2.1 phil struct ieee80211vap *vap = ni->ni_vap;
798 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
799 1.31.2.1 phil
800 1.31.2.1 phil notify_macaddr(ifp, RTM_IEEE80211_WDS, ni->ni_macaddr);
801 1.31.2.1 phil }
802 1.31.2.1 phil
803 1.31.2.1 phil void
804 1.31.2.1 phil ieee80211_notify_csa(struct ieee80211com *ic,
805 1.31.2.1 phil const struct ieee80211_channel *c, int mode, int count)
806 1.31.2.1 phil {
807 1.31.2.1 phil struct ieee80211_csa_event iev;
808 1.31.2.1 phil struct ieee80211vap *vap;
809 1.31.2.1 phil struct ifnet *ifp;
810 1.1 dyoung
811 1.31.2.1 phil memset(&iev, 0, sizeof(iev));
812 1.31.2.1 phil iev.iev_flags = c->ic_flags;
813 1.31.2.1 phil iev.iev_freq = c->ic_freq;
814 1.31.2.1 phil iev.iev_ieee = c->ic_ieee;
815 1.31.2.1 phil iev.iev_mode = mode;
816 1.31.2.1 phil iev.iev_count = count;
817 1.31.2.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
818 1.31.2.1 phil ifp = vap->iv_ifp;
819 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
820 1.31.2.1 phil rt_ieee80211msg(ifp, RTM_IEEE80211_CSA, &iev, sizeof(iev));
821 1.31.2.1 phil CURVNET_RESTORE();
822 1.31.2.1 phil }
823 1.31.2.1 phil }
824 1.31.2.1 phil
825 1.31.2.1 phil void
826 1.31.2.1 phil ieee80211_notify_radar(struct ieee80211com *ic,
827 1.31.2.1 phil const struct ieee80211_channel *c)
828 1.31.2.1 phil {
829 1.31.2.1 phil struct ieee80211_radar_event iev;
830 1.31.2.1 phil struct ieee80211vap *vap;
831 1.31.2.1 phil struct ifnet *ifp;
832 1.31.2.1 phil
833 1.31.2.1 phil memset(&iev, 0, sizeof(iev));
834 1.31.2.1 phil iev.iev_flags = c->ic_flags;
835 1.31.2.1 phil iev.iev_freq = c->ic_freq;
836 1.31.2.1 phil iev.iev_ieee = c->ic_ieee;
837 1.31.2.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
838 1.31.2.1 phil ifp = vap->iv_ifp;
839 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
840 1.31.2.1 phil rt_ieee80211msg(ifp, RTM_IEEE80211_RADAR, &iev, sizeof(iev));
841 1.31.2.1 phil CURVNET_RESTORE();
842 1.31.2.1 phil }
843 1.31.2.1 phil }
844 1.31.2.1 phil
845 1.31.2.1 phil void
846 1.31.2.1 phil ieee80211_notify_cac(struct ieee80211com *ic,
847 1.31.2.1 phil const struct ieee80211_channel *c, enum ieee80211_notify_cac_event type)
848 1.31.2.1 phil {
849 1.31.2.1 phil struct ieee80211_cac_event iev;
850 1.31.2.1 phil struct ieee80211vap *vap;
851 1.31.2.1 phil struct ifnet *ifp;
852 1.31.2.1 phil
853 1.31.2.1 phil memset(&iev, 0, sizeof(iev));
854 1.31.2.1 phil iev.iev_flags = c->ic_flags;
855 1.31.2.1 phil iev.iev_freq = c->ic_freq;
856 1.31.2.1 phil iev.iev_ieee = c->ic_ieee;
857 1.31.2.1 phil iev.iev_type = type;
858 1.31.2.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
859 1.31.2.1 phil ifp = vap->iv_ifp;
860 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
861 1.31.2.1 phil rt_ieee80211msg(ifp, RTM_IEEE80211_CAC, &iev, sizeof(iev));
862 1.31.2.1 phil CURVNET_RESTORE();
863 1.31.2.1 phil }
864 1.31.2.1 phil }
865 1.31.2.1 phil
866 1.31.2.1 phil void
867 1.31.2.1 phil ieee80211_notify_node_deauth(struct ieee80211_node *ni)
868 1.31.2.1 phil {
869 1.31.2.1 phil struct ieee80211vap *vap = ni->ni_vap;
870 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
871 1.31.2.1 phil
872 1.31.2.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%s", "node deauth");
873 1.31.2.1 phil
874 1.31.2.1 phil notify_macaddr(ifp, RTM_IEEE80211_DEAUTH, ni->ni_macaddr);
875 1.31.2.1 phil }
876 1.31.2.1 phil
877 1.31.2.1 phil void
878 1.31.2.1 phil ieee80211_notify_node_auth(struct ieee80211_node *ni)
879 1.31.2.1 phil {
880 1.31.2.1 phil struct ieee80211vap *vap = ni->ni_vap;
881 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
882 1.31.2.1 phil
883 1.31.2.1 phil IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%s", "node auth");
884 1.31.2.1 phil
885 1.31.2.1 phil notify_macaddr(ifp, RTM_IEEE80211_AUTH, ni->ni_macaddr);
886 1.31.2.1 phil }
887 1.31.2.1 phil
888 1.31.2.1 phil void
889 1.31.2.1 phil ieee80211_notify_country(struct ieee80211vap *vap,
890 1.31.2.1 phil const uint8_t bssid[IEEE80211_ADDR_LEN], const uint8_t cc[2])
891 1.31.2.1 phil {
892 1.31.2.1 phil struct ifnet *ifp = vap->iv_ifp;
893 1.31.2.1 phil struct ieee80211_country_event iev;
894 1.31.2.1 phil
895 1.31.2.1 phil memset(&iev, 0, sizeof(iev));
896 1.31.2.1 phil IEEE80211_ADDR_COPY(iev.iev_addr, bssid);
897 1.31.2.1 phil iev.iev_cc[0] = cc[0];
898 1.31.2.1 phil iev.iev_cc[1] = cc[1];
899 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
900 1.31.2.1 phil rt_ieee80211msg(ifp, RTM_IEEE80211_COUNTRY, &iev, sizeof(iev));
901 1.31.2.1 phil CURVNET_RESTORE();
902 1.31.2.1 phil }
903 1.31.2.1 phil
904 1.31.2.1 phil void
905 1.31.2.1 phil ieee80211_notify_radio(struct ieee80211com *ic, int state)
906 1.31.2.1 phil {
907 1.31.2.1 phil struct ieee80211_radio_event iev;
908 1.31.2.1 phil struct ieee80211vap *vap;
909 1.31.2.1 phil struct ifnet *ifp;
910 1.31.2.1 phil
911 1.31.2.1 phil memset(&iev, 0, sizeof(iev));
912 1.31.2.1 phil iev.iev_state = state;
913 1.31.2.1 phil TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
914 1.31.2.1 phil ifp = vap->iv_ifp;
915 1.31.2.1 phil CURVNET_SET(ifp->if_vnet);
916 1.31.2.1 phil rt_ieee80211msg(ifp, RTM_IEEE80211_RADIO, &iev, sizeof(iev));
917 1.31.2.1 phil CURVNET_RESTORE();
918 1.1 dyoung }
919 1.31.2.1 phil }
920 1.31.2.1 phil
921 1.31.2.1 phil void
922 1.31.2.1 phil ieee80211_load_module(const char *modname)
923 1.31.2.1 phil {
924 1.31.2.1 phil
925 1.31.2.1 phil #ifdef notyet
926 1.31.2.1 phil (void)kern_kldload(curthread, modname, NULL);
927 1.1 dyoung #else
928 1.1 dyoung printf("%s: load the %s module by hand for now.\n", __func__, modname);
929 1.1 dyoung #endif
930 1.1 dyoung }
931 1.31 maxv
932 1.31.2.1 phil static eventhandler_tag wlan_bpfevent;
933 1.31.2.1 phil static eventhandler_tag wlan_ifllevent;
934 1.31.2.1 phil
935 1.31.2.1 phil static void
936 1.31.2.1 phil bpf_track(void *arg, struct ifnet *ifp, int dlt, int attach)
937 1.31.2.1 phil {
938 1.31.2.1 phil /* NB: identify vap's by if_init */
939 1.31.2.1 phil if (dlt == DLT_IEEE802_11_RADIO &&
940 1.31.2.1 phil ifp->if_init == ieee80211_init) {
941 1.31.2.1 phil struct ieee80211vap *vap = ifp->if_softc;
942 1.31.2.1 phil /*
943 1.31.2.1 phil * Track bpf radiotap listener state. We mark the vap
944 1.31.2.1 phil * to indicate if any listener is present and the com
945 1.31.2.1 phil * to indicate if any listener exists on any associated
946 1.31.2.1 phil * vap. This flag is used by drivers to prepare radiotap
947 1.31.2.1 phil * state only when needed.
948 1.31.2.1 phil */
949 1.31.2.1 phil if (attach) {
950 1.31.2.1 phil ieee80211_syncflag_ext(vap, IEEE80211_FEXT_BPF);
951 1.31.2.1 phil if (vap->iv_opmode == IEEE80211_M_MONITOR)
952 1.31.2.1 phil atomic_add_int(&vap->iv_ic->ic_montaps, 1);
953 1.31.2.1 phil } else if (!bpf_peers_present(vap->iv_rawbpf)) {
954 1.31.2.1 phil ieee80211_syncflag_ext(vap, -IEEE80211_FEXT_BPF);
955 1.31.2.1 phil if (vap->iv_opmode == IEEE80211_M_MONITOR)
956 1.31.2.1 phil atomic_subtract_int(&vap->iv_ic->ic_montaps, 1);
957 1.31.2.1 phil }
958 1.31.2.1 phil }
959 1.31.2.1 phil }
960 1.31 maxv
961 1.31 maxv /*
962 1.31.2.1 phil * Change MAC address on the vap (if was not started).
963 1.31 maxv */
964 1.31.2.1 phil static void
965 1.31.2.1 phil wlan_iflladdr(void *arg __unused, struct ifnet *ifp)
966 1.31 maxv {
967 1.31.2.1 phil /* NB: identify vap's by if_init */
968 1.31.2.1 phil if (ifp->if_init == ieee80211_init &&
969 1.31.2.1 phil (ifp->if_flags & IFF_UP) == 0) {
970 1.31.2.1 phil struct ieee80211vap *vap = ifp->if_softc;
971 1.31 maxv
972 1.31.2.1 phil IEEE80211_ADDR_COPY(vap->iv_myaddr, IF_LLADDR(ifp));
973 1.31.2.1 phil }
974 1.31 maxv }
975 1.31 maxv
976 1.31 maxv /*
977 1.31.2.1 phil * Module glue.
978 1.31 maxv *
979 1.31.2.1 phil * NB: the module name is "wlan" for compatibility with NetBSD.
980 1.31 maxv */
981 1.31.2.1 phil static int
982 1.31.2.1 phil wlan_modevent(module_t mod, int type, void *unused)
983 1.31 maxv {
984 1.31.2.1 phil switch (type) {
985 1.31.2.1 phil case MOD_LOAD:
986 1.31.2.1 phil if (bootverbose)
987 1.31.2.1 phil printf("wlan: <802.11 Link Layer>\n");
988 1.31.2.1 phil wlan_bpfevent = EVENTHANDLER_REGISTER(bpf_track,
989 1.31.2.1 phil bpf_track, 0, EVENTHANDLER_PRI_ANY);
990 1.31.2.1 phil wlan_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event,
991 1.31.2.1 phil wlan_iflladdr, NULL, EVENTHANDLER_PRI_ANY);
992 1.31.2.1 phil wlan_cloner = if_clone_simple(wlanname, wlan_clone_create,
993 1.31.2.1 phil wlan_clone_destroy, 0);
994 1.31.2.1 phil return 0;
995 1.31.2.1 phil case MOD_UNLOAD:
996 1.31.2.1 phil if_clone_detach(wlan_cloner);
997 1.31.2.1 phil EVENTHANDLER_DEREGISTER(bpf_track, wlan_bpfevent);
998 1.31.2.1 phil EVENTHANDLER_DEREGISTER(iflladdr_event, wlan_ifllevent);
999 1.31.2.1 phil return 0;
1000 1.31 maxv }
1001 1.31.2.1 phil return EINVAL;
1002 1.31 maxv }
1003 1.31.2.1 phil
1004 1.31.2.1 phil static moduledata_t wlan_mod = {
1005 1.31.2.1 phil wlanname,
1006 1.31.2.1 phil wlan_modevent,
1007 1.31.2.1 phil 0
1008 1.31.2.1 phil };
1009 1.31.2.1 phil DECLARE_MODULE(wlan, wlan_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
1010 1.31.2.1 phil MODULE_VERSION(wlan, 1);
1011 1.31.2.1 phil MODULE_DEPEND(wlan, ether, 1, 1, 1);
1012 1.31.2.1 phil #ifdef IEEE80211_ALQ
1013 1.31.2.1 phil MODULE_DEPEND(wlan, alq, 1, 1, 1);
1014 1.31.2.1 phil #endif /* IEEE80211_ALQ */
1015 1.31.2.1 phil
1016