Bug Summary

File:src/usr.sbin/hostapd/print-802_11.c
Warning:line 623, column 3
Value stored to 't' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name print-802_11.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/hostapd/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/hostapd -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/hostapd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/usr.sbin/hostapd/print-802_11.c
1/* $OpenBSD: print-802_11.c,v 1.11 2019/05/10 01:29:31 guenther Exp $ */
2
3/*
4 * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19/* usr.sbin/tcpdump/print-802_11.c,v 1.3 2005/03/09 11:43:17 deraadt Exp */
20
21#include <sys/time.h>
22#include <sys/socket.h>
23
24#include <net/if.h>
25#include <net/if_media.h>
26#include <net/if_arp.h>
27#include <net/if_llc.h>
28#include <net/bpf.h>
29
30#include <netinet/in.h>
31#include <netinet/if_ether.h>
32#include <arpa/inet.h>
33
34#include <net80211/ieee80211.h>
35#include <net80211/ieee80211_radiotap.h>
36
37#include <pcap.h>
38#include <stdio.h>
39#include <string.h>
40#include <limits.h>
41
42#include "hostapd.h"
43
44const char *ieee80211_mgt_subtype_name[] = {
45 "association request",
46 "association response",
47 "reassociation request",
48 "reassociation response",
49 "probe request",
50 "probe response",
51 "reserved#6",
52 "reserved#7",
53 "beacon",
54 "atim",
55 "disassociation",
56 "authentication",
57 "deauthentication",
58 "reserved#13",
59 "reserved#14",
60 "reserved#15"
61};
62
63const u_int8_t *snapend;
64int vflag = 1, eflag = 1;
65
66int ieee80211_hdr(struct ieee80211_frame *);
67void ieee80211_print_element(u_int8_t *, u_int);
68void ieee80211_print_essid(u_int8_t *, u_int);
69int ieee80211_elements(struct ieee80211_frame *);
70int ieee80211_frame(struct ieee80211_frame *);
71int ieee80211_print(struct ieee80211_frame *);
72u_int ieee80211_any2ieee(u_int, u_int);
73void ieee802_11_if_print(u_int8_t *, u_int);
74void ieee802_11_radio_if_print(u_int8_t *, u_int);
75
76#define TCARR(a)if (!( snapend - (sizeof(a)) <= snapend && (const u_char
*)&(*a) <= snapend - (sizeof(a)) )) goto trunc
TCHECK2(*a, sizeof(a))if (!( snapend - (sizeof(a)) <= snapend && (const u_char
*)&(*a) <= snapend - (sizeof(a)) )) goto trunc
77
78int
79ieee80211_hdr(struct ieee80211_frame *wh)
80{
81 struct ieee80211_frame_addr4 *w4;
82
83 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK0x03) {
84 case IEEE80211_FC1_DIR_NODS0x00:
85 TCARR(wh->i_addr2)if (!( snapend - (sizeof(wh->i_addr2)) <= snapend &&
(const u_char *)&(*wh->i_addr2) <= snapend - (sizeof
(wh->i_addr2)) )) goto trunc
;
86 PRINTFhostapd_printf("%s", etheraddr_string(wh->i_addr2)ether_ntoa((struct ether_addr*)wh->i_addr2));
87 TCARR(wh->i_addr1)if (!( snapend - (sizeof(wh->i_addr1)) <= snapend &&
(const u_char *)&(*wh->i_addr1) <= snapend - (sizeof
(wh->i_addr1)) )) goto trunc
;
88 PRINTFhostapd_printf(" > %s", etheraddr_string(wh->i_addr1)ether_ntoa((struct ether_addr*)wh->i_addr1));
89 TCARR(wh->i_addr3)if (!( snapend - (sizeof(wh->i_addr3)) <= snapend &&
(const u_char *)&(*wh->i_addr3) <= snapend - (sizeof
(wh->i_addr3)) )) goto trunc
;
90 PRINTFhostapd_printf(", bssid %s", etheraddr_string(wh->i_addr3)ether_ntoa((struct ether_addr*)wh->i_addr3));
91 break;
92 case IEEE80211_FC1_DIR_TODS0x01:
93 TCARR(wh->i_addr2)if (!( snapend - (sizeof(wh->i_addr2)) <= snapend &&
(const u_char *)&(*wh->i_addr2) <= snapend - (sizeof
(wh->i_addr2)) )) goto trunc
;
94 PRINTFhostapd_printf("%s", etheraddr_string(wh->i_addr2)ether_ntoa((struct ether_addr*)wh->i_addr2));
95 TCARR(wh->i_addr3)if (!( snapend - (sizeof(wh->i_addr3)) <= snapend &&
(const u_char *)&(*wh->i_addr3) <= snapend - (sizeof
(wh->i_addr3)) )) goto trunc
;
96 PRINTFhostapd_printf(" > %s", etheraddr_string(wh->i_addr3)ether_ntoa((struct ether_addr*)wh->i_addr3));
97 TCARR(wh->i_addr1)if (!( snapend - (sizeof(wh->i_addr1)) <= snapend &&
(const u_char *)&(*wh->i_addr1) <= snapend - (sizeof
(wh->i_addr1)) )) goto trunc
;
98 PRINTFhostapd_printf(", bssid %s, > DS", etheraddr_string(wh->i_addr1)ether_ntoa((struct ether_addr*)wh->i_addr1));
99 break;
100 case IEEE80211_FC1_DIR_FROMDS0x02:
101 TCARR(wh->i_addr3)if (!( snapend - (sizeof(wh->i_addr3)) <= snapend &&
(const u_char *)&(*wh->i_addr3) <= snapend - (sizeof
(wh->i_addr3)) )) goto trunc
;
102 PRINTFhostapd_printf("%s", etheraddr_string(wh->i_addr3)ether_ntoa((struct ether_addr*)wh->i_addr3));
103 TCARR(wh->i_addr1)if (!( snapend - (sizeof(wh->i_addr1)) <= snapend &&
(const u_char *)&(*wh->i_addr1) <= snapend - (sizeof
(wh->i_addr1)) )) goto trunc
;
104 PRINTFhostapd_printf(" > %s", etheraddr_string(wh->i_addr1)ether_ntoa((struct ether_addr*)wh->i_addr1));
105 TCARR(wh->i_addr2)if (!( snapend - (sizeof(wh->i_addr2)) <= snapend &&
(const u_char *)&(*wh->i_addr2) <= snapend - (sizeof
(wh->i_addr2)) )) goto trunc
;
106 PRINTFhostapd_printf(", bssid %s, DS >", etheraddr_string(wh->i_addr2)ether_ntoa((struct ether_addr*)wh->i_addr2));
107 break;
108 case IEEE80211_FC1_DIR_DSTODS0x03:
109 w4 = (struct ieee80211_frame_addr4 *) wh;
110 TCARR(w4->i_addr4)if (!( snapend - (sizeof(w4->i_addr4)) <= snapend &&
(const u_char *)&(*w4->i_addr4) <= snapend - (sizeof
(w4->i_addr4)) )) goto trunc
;
111 PRINTFhostapd_printf("%s", etheraddr_string(w4->i_addr4)ether_ntoa((struct ether_addr*)w4->i_addr4));
112 TCARR(w4->i_addr3)if (!( snapend - (sizeof(w4->i_addr3)) <= snapend &&
(const u_char *)&(*w4->i_addr3) <= snapend - (sizeof
(w4->i_addr3)) )) goto trunc
;
113 PRINTFhostapd_printf(" > %s", etheraddr_string(w4->i_addr3)ether_ntoa((struct ether_addr*)w4->i_addr3));
114 TCARR(w4->i_addr2)if (!( snapend - (sizeof(w4->i_addr2)) <= snapend &&
(const u_char *)&(*w4->i_addr2) <= snapend - (sizeof
(w4->i_addr2)) )) goto trunc
;
115 PRINTFhostapd_printf(", bssid %s", etheraddr_string(w4->i_addr2)ether_ntoa((struct ether_addr*)w4->i_addr2));
116 TCARR(w4->i_addr1)if (!( snapend - (sizeof(w4->i_addr1)) <= snapend &&
(const u_char *)&(*w4->i_addr1) <= snapend - (sizeof
(w4->i_addr1)) )) goto trunc
;
117 PRINTFhostapd_printf(" > %s, DS > DS", etheraddr_string(w4->i_addr1)ether_ntoa((struct ether_addr*)w4->i_addr1));
118 break;
119 }
120 if (vflag) {
121 TCARR(wh->i_seq)if (!( snapend - (sizeof(wh->i_seq)) <= snapend &&
(const u_char *)&(*wh->i_seq) <= snapend - (sizeof
(wh->i_seq)) )) goto trunc
;
122 PRINTFhostapd_printf(" (seq %u)", letoh16(*(u_int16_t *)&wh->i_seq[0])((__uint16_t)(*(u_int16_t *)&wh->i_seq[0])));
123 }
124
125 return (0);
126
127 trunc:
128 /* Truncated elements in frame */
129 return (1);
130}
131
132/* Caller checks len */
133void
134ieee80211_print_element(u_int8_t *data, u_int len)
135{
136 u_int8_t *p;
137 u_int i;
138
139 PRINTFhostapd_printf(" 0x");
140 for (i = 0, p = data; i < len; i++, p++)
141 PRINTFhostapd_printf("%02x", *p);
142}
143
144/* Caller checks len */
145void
146ieee80211_print_essid(u_int8_t *essid, u_int len)
147{
148 u_int8_t *p;
149 u_int i;
150
151 if (len > IEEE80211_NWID_LEN32)
152 len = IEEE80211_NWID_LEN32;
153
154 /* determine printable or not */
155 for (i = 0, p = essid; i < len; i++, p++) {
156 if (*p < ' ' || *p > 0x7e)
157 break;
158 }
159 if (i == len) {
160 PRINTFhostapd_printf(" (");
161 for (i = 0, p = essid; i < len; i++, p++)
162 PRINTFhostapd_printf("%c", *p);
163 PRINTFhostapd_printf(")");
164 } else
165 ieee80211_print_element(essid, len);
166}
167
168int
169ieee80211_elements(struct ieee80211_frame *wh)
170{
171 u_int8_t *frm;
172 u_int8_t *tstamp, *bintval, *capinfo;
173 int i;
174
175 frm = (u_int8_t *)&wh[1];
176
177 tstamp = frm;
178 TCHECK2(*tstamp, 8)if (!( snapend - (8) <= snapend && (const u_char *
)&(*tstamp) <= snapend - (8) )) goto trunc
;
179 frm += 8;
180
181 bintval = frm;
182 TCHECK2(*bintval, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*bintval) <= snapend - (2) )) goto trunc
;
183 frm += 2;
184
185 if (vflag)
186 PRINTFhostapd_printf(", interval %u", letoh16(*(u_int16_t *)bintval)((__uint16_t)(*(u_int16_t *)bintval)));
187
188 capinfo = frm;
189 TCHECK2(*capinfo, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*capinfo) <= snapend - (2) )) goto trunc
;
190 frm += 2;
191
192#if 0
193 if (vflag)
194 printb(", caps", letoh16(*(u_int16_t *)capinfo)((__uint16_t)(*(u_int16_t *)capinfo)),
195 IEEE80211_CAPINFO_BITS"\10\01ESS\02IBSS\03CF_POLLABLE\04CF_POLLREQ" "\05PRIVACY\06SHORT_PREAMBLE\07PBCC\10CHNL_AGILITY"
"\11SPECTRUM_MGMT\12QOS\13SHORT_SLOTTIME\14APSD" "\15RADIO_MEASUREMENT\16DSSSOFDM\17DELAYED_B_ACK\20IMMEDIATE_B_ACK"
);
196#endif
197
198 while (TTEST2(*frm, 2)( snapend - (2) <= snapend && (const u_char *)&
(*frm) <= snapend - (2) )
) {
199 u_int len = frm[1];
200 u_int8_t *data = frm + 2;
201
202 if (!TTEST2(*data, len)( snapend - (len) <= snapend && (const u_char *)&
(*data) <= snapend - (len) )
)
203 break;
204
205#define ELEM_CHECK(l) if (len != l) break
206
207 switch (*frm) {
208 case IEEE80211_ELEMID_SSID:
209 PRINTFhostapd_printf(", ssid");
210 ieee80211_print_essid(data, len);
211 break;
212 case IEEE80211_ELEMID_RATES:
213 if (!vflag)
214 break;
215 PRINTFhostapd_printf(", rates");
216 for (i = len; i > 0; i--, data++)
217 PRINTFhostapd_printf(" %uM",
218 (data[0] & IEEE80211_RATE_VAL0x7f) / 2);
219 break;
220 case IEEE80211_ELEMID_FHPARMS:
221 ELEM_CHECK(5);
222 PRINTFhostapd_printf(", fh (dwell %u, chan %u, index %u)",
223 (data[1] << 8) | data[0],
224 (data[2] - 1) * 80 + data[3], /* FH_CHAN */
225 data[4]);
226 break;
227 case IEEE80211_ELEMID_DSPARMS:
228 ELEM_CHECK(1);
229 if (!vflag)
230 break;
231 PRINTFhostapd_printf(", ds");
232 PRINTFhostapd_printf(" (chan %u)", data[0]);
233 break;
234 case IEEE80211_ELEMID_CFPARMS:
235 if (!vflag)
236 break;
237 PRINTFhostapd_printf(", cf");
238 ieee80211_print_element(data, len);
239 break;
240 case IEEE80211_ELEMID_TIM:
241 if (!vflag)
242 break;
243 PRINTFhostapd_printf(", tim");
244 ieee80211_print_element(data, len);
245 break;
246 case IEEE80211_ELEMID_IBSSPARMS:
247 if (!vflag)
248 break;
249 PRINTFhostapd_printf(", ibss");
250 ieee80211_print_element(data, len);
251 break;
252 case IEEE80211_ELEMID_COUNTRY:
253 if (!vflag)
254 break;
255 PRINTFhostapd_printf(", country");
256 for (i = len; i > 0; i--, data++)
257 PRINTFhostapd_printf(" %u", data[0]);
258 break;
259 case IEEE80211_ELEMID_CHALLENGE:
260 if (!vflag)
261 break;
262 PRINTFhostapd_printf(", challenge");
263 ieee80211_print_element(data, len);
264 break;
265 case IEEE80211_ELEMID_ERP:
266 if (!vflag)
267 break;
268 PRINTFhostapd_printf(", erp");
269 ieee80211_print_element(data, len);
270 break;
271 case IEEE80211_ELEMID_RSN:
272 if (!vflag)
273 break;
274 PRINTFhostapd_printf(", rsn");
275 ieee80211_print_element(data, len);
276 break;
277 case IEEE80211_ELEMID_XRATES:
278 if (!vflag)
279 break;
280 PRINTFhostapd_printf(", xrates");
281 for (i = len; i > 0; i--, data++)
282 PRINTFhostapd_printf(" %uM",
283 (data[0] & IEEE80211_RATE_VAL0x7f) / 2);
284 break;
285 case IEEE80211_ELEMID_TPC_REQUEST:
286 if (!vflag)
287 break;
288 PRINTFhostapd_printf(", tpcrequest");
289 ieee80211_print_element(data, len);
290 break;
291 case IEEE80211_ELEMID_TPC_REPORT:
292 if (!vflag)
293 break;
294 PRINTFhostapd_printf(", tpcreport");
295 ieee80211_print_element(data, len);
296 break;
297 case IEEE80211_ELEMID_VENDOR:
298 if (!vflag)
299 break;
300 PRINTFhostapd_printf(", vendor");
301 ieee80211_print_element(data, len);
302 break;
303 default:
304 if (!vflag)
305 break;
306 PRINTFhostapd_printf(", %u:%u", (u_int) *frm, len);
307 ieee80211_print_element(data, len);
308 break;
309 }
310 frm += len + 2;
311
312 if (frm >= snapend)
313 break;
314 }
315
316#undef ELEM_CHECK
317
318 return (0);
319
320 trunc:
321 /* Truncated elements in frame */
322 return (1);
323}
324
325int
326ieee80211_frame(struct ieee80211_frame *wh)
327{
328 u_int8_t subtype, type, *frm;
329
330 TCARR(wh->i_fc)if (!( snapend - (sizeof(wh->i_fc)) <= snapend &&
(const u_char *)&(*wh->i_fc) <= snapend - (sizeof(
wh->i_fc)) )) goto trunc
;
331
332 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK0x0c;
333 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK0xf0;
334
335 frm = (u_int8_t *)&wh[1];
336
337 switch (type) {
338 case IEEE80211_FC0_TYPE_DATA0x08:
339 PRINTFhostapd_printf(": data");
340 break;
341 case IEEE80211_FC0_TYPE_MGT0x00:
342 PRINTFhostapd_printf(": %s", ieee80211_mgt_subtype_name[
343 subtype >> IEEE80211_FC0_SUBTYPE_SHIFT4]);
344 switch (subtype) {
345 case IEEE80211_FC0_SUBTYPE_BEACON0x80:
346 case IEEE80211_FC0_SUBTYPE_PROBE_RESP0x50:
347 if (ieee80211_elements(wh) != 0)
348 goto trunc;
349 break;
350 case IEEE80211_FC0_SUBTYPE_AUTH0xb0:
351 TCHECK2(*frm, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*frm) <= snapend - (2) )) goto trunc
; /* Auth Algorithm */
352 switch (IEEE80211_AUTH_ALGORITHM(frm)((frm)[0] | ((frm)[1] << 8))) {
353 case IEEE80211_AUTH_ALG_OPEN0x0000:
354 TCHECK2(*frm, 4)if (!( snapend - (4) <= snapend && (const u_char *
)&(*frm) <= snapend - (4) )) goto trunc
; /* Auth Transaction */
355 switch (IEEE80211_AUTH_TRANSACTION(frm)((frm)[2] | ((frm)[3] << 8))) {
356 case IEEE80211_AUTH_OPEN_REQUEST:
357 PRINTFhostapd_printf(" request");
358 break;
359 case IEEE80211_AUTH_OPEN_RESPONSE:
360 PRINTFhostapd_printf(" response");
361 break;
362 }
363 break;
364 case IEEE80211_AUTH_ALG_SHARED0x0001:
365 TCHECK2(*frm, 4)if (!( snapend - (4) <= snapend && (const u_char *
)&(*frm) <= snapend - (4) )) goto trunc
; /* Auth Transaction */
366 switch (IEEE80211_AUTH_TRANSACTION(frm)((frm)[2] | ((frm)[3] << 8))) {
367 case IEEE80211_AUTH_SHARED_REQUEST:
368 PRINTFhostapd_printf(" request");
369 break;
370 case IEEE80211_AUTH_SHARED_CHALLENGE:
371 PRINTFhostapd_printf(" challenge");
372 break;
373 case IEEE80211_AUTH_SHARED_RESPONSE:
374 PRINTFhostapd_printf(" response");
375 break;
376 case IEEE80211_AUTH_SHARED_PASS:
377 PRINTFhostapd_printf(" pass");
378 break;
379 }
380 break;
381 case IEEE80211_AUTH_ALG_LEAP0x0080:
382 PRINTFhostapd_printf(" (leap)");
383 break;
384 }
385 break;
386 }
387 break;
388 default:
389 PRINTFhostapd_printf(": type#%d", type);
390 break;
391 }
392
393 if (wh->i_fc[1] & IEEE80211_FC1_WEP0x40)
394 PRINTFhostapd_printf(", WEP");
395
396 return (0);
397
398 trunc:
399 /* Truncated 802.11 frame */
400 return (1);
401}
402
403u_int
404ieee80211_any2ieee(u_int freq, u_int flags)
405{
406 if (flags & IEEE80211_CHAN_2GHZ0x0080) {
407 if (freq == 2484)
408 return 14;
409 if (freq < 2484)
410 return (freq - 2407) / 5;
411 else
412 return 15 + ((freq - 2512) / 20);
413 } else if (flags & IEEE80211_CHAN_5GHZ0x0100) {
414 return (freq - 5000) / 5;
415 } else {
416 /* Assume channel is already an IEEE number */
417 return (freq);
418 }
419}
420
421int
422ieee80211_print(struct ieee80211_frame *wh)
423{
424 if (eflag)
425 if (ieee80211_hdr(wh))
426 return (1);
427
428 return (ieee80211_frame(wh));
429}
430
431void
432ieee802_11_if_print(u_int8_t *buf, u_int len)
433{
434 struct ieee80211_frame *wh = (struct ieee80211_frame*)buf;
435
436 snapend = buf + len;
437
438 if (ieee80211_print(wh) != 0)
439 PRINTFhostapd_printf("[|802.11]");
440
441 PRINTFhostapd_printf(NULL((void *)0));
442}
443
444void
445ieee802_11_radio_if_print(u_int8_t *buf, u_int len)
446{
447 struct ieee80211_radiotap_header *rh =
448 (struct ieee80211_radiotap_header*)buf;
449 struct ieee80211_frame *wh;
450 u_int8_t *t;
451 u_int32_t present;
452 u_int rh_len;
453
454 snapend = buf + len;
455
456 TCHECK(*rh)if (!( snapend - (sizeof(*rh)) <= snapend && (const
u_char *)&(*rh) <= snapend - (sizeof(*rh)) )) goto trunc
;
457
458 rh_len = letoh16(rh->it_len)((__uint16_t)(rh->it_len));
459 if (rh->it_version != 0) {
460 PRINTFhostapd_printf("[?radiotap + 802.11 v:%u]", rh->it_version);
461 goto out;
462 }
463
464 wh = (struct ieee80211_frame *)(buf + rh_len);
465 if (len <= rh_len || ieee80211_print(wh))
466 PRINTFhostapd_printf("[|802.11]");
467
468 t = (u_int8_t*)buf + sizeof(struct ieee80211_radiotap_header);
469
470 if ((present = letoh32(rh->it_present)((__uint32_t)(rh->it_present))) == 0)
471 goto out;
472
473 PRINTFhostapd_printf(", <radiotap v%u", rh->it_version);
474
475#define RADIOTAP(_x) \
476 (present & (1 << IEEE80211_RADIOTAP_##_x))
477
478 if (RADIOTAP(TSFT)) {
479 u_int64_t tsf;
480 u_int32_t tsf_v[2];
481
482 TCHECK2(*t, 8)if (!( snapend - (8) <= snapend && (const u_char *
)&(*t) <= snapend - (8) )) goto trunc
;
483
484 tsf = letoh64(*(u_int64_t *)t)((__uint64_t)(*(u_int64_t *)t));
485 tsf_v[0] = (u_int32_t)(tsf >> 32);
486 tsf_v[1] = (u_int32_t)(tsf & 0x00000000ffffffff);
487 if (vflag > 1)
488 PRINTFhostapd_printf(", tsf 0x%08x%08x", tsf_v[0], tsf_v[1]);
489 t += 8;
490 }
491
492 if (RADIOTAP(FLAGS)) {
493 u_int8_t flags = *(u_int8_t*)t;
494 TCHECK2(*t, 1)if (!( snapend - (1) <= snapend && (const u_char *
)&(*t) <= snapend - (1) )) goto trunc
;
495
496 if (flags & IEEE80211_RADIOTAP_F_CFP0x01)
497 PRINTFhostapd_printf(", CFP");
498 if (flags & IEEE80211_RADIOTAP_F_SHORTPRE0x02)
499 PRINTFhostapd_printf(", SHORTPRE");
500 if (flags & IEEE80211_RADIOTAP_F_WEP0x04)
501 PRINTFhostapd_printf(", WEP");
502 if (flags & IEEE80211_RADIOTAP_F_FRAG0x08)
503 PRINTFhostapd_printf(", FRAG");
504 t += 1;
505 }
506
507 if (RADIOTAP(RATE)) {
508 TCHECK2(*t, 1)if (!( snapend - (1) <= snapend && (const u_char *
)&(*t) <= snapend - (1) )) goto trunc
;
509 if (vflag)
510 PRINTFhostapd_printf(", %uMbit/s", (*(u_int8_t*)t) / 2);
511 t += 1;
512 }
513
514 if (RADIOTAP(CHANNEL)) {
515 u_int16_t freq, flags;
516 TCHECK2(*t, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*t) <= snapend - (2) )) goto trunc
;
517
518 freq = letoh16(*(u_int16_t*)t)((__uint16_t)(*(u_int16_t*)t));
519 t += 2;
520 TCHECK2(*t, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*t) <= snapend - (2) )) goto trunc
;
521 flags = letoh16(*(u_int16_t*)t)((__uint16_t)(*(u_int16_t*)t));
522 t += 2;
523
524 PRINTFhostapd_printf(", chan %u", ieee80211_any2ieee(freq, flags));
525
526 if (flags & IEEE80211_CHAN_DYN0x0400 &&
527 flags & IEEE80211_CHAN_2GHZ0x0080)
528 PRINTFhostapd_printf(", 11g");
529 else if (flags & IEEE80211_CHAN_CCK0x0020 &&
530 flags & IEEE80211_CHAN_2GHZ0x0080)
531 PRINTFhostapd_printf(", 11b");
532 else if (flags & IEEE80211_CHAN_OFDM0x0040 &&
533 flags & IEEE80211_CHAN_2GHZ0x0080)
534 PRINTFhostapd_printf(", 11G");
535 else if (flags & IEEE80211_CHAN_OFDM0x0040 &&
536 flags & IEEE80211_CHAN_5GHZ0x0100)
537 PRINTFhostapd_printf(", 11a");
538
539 if (flags & IEEE80211_CHAN_XR0x1000)
540 PRINTFhostapd_printf(", XR");
541 }
542
543 if (RADIOTAP(FHSS)) {
544 TCHECK2(*t, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*t) <= snapend - (2) )) goto trunc
;
545 PRINTFhostapd_printf(", fhss %u/%u", *(u_int8_t*)t, *(u_int8_t*)t + 1);
546 t += 2;
547 }
548
549 if (RADIOTAP(DBM_ANTSIGNAL)) {
550 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
551 PRINTFhostapd_printf(", sig %ddBm", *(int8_t*)t);
552 t += 1;
553 }
554
555 if (RADIOTAP(DBM_ANTNOISE)) {
556 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
557 PRINTFhostapd_printf(", noise %ddBm", *(int8_t*)t);
558 t += 1;
559 }
560
561 if (RADIOTAP(LOCK_QUALITY)) {
562 TCHECK2(*t, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*t) <= snapend - (2) )) goto trunc
;
563 if (vflag)
564 PRINTFhostapd_printf(", quality %u", letoh16(*(u_int16_t*)t)((__uint16_t)(*(u_int16_t*)t)));
565 t += 2;
566 }
567
568 if (RADIOTAP(TX_ATTENUATION)) {
569 TCHECK2(*t, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*t) <= snapend - (2) )) goto trunc
;
570 if (vflag)
571 PRINTFhostapd_printf(", txatt %u",
572 letoh16(*(u_int16_t*)t)((__uint16_t)(*(u_int16_t*)t)));
573 t += 2;
574 }
575
576 if (RADIOTAP(DB_TX_ATTENUATION)) {
577 TCHECK2(*t, 2)if (!( snapend - (2) <= snapend && (const u_char *
)&(*t) <= snapend - (2) )) goto trunc
;
578 if (vflag)
579 PRINTFhostapd_printf(", txatt %udB",
580 letoh16(*(u_int16_t*)t)((__uint16_t)(*(u_int16_t*)t)));
581 t += 2;
582 }
583
584 if (RADIOTAP(DBM_TX_POWER)) {
585 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
586 PRINTFhostapd_printf(", txpower %ddBm", *(int8_t*)t);
587 t += 1;
588 }
589
590 if (RADIOTAP(ANTENNA)) {
591 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
592 if (vflag)
593 PRINTFhostapd_printf(", antenna %u", *(u_int8_t*)t);
594 t += 1;
595 }
596
597 if (RADIOTAP(DB_ANTSIGNAL)) {
598 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
599 PRINTFhostapd_printf(", signal %udB", *(u_int8_t*)t);
600 t += 1;
601 }
602
603 if (RADIOTAP(DB_ANTNOISE)) {
604 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
605 PRINTFhostapd_printf(", noise %udB", *(u_int8_t*)t);
606 t += 1;
607 }
608
609 if (RADIOTAP(FCS)) {
610 TCHECK2(*t, 4)if (!( snapend - (4) <= snapend && (const u_char *
)&(*t) <= snapend - (4) )) goto trunc
;
611 if (vflag)
612 PRINTFhostapd_printf(", fcs %08x", letoh32(*(u_int32_t*)t)((__uint32_t)(*(u_int32_t*)t)));
613 t += 4;
614 }
615
616 if (RADIOTAP(RSSI)) {
617 u_int8_t rssi, max_rssi;
618 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
619 rssi = *(u_int8_t*)t;
620 t += 1;
621 TCHECK(*t)if (!( snapend - (sizeof(*t)) <= snapend && (const
u_char *)&(*t) <= snapend - (sizeof(*t)) )) goto trunc
;
622 max_rssi = *(u_int8_t*)t;
623 t += 1;
Value stored to 't' is never read
624
625 PRINTFhostapd_printf(", rssi %u/%u", rssi, max_rssi);
626 }
627
628#undef RADIOTAP
629
630 PRINTFhostapd_printf(">");
631 goto out;
632
633 trunc:
634 /* Truncated frame */
635 PRINTFhostapd_printf("[|radiotap + 802.11]");
636
637 out:
638 PRINTFhostapd_printf(NULL((void *)0));
639}
640
641void
642hostapd_print_ieee80211(u_int dlt, u_int verbose, u_int8_t *buf, u_int len)
643{
644 if (verbose)
645 vflag = 1;
646 else
647 vflag = 0;
648
649 if (dlt == DLT_IEEE802_11105)
650 ieee802_11_if_print(buf, len);
651 else
652 ieee802_11_radio_if_print(buf, len);
653}