Date: Fri, 4 Jan 2013 06:29:53 +0000 (UTC) From: Adrian Chadd <adrian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r245032 - user/adrian/ath_radar_stuff/src/pktlog Message-ID: <201301040629.r046TrTE070510@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: adrian Date: Fri Jan 4 06:29:52 2013 New Revision: 245032 URL: http://svnweb.freebsd.org/changeset/base/245032 Log: Add some logic to pull out the XCHANNEL field from the radiotap header and decode it. The -HEAD driver now includes the correct xchan flags for PHY errors, so I can figure out whether it's a HT20/HT40 configured channel. Added: user/adrian/ath_radar_stuff/src/pktlog/chan.c user/adrian/ath_radar_stuff/src/pktlog/chan.h Modified: user/adrian/ath_radar_stuff/src/pktlog/Makefile user/adrian/ath_radar_stuff/src/pktlog/main.c Modified: user/adrian/ath_radar_stuff/src/pktlog/Makefile ============================================================================== --- user/adrian/ath_radar_stuff/src/pktlog/Makefile Fri Jan 4 06:28:34 2013 (r245031) +++ user/adrian/ath_radar_stuff/src/pktlog/Makefile Fri Jan 4 06:29:52 2013 (r245032) @@ -3,7 +3,7 @@ PROG= main X_INCS= -I../../lib/ X_LIBS= -L../../lib/libradarpkt/ -SRCS= main.c +SRCS= main.c chan.c radiotap.c CFLAGS+= -I/home/adrian/work/freebsd/ath/head/src/sys $(X_INCS) -g -ggdb \ -DATH_ENABLE_RADIOTAP_VENDOR_EXT LDADD+= $(X_LIBS) -lpcap -lradarpkt Added: user/adrian/ath_radar_stuff/src/pktlog/chan.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/adrian/ath_radar_stuff/src/pktlog/chan.c Fri Jan 4 06:29:52 2013 (r245032) @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "radiotap.h" +#include "radiotap_iter.h" + +#include "chan.h" + +int +pkt_lookup_chan(const char *buf, int len, struct xchan *x) +{ + struct ieee80211_radiotap_iterator iter; + int err; + + bzero(&iter, sizeof(iter)); + + err = ieee80211_radiotap_iterator_init(&iter, (void *) buf, len, NULL); + if (err < 0) { + printf("%s: ieee80211_radiotap_iterator_init: failed; err=%d\n", + __func__, + err); + return (-1); + } + + /* Iterate over, looping for the xchannel struct */ + while (!(err = ieee80211_radiotap_iterator_next(&iter))) { + if (iter.is_radiotap_ns) { + if (iter.this_arg_index == IEEE80211_RADIOTAP_XCHANNEL) { + /* XXX endian! */ + memcpy(x, iter.this_arg, 8); + return (0); + } + } + } + return (-1); +} Added: user/adrian/ath_radar_stuff/src/pktlog/chan.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/adrian/ath_radar_stuff/src/pktlog/chan.h Fri Jan 4 06:29:52 2013 (r245032) @@ -0,0 +1,17 @@ +#ifndef __CHAN_H__ +#define __CHAN_H__ + + +struct xchan { + /* DWORD 0 */ + uint32_t flags; + /* DWORD 1 */ + uint16_t freq; + uint8_t chan; + uint8_t txpow; +}; + + +extern int pkt_lookup_chan(const char *buf, int len, struct xchan *x); + +#endif Modified: user/adrian/ath_radar_stuff/src/pktlog/main.c ============================================================================== --- user/adrian/ath_radar_stuff/src/pktlog/main.c Fri Jan 4 06:28:34 2013 (r245031) +++ user/adrian/ath_radar_stuff/src/pktlog/main.c Fri Jan 4 06:29:52 2013 (r245032) @@ -14,6 +14,17 @@ #include "libradarpkt/ar5416_radar.h" #include "libradarpkt/ar9280_radar.h" +#include "chan.h" + +/* from _ieee80211.h */ +#define IEEE80211_CHAN_HT40U 0x00020000 /* HT 40 channel w/ ext above */ +#define IEEE80211_CHAN_HT40D 0x00040000 /* HT 40 channel w/ ext below */ + +// non-HT +// 0x00200140 +// HT, not HT40 +// 0x00210140 + /* * Compile up a rule that's bound to be useful - it only matches on * radar errors. @@ -35,9 +46,11 @@ pkt_compile(pcap_t *p, struct bpf_progra static void pkt_print(struct radar_entry *re) { - printf("ts: %llu, freq=%u, rssi=%d, dur=%d\n", + printf("ts: %llu, freq=%u, freqsec=%d, chwidth=%d, rssi=%d, dur=%d\n", re->re_timestamp, re->re_freq, + re->re_freq_sec, + re->re_freqwidth, re->re_rssi, re->re_dur); } @@ -49,6 +62,7 @@ pkt_handle(int chip, const char *pkt, in uint8_t rssi, nf; struct radar_entry re; int r; + struct xchan x; /* XXX assume it's a radiotap frame */ rh = (struct ieee80211_radiotap_header *) pkt; @@ -86,6 +100,16 @@ pkt_handle(int chip, const char *pkt, in return; } #endif + + /* + * Do a frequency lookup. + */ + /* XXX rh->it_len should be endian checked?! */ + if (pkt_lookup_chan((char *) pkt, len, &x) != 0) { + printf("%s: channel lookup failed\n", __func__); + return; + } + if (chip == CHIP_AR5212) r = ar5212_radar_decode(rh, pkt + rh->it_len, len - rh->it_len, &re); @@ -96,11 +120,32 @@ pkt_handle(int chip, const char *pkt, in r = ar9280_radar_decode(rh, pkt + rh->it_len, len - rh->it_len, &re); + /* Update the channel/frequency information */ + re.re_freq = x.freq; + + if (x.flags & IEEE80211_CHAN_QUARTER) { + re.re_freq_sec = 0; + re.re_freqwidth = 5; + } else if (x.flags & IEEE80211_CHAN_HALF) { + re.re_freq_sec = 0; + re.re_freqwidth = 10; + } else if (x.flags & IEEE80211_CHAN_HT40U) { + re.re_freq_sec = re.re_freq + 20; + re.re_freqwidth = 40; + } else if (x.flags & IEEE80211_CHAN_HT40D) { + re.re_freq_sec = re.re_freq - 20; + re.re_freqwidth = 40; + } else { + re.re_freq_sec = 0; + re.re_freqwidth = 20; + } + /* * TODO: Print the summary record */ - if (r) + if (r) { pkt_print(&re); + } } static pcap_t *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301040629.r046TrTE070510>