2 * Routines for ZVT dissection
3 * Copyright 2014-2015, Martin Kaiser <martin@kaiser.cx>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 /* ZVT is a manufacturer-independent protocol between payment terminals and
25 * electronic cash-register systems / vending machines
27 * the specifications are available from http://www.zvt-kassenschnittstelle.de
29 * ZVT defines a "serial transport protocol" and a "TCP/IP transport
32 * ZVT can sit on top of USB, either the serial or the TCP/IP protocol
33 * can be used in this case - this is not supported for now
35 * a dump of ZVT data can be converted to pcap, using a user-defined DLT
36 * we register the dissector by name and try to auto-detect the serial
39 * finally, ZVT can run on top of TCP, the default port is 20007, only
40 * the TCP/IP protocol can be used here
46 #include <epan/packet.h>
47 #include <epan/prefs.h>
48 #include <epan/addr_resolv.h>
49 #include <epan/expert.h>
51 /* special characters of the serial transport protocol */
58 /* an APDU needs at least a 2-byte control-field and one byte length */
59 #define ZVT_APDU_MIN_LEN 3
62 static GHashTable *apdu_table = NULL;
64 static wmem_tree_t *transactions = NULL;
66 typedef struct _zvt_transaction_t {
72 typedef enum _zvt_direction_t {
78 /* source/destination address field */
79 #define ADDR_ECR "ECR"
85 /* "don't care" value for min_len_field */
86 #define LEN_FIELD_ANY G_MAXUINT32
88 typedef struct _apdu_info_t {
90 guint32 min_len_field;
91 zvt_direction_t direction;
92 void (*dissect_payload)(tvbuff_t *, gint, guint16,
93 packet_info *, proto_tree *, zvt_transaction_t *);
96 /* control code 0 is not defined in the specification */
97 #define ZVT_CTRL_NONE 0x0000
99 #define CTRL_STATUS 0x040F
100 #define CTRL_INT_STATUS 0x04FF
101 #define CTRL_REGISTRATION 0x0600
102 #define CTRL_AUTHORISATION 0x0601
103 #define CTRL_COMPLETION 0x060F
104 #define CTRL_ABORT 0x061E
105 #define CTRL_END_OF_DAY 0x0650
106 #define CTRL_DIAG 0x0670
107 #define CTRL_INIT 0x0693
108 #define CTRL_PRINT_LINE 0x06D1
110 static void dissect_zvt_reg(tvbuff_t *tvb, gint offset, guint16 len,
111 packet_info *pinfo, proto_tree *tree, zvt_transaction_t *zvt_trans);
112 static void dissect_zvt_bitmap_apdu(tvbuff_t *tvb, gint offset, guint16 len,
113 packet_info *pinfo, proto_tree *tree, zvt_transaction_t *zvt_trans);
115 static const apdu_info_t apdu_info[] = {
116 { CTRL_STATUS, 0, DIRECTION_PT_TO_ECR, NULL },
117 { CTRL_INT_STATUS, 0, DIRECTION_PT_TO_ECR, NULL },
118 { CTRL_REGISTRATION, 4, DIRECTION_ECR_TO_PT, dissect_zvt_reg },
119 /* authorisation has at least a 0x04 tag and 6 bytes for the amount */
120 { CTRL_AUTHORISATION, 7, DIRECTION_ECR_TO_PT, dissect_zvt_bitmap_apdu },
121 { CTRL_COMPLETION, 0, DIRECTION_PT_TO_ECR, dissect_zvt_bitmap_apdu },
122 { CTRL_ABORT, 0, DIRECTION_PT_TO_ECR, NULL },
123 { CTRL_END_OF_DAY, 0, DIRECTION_ECR_TO_PT, NULL },
124 { CTRL_DIAG, 0, DIRECTION_ECR_TO_PT, NULL },
125 { CTRL_INIT, 0, DIRECTION_ECR_TO_PT, NULL },
126 { CTRL_PRINT_LINE, 0, DIRECTION_PT_TO_ECR, NULL }
129 void proto_register_zvt(void);
130 void proto_reg_handoff_zvt(void);
132 /* the specification mentions tcp port 20007
133 this port is not officially registered with IANA */
134 static guint pref_zvt_tcp_port = 0;
136 static int proto_zvt = -1;
138 static int ett_zvt = -1;
139 static int ett_zvt_apdu = -1;
140 static int ett_zvt_tlv_dat_obj = -1;
142 static int hf_zvt_resp_in = -1;
143 static int hf_zvt_resp_to = -1;
144 static int hf_zvt_serial_char = -1;
145 static int hf_zvt_crc = -1;
146 static int hf_zvt_ctrl = -1;
147 static int hf_zvt_ccrc = -1;
148 static int hf_zvt_aprc = -1;
149 static int hf_zvt_len = -1;
150 static int hf_zvt_data = -1;
151 static int hf_zvt_reg_pwd = -1;
152 static int hf_zvt_reg_cfg = -1;
153 static int hf_zvt_cc = -1;
154 static int hf_zvt_reg_svc_byte = -1;
155 static int hf_zvt_bitmap = -1;
156 static int hf_zvt_tlv_tag = -1;
157 static int hf_zvt_tlv_len = -1;
159 static expert_field ei_invalid_apdu_len = EI_INIT;
161 static const value_string serial_char[] = {
162 { STX, "Start of text (STX)" },
163 { ETX, "End of text (ETX)" },
164 { ACK, "Acknowledged (ACK)" },
165 { DLE, "Data line escape (DLE)" },
166 { NAK, "Not acknowledged (NAK)" },
169 static value_string_ext serial_char_ext = VALUE_STRING_EXT_INIT(serial_char);
172 static const value_string ctrl_field[] = {
173 { CTRL_STATUS, "Status Information" },
174 { CTRL_INT_STATUS, "Intermediate Status Information" },
175 { CTRL_REGISTRATION, "Registration" },
176 { CTRL_AUTHORISATION, "Authorisation" },
177 { CTRL_COMPLETION, "Completion" },
178 { CTRL_ABORT, "Abort" },
179 { CTRL_END_OF_DAY, "End Of Day" },
180 { CTRL_DIAG, "Diagnosis" },
181 { CTRL_INIT, "Initialisation" },
182 { CTRL_PRINT_LINE, "Print Line" },
183 { 0x06D3, "Print Text Block" },
186 static value_string_ext ctrl_field_ext = VALUE_STRING_EXT_INIT(ctrl_field);
188 #define BMP_TIMEOUT 0x01
189 #define BMP_MAX_STAT_INFO 0x02
190 #define BMP_AMOUNT 0x04
191 #define BMP_PUMP_NR 0x05
192 #define BMP_TLV_CONTAINER 0x06
193 #define BMP_EXP_DATE 0x0E
194 #define BMP_PAYMENT_TYPE 0x19
195 #define BMP_CARD_NUM 0x22
196 #define BMP_T2_DAT 0x23
197 #define BMP_T3_DAT 0x24
198 #define BMP_T1_DAT 0x2D
199 #define BMP_CVV_CVC 0x3A
200 #define BMP_ADD_DATA 0x3C
203 static const value_string bitmap[] = {
204 { BMP_TIMEOUT, "Timeout" },
205 { BMP_MAX_STAT_INFO, "max. status info" },
206 { BMP_AMOUNT, "Amount" },
207 { BMP_PUMP_NR, "Pump number" },
208 { BMP_TLV_CONTAINER, "TLV container" },
209 { BMP_EXP_DATE, "Exipry date" },
210 { BMP_PAYMENT_TYPE, "Payment type" },
211 { BMP_CARD_NUM, "Card number" },
212 { BMP_T2_DAT, "Track 2 data" },
213 { BMP_T3_DAT, "Track 3 data" },
214 { BMP_T1_DAT, "Track 1 data" },
215 { BMP_CVV_CVC, "CVV / CVC" },
216 { BMP_ADD_DATA, "Additional data" },
217 { BMP_CC, "Currency code (CC)" },
220 static value_string_ext bitmap_ext = VALUE_STRING_EXT_INIT(bitmap);
222 static const value_string tlv_tags[] = {
225 static value_string_ext tlv_tags_ext = VALUE_STRING_EXT_INIT(tlv_tags);
229 dissect_zvt_tlv_tag(tvbuff_t *tvb, gint offset,
230 packet_info *pinfo _U_, proto_tree *tree, guint32 *tag)
234 tag_byte = tvb_get_guint8(tvb, offset);
235 if ((tag_byte & 0x1F) == 0x1F) {
236 /* XXX - handle multi-byte tags */
240 proto_tree_add_uint_format(tree, hf_zvt_tlv_tag,
241 tvb, offset, 1, tag_byte, "Tag: 0x%x", tag_byte);
250 dissect_zvt_tlv_container(tvbuff_t *tvb, gint offset,
251 packet_info *pinfo, proto_tree *tree)
254 proto_item *dat_obj_it;
255 proto_tree *dat_obj_tree;
258 guint8 data_len_bytes = 1;
261 offset_start = offset;
263 while (tvb_captured_length_remaining(tvb, offset) > 0) {
264 dat_obj_tree = proto_tree_add_subtree(tree,
265 tvb, offset, -1, ett_zvt_tlv_dat_obj, &dat_obj_it,
268 tag_len = dissect_zvt_tlv_tag(tvb, offset, pinfo, dat_obj_tree, &tag);
270 return offset - offset_start;
273 data_len = tvb_get_guint8(tvb, offset);
274 if (data_len & 0x80) {
275 if ((data_len & 0x03) == 1) {
277 data_len = tvb_get_guint8(tvb, offset+1);
279 else if ((data_len & 0x03) == 2) {
281 data_len = tvb_get_ntohs(tvb, offset+1);
284 /* XXX - expert info, exit */
287 proto_tree_add_uint(dat_obj_tree, hf_zvt_tlv_len,
288 tvb, offset, data_len_bytes, data_len);
289 offset += data_len_bytes;
291 /* XXX - dissect the data-element */
294 proto_item_set_len(dat_obj_it, tag_len + data_len_bytes + data_len);
297 return offset - offset_start;
301 /* dissect one "bitmap", i.e BMP and the corresponding data */
303 dissect_zvt_bitmap(tvbuff_t *tvb, gint offset,
304 packet_info *pinfo, proto_tree *tree)
310 offset_start = offset;
312 bmp = tvb_get_guint8(tvb, offset);
313 if (try_val_to_str(bmp, bitmap) == NULL)
316 proto_tree_add_item(tree, hf_zvt_bitmap, tvb, offset, 1, ENC_BIG_ENDIAN);
323 case BMP_MAX_STAT_INFO:
335 case BMP_PAYMENT_TYPE:
344 case BMP_TLV_CONTAINER:
345 ret = dissect_zvt_tlv_container(tvb, offset, pinfo, tree);
357 /* the bitmaps are not TLV but only TV, there's no length field
358 the tags listed above have variable length
359 -> if we see one of those tags, we have to stop the
360 dissection and report an error to the caller */
364 g_assert_not_reached();
368 return offset - offset_start;
372 dissect_zvt_reg(tvbuff_t *tvb, gint offset, guint16 len _U_,
373 packet_info *pinfo, proto_tree *tree, zvt_transaction_t *zvt_trans)
375 proto_tree_add_item(tree, hf_zvt_reg_pwd, tvb, offset, 3, ENC_NA);
378 proto_tree_add_item(tree, hf_zvt_reg_cfg,
379 tvb, offset, 1, ENC_BIG_ENDIAN);
382 /* check for the optional part CC|0x03|service byte */
383 if (tvb_captured_length_remaining(tvb, offset)>=4 &&
384 tvb_get_guint8(tvb, offset+2)==0x03) {
386 proto_tree_add_item(tree, hf_zvt_cc,
387 tvb, offset, 2, ENC_BIG_ENDIAN);
392 proto_tree_add_item(tree, hf_zvt_reg_svc_byte,
393 tvb, offset, 1, ENC_BIG_ENDIAN);
397 /* it's ok if the remaining len is 0 */
398 dissect_zvt_bitmap_apdu(tvb, offset,
399 tvb_captured_length_remaining(tvb, offset),
400 pinfo, tree, zvt_trans);
404 /* dissect an APDU that contains a sequence of bitmaps */
406 dissect_zvt_bitmap_apdu(tvbuff_t *tvb, gint offset, guint16 len,
407 packet_info *pinfo _U_, proto_tree *tree, zvt_transaction_t *zvt_trans _U_)
409 gint offset_start, ret;
411 offset_start = offset;
413 while (offset - offset_start < len) {
414 ret = dissect_zvt_bitmap(tvb, offset, pinfo, tree);
423 zvt_set_addresses(packet_info *pinfo, zvt_transaction_t *zvt_trans)
426 zvt_direction_t dir = DIRECTION_UNKNOWN;
431 ai = (apdu_info_t *)g_hash_table_lookup(
432 apdu_table, GUINT_TO_POINTER((guint)zvt_trans->ctrl));
436 if (zvt_trans->rqst_frame == PINFO_FD_NUM(pinfo)) {
439 else if (zvt_trans->resp_frame == PINFO_FD_NUM(pinfo)) {
440 if (ai->direction == DIRECTION_ECR_TO_PT)
441 dir = DIRECTION_PT_TO_ECR;
443 dir = DIRECTION_ECR_TO_PT;
446 if (dir == DIRECTION_ECR_TO_PT) {
447 SET_ADDRESS(&pinfo->src, AT_STRINGZ,
448 (int)strlen(ADDR_ECR)+1, ADDR_ECR);
449 SET_ADDRESS(&pinfo->dst, AT_STRINGZ,
450 (int)strlen(ADDR_PT)+1, ADDR_PT);
452 else if (dir == DIRECTION_PT_TO_ECR) {
453 SET_ADDRESS(&pinfo->src, AT_STRINGZ,
454 (int)strlen(ADDR_PT)+1, ADDR_PT);
455 SET_ADDRESS(&pinfo->dst, AT_STRINGZ,
456 (int)strlen(ADDR_ECR)+1, ADDR_ECR);
461 /* dissect a ZVT APDU
462 return -1 if we don't have a complete APDU, 0 if the packet is no ZVT APDU
463 or the length of the ZVT APDU if all goes well */
465 dissect_zvt_apdu(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
468 guint8 len_bytes = 1; /* number of bytes for the len field */
469 guint16 ctrl = ZVT_CTRL_NONE;
473 proto_tree *apdu_tree;
475 zvt_transaction_t *zvt_trans = NULL;
478 offset_start = offset;
480 if (tvb_captured_length_remaining(tvb, offset) < ZVT_APDU_MIN_LEN)
483 len = tvb_get_guint8(tvb, offset+2);
486 len = tvb_get_ntohs(tvb, offset+3);
489 /* ZVT_APDU_MIN_LEN already includes one length byte */
490 if (tvb_captured_length_remaining(tvb, offset) <
491 ZVT_APDU_MIN_LEN + (len_bytes-1) + len) {
495 apdu_tree = proto_tree_add_subtree(tree,
496 tvb, offset, -1, ett_zvt_apdu, &apdu_it, "ZVT APDU");
498 byte = tvb_get_guint8(tvb, offset);
499 if (byte == CCRC_POS || byte == CCRC_NEG) {
500 proto_tree_add_item(apdu_tree, hf_zvt_ccrc, tvb, offset, 1, ENC_BIG_ENDIAN);
501 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%s",
502 byte == CCRC_POS ? "Positive completion" : "Negative completion");
504 proto_tree_add_item(apdu_tree, hf_zvt_aprc, tvb, offset, 1, ENC_BIG_ENDIAN);
507 /* XXX - can this ever be NULL? */
509 zvt_trans = (zvt_transaction_t *)wmem_tree_lookup32_le(
510 transactions, PINFO_FD_NUM(pinfo));
511 if (zvt_trans && zvt_trans->resp_frame==0) {
512 /* there's a pending request, this packet is the response */
513 zvt_trans->resp_frame = PINFO_FD_NUM(pinfo);
516 if (zvt_trans && zvt_trans->resp_frame == PINFO_FD_NUM(pinfo)) {
517 it = proto_tree_add_uint(apdu_tree, hf_zvt_resp_to,
518 NULL, 0, 0, zvt_trans->rqst_frame);
519 PROTO_ITEM_SET_GENERATED(it);
525 ctrl = tvb_get_ntohs(tvb, offset);
526 proto_tree_add_item(apdu_tree, hf_zvt_ctrl, tvb, offset, 2, ENC_BIG_ENDIAN);
527 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%s",
528 val_to_str_const(ctrl, ctrl_field, "Unknown 0x%x"));
531 if (PINFO_FD_VISITED(pinfo)) {
532 zvt_trans = (zvt_transaction_t *)wmem_tree_lookup32(
533 transactions, PINFO_FD_NUM(pinfo));
534 if (zvt_trans && zvt_trans->rqst_frame==PINFO_FD_NUM(pinfo) &&
535 zvt_trans->resp_frame!=0) {
536 it = proto_tree_add_uint(apdu_tree, hf_zvt_resp_in,
537 NULL, 0, 0, zvt_trans->resp_frame);
538 PROTO_ITEM_SET_GENERATED(it);
542 /* XXX - can this ever be NULL? */
544 zvt_trans = wmem_new(wmem_file_scope(), zvt_transaction_t);
545 zvt_trans->rqst_frame = PINFO_FD_NUM(pinfo);
546 zvt_trans->resp_frame = 0;
547 zvt_trans->ctrl = ctrl;
548 wmem_tree_insert32(transactions,
549 zvt_trans->rqst_frame, (void *)zvt_trans);
554 ai = (apdu_info_t *)g_hash_table_lookup(
555 apdu_table, GUINT_TO_POINTER((guint)ctrl));
557 it = proto_tree_add_uint(apdu_tree, hf_zvt_len, tvb, offset, len_bytes, len);
558 if (ai && ai->min_len_field!=LEN_FIELD_ANY && len<ai->min_len_field) {
559 expert_add_info_format(pinfo, it, &ei_invalid_apdu_len,
560 "The APDU length is too short. The minimum length is %d",
565 zvt_set_addresses(pinfo, zvt_trans);
568 if (ai && ai->dissect_payload)
569 ai->dissect_payload(tvb, offset, len, pinfo, apdu_tree, zvt_trans);
571 proto_tree_add_item(apdu_tree, hf_zvt_data,
572 tvb, offset, len, ENC_NA);
576 proto_item_set_len(apdu_it, offset - offset_start);
577 return offset - offset_start;
582 dissect_zvt_serial(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *tree)
587 offset_start = offset;
589 if (tvb_reported_length_remaining(tvb, offset) == 1) {
590 proto_tree_add_item(tree, hf_zvt_serial_char,
591 tvb, offset, 1, ENC_BIG_ENDIAN);
592 offset++; /* ACK or NAK byte */
593 return offset - offset_start;
596 proto_tree_add_item(tree, hf_zvt_serial_char,
597 tvb, offset, 1, ENC_BIG_ENDIAN);
598 offset ++; /* DLE byte */
599 proto_tree_add_item(tree, hf_zvt_serial_char,
600 tvb, offset, 1, ENC_BIG_ENDIAN);
601 offset ++; /* STX byte */
603 apdu_len = dissect_zvt_apdu(tvb, offset, pinfo, tree);
609 proto_tree_add_item(tree, hf_zvt_serial_char,
610 tvb, offset, 1, ENC_BIG_ENDIAN);
611 offset ++; /* DLE byte */
612 proto_tree_add_item(tree, hf_zvt_serial_char,
613 tvb, offset, 1, ENC_BIG_ENDIAN);
614 offset ++; /* ETX byte */
616 /* the CRC is little endian, the other fields are big endian */
617 proto_tree_add_item(tree, hf_zvt_crc,
618 tvb, offset, 2, ENC_LITTLE_ENDIAN);
619 offset += 2; /* CRC bytes */
621 return offset - offset_start;
626 valid_ctrl_field(tvbuff_t *tvb, gint offset)
628 if (tvb_get_guint8(tvb, offset) == 0x80 ||
629 tvb_get_guint8(tvb, offset) == 0x84 ||
630 try_val_to_str_ext(tvb_get_ntohs(tvb, offset), &ctrl_field_ext)) {
639 dissect_zvt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
643 proto_tree *zvt_tree;
644 gboolean is_serial; /* serial or TCP/IP protocol? */
646 if (tvb_captured_length(tvb) == 1 &&
647 (tvb_get_guint8(tvb, 0) == ACK ||
648 tvb_get_guint8(tvb, 0) == NAK)) {
651 else if (tvb_captured_length(tvb) >= 2 &&
652 tvb_get_guint8(tvb, 0) == DLE &&
653 tvb_get_guint8(tvb, 1) == STX) {
656 else if (tvb_captured_length(tvb) >= ZVT_APDU_MIN_LEN &&
657 valid_ctrl_field(tvb, 0)) {
663 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZVT");
664 col_clear(pinfo->cinfo, COL_INFO);
665 zvt_ti = proto_tree_add_protocol_format(tree, proto_zvt,
667 "ZVT Kassenschnittstelle: %s", is_serial ?
668 "Serial Transport Protocol" : "Transport Protocol TCP/IP");
669 zvt_tree = proto_item_add_subtree(zvt_ti, ett_zvt);
672 zvt_len = dissect_zvt_serial(tvb, 0, pinfo, zvt_tree);
674 zvt_len = dissect_zvt_apdu(tvb, 0, pinfo, zvt_tree);
676 /* zvt_len < 0 means that we have an incomplete APDU
677 we can't do any reassembly here, so let's consume all bytes */
679 zvt_len = tvb_captured_length(tvb);
681 proto_item_set_len(zvt_ti, zvt_len);
687 dissect_zvt_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
689 gint offset = 0, zvt_len = 0, ret;
691 proto_tree *zvt_tree;
693 if (tvb_captured_length(tvb) < ZVT_APDU_MIN_LEN) {
694 if (pinfo->can_desegment) {
695 pinfo->desegment_offset = offset;
696 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
701 if (!valid_ctrl_field(tvb, 0))
702 return 0; /* reject the packet */
704 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZVT");
705 col_clear(pinfo->cinfo, COL_INFO);
706 zvt_ti = proto_tree_add_protocol_format(tree, proto_zvt,
708 "ZVT Kassenschnittstelle: Transport Protocol TCP/IP");
709 zvt_tree = proto_item_add_subtree(zvt_ti, ett_zvt);
711 while (tvb_captured_length_remaining(tvb, offset) > 0) {
712 ret = dissect_zvt_apdu(tvb, offset, pinfo, zvt_tree);
715 mark the bytes that we consumed and exit, give
716 other dissectors a chance to try the remaining
721 /* not enough data - ask the TCP layer for more */
723 if (pinfo->can_desegment) {
724 pinfo->desegment_offset = offset;
725 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
735 proto_item_set_len(zvt_ti, zvt_len);
741 proto_register_zvt(void)
744 module_t *zvt_module;
745 expert_module_t* expert_zvt;
747 static gint *ett[] = {
752 static hf_register_info hf[] = {
754 { "Response In", "zvt.resp_in",
755 FT_FRAMENUM, BASE_NONE, NULL, 0x0, NULL, HFILL } },
757 { "Response To", "zvt.resp_to",
758 FT_FRAMENUM, BASE_NONE, NULL, 0x0, NULL, HFILL } },
759 { &hf_zvt_serial_char,
760 { "Serial character", "zvt.serial_char", FT_UINT8,
761 BASE_HEX|BASE_EXT_STRING, &serial_char_ext, 0, NULL, HFILL } },
763 { "CRC", "zvt.crc", FT_UINT16,
764 BASE_HEX, NULL, 0, NULL, HFILL } },
766 { "Control-field", "zvt.control_field", FT_UINT16,
767 BASE_HEX|BASE_EXT_STRING, &ctrl_field_ext, 0, NULL, HFILL } },
769 { "CCRC", "zvt.ccrc",
770 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
772 { "APRC", "zvt.aprc",
773 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
775 { "Length-field", "zvt.length_field",
776 FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL } },
778 { "APDU data", "zvt.data",
779 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL } },
781 { "Password", "zvt.reg.password",
782 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL } },
784 { "Config byte", "zvt.reg.config_byte",
785 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
786 /* we don't call the filter zvt.reg.cc, the currency code
787 appears in several apdus */
789 { "Currency Code (CC)", "zvt.cc",
790 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL } },
791 { &hf_zvt_reg_svc_byte,
792 { "Service byte", "zvt.reg.service_byte",
793 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
795 { "Bitmap", "zvt.bitmap", FT_UINT8,
796 BASE_HEX|BASE_EXT_STRING, &bitmap_ext, 0, NULL, HFILL } },
798 { "Tag", "zvt.tlv.tag", FT_UINT32,
799 BASE_HEX|BASE_EXT_STRING, &tlv_tags_ext, 0, NULL, HFILL } },
801 { "Length", "zvt.tlv.len",
802 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } }
805 static ei_register_info ei[] = {
806 { &ei_invalid_apdu_len,
807 { "zvt.apdu_len.invalid", PI_PROTOCOL, PI_WARN,
808 "The APDU length is too short. The minimum length is %d",
812 apdu_table = g_hash_table_new(g_direct_hash, g_direct_equal);
813 for(i=0; i<array_length(apdu_info); i++) {
814 g_hash_table_insert(apdu_table,
815 GUINT_TO_POINTER((guint)apdu_info[i].ctrl),
816 (const gpointer)(&apdu_info[i]));
819 proto_zvt = proto_register_protocol(
820 "ZVT Kassenschnittstelle", "ZVT", "zvt");
821 proto_register_field_array(proto_zvt, hf, array_length(hf));
822 proto_register_subtree_array(ett, array_length(ett));
823 expert_zvt = expert_register_protocol(proto_zvt);
824 expert_register_field_array(expert_zvt, ei, array_length(ei));
826 zvt_module = prefs_register_protocol(proto_zvt, proto_reg_handoff_zvt);
827 prefs_register_uint_preference(zvt_module, "tcp.port",
829 "Set the TCP port for ZVT messages (port 20007 according to the spec)",
833 transactions = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
838 proto_reg_handoff_zvt(void)
840 static gboolean registered_dissector = FALSE;
841 static int zvt_tcp_port;
842 static dissector_handle_t zvt_tcp_handle;
844 if (!registered_dissector) {
845 /* register by name to allow mapping to a user DLT */
846 new_register_dissector("zvt", dissect_zvt, proto_zvt);
848 zvt_tcp_handle = new_create_dissector_handle(dissect_zvt_tcp, proto_zvt);
850 registered_dissector = TRUE;
853 dissector_delete_uint("tcp.port", zvt_tcp_port, zvt_tcp_handle);
855 zvt_tcp_port = pref_zvt_tcp_port;
856 dissector_add_uint("tcp.port", zvt_tcp_port, zvt_tcp_handle);
861 * Editor modelines - http://www.wireshark.org/tools/modelines.html
866 * indent-tabs-mode: nil
869 * vi: set shiftwidth=4 tabstop=8 expandtab:
870 * :indentSize=4:tabSize=8:noTabs=true: