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
10 * http://www.modbus.org/
12 * for information on Modbus/TCP.
16 * Wireshark - Network traffic analyzer
17 * By Gerald Combs <gerald@wireshark.org>
18 * Copyright 1998 Gerald Combs
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version 2
23 * of the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #define PORT_MBTCP 502 /* Modbus/TCP located on port 502 */
36 /* Modbus protocol function codes */
38 #define READ_INPUT_DISCRETES 2
39 #define READ_MULT_REGS 3
40 #define READ_INPUT_REGS 4
42 #define WRITE_SINGLE_REG 6
43 #define READ_EXCEPT_STAT 7
45 #define GET_COMM_EVENT_CTRS 11
46 #define GET_COMM_EVENT_LOG 12
47 #define WRITE_MULT_COILS 15
48 #define WRITE_MULT_REGS 16
49 #define REPORT_SLAVE_ID 17
50 #define READ_FILE_RECORD 20
51 #define WRITE_FILE_RECORD 21
52 #define MASK_WRITE_REG 22
53 #define READ_WRITE_REG 23
54 #define READ_FIFO_QUEUE 24
55 #define ENCAP_INTERFACE_TRANSP 43
57 /* Modbus protocol exception codes */
58 #define ILLEGAL_FUNCTION 0x01
59 #define ILLEGAL_ADDRESS 0x02
60 #define ILLEGAL_VALUE 0x03
61 #define ILLEGAL_RESPONSE 0x04
62 #define ACKNOWLEDGE 0x05
63 #define SLAVE_BUSY 0x06
64 #define MEMORY_ERR 0x08
65 #define GATEWAY_UNAVAILABLE 0x0a
66 #define GATEWAY_TRGT_FAIL 0x0b
68 /* Modbus diagnostic subfunction codes */
69 #define RETURN_QUERY_DATA 0x00
70 #define RESTART_COMMUNICATION_OPTION 0x01
71 #define RETURN_DIAGNOSTIC_REGISTER 0x02
72 #define CHANGE_ASCII_INPUT_DELIMITER 0x03
73 #define FORCE_LISTEN_ONLY_MODE 0x04
74 #define CLEAR_COUNTERS_AND_DIAG_REG 0x0A
75 #define RETURN_BUS_MESSAGE_COUNT 0x0B
76 #define RETURN_BUS_COMM_ERROR_COUNT 0x0C
77 #define RETURN_BUS_EXCEPTION_ERROR_COUNT 0x0D
78 #define RETURN_SLAVE_MESSAGE_COUNT 0x0E
79 #define RETURN_SLAVE_NO_RESPONSE_COUNT 0x0F
80 #define RETURN_SLAVE_NAK_COUNT 0x10
81 #define RETURN_SLAVE_BUSY_COUNT 0x11
82 #define RETURN_BUS_CHAR_OVERRUN_COUNT 0x12
83 #define CLEAR_OVERRUN_COUNTER_AND_FLAG 0x14
87 /* Encapsulation Interface codes */
88 #define CANOPEN_REQ_RESP 0x0D
89 #define READ_DEVICE_ID 0x0E
91 /* Event byte codes */
92 #define REMOTE_DEVICE_RECV_EVENT_MASK 0x80
93 #define REMOTE_DEVICE_SEND_EVENT_MASK 0xc0
94 #define REMOTE_DEVICE_SEND_EVENT_VALUE 0x40
96 /* return codes of function classifying packets as query/response */
97 #define QUERY_PACKET 0
98 #define RESPONSE_PACKET 1
99 #define CANNOT_CLASSIFY 2
101 #define MODBUS_PROTOCOL_ID 0