summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2005-05-23 20:09:32 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2005-05-23 20:09:32 +0000
commita82036c201b4206a70fe7b9753d66e78e0423fe8 (patch)
treef6a94a93b5f29918354135642160fc88a37cae06
parent4288617b8956c4d3682de202b8ea9910aa6562e4 (diff)
Initial radiotap support. ok dlg@
-rw-r--r--sys/dev/usb/if_atu.c73
-rw-r--r--sys/dev/usb/if_atureg.h52
2 files changed, 117 insertions, 8 deletions
diff --git a/sys/dev/usb/if_atu.c b/sys/dev/usb/if_atu.c
index 95c3a112916..ce63cbc1556 100644
--- a/sys/dev/usb/if_atu.c
+++ b/sys/dev/usb/if_atu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_atu.c,v 1.59 2005/03/08 12:15:12 dlg Exp $ */
+/* $OpenBSD: if_atu.c,v 1.60 2005/05/23 20:09:31 jsg Exp $ */
/*
* Copyright (c) 2003, 2004
* Daan Vreeken <Danovitsch@Vitsch.net>. All rights reserved.
@@ -68,7 +68,6 @@
#include <dev/usb/usbdevs.h>
#if NBPFILTER > 0
-#define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
#include <net/bpf.h>
#endif
@@ -1470,6 +1469,19 @@ atu_complete_attach(struct atu_softc *sc)
usb_init_task(&sc->sc_task, atu_task, sc);
+#if NBPFILTER > 0
+ bpfattach(&sc->sc_radiobpf, &sc->sc_ic.ic_if, DLT_IEEE802_11_RADIO,
+ sizeof(struct ieee80211_frame) + 64);
+
+ bzero(&sc->sc_rxtapu, sizeof(sc->sc_rxtapu));
+ sc->sc_rxtap.rr_ihdr.it_len = sizeof(sc->sc_rxtapu);
+ sc->sc_rxtap.rr_ihdr.it_present = htole32(ATU_RX_RADIOTAP_PRESENT);
+
+ bzero(&sc->sc_txtapu, sizeof(sc->sc_txtapu));
+ sc->sc_txtap.rt_ihdr.it_len = sizeof(sc->sc_txtapu);
+ sc->sc_txtap.rt_ihdr.it_present = htole32(ATU_TX_RADIOTAP_PRESENT);
+#endif
+
sc->sc_state = ATU_S_OK;
}
@@ -1483,7 +1495,9 @@ USB_DETACH(atu)
if (sc->sc_state != ATU_S_UNCONFIG) {
atu_stop(ifp, 1);
-
+#if NBPFILTER > 0
+ bpfdetach(ifp);
+#endif
ieee80211_ifdetach(ifp);
if_detach(ifp);
@@ -1722,9 +1736,25 @@ atu_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
}
#if NBPFILTER > 0
- if (ifp->if_bpf)
- bpf_mtap(ifp->if_bpf, m);
-#endif
+ if (sc->sc_radiobpf != NULL) {
+ struct mbuf mb;
+ struct atu_rx_radiotap_header *rr = &sc->sc_rxtap;
+
+ rr->rr_flags = 0;
+ rr->rr_chan_freq =
+ htole16(ic->ic_bss->ni_chan->ic_freq);
+ rr->rr_chan_flags =
+ htole16(ic->ic_bss->ni_chan->ic_flags);
+ rr->rr_antsignal = h->rssi;
+
+ M_DUP_PKTHDR(&mb, m);
+ mb.m_data = (caddr_t)rr;
+ mb.m_len = sizeof(sc->sc_txtapu);
+ mb.m_next = m;
+ mb.m_pkthdr.len += mb.m_len;
+ bpf_mtap(sc->sc_radiobpf, &mb);
+ }
+#endif /* NPBFILTER > 0 */
if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
/*
@@ -1817,6 +1847,7 @@ atu_tx_start(struct atu_softc *sc, struct ieee80211_node *ni,
struct atu_tx_hdr *h;
usbd_status err;
u_int8_t pad;
+ struct ieee80211com *ic = &sc->sc_ic;
DPRINTFN(25, ("%s: atu_tx_start\n", USBDEVNAME(sc->atu_dev)));
@@ -1826,6 +1857,26 @@ atu_tx_start(struct atu_softc *sc, struct ieee80211_node *ni,
return(EIO);
}
+#if NBPFILTER > 0
+ if (sc->sc_radiobpf != NULL) {
+ struct mbuf mb;
+ struct atu_tx_radiotap_header *rt = &sc->sc_txtap;
+
+ rt->rt_flags = 0;
+ rt->rt_chan_freq =
+ htole16(ic->ic_bss->ni_chan->ic_freq);
+ rt->rt_chan_flags =
+ htole16(ic->ic_bss->ni_chan->ic_flags);
+
+ M_DUP_PKTHDR(&mb, m);
+ mb.m_data = (caddr_t)rt;
+ mb.m_len = sizeof(sc->sc_txtapu);
+ mb.m_next = m;
+ mb.m_pkthdr.len += mb.m_len;
+ bpf_mtap(sc->sc_radiobpf, &mb);
+ }
+#endif
+
/*
* Copy the mbuf data into a contiguous buffer, leaving
* enough room for the atmel headers
@@ -1941,12 +1992,20 @@ atu_start(struct ifnet *ifp)
break;
}
- /* XXX bpf listener goes here */
+#if NBPFILTER > 0
+ if (ifp->if_bpf)
+ bpf_mtap(ifp->if_bpf, m);
+#endif
m = ieee80211_encap(ifp, m, &ni);
if (m == NULL)
goto bad;
wh = mtod(m, struct ieee80211_frame *);
+
+#if NBPFILTER > 0
+ if (ic->ic_rawbpf != NULL)
+ bpf_mtap(ic->ic_rawbpf, m);
+#endif
} else {
DPRINTFN(25, ("%s: atu_start: mgmt packet\n",
USBDEVNAME(sc->atu_dev)));
diff --git a/sys/dev/usb/if_atureg.h b/sys/dev/usb/if_atureg.h
index 4046a663609..a0eafb3fa07 100644
--- a/sys/dev/usb/if_atureg.h
+++ b/sys/dev/usb/if_atureg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_atureg.h,v 1.23 2005/03/08 12:15:12 dlg Exp $ */
+/* $OpenBSD: if_atureg.h,v 1.24 2005/05/23 20:09:31 jsg Exp $ */
/*
* Copyright (c) 2003
* Daan Vreeken <Danovitsch@Vitsch.net>. All rights reserved.
@@ -116,6 +116,42 @@ struct atu_chain {
SLIST_ENTRY(atu_chain) atu_list;
};
+/* Radio capture format */
+
+#define ATU_RX_RADIOTAP_PRESENT \
+ ((1 << IEEE80211_RADIOTAP_TSFT) | \
+ (1 << IEEE80211_RADIOTAP_FLAGS) | \
+ (1 << IEEE80211_RADIOTAP_RATE) | \
+ (1 << IEEE80211_RADIOTAP_CHANNEL) | \
+ (1 << IEEE80211_RADIOTAP_LOCK_QUALITY) | \
+ (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
+ 0)
+
+struct atu_rx_radiotap_header {
+ struct ieee80211_radiotap_header rr_ihdr;
+ u_int64_t rr_tsft;
+ u_int8_t rr_flags;
+ u_int8_t rr_rate;
+ u_int16_t rr_chan_freq;
+ u_int16_t rr_chan_flags;
+ u_int16_t rr_barker_lock;
+ u_int8_t rr_antsignal;
+} __attribute__((__packed__));
+
+#define ATU_TX_RADIOTAP_PRESENT \
+ ((1 << IEEE80211_RADIOTAP_FLAGS) | \
+ (1 << IEEE80211_RADIOTAP_RATE) | \
+ (1 << IEEE80211_RADIOTAP_CHANNEL) | \
+ 0)
+
+struct atu_tx_radiotap_header {
+ struct ieee80211_radiotap_header rt_ihdr;
+ u_int8_t rt_flags;
+ u_int8_t rt_rate;
+ u_int16_t rt_chan_freq;
+ u_int16_t rt_chan_flags;
+} __attribute__((__packed__));
+
struct atu_cdata {
struct atu_chain atu_tx_chain[ATU_TX_LIST_CNT];
struct atu_chain atu_rx_chain[ATU_RX_LIST_CNT];
@@ -172,8 +208,22 @@ struct atu_softc {
#define INFRASTRUCTURE_MODE 2
u_int8_t atu_radio_on;
+ caddr_t sc_radiobpf;
+
+ union {
+ struct atu_rx_radiotap_header tap;
+ u_int8_t pad[64];
+ } sc_rxtapu;
+ union {
+ struct atu_tx_radiotap_header tap;
+ u_int8_t pad[64];
+ } sc_txtapu;
+
};
+#define sc_rxtap sc_rxtapu.tap
+#define sc_txtap sc_txtapu.tap
+
/* Commands for uploading the firmware (standard DFU interface) */
#define DFU_DNLOAD UT_WRITE_CLASS_INTERFACE, 0x01
#define DFU_GETSTATUS UT_READ_CLASS_INTERFACE, 0x03