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