svn commit: r237278 - in user/adrian/ath_radar_stuff: . lib
lib/libradarpkt src src/pktlog
Adrian Chadd
adrian at FreeBSD.org
Tue Jun 19 23:45:18 UTC 2012
Author: adrian
Date: Tue Jun 19 23:45:17 2012
New Revision: 237278
URL: http://svn.freebsd.org/changeset/base/237278
Log:
Add some locally written code to tinker with radar frame capture and
decoding from userland.
* lib/libradarpkt/ has some bits that I've written to decode the PHY
error frame format, for AR5416 and post-AR5416. The AR9280 code is
just as applicable for AR9130/AR9160.
* src/pktlog will read either a radiotap interface or a capture file and
dump phy errors out at you.
It includes a BPF filter which limits the amount of stuff that gets
pushed to userland.
It doesn't output anything by default; you'll have to enable debug
printing for that to happen. check the source.
The code relies on the patch at http://wiki.freebsd.org/ath(4)/RadarFFT.
There's hard-coded -I references to my home-directory, sorry. You should
replace that with the path to your kernel tree which has the ath(4)
radiotap vendor extension patch.
Added:
user/adrian/ath_radar_stuff/
user/adrian/ath_radar_stuff/lib/
user/adrian/ath_radar_stuff/lib/libradarpkt/
user/adrian/ath_radar_stuff/lib/libradarpkt/Makefile
user/adrian/ath_radar_stuff/lib/libradarpkt/ar5416_radar.c
user/adrian/ath_radar_stuff/lib/libradarpkt/ar5416_radar.h
user/adrian/ath_radar_stuff/lib/libradarpkt/ar9280_radar.c
user/adrian/ath_radar_stuff/lib/libradarpkt/ar9280_radar.h
user/adrian/ath_radar_stuff/lib/libradarpkt/pkt.h
user/adrian/ath_radar_stuff/src/
user/adrian/ath_radar_stuff/src/pktlog/
user/adrian/ath_radar_stuff/src/pktlog/Makefile
user/adrian/ath_radar_stuff/src/pktlog/main.c
Added: user/adrian/ath_radar_stuff/lib/libradarpkt/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/lib/libradarpkt/Makefile Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,8 @@
+LIB= radarpkt
+
+SRCS= ar9280_radar.c ar5416_radar.c
+CFLAGS+= -I/home/adrian/work/freebsd/ath/head/src/sys -g -ggdb
+
+NO_MAN= 1
+
+.include <bsd.lib.mk>
Added: user/adrian/ath_radar_stuff/lib/libradarpkt/ar5416_radar.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/lib/libradarpkt/ar5416_radar.c Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,99 @@
+/*-
+ * Copyright (c) 2012 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <string.h> /* for memcpy() */
+
+/* Headers required for the ioctl interface */
+#include <sys/socket.h>
+#include <net/if.h>
+#include <sys/queue.h>
+
+//#include "net80211/ieee80211_var.h"
+#include "net80211/ieee80211_radiotap.h"
+
+#include "dev/ath/if_athioctl.h"
+
+#include "pkt.h"
+
+#include "ar5416_radar.h"
+
+int
+ar5416_radar_decode(struct ieee80211_radiotap_header *rh,
+ const unsigned char *pkt, int len, struct radar_entry *re)
+{
+ uint64_t tsf;
+ int8_t rssi, nf;
+ struct ath_rx_radiotap_header *rx =
+ (struct ath_rx_radiotap_header *) rh;
+
+ /* XXX we should really be implementing a real radiotap parser */
+ tsf = le64toh(rx->wr_tsf);
+
+ /*
+ * XXX For AR5416, we should use the ctl[0] RSSI for pre Owl-2.2.
+ */
+ rssi = rx->wr_v.rssi_ctl[0];
+ nf = rx->wr_antnoise;
+
+ /* Last byte is the pulse width */
+ if (len < 1) {
+ printf("short radar frame\n");
+ return (0);
+ }
+
+#if 0
+ printf("phyerr: %d ", rx->wr_v.vh_phyerr_code);
+ printf("ts: %lld", tsf);
+ printf("\tit_present: %x", le32toh(rh->it_present));
+ printf("\tlen: %d", len);
+ printf("\trssi: %d, nf: %d", rssi, nf);
+ printf("\tpri: %u", pkt[len - 1] & 0xff);
+ printf("\n");
+#endif
+
+ /*
+ * If RSSI > 0x80, it's a negative RSSI. We store it signed
+ * so we can at least log that it was negative in order to
+ * plot it. The radar code IIRC just tosses it.
+ */
+ re->re_rssi = rssi;
+
+ re->re_timestamp = tsf;
+ /* XXX TODO: re->re_freq */
+ re->re_dur = pkt[len - 1] & 0xff;
+ /* XXX TODO: also store ctl/ext RSSI, and some flags */
+ re->re_freq = 0;
+
+ return(1);
+}
Added: user/adrian/ath_radar_stuff/lib/libradarpkt/ar5416_radar.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/lib/libradarpkt/ar5416_radar.h Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+#ifndef __AR5416_RADAR_H__
+#define __AR5416_RADAR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CHIP_AR5416 1
+
+extern int ar5416_radar_decode(struct ieee80211_radiotap_header *rh,
+ const unsigned char *pkt, int len, struct radar_entry *re);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AR5416_RADAR__ */
Added: user/adrian/ath_radar_stuff/lib/libradarpkt/ar9280_radar.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/lib/libradarpkt/ar9280_radar.c Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2012 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <string.h> /* for memcpy() */
+
+#include <sys/socket.h>
+#include <net/if.h>
+
+#include "net80211/ieee80211_radiotap.h"
+
+#include "dev/ath/if_athioctl.h"
+
+#include "pkt.h"
+#include "ar9280_radar.h"
+
+/* Relevant for Sowl and later */
+#define EXT_CH_RADAR_EARLY_FOUND 0x04
+#define EXT_CH_RADAR_FOUND 0x02
+#define PRI_CH_RADAR_FOUND 0x01
+
+int
+ar9280_radar_decode(struct ieee80211_radiotap_header *rh,
+ const unsigned char *pkt, int len, struct radar_entry *re)
+{
+ uint64_t tsf;
+ int8_t comb_rssi, pri_rssi, ext_rssi, nf;
+ struct ath_rx_radiotap_header *rx =
+ (struct ath_rx_radiotap_header *) rh;
+
+ /* XXX we should really be implementing a real radiotap parser */
+ tsf = le64toh(rx->wr_tsf);
+
+ /*
+ * XXX which rssi should we use?
+ * XXX ext rssi?
+ */
+ comb_rssi = rx->wr_antsignal;
+ pri_rssi = rx->wr_v.rssi_ctl[0];
+ ext_rssi = rx->wr_v.rssi_ext[0];
+ nf = rx->wr_antnoise;
+
+ /* Last three bytes are the radar parameters */
+ if (len < 3) {
+ printf("short radar frame\n");
+ return (0);
+ }
+
+#if 0
+ printf("tsf: %lld", tsf);
+ printf(" len: %d", len);
+ printf(" rssi %d/%d", comb_rssi, nf);
+ printf(", pri/ext rssi: %d/%d", pri_rssi, ext_rssi);
+ printf(" pri: %u", pkt[len - 3] & 0xff);
+ printf(" ext: %u", pkt[len - 2] & 0xff);
+ printf(" flags: %s %s %s\n",
+ pkt[len - 1] & PRI_CH_RADAR_FOUND ? "pri" : "",
+ pkt[len - 1] & EXT_CH_RADAR_FOUND ? "ext" : "",
+ pkt[len - 1] & EXT_CH_RADAR_EARLY_FOUND ? "extearly" : ""
+ );
+#endif
+
+ re->re_timestamp = tsf;
+ re->re_rssi = comb_rssi; /* XXX extension rssi? */
+ re->re_dur = pkt[len - 3]; /* XXX extension duration? */
+ /* XXX flags? */
+ /* XXX freq? */
+
+ return(1);
+}
Added: user/adrian/ath_radar_stuff/lib/libradarpkt/ar9280_radar.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/lib/libradarpkt/ar9280_radar.h Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+#ifndef __AR9280_RADAR_H__
+#define __AR9280_RADAR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CHIP_AR9280 2
+
+extern int ar9280_radar_decode(struct ieee80211_radiotap_header *rh,
+ const unsigned char *pkt, int len, struct radar_entry *re);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AR9280_RADAR_H__ */
Added: user/adrian/ath_radar_stuff/lib/libradarpkt/pkt.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/lib/libradarpkt/pkt.h Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2012 Adrian Chadd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+#ifndef __PKTHDR_PKT_H__
+#define __PKTHDR_PKT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct radar_entry {
+ uint64_t re_timestamp;
+ uint32_t re_freq;
+ /*
+ * The hardware may give it to us as a negative number;
+ * eg CCK decode which can use self-correlation to decode
+ * a very very weak signal.
+ */
+ int32_t re_rssi;
+ uint32_t re_dur;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PKTHDR_PKT_H__ */
Added: user/adrian/ath_radar_stuff/src/pktlog/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/src/pktlog/Makefile Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,12 @@
+PROG= main
+
+X_INCS= -I../../lib/
+X_LIBS= -L../../lib/libradarpkt/
+
+SRCS= main.c
+CFLAGS+= -I/home/adrian/work/freebsd/ath/head/src/sys $(X_INCS) -g -ggdb
+LDADD+= $(X_LIBS) -lpcap -lradarpkt
+
+NO_MAN= 1
+
+.include <bsd.prog.mk>
Added: user/adrian/ath_radar_stuff/src/pktlog/main.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/src/pktlog/main.c Tue Jun 19 23:45:17 2012 (r237278)
@@ -0,0 +1,213 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include <string.h>
+#include <netinet/in.h> /* for ntohl etc */
+
+#include <pcap.h>
+
+#include "net80211/ieee80211_radiotap.h"
+
+#include "libradarpkt/pkt.h"
+#include "libradarpkt/ar5416_radar.h"
+#include "libradarpkt/ar9280_radar.h"
+
+/*
+ * Compile up a rule that's bound to be useful - it only matches on
+ * radar errors.
+ *
+ * tcpdump -ni wlan0 -y IEEE802_11_RADIO -x -X -s0 -v -ve \
+ * 'radio[73] == 0x2 && (radio[72] == 5 || radio[72] == 24)
+ */
+
+#define PKTRULE "radio[73] == 0x2 && (radio[72] == 5 || radio[72] == 24)"
+
+static int
+pkt_compile(pcap_t *p, struct bpf_program *fp)
+{
+ if (pcap_compile(p, fp, PKTRULE, 1, 0) != 0)
+ return 0;
+ return 1;
+}
+
+static void
+pkt_print(struct radar_entry *re)
+{
+ printf("ts: %llu, freq=%u, rssi=%d, dur=%d\n",
+ re->re_timestamp,
+ re->re_freq,
+ re->re_rssi,
+ re->re_dur);
+}
+
+void
+pkt_handle(int chip, const char *pkt, int len)
+{
+ struct ieee80211_radiotap_header *rh;
+ uint8_t rssi, nf;
+ struct radar_entry re;
+
+ /* XXX assume it's a radiotap frame */
+ rh = (struct ieee80211_radiotap_header *) pkt;
+
+ if (rh->it_version != 0) {
+ printf("%s: incorrect version (%d)\n", __func__,
+ rh->it_version);
+ return;
+ }
+
+#if 0
+ /* XXX short frames? */
+ if (len < 73) {
+ printf("%s: short frame (%d bytes)\n", __func__, len);
+ return;
+ }
+#endif
+
+#if 0
+ printf("%s: len=%d, present=0x%08x\n",
+ __func__,
+ (rh->it_len), /* XXX why aren't these endian-converted? */
+ (rh->it_present));
+#endif
+
+#if 0
+ /*
+ * XXX local hack - enable the radar checking
+ * XXX by assuming byte 72 is the radar status code.
+ */
+ if (pkt[72] != 5 && pkt[72] != 24) {
+ printf("%s: not a radar error (code %d)?!\n",
+ __func__,
+ pkt[72]);
+ return;
+ }
+#endif
+
+ if (chip == CHIP_AR5416)
+ ar5416_radar_decode(rh, pkt + rh->it_len, len - rh->it_len,
+ &re);
+ else if (chip == CHIP_AR9280)
+ ar9280_radar_decode(rh, pkt + rh->it_len, len - rh->it_len,
+ &re);
+
+ /*
+ * TODO: Print the summary record
+ */
+ //pkt_print(&re);
+}
+
+static pcap_t *
+open_offline(const char *fname)
+{
+ pcap_t *p;
+ char errbuf[PCAP_ERRBUF_SIZE];
+
+ p = pcap_open_offline(fname, errbuf);
+ if (p == NULL) {
+ printf("pcap_create failed: %s\n", errbuf);
+ return (NULL);
+ }
+
+ return (p);
+}
+
+static pcap_t *
+open_online(const char *ifname)
+{
+ pcap_t *p;
+ char errbuf[PCAP_ERRBUF_SIZE];
+ struct bpf_program fp;
+
+ p = pcap_open_live(ifname, 65536, 1, 1000, errbuf);
+ if (! p) {
+ err(1, "pcap_create: %s\n", errbuf);
+ return (NULL);
+ }
+
+ if (pcap_set_datalink(p, DLT_IEEE802_11_RADIO) != 0) {
+ pcap_perror(p, "pcap_set_datalink");
+ return (NULL);
+ }
+
+ /* XXX pcap_is_swapped() ? */
+
+ if (! pkt_compile(p, &fp)) {
+ pcap_perror(p, "pkg_compile compile error\n");
+ return (NULL);
+ }
+
+ if (pcap_setfilter(p, &fp) != 0) {
+ printf("pcap_setfilter failed\n");
+ return (NULL);
+ }
+
+ return (p);
+}
+
+static void
+usage(const char *progname)
+{
+
+ printf("Usage: %s <ar5416|ar9280> <file|if> <filename|ifname>\n",
+ progname);
+}
+
+int
+main(int argc, const char *argv[])
+{
+ char *dev;
+ pcap_t * p;
+ const char *fname;
+ const unsigned char *pkt;
+ struct pcap_pkthdr *hdr;
+ int len, r;
+ int chip = 0;
+
+ if (argc < 4) {
+ usage(argv[0]);
+ exit(255);
+ }
+
+ if (strcmp(argv[1], "ar5416") == 0) {
+ chip = CHIP_AR5416;
+ } else if (strcmp(argv[1], "ar9280") == 0) {
+ chip = CHIP_AR9280;
+ } else {
+ usage(argv[0]);
+ exit(255);
+ }
+
+ /* XXX verify */
+ fname = argv[3];
+
+ if (strcmp(argv[2], "file") == 0) {
+ p = open_offline(fname);
+ } else if (strcmp(argv[2], "if") == 0) {
+ p = open_online(fname);
+ } else {
+ usage(argv[0]);
+ exit(255);
+ }
+
+ if (p == NULL)
+ exit(255);
+
+ /*
+ * Iterate over frames, looking for radiotap frames
+ * which have PHY errors.
+ *
+ * XXX We should compile a filter for this, but the
+ * XXX access method is a non-standard hack atm.
+ */
+ while ((r = pcap_next_ex(p, &hdr, &pkt)) >= 0) {
+#if 0
+ printf("capture: len=%d, caplen=%d\n",
+ hdr->len, hdr->caplen);
+#endif
+ if (r > 0)
+ pkt_handle(chip, pkt, hdr->caplen);
+ }
+
+ pcap_close(p);
+}
More information about the svn-src-user
mailing list