diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2006-07-01 04:25:08 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2006-07-01 04:25:08 +0000 |
commit | d62a9bc8952671ff113015f40b08c82fe84f4aa5 (patch) | |
tree | 2813e1dcdb7c1296ee075f43d03c1140fec475a2 /sys | |
parent | 546456db72ce87fce98c1ee5e51b108d6e00dbe8 (diff) |
Initial radiotap/bpf bits based on ural.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/usb/if_zyd.c | 89 | ||||
-rw-r--r-- | sys/dev/usb/if_zydreg.h | 49 |
2 files changed, 136 insertions, 2 deletions
diff --git a/sys/dev/usb/if_zyd.c b/sys/dev/usb/if_zyd.c index 1d1a8dd3046..6c13eec6ced 100644 --- a/sys/dev/usb/if_zyd.c +++ b/sys/dev/usb/if_zyd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_zyd.c,v 1.11 2006/06/30 12:27:21 jsg Exp $ */ +/* $OpenBSD: if_zyd.c,v 1.12 2006/07/01 04:25:07 jsg Exp $ */ /* * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de> @@ -1263,6 +1263,26 @@ zyd_rxframeproc(struct zyd_rx_data *data, uint8_t *buf, uint16_t len) s = splnet(); +#if NBPFILTER > 0 + if (sc->sc_drvbpf != NULL) { + struct mbuf mb; + struct zyd_rx_radiotap_header *tap = &sc->sc_rxtap; + + tap->wr_flags = 0; + tap->wr_chan_freq = htole16(ic->ic_ibss_chan->ic_freq); + tap->wr_chan_flags = htole16(ic->ic_ibss_chan->ic_flags); + tap->wr_rssi = desc->signalstrength; + tap->wr_max_rssi = 0; /* XXX */ + + M_DUP_PKTHDR(&mb, m); + mb.m_data = (caddr_t)tap; + mb.m_len = sc->sc_rxtap_len; + mb.m_next = m; + mb.m_pkthdr.len += mb.m_len; + bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_IN); + } +#endif + wh = mtod(m, struct ieee80211_frame *); ni = ieee80211_find_rxnode(ic, wh); ieee80211_input(ifp, m, ni, desc->signalstrength, 0); @@ -2472,6 +2492,19 @@ zyd_complete_attach(struct zyd_softc *sc) /* setup ifmedia interface */ ieee80211_media_init(ifp, zyd_media_change, ieee80211_media_status); +#if NBPFILTER > 0 + bpfattach(&sc->sc_drvbpf, ifp, DLT_IEEE802_11_RADIO, + sizeof (struct ieee80211_frame) + 64); + + sc->sc_rxtap_len = sizeof sc->sc_rxtapu; + sc->sc_rxtap.wr_ihdr.it_len = htole16(sc->sc_rxtap_len); + sc->sc_rxtap.wr_ihdr.it_present = htole32(ZYD_RX_RADIOTAP_PRESENT); + + sc->sc_txtap_len = sizeof sc->sc_txtapu; + sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len); + sc->sc_txtap.wt_ihdr.it_present = htole32(ZYD_TX_RADIOTAP_PRESENT); +#endif + usb_init_task(&sc->sc_task, zyd_task, sc); /* ieee80211_announce(ic);*/ @@ -3001,6 +3034,25 @@ zyd_tx_mgt(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) flags |= RAL_TX_TIMESTAMP;*/ } +#if NBPFILTER > 0 + if (sc->sc_drvbpf != NULL) { + struct mbuf mb; + struct zyd_tx_radiotap_header *tap = &sc->sc_txtap; + + tap->wt_flags = 0; + tap->wt_rate = rate; + tap->wt_chan_freq = htole16(ic->ic_ibss_chan->ic_freq); + tap->wt_chan_flags = htole16(ic->ic_ibss_chan->ic_flags); + + M_DUP_PKTHDR(&mb, m0); + mb.m_data = (caddr_t)tap; + mb.m_len = sc->sc_txtap_len; + mb.m_next = m0; + mb.m_pkthdr.len += mb.m_len; + bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT); + } +#endif + m_copydata(m0, 0, m0->m_pkthdr.len, data->buf + ZYD_TX_DESC_SIZE); @@ -3101,6 +3153,25 @@ zyd_tx_data(struct zyd_softc *sc, struct mbuf *m0, struct ieee80211_node *ni) *(uint16_t *)wh->i_dur = htole16(dur); }*/ +#if NBPFILTER > 0 + if (sc->sc_drvbpf != NULL) { + struct mbuf mb; + struct zyd_tx_radiotap_header *tap = &sc->sc_txtap; + + tap->wt_flags = 0; + tap->wt_rate = rate; + tap->wt_chan_freq = htole16(ic->ic_ibss_chan->ic_freq); + tap->wt_chan_flags = htole16(ic->ic_ibss_chan->ic_flags); + + M_DUP_PKTHDR(&mb, m0); + mb.m_data = (caddr_t)tap; + mb.m_len = sc->sc_txtap_len; + mb.m_next = m0; + mb.m_pkthdr.len += mb.m_len; + bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT); + } +#endif + m_copydata(m0, 0, m0->m_pkthdr.len, data->buf + ZYD_TX_DESC_SIZE); zyd_setup_tx_desc(sc, desc, m0, m0->m_pkthdr.len, rate); @@ -3407,6 +3478,11 @@ zyd_if_start(struct ifnet *ifp) ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif; m0->m_pkthdr.rcvif = NULL; +#if NBPFILTER > 0 + if (ic->ic_rawbpf != NULL) + bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT); +#endif + DPRINTF(("if_state: @1\n")); if (zyd_tx_mgt(sc, m0, ni) != 0) @@ -3448,6 +3524,12 @@ zyd_if_start(struct ifnet *ifp) } DPRINTF(("if_state: @7\n")); + +#if NBPFILTER > 0 + if (ifp->if_bpf != NULL) + bpf_mtap(ifp->if_bpf, m0, BPF_DIRECTION_OUT); +#endif + m0 = ieee80211_encap(ifp, m0, &ni); if (m0 == NULL) { @@ -3455,6 +3537,11 @@ zyd_if_start(struct ifnet *ifp) continue; } +#if NBPFILTER > 0 + if (ic->ic_rawbpf != NULL) + bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT); +#endif + DPRINTF(("if_state: @8\n")); if (zyd_tx_data(sc, m0, ni) != 0) { diff --git a/sys/dev/usb/if_zydreg.h b/sys/dev/usb/if_zydreg.h index bd29514ffcf..b27c9526f7d 100644 --- a/sys/dev/usb/if_zydreg.h +++ b/sys/dev/usb/if_zydreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_zydreg.h,v 1.7 2006/06/30 12:27:21 jsg Exp $ */ +/* $OpenBSD: if_zydreg.h,v 1.8 2006/07/01 04:25:07 jsg Exp $ */ /* * Copyright (c) 2006 by Florian Stoehr <ich@florian-stoehr.de> @@ -1203,6 +1203,35 @@ struct zyd_rx_data { struct zyd_softc; +struct zyd_rx_radiotap_header { + struct ieee80211_radiotap_header wr_ihdr; + uint8_t wr_flags; + uint16_t wr_chan_freq; + uint16_t wr_chan_flags; + uint8_t wr_rssi; + uint8_t wr_max_rssi; +} __packed; + +#define ZYD_RX_RADIOTAP_PRESENT \ + ((1 << IEEE80211_RADIOTAP_FLAGS) | \ + (1 << IEEE80211_RADIOTAP_CHANNEL) | \ + (1 << IEEE80211_RADIOTAP_RSSI)) + +struct zyd_tx_radiotap_header { + struct ieee80211_radiotap_header wt_ihdr; + uint8_t wt_flags; + uint8_t wt_rate; + uint16_t wt_chan_freq; + uint16_t wt_chan_flags; + uint8_t wt_rssi; + uint8_t wt_max_rssi; +} __packed; + +#define ZYD_TX_RADIOTAP_PRESENT \ + ((1 << IEEE80211_RADIOTAP_FLAGS) | \ + (1 << IEEE80211_RADIOTAP_RATE) | \ + (1 << IEEE80211_RADIOTAP_CHANNEL)) + struct zyd_softc { /* Driver handling */ USBBASEDEVICE zyd_dev; @@ -1275,4 +1304,22 @@ struct zyd_softc { int zyd_wepkey; int zyd_wepkeylen; uint8_t zyd_wepkeys[4][13]; + +#if NBPFILTER > 0 + caddr_t sc_drvbpf; + + union { + struct zyd_rx_radiotap_header th; + uint8_t pad[64]; + } sc_rxtapu; +#define sc_rxtap sc_rxtapu.th + int sc_rxtap_len; + + union { + struct zyd_tx_radiotap_header th; + uint8_t pad[64]; + } sc_txtapu; +#define sc_txtap sc_txtapu.th + int sc_txtap_len; +#endif }; |