2001-04-24 19:29:14 +00:00
|
|
|
/* packet-mbtcp.c
|
2008-11-19 22:30:45 +00:00
|
|
|
* Routines for Modbus/TCP and Modbus/UDP dissection
|
2001-04-24 19:29:14 +00:00
|
|
|
* By Riaan Swart <rswart@cs.sun.ac.za>
|
|
|
|
* Copyright 2001, Institute for Applied Computer Science
|
|
|
|
* University of Stellenbosch
|
|
|
|
*
|
|
|
|
* See
|
|
|
|
*
|
2008-11-19 22:30:45 +00:00
|
|
|
* http://www.modbus.org/
|
2001-04-24 19:29:14 +00:00
|
|
|
*
|
|
|
|
* for information on Modbus/TCP.
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-04-24 19:29:14 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-04-24 19:29:14 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-04-24 19:29:14 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-04-24 19:29:14 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-04-24 19:29:14 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2001-04-24 19:29:14 +00:00
|
|
|
|
2008-11-19 22:30:45 +00:00
|
|
|
#define PORT_MBTCP 502 /* Modbus/TCP and Modbus/UDP located on port 502 */
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* Modbus protocol function codes */
|
2005-12-15 22:54:33 +00:00
|
|
|
#define READ_COILS 1
|
|
|
|
#define READ_INPUT_DISCRETES 2
|
|
|
|
#define READ_MULT_REGS 3
|
|
|
|
#define READ_INPUT_REGS 4
|
|
|
|
#define WRITE_COIL 5
|
|
|
|
#define WRITE_SINGLE_REG 6
|
|
|
|
#define READ_EXCEPT_STAT 7
|
|
|
|
#define DIAGNOSTICS 8
|
|
|
|
#define PROGRAM_484 9
|
|
|
|
#define POLL_484 10
|
|
|
|
#define GET_COMM_EVENT_CTRS 11
|
|
|
|
#define GET_COMM_EVENT_LOG 12
|
|
|
|
#define PROGRAM_584_984 13
|
|
|
|
#define POLL_584_984 14
|
|
|
|
#define FORCE_MULT_COILS 15
|
|
|
|
#define WRITE_MULT_REGS 16
|
|
|
|
#define REPORT_SLAVE_ID 17
|
|
|
|
#define PROGRAM_884_U84 18
|
|
|
|
#define RESET_COMM_LINK 19
|
|
|
|
#define READ_GENL_REF 20
|
|
|
|
#define WRITE_GENL_REF 21
|
|
|
|
#define MASK_WRITE_REG 22
|
|
|
|
#define READ_WRITE_REG 23
|
|
|
|
#define READ_FIFO_QUEUE 24
|
|
|
|
#define PROGRAM_CONCEPT 40
|
2008-09-30 21:23:19 +00:00
|
|
|
#define ENCAP_INTERFACE_TRANSP 43
|
2005-12-15 22:54:33 +00:00
|
|
|
#define FIRMWARE_REPLACE 125
|
|
|
|
#define PROGRAM_584_984_2 126
|
|
|
|
#define REPORT_LOCAL_ADDR_MB 127
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* Modbus protocol exception codes */
|
2005-12-15 22:54:33 +00:00
|
|
|
#define ILLEGAL_FUNCTION 0x01
|
|
|
|
#define ILLEGAL_ADDRESS 0x02
|
|
|
|
#define ILLEGAL_VALUE 0x03
|
|
|
|
#define ILLEGAL_RESPONSE 0x04
|
|
|
|
#define ACKNOWLEDGE 0x05
|
|
|
|
#define SLAVE_BUSY 0x06
|
|
|
|
#define NEGATIVE_ACK 0x07
|
|
|
|
#define MEMORY_ERR 0x08
|
|
|
|
#define GATEWAY_UNAVAILABLE 0x0a
|
|
|
|
#define GATEWAY_TRGT_FAIL 0x0b
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* return codes of function classifying packets as query/response */
|
2005-12-15 22:54:33 +00:00
|
|
|
#define QUERY_PACKET 0
|
|
|
|
#define RESPONSE_PACKET 1
|
|
|
|
#define CANNOT_CLASSIFY 2
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* Modbus header */
|
|
|
|
typedef struct _modbus_hdr {
|
2003-05-08 00:42:28 +00:00
|
|
|
guint8 unit_id; /* unit identifier (previously slave addr) */
|
|
|
|
guint8 function_code; /* Modbus function code */
|
2001-04-24 19:29:14 +00:00
|
|
|
} modbus_hdr;
|
|
|
|
|
|
|
|
/* Modbus/TCP header, containing the Modbus header */
|
|
|
|
typedef struct _mbtcp_hdr {
|
2003-04-16 06:57:38 +00:00
|
|
|
guint16 transaction_id; /* copied by svr, usually 0 */
|
|
|
|
guint16 protocol_id; /* always 0 */
|
|
|
|
guint16 len; /* len of data that follows */
|
|
|
|
modbus_hdr mdbs_hdr; /* mdbus hdr directly after mdbs/tcp hdr *
|
|
|
|
* in packet */
|
2001-04-24 19:29:14 +00:00
|
|
|
} mbtcp_hdr;
|
|
|
|
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_mbtcp = -1;
|
|
|
|
static int hf_mbtcp_transid = -1;
|
|
|
|
static int hf_mbtcp_protid = -1;
|
|
|
|
static int hf_mbtcp_len = -1;
|
|
|
|
static int hf_mbtcp_unitid = -1;
|
|
|
|
static int hf_mbtcp_functioncode = -1;
|
2003-04-16 06:57:38 +00:00
|
|
|
static int hf_modbus_reference = -1;
|
|
|
|
static int hf_modbus_lreference = -1;
|
|
|
|
static int hf_modbus_reftype = -1;
|
|
|
|
static int hf_modbus_readref = -1;
|
|
|
|
static int hf_modbus_writeref = -1;
|
|
|
|
static int hf_modbus_wordcnt = -1;
|
|
|
|
static int hf_modbus_readwordcnt = -1;
|
|
|
|
static int hf_modbus_writewordcnt = -1;
|
|
|
|
static int hf_modbus_bytecnt = -1;
|
|
|
|
static int hf_modbus_lbytecnt = -1;
|
|
|
|
static int hf_modbus_bitcnt = -1;
|
|
|
|
static int hf_modbus_exceptioncode = -1;
|
|
|
|
static int hf_modbus_andmask = -1;
|
|
|
|
static int hf_modbus_ormask = -1;
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_mbtcp = -1;
|
|
|
|
static gint ett_modbus_hdr = -1;
|
2003-04-16 06:57:38 +00:00
|
|
|
static gint ett_group_hdr = -1;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-04-24 19:29:14 +00:00
|
|
|
static int
|
|
|
|
classify_packet(packet_info *pinfo)
|
|
|
|
{
|
|
|
|
/* see if nature of packets can be derived from src/dst ports */
|
|
|
|
/* if so, return as found */
|
2008-11-19 22:30:45 +00:00
|
|
|
if (( pinfo->srcport == PORT_MBTCP ) && ( pinfo->destport != PORT_MBTCP ))
|
2008-09-30 21:23:19 +00:00
|
|
|
return RESPONSE_PACKET;
|
2008-11-19 22:30:45 +00:00
|
|
|
if (( pinfo->srcport != PORT_MBTCP ) && ( pinfo->destport == PORT_MBTCP ))
|
2008-09-30 21:23:19 +00:00
|
|
|
return QUERY_PACKET;
|
|
|
|
|
2001-04-24 19:29:14 +00:00
|
|
|
/* else, cannot classify */
|
2005-12-15 22:54:33 +00:00
|
|
|
return CANNOT_CLASSIFY;
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
/* Translate function to string, as given on p6 of
|
2001-04-24 19:29:14 +00:00
|
|
|
* "Open Modbus/TCP Specification", release 1 by Andy Swales. */
|
2003-04-16 06:57:38 +00:00
|
|
|
static const value_string function_code_vals[] = {
|
2005-12-15 22:54:33 +00:00
|
|
|
{ READ_COILS, "Read coils" },
|
|
|
|
{ READ_INPUT_DISCRETES, "Read input discretes" },
|
|
|
|
{ READ_MULT_REGS, "Read multiple registers" },
|
|
|
|
{ READ_INPUT_REGS, "Read input registers" },
|
|
|
|
{ WRITE_COIL, "Write coil" },
|
|
|
|
{ WRITE_SINGLE_REG, "Write single register" },
|
|
|
|
{ READ_EXCEPT_STAT, "Read exception status" },
|
|
|
|
{ DIAGNOSTICS, "Diagnostics" },
|
|
|
|
{ PROGRAM_484, "Program (484)" },
|
|
|
|
{ POLL_484, "Poll (484)" },
|
|
|
|
{ GET_COMM_EVENT_CTRS, "Get Comm. Event Counters" },
|
|
|
|
{ GET_COMM_EVENT_LOG, "Get Comm. Event Log" },
|
|
|
|
{ PROGRAM_584_984, "Program (584/984)" },
|
|
|
|
{ POLL_584_984, "Poll (584/984)" },
|
|
|
|
{ FORCE_MULT_COILS, "Force Multiple Coils" },
|
|
|
|
{ WRITE_MULT_REGS, "Write Multiple Registers" },
|
|
|
|
{ REPORT_SLAVE_ID, "Report Slave ID" },
|
|
|
|
{ PROGRAM_884_U84, "Program 884/u84" },
|
|
|
|
{ RESET_COMM_LINK, "Reset Comm. Link (884/u84)" },
|
|
|
|
{ READ_GENL_REF, "Read General Reference" },
|
|
|
|
{ WRITE_GENL_REF, "Write General Reference" },
|
|
|
|
{ MASK_WRITE_REG, "Mask Write Register" },
|
|
|
|
{ READ_WRITE_REG, "Read Write Register" },
|
|
|
|
{ READ_FIFO_QUEUE, "Read FIFO Queue" },
|
|
|
|
{ PROGRAM_CONCEPT, "Program (ConCept)" },
|
2008-09-30 21:23:19 +00:00
|
|
|
{ ENCAP_INTERFACE_TRANSP, "Encapsulated Interface Transport" },
|
2005-12-15 22:54:33 +00:00
|
|
|
{ FIRMWARE_REPLACE, "Firmware replacement" },
|
|
|
|
{ PROGRAM_584_984_2, "Program (584/984)" },
|
|
|
|
{ REPORT_LOCAL_ADDR_MB, "Report local address (Modbus)" },
|
2003-04-16 06:57:38 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string exception_code_vals[] = {
|
2005-12-15 22:54:33 +00:00
|
|
|
{ ILLEGAL_FUNCTION, "Illegal function" },
|
|
|
|
{ ILLEGAL_ADDRESS, "Illegal data address" },
|
|
|
|
{ ILLEGAL_VALUE, "Illegal data value" },
|
|
|
|
{ ILLEGAL_RESPONSE, "Illegal response length" },
|
|
|
|
{ ACKNOWLEDGE, "Acknowledge" },
|
|
|
|
{ SLAVE_BUSY, "Slave device busy" },
|
|
|
|
{ NEGATIVE_ACK, "Negative acknowledge" },
|
|
|
|
{ MEMORY_ERR, "Memory parity error" },
|
|
|
|
{ GATEWAY_UNAVAILABLE, "Gateway path unavailable" },
|
|
|
|
{ GATEWAY_TRGT_FAIL, "Gateway target device failed to respond" },
|
2003-04-16 06:57:38 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* Code to actually dissect the packets */
|
2005-12-15 22:54:33 +00:00
|
|
|
static int
|
2001-04-24 19:29:14 +00:00
|
|
|
dissect_mbtcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
/* Set up structures needed to add the protocol subtree and manage it */
|
|
|
|
mbtcp_hdr mh;
|
|
|
|
proto_item *mi, *mf;
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree *mbtcp_tree, *modbus_tree, *group_tree;
|
|
|
|
int offset, group_offset, packet_type;
|
|
|
|
guint i;
|
|
|
|
gint packet_len, payload_start, payload_len;
|
2005-06-26 19:56:52 +00:00
|
|
|
const char *func_string = "";
|
2008-06-25 09:12:35 +00:00
|
|
|
const char *pkt_type_str = "";
|
|
|
|
const char *err_str = "";
|
2003-04-16 06:57:38 +00:00
|
|
|
guint32 byte_cnt, group_byte_cnt, group_word_cnt;
|
|
|
|
guint32 packet_num; /* num to uniquely identify different mbtcp
|
2008-11-19 22:30:45 +00:00
|
|
|
* packets in one packet */
|
2003-04-16 06:57:38 +00:00
|
|
|
guint8 exception_code;
|
|
|
|
gboolean exception_returned;
|
2005-12-15 22:54:33 +00:00
|
|
|
guint8 fc;
|
|
|
|
|
|
|
|
mh.transaction_id = tvb_get_ntohs(tvb, 0);
|
|
|
|
mh.protocol_id = tvb_get_ntohs(tvb, 2);
|
|
|
|
mh.len = tvb_get_ntohs(tvb, 4);
|
|
|
|
mh.mdbs_hdr.unit_id = tvb_get_guint8(tvb, 6);
|
|
|
|
mh.mdbs_hdr.function_code = tvb_get_guint8(tvb, 7);
|
|
|
|
|
|
|
|
|
|
|
|
/* check that it actually looks like Modbus/TCP */
|
|
|
|
/* protocol id == 0 */
|
|
|
|
if( mh.protocol_id != 0 ){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* length is at least 2 (unit_id + function_code) */
|
|
|
|
if( mh.len < 2 ){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* function code is in the set 1-24, 40, 125-127.
|
|
|
|
* Note that function code is only 7 bits.
|
|
|
|
*/
|
|
|
|
fc=mh.mdbs_hdr.function_code&0x7f;
|
2008-09-30 21:23:19 +00:00
|
|
|
if(!match_strval(fc, function_code_vals))
|
2005-12-15 22:54:33 +00:00
|
|
|
return 0;
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
/* Make entries in Protocol column on summary display */
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Modbus/TCP");
|
2001-04-24 19:29:14 +00:00
|
|
|
|
2009-08-09 07:36:13 +00:00
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2001-04-24 23:22:03 +00:00
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
|
|
|
|
/* Make entries in Info column on summary display */
|
2003-04-16 06:57:38 +00:00
|
|
|
offset = 0;
|
2005-12-15 22:54:33 +00:00
|
|
|
|
2001-04-24 19:29:14 +00:00
|
|
|
if ( mh.mdbs_hdr.function_code & 0x80 ) {
|
2003-04-16 06:57:38 +00:00
|
|
|
exception_code = tvb_get_guint8(tvb, offset + sizeof(mbtcp_hdr));
|
2001-04-24 19:29:14 +00:00
|
|
|
mh.mdbs_hdr.function_code ^= 0x80;
|
2003-04-16 06:57:38 +00:00
|
|
|
exception_returned = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exception_code = 0;
|
|
|
|
exception_returned = FALSE;
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
2003-04-16 06:57:38 +00:00
|
|
|
func_string = val_to_str(mh.mdbs_hdr.function_code, function_code_vals,
|
|
|
|
"Unknown function (%u)");
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
2001-04-24 23:22:03 +00:00
|
|
|
{
|
2001-04-24 19:29:14 +00:00
|
|
|
packet_type = classify_packet(pinfo);
|
|
|
|
switch ( packet_type ) {
|
2005-12-15 22:54:33 +00:00
|
|
|
case QUERY_PACKET : pkt_type_str="query";
|
2001-04-24 19:29:14 +00:00
|
|
|
break;
|
2005-12-15 22:54:33 +00:00
|
|
|
case RESPONSE_PACKET : pkt_type_str="response";
|
2001-04-24 19:29:14 +00:00
|
|
|
break;
|
2005-12-15 22:54:33 +00:00
|
|
|
case CANNOT_CLASSIFY : err_str="Unable to classify as query or response.";
|
2005-10-08 11:37:00 +00:00
|
|
|
pkt_type_str="unknown";
|
2001-04-24 19:29:14 +00:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( exception_returned )
|
2005-10-08 11:37:00 +00:00
|
|
|
err_str="Exception returned ";
|
2002-08-28 21:04:11 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO,
|
|
|
|
"%8s [%2u pkt(s)]: trans: %5u; unit: %3u, func: %3u: %s. %s",
|
|
|
|
pkt_type_str, 1, mh.transaction_id, (unsigned char) mh.mdbs_hdr.unit_id,
|
2001-04-24 19:29:14 +00:00
|
|
|
(unsigned char) mh.mdbs_hdr.function_code, func_string, err_str);
|
2002-08-28 21:04:11 +00:00
|
|
|
}
|
2001-04-24 19:29:14 +00:00
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
/* build up protocol tree and iterate over multiple packets */
|
|
|
|
packet_num = 0;
|
|
|
|
while (1) {
|
2001-04-24 19:29:14 +00:00
|
|
|
packet_type = classify_packet(pinfo);
|
2003-04-16 06:57:38 +00:00
|
|
|
packet_len = sizeof(mbtcp_hdr) - sizeof(modbus_hdr) + mh.len;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-04-24 19:29:14 +00:00
|
|
|
/* if a tree exists, perform operations to add fields to it */
|
|
|
|
if (tree) {
|
2002-08-28 21:04:11 +00:00
|
|
|
mi = proto_tree_add_protocol_format(tree, proto_mbtcp, tvb, offset,
|
2001-04-24 19:29:14 +00:00
|
|
|
packet_len, "Modbus/TCP");
|
|
|
|
mbtcp_tree = proto_item_add_subtree(mi, ett_mbtcp);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2008-11-19 22:30:45 +00:00
|
|
|
/* Add items to protocol tree specific to Modbus/TCP */
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_tree_add_uint(mbtcp_tree, hf_mbtcp_transid, tvb, offset, 2,
|
2001-04-24 19:29:14 +00:00
|
|
|
mh.transaction_id);
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_tree_add_uint(mbtcp_tree, hf_mbtcp_protid, tvb, offset + 2, 2,
|
2001-04-24 19:29:14 +00:00
|
|
|
mh.protocol_id);
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_tree_add_uint(mbtcp_tree, hf_mbtcp_len, tvb, offset + 4, 2,
|
2001-04-24 19:29:14 +00:00
|
|
|
mh.len);
|
2003-04-16 06:57:38 +00:00
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
proto_tree_add_uint(mbtcp_tree, hf_mbtcp_unitid, tvb, offset + 6, 1,
|
|
|
|
mh.mdbs_hdr.unit_id);
|
|
|
|
|
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
/* Add items to protocol tree specific to Modbus generic */
|
2008-09-30 21:23:19 +00:00
|
|
|
mf = proto_tree_add_text(mbtcp_tree, tvb, offset + 7, mh.len - 1,
|
2001-04-24 19:29:14 +00:00
|
|
|
"Modbus");
|
2002-08-28 21:04:11 +00:00
|
|
|
modbus_tree = proto_item_add_subtree(mf, ett_modbus_hdr);
|
2003-04-16 06:57:38 +00:00
|
|
|
mi = proto_tree_add_uint(modbus_tree, hf_mbtcp_functioncode, tvb, offset + 7, 1,
|
2001-04-24 19:29:14 +00:00
|
|
|
mh.mdbs_hdr.function_code);
|
2003-04-16 06:57:38 +00:00
|
|
|
|
|
|
|
/** detail payload as a function of exception/function code */
|
|
|
|
func_string = val_to_str(mh.mdbs_hdr.function_code,
|
|
|
|
function_code_vals, "Unknown function");
|
|
|
|
payload_start = offset + 8;
|
|
|
|
payload_len = mh.len - sizeof(modbus_hdr);
|
|
|
|
if (exception_returned) {
|
|
|
|
proto_item_set_text(mi, "function %u: %s. Exception: %s",
|
|
|
|
mh.mdbs_hdr.function_code,
|
|
|
|
func_string,
|
|
|
|
val_to_str(exception_code,
|
|
|
|
exception_code_vals,
|
|
|
|
"Unknown exception code (%u)"));
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_exceptioncode, tvb, payload_start, 1,
|
|
|
|
exception_code);
|
|
|
|
}
|
|
|
|
else {
|
2002-08-28 21:04:11 +00:00
|
|
|
proto_item_set_text(mi, "function %u: %s", mh.mdbs_hdr.function_code,
|
2001-04-24 19:29:14 +00:00
|
|
|
func_string);
|
2003-04-16 06:57:38 +00:00
|
|
|
switch (mh.mdbs_hdr.function_code) {
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case READ_COILS:
|
|
|
|
case READ_INPUT_DISCRETES:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_bitcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start, 1, byte_cnt);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 1, byte_cnt, "Data");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case READ_MULT_REGS:
|
|
|
|
case READ_INPUT_REGS:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_wordcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start, 1, byte_cnt);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 1, byte_cnt, "Data");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case WRITE_COIL:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 2, 1, "Data");
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 3, 1, "Padding");
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 2, 1, "Data");
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 3, 1, "Padding");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case WRITE_SINGLE_REG:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 2, 2, "Data");
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 2, 2, "Data");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case READ_EXCEPT_STAT:
|
|
|
|
if (packet_type == RESPONSE_PACKET)
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start, 1, "Data");
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case FORCE_MULT_COILS:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_bitcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start + 4);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start + 4, 1,
|
|
|
|
byte_cnt);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 5, byte_cnt, "Data");
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_bitcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case WRITE_MULT_REGS:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_wordcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start + 4);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start + 4, 1,
|
|
|
|
byte_cnt);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 5, byte_cnt, "Data");
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_wordcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case READ_GENL_REF:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start, 1,
|
|
|
|
byte_cnt);
|
|
|
|
|
|
|
|
/* add subtrees to describe each group of packet */
|
|
|
|
group_offset = payload_start + 1;
|
|
|
|
for (i = 0; i < byte_cnt / 7; i++) {
|
|
|
|
mi = proto_tree_add_text( modbus_tree, tvb, group_offset, 7,
|
|
|
|
"Group %u", i);
|
|
|
|
group_tree = proto_item_add_subtree(mi, ett_group_hdr);
|
|
|
|
proto_tree_add_item(group_tree, hf_modbus_reftype, tvb, group_offset, 1, FALSE);
|
|
|
|
proto_tree_add_item(group_tree, hf_modbus_lreference, tvb, group_offset + 1, 4, FALSE);
|
|
|
|
proto_tree_add_item(group_tree, hf_modbus_wordcnt, tvb, group_offset + 5, 2, FALSE);
|
|
|
|
group_offset += 7;
|
|
|
|
}
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start, 1,
|
|
|
|
byte_cnt);
|
|
|
|
|
|
|
|
/* add subtrees to describe each group of packet */
|
|
|
|
group_offset = payload_start + 1;
|
|
|
|
i = 0;
|
|
|
|
while (byte_cnt > 0) {
|
|
|
|
group_byte_cnt = (guint32)tvb_get_guint8(tvb, group_offset);
|
|
|
|
mi = proto_tree_add_text( modbus_tree, tvb, group_offset, group_byte_cnt + 1,
|
|
|
|
"Group %u", i);
|
|
|
|
group_tree = proto_item_add_subtree(mi, ett_group_hdr);
|
|
|
|
proto_tree_add_uint(group_tree, hf_modbus_bytecnt, tvb, group_offset, 1,
|
|
|
|
group_byte_cnt);
|
|
|
|
proto_tree_add_item(group_tree, hf_modbus_reftype, tvb, group_offset + 1, 1, FALSE);
|
|
|
|
proto_tree_add_text(group_tree, tvb, group_offset + 2, group_byte_cnt - 1, "Data");
|
|
|
|
group_offset += (group_byte_cnt + 1);
|
|
|
|
byte_cnt -= (group_byte_cnt + 1);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case WRITE_GENL_REF:
|
|
|
|
if ((packet_type == QUERY_PACKET) || (packet_type == RESPONSE_PACKET)) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start, 1,
|
|
|
|
byte_cnt);
|
|
|
|
|
|
|
|
/* add subtrees to describe each group of packet */
|
|
|
|
group_offset = payload_start + 1;
|
|
|
|
i = 0;
|
|
|
|
while (byte_cnt > 0) {
|
|
|
|
group_word_cnt = tvb_get_ntohs(tvb, group_offset + 5);
|
|
|
|
group_byte_cnt = (2 * group_word_cnt) + 7;
|
|
|
|
mi = proto_tree_add_text( modbus_tree, tvb, group_offset,
|
|
|
|
group_byte_cnt, "Group %u", i);
|
|
|
|
group_tree = proto_item_add_subtree(mi, ett_group_hdr);
|
|
|
|
proto_tree_add_item(group_tree, hf_modbus_reftype, tvb, group_offset, 1, FALSE);
|
|
|
|
proto_tree_add_item(group_tree, hf_modbus_lreference, tvb, group_offset + 1, 4, FALSE);
|
|
|
|
proto_tree_add_uint(group_tree, hf_modbus_wordcnt, tvb, group_offset + 5, 2,
|
|
|
|
group_word_cnt);
|
|
|
|
proto_tree_add_text(group_tree, tvb, group_offset + 7, group_byte_cnt - 7, "Data");
|
|
|
|
group_offset += group_byte_cnt;
|
|
|
|
byte_cnt -= group_byte_cnt;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case MASK_WRITE_REG:
|
|
|
|
if ((packet_type == QUERY_PACKET) || (packet_type == RESPONSE_PACKET)) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_andmask, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_ormask, tvb, payload_start + 4, 2, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case READ_WRITE_REG:
|
|
|
|
if (packet_type == QUERY_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_readref, tvb, payload_start, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_readwordcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_writeref, tvb, payload_start + 4, 2, FALSE);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_writewordcnt, tvb, payload_start + 6, 2, FALSE);
|
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start + 8);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start + 8, 1,
|
|
|
|
byte_cnt);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 9, byte_cnt, "Data");
|
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_guint8(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_bytecnt, tvb, payload_start, 1,
|
|
|
|
byte_cnt);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 1, byte_cnt, "Data");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case READ_FIFO_QUEUE:
|
|
|
|
if (packet_type == QUERY_PACKET)
|
2003-04-16 06:57:38 +00:00
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_reference, tvb, payload_start, 2, FALSE);
|
2005-12-15 22:54:33 +00:00
|
|
|
else if (packet_type == RESPONSE_PACKET) {
|
2003-04-16 06:57:38 +00:00
|
|
|
byte_cnt = (guint32)tvb_get_ntohs(tvb, payload_start);
|
|
|
|
proto_tree_add_uint(modbus_tree, hf_modbus_lbytecnt, tvb, payload_start, 2,
|
|
|
|
byte_cnt);
|
|
|
|
proto_tree_add_item(modbus_tree, hf_modbus_wordcnt, tvb, payload_start + 2, 2, FALSE);
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start + 4, byte_cnt - 2, "Data");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
case DIAGNOSTICS:
|
|
|
|
case PROGRAM_484:
|
|
|
|
case POLL_484:
|
|
|
|
case GET_COMM_EVENT_CTRS:
|
|
|
|
case GET_COMM_EVENT_LOG:
|
|
|
|
case PROGRAM_584_984:
|
|
|
|
case POLL_584_984:
|
|
|
|
case REPORT_SLAVE_ID:
|
|
|
|
case PROGRAM_884_U84:
|
|
|
|
case RESET_COMM_LINK:
|
|
|
|
case PROGRAM_CONCEPT:
|
|
|
|
case FIRMWARE_REPLACE:
|
|
|
|
case PROGRAM_584_984_2:
|
|
|
|
case REPORT_LOCAL_ADDR_MB:
|
2003-04-16 06:57:38 +00:00
|
|
|
/* these function codes are not part of the Modbus/TCP specification */
|
|
|
|
default:
|
|
|
|
if (payload_len > 0)
|
|
|
|
proto_tree_add_text(modbus_tree, tvb, payload_start, payload_len, "Data");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
2003-04-16 06:57:38 +00:00
|
|
|
|
|
|
|
/* move onto next packet (if there) */
|
|
|
|
offset += packet_len;
|
2001-04-24 19:29:14 +00:00
|
|
|
packet_num++;
|
2003-04-16 06:57:38 +00:00
|
|
|
if (tvb_reported_length_remaining(tvb, offset) > 0) {
|
|
|
|
|
|
|
|
/* load header structure for next packet */
|
2005-12-15 22:54:33 +00:00
|
|
|
mh.transaction_id = tvb_get_ntohs(tvb, offset+0);
|
|
|
|
mh.protocol_id = tvb_get_ntohs(tvb, offset+2);
|
|
|
|
mh.len = tvb_get_ntohs(tvb, offset+4);
|
|
|
|
mh.mdbs_hdr.unit_id = tvb_get_guint8(tvb, offset+6);
|
|
|
|
mh.mdbs_hdr.function_code = tvb_get_guint8(tvb, offset+7);
|
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
|
|
|
|
if ( mh.mdbs_hdr.function_code & 0x80 ) {
|
|
|
|
exception_code = tvb_get_guint8(tvb, offset + sizeof(mbtcp_hdr));
|
|
|
|
mh.mdbs_hdr.function_code ^= 0x80;
|
|
|
|
exception_returned = TRUE;
|
|
|
|
} else
|
|
|
|
exception_returned = FALSE;
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
2003-04-16 06:57:38 +00:00
|
|
|
else
|
|
|
|
break;
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
2005-12-15 22:54:33 +00:00
|
|
|
|
|
|
|
return tvb_length(tvb);
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-21 04:49:01 +00:00
|
|
|
/* Register the protocol with Wireshark */
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_modbus(void)
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
2001-04-24 19:29:14 +00:00
|
|
|
|
|
|
|
/* Setup list of header fields See Section 1.6.1 for details*/
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
/* Modbus/TCP header fields */
|
|
|
|
{ &hf_mbtcp_transid,
|
2003-04-16 06:57:38 +00:00
|
|
|
{ "transaction identifier", "modbus_tcp.trans_id",
|
2002-08-28 21:04:11 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2001-04-24 19:29:14 +00:00
|
|
|
},
|
|
|
|
{ &hf_mbtcp_protid,
|
2003-04-16 06:57:38 +00:00
|
|
|
{ "protocol identifier", "modbus_tcp.prot_id",
|
2002-08-28 21:04:11 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2001-04-24 19:29:14 +00:00
|
|
|
},
|
|
|
|
{ &hf_mbtcp_len,
|
2003-04-16 06:57:38 +00:00
|
|
|
{ "length", "modbus_tcp.len",
|
2002-08-28 21:04:11 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2001-04-24 19:29:14 +00:00
|
|
|
},
|
|
|
|
/* Modbus header fields */
|
|
|
|
{ &hf_mbtcp_unitid,
|
2003-04-16 06:57:38 +00:00
|
|
|
{ "unit identifier", "modbus_tcp.unit_id",
|
2002-08-28 21:04:11 +00:00
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2001-04-24 19:29:14 +00:00
|
|
|
},
|
|
|
|
{ &hf_mbtcp_functioncode,
|
2003-04-16 06:57:38 +00:00
|
|
|
{ "function code", "modbus_tcp.func_code",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(function_code_vals), 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_reference,
|
|
|
|
{ "reference number", "modbus_tcp.reference_num",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_lreference,
|
|
|
|
{ "reference number (32 bit)", "modbus_tcp.reference_num_32",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_reftype,
|
|
|
|
{ "reference type", "modbus_tcp.reference_type",
|
2002-08-28 21:04:11 +00:00
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_readref,
|
|
|
|
{ "read reference number", "modbus_tcp.read_reference_num",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_writeref,
|
|
|
|
{ "write reference number", "modbus_tcp.write_reference_num",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_wordcnt,
|
|
|
|
{ "word count", "modbus_tcp.word_cnt",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_readwordcnt,
|
|
|
|
{ "read word count", "modbus_tcp.read_word_cnt",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_writewordcnt,
|
|
|
|
{ "write word count", "modbus_tcp.write_word_cnt",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_bitcnt,
|
|
|
|
{ "bit count", "modbus_tcp.bit_cnt",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_bytecnt,
|
|
|
|
{ "byte count", "modbus_tcp.byte_cnt",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_lbytecnt,
|
|
|
|
{ "byte count (16-bit)", "modbus_tcp.byte_cnt_16",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_exceptioncode,
|
|
|
|
{ "exception code", "modbus_tcp.exception_code",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(exception_code_vals), 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_andmask,
|
|
|
|
{ "AND mask", "modbus_tcp.and_mask",
|
|
|
|
FT_UINT16, BASE_HEX, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2003-04-16 06:57:38 +00:00
|
|
|
},
|
|
|
|
{ &hf_modbus_ormask,
|
|
|
|
{ "OR mask", "modbus_tcp.or_mask",
|
|
|
|
FT_UINT16, BASE_HEX, NULL, 0x0,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
/* Setup protocol subtree array */
|
2001-04-24 19:29:14 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_mbtcp,
|
2003-04-16 06:57:38 +00:00
|
|
|
&ett_modbus_hdr,
|
|
|
|
&ett_group_hdr
|
2001-04-24 19:29:14 +00:00
|
|
|
};
|
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_mbtcp = proto_register_protocol("Modbus/TCP", "Modbus/TCP", "mbtcp");
|
2001-04-24 19:29:14 +00:00
|
|
|
|
2003-04-16 06:57:38 +00:00
|
|
|
/* Required function calls to register the header fields and subtrees used */
|
2001-04-24 19:29:14 +00:00
|
|
|
proto_register_field_array(proto_mbtcp, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If this dissector uses sub-dissector registration add a registration routine.
|
|
|
|
This format is required because a script is used to find these routines and
|
|
|
|
create the code that calls these routines.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_reg_handoff_mbtcp(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t mbtcp_handle;
|
|
|
|
|
2005-12-15 22:54:33 +00:00
|
|
|
mbtcp_handle = new_create_dissector_handle(dissect_mbtcp, proto_mbtcp);
|
2008-11-19 22:30:45 +00:00
|
|
|
dissector_add("tcp.port", PORT_MBTCP, mbtcp_handle);
|
|
|
|
dissector_add("udp.port", PORT_MBTCP, mbtcp_handle);
|
2001-04-24 19:29:14 +00:00
|
|
|
}
|