summaryrefslogtreecommitdiff
path: root/net/tcpdump/files/extra-patch-print-802_11.c
diff options
context:
space:
mode:
authorBruce M Simpson <bms@FreeBSD.org>2004-04-03 06:24:17 +0000
committerBruce M Simpson <bms@FreeBSD.org>2004-04-03 06:24:17 +0000
commit636cf71163d6bbe046512b4f78dc31baf0bb2478 (patch)
tree16c9bd409594c82f16dbc0f8cd2a9aa927f34aae /net/tcpdump/files/extra-patch-print-802_11.c
parentAdd deskutils/phpicalendar (diff)
Update WITH_RADIOTAP patches to new endian-aware version. DLT 127 is to
be treated as little-endian. Submitted by: Sam Leffler
Diffstat (limited to 'net/tcpdump/files/extra-patch-print-802_11.c')
-rw-r--r--net/tcpdump/files/extra-patch-print-802_11.c332
1 files changed, 200 insertions, 132 deletions
diff --git a/net/tcpdump/files/extra-patch-print-802_11.c b/net/tcpdump/files/extra-patch-print-802_11.c
index 571adc13b29d..9166b213ad69 100644
--- a/net/tcpdump/files/extra-patch-print-802_11.c
+++ b/net/tcpdump/files/extra-patch-print-802_11.c
@@ -1,11 +1,8 @@
---- print-802_11.c.orig Wed Dec 10 09:52:33 2003
-+++ print-802_11.c Wed Mar 31 01:03:41 2004
-@@ -41,15 +41,20 @@
-
+--- print-802_11.c.orig Wed Dec 10 01:52:33 2003
++++ print-802_11.c Wed Mar 31 11:51:54 2004
+@@ -42,14 +42,17 @@
#include "extract.h"
-+#include "cpack.h"
-+
#include "ieee802_11.h"
+#include "ieee802_11_radio.h"
@@ -23,124 +20,38 @@
sep = " "; \
} \
if (p.rates.length != 0) \
-@@ -919,9 +924,194 @@
+@@ -919,9 +922,265 @@
return ieee802_11_print(p, h->len, h->caplen);
}
-+static int
-+print_radiotap_field(struct cpack_state *s, u_int32_t bit)
-+{
-+ union {
-+ int8_t i8;
-+ u_int8_t u8;
-+ int16_t i16;
-+ u_int16_t u16;
-+ u_int32_t u32;
-+ u_int64_t u64;
-+ } u, u2;
-+ int rc;
-+
-+ switch (bit) {
-+ case IEEE80211_RADIOTAP_FLAGS:
-+ case IEEE80211_RADIOTAP_RATE:
-+ case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
-+ case IEEE80211_RADIOTAP_DB_ANTNOISE:
-+ case IEEE80211_RADIOTAP_ANTENNA:
-+ rc = cpack_uint8(s, &u.u8);
-+ break;
-+ case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
-+ case IEEE80211_RADIOTAP_DBM_ANTNOISE:
-+ rc = cpack_int8(s, &u.i8);
-+ break;
-+ case IEEE80211_RADIOTAP_CHANNEL:
-+ rc = cpack_uint16(s, &u.u16);
-+ if (rc != 0)
-+ break;
-+ rc = cpack_uint16(s, &u2.u16);
-+ break;
-+ case IEEE80211_RADIOTAP_FHSS:
-+ case IEEE80211_RADIOTAP_LOCK_QUALITY:
-+ case IEEE80211_RADIOTAP_TX_ATTENUATION:
-+ rc = cpack_uint16(s, &u.u16);
-+ break;
-+ case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
-+ rc = cpack_uint8(s, &u.u8);
-+ break;
-+ case IEEE80211_RADIOTAP_DBM_TX_POWER:
-+ rc = cpack_uint8(s, &u.i8);
-+ break;
-+ case IEEE80211_RADIOTAP_TSFT:
-+ rc = cpack_uint64(s, &u.u64);
-+ break;
-+ default:
-+ /* this bit indicates a field whose
-+ * size we do not know, so we cannot
-+ * proceed.
-+ */
-+ printf("[0x%08x] ", bit);
-+ return -1;
-+ }
++/*
++ * Useful combinations of channel characteristics.
++ */
++#define IEEE80211_CHAN_FHSS \
++ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
++#define IEEE80211_CHAN_A \
++ (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
++#define IEEE80211_CHAN_B \
++ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
++#define IEEE80211_CHAN_PUREG \
++ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
++#define IEEE80211_CHAN_G \
++ (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
++#define IEEE80211_CHAN_T \
++ (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
+
-+ if (rc != 0) {
-+ printf("[|802.11]");
-+ return rc;
-+ }
-+
-+ switch (bit) {
-+ case IEEE80211_RADIOTAP_CHANNEL:
-+ printf("%u MHz ", u.u16);
-+ if (u2.u16 != 0)
-+ printf("(0x%04x) ", u2.u16);
-+ break;
-+ case IEEE80211_RADIOTAP_FHSS:
-+ printf("fhset %d fhpat %d ", u.u16 & 0xff, (u.u16 >> 8) & 0xff);
-+ break;
-+ case IEEE80211_RADIOTAP_RATE:
-+ PRINT_RATE("", u.u8, " Mb/s ");
-+ break;
-+ case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
-+ printf("%ddB signal ", u.i8);
-+ break;
-+ case IEEE80211_RADIOTAP_DBM_ANTNOISE:
-+ printf("%ddB noise ", u.i8);
-+ break;
-+ case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
-+ printf("%ddB signal ", u.u8);
-+ break;
-+ case IEEE80211_RADIOTAP_DB_ANTNOISE:
-+ printf("%ddB noise ", u.u8);
-+ break;
-+ case IEEE80211_RADIOTAP_LOCK_QUALITY:
-+ printf("%u sq ", u.u16);
-+ break;
-+ case IEEE80211_RADIOTAP_TX_ATTENUATION:
-+ printf("%d tx power ", -(int)u.u16);
-+ break;
-+ case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
-+ printf("%ddB tx power ", -(int)u.u8);
-+ break;
-+ case IEEE80211_RADIOTAP_DBM_TX_POWER:
-+ printf("%ddBm tx power ", u.i8);
-+ break;
-+ case IEEE80211_RADIOTAP_FLAGS:
-+ if (u.u8 & IEEE80211_RADIOTAP_F_CFP)
-+ printf("cfp ");
-+ if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE)
-+ printf("short preamble ");
-+ if (u.u8 & IEEE80211_RADIOTAP_F_WEP)
-+ printf("wep ");
-+ if (u.u8 & IEEE80211_RADIOTAP_F_FRAG)
-+ printf("fragmented ");
-+ break;
-+ case IEEE80211_RADIOTAP_ANTENNA:
-+ printf("antenna %d ", u.u8);
-+ break;
-+ case IEEE80211_RADIOTAP_TSFT:
-+ printf("%lldus tsft ", (long long)u.u64);
-+ break;
-+ }
-+ return 0;
-+}
++#define IEEE80211_IS_CHAN_FHSS(_flags) \
++ (((_flags) & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
++#define IEEE80211_IS_CHAN_A(_flags) \
++ (((_flags) & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
++#define IEEE80211_IS_CHAN_B(_flags) \
++ (((_flags) & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
++#define IEEE80211_IS_CHAN_PUREG(_flags) \
++ (((_flags) & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
++#define IEEE80211_IS_CHAN_G(_flags) \
++ (((_flags) & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
++#define IEEE80211_IS_CHAN_T(_flags) \
++ (((_flags) & IEEE80211_CHAN_T) == IEEE80211_CHAN_T)
+
static u_int
ieee802_11_radio_print(const u_char *p, u_int length, u_int caplen)
@@ -152,13 +63,43 @@
+#define BITNO_2(x) (((x) & 2) ? 1 : 0)
+#define BIT(n) (1 << n)
+
-+ struct cpack_state cpacker;
++#define CHECK_EXTRACT_LE_8BITS(_v,_bad) do { \
++ if (iter + sizeof(u_int8_t) > iterlast) { \
++ _bad; \
++ } \
++ _v = EXTRACT_LE_8BITS(iter); \
++ iter += sizeof(u_int8_t); \
++} while (0)
++#define CHECK_EXTRACT_LE_16BITS(_v,_bad) do { \
++ if (iter + sizeof(u_int16_t) > iterlast) { \
++ _bad; \
++ } \
++ _v = EXTRACT_LE_16BITS(iter); \
++ iter += sizeof(u_int16_t); \
++} while (0)
++#define CHECK_EXTRACT_LE_64BITS(_v,_bad) do { \
++ if (iter + sizeof(u_int64_t) > iterlast) { \
++ _bad; \
++ } \
++ _v = EXTRACT_LE_64BITS(iter); \
++ iter += sizeof(u_int64_t); \
++} while (0)
++
+ struct ieee80211_radiotap_header *hdr;
+ u_int32_t present, next_present;
+ u_int32_t *presentp, *last_presentp;
+ enum ieee80211_radiotap_type bit;
-+ int bit0;
-+ const u_char *iter;
++ int bit0, len;
++ const u_int8_t *iter;
++ const u_int8_t *iterlast;
++ union {
++ int8_t i8;
++ u_int8_t u8;
++ int16_t i16;
++ u_int16_t u16;
++ u_int32_t u32;
++ u_int64_t u64;
++ } u, u2;
+
+ if (caplen < sizeof(*hdr)) {
+ printf("[|802.11]");
@@ -167,14 +108,15 @@
+
+ hdr = (struct ieee80211_radiotap_header *)p;
+
-+ if (caplen < hdr->it_len) {
++ len = EXTRACT_LE_16BITS(&hdr->it_len);
++ if (caplen < len) {
+ printf("[|802.11]");
+ return caplen;
+ }
+
+ for (last_presentp = &hdr->it_present;
+ (*last_presentp & BIT(IEEE80211_RADIOTAP_EXT)) != 0 &&
-+ (u_char*)(last_presentp + 1) <= p + hdr->it_len;
++ (u_char*)(last_presentp + 1) <= p + len;
+ last_presentp++);
+
+ /* are there more bitmap extensions than bytes in header? */
@@ -184,26 +126,138 @@
+ }
+
+ iter = (u_char*)(last_presentp + 1);
-+
-+ cpack_init_in(&cpacker, (u_int8_t*)iter, hdr->it_len - (iter - p));
++ iterlast = (u_char*)(p + len);
+
+ for (bit0 = 0, presentp = &hdr->it_present; presentp <= last_presentp;
+ presentp++, bit0 += 32) {
-+ for (present = *presentp; present; present = next_present) {
++ present = EXTRACT_LE_32BITS(presentp);
++ for (; present; present = next_present) {
+ /* clear the least significant bit that is set */
+ next_present = present & (present - 1);
+
+ /* extract the least significant bit that is set */
+ bit = bit0 + BITNO_32(present ^ next_present);
+
-+ if (print_radiotap_field(&cpacker, bit) != 0)
++ switch (bit) {
++ case IEEE80211_RADIOTAP_FLAGS:
++ case IEEE80211_RADIOTAP_RATE:
++ case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
++ case IEEE80211_RADIOTAP_DB_ANTNOISE:
++ case IEEE80211_RADIOTAP_ANTENNA:
++ case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
++ CHECK_EXTRACT_LE_8BITS(u.u8, goto bad);
++ break;
++ case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
++ case IEEE80211_RADIOTAP_DBM_ANTNOISE:
++ case IEEE80211_RADIOTAP_DBM_TX_POWER:
++ CHECK_EXTRACT_LE_8BITS(u.i8, goto bad);
++ break;
++ case IEEE80211_RADIOTAP_FHSS:
++ case IEEE80211_RADIOTAP_LOCK_QUALITY:
++ case IEEE80211_RADIOTAP_TX_ATTENUATION:
++ case IEEE80211_RADIOTAP_CHANNEL:
++ CHECK_EXTRACT_LE_16BITS(u.u16, goto bad);
++ if (bit == IEEE80211_RADIOTAP_CHANNEL)
++ CHECK_EXTRACT_LE_16BITS(u2.u16,
++ goto bad);
++ break;
++ case IEEE80211_RADIOTAP_TSFT:
++ CHECK_EXTRACT_LE_64BITS(u.u64, goto bad);
++ break;
++ default:
++ /* this bit indicates a field whose
++ * size we do not know, so we cannot
++ * proceed.
++ */
++ printf("[0x%08x] ", bit);
++ return -1;
++ bad:
++ /*
++ * There wasn't enough data for the
++ * data type; stop decoding.
++ */
++ printf("[|802.11]");
+ goto out;
++ }
++
++ switch (bit) {
++ case IEEE80211_RADIOTAP_CHANNEL:
++ printf("%u MHz ", u.u16);
++ if (u2.u16 != 0) {
++ /* use flags to disambiguate */
++ if (IEEE80211_IS_CHAN_G(u2.u16) ||
++ IEEE80211_IS_CHAN_PUREG(u2.u16))
++ printf("(11g) ", u2.u16);
++ else if (IEEE80211_IS_CHAN_T(u2.u16))
++ printf("(turbo) ", u2.u16);
++ else if (IEEE80211_IS_CHAN_B(u2.u16))
++ ;
++ else if (IEEE80211_IS_CHAN_A(u2.u16))
++ ;
++ else if (IEEE80211_IS_CHAN_FHSS(u2.u16))
++ ;
++ else
++ printf("(0x%04x) ", u2.u16);
++ }
++ break;
++ case IEEE80211_RADIOTAP_FHSS:
++ printf("fhset %d fhpat %d ",
++ u.u16 & 0xff, (u.u16 >> 8) & 0xff);
++ break;
++ case IEEE80211_RADIOTAP_RATE:
++ PRINT_RATE("", u.u8, " Mb/s ");
++ break;
++ case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
++ printf("%ddB signal ", u.i8);
++ break;
++ case IEEE80211_RADIOTAP_DBM_ANTNOISE:
++ printf("%ddB noise ", u.i8);
++ break;
++ case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
++ printf("%ddB signal ", u.u8);
++ break;
++ case IEEE80211_RADIOTAP_DB_ANTNOISE:
++ printf("%ddB noise ", u.u8);
++ break;
++ case IEEE80211_RADIOTAP_LOCK_QUALITY:
++ printf("%u sq ", u.u16);
++ break;
++ case IEEE80211_RADIOTAP_TX_ATTENUATION:
++ printf("%d tx power ", -(int)u.u16);
++ break;
++ case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
++ printf("%ddB tx power ", -(int)u.u8);
++ break;
++ case IEEE80211_RADIOTAP_DBM_TX_POWER:
++ printf("%ddBm tx power ", u.i8);
++ break;
++ case IEEE80211_RADIOTAP_FLAGS:
++ if (u.u8 & IEEE80211_RADIOTAP_F_CFP)
++ printf("cfp ");
++ if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE)
++ printf("short preamble ");
++ if (u.u8 & IEEE80211_RADIOTAP_F_WEP)
++ printf("wep ");
++ if (u.u8 & IEEE80211_RADIOTAP_F_FRAG)
++ printf("fragmented ");
++ break;
++ case IEEE80211_RADIOTAP_ANTENNA:
++ printf("antenna %d ", u.u8);
++ break;
++ case IEEE80211_RADIOTAP_TSFT:
++ printf("%lldus tsft ", (long long)u.u64);
++ break;
++ }
+ }
+ }
+out:
+
-+ return hdr->it_len + ieee802_11_print(p + hdr->it_len,
-+ length - hdr->it_len, caplen - hdr->it_len);
++ return len + ieee802_11_print(p + len, length - len, caplen - len);
++
++#undef CHECK_EXTRACT_8BITS
++#undef CHECK_EXTRACT_LE_16BITS
++#undef CHECK_EXTRACT_LE_64BITS
++
+#undef BITNO_32
+#undef BITNO_16
+#undef BITNO_8
@@ -212,13 +266,27 @@
+#undef BIT
+}
+
++#undef IEEE80211_CHAN_FHSS
++#undef IEEE80211_CHAN_A
++#undef IEEE80211_CHAN_B
++#undef IEEE80211_CHAN_PUREG
++#undef IEEE80211_CHAN_G
++#undef IEEE80211_CHAN_T
++
++#undef IEEE80211_IS_CHAN_FHSS
++#undef IEEE80211_IS_CHAN_A
++#undef IEEE80211_IS_CHAN_B
++#undef IEEE80211_IS_CHAN_PUREG
++#undef IEEE80211_IS_CHAN_G
++#undef IEEE80211_IS_CHAN_T
++
+static u_int
+ieee802_11_avs_radio_print(const u_char *p, u_int length, u_int caplen)
+{
u_int32_t caphdr_len;
caphdr_len = EXTRACT_32BITS(p + 4);
-@@ -972,7 +1162,7 @@
+@@ -972,7 +1231,7 @@
}
if (EXTRACT_32BITS(p) == WLANCAP_MAGIC_COOKIE_V1)