aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-iec104.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-10-07 16:25:01 -0400
committerMichael Mann <mmann78@netscape.net>2016-10-08 02:44:53 +0000
commit268841f3e00b7cf0f16c81dd2b3b952172130b8b (patch)
tree359e01cf5eba83308760531888713fe0ff0bc10b /epan/dissectors/packet-iec104.c
parent11d3224142c0531879fb8e415daf9639a4eace66 (diff)
Combine Decode As and port preferences for tcp.port dissector table.
This patch introduces new APIs to allow dissectors to have a preference for a (TCP) port, but the underlying data is actually part of Decode As functionality. For now the APIs are intentionally separate from the regular APIs that register a dissector within a dissector table. It may be possible to eventually combine the two so that all dissectors that register with a dissector table have an opportunity to "automatically" have a preference to adjust the "table value" through the preferences dialog. The tcp.port dissector table was used as the guinea pig. This will eventually be expanded to other dissector tables as well (most notably UDP ports). Some dissectors that "shared" a TCP/UDP port preference were also converted. It also removed the need for some preference callback functions (mostly when the callback function was the proto_reg_handoff function) so there is cleanup around that. Dissectors that has a port preference whose default was 0 were switched to using the dissector_add_for_decode_as_with_preference API rather than dissector_add_uint_with_preference Also added comments for TCP ports used that aren't IANA registered. Change-Id: I99604f95d426ad345f4b494598d94178b886eb67 Reviewed-on: https://code.wireshark.org/review/17724 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/packet-iec104.c')
-rw-r--r--epan/dissectors/packet-iec104.c52
1 files changed, 19 insertions, 33 deletions
diff --git a/epan/dissectors/packet-iec104.c b/epan/dissectors/packet-iec104.c
index 8507fbd10d..47a6164d63 100644
--- a/epan/dissectors/packet-iec104.c
+++ b/epan/dissectors/packet-iec104.c
@@ -34,6 +34,7 @@
#include <epan/packet.h>
#include <epan/prefs.h>
+#include <epan/prefs-int.h>
#include <epan/expert.h>
#include "packet-tcp.h"
@@ -76,7 +77,8 @@ typedef struct {
gboolean SE; /* Select (1) / Execute (0) */
} td_CmdInfo;
-static guint iec104_port = 2404;
+#define IEC104_PORT 2404
+static guint iec104_port = IEC104_PORT;
/* Define the iec104 proto */
static int proto_iec104apci = -1;
@@ -1488,6 +1490,14 @@ static int dissect_iec104reas(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
return tvb_captured_length(tvb);
}
+static void
+apply_iec104_prefs(void)
+{
+ /* IEC104 uses the port preference to determine direction */
+ pref_t *iec104_port_pref = prefs_find_preference(prefs_find_module("104apci"), "tcp.port");
+ iec104_port = *iec104_port_pref->varp.uint;
+}
+
/* The protocol has two subprotocols: Register APCI */
void
proto_register_iec104apci(void)
@@ -1523,22 +1533,12 @@ proto_register_iec104apci(void)
&ett_apci,
};
- module_t *iec104_module;
+ proto_iec104apci = proto_register_protocol("IEC 60870-5-104-Apci", "104apci", "104apci");
- proto_iec104apci = proto_register_protocol(
- "IEC 60870-5-104-Apci",
- "104apci",
- "104apci"
- );
proto_register_field_array(proto_iec104apci, hf_ap, array_length(hf_ap));
proto_register_subtree_array(ett_ap, array_length(ett_ap));
- iec104_module = prefs_register_protocol(proto_iec104apci, proto_reg_handoff_iec104);
-
- prefs_register_uint_preference(iec104_module, "tcp.port",
- "IEC104 TCP port used by source",
- "TCP port used by source of IEC104, usually 2404",
- 10, &iec104_port);
+ prefs_register_protocol(proto_iec104apci, apply_iec104_prefs);
}
@@ -1846,11 +1846,7 @@ proto_register_iec104asdu(void)
expert_module_t* expert_iec104;
- proto_iec104asdu = proto_register_protocol(
- "IEC 60870-5-104-Asdu",
- "104asdu",
- "104asdu"
- );
+ proto_iec104asdu = proto_register_protocol("IEC 60870-5-104-Asdu", "104asdu", "104asdu");
proto_register_field_array(proto_iec104asdu, hf_as, array_length(hf_as));
proto_register_subtree_array(ett_as, array_length(ett_as));
@@ -1864,22 +1860,12 @@ proto_register_iec104asdu(void)
void
proto_reg_handoff_iec104(void)
{
- static dissector_handle_t iec104apci_handle;
- static gboolean iec104_prefs_initialized = FALSE;
- static guint saved_iec104_port;
-
- if (!iec104_prefs_initialized) {
- iec104apci_handle = create_dissector_handle(dissect_iec104reas, proto_iec104apci);
- iec104asdu_handle = create_dissector_handle(dissect_iec104asdu, proto_iec104asdu);
- dissector_add_uint("tcp.port", iec104_port, iec104apci_handle);
- } else {
- dissector_delete_uint("tcp.port", saved_iec104_port, iec104apci_handle);
- }
+ dissector_handle_t iec104apci_handle;
- saved_iec104_port = iec104_port;
- if (iec104_port != 0) {
- dissector_add_uint("tcp.port", iec104_port, iec104apci_handle);
- }
+ iec104apci_handle = create_dissector_handle(dissect_iec104reas, proto_iec104apci);
+ iec104asdu_handle = create_dissector_handle(dissect_iec104asdu, proto_iec104asdu);
+
+ dissector_add_uint_with_preference("tcp.port", IEC104_PORT, iec104apci_handle);
}
/*