2 * Routines for ACR122 USB NFC dongle
4 * Copyright 2013, Michal Labedzki for Tieto Corporation
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/prefs.h>
17 #include <epan/expert.h>
20 #include "packet-usb.h"
22 static int proto_acr122
;
29 static int hf_status_word
;
30 static int hf_status_word_sw1
;
31 static int hf_status_word_sw2
;
32 static int hf_status_word_led_reserved
;
33 static int hf_status_word_led_green
;
34 static int hf_status_word_led_red
;
35 static int hf_command
;
36 static int hf_response
;
37 static int hf_response_for
;
38 static int hf_picc_operating_auto_picc_polling
;
39 static int hf_picc_operating_auto_ats_generation
;
40 static int hf_picc_operating_polling_interval
;
41 static int hf_picc_operating_felica_424k
;
42 static int hf_picc_operating_felica_212k
;
43 static int hf_picc_operating_topaz
;
44 static int hf_picc_operating_iso_14443_type_b
;
45 static int hf_picc_operating_iso_14443_type_a
;
46 static int hf_firmware_version
;
47 static int hf_led_green_blinking_state
;
48 static int hf_led_red_blinking_state
;
49 static int hf_led_green_mask
;
50 static int hf_led_red_mask
;
51 static int hf_led_initial_green_blinking_state
;
52 static int hf_led_initial_red_blinking_state
;
53 static int hf_led_final_green_state
;
54 static int hf_led_final_red_state
;
55 static int hf_led_t1_duration
;
56 static int hf_led_t2_duration
;
57 static int hf_led_number_of_repetition
;
58 static int hf_led_link_to_buzzer
;
59 static int hf_timeout
;
60 static int hf_poll_buzzer_status
;
62 static int hf_key_structure
;
63 static int hf_key_number
;
64 static int hf_key_type
;
65 static int hf_block_number
;
66 static int hf_source_block_number
;
67 static int hf_target_block_number
;
69 static int hf_static_byte
;
70 static int hf_version
;
76 static int ett_acr122
;
77 static int ett_p1_item
;
78 static int ett_p2_item
;
79 static int ett_status_word
;
80 static int ett_status_word_sw2
;
82 static expert_field ei_unknown_command_or_invalid_parameters
;
84 static dissector_handle_t acr122_handle
;
85 static dissector_handle_t pn532_handle
;
87 static wmem_tree_t
*command_info
;
89 typedef struct command_data_t
{
91 uint32_t device_address
;
95 uint32_t command_frame_number
;
96 uint32_t response_frame_number
;
99 /* Not part of protocol, generated values */
100 #define CMD_UNKNOWN 0x00
101 #define CMD_GET_DATA_UID 0x01
102 #define CMD_GET_DATA_ATS 0x02
103 #define CMD_LOAD_AUTHENTICATION_KEYS 0x03
104 #define CMD_AUTHENTICATION_OBSOLETE 0x04
105 #define CMD_AUTHENTICATION 0x05
106 #define CMD_READ_BINARY_BLOCKS 0x06
107 #define CMD_UPDATE_BINARY_BLOCKS 0x07
108 #define CMD_VALUE_BLOCK_OPERATION 0x08
109 #define CMD_READ_VALUE_BLOCK 0x09
110 #define CMD_RESTORE_VALUE_BLOCK 0x0A
111 #define CMD_DIRECT_TRANSMIT 0x0B
112 #define CMD_BI_COLOR_AND_BUZZER_LED_CONTROL 0x0C
113 #define CMD_GET_FIRMWARE_VERSION 0x0D
114 #define CMD_GET_PICC_OPERATING_PARAMETER 0x0E
115 #define CMD_SET_PICC_OPERATING_PARAMETER 0x0F
116 #define CMD_SET_TIMEOUT_PARAMETER 0x10
117 #define CMD_SET_BUZZER_OUTPUT_FOR_CARD_DETECTION 0x11
119 static const value_string command_vals
[] = {
120 { CMD_GET_DATA_UID
, "Get Data - UID" },
121 { CMD_GET_DATA_ATS
, "Get Data - ATS" },
122 { CMD_LOAD_AUTHENTICATION_KEYS
, "Load Authentication Keys" },
123 { CMD_AUTHENTICATION_OBSOLETE
, "Authentication (Obsolete)" },
124 { CMD_AUTHENTICATION
, "Authentication" },
125 { CMD_READ_BINARY_BLOCKS
, "Read Binary Blocks" },
126 { CMD_UPDATE_BINARY_BLOCKS
, "Update Binary Blocks" },
127 { CMD_VALUE_BLOCK_OPERATION
, "Value Block Operation" },
128 { CMD_READ_VALUE_BLOCK
, "Read Value Block" },
129 { CMD_RESTORE_VALUE_BLOCK
, "Restore Value Block" },
130 { CMD_DIRECT_TRANSMIT
, "Direct Transmit" },
131 { CMD_BI_COLOR_AND_BUZZER_LED_CONTROL
, "Bi-Color and Buzzer LED Control" },
132 { CMD_GET_FIRMWARE_VERSION
, "Get Firmware Version" },
133 { CMD_GET_PICC_OPERATING_PARAMETER
, "Get PICC Operating Parameter" },
134 { CMD_SET_PICC_OPERATING_PARAMETER
, "Set PICC Operating Parameter" },
135 { CMD_SET_TIMEOUT_PARAMETER
, "Set Timeout Parameter" },
136 { CMD_SET_BUZZER_OUTPUT_FOR_CARD_DETECTION
, "Set Buzzer Output for Card Detection" },
139 static value_string_ext command_vals_ext
= VALUE_STRING_EXT_INIT(command_vals
);
141 static const range_string status_word_rvals
[] = {
142 { 0x6300, 0x6300, "Operation Fail" },
143 { 0x6a81, 0x6a81, "Function not Supported" },
144 { 0x9000, 0x90FF, "Success" },
148 static const value_string link_to_buzzer_vals
[] = {
149 { 0x00, "The buzzer will not turn on" },
150 { 0x01, "The buzzer will turn on during the T1 Duration" },
151 { 0x02, "The buzzer will turn on during the T2 Duration" },
152 { 0x03, "The buzzer will turn on during the T1 and T2 Duration" },
156 static const value_string key_structure_vals
[] = {
157 { 0x00, "Key is loaded into the reader volatile memory" },
161 static const value_string poll_buzzer_status_vals
[] = {
162 { 0x00, "Buzzer disabled on card detected" },
163 { 0xFF, "Buzzer enabled on card detected" },
167 static const value_string key_type_vals
[] = {
173 static const value_string vb_op_vals
[] = {
174 { 0x00, "Store the \"Value\" into the block. The block will then be converted to a value block." },
175 { 0x01, "Increment the value of the value block by the \"Value\". This command is only valid for value block." },
176 { 0x02, "Decrement the value of the value block by the \"Value\". This command is only valid for value block." },
180 void proto_register_acr122(void);
181 void proto_reg_handoff_acr122(void);
184 duration_base(char *buf
, uint32_t value
) {
185 snprintf(buf
, ITEM_LABEL_LENGTH
, "%u.%03u s", value
* 100 / 1000, value
* 100 % 1000);
189 timeout_base(char *buf
, uint32_t value
) {
191 snprintf(buf
, ITEM_LABEL_LENGTH
, "No timeout check");
192 else if (value
== 0xFF)
193 snprintf(buf
, ITEM_LABEL_LENGTH
, "Wait until the contactless chip responds");
195 snprintf(buf
, ITEM_LABEL_LENGTH
, "%u [s]", value
* 5);
197 snprintf(buf
, ITEM_LABEL_LENGTH
, "%u:%02u [mm:ss]", value
* 5 / 60, value
* 5 % 60);
202 dissect_acr122(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
204 proto_item
*main_item
;
205 proto_tree
*main_tree
;
210 proto_item
*sub_item
;
211 proto_item
*sub_tree
;
212 proto_item
*sw2_item
;
213 proto_item
*sw2_tree
;
222 uint8_t command
= CMD_UNKNOWN
;
223 command_data_t
*command_data
;
225 wmem_tree_key_t key
[5];
227 uint32_t device_address
;
230 uint32_t k_device_address
;
232 uint32_t k_frame_number
;
234 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ACR 122");
235 col_clear(pinfo
->cinfo
, COL_INFO
);
237 main_item
= proto_tree_add_item(tree
, proto_acr122
, tvb
, offset
, -1, ENC_NA
);
238 main_tree
= proto_item_add_subtree(main_item
, ett_acr122
);
240 if (!data
) return offset
;
241 urb
= (urb_info_t
*) data
;
243 bus_id
= urb
->bus_id
;
244 device_address
= urb
->device_address
;
245 endpoint
= urb
->endpoint
;
248 k_device_address
= device_address
;
249 k_endpoint
= endpoint
;
250 k_frame_number
= pinfo
->num
;
253 key
[0].key
= &k_bus_id
;
255 key
[1].key
= &k_device_address
;
257 key
[2].key
= &k_endpoint
;
259 key
[3].key
= &k_frame_number
;
264 if (pinfo
->p2p_dir
== P2P_DIR_SENT
) { /* Request */
265 acr_class
= tvb_get_uint8(tvb
, offset
);
266 ins
= tvb_get_uint8(tvb
, offset
+ 1);
267 p1
= tvb_get_uint8(tvb
, offset
+ 2);
268 p2
= tvb_get_uint8(tvb
, offset
+ 3);
269 length
= tvb_get_uint8(tvb
, offset
+ 4);
271 /* Recognize command by simple heuristic */
272 if (acr_class
== 0xFF) {
273 if (ins
== 0xCA && p1
== 0x00 && p2
== 0x00 && length
== 0)
274 command
= CMD_GET_DATA_UID
;
275 if (ins
== 0xCA && p1
== 0x01 && p2
== 0x00 && length
== 0)
276 command
= CMD_GET_DATA_ATS
;
277 else if (ins
== 0x82 && length
== 6)
278 command
= CMD_LOAD_AUTHENTICATION_KEYS
;
279 else if (ins
== 0x88 && p1
== 0x00)
280 command
= CMD_AUTHENTICATION_OBSOLETE
;
281 else if (ins
== 0x86 && p1
== 0x00 && p2
== 0x00 && length
== 5)
282 command
= CMD_AUTHENTICATION
;
283 else if (ins
== 0xB0 && p1
== 0x00)
284 command
= CMD_READ_BINARY_BLOCKS
;
285 else if (ins
== 0xD6 && p1
== 0x00)
286 command
= CMD_UPDATE_BINARY_BLOCKS
;
287 else if (ins
== 0xD7 && p1
== 0x00 && length
== 5)
288 command
= CMD_VALUE_BLOCK_OPERATION
;
289 else if (ins
== 0xB1 && p1
== 0x00 && length
== 4)
290 command
= CMD_READ_VALUE_BLOCK
;
291 else if (ins
== 0xD7 && p1
== 0x00 && length
== 2)
292 command
= CMD_RESTORE_VALUE_BLOCK
;
293 else if (ins
== 0x00 && p1
== 0x00 && p2
== 0x00)
294 command
= CMD_DIRECT_TRANSMIT
;
295 else if (ins
== 0x00 && p1
== 0x40 && length
== 4)
296 command
= CMD_BI_COLOR_AND_BUZZER_LED_CONTROL
;
297 else if (ins
== 0x00 && p1
== 0x48 && p2
== 0x00)
298 command
= CMD_GET_FIRMWARE_VERSION
;
299 else if (ins
== 0x00 && p1
== 0x50 && p2
== 0x00)
300 command
= CMD_GET_PICC_OPERATING_PARAMETER
;
301 else if (ins
== 0x00 && p1
== 0x51 && length
== 0)
302 command
= CMD_SET_PICC_OPERATING_PARAMETER
;
303 else if (ins
== 0x00 && p1
== 0x41 && length
== 0)
304 command
= CMD_SET_TIMEOUT_PARAMETER
;
305 else if (ins
== 0x00 && p1
== 0x52 && length
== 0)
306 command
= CMD_SET_BUZZER_OUTPUT_FOR_CARD_DETECTION
;
309 sub_item
= proto_tree_add_uint(main_tree
, hf_command
, tvb
, offset
, 4 + length
, command
);
310 proto_item_set_generated(sub_item
);
311 if (command
== CMD_UNKNOWN
)
312 expert_add_info(pinfo
, sub_item
, &ei_unknown_command_or_invalid_parameters
);
314 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Command: %s", val_to_str_ext_const(command
, &command_vals_ext
, "Unknown"));
316 proto_tree_add_item(main_tree
, hf_class
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
319 proto_tree_add_item(main_tree
, hf_ins
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
322 p1_item
= proto_tree_add_item(main_tree
, hf_p1
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
325 p2_item
= proto_tree_add_item(main_tree
, hf_p2
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
328 proto_tree_add_item(main_tree
, hf_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
332 case CMD_DIRECT_TRANSMIT
:
334 next_tvb
= tvb_new_subset_length(tvb
, offset
, length
);
335 call_dissector_with_data(pn532_handle
, next_tvb
, pinfo
, tree
, urb
);
339 case CMD_BI_COLOR_AND_BUZZER_LED_CONTROL
:
340 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
341 proto_tree_add_item(p2_tree
, hf_led_green_blinking_state
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
342 proto_tree_add_item(p2_tree
, hf_led_red_blinking_state
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
343 proto_tree_add_item(p2_tree
, hf_led_green_mask
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
344 proto_tree_add_item(p2_tree
, hf_led_red_mask
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
345 proto_tree_add_item(p2_tree
, hf_led_initial_green_blinking_state
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
346 proto_tree_add_item(p2_tree
, hf_led_initial_red_blinking_state
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
347 proto_tree_add_item(p2_tree
, hf_led_final_green_state
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
348 proto_tree_add_item(p2_tree
, hf_led_final_red_state
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
350 proto_tree_add_item(main_tree
, hf_led_t1_duration
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
353 proto_tree_add_item(main_tree
, hf_led_t2_duration
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
356 proto_tree_add_item(main_tree
, hf_led_number_of_repetition
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
359 proto_tree_add_item(main_tree
, hf_led_link_to_buzzer
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
362 case CMD_GET_DATA_UID
:
363 case CMD_GET_DATA_ATS
:
364 /* Nothing to decode */
366 case CMD_LOAD_AUTHENTICATION_KEYS
:
367 p1_tree
= proto_item_add_subtree(p1_item
, ett_p1_item
);
368 proto_tree_add_item(p1_tree
, hf_key_structure
, tvb
, offset
- 3, 1, ENC_BIG_ENDIAN
);
370 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
371 proto_tree_add_item(p2_tree
, hf_key_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
373 proto_tree_add_item(main_tree
, hf_key
, tvb
, offset
, 6, ENC_NA
);
376 case CMD_AUTHENTICATION_OBSOLETE
:
377 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
378 proto_tree_add_item(p2_tree
, hf_block_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
380 proto_tree_add_item(main_tree
, hf_key_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
383 proto_tree_add_item(main_tree
, hf_key_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
386 case CMD_AUTHENTICATION
:
387 proto_tree_add_item(main_tree
, hf_version
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
390 proto_tree_add_item(main_tree
, hf_block_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
393 proto_tree_add_item(main_tree
, hf_key_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
396 proto_tree_add_item(main_tree
, hf_key_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
399 case CMD_READ_BINARY_BLOCKS
:
400 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
401 proto_tree_add_item(p2_tree
, hf_block_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
403 case CMD_UPDATE_BINARY_BLOCKS
:
404 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
405 proto_tree_add_item(p2_tree
, hf_block_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
407 proto_tree_add_item(main_tree
, hf_data
, tvb
, offset
, length
, ENC_NA
);
410 case CMD_VALUE_BLOCK_OPERATION
:
411 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
412 proto_tree_add_item(p2_tree
, hf_block_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
414 proto_tree_add_item(main_tree
, hf_vb_op
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
417 proto_tree_add_item(main_tree
, hf_value
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
420 case CMD_READ_VALUE_BLOCK
:
421 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
422 proto_tree_add_item(p2_tree
, hf_block_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
425 case CMD_RESTORE_VALUE_BLOCK
:
426 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
427 proto_tree_add_item(p2_tree
, hf_source_block_number
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
429 proto_tree_add_item(main_tree
, hf_static_byte
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
432 proto_tree_add_item(main_tree
, hf_target_block_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
435 case CMD_SET_PICC_OPERATING_PARAMETER
:
436 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
437 proto_tree_add_item(p2_tree
, hf_picc_operating_auto_picc_polling
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
438 proto_tree_add_item(p2_tree
, hf_picc_operating_auto_ats_generation
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
439 proto_tree_add_item(p2_tree
, hf_picc_operating_polling_interval
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
440 proto_tree_add_item(p2_tree
, hf_picc_operating_felica_424k
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
441 proto_tree_add_item(p2_tree
, hf_picc_operating_felica_212k
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
442 proto_tree_add_item(p2_tree
, hf_picc_operating_topaz
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
443 proto_tree_add_item(p2_tree
, hf_picc_operating_iso_14443_type_b
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
444 proto_tree_add_item(p2_tree
, hf_picc_operating_iso_14443_type_a
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
446 case CMD_SET_TIMEOUT_PARAMETER
:
447 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
448 proto_tree_add_item(p2_tree
, hf_timeout
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
450 case CMD_SET_BUZZER_OUTPUT_FOR_CARD_DETECTION
:
451 p2_tree
= proto_item_add_subtree(p2_item
, ett_p2_item
);
452 proto_tree_add_item(p2_tree
, hf_poll_buzzer_status
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
454 case CMD_GET_PICC_OPERATING_PARAMETER
:
459 if (!pinfo
->fd
->visited
) {
460 command_data
= wmem_new(wmem_file_scope(), command_data_t
);
461 command_data
->bus_id
= bus_id
;
462 command_data
->device_address
= device_address
;
463 command_data
->endpoint
= endpoint
;
465 command_data
->command
= command
;
466 command_data
->command_frame_number
= pinfo
->num
;
467 command_data
->response_frame_number
= 0;
469 wmem_tree_insert32_array(command_info
, key
, command_data
);
472 } else { /* Response */
473 uint32_t command_frame_number
= 0;
474 bool use_status_word
= false;
475 wmem_tree_t
*wmem_tree
;
480 wmem_tree
= (wmem_tree_t
*) wmem_tree_lookup32_array(command_info
, key
);
482 command_data
= (command_data_t
*) wmem_tree_lookup32_le(wmem_tree
, pinfo
->num
);
484 if (command_data
&& (command_data
->response_frame_number
== 0 ||
485 command_data
->response_frame_number
== pinfo
->num
)) {
487 command
= command_data
->command
;
488 command_frame_number
= command_data
->command_frame_number
;
489 if (!pinfo
->fd
->visited
&& command_data
->response_frame_number
== 0) {
490 command_data
->response_frame_number
= pinfo
->num
;
495 sub_item
= proto_tree_add_uint(main_tree
, hf_response
, tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
), command
);
496 proto_item_set_generated(sub_item
);
498 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Response: %s", val_to_str_ext_const(command
, &command_vals_ext
, "Unknown"));
500 if (command
!= CMD_UNKNOWN
) {
501 sub_item
= proto_tree_add_uint(main_tree
, hf_response_for
, tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
), command_frame_number
);
502 proto_item_set_generated(sub_item
);
506 case CMD_GET_FIRMWARE_VERSION
:
507 proto_tree_add_item(main_tree
, hf_firmware_version
, tvb
, offset
, -1, ENC_NA
| ENC_ASCII
);
508 offset
+= tvb_captured_length_remaining(tvb
, offset
);
511 case CMD_DIRECT_TRANSMIT
:
512 use_status_word
= true;
514 if (tvb_captured_length_remaining(tvb
, offset
) > 2) {
515 next_tvb
= tvb_new_subset_length(tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
) - 2);
516 call_dissector_with_data(pn532_handle
, next_tvb
, pinfo
, tree
, urb
);
517 offset
+= tvb_captured_length_remaining(tvb
, offset
) - 2;
522 case CMD_READ_BINARY_BLOCKS
:
523 use_status_word
= true;
524 proto_tree_add_item(main_tree
, hf_data
, tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
) - 2, ENC_NA
);
525 offset
+= tvb_captured_length_remaining(tvb
, offset
) - 2;
528 case CMD_READ_VALUE_BLOCK
:
529 use_status_word
= true;
530 proto_tree_add_item(main_tree
, hf_value
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
533 case CMD_GET_DATA_UID
:
534 use_status_word
= true;
535 proto_tree_add_item(main_tree
, hf_uid
, tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
) - 2, ENC_NA
);
536 offset
+= tvb_captured_length_remaining(tvb
, offset
) - 2;
539 case CMD_GET_DATA_ATS
:
540 use_status_word
= true;
541 proto_tree_add_item(main_tree
, hf_ats
, tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
) - 2, ENC_NA
);
542 offset
+= tvb_captured_length_remaining(tvb
, offset
) - 2;
545 case CMD_BI_COLOR_AND_BUZZER_LED_CONTROL
:
546 case CMD_LOAD_AUTHENTICATION_KEYS
:
547 case CMD_AUTHENTICATION
:
548 case CMD_AUTHENTICATION_OBSOLETE
:
549 case CMD_UPDATE_BINARY_BLOCKS
:
550 case CMD_VALUE_BLOCK_OPERATION
:
551 case CMD_RESTORE_VALUE_BLOCK
:
552 case CMD_SET_TIMEOUT_PARAMETER
:
553 case CMD_SET_BUZZER_OUTPUT_FOR_CARD_DETECTION
:
554 case CMD_SET_PICC_OPERATING_PARAMETER
:
555 case CMD_GET_PICC_OPERATING_PARAMETER
:
557 use_status_word
= true;
561 if (use_status_word
) {
562 value
= tvb_get_ntohs(tvb
, offset
);
563 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s%s",
564 (((value
& 0xFF00) != 0x9000) && (value
& 0xFF00) != 0x6100) ?
566 rval_to_str_const(value
, status_word_rvals
, "Unknown error"));
568 if ((value
& 0xFF00) == 0x6100)
569 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - Length %u", value
& 0x00FF);
571 sub_item
= proto_tree_add_item(main_tree
, hf_status_word
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
572 sub_tree
= proto_item_add_subtree(sub_item
, ett_status_word
);
573 proto_tree_add_item(sub_tree
, hf_status_word_sw1
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
575 sw2_item
= proto_tree_add_item(sub_tree
, hf_status_word_sw2
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
577 if (command
== CMD_BI_COLOR_AND_BUZZER_LED_CONTROL
) {
578 sw2_tree
= proto_item_add_subtree(sw2_item
, ett_status_word_sw2
);
580 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - Red LED: %s, Green LED: %s", (value
& 0x02) ? "On" : "Off", (value
& 0x01) ? "On" : "Off");
582 proto_tree_add_item(sw2_tree
, hf_status_word_led_reserved
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
583 proto_tree_add_item(sw2_tree
, hf_status_word_led_green
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
584 proto_tree_add_item(sw2_tree
, hf_status_word_led_red
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
585 } else if (command
== CMD_SET_PICC_OPERATING_PARAMETER
|| command
== CMD_GET_PICC_OPERATING_PARAMETER
) {
586 sw2_tree
= proto_item_add_subtree(sw2_item
, ett_status_word_sw2
);
587 proto_tree_add_item(sw2_tree
, hf_picc_operating_auto_picc_polling
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
588 proto_tree_add_item(sw2_tree
, hf_picc_operating_auto_ats_generation
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
589 proto_tree_add_item(sw2_tree
, hf_picc_operating_polling_interval
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
590 proto_tree_add_item(sw2_tree
, hf_picc_operating_felica_424k
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
591 proto_tree_add_item(sw2_tree
, hf_picc_operating_felica_212k
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
592 proto_tree_add_item(sw2_tree
, hf_picc_operating_topaz
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
593 proto_tree_add_item(sw2_tree
, hf_picc_operating_iso_14443_type_b
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
594 proto_tree_add_item(sw2_tree
, hf_picc_operating_iso_14443_type_a
, tvb
, offset
- 2, 1, ENC_BIG_ENDIAN
);
604 proto_register_acr122(void)
607 expert_module_t
*expert_module
;
609 static hf_register_info hf
[] = {
611 { "Class", "acr122.class",
612 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
616 { "Ins", "acr122.ins",
617 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
622 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
627 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
631 { "Length", "acr122.length",
632 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
636 { "Status Word", "acr122.status_word",
637 FT_UINT16
, BASE_HEX
| BASE_RANGE_STRING
, RVALS(status_word_rvals
), 0x00,
640 { &hf_status_word_sw1
,
641 { "SW1", "acr122.status_word.sw1",
642 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
645 { &hf_status_word_sw2
,
646 { "SW2", "acr122.status_word.sw2",
647 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
651 { "Command", "acr122.command",
652 FT_UINT8
, BASE_HEX
| BASE_EXT_STRING
, &command_vals_ext
, 0x00,
656 { "Response", "acr122.response",
657 FT_UINT8
, BASE_HEX
| BASE_EXT_STRING
, &command_vals_ext
, 0x00,
661 { "Response for", "acr122.response_for",
662 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00,
665 { &hf_picc_operating_auto_picc_polling
,
666 { "Auto PICC Polling", "acr122.picc_operating.auto_picc_polling",
667 FT_BOOLEAN
, 8, NULL
, 0x80,
670 { &hf_picc_operating_auto_ats_generation
,
671 { "ATS Generation", "acr122.picc_operating.ats_generation",
672 FT_BOOLEAN
, 8, NULL
, 0x40,
675 { &hf_picc_operating_polling_interval
,
676 { "Polling Interval", "acr122.picc_operating.polling_interval",
677 FT_BOOLEAN
, 8, NULL
, 0x20,
680 { &hf_picc_operating_felica_424k
,
681 { "FeliCa 424k", "acr122.picc_operating.felica_424k",
682 FT_BOOLEAN
, 8, NULL
, 0x10,
685 { &hf_picc_operating_felica_212k
,
686 { "FeliCa 212k", "acr122.picc_operating.felica_212k",
687 FT_BOOLEAN
, 8, NULL
, 0x08,
690 { &hf_picc_operating_topaz
,
691 { "Topaz", "acr122.picc_operating.topaz",
692 FT_BOOLEAN
, 8, NULL
, 0x04,
695 { &hf_picc_operating_iso_14443_type_b
,
696 { "ISO 14443 Type B", "acr122.picc_operating.iso_14443_type_b",
697 FT_BOOLEAN
, 8, NULL
, 0x02,
700 { &hf_picc_operating_iso_14443_type_a
,
701 { "ISO 14443 Type A", "acr122.picc_operating.iso_14443_type_a",
702 FT_BOOLEAN
, 8, NULL
, 0x01,
705 { &hf_firmware_version
,
706 { "Firmware Version", "acr122.firmware_version",
707 FT_STRING
, BASE_NONE
, NULL
, 0x00,
710 { &hf_led_green_blinking_state
,
711 { "Green LED Blinking", "acr122.led.green.blinking",
712 FT_BOOLEAN
, 8, NULL
, 0x80,
715 { &hf_led_red_blinking_state
,
716 { "Red LED Blinking", "acr122.led.red.blinking",
717 FT_BOOLEAN
, 8, NULL
, 0x40,
720 { &hf_led_green_mask
,
721 { "Green LED Mask", "acr122.led.green.mask",
722 FT_BOOLEAN
, 8, NULL
, 0x20,
726 { "Red LED Mask", "acr122.led.red.mask",
727 FT_BOOLEAN
, 8, NULL
, 0x10,
730 { &hf_led_initial_green_blinking_state
,
731 { "Initial Green LED Blinking", "acr122.led.green.initial",
732 FT_BOOLEAN
, 8, NULL
, 0x08,
735 { &hf_led_initial_red_blinking_state
,
736 { "Initial Red LED Blinking", "acr122.led.red.initial",
737 FT_BOOLEAN
, 8, NULL
, 0x04,
740 { &hf_led_final_green_state
,
741 { "Final Green LED", "acr122.led.green.final",
742 FT_BOOLEAN
, 8, NULL
, 0x02,
745 { &hf_led_final_red_state
,
746 { "Final Red LED", "acr122.led.red.final",
747 FT_BOOLEAN
, 8, NULL
, 0x01,
750 { &hf_led_t1_duration
,
751 { "T1 Duration", "acr122.led.t1_duration",
752 FT_UINT8
, BASE_CUSTOM
, CF_FUNC(duration_base
), 0x00,
753 "Initial Blinking State", HFILL
}
755 { &hf_led_t2_duration
,
756 { "T2 Duration", "acr122.led.t2_duration",
757 FT_UINT8
, BASE_CUSTOM
, CF_FUNC(duration_base
), 0x00,
758 "Toggle Blinking State", HFILL
}
760 { &hf_led_number_of_repetition
,
761 { "Number of Repetition", "acr122.led.number_of_repetition",
762 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
765 { &hf_led_link_to_buzzer
,
766 { "Link to Buzzer", "acr122.led.link_to_buzzer",
767 FT_UINT8
, BASE_HEX
, VALS(link_to_buzzer_vals
), 0x00,
770 { &hf_poll_buzzer_status
,
771 { "Poll Buzzer Status", "acr122.poll_buzzer_status",
772 FT_UINT8
, BASE_HEX
, VALS(poll_buzzer_status_vals
), 0x00,
776 { "Timeout", "acr122.timeout",
777 FT_UINT8
, BASE_CUSTOM
, CF_FUNC(timeout_base
), 0x00,
780 { &hf_status_word_led_reserved
,
781 { "Reserved", "acr122.status_word.sw2.reserved",
782 FT_UINT8
, BASE_HEX
, NULL
, 0xFC,
785 { &hf_status_word_led_green
,
786 { "Current Green LED", "acr122.status_word.sw2.led.green",
787 FT_BOOLEAN
, 8, NULL
, 0x02,
790 { &hf_status_word_led_red
,
791 { "Current Red LED", "acr122.status_word.sw2.led.red",
792 FT_BOOLEAN
, 8, NULL
, 0x01,
796 { "Key", "acr122.key",
797 FT_BYTES
, BASE_NONE
, NULL
, 0x00,
801 { "Key Structure", "acr122.key_structure",
802 FT_UINT8
, BASE_HEX
, VALS(key_structure_vals
), 0x00,
806 { "Key Number", "acr122.key_number",
807 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
811 { "Key Type", "acr122.key_type",
812 FT_UINT8
, BASE_HEX
, VALS(key_type_vals
), 0x00,
816 { "Block Number", "acr122.block_number",
817 FT_UINT8
, BASE_DEC_HEX
, NULL
, 0x00,
820 { &hf_source_block_number
,
821 { "Source Block Number", "acr122.source_block_number",
822 FT_UINT8
, BASE_DEC_HEX
, NULL
, 0x00,
825 { &hf_target_block_number
,
826 { "Target Block Number", "acr122.target_block_number",
827 FT_UINT8
, BASE_DEC_HEX
, NULL
, 0x00,
831 { "Static Byte", "acr122.static_byte",
832 FT_UINT8
, BASE_HEX
, NULL
, 0x00,
836 { "VB Op", "acr122.vb_op",
837 FT_UINT8
, BASE_HEX
, VALS(vb_op_vals
), 0x00,
841 { "Version", "acr122.version",
842 FT_UINT16
, BASE_HEX
, NULL
, 0x00,
846 { "Value", "acr122.value",
847 FT_INT32
, BASE_DEC
, NULL
, 0x00,
851 { "UID", "acr122.uid",
852 FT_BYTES
, BASE_NONE
, NULL
, 0x00,
856 { "ATS", "acr122.ats",
857 FT_BYTES
, BASE_NONE
, NULL
, 0x00,
861 { "Data", "acr122.data",
862 FT_BYTES
, BASE_NONE
, NULL
, 0x00,
867 static int *ett
[] = {
875 static ei_register_info ei
[] = {
876 { &ei_unknown_command_or_invalid_parameters
, { "acr122.expert.unknown_command", PI_PROTOCOL
, PI_NOTE
, "Unknown command or invalid parameters", EXPFILL
}},
879 command_info
= wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
881 proto_acr122
= proto_register_protocol("Advanced Card Systems ACR122", "ACR 122", "acr122");
882 acr122_handle
= register_dissector("acr122", dissect_acr122
, proto_acr122
);
884 proto_register_field_array(proto_acr122
, hf
, array_length(hf
));
885 proto_register_subtree_array(ett
, array_length(ett
));
886 expert_module
= expert_register_protocol(proto_acr122
);
887 expert_register_field_array(expert_module
, ei
, array_length(ei
));
889 module
= prefs_register_protocol(proto_acr122
, NULL
);
890 prefs_register_static_text_preference(module
, "version",
891 "ACR122U USB NFC Reader - Application Programming Interface V2.02",
892 "Version of protocol supported by this dissector.");
896 proto_reg_handoff_acr122(void)
898 pn532_handle
= find_dissector_add_dependency("pn532", proto_acr122
);
899 dissector_add_for_decode_as("usbccid.subdissector", acr122_handle
);
903 * Editor modelines - https://www.wireshark.org/tools/modelines.html
908 * indent-tabs-mode: nil
911 * vi: set shiftwidth=4 tabstop=8 expandtab:
912 * :indentSize=4:tabSize=8:noTabs=true: