aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2014-09-04 08:35:51 -0400
committerMichael Mann <mmann78@netscape.net>2014-09-07 01:45:12 +0000
commit419de19c1dac8c2a922e3d6f455bd02dec7e9f25 (patch)
tree3cf5877e785305a926ea6eb7d2970ccb85dab9fb /epan
parent0d6fb098d0f3d7b2a40e61e0c1afd25cfcee7554 (diff)
Create subdissector table for RTAC Serial and have dissectors register with it, rather than have the RTAC Serial dissector go find all of the dissectors its interested in.
Change-Id: I6b6a05ec242e4798fb56ffa43c661ec277aca955 Reviewed-on: https://code.wireshark.org/review/3984 Reviewed-by: Chris Bontje <cbontje@gmail.com> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/Makefile.common1
-rw-r--r--epan/dissectors/packet-cp2179.c9
-rw-r--r--epan/dissectors/packet-dnp.c4
-rw-r--r--epan/dissectors/packet-lg8979.c2
-rw-r--r--epan/dissectors/packet-mbtcp.c2
-rw-r--r--epan/dissectors/packet-rtacser.c105
-rw-r--r--epan/dissectors/packet-rtacser.h42
-rw-r--r--epan/dissectors/packet-selfm.c2
-rw-r--r--epan/dissectors/packet-synphasor.c4
9 files changed, 99 insertions, 72 deletions
diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common
index c37bfe7e14..58959f2afa 100644
--- a/epan/dissectors/Makefile.common
+++ b/epan/dissectors/Makefile.common
@@ -1619,6 +1619,7 @@ DISSECTOR_INCLUDES = \
packet-rquota.h \
packet-rrc.h \
packet-rsvp.h \
+ packet-rtacser.h \
packet-rtcp.h \
packet-rtp.h \
packet-rtps.h \
diff --git a/epan/dissectors/packet-cp2179.c b/epan/dissectors/packet-cp2179.c
index e5686892fc..017bd5033f 100644
--- a/epan/dissectors/packet-cp2179.c
+++ b/epan/dissectors/packet-cp2179.c
@@ -52,7 +52,8 @@ F = 16-bit CRC
#include "config.h"
#include <epan/packet.h>
-#include <epan/dissectors/packet-tcp.h>
+#include "packet-tcp.h"
+#include "packet-rtacser.h"
#include <epan/to_str.h>
#include <epan/conversation.h>
#include <epan/wmem/wmem.h>
@@ -238,7 +239,7 @@ static int hf_cp2179_number_characters = -1;
static int hf_cp2179_analog_16bit = -1;
static int hf_cp2179_accumulator = -1;
static int hf_cp2179_crc = -1;
-static int hf_cp2179_data_field = -1;
+/* static int hf_cp2179_data_field = -1; */
static int hf_cp2179_status_byte = -1;
static int hf_cp2179_port_status_byte = -1;
static int hf_cp2179_simplestatusbit = -1;
@@ -1106,13 +1107,14 @@ proto_register_cp2179(void)
0x0, 0x0,
NULL, HFILL }
},
+#if 0
{ &hf_cp2179_data_field,
{ "Data Field", "cp2179.datafield",
FT_UINT8, BASE_DEC,
0x0, 0x0,
NULL, HFILL }
},
-
+#endif
{ &hf_cp2179_accumulator,
{ "Accumulator", "cp2179.accumulator",
FT_UINT16, BASE_DEC,
@@ -1401,6 +1403,7 @@ proto_reg_handoff_cp2179(void)
cp2179_port = global_cp2179_tcp_port;
dissector_add_uint("tcp.port", cp2179_port, cp2179_handle);
+ dissector_add_uint("rtacser.data", RTACSER_PAYLOAD_CP2179, cp2179_handle);
}
/*
diff --git a/epan/dissectors/packet-dnp.c b/epan/dissectors/packet-dnp.c
index 3ff7795d3f..fe4f0c646f 100644
--- a/epan/dissectors/packet-dnp.c
+++ b/epan/dissectors/packet-dnp.c
@@ -38,7 +38,8 @@
#include <epan/prefs.h>
#include <epan/reassemble.h>
#include <epan/wmem/wmem.h>
-#include <epan/dissectors/packet-tcp.h>
+#include "packet-tcp.h"
+#include "packet-rtacser.h"
#include <epan/conversation.h>
#include <epan/expert.h>
#include <epan/to_str.h>
@@ -4439,6 +4440,7 @@ proto_reg_handoff_dnp3(void)
dnp3_udp_handle = new_create_dissector_handle(dissect_dnp3_udp, proto_dnp3);
dissector_add_uint("tcp.port", TCP_PORT_DNP, dnp3_tcp_handle);
dissector_add_uint("udp.port", UDP_PORT_DNP, dnp3_udp_handle);
+ dissector_add_uint("rtacser.data", RTACSER_PAYLOAD_DNP3, dnp3_udp_handle);
}
/*
diff --git a/epan/dissectors/packet-lg8979.c b/epan/dissectors/packet-lg8979.c
index 5c3d228317..d23b989462 100644
--- a/epan/dissectors/packet-lg8979.c
+++ b/epan/dissectors/packet-lg8979.c
@@ -28,6 +28,7 @@
#include <epan/packet.h>
#include "packet-tcp.h"
#include <epan/prefs.h>
+#include "packet-rtacser.h"
void proto_register_lg8979(void);
@@ -1548,6 +1549,7 @@ proto_reg_handoff_lg8979(void)
lg8979_port = global_lg8979_tcp_port;
+ dissector_add_uint("rtacser.data", RTACSER_PAYLOAD_LG8979, lg8979_handle);
}
/*
diff --git a/epan/dissectors/packet-mbtcp.c b/epan/dissectors/packet-mbtcp.c
index a1a79c9960..41dcd1e2c5 100644
--- a/epan/dissectors/packet-mbtcp.c
+++ b/epan/dissectors/packet-mbtcp.c
@@ -77,6 +77,7 @@
#include <epan/wmem/wmem.h>
#include "packet-tcp.h"
#include "packet-mbtcp.h"
+#include "packet-rtacser.h"
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/crc16-tvb.h> /* For CRC verification */
@@ -1873,5 +1874,6 @@ proto_reg_handoff_mbrtu(void)
mbrtu_port = global_mbus_rtu_port;
dissector_add_uint("mbtcp.prot_id", MODBUS_PROTOCOL_ID, modbus_handle);
+ dissector_add_uint("rtacser.data", RTACSER_PAYLOAD_MODBUS, modbus_handle);
}
diff --git a/epan/dissectors/packet-rtacser.c b/epan/dissectors/packet-rtacser.c
index 14bd1b58d5..829e5e7b00 100644
--- a/epan/dissectors/packet-rtacser.c
+++ b/epan/dissectors/packet-rtacser.c
@@ -62,7 +62,9 @@
#include <epan/packet.h>
#include <epan/prefs.h>
+#include <epan/decode_as.h>
#include <wiretap/wtap.h>
+#include "packet-rtacser.h"
void proto_register_rtacser(void);
@@ -78,22 +80,16 @@ static int hf_rtacser_ctrl_dtr = -1;
static int hf_rtacser_ctrl_ring = -1;
static int hf_rtacser_ctrl_mbok = -1;
static int hf_rtacser_footer = -1;
-static int hf_rtacser_data = -1;
/* Initialize the subtree pointers */
static gint ett_rtacser = -1;
static gint ett_rtacser_cl = -1;
/* Globals for RTAC Serial Preferences */
-static guint global_rtacser_payload_proto = 0; /* No Payload, by default */
+static guint global_rtacser_payload_proto = RTACSER_PAYLOAD_NONE; /* No Payload, by default */
-/* Handles for Payload Protocols */
-static dissector_handle_t selfm_handle;
-static dissector_handle_t dnp3_handle;
-static dissector_handle_t modbus_handle;
-static dissector_handle_t synphasor_handle;
-static dissector_handle_t lg8979_handle;
-static dissector_handle_t cp2179_handle;
+static dissector_table_t subdissector_table;
+static dissector_handle_t data_handle;
#define RTACSER_HEADER_LEN 12
@@ -106,7 +102,7 @@ static dissector_handle_t cp2179_handle;
#define RTACSER_CTRL_RING 0x20
#define RTACSER_CTRL_MBOK 0x40
-/* Payload Protocol Types from Preferences */
+/* Payload Protocol Types */
#define RTACSER_PAYLOAD_NONE 0
#define RTACSER_PAYLOAD_SELFM 1
#define RTACSER_PAYLOAD_DNP3 2
@@ -142,6 +138,17 @@ static const enum_val_t rtacser_payload_proto_type[] = {
{ NULL, NULL, 0 }
};
+static void
+rtacser_ppi_prompt(packet_info *pinfo _U_, gchar* result)
+{
+ g_snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Payload as");
+}
+
+static gpointer
+rtacser_ppi_value(packet_info *pinfo)
+{
+ return p_get_proto_data(pinfo->pool, pinfo, proto_rtacser, 0 );
+}
/******************************************************************************************************/
/* Code to dissect RTAC Serial-Line Protocol packets */
@@ -150,11 +157,11 @@ static void
dissect_rtacser_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
/* Set up structures needed to add the protocol subtree and manage it */
- proto_item *rtacser_item, *ts_item, *cl_item, *data_payload;
+ proto_item *rtacser_item, *cl_item;
proto_tree *rtacser_tree, *cl_tree;
int offset = 0, len;
guint event_type;
- guint32 timestamp1, timestamp2;
+ nstime_t tv;
gboolean cts, dcd, dsr, rts, dtr, ring, mbok;
tvbuff_t *payload_tvb;
@@ -169,10 +176,9 @@ dissect_rtacser_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Time-stamp is stored as 2 x 32-bit unsigned integers, the left and right-hand side of the decimal point respectively */
/* The format mirrors the timeval struct - absolute Epoch time (seconds since 1/1/1970) with an added microsecond component */
- timestamp1 = tvb_get_ntohl(tvb, offset);
- timestamp2 = tvb_get_ntohl(tvb, offset+4);
- ts_item = proto_tree_add_item(rtacser_tree, hf_rtacser_timestamp, tvb, offset, 8, ENC_BIG_ENDIAN);
- proto_item_set_text(ts_item, "Arrived At Time: %u.%u" , timestamp1, timestamp2);
+ tv.secs = tvb_get_ntohl(tvb, offset);
+ tv.nsecs = tvb_get_ntohl(tvb, offset+4)*1000;
+ proto_tree_add_time(rtacser_tree, hf_rtacser_timestamp, tvb, offset, 8, &tv);
offset += 8;
/* Set INFO column with RTAC Serial Event Type */
@@ -229,47 +235,14 @@ dissect_rtacser_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_item(rtacser_tree, hf_rtacser_footer, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
- /* If no payload dissector has been selected, indicate to the user the preferences options */
- if ((tvb_reported_length_remaining(tvb, offset) > 0) && (global_rtacser_payload_proto == RTACSER_PAYLOAD_NONE)) {
- data_payload = proto_tree_add_item(tree, hf_rtacser_data, tvb, offset, -1, ENC_NA);
- proto_item_set_text(data_payload,"Payload Protocol not selected. Check 'Preferences-> Protocols-> RTAC Serial' for options");
- return;
- }
-
+ p_add_proto_data(pinfo->pool, pinfo, proto_rtacser, 0, GUINT_TO_POINTER(global_rtacser_payload_proto));
- /* Determine correct message type and call appropriate dissector */
if (tvb_reported_length_remaining(tvb, RTACSER_HEADER_LEN) > 0) {
-
- switch (global_rtacser_payload_proto) {
- case RTACSER_PAYLOAD_SELFM:
- payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
- call_dissector(selfm_handle, payload_tvb, pinfo, tree);
- break;
- case RTACSER_PAYLOAD_DNP3:
- payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
- call_dissector(dnp3_handle, payload_tvb, pinfo, tree);
- break;
- case RTACSER_PAYLOAD_MODBUS:
- payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
- call_dissector(modbus_handle, payload_tvb, pinfo, tree);
- break;
- case RTACSER_PAYLOAD_SYNPHASOR:
- payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
- call_dissector(synphasor_handle, payload_tvb, pinfo, tree);
- break;
- case RTACSER_PAYLOAD_LG8979:
- payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
- call_dissector(lg8979_handle, payload_tvb, pinfo, tree);
- break;
- case RTACSER_PAYLOAD_CP2179:
- payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
- call_dissector(cp2179_handle, payload_tvb, pinfo, tree);
- break;
- default:
- break;
+ payload_tvb = tvb_new_subset_remaining(tvb, RTACSER_HEADER_LEN);
+ if (!dissector_try_uint(subdissector_table, global_rtacser_payload_proto, payload_tvb, pinfo, tree)){
+ call_dissector(data_handle, payload_tvb, pinfo, tree);
}
}
-
}
@@ -304,7 +277,7 @@ proto_register_rtacser(void)
/* RTAC Serial Protocol header fields */
static hf_register_info rtacser_hf[] = {
{ &hf_rtacser_timestamp,
- { "Timestamp", "rtacser.timestamp", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL }},
+ { "Arrived At Time", "rtacser.timestamp", FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, NULL, HFILL }},
{ &hf_rtacser_event_type,
{ "Event Type", "rtacser.eventtype", FT_UINT8, BASE_HEX, VALS(rtacser_eventtype_vals), 0x0, NULL, HFILL }},
{ &hf_rtacser_ctrl_cts,
@@ -323,16 +296,18 @@ proto_register_rtacser(void)
{ "MBOK", "rtacser.mbok", FT_UINT8, BASE_DEC, NULL, RTACSER_CTRL_MBOK, NULL, HFILL }},
{ &hf_rtacser_footer,
{ "Footer", "rtacser.footer", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
- { &hf_rtacser_data,
- { "Payload data", "rtacser.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
-
};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_rtacser,
&ett_rtacser_cl,
- };
+ };
+
+ static build_valid_func rtacser_da_ppi_build_value[1] = {rtacser_ppi_value};
+ static decode_as_value_t rtacser_da_ppi_values[1] = {{rtacser_ppi_prompt, 1, rtacser_da_ppi_build_value}};
+ static decode_as_t rtacser_da_ppi = {"rtacser", "RTAC Serial", "rtacser.data", 1, 0, rtacser_da_ppi_values, "RTAC Serial", NULL,
+ decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
module_t *rtacser_module;
@@ -342,6 +317,8 @@ proto_register_rtacser(void)
/* Registering protocol to be called by another dissector */
new_register_dissector("rtacser", dissect_rtacser, proto_rtacser);
+ subdissector_table = register_dissector_table("rtacser.data", "RTAC Serial Data Subdissector", FT_UINT32, BASE_HEX);
+
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_rtacser, rtacser_hf, array_length(rtacser_hf));
proto_register_subtree_array(ett, array_length(ett));
@@ -357,7 +334,7 @@ proto_register_rtacser(void)
rtacser_payload_proto_type,
TRUE);
-
+ register_decode_as(&rtacser_da_ppi);
}
/******************************************************************************************************/
@@ -378,15 +355,9 @@ proto_reg_handoff_rtacser(void)
rtacser_prefs_initialized = TRUE;
}
- /* Create a handle for each expected payload protocol that can be called via the Preferences */
- selfm_handle = find_dissector("selfm");
- dnp3_handle = find_dissector("dnp3.udp");
- modbus_handle = find_dissector("mbrtu");
- synphasor_handle = find_dissector("synphasor");
- lg8979_handle = find_dissector("lg8979");
- cp2179_handle = find_dissector("cp2179");
-
dissector_add_uint("wtap_encap", WTAP_ENCAP_RTAC_SERIAL, rtacser_handle);
+
+ data_handle = find_dissector("data");
}
diff --git a/epan/dissectors/packet-rtacser.h b/epan/dissectors/packet-rtacser.h
new file mode 100644
index 0000000000..68ea024d39
--- /dev/null
+++ b/epan/dissectors/packet-rtacser.h
@@ -0,0 +1,42 @@
+/* packet-rtacser.h
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+/* Payload Protocol Types */
+#define RTACSER_PAYLOAD_NONE 0
+#define RTACSER_PAYLOAD_SELFM 1
+#define RTACSER_PAYLOAD_DNP3 2
+#define RTACSER_PAYLOAD_MODBUS 3
+#define RTACSER_PAYLOAD_SYNPHASOR 4
+#define RTACSER_PAYLOAD_LG8979 5
+#define RTACSER_PAYLOAD_CP2179 6
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/epan/dissectors/packet-selfm.c b/epan/dissectors/packet-selfm.c
index c39c92ad36..4b30dda503 100644
--- a/epan/dissectors/packet-selfm.c
+++ b/epan/dissectors/packet-selfm.c
@@ -66,6 +66,7 @@
#include <epan/conversation.h>
#include <epan/wmem/wmem.h>
#include <epan/crc16-tvb.h>
+#include "packet-rtacser.h"
void proto_register_selfm(void);
@@ -2972,6 +2973,7 @@ proto_reg_handoff_selfm(void)
selfm_port = global_selfm_tcp_port;
dissector_add_uint("tcp.port", selfm_port, selfm_handle);
+ dissector_add_uint("rtacser.data", RTACSER_PAYLOAD_SELFM, selfm_handle);
}
/*
diff --git a/epan/dissectors/packet-synphasor.c b/epan/dissectors/packet-synphasor.c
index f7f95fa556..2713956cf7 100644
--- a/epan/dissectors/packet-synphasor.c
+++ b/epan/dissectors/packet-synphasor.c
@@ -27,10 +27,11 @@
#include <glib.h>
#include <epan/conversation.h>
#include <epan/crc16-tvb.h>
-#include <epan/dissectors/packet-tcp.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/wmem/wmem.h>
+#include "packet-tcp.h"
+#include "packet-rtacser.h"
#include <math.h>
@@ -1345,4 +1346,5 @@ void proto_reg_handoff_synphasor(void)
dissector_add_uint("udp.port", current_udp_port, synphasor_udp_handle);
dissector_add_uint("tcp.port", current_tcp_port, synphasor_tcp_handle);
+ dissector_add_uint("rtacser.data", RTACSER_PAYLOAD_SYNPHASOR, synphasor_udp_handle);
} /* proto_reg_handoff_synphasor() */