2 * Routines for CIP (Common Industrial Protocol) dissection
3 * CIP Home: www.odva.org
6 * Magnus Hansson <mah@hms.se>
7 * Joakim Wiberg <jow@hms.se>
9 * Added support for Connection Configuration Object
10 * ryan wamsley * Copyright 2007
14 * Wireshark - Network traffic analyzer
15 * By Gerald Combs <gerald@wireshark.org>
16 * Copyright 1998 Gerald Combs
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 /* CIP Service Codes */
34 #define SC_GET_ATT_ALL 0x01
35 #define SC_SET_ATT_ALL 0x02
36 #define SC_GET_ATT_LIST 0x03
37 #define SC_SET_ATT_LIST 0x04
41 #define SC_CREATE 0x08
42 #define SC_DELETE 0x09
43 #define SC_MULT_SERV_PACK 0x0A
44 #define SC_APPLY_ATTRIBUTES 0x0D
45 #define SC_GET_ATT_SINGLE 0x0E
46 #define SC_SET_ATT_SINGLE 0x10
47 #define SC_FIND_NEXT_OBJ_INST 0x11
48 #define SC_RESTOR 0x15
51 #define SC_GET_MEMBER 0x18
52 #define SC_SET_MEMBER 0x19
53 #define SC_INSERT_MEMBER 0x1A
54 #define SC_REMOVE_MEMBER 0x1B
55 #define SC_GROUP_SYNC 0x1C
57 /* Classes that have class-specfic dissectors */
58 #define CI_CLS_MR 0x02 /* Message Router */
59 #define CI_CLS_CM 0x06 /* Connection Manager */
60 #define CI_CLS_MB 0x44 /* Modbus Object */
61 #define CI_CLS_CCO 0xF3 /* Connection Configuration Object */
63 /* Class specific services */
64 /* Connection Manager */
65 #define SC_CM_FWD_CLOSE 0x4E
66 #define SC_CM_UNCON_SEND 0x52
67 #define SC_CM_FWD_OPEN 0x54
68 #define SC_CM_LARGE_FWD_OPEN 0x5B
69 #define SC_CM_GET_CONN_OWNER 0x5A
71 /* Modbus Object services */
72 #define SC_MB_READ_DISCRETE_INPUTS 0x4B
73 #define SC_MB_READ_COILS 0x4C
74 #define SC_MB_READ_INPUT_REGISTERS 0x4D
75 #define SC_MB_READ_HOLDING_REGISTERS 0x4E
76 #define SC_MB_WRITE_COILS 0x4F
77 #define SC_MB_WRITE_HOLDING_REGISTERS 0x50
78 #define SC_MB_PASSTHROUGH 0x51
80 /* Connection Configuration Object services */
81 #define SC_CCO_KICK_TIMER 0x4B
82 #define SC_CCO_OPEN_CONN 0x4C
83 #define SC_CCO_CLOSE_CONN 0x4D
84 #define SC_CCO_STOP_CONN 0x4E
85 #define SC_CCO_CHANGE_START 0x4F
86 #define SC_CCO_GET_STATUS 0x50
87 #define SC_CCO_CHANGE_COMPLETE 0x51
88 #define SC_CCO_AUDIT_CHANGE 0x52
90 /* CIP General status codes */
91 #define CI_GRC_SUCCESS 0x00
92 #define CI_GRC_FAILURE 0x01
93 #define CI_GRC_NO_RESOURCE 0x02
94 #define CI_GRC_BAD_DATA 0x03
95 #define CI_GRC_BAD_PATH 0x04
96 #define CI_GRC_BAD_CLASS_INSTANCE 0x05
97 #define CI_GRC_PARTIAL_DATA 0x06
98 #define CI_GRC_CONN_LOST 0x07
99 #define CI_GRC_BAD_SERVICE 0x08
100 #define CI_GRC_BAD_ATTR_DATA 0x09
101 #define CI_GRC_ATTR_LIST_ERROR 0x0A
102 #define CI_GRC_ALREADY_IN_MODE 0x0B
103 #define CI_GRC_BAD_OBJ_MODE 0x0C
104 #define CI_GRC_OBJ_ALREADY_EXISTS 0x0D
105 #define CI_GRC_ATTR_NOT_SETTABLE 0x0E
106 #define CI_GRC_PERMISSION_DENIED 0x0F
107 #define CI_GRC_DEV_IN_WRONG_STATE 0x10
108 #define CI_GRC_REPLY_DATA_TOO_LARGE 0x11
109 #define CI_GRC_FRAGMENT_PRIMITIVE 0x12
110 #define CI_GRC_CONFIG_TOO_SMALL 0x13
111 #define CI_GRC_UNDEFINED_ATTR 0x14
112 #define CI_GRC_CONFIG_TOO_BIG 0x15
113 #define CI_GRC_OBJ_DOES_NOT_EXIST 0x16
114 #define CI_GRC_NO_FRAGMENTATION 0x17
115 #define CI_GRC_DATA_NOT_SAVED 0x18
116 #define CI_GRC_DATA_WRITE_FAILURE 0x19
117 #define CI_GRC_REQUEST_TOO_LARGE 0x1A
118 #define CI_GRC_RESPONSE_TOO_LARGE 0x1B
119 #define CI_GRC_MISSING_LIST_DATA 0x1C
120 #define CI_GRC_INVALID_LIST_STATUS 0x1D
121 #define CI_GRC_SERVICE_ERROR 0x1E
122 #define CI_GRC_CONN_RELATED_FAILURE 0x1F
123 #define CI_GRC_INVALID_PARAMETER 0x20
124 #define CI_GRC_WRITE_ONCE_FAILURE 0x21
125 #define CI_GRC_INVALID_REPLY 0x22
126 #define CI_GRC_BUFFER_OVERFLOW 0x23
127 #define CI_GRC_MESSAGE_FORMAT 0x24
128 #define CI_GRC_BAD_KEY_IN_PATH 0x25
129 #define CI_GRC_BAD_PATH_SIZE 0x26
130 #define CI_GRC_UNEXPECTED_ATTR 0x27
131 #define CI_GRC_INVALID_MEMBER 0x28
132 #define CI_GRC_MEMBER_NOT_SETTABLE 0x29
133 #define CI_GRC_G2_SERVER_FAILURE 0x2A
134 #define CI_GRC_UNKNOWN_MB_ERROR 0x2B
135 #define CI_GRC_ATTRIBUTE_NOT_GET 0x2C
137 #define CI_GRC_STILL_PROCESSING 0xFF
141 #define CI_SEGMENT_TYPE_MASK 0xE0
143 #define CI_PORT_SEGMENT 0x00
144 #define CI_LOGICAL_SEGMENT 0x20
145 #define CI_NETWORK_SEGMENT 0x40
146 #define CI_SYMBOLIC_SEGMENT 0x60
147 #define CI_DATA_SEGMENT 0x80
149 #define CI_PORT_SEG_EX_LINK_ADDRESS 0x10
150 #define CI_PORT_SEG_PORT_ID_MASK 0x0F
152 #define CI_LOGICAL_SEG_TYPE_MASK 0x1C
153 #define CI_LOGICAL_SEG_CLASS_ID 0x00
154 #define CI_LOGICAL_SEG_INST_ID 0x04
155 #define CI_LOGICAL_SEG_MBR_ID 0x08
156 #define CI_LOGICAL_SEG_CON_POINT 0x0C
157 #define CI_LOGICAL_SEG_ATTR_ID 0x10
158 #define CI_LOGICAL_SEG_SPECIAL 0x14
159 #define CI_LOGICAL_SEG_SERV_ID 0x18
160 #define CI_LOGICAL_SEG_RES_1 0x1C
162 #define CI_LOGICAL_SEG_FORMAT_MASK 0x03
163 #define CI_LOGICAL_SEG_8_BIT 0x00
164 #define CI_LOGICAL_SEG_16_BIT 0x01
165 #define CI_LOGICAL_SEG_32_BIT 0x02
166 #define CI_LOGICAL_SEG_RES_2 0x03
167 #define CI_LOGICAL_SEG_E_KEY 0x00
169 #define CI_E_KEY_FORMAT_VAL 0x04
171 #define CI_DATA_SEG_TYPE_MASK 0x1F
172 #define CI_DATA_SEG_SIMPLE 0x00
173 #define CI_DATA_SEG_SYMBOL 0x11
175 #define CI_NETWORK_SEG_TYPE_MASK 0x1F
176 #define CI_NETWORK_SEG_SCHEDULE 0x01
177 #define CI_NETWORK_SEG_FIXED_TAG 0x02
178 #define CI_NETWORK_SEG_PROD_INHI 0x03
179 #define CI_NETWORK_SEG_SAFETY 0x10
180 #define CI_NETWORK_SEG_EXTENDED 0x1F
182 #define CI_TRANSPORT_CLASS_MASK 0x0F
183 #define CI_PRODUCTION_TRIGGER_MASK 0x70
184 #define CI_PRODUCTION_DIR_MASK 0x80
186 #define CONN_TYPE_NULL 0
187 #define CONN_TYPE_MULTICAST 1
188 #define CONN_TYPE_P2P 2
189 #define CONN_TYPE_RESERVED 3
191 /* Define common services */
192 #define GENERIC_SC_LIST \
193 { SC_GET_ATT_ALL, "Get Attribute All" }, \
194 { SC_SET_ATT_ALL, "Set Attribute All" }, \
195 { SC_GET_ATT_LIST, "Get Attribute List" }, \
196 { SC_SET_ATT_LIST, "Set Attribute List" }, \
197 { SC_RESET, "Reset" }, \
198 { SC_START, "Start" }, \
199 { SC_STOP, "Stop" }, \
200 { SC_CREATE, "Create" }, \
201 { SC_DELETE, "Delete" }, \
202 { SC_MULT_SERV_PACK, "Multiple Service Packet" }, \
203 { SC_APPLY_ATTRIBUTES, "Apply Attributes" }, \
204 { SC_GET_ATT_SINGLE, "Get Attribute Single" }, \
205 { SC_SET_ATT_SINGLE, "Set Attribute Single" }, \
206 { SC_FIND_NEXT_OBJ_INST, "Find Next Object Instance" }, \
207 { SC_RESTOR, "Restore" }, \
208 { SC_SAVE, "Save" }, \
209 { SC_NO_OP, "Nop" }, \
210 { SC_GET_MEMBER, "Get Member" }, \
211 { SC_SET_MEMBER, "Set Member" }, \
212 { SC_INSERT_MEMBER, "Insert Member" }, \
213 { SC_REMOVE_MEMBER, "Remove Member" }, \
214 { SC_GROUP_SYNC, "Group Sync" }, \
216 typedef struct cip_simple_request_info {
221 } cip_simple_request_info_t
;
253 /* Currently not supported */
259 typedef int attribute_dissector_func(packet_info
*pinfo
, proto_tree
*tree
, proto_item
*item
, tvbuff_t
*tvb
,
260 int offset
, int total_len
);
262 typedef struct attribute_info
{
264 gboolean class_instance
;
267 enum cip_datatype datatype
;
269 attribute_dissector_func
* pdissect
;
272 typedef struct cip_connID_info
{
279 enum cip_safety_format_type
{CIP_SAFETY_BASE_FORMAT
, CIP_SAFETY_EXTENDED_FORMAT
};
281 typedef struct cip_safety_epath_info
{
283 enum cip_safety_format_type format
;
284 } cip_safety_epath_info_t
;
286 typedef struct cip_conn_info
{
287 guint16 ConnSerialNumber
;
289 guint32 DeviceSerialNumber
;
290 cip_connID_info_t O2T
;
291 cip_connID_info_t T2O
;
292 guint8 TransportClass_trigger
;
293 cip_safety_epath_info_t safety
;
297 typedef struct cip_req_info
{
298 dissector_handle_t dissector
;
303 cip_simple_request_info_t
* ciaData
;
304 cip_conn_info_t
* connInfo
;
305 gboolean isUnconnectedSend
;
309 ** Exported functions
311 extern void dissect_epath( tvbuff_t
*tvb
, packet_info
*pinfo
, proto_item
*epath_item
, int offset
, int path_length
,
312 gboolean generate
, gboolean packed
, cip_simple_request_info_t
* req_data
, cip_safety_epath_info_t
* safety
);
313 extern void dissect_cip_date_and_time(proto_tree
*tree
, tvbuff_t
*tvb
, int offset
, int hf_datetime
);
316 ** Exported variables
318 extern dissector_table_t subdissector_class_table
;
319 extern const value_string cip_sc_rr
[];
320 extern const value_string cip_reset_type_vals
[];
321 extern value_string_ext cip_gs_vals_ext
;
322 extern value_string_ext cip_cm_ext_st_vals_ext
;
323 extern value_string_ext cip_vendor_vals_ext
;
324 extern value_string_ext cip_devtype_vals_ext
;
325 extern value_string_ext cip_class_names_vals_ext
;
333 * indent-tabs-mode: nil
336 * ex: set shiftwidth=3 tabstop=8 expandtab:
337 * :indentSize=3:tabSize=8:noTabs=true: