3 * $Id: packet-tzsp.c,v 1.5 2003/12/15 00:08:57 guy Exp $
5 * Copyright 2002, Tazmen Technologies Inc
7 * Tazmen Sniffer Protocol for encapsulating the packets across a network
8 * from a remote packet sniffer. TZSP can encapsulate any other protocol.
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
39 #include <epan/packet.h>
41 #define UDP_PORT_TZSP 0x9090
43 static int proto_tzsp = -1;
44 static int hf_tzsp_version = -1;
45 static int hf_tzsp_type = -1;
46 static int hf_tzsp_encap = -1;
48 static const value_string tzsp_type[] = {
49 {0, "Received tag list"},
50 {1, "Packet for transmit"},
58 static gint ett_tzsp = -1;
60 static dissector_handle_t data_handle;
61 static dissector_table_t encap_dissector_table;
63 /* ************************************************************************* */
64 /* WLAN radio header felds */
65 /* ************************************************************************* */
67 static int hf_status_field = -1;
68 static int hf_status_msg_type = -1;
69 static int hf_status_pcf = -1;
70 static int hf_status_mac_port = -1;
71 static int hf_status_undecrypted = -1;
72 static int hf_status_fcs_error = -1;
74 static int hf_time = -1;
75 static int hf_silence = -1;
76 static int hf_signal = -1;
77 static int hf_rate = -1;
78 static int hf_channel = -1;
79 static int hf_unknown = -1;
80 static int hf_original_length = -1;
81 static int hf_sensormac = -1;
83 /* ************************************************************************* */
84 /* Encapsulation type values */
85 /* ************************************************************************* */
87 #define TZSP_ENCAP_ETHERNET 1
88 #define TZSP_ENCAP_IEEE_802_11 18
89 #define TZSP_ENCAP_PRISM_HEADER 119
90 #define TZSP_ENCAP_WLAN_HEADER 127
92 /* ************************************************************************* */
93 /* Generic header options */
94 /* ************************************************************************* */
96 #define TZSP_HDR_PAD 0 /* Pad. */
97 #define TZSP_HDR_END 1 /* End of the list. */
98 #define TZSP_HDR_ORIGINAL_LENGTH 41 /* Length of the packet before slicing. 2 bytes. */
99 #define TZSP_HDR_SENSOR 60 /* Sensor MAC address packet was received on, 6 byte ethernet address.*/
101 /* ************************************************************************* */
102 /* Options for 802.11 radios */
103 /* ************************************************************************* */
105 #define WLAN_RADIO_HDR_SIGNAL 10 /* Signal strength in dBm, signed byte. */
106 #define WLAN_RADIO_HDR_NOISE 11 /* Noise level in dBm, signed byte. */
107 #define WLAN_RADIO_HDR_RATE 12 /* Data rate, unsigned byte. */
108 #define WLAN_RADIO_HDR_TIMESTAMP 13 /* Timestamp in us, unsigned 32-bits network byte order. */
109 #define WLAN_RADIO_HDR_MSG_TYPE 14 /* Packet type, unsigned byte. */
110 #define WLAN_RADIO_HDR_CF 15 /* Whether packet arrived during CF period, unsigned byte. */
111 #define WLAN_RADIO_HDR_UN_DECR 16 /* Whether packet could not be decrypted by MAC, unsigned byte. */
112 #define WLAN_RADIO_HDR_FCS_ERR 17 /* Whether packet contains an FCS error, unsigned byte. */
113 #define WLAN_RADIO_HDR_CHANNEL 18 /* Channel number packet was received on, unsigned byte.*/
115 /* ************************************************************************* */
116 /* Add option information to the display */
117 /* ************************************************************************* */
120 add_option_info(tvbuff_t *tvb, int pos, proto_tree *tree, proto_item *ti)
122 guint8 tag, length, fcs_err = 0, encr = 0, seen_fcs_err = 0;
125 * Read all option tags in an endless loop. If the packet is malformed this
126 * loop might be a problem.
129 tag = tvb_get_guint8(tvb, pos++);
137 /* Fill in header with information from other tags. */
140 proto_item_append_text(ti,"%s", fcs_err?"FCS Error":(encr?"Encrypted":"Good"));
144 case TZSP_HDR_ORIGINAL_LENGTH:
145 length = tvb_get_guint8(tvb, pos++);
147 proto_tree_add_int (tree, hf_original_length, tvb, pos-2, 4,
148 tvb_get_ntohs(tvb, pos));
152 case WLAN_RADIO_HDR_SIGNAL:
153 length = tvb_get_guint8(tvb, pos++);
155 proto_tree_add_int (tree, hf_signal, tvb, pos-2, 3,
156 tvb_get_ntohs(tvb, pos));
160 case WLAN_RADIO_HDR_NOISE:
161 length = tvb_get_guint8(tvb, pos++);
163 proto_tree_add_int (tree, hf_silence, tvb, pos-2, 3,
164 tvb_get_ntohs(tvb, pos));
168 case WLAN_RADIO_HDR_RATE:
169 length = tvb_get_guint8(tvb, pos++);
171 proto_tree_add_uint (tree, hf_rate, tvb, pos-2, 3,
172 tvb_get_guint8(tvb, pos));
176 case WLAN_RADIO_HDR_TIMESTAMP:
177 length = tvb_get_guint8(tvb, pos++);
179 proto_tree_add_uint (tree, hf_time, tvb, pos-2, 6,
180 tvb_get_ntohl(tvb, pos));
184 case WLAN_RADIO_HDR_MSG_TYPE:
185 length = tvb_get_guint8(tvb, pos++);
187 proto_tree_add_uint (tree, hf_status_msg_type, tvb, pos-2, 3,
188 tvb_get_guint8(tvb, pos));
192 case WLAN_RADIO_HDR_CF:
193 length = tvb_get_guint8(tvb, pos++);
195 proto_tree_add_boolean (tree, hf_status_pcf, tvb, pos-2, 3,
196 tvb_get_guint8(tvb, pos));
200 case WLAN_RADIO_HDR_UN_DECR:
201 length = tvb_get_guint8(tvb, pos++);
203 proto_tree_add_boolean (tree, hf_status_undecrypted, tvb, pos-2, 3,
204 tvb_get_guint8(tvb, pos));
205 encr = tvb_get_guint8(tvb, pos);
209 case WLAN_RADIO_HDR_FCS_ERR:
211 length = tvb_get_guint8(tvb, pos++);
213 proto_tree_add_boolean (tree, hf_status_fcs_error, tvb, pos-2, 3,
214 tvb_get_guint8(tvb, pos));
215 fcs_err = tvb_get_guint8(tvb, pos);
219 case WLAN_RADIO_HDR_CHANNEL:
220 length = tvb_get_guint8(tvb, pos++);
222 proto_tree_add_uint (tree, hf_channel, tvb, pos-2, 3,
223 tvb_get_guint8(tvb, pos));
227 case TZSP_HDR_SENSOR:
228 length = tvb_get_guint8(tvb, pos++);
230 proto_tree_add_ether(tree, hf_sensormac, tvb, pos-2, 6,
231 tvb_get_ptr (tvb, pos, 6));
236 length = tvb_get_guint8(tvb, pos++);
238 proto_tree_add_bytes(tree, hf_unknown, tvb, pos-2, length+2,
239 tvb_get_ptr(tvb, pos, length));
246 /* ************************************************************************* */
247 /* Map TZSP encapsulation types to Wiretap encapsulation types */
248 /* ************************************************************************* */
254 static const struct encap_map map_table[] = {
255 { TZSP_ENCAP_ETHERNET, WTAP_ENCAP_ETHERNET },
256 { TZSP_ENCAP_PRISM_HEADER, WTAP_ENCAP_PRISM_HEADER },
257 { TZSP_ENCAP_WLAN_HEADER, WTAP_ENCAP_WLAN_HEADER },
258 { TZSP_ENCAP_IEEE_802_11, WTAP_ENCAP_IEEE_802_11 },
263 tzsp_encap_to_wtap_encap(guint16 encap)
267 for (i = 0; map_table[i].wtap_encap != -1; i++) {
268 if (map_table[i].tzsp_encap == encap)
269 return map_table[i].wtap_encap;
274 /* ************************************************************************* */
275 /* Dissect a TZSP packet */
276 /* ************************************************************************* */
279 dissect_tzsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
281 proto_tree *tzsp_tree = NULL;
282 proto_item *ti = NULL;
285 guint16 encapsulation = 0;
287 dissector_handle_t encap_dissector;
288 char *encap_name, *info;
291 if (check_col(pinfo->cinfo, COL_PROTOCOL))
292 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TZSP");
293 if (check_col(pinfo->cinfo, COL_INFO))
294 col_clear(pinfo->cinfo, COL_INFO);
296 type = tvb_get_guint8(tvb, 1);
298 /* Find the dissector. */
299 encapsulation = tvb_get_ntohs(tvb, 2);
300 if (encapsulation != 0) {
301 wtap_encap = tzsp_encap_to_wtap_encap(encapsulation);
302 if (wtap_encap != -1 &&
303 (encap_dissector = dissector_get_port_handle(encap_dissector_table, wtap_encap))) {
304 encap_name = dissector_handle_get_short_name(encap_dissector);
307 encap_name = "Unknown";
313 encap_name = "Nothing";
314 info = tzsp_type[type].strptr;
317 if (check_col(pinfo->cinfo, COL_INFO))
318 col_set_str(pinfo->cinfo, COL_INFO, info);
321 /* Adding TZSP item and subtree */
322 ti = proto_tree_add_protocol_format(tree, proto_tzsp, tvb, 0,
323 -1, "TZSP: %s: ", info);
324 tzsp_tree = proto_item_add_subtree(ti, ett_tzsp);
326 proto_tree_add_item (tzsp_tree, hf_tzsp_version, tvb, 0, 1,
328 proto_tree_add_uint (tzsp_tree, hf_tzsp_type, tvb, 1, 1,
330 proto_tree_add_uint_format (tzsp_tree, hf_tzsp_encap, tvb, 2, 2,
331 encapsulation, "Encapsulates: %s (%d)",
332 encap_name, encapsulation);
335 if (type != 4 && type != 5) {
336 pos = add_option_info(tvb, 4, tzsp_tree, ti);
339 proto_item_set_end(ti, tvb, pos);
340 next_tvb = tvb_new_subset(tvb, pos, -1, -1);
341 if (encapsulation != 0
343 || !dissector_try_port(encap_dissector_table, wtap_encap,
344 next_tvb, pinfo, tree))) {
346 if (check_col(pinfo->cinfo, COL_PROTOCOL))
347 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
348 if (check_col(pinfo->cinfo, COL_INFO))
349 col_add_fstr(pinfo->cinfo, COL_INFO, "TZSP_ENCAP = %u",
351 call_dissector(data_handle, next_tvb, pinfo, tree);
356 /* ************************************************************************* */
357 /* Register the TZSP dissector */
358 /* ************************************************************************* */
361 proto_register_tzsp(void)
363 static const value_string msg_type[] = {
365 {1, "RFC1042 encoded"},
366 {2, "Bridge-tunnel encoded"},
367 {4, "802.11 management frame"},
371 static const true_false_string pcf_flag = {
372 "CF: Frame received during CF period",
376 static const true_false_string undecr_flag = {
377 "Encrypted frame could not be decrypted",
381 static const true_false_string fcs_err_flag = {
382 "FCS error, frame is corrupted",
386 static const value_string channels[] = {
388 {1, "1 (2.412 GHz)"},
389 {2, "2 (2.417 GHz)"},
390 {3, "3 (2.422 GHz)"},
391 {4, "4 (2.427 GHz)"},
392 {5, "5 (2.432 GHz)"},
393 {6, "6 (2.437 GHz)"},
394 {7, "7 (2.442 GHz)"},
395 {8, "8 (2.447 GHz)"},
396 {9, "9 (2.452 GHz)"},
397 {10, "10 (2.457 GHz)"},
398 {11, "11 (2.462 GHz)"},
399 {12, "12 (2.467 GHz)"},
400 {13, "13 (2.472 GHz)"},
401 {14, "14 (2.484 GHz)"},
403 {36, "36 (5.180 GHz)"},
404 {40, "40 (5.200 GHz)"},
405 {44, "44 (5.220 GHz)"},
406 {48, "48 (5.240 GHz)"},
407 {52, "52 (5.260 GHz)"},
408 {56, "56 (5.280 GHz)"},
409 {60, "60 (5.300 GHz)"},
410 {64, "64 (5.320 GHz)"},
411 {149, "149 (5.745 GHz)"},
412 {153, "153 (5.765 GHz)"},
413 {157, "157 (5.785 GHz)"},
414 {161, "161 (5.805 GHz)"},
418 static const value_string rates[] = {
419 /* Old PRISM rates */
422 {0x37, "5.5 Mbit/s"},
440 static hf_register_info hf[] = {
441 { &hf_tzsp_version, {
442 "Version", "tzsp.version", FT_UINT8, BASE_DEC,
443 NULL, 0, "Version", HFILL }},
445 "Type", "tzsp.type", FT_UINT8, BASE_DEC,
446 VALS(tzsp_type), 0, "Type", HFILL }},
448 "Encapsulation", "tzsp.encap", FT_UINT16, BASE_DEC,
449 NULL, 0, "Encapsulation", HFILL }},
450 { &hf_status_field, {
451 "Status", "tzsp.wlan.status", FT_UINT16, BASE_HEX,
452 NULL, 0, "Status", HFILL }},
453 { &hf_status_msg_type, {
454 "Type", "tzsp.wlan.status.msg_type", FT_UINT8, BASE_HEX,
455 VALS(msg_type), 0, "Message type", HFILL }},
456 { &hf_status_mac_port, {
457 "Port", "tzsp.wlan.status.mac_port", FT_UINT8, BASE_DEC,
458 NULL, 0, "MAC port", HFILL }},
460 "PCF", "tzsp.wlan.status.pcf", FT_BOOLEAN, BASE_HEX,
461 TFS (&pcf_flag), 0, "Point Coordination Function", HFILL }},
462 { &hf_status_undecrypted, {
463 "Undecrypted", "tzsp.wlan.status.undecrypted", FT_BOOLEAN, BASE_HEX,
464 TFS (&undecr_flag), 0, "Undecrypted", HFILL }},
465 { &hf_status_fcs_error, {
466 "FCS", "tzsp.wlan.status.fcs_err", FT_BOOLEAN, BASE_HEX,
467 TFS (&fcs_err_flag), 0, "Frame check sequence", HFILL }},
469 "Time", "tzsp.wlan.time", FT_UINT32, BASE_HEX,
470 NULL, 0, "Time", HFILL }},
472 "Silence", "tzsp.wlan.silence", FT_INT8, BASE_HEX,
473 NULL, 0, "Silence", HFILL }},
474 { &hf_original_length, {
475 "Original Length", "tzsp.original_length", FT_INT16, BASE_DEC,
476 NULL, 0, "OrigLength", HFILL }},
478 "Signal", "tzsp.wlan.signal", FT_INT8, BASE_HEX,
479 NULL, 0, "Signal", HFILL }},
481 "Rate", "tzsp.wlan.rate", FT_UINT8, BASE_HEX,
482 VALS(rates), 0, "Rate", HFILL }},
484 "Channel", "tzsp.wlan.channel", FT_UINT8, BASE_DEC,
485 VALS(channels), 0, "Channel", HFILL }},
487 "Unknown tag", "tzsp.unknown", FT_BYTES, BASE_HEX,
488 NULL, 0, "Unknown", HFILL }},
490 "Sensor Address", "tzsp.sensormac", FT_ETHER, BASE_HEX,
491 NULL, 0, "Sensor MAC", HFILL }}
494 static gint *ett[] = {
498 proto_tzsp = proto_register_protocol("Tazmen Sniffer Protocol", "TZSP",
500 proto_register_field_array(proto_tzsp, hf, array_length(hf));
501 proto_register_subtree_array(ett, array_length(ett));
506 proto_reg_handoff_tzsp(void)
508 dissector_handle_t tzsp_handle;
510 tzsp_handle = create_dissector_handle(dissect_tzsp, proto_tzsp);
511 dissector_add("udp.port", UDP_PORT_TZSP, tzsp_handle);
513 /* Get the data dissector for handling unknown encapsulation types. */
514 data_handle = find_dissector("data");
516 /* Register this protocol as an ecapsulation type. */
517 dissector_add("wtap_encap", WTAP_ENCAP_TZSP, tzsp_handle);
519 encap_dissector_table = find_dissector_table("wtap_encap");