channel-switch: use sys/ioctl.h instead of stropts.h
[rofl0r-MacGeiger.git] / radiotap_flags.h
blob1df4136b61d4e3d2a6d592e9086c259fa451c171
1 #ifndef RADIOTAP_FLAGS_H
2 #define RADIOTAP_FLAGS_H
4 /* (C) 2014 - 2017 rofl0r
5 released under the public domain.
6 */
8 #include <stdint.h>
10 /* prevent redefining the same types when the official radiotap
11 header is in use too */
12 #ifndef IEEE80211RADIOTAP_H
14 struct ieee80211_radiotap_header {
15 uint8_t it_version;
16 uint8_t it_pad;
17 uint16_t it_len;
18 uint32_t it_present;
21 enum ieee80211_radiotap_type {
22 IEEE80211_RADIOTAP_TSFT = 0,
23 IEEE80211_RADIOTAP_FLAGS = 1,
24 IEEE80211_RADIOTAP_RATE = 2,
25 IEEE80211_RADIOTAP_CHANNEL = 3,
26 IEEE80211_RADIOTAP_FHSS = 4,
27 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
28 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
29 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
30 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
31 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
32 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
33 IEEE80211_RADIOTAP_ANTENNA = 11,
34 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
35 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
36 IEEE80211_RADIOTAP_RX_FLAGS = 14,
37 IEEE80211_RADIOTAP_TX_FLAGS = 15,
38 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
39 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
40 IEEE80211_RADIOTAP_XCHANNEL = 18,
41 IEEE80211_RADIOTAP_MCS = 19,
42 IEEE80211_RADIOTAP_AMPDU_STATUS = 20,
43 IEEE80211_RADIOTAP_VHT = 21,
44 IEEE80211_RADIOTAP_TIMESTAMP = 22,
45 IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29,
46 IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
47 IEEE80211_RADIOTAP_EXT = 31
50 #endif
52 static const unsigned char ieee80211_radiotap_type_size[] = {
53 [IEEE80211_RADIOTAP_TSFT] = 8,
54 [IEEE80211_RADIOTAP_FLAGS] = 1,
55 [IEEE80211_RADIOTAP_RATE] = 1,
56 [IEEE80211_RADIOTAP_CHANNEL] = 2*2,
57 [IEEE80211_RADIOTAP_FHSS] = 2,
58 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 1,
59 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 1,
60 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 2,
61 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 2,
62 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 2,
63 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 1,
64 [IEEE80211_RADIOTAP_ANTENNA] = 1,
65 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 1,
66 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 1,
67 [IEEE80211_RADIOTAP_RX_FLAGS] = 2,
68 [IEEE80211_RADIOTAP_TX_FLAGS] = 2,
69 [IEEE80211_RADIOTAP_RTS_RETRIES] = 1,
70 [IEEE80211_RADIOTAP_DATA_RETRIES] = 1,
71 [IEEE80211_RADIOTAP_MCS] = 1+1+1,
72 [IEEE80211_RADIOTAP_AMPDU_STATUS] = 4+2+1+1,
73 [IEEE80211_RADIOTAP_VHT] = 12,
74 [IEEE80211_RADIOTAP_TIMESTAMP] = 12,
77 static const unsigned char ieee80211_radiotap_type_align[] = {
78 [IEEE80211_RADIOTAP_TSFT] = 8,
79 [IEEE80211_RADIOTAP_FLAGS] = 1,
80 [IEEE80211_RADIOTAP_RATE] = 1,
81 [IEEE80211_RADIOTAP_CHANNEL] = 2,
82 [IEEE80211_RADIOTAP_FHSS] = 2,
83 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 1,
84 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 1,
85 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 2,
86 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 2,
87 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 2,
88 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 1,
89 [IEEE80211_RADIOTAP_ANTENNA] = 1,
90 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 1,
91 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 1,
92 [IEEE80211_RADIOTAP_RX_FLAGS] = 2,
93 [IEEE80211_RADIOTAP_TX_FLAGS] = 2,
94 [IEEE80211_RADIOTAP_RTS_RETRIES] = 1,
95 [IEEE80211_RADIOTAP_DATA_RETRIES] = 1,
96 [IEEE80211_RADIOTAP_MCS] = 1,
97 [IEEE80211_RADIOTAP_AMPDU_STATUS] = 4,
98 [IEEE80211_RADIOTAP_VHT] = 2,
99 [IEEE80211_RADIOTAP_TIMESTAMP] = 8,
102 /* get offset of the specified flag, starting from start_off */
103 static uint32_t rt_get_flag_offset(uint32_t pflags, uint32_t which, uint32_t start_off)
105 unsigned i,c=start_off;
106 for(i=0;i<which;i++) if(pflags & (1U << i)) {
107 c+= c & (ieee80211_radiotap_type_align[i]-1);
108 c+= ieee80211_radiotap_type_size[i];
110 return c;
113 #include <string.h>
115 #include "endianness.h"
117 /* get present flags and offset of just after the radiotap header end.
118 returns 1 on succes, 0 on bogus data */
119 static int rt_get_presentflags(const void *data, size_t len, uint32_t *pflags, uint32_t *offset)
121 const struct ieee80211_radiotap_header* rh = data;
122 *offset = sizeof(*rh);
123 uint32_t fc = *pflags = end_le32toh(rh->it_present);
124 while(fc & (1U << IEEE80211_RADIOTAP_EXT)) {
125 if (*offset > len - 4) return 0;
126 memcpy(&fc, data + *offset, 4);
127 fc = end_le32toh(fc);
128 *offset += 4;
130 return 1;
133 #endif