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