about summary refs log tree commit diff stats
path: root/utils/src/test_parsing.c
diff options
context:
space:
mode:
authorMarc <marc@malloc.me>2022-09-10 20:18:18 +0100
committerMarc <marc@malloc.me>2022-09-10 20:18:18 +0100
commit7c2b373bf37186fd94fdc1d46393780e46f646a8 (patch)
treec424e584658ee3fdcf0f0c0d3466f2906681577b /utils/src/test_parsing.c
parent18b3f897df1d17e9d140fb24b7bad4bdd2b849f1 (diff)
downloadlibwifi-7c2b373bf37186fd94fdc1d46393780e46f646a8.tar.gz
libwifi-7c2b373bf37186fd94fdc1d46393780e46f646a8.tar.bz2
libwifi-7c2b373bf37186fd94fdc1d46393780e46f646a8.zip
core/parse: Better handling of Radiotap information
Radiotap information is now stored in the `libwifi_frame` struct, and will
be kept automatically in `libwifi_frame.radiotap_info` for the lifecycle of
said frame, if it is present.

A new flag has been added for the frame for use with `libwifi_frame.flags`
to detect if the radiotap info is present: `LIBWIFI_FLAGS_RADIOTAP_PRESENT`.

The frame parser will now automatically calculate the band and center channel
from radiotap data, and will store them in `libwifi_radiotap_info.channel.center`
and `libwifi_radiotap_info.channel.band`.

Four new flags have been added for use with the new radiotap band field:
- `LIBWIFI_RADIOTAP_BAND_2GHZ`
- `LIBWIFI_RADIOTAP_BAND_5GHZ`
- `LIBWIFI_RADIOTAP_BAND_6GHZ`
- `LIBWIFI_RADIOTAP_BAND_900MHZ`

These can be used with a binary AND:
`if (rtap.channel.band & LIBWIFI_RADIOTAP_BAND_6GHZ) { }`
Diffstat (limited to 'utils/src/test_parsing.c')
-rw-r--r--utils/src/test_parsing.c84
1 files changed, 31 insertions, 53 deletions
diff --git a/utils/src/test_parsing.c b/utils/src/test_parsing.c index b9f9dbc..b5e2d53 100644 --- a/utils/src/test_parsing.c +++ b/utils/src/test_parsing.c
@@ -132,26 +132,36 @@ void print_tag_info(unsigned char *data, size_t data_len) {
132 } while (libwifi_tag_iterator_next(&it) != -1); 132 } while (libwifi_tag_iterator_next(&it) != -1);
133} 133}
134 134
135void parse_radiotap(const unsigned char *packet, size_t packet_len) { 135void parse_radiotap(const struct libwifi_frame *frame) {
136 struct libwifi_radiotap_info rtap_info; 136 const struct libwifi_radiotap_info *rtap_info = frame->radiotap_info;
137 libwifi_parse_radiotap_info(&rtap_info, packet, packet_len);
138 137
139 printf("=== Radiotap Parsing ===\n"); 138 printf("=== Radiotap Parsing ===\n");
140 printf("Radiotap Channel: %d\n", rtap_info.channel.freq); 139 printf("Radiotap Channel Freq: %d MHz\n", rtap_info->channel.freq);
141 printf("Radiotap Channel Flags: 0x%04x\n", rtap_info.channel.flags); 140 printf("Radiotap Freq Band: ");
142 printf("Radiotap Rate: %.2f Mb/s\n", rtap_info.rate); 141 if (rtap_info->channel.band & LIBWIFI_RADIOTAP_BAND_2GHZ) {
143 printf("Radiotap Rate Raw: 0x%02x\n", rtap_info.rate_raw); 142 printf("2.4 GHz\n");
144 printf("Radiotap Signal: %d dBm\n", rtap_info.signal); 143 } else if (rtap_info->channel.band & LIBWIFI_RADIOTAP_BAND_5GHZ) {
145 for (int i = 0; i < rtap_info.antenna_count; i++) { 144 printf("5 GHz\n");
146 printf("Radiotap Antenna %d: %d dBm\n", rtap_info.antennas[i].antenna_number, rtap_info.antennas[i].signal); 145 } else if (rtap_info->channel.band & LIBWIFI_RADIOTAP_BAND_6GHZ) {
146 printf("6 GHz\n");
147 } else {
148 printf("Unknown Band\n");
149 }
150 printf("Radiotap Channel: %d\n", rtap_info->channel.center);
151 printf("Radiotap Channel Flags: 0x%04x\n", rtap_info->channel.flags);
152 printf("Radiotap Rate: %.2f Mb/s\n", rtap_info->rate);
153 printf("Radiotap Rate Raw: 0x%02x\n", rtap_info->rate_raw);
154 printf("Radiotap Signal: %d dBm\n", rtap_info->signal);
155 for (int i = 0; i < rtap_info->antenna_count; i++) {
156 printf("Radiotap Antenna %d: %d dBm\n", rtap_info->antennas[i].antenna_number, rtap_info->antennas[i].signal);
147 } 157 }
148 printf("Radiotap Flags: 0x%04x\n", rtap_info.flags); 158 printf("Radiotap Flags: 0x%04x\n", rtap_info->flags);
149 printf("Radiotap Extended Flags: 0x%08x\n", rtap_info.extended_flags); 159 printf("Radiotap Extended Flags: 0x%08x\n", rtap_info->extended_flags);
150 printf("Radiotap RX Flags: 0x%04x\n", rtap_info.rx_flags); 160 printf("Radiotap RX Flags: 0x%04x\n", rtap_info->rx_flags);
151 printf("Radiotap TX Flags: 0x%04x\n", rtap_info.tx_flags); 161 printf("Radiotap TX Flags: 0x%04x\n", rtap_info->tx_flags);
152 printf("Radiotap TX Power: %d\n", rtap_info.tx_power); 162 printf("Radiotap TX Power: %d\n", rtap_info->tx_power);
153 printf("Radiotap RTS Retries: %d\n", rtap_info.rts_retries); 163 printf("Radiotap RTS Retries: %d\n", rtap_info->rts_retries);
154 printf("Radiotap Data Retries: %d\n", rtap_info.data_retries); 164 printf("Radiotap Data Retries: %d\n", rtap_info->data_retries);
155 printf("=== Radiotap End ===\n"); 165 printf("=== Radiotap End ===\n");
156} 166}
157 167
@@ -165,10 +175,6 @@ void parse_beacon(struct libwifi_frame frame, unsigned char *args, const struct
165 return; 175 return;
166 } 176 }
167 177
168 if (got_radiotap && parse_radiotap_header) {
169 parse_radiotap(packet, header->caplen);
170 }
171
172 print_bss_info(&bss); 178 print_bss_info(&bss);
173 } 179 }
174} 180}
@@ -183,10 +189,6 @@ void parse_probe_request(struct libwifi_frame frame, unsigned char *args, const
183 return; 189 return;
184 } 190 }
185 191
186 if (got_radiotap && parse_radiotap_header) {
187 parse_radiotap(packet, header->caplen);
188 }
189
190 print_sta_info(&sta); 192 print_sta_info(&sta);
191 } 193 }
192} 194}
@@ -200,10 +202,6 @@ void parse_probe_response(struct libwifi_frame frame, unsigned char *args, const
200 return; 202 return;
201 } 203 }
202 204
203 if (got_radiotap && parse_radiotap_header) {
204 parse_radiotap(packet, header->caplen);
205 }
206
207 print_bss_info(&bss); 205 print_bss_info(&bss);
208 } 206 }
209} 207}
@@ -218,10 +216,6 @@ void parse_deauth(struct libwifi_frame frame, unsigned char *args, const struct
218 return; 216 return;
219 } 217 }
220 218
221 if (got_radiotap && parse_radiotap_header) {
222 parse_radiotap(packet, header->caplen);
223 }
224
225 printf("=== Deauthentication Frame ===\n"); 219 printf("=== Deauthentication Frame ===\n");
226 if (deauth.ordered) { 220 if (deauth.ordered) {
227 printf("Address 1: " MACSTR "\n", MAC2STR(deauth.frame_header.ordered.addr1)); 221 printf("Address 1: " MACSTR "\n", MAC2STR(deauth.frame_header.ordered.addr1));
@@ -257,10 +251,6 @@ void parse_disassoc(struct libwifi_frame frame, unsigned char *args, const struc
257 return; 251 return;
258 } 252 }
259 253
260 if (got_radiotap && parse_radiotap_header) {
261 parse_radiotap(packet, header->caplen);
262 }
263
264 printf("=== Disassociation Frame ===\n"); 254 printf("=== Disassociation Frame ===\n");
265 if (disassoc.ordered) { 255 if (disassoc.ordered) {
266 printf("Address 1: " MACSTR "\n", MAC2STR(disassoc.frame_header.ordered.addr1)); 256 printf("Address 1: " MACSTR "\n", MAC2STR(disassoc.frame_header.ordered.addr1));
@@ -295,10 +285,6 @@ void parse_assoc_request(struct libwifi_frame frame, unsigned char *args, const
295 return; 285 return;
296 } 286 }
297 287
298 if (got_radiotap && parse_radiotap_header) {
299 parse_radiotap(packet, header->caplen);
300 }
301
302 print_sta_info(&sta); 288 print_sta_info(&sta);
303 } 289 }
304} 290}
@@ -312,10 +298,6 @@ void parse_assoc_response(struct libwifi_frame frame, unsigned char *args, const
312 return; 298 return;
313 } 299 }
314 300
315 if (got_radiotap && parse_radiotap_header) {
316 parse_radiotap(packet, header->caplen);
317 }
318
319 print_bss_info(&bss); 301 print_bss_info(&bss);
320 } 302 }
321} 303}
@@ -329,10 +311,6 @@ void parse_reassoc_request(struct libwifi_frame frame, unsigned char *args, cons
329 return; 311 return;
330 } 312 }
331 313
332 if (got_radiotap && parse_radiotap_header) {
333 parse_radiotap(packet, header->caplen);
334 }
335
336 print_sta_info(&sta); 314 print_sta_info(&sta);
337 } 315 }
338} 316}
@@ -346,10 +324,6 @@ void parse_reassoc_response(struct libwifi_frame frame, unsigned char *args, con
346 return; 324 return;
347 } 325 }
348 326
349 if (got_radiotap && parse_radiotap_header) {
350 parse_radiotap(packet, header->caplen);
351 }
352
353 print_bss_info(&bss); 327 print_bss_info(&bss);
354 } 328 }
355} 329}
@@ -427,6 +401,10 @@ void parse_packet(unsigned char *args, const struct pcap_pkthdr *header, const u
427 return; 401 return;
428 } 402 }
429 403
404 if (got_radiotap && parse_radiotap_header && frame.flags & LIBWIFI_FLAGS_RADIOTAP_PRESENT) {
405 parse_radiotap(&frame);
406 }
407
430 memset(&bss, 0, sizeof(struct libwifi_bss)); 408 memset(&bss, 0, sizeof(struct libwifi_bss));
431 memset(&sta, 0, sizeof(struct libwifi_sta)); 409 memset(&sta, 0, sizeof(struct libwifi_sta));
432 410