aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-rfid-felica.c
diff options
context:
space:
mode:
authorChris Maynard <Christopher.Maynard@GTECH.COM>2012-02-07 17:01:01 +0000
committerChris Maynard <Christopher.Maynard@GTECH.COM>2012-02-07 17:01:01 +0000
commit77e48cb48816f9e928f69e869c14879dcfc95432 (patch)
treea5ba1f43a0d3cb645d595d592c7934158411635d /epan/dissectors/packet-rfid-felica.c
parent76efc975bdbc28edaba213f784dc8560814e8ec0 (diff)
Make some minimally required changes as pointed out in bug6758[1].
In addition: -> I didn't think using tvb_new_subset_remaining() in order to iterate through the blocks was the best way to implement this, so I changed it to the method I had proposed earlier[2]. -> Some whitespace cleanup. -> Noted some "TODO"'s for potential further improvements. [1]: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6758#c9 [2]: http://article.gmane.org/gmane.network.wireshark.devel/24721 svn path=/trunk/; revision=40920
Diffstat (limited to 'epan/dissectors/packet-rfid-felica.c')
-rw-r--r--epan/dissectors/packet-rfid-felica.c312
1 files changed, 159 insertions, 153 deletions
diff --git a/epan/dissectors/packet-rfid-felica.c b/epan/dissectors/packet-rfid-felica.c
index 7729fab159..d770f9cd02 100644
--- a/epan/dissectors/packet-rfid-felica.c
+++ b/epan/dissectors/packet-rfid-felica.c
@@ -6,14 +6,14 @@
* http://www.sony.net/Products/felica/business/tech-support/data/format_sequence_guidelines_1.1.pdf
* http://code.google.com/u/101410204121169118393/updates
* https://github.com/codebutler/farebot/wiki/Suica
- *
+ *
* Copyright 2012, Tyson Key <tyson.key@gmail.com>
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
- * Copyright 1998 Gerald Combs
+ * 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
@@ -78,7 +78,7 @@ static int hf_felica_status_flag1 = -1;
static int hf_felica_status_flag2 = -1;
/* - Commands - */
-#define CMD_POLLING 0x00
+#define CMD_POLLING 0x00
#define CMD_READ_WO_ENCRYPTION 0x06
#define CMD_WRITE_WO_ENCRYPTION 0x08
@@ -111,6 +111,12 @@ static int hf_felica_status_flag2 = -1;
#define SC_DOUBLE_WILDCARD 0xffff
+/* TODO: Since commands and responses do not have any overlapping values,
+ * consider a single felica_opcodes[] value_string array encompassing both.
+ * This would simplify the column update by only calling it in one place, i.e.:
+ * col_set_str(pinfo->cinfo, COL_INFO,
+ * val_to_str_const(opcode, felica_opcodes, "Unknown"));
+ */
static const value_string felica_commands[] = {
{CMD_POLLING, "Polling"},
{CMD_READ_WO_ENCRYPTION, "Read Without Encryption"},
@@ -135,7 +141,7 @@ static const value_string felica_req_codes[] = {
{RC_COM_PERF_REQ, "Communication Performance Request"},
/* Others are reserved for future use */
-
+
/* End of request codes */
{0x00, NULL}
};
@@ -164,98 +170,98 @@ static void dissect_felica(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_item *item;
proto_tree *felica_tree;
guint8 opcode;
-
guint8 rwe_pos = 0;
-
- tvbuff_t *rwe_blocks_tvb;
tvbuff_t *rwe_resp_data_tvb;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "FeliCa");
col_set_str(pinfo->cinfo, COL_INFO, "FeliCa Packet");
if (tree) {
- /* Start with a top-level item to add everything else to */
-
- item = proto_tree_add_item(tree, proto_felica, tvb, 0, -1, ENC_NA);
- felica_tree = proto_item_add_subtree(item, ett_felica);
- opcode = tvb_get_guint8(tvb, 0);
-
- switch (opcode) {
-
- case CMD_POLLING:
- proto_tree_add_item(felica_tree, hf_felica_command, tvb, 0, 1, ENC_NA);
-
- proto_tree_add_item(felica_tree, hf_felica_sys_code, tvb, 1, 2, ENC_BIG_ENDIAN);
- proto_tree_add_item(felica_tree, hf_felica_req_code, tvb, 3, 1, ENC_BIG_ENDIAN);
- proto_tree_add_item(felica_tree, hf_felica_timeslot, tvb, 4, 1, ENC_BIG_ENDIAN);
-
- col_set_str(pinfo->cinfo, COL_INFO, "Polling Request");
-
- break;
-
- case RES_POLLING:
- proto_tree_add_item(felica_tree, hf_felica_response, tvb, 0, 1, ENC_NA);
-
- proto_tree_add_item(felica_tree, hf_felica_idm, tvb, 1, 8, ENC_BIG_ENDIAN);
- proto_tree_add_item(felica_tree, hf_felica_pnm, tvb, 9, 8, ENC_BIG_ENDIAN);
-
- if (tvb_length(tvb) == 19) {
- proto_tree_add_item(felica_tree, hf_felica_sys_code, tvb, 17, 2, ENC_BIG_ENDIAN);
- }
-
- /* Request data - 0 or 2 bytes long; data corresponding to request code; only if
- request code of command packet is not 00 and corresponds to request data */
-
- col_set_str(pinfo->cinfo, COL_INFO, "Polling Response");
-
- break;
-
- case CMD_READ_WO_ENCRYPTION:
- proto_tree_add_item(felica_tree, hf_felica_command, tvb, 0, 1, ENC_NA);
-
- proto_tree_add_item(felica_tree, hf_felica_idm, tvb, 1, 8, ENC_BIG_ENDIAN);
- proto_tree_add_item(felica_tree, hf_felica_nbr_of_svcs, tvb, 9, 1, ENC_BIG_ENDIAN);
-
- /* Service codes are always 2 bytes in length */
-
- /* There can technically be multiple Service Codes - although my traces only contain 1 */
- proto_tree_add_item(felica_tree, hf_felica_svc_code, tvb, 10, 2, ENC_BIG_ENDIAN);
-
- /* Number of Blocks - 1byte */
- proto_tree_add_item(felica_tree, hf_felica_nbr_of_blocks, tvb, 12, 1, ENC_BIG_ENDIAN);
-
- /* Collect the data after the Number of Block IDs byte */
- rwe_blocks_tvb = tvb_new_subset_remaining(tvb, 13);
-
- /* Iterate through the block list, and update the tree */
- for (rwe_pos = 0; rwe_pos < tvb_length(rwe_blocks_tvb); rwe_pos+=2) {
- proto_tree_add_uint(felica_tree, hf_felica_block_nbr, rwe_blocks_tvb, rwe_pos,
- 2, tvb_get_guint8(rwe_blocks_tvb, rwe_pos + 1));
- }
-
- col_set_str(pinfo->cinfo, COL_INFO, "Read Without Encryption Request");
- break;
-
- case RES_READ_WO_ENCRYPTION:
- proto_tree_add_item(felica_tree, hf_felica_response, tvb, 0, 1, ENC_NA);
-
- proto_tree_add_item(felica_tree, hf_felica_idm, tvb, 1, 8, ENC_BIG_ENDIAN);
- proto_tree_add_item(felica_tree, hf_felica_status_flag1, tvb, 9, 1, ENC_BIG_ENDIAN);
- proto_tree_add_item(felica_tree, hf_felica_status_flag2, tvb, 10, 1, ENC_BIG_ENDIAN);
-
- proto_tree_add_item(felica_tree, hf_felica_nbr_of_blocks, tvb, 11, 1, ENC_BIG_ENDIAN);
-
- rwe_resp_data_tvb = tvb_new_subset_remaining(tvb, 12);
- call_dissector(data_handle, rwe_resp_data_tvb, pinfo, tree);
-
- col_set_str(pinfo->cinfo, COL_INFO, "Read Without Encryption Response");
-
- break;
-
- default:
- col_set_str(pinfo->cinfo, COL_INFO, "Unknown");
- break;
- }
+ /* Start with a top-level item to add everything else to */
+ item = proto_tree_add_item(tree, proto_felica, tvb, 0, -1, ENC_NA);
+ felica_tree = proto_item_add_subtree(item, ett_felica);
+ }
+ opcode = tvb_get_guint8(tvb, 0);
+
+ switch (opcode) {
+
+ case CMD_POLLING:
+ col_set_str(pinfo->cinfo, COL_INFO, "Polling Request");
+ if (tree) {
+ proto_tree_add_item(felica_tree, hf_felica_command, tvb, 0, 1, ENC_NA);
+ proto_tree_add_item(felica_tree, hf_felica_sys_code, tvb, 1, 2, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_req_code, tvb, 3, 1, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_timeslot, tvb, 4, 1, ENC_BIG_ENDIAN);
+ }
+ break;
+
+ case RES_POLLING:
+ col_set_str(pinfo->cinfo, COL_INFO, "Polling Response");
+ if (tree) {
+ proto_tree_add_item(felica_tree, hf_felica_response, tvb, 0, 1, ENC_NA);
+ proto_tree_add_item(felica_tree, hf_felica_idm, tvb, 1, 8, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_pnm, tvb, 9, 8, ENC_BIG_ENDIAN);
+
+ if (tvb_reported_length(tvb) == 19)
+ proto_tree_add_item(felica_tree, hf_felica_sys_code, tvb, 17, 2, ENC_BIG_ENDIAN);
+
+ /*
+ * Request data - 0 or 2 bytes long; data corresponding to request
+ * code; only if request code of command packet is not 00 and
+ * corresponds to request data
+ */
+ }
+ break;
+
+ case CMD_READ_WO_ENCRYPTION:
+ col_set_str(pinfo->cinfo, COL_INFO, "Read Without Encryption Request");
+ if (tree) {
+ proto_tree_add_item(felica_tree, hf_felica_command, tvb, 0, 1, ENC_NA);
+ proto_tree_add_item(felica_tree, hf_felica_idm, tvb, 1, 8, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_nbr_of_svcs, tvb, 9, 1, ENC_BIG_ENDIAN);
+
+ /* Service codes are always 2 bytes in length */
+
+ /* There can technically be multiple Service Codes - although my traces only contain 1 */
+ proto_tree_add_item(felica_tree, hf_felica_svc_code, tvb, 10, 2, ENC_BIG_ENDIAN);
+
+ /* Number of Blocks - 1byte */
+ proto_tree_add_item(felica_tree, hf_felica_nbr_of_blocks, tvb, 12, 1, ENC_BIG_ENDIAN);
+
+ /* Iterate through the block list, and update the tree */
+ for (rwe_pos = 0; rwe_pos < tvb_get_guint8(tvb, 12); rwe_pos++) {
+ proto_tree_add_uint(felica_tree, hf_felica_block_nbr, tvb,
+ 13 + 2 * rwe_pos, 2, tvb_get_guint8(tvb, 14 + 2 * rwe_pos));
+ }
+ }
+ break;
+
+ case RES_READ_WO_ENCRYPTION:
+ col_set_str(pinfo->cinfo, COL_INFO, "Read Without Encryption Response");
+ if (tree) {
+ proto_tree_add_item(felica_tree, hf_felica_response, tvb, 0, 1, ENC_NA);
+ proto_tree_add_item(felica_tree, hf_felica_idm, tvb, 1, 8, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_status_flag1, tvb, 9, 1, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_status_flag2, tvb, 10, 1, ENC_BIG_ENDIAN);
+ proto_tree_add_item(felica_tree, hf_felica_nbr_of_blocks, tvb, 11, 1, ENC_BIG_ENDIAN);
+ }
+ rwe_resp_data_tvb = tvb_new_subset_remaining(tvb, 12);
+ call_dissector(data_handle, rwe_resp_data_tvb, pinfo, tree);
+ break;
+
+ case CMD_WRITE_WO_ENCRYPTION:
+ col_set_str(pinfo->cinfo, COL_INFO, "Write Without Encryption Request");
+ /* TODO */
+ break;
+
+ case RES_WRITE_WO_ENCRYPTION:
+ col_set_str(pinfo->cinfo, COL_INFO, "Write Without Encryption Response");
+ /* TODO */
+ break;
+
+ default:
+ col_set_str(pinfo->cinfo, COL_INFO, "Unknown");
+ break;
}
}
@@ -263,71 +269,71 @@ void
proto_register_felica(void)
{
static hf_register_info hf[] = {
-
- {&hf_felica_command,
- { "Command", "felica.cmd", FT_UINT8, BASE_HEX,
- VALS(felica_commands), 0x0, NULL, HFILL }},
- {&hf_felica_response,
- { "Response", "felica.res", FT_UINT8, BASE_HEX,
- VALS(felica_responses), 0x0, NULL, HFILL }},
-
- /* Request Code */
- {&hf_felica_req_code,
- { "Request Code", "felica.req.code", FT_UINT8, BASE_HEX,
- VALS(felica_req_codes), 0x0, NULL, HFILL }},
-
- {&hf_felica_idm,
- { "IDm (Manufacture ID)/NFCID2", "felica.idm", FT_UINT64, BASE_HEX,
- NULL, 0x0, NULL, HFILL }},
-
- /* System Code */
- {&hf_felica_sys_code,
- { "System Code", "felica.sys_c", FT_UINT16, BASE_HEX,
- VALS(felica_sys_codes), 0x0, NULL, HFILL }},
-
- /* Service Code */
- {&hf_felica_svc_code,
- { "Service Code", "felica.svc_code", FT_UINT16, BASE_HEX,
- NULL, 0x0, NULL, HFILL }},
-
- /* Parameter/PAD */
- {&hf_felica_pnm,
- { "PNm (Manufacture Parameter)/PAD", "felica.pnm", FT_UINT64, BASE_HEX,
- NULL, 0x0, NULL, HFILL }},
-
- /* Number of Services */
- {&hf_felica_nbr_of_svcs,
- { "Number of Services", "felica.svcs", FT_UINT8, BASE_DEC,
- NULL, 0x0, NULL, HFILL }},
-
- /* Number of Blocks */
- {&hf_felica_nbr_of_blocks,
- { "Number of Blocks", "felica.blocks", FT_UINT8, BASE_DEC,
- NULL, 0x0, NULL, HFILL }},
-
- /* Block ID */
- {&hf_felica_block_nbr,
- { "Block Number", "felica.block.nbr", FT_UINT8, BASE_DEC,
- NULL, 0x0, NULL, HFILL }},
-
- /* Status Flag 1 */
- {&hf_felica_status_flag1,
- { "Status Flag 1", "felica.status.flag1", FT_UINT8, BASE_HEX,
- NULL, 0x0, NULL, HFILL }},
-
- /* Status Flag 2 */
- {&hf_felica_status_flag2,
- { "Status Flag 2", "felica.status.flag2", FT_UINT8, BASE_HEX,
- NULL, 0x0, NULL, HFILL }},
-
- /* Timeslot */
- {&hf_felica_timeslot,
- { "Timeslot", "felica.timeslot", FT_UINT8, BASE_HEX,
- NULL, 0x0, NULL, HFILL }},
+
+ {&hf_felica_command,
+ { "Command", "felica.cmd", FT_UINT8, BASE_HEX,
+ VALS(felica_commands), 0x0, NULL, HFILL }},
+ {&hf_felica_response,
+ { "Response", "felica.res", FT_UINT8, BASE_HEX,
+ VALS(felica_responses), 0x0, NULL, HFILL }},
+
+ /* Request Code */
+ {&hf_felica_req_code,
+ { "Request Code", "felica.req.code", FT_UINT8, BASE_HEX,
+ VALS(felica_req_codes), 0x0, NULL, HFILL }},
+
+ {&hf_felica_idm,
+ { "IDm (Manufacture ID)/NFCID2", "felica.idm", FT_UINT64, BASE_HEX,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* System Code */
+ {&hf_felica_sys_code,
+ { "System Code", "felica.sys_code", FT_UINT16, BASE_HEX,
+ VALS(felica_sys_codes), 0x0, NULL, HFILL }},
+
+ /* Service Code */
+ {&hf_felica_svc_code,
+ { "Service Code", "felica.svc_code", FT_UINT16, BASE_HEX,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Parameter/PAD */
+ {&hf_felica_pnm,
+ { "PNm (Manufacture Parameter)/PAD", "felica.pnm", FT_UINT64, BASE_HEX,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Number of Services */
+ {&hf_felica_nbr_of_svcs,
+ { "Number of Services", "felica.svcs", FT_UINT8, BASE_DEC,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Number of Blocks */
+ {&hf_felica_nbr_of_blocks,
+ { "Number of Blocks", "felica.blocks", FT_UINT8, BASE_DEC,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Block ID */
+ {&hf_felica_block_nbr,
+ { "Block Number", "felica.block.nbr", FT_UINT8, BASE_DEC,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Status Flag 1 */
+ {&hf_felica_status_flag1,
+ { "Status Flag 1", "felica.status.flag1", FT_UINT8, BASE_HEX,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Status Flag 2 */
+ {&hf_felica_status_flag2,
+ { "Status Flag 2", "felica.status.flag2", FT_UINT8, BASE_HEX,
+ NULL, 0x0, NULL, HFILL }},
+
+ /* Timeslot */
+ {&hf_felica_timeslot,
+ { "Timeslot", "felica.timeslot", FT_UINT8, BASE_HEX,
+ NULL, 0x0, NULL, HFILL }}
};
-
+
static gint *ett[] = {
- &ett_felica
+ &ett_felica
};
proto_felica = proto_register_protocol("Sony FeliCa", "FeliCa", "felica");
@@ -341,7 +347,7 @@ proto_register_felica(void)
void
proto_reg_handoff_felica(void)
{
- data_handle = find_dissector("data");
+ data_handle = find_dissector("data");
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html