xref: /openbsd-src/usr.sbin/tcpdump/print-iapp.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: print-iapp.c,v 1.3 2006/03/10 18:13:11 reyk 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 #include <sys/param.h>
20 #include <sys/time.h>
21 #include <sys/socket.h>
22 #include <sys/file.h>
23 #include <sys/ioctl.h>
24 
25 #include <net/if.h>
26 
27 #include <netinet/in.h>
28 #include <netinet/in_systm.h>
29 #include <netinet/if_ether.h>
30 
31 #include <net80211/ieee80211.h>
32 
33 #include <pcap.h>
34 #include <stdio.h>
35 #include <string.h>
36 
37 #include "addrtoname.h"
38 #include "interface.h"
39 #include "iapp.h"
40 
41 const char *ieee80211_iapp_frame_type_name[] =
42     IEEE80211_IAPP_FRAME_TYPE_NAME;
43 
44 extern int ieee80211_encap;
45 
46 void
47 iapp_print(const u_char *p, u_int len)
48 {
49 	struct ieee80211_iapp_frame *wf = (struct ieee80211_iapp_frame *)p;
50 	struct ieee80211_iapp_add_notify *add;
51 	struct pcap_pkthdr fakeh;
52 	const u_char *data;
53 
54 	TCHECK2(*wf, sizeof(struct ieee80211_iapp_frame));
55 
56 	/* Print common IAPP information */
57 	printf(" IAPPv%u ", wf->i_version);
58 	if (wf->i_command & 0xf0)
59 		printf("unknown: 0x%0x ", wf->i_command);
60 	else
61 		printf("%s ", ieee80211_iapp_frame_type_name[wf->i_command]);
62 	printf("(id %u) %u: ", wf->i_identifier, wf->i_length);
63 
64 
65 	data = p + sizeof(struct ieee80211_iapp_frame);
66 
67 	switch (wf->i_command) {
68 	case IEEE80211_IAPP_FRAME_ADD_NOTIFY:
69 		/*
70 		 * Print details about the IAPP ADD.notify message.
71 		 */
72 		TCHECK2(*data, sizeof(struct ieee80211_iapp_add_notify));
73 		add = (struct ieee80211_iapp_add_notify *)data;
74 
75 		printf("octets %u, ", add->a_length);
76 		if (add->a_reserved)
77 			printf("reserved %u, ", add->a_reserved);
78 		if (add->a_length == IEEE80211_ADDR_LEN)
79 			printf("lladdr %s, ", etheraddr_string(add->a_macaddr));
80 		printf("seq %u", add->a_seqnum);
81 		break;
82 	case IEEE80211_IAPP_FRAME_HOSTAPD_RADIOTAP:
83 	case IEEE80211_IAPP_FRAME_HOSTAPD_PCAP:
84 		/*
85 		 * hostapd(8) uses its own subtypes to send IEEE 802.11
86 		 * frame dumps to the IAPP group (either with or without
87 		 * radiotap header). Decode it using the IEEE 802.11
88 		 * printer.
89 		 */
90 		bzero(&fakeh, sizeof(fakeh));
91 		fakeh.len = wf->i_length;
92 		fakeh.caplen = snapend - data;
93 
94 		ieee80211_encap = 1;
95 		if (wf->i_command == IEEE80211_IAPP_FRAME_HOSTAPD_RADIOTAP)
96 			ieee802_11_radio_if_print(NULL, &fakeh, data);
97 		else
98 			ieee802_11_if_print(NULL, &fakeh, data);
99 		ieee80211_encap = 0;
100 		break;
101 	}
102 	return;
103 
104 trunc:
105 	printf(" [|IAPP]");
106 }
107 
108