Added support for optional display of signed 16/32-bit integer Modbus register data
[metze/wireshark/wip.git] / epan / dissectors / packet-mbtcp.h
1 /* packet-mbtcp.h
2  *
3  * Routines for Modbus/TCP dissection
4  * By Riaan Swart <rswart@cs.sun.ac.za>
5  * Copyright 2001, Institute for Applied Computer Science
6  *                      University of Stellenbosch
7  *
8  * See http://www.modbus.org/ for information on Modbus/TCP.
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  */
28 #define PORT_MBTCP        502    /* Modbus/TCP located on port 502, with IANA registration */
29 #define PORT_MBRTU        0    /* Modbus RTU over TCP does not have a standard port, default to zero */
30
31 /* Modbus protocol function codes */
32 #define READ_COILS                  1
33 #define READ_DISCRETE_INPUTS        2
34 #define READ_HOLDING_REGS           3
35 #define READ_INPUT_REGS             4
36 #define WRITE_SINGLE_COIL           5
37 #define WRITE_SINGLE_REG            6
38 #define READ_EXCEPT_STAT            7
39 #define DIAGNOSTICS                 8
40 #define GET_COMM_EVENT_CTRS         11
41 #define GET_COMM_EVENT_LOG          12
42 #define WRITE_MULT_COILS            15
43 #define WRITE_MULT_REGS             16
44 #define REPORT_SLAVE_ID             17
45 #define READ_FILE_RECORD            20
46 #define WRITE_FILE_RECORD           21
47 #define MASK_WRITE_REG              22
48 #define READ_WRITE_REG              23
49 #define READ_FIFO_QUEUE             24
50 #define ENCAP_INTERFACE_TRANSP      43
51 #define UNITY_SCHNEIDER             90
52
53 /* Modbus protocol exception codes */
54 #define ILLEGAL_FUNCTION            0x01
55 #define ILLEGAL_ADDRESS             0x02
56 #define ILLEGAL_VALUE               0x03
57 #define SLAVE_FAILURE               0x04
58 #define ACKNOWLEDGE                 0x05
59 #define SLAVE_BUSY                  0x06
60 #define MEMORY_ERR                  0x08
61 #define GATEWAY_UNAVAILABLE         0x0a
62 #define GATEWAY_TRGT_FAIL           0x0b
63
64 /* Modbus diagnostic subfunction codes */
65 #define RETURN_QUERY_DATA                 0x00
66 #define RESTART_COMMUNICATION_OPTION      0x01
67 #define RETURN_DIAGNOSTIC_REGISTER        0x02
68 #define CHANGE_ASCII_INPUT_DELIMITER      0x03
69 #define FORCE_LISTEN_ONLY_MODE            0x04
70 #define CLEAR_COUNTERS_AND_DIAG_REG       0x0A
71 #define RETURN_BUS_MESSAGE_COUNT          0x0B
72 #define RETURN_BUS_COMM_ERROR_COUNT       0x0C
73 #define RETURN_BUS_EXCEPTION_ERROR_COUNT  0x0D
74 #define RETURN_SLAVE_MESSAGE_COUNT        0x0E
75 #define RETURN_SLAVE_NO_RESPONSE_COUNT    0x0F
76 #define RETURN_SLAVE_NAK_COUNT            0x10
77 #define RETURN_SLAVE_BUSY_COUNT           0x11
78 #define RETURN_BUS_CHAR_OVERRUN_COUNT     0x12
79 #define CLEAR_OVERRUN_COUNTER_AND_FLAG    0x14
80
81
82
83 /* Encapsulation Interface codes */
84 #define CANOPEN_REQ_RESP   0x0D
85 #define READ_DEVICE_ID     0x0E
86
87 /* Event byte codes */
88 #define REMOTE_DEVICE_RECV_EVENT_MASK     0x80
89 #define REMOTE_DEVICE_SEND_EVENT_MASK     0xc0
90 #define REMOTE_DEVICE_SEND_EVENT_VALUE    0x40
91
92 /* return codes of function classifying packets as query/response */
93 #define QUERY_PACKET            0
94 #define RESPONSE_PACKET         1
95 #define CANNOT_CLASSIFY         2
96
97 #define MODBUS_PROTOCOL_ID      0
98
99 /* Preferences for Modbus/TCP Dissector */
100 #define MBTCP_PREF_REGISTER_FORMAT_UINT16          0
101 #define MBTCP_PREF_REGISTER_FORMAT_UINT32          1
102 #define MBTCP_PREF_REGISTER_FORMAT_IEEE_FLOAT      2
103 #define MBTCP_PREF_REGISTER_FORMAT_MODICON_FLOAT   3
104 #define MBTCP_PREF_REGISTER_FORMAT_INT16           4
105 #define MBTCP_PREF_REGISTER_FORMAT_INT32           5
106
107 #define MBTCP_PREF_REGISTER_ADDR_RAW    0
108 #define MBTCP_PREF_REGISTER_ADDR_MOD5   1
109 #define MBTCP_PREF_REGISTER_ADDR_MOD6   2
110
111
112 typedef struct {
113     guint8 register_format;
114     guint8 register_addr_type;
115     guint8 packet_type;
116 } modbus_request_info_t;
117
118 /*
119  * Editor modelines
120  *
121  * Local Variables:
122  * c-basic-offset: 4
123  * tab-width: 8
124  * indent-tabs-mode: nil
125  * End:
126  *
127  * ex: set shiftwidth=4 tabstop=8 expandtab:
128  * :indentSize=4:tabSize=8:noTabs=true:
129  */