aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2019-11-22 22:27:13 +0100
committerHarald Welte <laforge@osmocom.org>2023-03-11 14:36:51 +0100
commit1ba3d0f25c807ae1994a2f60b2a643b96a75d220 (patch)
tree3717178d3619101192cbb8e6d8c309db2737a2c5 /epan
parent88782ea4315462d0bf4228ed5bec1ecf76abbcae (diff)
WIP: dissector for vsmartcard protocollaforge/rspro
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/CMakeLists.txt1
-rw-r--r--epan/dissectors/packet-vsmartcard.c171
2 files changed, 172 insertions, 0 deletions
diff --git a/epan/dissectors/CMakeLists.txt b/epan/dissectors/CMakeLists.txt
index f2590b8f62..5b814e8fea 100644
--- a/epan/dissectors/CMakeLists.txt
+++ b/epan/dissectors/CMakeLists.txt
@@ -2007,6 +2007,7 @@ set(DISSECTOR_SRC
${CMAKE_CURRENT_SOURCE_DIR}/packet-vrrp.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-vrt.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-vsip.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/packet-vsmartcard.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-vsock.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-vssmonitoring.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-vtp.c
diff --git a/epan/dissectors/packet-vsmartcard.c b/epan/dissectors/packet-vsmartcard.c
new file mode 100644
index 0000000000..e19ec35d8e
--- /dev/null
+++ b/epan/dissectors/packet-vsmartcard.c
@@ -0,0 +1,171 @@
+/* packet-vsmartcard.c
+ * Routines for packet dissection of vsmartcard VPCD/VPICC protocol
+ * Copyright 2019 by Harald Welte <laforge@gnumonks.org>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "config.h"
+
+#include <epan/packet.h>
+#include <epan/prefs.h>
+
+void proto_register_vsmartcard(void);
+void proto_reg_handoff_vsmartcard(void);
+
+/*
+ * Protocol used by Frank Morgners vsmartcard VPICC + VPCD
+ *
+ * https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html
+ */
+
+/*
+ * These ports are not registered for other protocols, as per
+ * http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml
+ *
+ * But, as that document says:
+ *
+ ************************************************************************
+ * PLEASE NOTE THE FOLLOWING: *
+ * *
+ * ASSIGNMENT OF A PORT NUMBER DOES NOT IN ANY WAY IMPLY AN *
+ * ENDORSEMENT OF AN APPLICATION OR PRODUCT, AND THE FACT THAT NETWORK *
+ * TRAFFIC IS FLOWING TO OR FROM A REGISTERED PORT DOES NOT MEAN THAT *
+ * IT IS "GOOD" TRAFFIC, NOR THAT IT NECESSARILY CORRESPONDS TO THE *
+ * ASSIGNED SERVICE. FIREWALL AND SYSTEM ADMINISTRATORS SHOULD *
+ * CHOOSE HOW TO CONFIGURE THEIR SYSTEMS BASED ON THEIR KNOWLEDGE OF *
+ * THE TRAFFIC IN QUESTION, NOT WHETHER THERE IS A PORT NUMBER *
+ * REGISTERED OR NOT. *
+ ************************************************************************
+ */
+#define VSMARTCARD_TCP_PORTS "35963,35964"
+
+static dissector_handle_t vsmartcard_tcp_handle;
+//static gboolean global_ipa_in_root = FALSE;
+//static gboolean global_ipa_in_info = FALSE;
+
+/* Initialize the protocol and registered fields */
+static int proto_vsmartcard = -1;
+
+static int hf_vsmartcard_len = -1;
+static int hf_vsmartcard_cmd = -1;
+static int hf_vsmartcard_data = -1;
+
+/* Initialize the subtree pointers */
+static gint ett_vsmartcard = -1;
+
+static dissector_handle_t sub_handle_simcard;
+
+static const value_string vsmartcard_cmd_vals[] = {
+ { 0x00, "OFF" },
+ { 0x01, "ON" },
+ { 0x02, "RESET" },
+ { 0x04, "ATR" },
+ { 0, NULL }
+};
+
+/* Code to actually dissect the packets */
+static int
+dissect_vsmartcard(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
+{
+ gint remaining;
+ const gint header_length = 2;
+ int offset = 0;
+ guint16 len;
+
+ if (tvb_reported_length(tvb) < 3)
+ return 0;
+
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "vsmartcard");
+ col_clear(pinfo->cinfo, COL_INFO);
+
+ while ((remaining = tvb_reported_length_remaining(tvb, offset)) > 0) {
+ proto_item *ti;
+ proto_tree *vsmartcard_tree = NULL;
+ tvbuff_t *next_tvb;
+
+ len = tvb_get_ntohs(tvb, offset);
+ if ((guint) tvb_reported_length(tvb) < (guint) len + header_length)
+ return 0;
+
+ ti = proto_tree_add_protocol_format(tree, proto_vsmartcard,
+ tvb, offset, len+header_length, "vsmartcard protocol");
+ vsmartcard_tree = proto_item_add_subtree(ti, ett_vsmartcard);
+ proto_tree_add_item(vsmartcard_tree, hf_vsmartcard_len,
+ tvb, offset, 2, ENC_BIG_ENDIAN);
+ if (len == 1) {
+ proto_tree_add_item(vsmartcard_tree, hf_vsmartcard_cmd,
+ tvb, offset, 1, ENC_NA);
+ } else {
+ next_tvb = tvb_new_subset_length(tvb, offset+header_length, len);
+ call_dissector(sub_handle_simcard, next_tvb, pinfo, tree);
+ }
+ offset += len + header_length;
+ }
+
+ return tvb_captured_length(tvb);
+}
+
+void proto_register_vsmartcard(void)
+{
+ //module_t *vsmartcard_module;
+
+ static hf_register_info hf[] = {
+ {&hf_vsmartcard_len,
+ {"Length", "vsmartcard.length",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
+ "The length of the data (in bytes)", HFILL}
+ },
+ {&hf_vsmartcard_cmd,
+ {"Command", "vsmartcard.command",
+ FT_UINT8, BASE_HEX, VALS(vsmartcard_cmd_vals), 0x0,
+ NULL, HFILL}
+ },
+ {&hf_vsmartcard_data,
+ {"Data", "vsmartcard.data",
+ FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL}
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_vsmartcard,
+ };
+
+ proto_vsmartcard = proto_register_protocol("Smartcard (ISO7816) over TCP", "vsmartcard", "vsmartcard");
+ proto_register_field_array(proto_vsmartcard, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+
+#if 0
+ vsmartcard_module = prefs_register_protocol(proto_vsmartcard, NULL);
+ prefs_register_bool_preference(vsmartcard_module, "hsl_debug_in_root_tree",
+ "HSL Debug messages in root protocol tree",
+ NULL, &global_ipa_in_root);
+ prefs_register_bool_preference(vsmartcard_module, "hsl_debug_in_info",
+ "HSL Debug messages in INFO column",
+ NULL, &global_ipa_in_info);
+#endif
+}
+
+void proto_reg_handoff_vsmartcard(void)
+{
+ sub_handle_simcard = find_dissector_add_dependency("gsm_sim", proto_vsmartcard);
+ vsmartcard_tcp_handle = create_dissector_handle(dissect_vsmartcard, proto_vsmartcard);
+ dissector_add_uint_range_with_preference("tcp.port", VSMARTCARD_TCP_PORTS, vsmartcard_tcp_handle);
+}
+
+/*
+ * Editor modelines - https://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */