2 * Copyright (c) 2003-2009 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
30 * IEEE 802.11 support (FreeBSD-specific code)
34 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <sys/linker.h>
39 #include <sys/module.h>
41 #include <sys/sysctl.h>
43 #include <sys/socket.h>
44 #include <sys/vimage.h>
48 #include <net/if_dl.h>
49 #include <net/if_clone.h>
50 #include <net/if_media.h>
51 #include <net/if_types.h>
52 #include <net/ethernet.h>
53 #include <net/route.h>
55 #include <net80211/ieee80211_var.h>
57 SYSCTL_NODE(_net, OID_AUTO, wlan, CTLFLAG_RD, 0, "IEEE 80211 parameters");
59 #ifdef IEEE80211_DEBUG
60 int ieee80211_debug = 0;
61 SYSCTL_INT(_net_wlan, OID_AUTO, debug, CTLFLAG_RW, &ieee80211_debug,
62 0, "debugging printfs");
65 MALLOC_DEFINE(M_80211_COM, "80211com", "802.11 com state");
68 * Allocate/free com structure in conjunction with ifnet;
69 * these routines are registered with if_register_com_alloc
70 * below and are called automatically by the ifnet code
71 * when the ifnet of the parent device is created.
74 wlan_alloc(u_char type, struct ifnet *ifp)
76 struct ieee80211com *ic;
78 ic = malloc(sizeof(struct ieee80211com), M_80211_COM, M_WAITOK|M_ZERO);
85 wlan_free(void *ic, u_char type)
87 free(ic, M_80211_COM);
91 wlan_clone_create(struct if_clone *ifc, int unit, caddr_t params)
93 struct ieee80211_clone_params cp;
94 struct ieee80211vap *vap;
95 struct ieee80211com *ic;
99 error = copyin(params, &cp, sizeof(cp));
102 ifp = ifunit(cp.icp_parent);
105 /* XXX move printfs to DIAGNOSTIC before release */
106 if (ifp->if_type != IFT_IEEE80211) {
107 if_printf(ifp, "%s: reject, not an 802.11 device\n", __func__);
110 if (cp.icp_opmode >= IEEE80211_OPMODE_MAX) {
111 if_printf(ifp, "%s: invalid opmode %d\n",
112 __func__, cp.icp_opmode);
116 if ((ic->ic_caps & ieee80211_opcap[cp.icp_opmode]) == 0) {
117 if_printf(ifp, "%s mode not supported\n",
118 ieee80211_opmode_name[cp.icp_opmode]);
121 if ((cp.icp_flags & IEEE80211_CLONE_TDMA) &&
122 #ifdef IEEE80211_SUPPORT_TDMA
123 (ic->ic_caps & IEEE80211_C_TDMA) == 0
128 if_printf(ifp, "TDMA not supported\n");
131 vap = ic->ic_vap_create(ic, ifc->ifc_name, unit,
132 cp.icp_opmode, cp.icp_flags, cp.icp_bssid,
133 cp.icp_flags & IEEE80211_CLONE_MACADDR ?
134 cp.icp_macaddr : (const uint8_t *)IF_LLADDR(ifp));
135 return (vap == NULL ? EIO : 0);
139 wlan_clone_destroy(struct ifnet *ifp)
141 struct ieee80211vap *vap = ifp->if_softc;
142 struct ieee80211com *ic = vap->iv_ic;
144 ic->ic_vap_delete(vap);
146 IFC_SIMPLE_DECLARE(wlan, 0);
149 ieee80211_vap_destroy(struct ieee80211vap *vap)
151 if_clone_destroyif(&wlan_cloner, vap->iv_ifp);
155 ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS)
157 int msecs = ticks_to_msecs(*(int *)arg1);
160 error = sysctl_handle_int(oidp, &msecs, 0, req);
161 if (error || !req->newptr)
163 t = msecs_to_ticks(msecs);
164 *(int *)arg1 = (t < 1) ? 1 : t;
169 ieee80211_sysctl_inact(SYSCTL_HANDLER_ARGS)
171 int inact = (*(int *)arg1) * IEEE80211_INACT_WAIT;
174 error = sysctl_handle_int(oidp, &inact, 0, req);
175 if (error || !req->newptr)
177 *(int *)arg1 = inact / IEEE80211_INACT_WAIT;
182 ieee80211_sysctl_parent(SYSCTL_HANDLER_ARGS)
184 struct ieee80211com *ic = arg1;
185 const char *name = ic->ic_ifp->if_xname;
187 return SYSCTL_OUT(req, name, strlen(name));
191 ieee80211_sysctl_radar(SYSCTL_HANDLER_ARGS)
193 struct ieee80211com *ic = arg1;
196 error = sysctl_handle_int(oidp, &t, 0, req);
197 if (error || !req->newptr)
200 ieee80211_dfs_notify_radar(ic, ic->ic_curchan);
201 IEEE80211_UNLOCK(ic);
206 ieee80211_sysctl_attach(struct ieee80211com *ic)
211 ieee80211_sysctl_detach(struct ieee80211com *ic)
216 ieee80211_sysctl_vattach(struct ieee80211vap *vap)
218 struct ifnet *ifp = vap->iv_ifp;
219 struct sysctl_ctx_list *ctx;
220 struct sysctl_oid *oid;
221 char num[14]; /* sufficient for 32 bits */
223 ctx = (struct sysctl_ctx_list *) malloc(sizeof(struct sysctl_ctx_list),
224 M_DEVBUF, M_NOWAIT | M_ZERO);
226 if_printf(ifp, "%s: cannot allocate sysctl context!\n",
230 sysctl_ctx_init(ctx);
231 snprintf(num, sizeof(num), "%u", ifp->if_dunit);
232 oid = SYSCTL_ADD_NODE(ctx, &SYSCTL_NODE_CHILDREN(_net, wlan),
233 OID_AUTO, num, CTLFLAG_RD, NULL, "");
234 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
235 "%parent", CTLFLAG_RD, vap->iv_ic, 0,
236 ieee80211_sysctl_parent, "A", "parent device");
237 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
238 "driver_caps", CTLFLAG_RW, &vap->iv_caps, 0,
239 "driver capabilities");
240 #ifdef IEEE80211_DEBUG
241 vap->iv_debug = ieee80211_debug;
242 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
243 "debug", CTLFLAG_RW, &vap->iv_debug, 0,
244 "control debugging printfs");
246 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
247 "bmiss_max", CTLFLAG_RW, &vap->iv_bmiss_max, 0,
248 "consecutive beacon misses before scanning");
249 /* XXX inherit from tunables */
250 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
251 "inact_run", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_run, 0,
252 ieee80211_sysctl_inact, "I",
253 "station inactivity timeout (sec)");
254 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
255 "inact_probe", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_probe, 0,
256 ieee80211_sysctl_inact, "I",
257 "station inactivity probe timeout (sec)");
258 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
259 "inact_auth", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_auth, 0,
260 ieee80211_sysctl_inact, "I",
261 "station authentication timeout (sec)");
262 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
263 "inact_init", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_init, 0,
264 ieee80211_sysctl_inact, "I",
265 "station initial state timeout (sec)");
266 if (vap->iv_htcaps & IEEE80211_HTC_HT) {
267 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
268 "ampdu_mintraffic_bk", CTLFLAG_RW,
269 &vap->iv_ampdu_mintraffic[WME_AC_BK], 0,
270 "BK traffic tx aggr threshold (pps)");
271 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
272 "ampdu_mintraffic_be", CTLFLAG_RW,
273 &vap->iv_ampdu_mintraffic[WME_AC_BE], 0,
274 "BE traffic tx aggr threshold (pps)");
275 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
276 "ampdu_mintraffic_vo", CTLFLAG_RW,
277 &vap->iv_ampdu_mintraffic[WME_AC_VO], 0,
278 "VO traffic tx aggr threshold (pps)");
279 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
280 "ampdu_mintraffic_vi", CTLFLAG_RW,
281 &vap->iv_ampdu_mintraffic[WME_AC_VI], 0,
282 "VI traffic tx aggr threshold (pps)");
284 if (vap->iv_caps & IEEE80211_C_DFS) {
285 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
286 "radar", CTLTYPE_INT | CTLFLAG_RW, vap->iv_ic, 0,
287 ieee80211_sysctl_radar, "I", "simulate radar event");
289 vap->iv_sysctl = ctx;
294 ieee80211_sysctl_vdetach(struct ieee80211vap *vap)
297 if (vap->iv_sysctl != NULL) {
298 sysctl_ctx_free(vap->iv_sysctl);
299 free(vap->iv_sysctl, M_DEVBUF);
300 vap->iv_sysctl = NULL;
305 ieee80211_node_dectestref(struct ieee80211_node *ni)
307 /* XXX need equivalent of atomic_dec_and_test */
308 atomic_subtract_int(&ni->ni_refcnt, 1);
309 return atomic_cmpset_int(&ni->ni_refcnt, 0, 1);
313 ieee80211_drain_ifq(struct ifqueue *ifq)
315 struct ieee80211_node *ni;
323 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
324 KASSERT(ni != NULL, ("frame w/o node"));
325 ieee80211_free_node(ni);
326 m->m_pkthdr.rcvif = NULL;
333 ieee80211_flush_ifq(struct ifqueue *ifq, struct ieee80211vap *vap)
335 struct ieee80211_node *ni;
336 struct mbuf *m, **mprev;
339 mprev = &ifq->ifq_head;
340 while ((m = *mprev) != NULL) {
341 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
342 if (ni != NULL && ni->ni_vap == vap) {
343 *mprev = m->m_nextpkt; /* remove from list */
347 ieee80211_free_node(ni); /* reclaim ref */
349 mprev = &m->m_nextpkt;
351 /* recalculate tail ptr */
353 for (; m != NULL && m->m_nextpkt != NULL; m = m->m_nextpkt)
360 * As above, for mbufs allocated with m_gethdr/MGETHDR
361 * or initialized by M_COPY_PKTHDR.
363 #define MC_ALIGN(m, len) \
365 (m)->m_data += (MCLBYTES - (len)) &~ (sizeof(long) - 1); \
366 } while (/* CONSTCOND */ 0)
369 * Allocate and setup a management frame of the specified
370 * size. We return the mbuf and a pointer to the start
371 * of the contiguous data area that's been reserved based
372 * on the packet length. The data area is forced to 32-bit
373 * alignment and the buffer length to a multiple of 4 bytes.
374 * This is done mainly so beacon frames (that require this)
375 * can use this interface too.
378 ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen)
384 * NB: we know the mbuf routines will align the data area
385 * so we don't need to do anything special.
387 len = roundup2(headroom + pktlen, 4);
388 KASSERT(len <= MCLBYTES, ("802.11 mgt frame too large: %u", len));
389 if (len < MINCLSIZE) {
390 m = m_gethdr(M_NOWAIT, MT_DATA);
392 * Align the data in case additional headers are added.
393 * This should only happen when a WEP header is added
394 * which only happens for shared key authentication mgt
395 * frames which all fit in MHLEN.
400 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
405 m->m_data += headroom;
412 ieee80211_add_callback(struct mbuf *m,
413 void (*func)(struct ieee80211_node *, void *, int), void *arg)
416 struct ieee80211_cb *cb;
418 mtag = m_tag_alloc(MTAG_ABI_NET80211, NET80211_TAG_CALLBACK,
419 sizeof(struct ieee80211_cb), M_NOWAIT);
423 cb = (struct ieee80211_cb *)(mtag+1);
426 m_tag_prepend(m, mtag);
427 m->m_flags |= M_TXCB;
432 ieee80211_process_callback(struct ieee80211_node *ni,
433 struct mbuf *m, int status)
437 mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_CALLBACK, NULL);
439 struct ieee80211_cb *cb = (struct ieee80211_cb *)(mtag+1);
440 cb->func(ni, cb->arg, status);
444 #include <sys/libkern.h>
447 get_random_bytes(void *p, size_t n)
452 uint32_t v = arc4random();
453 size_t nb = n > sizeof(uint32_t) ? sizeof(uint32_t) : n;
454 bcopy(&v, dp, n > sizeof(uint32_t) ? sizeof(uint32_t) : n);
455 dp += sizeof(uint32_t), n -= nb;
460 * Helper function for events that pass just a single mac address.
463 notify_macaddr(struct ifnet *ifp, int op, const uint8_t mac[IEEE80211_ADDR_LEN])
465 struct ieee80211_join_event iev;
467 CURVNET_SET(ifp->if_vnet);
468 memset(&iev, 0, sizeof(iev));
469 IEEE80211_ADDR_COPY(iev.iev_addr, mac);
470 rt_ieee80211msg(ifp, op, &iev, sizeof(iev));
475 ieee80211_notify_node_join(struct ieee80211_node *ni, int newassoc)
477 struct ieee80211vap *vap = ni->ni_vap;
478 struct ifnet *ifp = vap->iv_ifp;
480 CURVNET_SET_QUIET(ifp->if_vnet);
481 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode join",
482 (ni == vap->iv_bss) ? "bss " : "");
484 if (ni == vap->iv_bss) {
485 notify_macaddr(ifp, newassoc ?
486 RTM_IEEE80211_ASSOC : RTM_IEEE80211_REASSOC, ni->ni_bssid);
487 if_link_state_change(ifp, LINK_STATE_UP);
489 notify_macaddr(ifp, newassoc ?
490 RTM_IEEE80211_JOIN : RTM_IEEE80211_REJOIN, ni->ni_macaddr);
496 ieee80211_notify_node_leave(struct ieee80211_node *ni)
498 struct ieee80211vap *vap = ni->ni_vap;
499 struct ifnet *ifp = vap->iv_ifp;
501 CURVNET_SET_QUIET(ifp->if_vnet);
502 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode leave",
503 (ni == vap->iv_bss) ? "bss " : "");
505 if (ni == vap->iv_bss) {
506 rt_ieee80211msg(ifp, RTM_IEEE80211_DISASSOC, NULL, 0);
507 if_link_state_change(ifp, LINK_STATE_DOWN);
509 /* fire off wireless event station leaving */
510 notify_macaddr(ifp, RTM_IEEE80211_LEAVE, ni->ni_macaddr);
516 ieee80211_notify_scan_done(struct ieee80211vap *vap)
518 struct ifnet *ifp = vap->iv_ifp;
520 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s\n", "notify scan done");
522 /* dispatch wireless event indicating scan completed */
523 CURVNET_SET(ifp->if_vnet);
524 rt_ieee80211msg(ifp, RTM_IEEE80211_SCAN, NULL, 0);
529 ieee80211_notify_replay_failure(struct ieee80211vap *vap,
530 const struct ieee80211_frame *wh, const struct ieee80211_key *k,
531 u_int64_t rsc, int tid)
533 struct ifnet *ifp = vap->iv_ifp;
535 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
536 "%s replay detected <rsc %ju, csc %ju, keyix %u rxkeyix %u>",
537 k->wk_cipher->ic_name, (intmax_t) rsc,
538 (intmax_t) k->wk_keyrsc[tid],
539 k->wk_keyix, k->wk_rxkeyix);
541 if (ifp != NULL) { /* NB: for cipher test modules */
542 struct ieee80211_replay_event iev;
544 IEEE80211_ADDR_COPY(iev.iev_dst, wh->i_addr1);
545 IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2);
546 iev.iev_cipher = k->wk_cipher->ic_cipher;
547 if (k->wk_rxkeyix != IEEE80211_KEYIX_NONE)
548 iev.iev_keyix = k->wk_rxkeyix;
550 iev.iev_keyix = k->wk_keyix;
551 iev.iev_keyrsc = k->wk_keyrsc[tid];
553 CURVNET_SET(ifp->if_vnet);
554 rt_ieee80211msg(ifp, RTM_IEEE80211_REPLAY, &iev, sizeof(iev));
560 ieee80211_notify_michael_failure(struct ieee80211vap *vap,
561 const struct ieee80211_frame *wh, u_int keyix)
563 struct ifnet *ifp = vap->iv_ifp;
565 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
566 "michael MIC verification failed <keyix %u>", keyix);
567 vap->iv_stats.is_rx_tkipmic++;
569 if (ifp != NULL) { /* NB: for cipher test modules */
570 struct ieee80211_michael_event iev;
572 IEEE80211_ADDR_COPY(iev.iev_dst, wh->i_addr1);
573 IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2);
574 iev.iev_cipher = IEEE80211_CIPHER_TKIP;
575 iev.iev_keyix = keyix;
576 CURVNET_SET(ifp->if_vnet);
577 rt_ieee80211msg(ifp, RTM_IEEE80211_MICHAEL, &iev, sizeof(iev));
583 ieee80211_notify_wds_discover(struct ieee80211_node *ni)
585 struct ieee80211vap *vap = ni->ni_vap;
586 struct ifnet *ifp = vap->iv_ifp;
588 notify_macaddr(ifp, RTM_IEEE80211_WDS, ni->ni_macaddr);
592 ieee80211_notify_csa(struct ieee80211com *ic,
593 const struct ieee80211_channel *c, int mode, int count)
595 struct ifnet *ifp = ic->ic_ifp;
596 struct ieee80211_csa_event iev;
598 memset(&iev, 0, sizeof(iev));
599 iev.iev_flags = c->ic_flags;
600 iev.iev_freq = c->ic_freq;
601 iev.iev_ieee = c->ic_ieee;
603 iev.iev_count = count;
604 rt_ieee80211msg(ifp, RTM_IEEE80211_CSA, &iev, sizeof(iev));
608 ieee80211_notify_radar(struct ieee80211com *ic,
609 const struct ieee80211_channel *c)
611 struct ifnet *ifp = ic->ic_ifp;
612 struct ieee80211_radar_event iev;
614 memset(&iev, 0, sizeof(iev));
615 iev.iev_flags = c->ic_flags;
616 iev.iev_freq = c->ic_freq;
617 iev.iev_ieee = c->ic_ieee;
618 rt_ieee80211msg(ifp, RTM_IEEE80211_RADAR, &iev, sizeof(iev));
622 ieee80211_notify_cac(struct ieee80211com *ic,
623 const struct ieee80211_channel *c, enum ieee80211_notify_cac_event type)
625 struct ifnet *ifp = ic->ic_ifp;
626 struct ieee80211_cac_event iev;
628 memset(&iev, 0, sizeof(iev));
629 iev.iev_flags = c->ic_flags;
630 iev.iev_freq = c->ic_freq;
631 iev.iev_ieee = c->ic_ieee;
633 rt_ieee80211msg(ifp, RTM_IEEE80211_CAC, &iev, sizeof(iev));
637 ieee80211_notify_node_deauth(struct ieee80211_node *ni)
639 struct ieee80211vap *vap = ni->ni_vap;
640 struct ifnet *ifp = vap->iv_ifp;
642 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%s", "node deauth");
644 notify_macaddr(ifp, RTM_IEEE80211_DEAUTH, ni->ni_macaddr);
648 ieee80211_notify_node_auth(struct ieee80211_node *ni)
650 struct ieee80211vap *vap = ni->ni_vap;
651 struct ifnet *ifp = vap->iv_ifp;
653 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%s", "node auth");
655 notify_macaddr(ifp, RTM_IEEE80211_AUTH, ni->ni_macaddr);
659 ieee80211_notify_country(struct ieee80211vap *vap,
660 const uint8_t bssid[IEEE80211_ADDR_LEN], const uint8_t cc[2])
662 struct ifnet *ifp = vap->iv_ifp;
663 struct ieee80211_country_event iev;
665 memset(&iev, 0, sizeof(iev));
666 IEEE80211_ADDR_COPY(iev.iev_addr, bssid);
667 iev.iev_cc[0] = cc[0];
668 iev.iev_cc[1] = cc[1];
669 rt_ieee80211msg(ifp, RTM_IEEE80211_COUNTRY, &iev, sizeof(iev));
673 ieee80211_notify_radio(struct ieee80211com *ic, int state)
675 struct ifnet *ifp = ic->ic_ifp;
676 struct ieee80211_radio_event iev;
678 memset(&iev, 0, sizeof(iev));
679 iev.iev_state = state;
680 rt_ieee80211msg(ifp, RTM_IEEE80211_RADIO, &iev, sizeof(iev));
684 ieee80211_load_module(const char *modname)
688 (void)kern_kldload(curthread, modname, NULL);
690 printf("%s: load the %s module by hand for now.\n", __func__, modname);
694 static eventhandler_tag wlan_bpfevent;
697 bpf_track(void *arg, struct ifnet *ifp, int dlt, int attach)
699 /* NB: identify vap's by if_start */
700 if (dlt == DLT_IEEE802_11_RADIO && ifp->if_start == ieee80211_start) {
701 struct ieee80211vap *vap = ifp->if_softc;
703 * Track bpf radiotap listener state. We mark the vap
704 * to indicate if any listener is present and the com
705 * to indicate if any listener exists on any associated
706 * vap. This flag is used by drivers to prepare radiotap
707 * state only when needed.
710 ieee80211_syncflag_ext(vap, IEEE80211_FEXT_BPF);
711 if (vap->iv_opmode == IEEE80211_M_MONITOR)
712 atomic_add_int(&vap->iv_ic->ic_montaps, 1);
713 } else if (!bpf_peers_present(vap->iv_rawbpf)) {
714 ieee80211_syncflag_ext(vap, -IEEE80211_FEXT_BPF);
715 if (vap->iv_opmode == IEEE80211_M_MONITOR)
716 atomic_subtract_int(&vap->iv_ic->ic_montaps, 1);
724 * NB: the module name is "wlan" for compatibility with NetBSD.
727 wlan_modevent(module_t mod, int type, void *unused)
732 printf("wlan: <802.11 Link Layer>\n");
733 wlan_bpfevent = EVENTHANDLER_REGISTER(bpf_track,
734 bpf_track, 0, EVENTHANDLER_PRI_ANY);
735 if (wlan_bpfevent == NULL)
737 if_clone_attach(&wlan_cloner);
738 if_register_com_alloc(IFT_IEEE80211, wlan_alloc, wlan_free);
741 if_deregister_com_alloc(IFT_IEEE80211);
742 if_clone_detach(&wlan_cloner);
743 EVENTHANDLER_DEREGISTER(bpf_track, wlan_bpfevent);
749 static moduledata_t wlan_mod = {
754 DECLARE_MODULE(wlan, wlan_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
755 MODULE_VERSION(wlan, 1);
756 MODULE_DEPEND(wlan, ether, 1, 1, 1);