2011-11-07 16:56:16 +00:00
|
|
|
/* packet-usb-ccid.c
|
|
|
|
* Dissector for the Integrated Circuit Card Interface Device Class
|
|
|
|
*
|
|
|
|
* References:
|
|
|
|
* http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.pdf
|
2011-11-14 18:19:14 +00:00
|
|
|
*
|
2011-11-07 16:56:16 +00:00
|
|
|
* Copyright 2011, Tyson Key <tyson.key@gmail.com>
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-11-07 16:56:16 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/dissectors/packet-usb.h>
|
2012-02-23 09:12:30 +00:00
|
|
|
#include <epan/prefs.h>
|
2011-11-07 16:56:16 +00:00
|
|
|
|
|
|
|
static int proto_ccid = -1;
|
|
|
|
|
|
|
|
static int hf_ccid_bMessageType = -1;
|
|
|
|
static int hf_ccid_dwLength = -1;
|
|
|
|
static int hf_ccid_bSlot = -1;
|
|
|
|
static int hf_ccid_bSeq = -1;
|
|
|
|
static int hf_ccid_bStatus = -1;
|
|
|
|
static int hf_ccid_bError = -1;
|
|
|
|
static int hf_ccid_bChainParameter = -1;
|
|
|
|
static int hf_ccid_bPowerSelect = -1;
|
|
|
|
static int hf_ccid_bClockStatus = -1;
|
|
|
|
static int hf_ccid_bProtocolNum = -1;
|
|
|
|
static int hf_ccid_bBWI = -1;
|
|
|
|
static int hf_ccid_wLevelParameter = -1;
|
|
|
|
|
|
|
|
/* Standardised Bulk Out message types */
|
2012-01-13 22:04:09 +00:00
|
|
|
#define PC_RDR_SET_PARAMS 0x61
|
|
|
|
#define PC_RDR_ICC_ON 0x62
|
|
|
|
#define PC_RDR_ICC_OFF 0x63
|
2011-11-07 16:56:16 +00:00
|
|
|
#define PC_RDR_GET_SLOT_STATUS 0x65
|
2012-01-13 22:04:09 +00:00
|
|
|
#define PC_RDR_SECURE 0x69
|
|
|
|
#define PC_RDR_T0APDU 0x6A
|
|
|
|
#define PC_RDR_ESCAPE 0x6B
|
|
|
|
#define PC_RDR_GET_PARAMS 0x6C
|
|
|
|
#define PC_RDR_RESET_PARAMS 0x6D
|
|
|
|
#define PC_RDR_ICC_CLOCK 0x6E
|
|
|
|
#define PC_RDR_XFR_BLOCK 0x6F
|
|
|
|
#define PC_RDR_MECH 0x71
|
|
|
|
#define PC_RDR_ABORT 0x72
|
|
|
|
#define PC_RDR_DATA_CLOCK 0x73
|
2011-11-07 16:56:16 +00:00
|
|
|
|
|
|
|
/* Standardised Bulk In message types */
|
2012-01-13 22:04:09 +00:00
|
|
|
#define RDR_PC_DATA_BLOCK 0x80
|
|
|
|
#define RDR_PC_SLOT_STATUS 0x81
|
|
|
|
#define RDR_PC_PARAMS 0x82
|
|
|
|
#define RDR_PC_ESCAPE 0x83
|
|
|
|
#define RDR_PC_DATA_CLOCK 0x84
|
2011-11-07 16:56:16 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
static const value_string ccid_opcode_vals[] = {
|
2011-11-07 16:56:16 +00:00
|
|
|
/* Standardised Bulk Out message types */
|
2012-01-13 22:04:09 +00:00
|
|
|
{PC_RDR_SET_PARAMS , "PC_to_RDR_SetParameters"},
|
|
|
|
{PC_RDR_ICC_ON , "PC_to_RDR_IccPowerOn"},
|
|
|
|
{PC_RDR_ICC_OFF , "PC_to_RDR_IccPowerOff"},
|
|
|
|
{PC_RDR_GET_SLOT_STATUS , "PC_to_RDR_GetSlotStatus"},
|
|
|
|
{PC_RDR_SECURE , "PC_to_RDR_Secure"},
|
|
|
|
{PC_RDR_T0APDU , "PC_to_RDR_T0APDU"},
|
|
|
|
{PC_RDR_ESCAPE , "PC_to_RDR_Escape"},
|
|
|
|
{PC_RDR_GET_PARAMS , "PC_to_RDR_GetParameters"},
|
|
|
|
{PC_RDR_RESET_PARAMS , "PC_to_RDR_ResetParameters"},
|
|
|
|
{PC_RDR_ICC_CLOCK , "PC_to_RDR_IccClock"},
|
|
|
|
{PC_RDR_XFR_BLOCK , "PC_to_RDR_XfrBlock"},
|
|
|
|
{PC_RDR_MECH , "PC_to_RDR_Mechanical"},
|
|
|
|
{PC_RDR_ABORT , "PC_to_RDR_Abort"},
|
|
|
|
{PC_RDR_DATA_CLOCK , "PC_to_RDR_SetDataRateAndClockFrequency"},
|
2011-11-07 16:56:16 +00:00
|
|
|
|
|
|
|
/* Standardised Bulk In message types */
|
2012-01-13 22:04:09 +00:00
|
|
|
{RDR_PC_DATA_BLOCK , "RDR_to_PC_DataBlock"},
|
|
|
|
{RDR_PC_SLOT_STATUS , "RDR_to_PC_SlotStatus"},
|
|
|
|
{RDR_PC_PARAMS , "RDR_to_PC_Parameters"},
|
|
|
|
{RDR_PC_ESCAPE , "RDR_to_PC_Escape"},
|
|
|
|
{RDR_PC_DATA_CLOCK , "RDR_to_PC_DataRateAndClockFrequency"},
|
2011-11-07 16:56:16 +00:00
|
|
|
|
|
|
|
/* End of message types */
|
|
|
|
{0x00, NULL}
|
|
|
|
};
|
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
static const value_string ccid_messagetypes_vals[] = {
|
|
|
|
/* Standardised Bulk Out message types */
|
|
|
|
{PC_RDR_SET_PARAMS , "PC to Reader: Set Parameters"},
|
|
|
|
{PC_RDR_ICC_ON , "PC to Reader: ICC Power On"},
|
|
|
|
{PC_RDR_ICC_OFF , "PC to Reader: ICC Power Off"},
|
|
|
|
{PC_RDR_GET_SLOT_STATUS , "PC to Reader: Get Slot Status"},
|
|
|
|
{PC_RDR_SECURE , "PC to Reader: Secure"},
|
|
|
|
{PC_RDR_T0APDU , "PC to Reader: T=0 APDU"},
|
|
|
|
{PC_RDR_ESCAPE , "PC to Reader: Escape"},
|
|
|
|
{PC_RDR_GET_PARAMS , "PC to Reader: Get Parameters"},
|
|
|
|
{PC_RDR_RESET_PARAMS , "PC to Reader: Reset Parameters"},
|
|
|
|
{PC_RDR_ICC_CLOCK , "PC to Reader: ICC Clock"},
|
|
|
|
{PC_RDR_XFR_BLOCK , "PC to Reader: Transfer Block"},
|
|
|
|
{PC_RDR_MECH , "PC to Reader: Mechanical"},
|
|
|
|
{PC_RDR_ABORT , "PC to Reader: Abort"},
|
|
|
|
{PC_RDR_DATA_CLOCK , "PC to Reader: Set Data Rate and Clock Frequency"},
|
|
|
|
|
|
|
|
/* Standardised Bulk In message types */
|
|
|
|
{RDR_PC_DATA_BLOCK , "Reader to PC: Data Block"},
|
|
|
|
{RDR_PC_SLOT_STATUS , "Reader to PC: Slot Status"},
|
|
|
|
{RDR_PC_PARAMS , "Reader to PC: Parameters"},
|
|
|
|
{RDR_PC_ESCAPE , "Reader to PC: Escape"},
|
|
|
|
{RDR_PC_DATA_CLOCK , "Reader to PC: Data Rate and Clock Frequency"},
|
|
|
|
|
|
|
|
/* End of message types */
|
|
|
|
{0x00, NULL}
|
|
|
|
};
|
|
|
|
|
2011-11-07 16:56:16 +00:00
|
|
|
static const value_string ccid_voltage_levels_vals[] = {
|
|
|
|
/* Standardised voltage levels */
|
|
|
|
{0x00, "Automatic Voltage Selection"},
|
|
|
|
{0x01, "5.0 volts"},
|
|
|
|
{0x02, "3.0 volts"},
|
|
|
|
{0x03, "1.8 volts"},
|
|
|
|
|
|
|
|
/* End of voltage levels */
|
|
|
|
{0x00, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string ccid_clock_states_vals[] = {
|
|
|
|
/* Standardised clock states */
|
|
|
|
{0x00, "Clock running"},
|
|
|
|
{0x01, "Clock stopped in state L"},
|
|
|
|
{0x02, "Clock stopped in state H"},
|
|
|
|
{0x03, "Clock stopped in an unknown state"},
|
|
|
|
|
|
|
|
/* End of clock states */
|
|
|
|
{0x00, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string ccid_proto_structs_vals[] = {
|
|
|
|
/* Standardised clock states */
|
|
|
|
{0x00, "Structure for protocol T=0"},
|
|
|
|
{0x01, "Structure for protocol T=1"},
|
|
|
|
|
|
|
|
/* Marked as RFU, but added for completeness: */
|
|
|
|
{0x80, "Structure for 2-wire protocol"},
|
|
|
|
{0x81, "Structure for 3-wire protocol"},
|
|
|
|
{0x82, "Structure for I2C protocol"},
|
|
|
|
|
|
|
|
/* End of protocol structures */
|
|
|
|
{0x00, NULL}
|
|
|
|
};
|
|
|
|
|
2012-01-13 22:04:09 +00:00
|
|
|
static dissector_table_t ccid_dissector_table;
|
2011-11-07 16:56:16 +00:00
|
|
|
|
|
|
|
/* Subtree handles: set by register_subtree_array */
|
|
|
|
static gint ett_ccid = -1;
|
|
|
|
|
2012-02-23 11:14:57 +00:00
|
|
|
/* Table of payload types - adapted from the I2C dissector */
|
2012-02-23 09:12:30 +00:00
|
|
|
enum {
|
|
|
|
SUB_DATA = 0,
|
2012-05-17 21:11:22 +00:00
|
|
|
SUB_ISO7816,
|
2013-06-13 10:52:34 +00:00
|
|
|
SUB_GSM_SIM_CMD,
|
2012-03-13 06:34:32 +00:00
|
|
|
SUB_PN532_ACS_PSEUDO_APDU,
|
2013-06-13 10:52:34 +00:00
|
|
|
SUB_GSM_SIM_RSP,
|
2012-02-23 09:12:30 +00:00
|
|
|
|
|
|
|
SUB_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef gboolean (*sub_checkfunc_t)(packet_info *);
|
|
|
|
|
|
|
|
static dissector_handle_t sub_handles[SUB_MAX];
|
|
|
|
static gint sub_selected = SUB_DATA;
|
|
|
|
|
2012-01-13 22:04:09 +00:00
|
|
|
static void
|
|
|
|
dissect_ccid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
2011-11-07 16:56:16 +00:00
|
|
|
{
|
|
|
|
proto_item *item;
|
|
|
|
proto_tree *ccid_tree;
|
2012-01-13 22:04:09 +00:00
|
|
|
guint8 cmd;
|
|
|
|
tvbuff_t *next_tvb;
|
2011-11-07 16:56:16 +00:00
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "USBCCID");
|
2012-01-13 22:04:09 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "CCID Packet");
|
2011-11-07 16:56:16 +00:00
|
|
|
|
2012-03-13 15:19:29 +00:00
|
|
|
/* Start with a top-level item to add everything else to */
|
2013-01-26 15:34:48 +00:00
|
|
|
item = proto_tree_add_item(tree, proto_ccid, tvb, 0, 10, ENC_NA);
|
2012-03-13 15:19:29 +00:00
|
|
|
ccid_tree = proto_item_add_subtree(item, ett_ccid);
|
2011-11-07 16:56:16 +00:00
|
|
|
|
2012-03-13 15:19:29 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bMessageType, tvb, 0, 1, ENC_NA);
|
|
|
|
cmd = tvb_get_guint8(tvb, 0);
|
2011-11-07 16:56:16 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " - %s", val_to_str_const(cmd, ccid_messagetypes_vals, "Unknown"));
|
|
|
|
|
2012-03-13 15:19:29 +00:00
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case PC_RDR_SET_PARAMS:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bProtocolNum, tvb, 7, 1, ENC_LITTLE_ENDIAN);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-05-17 21:24:48 +00:00
|
|
|
/* Placeholder for abRFU */
|
|
|
|
proto_tree_add_text(ccid_tree, tvb, 8, 2, "Reserved for Future Use");
|
2013-05-31 12:54:35 +00:00
|
|
|
if (tvb_get_letohl(tvb, 1) != 0)
|
|
|
|
{
|
|
|
|
next_tvb = tvb_new_subset_remaining(tvb, 10);
|
|
|
|
call_dissector(sub_handles[SUB_DATA], next_tvb, pinfo, tree);
|
|
|
|
}
|
2012-05-17 21:24:48 +00:00
|
|
|
break;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
|
|
|
case PC_RDR_ICC_ON:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bPowerSelect, tvb, 7, 1, ENC_LITTLE_ENDIAN);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-05-17 21:24:48 +00:00
|
|
|
/* Placeholder for abRFU */
|
|
|
|
proto_tree_add_text(ccid_tree, tvb, 8, 2, "Reserved for Future Use");
|
|
|
|
break;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
|
|
|
case PC_RDR_ICC_OFF:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-05-17 21:24:48 +00:00
|
|
|
/* Placeholder for abRFU */
|
|
|
|
proto_tree_add_text(ccid_tree, tvb, 7, 3, "Reserved for Future Use");
|
|
|
|
break;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
|
|
|
case PC_RDR_GET_SLOT_STATUS:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-05-17 21:24:48 +00:00
|
|
|
/* Placeholder for abRFU */
|
|
|
|
proto_tree_add_text(ccid_tree, tvb, 7, 3, "Reserved for Future Use");
|
|
|
|
break;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
|
|
|
case PC_RDR_GET_PARAMS:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-05-17 21:24:48 +00:00
|
|
|
/* Placeholder for abRFU */
|
|
|
|
proto_tree_add_text(ccid_tree, tvb, 7, 3, "Reserved for Future Use");
|
|
|
|
break;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
|
|
|
case PC_RDR_XFR_BLOCK:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bBWI, tvb, 7, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_wLevelParameter, tvb, 8, 2, ENC_LITTLE_ENDIAN);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
if (tvb_get_letohl(tvb, 1) != 0)
|
|
|
|
{
|
|
|
|
next_tvb = tvb_new_subset_remaining(tvb, 10);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* See if the dissector isn't Data */
|
|
|
|
if (sub_selected != SUB_DATA) {
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* See if we're in PN532-with-ACS PseudoHeader Mode */
|
|
|
|
if (sub_selected == SUB_PN532_ACS_PSEUDO_APDU) {
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* See if the payload starts with 0xD4 (Host -> PN532) */
|
|
|
|
if (tvb_get_guint8(tvb, 15) == 0xD4) {
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* Skip the 5 byte ACS Pseudo-Header */
|
|
|
|
call_dissector(sub_handles[sub_selected], tvb_new_subset_remaining(tvb, 15), pinfo, tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* We've probably got an APDU addressed elsewhere */
|
|
|
|
call_dissector(sub_handles[SUB_DATA], next_tvb, pinfo, tree);
|
|
|
|
}
|
2012-05-17 21:24:48 +00:00
|
|
|
}
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
else if (sub_selected == SUB_ISO7816) {
|
|
|
|
/* sent/received is from the perspective of the card reader */
|
|
|
|
pinfo->p2p_dir = P2P_DIR_SENT;
|
|
|
|
call_dissector(sub_handles[SUB_ISO7816], next_tvb, pinfo, tree);
|
|
|
|
}
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* The user probably wanted GSM SIM, or something else */
|
|
|
|
else {
|
|
|
|
call_dissector(sub_handles[sub_selected], next_tvb, pinfo, tree);
|
2012-05-17 21:24:48 +00:00
|
|
|
}
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-05-17 21:24:48 +00:00
|
|
|
}
|
2012-05-17 21:11:22 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* The user only wants plain data */
|
2012-05-17 21:24:48 +00:00
|
|
|
else {
|
2013-05-31 12:54:35 +00:00
|
|
|
call_dissector(sub_handles[SUB_DATA], next_tvb, pinfo, tree);
|
2012-05-17 21:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
|
|
|
case RDR_PC_DATA_BLOCK:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bStatus, tvb, 7, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bError, tvb, 8, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bChainParameter, tvb, 9, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
if (tvb_get_letohl(tvb, 1) != 0)
|
|
|
|
{
|
|
|
|
next_tvb = tvb_new_subset_remaining(tvb, 10);
|
2012-05-17 21:24:48 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
/* If the user has opted to use the PN532 dissector for PC -> Reader comms, then use it here */
|
|
|
|
if (sub_selected == SUB_PN532_ACS_PSEUDO_APDU && tvb_get_guint8(tvb, 10) == 0xD5) {
|
|
|
|
call_dissector(sub_handles[SUB_PN532_ACS_PSEUDO_APDU], next_tvb, pinfo, tree);
|
|
|
|
}
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2013-06-13 10:52:34 +00:00
|
|
|
/* Try to dissect responses to GSM SIM packets */
|
|
|
|
if (sub_selected == SUB_GSM_SIM_CMD) {
|
|
|
|
call_dissector(sub_handles[SUB_GSM_SIM_RSP], next_tvb, pinfo, tree);
|
|
|
|
}
|
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
else if (sub_selected == SUB_ISO7816) {
|
|
|
|
pinfo->p2p_dir = P2P_DIR_RECV;
|
|
|
|
call_dissector(sub_handles[SUB_ISO7816], next_tvb, pinfo, tree);
|
|
|
|
}
|
2012-05-17 21:11:22 +00:00
|
|
|
|
2013-05-31 12:54:35 +00:00
|
|
|
else {
|
|
|
|
call_dissector(sub_handles[SUB_DATA], next_tvb, pinfo, tree);
|
|
|
|
}
|
2012-05-17 21:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-11-07 16:56:16 +00:00
|
|
|
|
2012-03-13 15:19:29 +00:00
|
|
|
case RDR_PC_SLOT_STATUS:
|
2012-05-17 21:24:48 +00:00
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_dwLength, tvb, 1, 4, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSlot, tvb, 5, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bSeq, tvb, 6, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bStatus, tvb, 7, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bError, tvb, 8, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
proto_tree_add_item(ccid_tree, hf_ccid_bClockStatus, tvb, 9, 1, ENC_LITTLE_ENDIAN);
|
|
|
|
break;
|
2011-11-07 16:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_ccid(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
|
|
|
|
{&hf_ccid_bMessageType,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Message Type", "usbccid.bMessageType", FT_UINT8, BASE_HEX,
|
2013-05-31 12:54:35 +00:00
|
|
|
VALS(ccid_opcode_vals), 0x0, NULL, HFILL }},
|
2011-11-07 16:56:16 +00:00
|
|
|
{&hf_ccid_dwLength,
|
2013-05-31 12:54:35 +00:00
|
|
|
{ "Packet Length", "usbccid.dwLength", FT_UINT32, BASE_DEC,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bSlot,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Slot", "usbccid.bSlot", FT_UINT8, BASE_DEC,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bSeq,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Sequence", "usbccid.bSeq", FT_UINT8, BASE_DEC,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bStatus,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Status", "usbccid.bStatus", FT_UINT8, BASE_DEC,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bError,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Error", "usbccid.bError", FT_UINT8, BASE_DEC,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bChainParameter,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Chain Parameter", "usbccid.bChainParameter", FT_UINT8, BASE_DEC,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bPowerSelect,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Voltage Level", "usbccid.bPowerSelect", FT_UINT8, BASE_HEX,
|
2011-11-07 16:56:16 +00:00
|
|
|
VALS(ccid_voltage_levels_vals), 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bClockStatus,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Clock Status", "usbccid.bClockStatus", FT_UINT8, BASE_HEX,
|
2011-11-07 16:56:16 +00:00
|
|
|
VALS(ccid_clock_states_vals), 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bProtocolNum,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Data Structure Type", "usbccid.bProtocolNum", FT_UINT8, BASE_HEX,
|
2011-11-07 16:56:16 +00:00
|
|
|
VALS(ccid_proto_structs_vals), 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_bBWI,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Block Wait Time Integer", "usbccid.bBWI", FT_UINT8, BASE_HEX,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }},
|
|
|
|
{&hf_ccid_wLevelParameter,
|
2012-01-28 17:19:25 +00:00
|
|
|
{ "Level Parameter", "usbccid.wLevelParameter", FT_UINT8, BASE_HEX,
|
2011-11-07 16:56:16 +00:00
|
|
|
NULL, 0x0, NULL, HFILL }}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_ccid
|
|
|
|
};
|
|
|
|
|
2012-02-23 09:12:30 +00:00
|
|
|
static const enum_val_t sub_enum_vals[] = {
|
|
|
|
{ "data", "Data", SUB_DATA },
|
2012-05-17 21:11:22 +00:00
|
|
|
{ "iso7816", "Generic ISO 7816", SUB_ISO7816 },
|
2013-06-13 10:52:34 +00:00
|
|
|
{ "gsm_sim", "GSM SIM", SUB_GSM_SIM_CMD },
|
2012-05-17 21:24:48 +00:00
|
|
|
{ "pn532", "NXP PN532 with ACS Pseudo-Header", SUB_PN532_ACS_PSEUDO_APDU},
|
2012-02-23 09:12:30 +00:00
|
|
|
{ NULL, NULL, 0 }
|
2012-03-13 15:19:29 +00:00
|
|
|
};
|
|
|
|
|
2012-02-23 09:12:30 +00:00
|
|
|
module_t *pref_mod;
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-01-28 17:19:25 +00:00
|
|
|
proto_ccid = proto_register_protocol("USB CCID", "USBCCID", "usbccid");
|
2011-11-07 16:56:16 +00:00
|
|
|
proto_register_field_array(proto_ccid, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-02-23 09:12:30 +00:00
|
|
|
pref_mod = prefs_register_protocol(proto_ccid, NULL);
|
|
|
|
prefs_register_enum_preference(pref_mod, "prtype", "PC -> Reader Payload Type", "How commands from the PC to the reader are interpreted",
|
|
|
|
&sub_selected, sub_enum_vals, FALSE);
|
2011-11-07 16:56:16 +00:00
|
|
|
|
2012-01-28 17:19:25 +00:00
|
|
|
ccid_dissector_table = register_dissector_table("usbccid.payload",
|
2011-11-07 16:56:16 +00:00
|
|
|
"CCID Payload", FT_UINT8, BASE_DEC);
|
|
|
|
|
2012-01-28 17:19:25 +00:00
|
|
|
register_dissector("usbccid", dissect_ccid, proto_ccid);
|
2011-11-07 16:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handler registration */
|
|
|
|
void
|
|
|
|
proto_reg_handoff_ccid(void)
|
|
|
|
{
|
2012-01-13 22:04:09 +00:00
|
|
|
dissector_handle_t usb_ccid_bulk_handle;
|
|
|
|
|
2012-01-28 17:19:25 +00:00
|
|
|
usb_ccid_bulk_handle = find_dissector("usbccid");
|
2011-11-07 16:56:16 +00:00
|
|
|
dissector_add_uint("usb.bulk", IF_CLASS_SMART_CARD, usb_ccid_bulk_handle);
|
2012-03-13 15:19:29 +00:00
|
|
|
|
2012-02-23 09:12:30 +00:00
|
|
|
sub_handles[SUB_DATA] = find_dissector("data");
|
2012-05-17 21:11:22 +00:00
|
|
|
sub_handles[SUB_ISO7816] = find_dissector("iso7816");
|
2013-06-13 10:52:34 +00:00
|
|
|
sub_handles[SUB_GSM_SIM_CMD] = find_dissector("gsm_sim.command");
|
2012-03-13 15:19:29 +00:00
|
|
|
sub_handles[SUB_PN532_ACS_PSEUDO_APDU] = find_dissector("pn532");
|
2013-06-13 10:52:34 +00:00
|
|
|
sub_handles[SUB_GSM_SIM_RSP] = find_dissector("gsm_sim.response");
|
2011-11-07 16:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|