forked from osmocom/wireshark
172 lines
5.2 KiB
C
172 lines
5.2 KiB
C
/* 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:
|
|
*/
|