summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump/print-iapp.c
blob: 614a917c4ce494e191b2420ed470d587c1d88745 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*	$OpenBSD: print-iapp.c,v 1.5 2015/01/16 06:40:21 deraadt Exp $	*/

/*
 * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/time.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>

#include <net/if.h>

#include <netinet/in.h>
#include <netinet/if_ether.h>

#include <net80211/ieee80211.h>

#include <pcap.h>
#include <stdio.h>
#include <string.h>

#include "addrtoname.h"
#include "interface.h"
#include "iapp.h"

const char *ieee80211_iapp_frame_type_name[] =
    IEEE80211_IAPP_FRAME_TYPE_NAME;

extern int ieee80211_encap;

void
iapp_print(const u_char *p, u_int len)
{
	struct ieee80211_iapp_frame *wf = (struct ieee80211_iapp_frame *)p;
	struct ieee80211_iapp_add_notify *add;
	struct pcap_pkthdr fakeh;
	const u_char *data;

	TCHECK2(*wf, sizeof(struct ieee80211_iapp_frame));

	/* Print common IAPP information */
	printf(" IAPPv%u ", wf->i_version);
	if (wf->i_command & 0xf0)
		printf("unknown: 0x%0x ", wf->i_command);
	else
		printf("%s ", ieee80211_iapp_frame_type_name[wf->i_command]);
	printf("(id %u) %u: ", wf->i_identifier, wf->i_length);


	data = p + sizeof(struct ieee80211_iapp_frame);

	switch (wf->i_command) {
	case IEEE80211_IAPP_FRAME_ADD_NOTIFY:
		/*
		 * Print details about the IAPP ADD.notify message.
		 */
		TCHECK2(*data, sizeof(struct ieee80211_iapp_add_notify));
		add = (struct ieee80211_iapp_add_notify *)data;

		printf("octets %u, ", add->a_length);
		if (add->a_reserved)
			printf("reserved %u, ", add->a_reserved);
		if (add->a_length == IEEE80211_ADDR_LEN)
			printf("lladdr %s, ", etheraddr_string(add->a_macaddr));
		printf("seq %u", add->a_seqnum);
		break;
	case IEEE80211_IAPP_FRAME_HOSTAPD_RADIOTAP:
	case IEEE80211_IAPP_FRAME_HOSTAPD_PCAP:
		/*
		 * hostapd(8) uses its own subtypes to send IEEE 802.11
		 * frame dumps to the IAPP group (either with or without
		 * radiotap header). Decode it using the IEEE 802.11
		 * printer.
		 */
		bzero(&fakeh, sizeof(fakeh));
		fakeh.len = wf->i_length;
		fakeh.caplen = snapend - data;

		ieee80211_encap = 1;
		if (wf->i_command == IEEE80211_IAPP_FRAME_HOSTAPD_RADIOTAP)
			ieee802_11_radio_if_print(NULL, &fakeh, data);
		else
			ieee802_11_if_print(NULL, &fakeh, data);
		ieee80211_encap = 0;
		break;
	}
	return;

trunc:
	printf(" [|IAPP]");
}