3 * Decode packets with a AVS-WLAN header
5 * AVS linux-wlan-based products use a new sniff header to replace the
6 * old prism2-specific one dissected in packet-prism2.c. This one has
7 * additional fields, is designed to be non-hardware-specific, and more
8 * importantly, version and length fields so it can be extended later
9 * without breaking anything.
13 * http://www.shaftnet.org/~pizza/software/capturefrm.txt
17 * $Id: packet-wlancap.c,v 1.6 2004/07/06 19:22:45 guy Exp $
19 * Ethereal - Network traffic analyzer
20 * By Gerald Combs <gerald@ethereal.com>
21 * Copyright 1998 Gerald Combs
23 * Copied from README.developer
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
47 #include <epan/packet.h>
48 #include "packet-ieee80211.h"
49 #include "packet-wlancap.h"
54 static int proto_wlancap = -1;
56 /* header attached during wlan monitor mode */
57 struct wlan_header_v1 {
74 static int hf_wlan_version = -1;
75 static int hf_wlan_length = -1;
76 static int hf_wlan_mactime = -1;
77 static int hf_wlan_hosttime = -1;
78 static int hf_wlan_phytype = -1;
79 static int hf_wlan_channel = -1;
80 static int hf_wlan_datarate = -1;
81 static int hf_wlan_antenna = -1;
82 static int hf_wlan_priority = -1;
83 static int hf_wlan_ssi_type = -1;
84 static int hf_wlan_ssi_signal = -1;
85 static int hf_wlan_ssi_noise = -1;
86 static int hf_wlan_preamble = -1;
87 static int hf_wlan_encoding = -1;
89 static gint ett_wlan = -1;
91 static dissector_handle_t ieee80211_handle;
94 dissect_wlancap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
97 capture_wlancap(const guchar *pd, int offset, int len, packet_counts *ld)
99 /* XXX eventually add in a version test. */
100 if(!BYTES_ARE_IN_FRAME(offset, len, (int)sizeof(struct wlan_header_v1))) {
104 offset += sizeof(struct wlan_header_v1);
106 /* 802.11 header follows */
107 capture_ieee80211(pd, offset, len, ld);
111 proto_register_wlancap(void)
114 static const value_string phy_type[] = {
116 { 1, "FHSS 802.11 '97" },
117 { 2, "DSSS 802.11 '97" },
118 { 3, "IR Baseband" },
119 { 4, "DSSS 802.11b" },
120 { 5, "PBCC 802.11b" },
121 { 6, "OFDM 802.11g" },
122 { 7, "PBCC 802.11g" },
123 { 8, "OFDM 802.11a" },
127 static const value_string encoding_type[] = {
135 static const value_string ssi_type[] = {
137 { 1, "Normalized RSSI" },
143 static const value_string preamble_type[] = {
150 static hf_register_info hf[] = {
151 { &hf_wlan_version, { "Header revision", "wlancap.version", FT_UINT32,
152 BASE_DEC, NULL, 0x0, "", HFILL } },
153 { &hf_wlan_length, { "Header length", "wlancap.length", FT_UINT32,
154 BASE_DEC, NULL, 0x0, "", HFILL } },
155 { &hf_wlan_mactime, { "MAC timestamp", "wlancap.mactime", FT_UINT64,
156 BASE_DEC, NULL, 0x0, "", HFILL } },
157 { &hf_wlan_hosttime, { "Host timestamp", "wlancap.hosttime", FT_UINT64,
158 BASE_DEC, NULL, 0x0, "", HFILL } },
159 { &hf_wlan_phytype, { "PHY type", "wlancap.phytype", FT_UINT32, BASE_DEC,
160 VALS(phy_type), 0x0, "", HFILL } },
161 { &hf_wlan_channel, { "Channel", "wlancap.channel", FT_UINT32, BASE_DEC,
162 NULL, 0x0, "", HFILL } },
163 { &hf_wlan_datarate, { "Data rate", "wlancap.datarate", FT_UINT32,
164 BASE_DEC, NULL, 0x0, "", HFILL } },
165 { &hf_wlan_antenna, { "Antenna", "wlancap.antenna", FT_UINT32, BASE_DEC,
166 NULL, 0x0, "", HFILL } },
167 { &hf_wlan_priority, { "Priority", "wlancap.priority", FT_UINT32, BASE_DEC,
168 NULL, 0x0, "", HFILL } },
169 { &hf_wlan_ssi_type, { "SSI Type", "wlancap.ssi_type", FT_UINT32, BASE_DEC,
170 VALS(ssi_type), 0x0, "", HFILL } },
171 { &hf_wlan_ssi_signal, { "SSI Signal", "wlancap.ssi_signal", FT_INT32,
172 BASE_DEC, NULL, 0x0, "", HFILL } },
173 { &hf_wlan_ssi_noise, { "SSI Noise", "wlancap.ssi_noise", FT_INT32,
174 BASE_DEC, NULL, 0x0, "", HFILL } },
175 { &hf_wlan_preamble, { "Preamble", "wlancap.preamble", FT_UINT32,
176 BASE_DEC, VALS(preamble_type), 0x0, "", HFILL } },
177 { &hf_wlan_encoding, { "Encoding Type", "wlancap.encoding", FT_UINT32,
178 BASE_DEC, VALS(encoding_type), 0x0, "", HFILL } },
180 static gint *ett[] = {
184 proto_wlancap = proto_register_protocol("AVS WLAN Capture header", "AVS WLANCAP", "wlancap");
185 proto_register_field_array(proto_wlancap, hf, array_length(hf));
186 proto_register_subtree_array(ett, array_length(ett));
187 register_dissector("wlancap", dissect_wlancap, proto_wlancap);
192 dissect_wlancap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
194 proto_tree *wlan_tree;
202 if(check_col(pinfo->cinfo, COL_PROTOCOL))
203 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WLAN");
204 if(check_col(pinfo->cinfo, COL_INFO))
205 col_clear(pinfo->cinfo, COL_INFO);
208 version = tvb_get_ntohl(tvb, offset) - WLANCAP_MAGIC_COOKIE_BASE;
209 length = tvb_get_ntohl(tvb, offset+4);
211 if(check_col(pinfo->cinfo, COL_INFO))
212 col_add_fstr(pinfo->cinfo, COL_INFO, "AVS WLAN Capture v%x, Length %d",version, length);
214 if (check_col(pinfo->cinfo, COL_TX_RATE)) {
215 guint32 txrate = tvb_get_ntohl(tvb, offset + 32);
216 col_add_fstr(pinfo->cinfo, COL_TX_RATE, "%d.%d",
217 txrate / 10, txrate % 10);
219 if (check_col(pinfo->cinfo, COL_RSSI)) {
220 /* XXX cook ssi_signal (Based on type; ie format) */
221 col_add_fstr(pinfo->cinfo, COL_RSSI, "%d",
222 tvb_get_ntohl(tvb, offset + 48));
225 /* Dissect the packet */
227 ti = proto_tree_add_protocol_format(tree, proto_wlancap,
228 tvb, 0, length, "AVS WLAN Monitoring Header");
229 wlan_tree = proto_item_add_subtree(ti, ett_wlan);
230 proto_tree_add_uint(wlan_tree, hf_wlan_version, tvb, offset,
231 4, tvb_get_ntohl(tvb, offset) - WLANCAP_MAGIC_COOKIE_BASE);
233 proto_tree_add_uint(wlan_tree, hf_wlan_length, tvb, offset,
234 4, tvb_get_ntohl(tvb, offset));
236 proto_tree_add_item(wlan_tree, hf_wlan_mactime, tvb, offset,
239 proto_tree_add_item(wlan_tree, hf_wlan_hosttime, tvb, offset,
243 proto_tree_add_uint(wlan_tree, hf_wlan_phytype, tvb, offset,
244 4, tvb_get_ntohl(tvb, offset));
246 /* XXX cook channel (fh uses different numbers) */
247 proto_tree_add_uint(wlan_tree, hf_wlan_channel, tvb, offset,
248 4, tvb_get_ntohl(tvb, offset));
251 /* XXX - all other 802.11 pseudo-headers use 500Kb/s, not 100Kb/s,
253 datarate = tvb_get_ntohl(tvb, offset);
254 proto_tree_add_uint_format(wlan_tree, hf_wlan_datarate, tvb, offset,
256 "Data Rate: %u Kb/s", datarate * 100);
258 proto_tree_add_uint(wlan_tree, hf_wlan_antenna, tvb, offset,
259 4, tvb_get_ntohl(tvb, offset));
261 proto_tree_add_uint(wlan_tree, hf_wlan_priority, tvb, offset,
262 4, tvb_get_ntohl(tvb, offset));
264 proto_tree_add_uint(wlan_tree, hf_wlan_ssi_type, tvb, offset,
265 4, tvb_get_ntohl(tvb, offset));
267 /* XXX cook ssi_signal (Based on type; ie format) */
268 proto_tree_add_int(wlan_tree, hf_wlan_ssi_signal, tvb, offset,
269 4, tvb_get_ntohl(tvb, offset));
271 /* XXX cook ssi_noise (Based on type; ie format) */
272 proto_tree_add_int(wlan_tree, hf_wlan_ssi_noise, tvb, offset,
273 4, tvb_get_ntohl(tvb, offset));
275 proto_tree_add_uint(wlan_tree, hf_wlan_preamble, tvb, offset,
276 4, tvb_get_ntohl(tvb, offset));
278 proto_tree_add_uint(wlan_tree, hf_wlan_encoding, tvb, offset,
279 4, tvb_get_ntohl(tvb, offset));
286 /* dissect the 802.11 header next */
287 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
288 call_dissector(ieee80211_handle, next_tvb, pinfo, tree);
292 proto_reg_handoff_wlancap(void)
294 dissector_handle_t wlancap_handle;
296 /* handle for 802.11 dissector */
297 ieee80211_handle = find_dissector("wlan");
299 wlancap_handle = create_dissector_handle(dissect_wlancap, proto_wlancap);
301 dissector_add("wtap_encap", WTAP_ENCAP_IEEE_802_11_WLAN_AVS, wlancap_handle);