Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
packet-cip.h
1/* packet-cip.h
2 * Routines for CIP (Common Industrial Protocol) dissection
3 * CIP Home: www.odva.org
4 *
5 * Copyright 2004
6 * Magnus Hansson <mah@hms.se>
7 * Joakim Wiberg <jow@hms.se>
8 *
9 * Added support for Connection Configuration Object
10 * ryan wamsley * Copyright 2007
11 *
12 * Added support for PCCC Objects
13 * Jared Rittle - Cisco Talos
14 * Copyright 2017
15 *
16 * Wireshark - Network traffic analyzer
17 * By Gerald Combs <gerald@wireshark.org>
18 * Copyright 1998 Gerald Combs
19 *
20 * SPDX-License-Identifier: GPL-2.0-or-later
21 */
22
23#ifndef PACKET_CIP_H
24#define PACKET_CIP_H
25
26/* CIP Service Codes */
27#define SC_GET_ATT_ALL 0x01
28#define SC_SET_ATT_ALL 0x02
29#define SC_GET_ATT_LIST 0x03
30#define SC_SET_ATT_LIST 0x04
31#define SC_RESET 0x05
32#define SC_START 0x06
33#define SC_STOP 0x07
34#define SC_CREATE 0x08
35#define SC_DELETE 0x09
36#define SC_MULT_SERV_PACK 0x0A
37#define SC_APPLY_ATTRIBUTES 0x0D
38#define SC_GET_ATT_SINGLE 0x0E
39#define SC_SET_ATT_SINGLE 0x10
40#define SC_FIND_NEXT_OBJ_INST 0x11
41#define SC_RESTOR 0x15
42#define SC_SAVE 0x16
43#define SC_NO_OP 0x17
44#define SC_GET_MEMBER 0x18
45#define SC_SET_MEMBER 0x19
46#define SC_INSERT_MEMBER 0x1A
47#define SC_REMOVE_MEMBER 0x1B
48#define SC_GROUP_SYNC 0x1C
49
50#define CIP_SC_MASK 0x7F
51#define CIP_SC_RESPONSE_MASK 0x80
52
53/* Classes that have class-specific dissectors */
54#define CI_CLS_MR 0x02 /* Message Router */
55#define CI_CLS_CM 0x06 /* Connection Manager */
56#define CI_CLS_PCCC 0x67 /* PCCC Class */
57#define CI_CLS_MOTION 0x42 /* Motion Device Axis Object */
58#define CI_CLS_MB 0x44 /* Modbus Object */
59#define CI_CLS_CCO 0xF3 /* Connection Configuration Object */
60
61/* Class specific services */
62/* Connection Manager */
63#define SC_CM_FWD_CLOSE 0x4E
64#define SC_CM_UNCON_SEND 0x52
65#define SC_CM_FWD_OPEN 0x54
66#define SC_CM_GET_CONN_DATA 0x56
67#define SC_CM_SEARCH_CONN_DATA 0x57
68#define SC_CM_GET_CONN_OWNER 0x5A
69#define SC_CM_LARGE_FWD_OPEN 0x5B
70#define SC_CM_CONCURRENT_FWD_OPEN 0x5C
71#define SC_CM_CONCURRENT_FWD_CLOSE 0x5E
72
73/* PCCC Class */
74#define SC_PCCC_EXECUTE_PCCC 0x4B
75
76/* Modbus Object services */
77#define SC_MB_READ_DISCRETE_INPUTS 0x4B
78#define SC_MB_READ_COILS 0x4C
79#define SC_MB_READ_INPUT_REGISTERS 0x4D
80#define SC_MB_READ_HOLDING_REGISTERS 0x4E
81#define SC_MB_WRITE_COILS 0x4F
82#define SC_MB_WRITE_HOLDING_REGISTERS 0x50
83#define SC_MB_PASSTHROUGH 0x51
84
85/* Connection Configuration Object services */
86#define SC_CCO_KICK_TIMER 0x4B
87#define SC_CCO_OPEN_CONN 0x4C
88#define SC_CCO_CLOSE_CONN 0x4D
89#define SC_CCO_STOP_CONN 0x4E
90#define SC_CCO_CHANGE_START 0x4F
91#define SC_CCO_GET_STATUS 0x50
92#define SC_CCO_CHANGE_COMPLETE 0x51
93#define SC_CCO_AUDIT_CHANGE 0x52
94
95/* Process Device Diagnostics Object services */
96#define SC_PDD_RESET_DIAGNOSTICS_COUNTER 0x4B
97#define SC_PDD_GET_NEXT_ACTIVE_INSTANCE 0x4C
98#define SC_PDD_GET_ACTIVE_INSTANCES 0x4D
99#define SC_PDD_GET_INSTANCES_BY_USER_DIAG_GRP 0x4E
100#define SC_PDD_GET_ACTIVE_INSTANCES_BY_STATUS_SIGNAL 0x4F
101#define SC_PDD_GET_INSTANCES_BY_COMPONENT 0x50
102
103
104/* CIP General status codes */
105#define CI_GRC_SUCCESS 0x00
106#define CI_GRC_FAILURE 0x01
107#define CI_GRC_NO_RESOURCE 0x02
108#define CI_GRC_BAD_DATA 0x03
109#define CI_GRC_BAD_PATH 0x04
110#define CI_GRC_BAD_CLASS_INSTANCE 0x05
111#define CI_GRC_PARTIAL_DATA 0x06
112#define CI_GRC_CONN_LOST 0x07
113#define CI_GRC_BAD_SERVICE 0x08
114#define CI_GRC_BAD_ATTR_DATA 0x09
115#define CI_GRC_ATTR_LIST_ERROR 0x0A
116#define CI_GRC_ALREADY_IN_MODE 0x0B
117#define CI_GRC_BAD_OBJ_MODE 0x0C
118#define CI_GRC_OBJ_ALREADY_EXISTS 0x0D
119#define CI_GRC_ATTR_NOT_SETTABLE 0x0E
120#define CI_GRC_PERMISSION_DENIED 0x0F
121#define CI_GRC_DEV_IN_WRONG_STATE 0x10
122#define CI_GRC_REPLY_DATA_TOO_LARGE 0x11
123#define CI_GRC_FRAGMENT_PRIMITIVE 0x12
124#define CI_GRC_CONFIG_TOO_SMALL 0x13
125#define CI_GRC_UNDEFINED_ATTR 0x14
126#define CI_GRC_CONFIG_TOO_BIG 0x15
127#define CI_GRC_OBJ_DOES_NOT_EXIST 0x16
128#define CI_GRC_NO_FRAGMENTATION 0x17
129#define CI_GRC_DATA_NOT_SAVED 0x18
130#define CI_GRC_DATA_WRITE_FAILURE 0x19
131#define CI_GRC_REQUEST_TOO_LARGE 0x1A
132#define CI_GRC_RESPONSE_TOO_LARGE 0x1B
133#define CI_GRC_MISSING_LIST_DATA 0x1C
134#define CI_GRC_INVALID_LIST_STATUS 0x1D
135#define CI_GRC_SERVICE_ERROR 0x1E
136#define CI_GRC_CONN_RELATED_FAILURE 0x1F
137#define CI_GRC_INVALID_PARAMETER 0x20
138#define CI_GRC_WRITE_ONCE_FAILURE 0x21
139#define CI_GRC_INVALID_REPLY 0x22
140#define CI_GRC_BUFFER_OVERFLOW 0x23
141#define CI_GRC_MESSAGE_FORMAT 0x24
142#define CI_GRC_BAD_KEY_IN_PATH 0x25
143#define CI_GRC_BAD_PATH_SIZE 0x26
144#define CI_GRC_UNEXPECTED_ATTR 0x27
145#define CI_GRC_INVALID_MEMBER 0x28
146#define CI_GRC_MEMBER_NOT_SETTABLE 0x29
147#define CI_GRC_G2_SERVER_FAILURE 0x2A
148#define CI_GRC_UNKNOWN_MB_ERROR 0x2B
149#define CI_GRC_ATTRIBUTE_NOT_GET 0x2C
150
151#define CI_GRC_STILL_PROCESSING 0xFF
152
153
154/* PCCC Status Codes */
155#define PCCC_GS_SUCCESS 0x00
156#define PCCC_GS_ILLEGAL_CMD 0x10
157#define PCCC_GS_HOST_COMMS 0x20
158#define PCCC_GS_MISSING_REMOTE_NODE 0x30
159#define PCCC_GS_HARDWARE_FAULT 0x40
160#define PCCC_GS_ADDRESSING_ERROR 0x50
161#define PCCC_GS_CMD_PROTECTION 0x60
162#define PCCC_GS_PROGRAM_MODE 0x70
163#define PCCC_GS_MISSING_COMPATIBILITY_FILE 0x80
164#define PCCC_GS_BUFFER_FULL_1 0x90
165#define PCCC_GS_WAIT_ACK 0xA0
166#define PCCC_GS_REMOTE_DOWNLOAD_ERROR 0xB0
167#define PCCC_GS_BUFFER_FULL_2 0xC0
168#define PCCC_GS_NOT_USED_1 0xD0
169#define PCCC_GS_NOT_USED_2 0xE0
170#define PCCC_GS_USE_EXTSTS 0xF0
171
172/* PCCC Extended Status Codes */
173#define PCCC_ES_ILLEGAL_VALUE 0x01
174#define PCCC_ES_SHORT_ADDRESS 0x02
175#define PCCC_ES_LONG_ADDRESS 0x03
176#define PCCC_ES_NOT_FOUND 0x04
177#define PCCC_ES_BAD_FORMAT 0x05
178#define PCCC_ES_BAD_POINTER 0x06
179#define PCCC_ES_BAD_SIZE 0x07
180#define PCCC_ES_SITUATION_CHANGED 0x08
181#define PCCC_ES_DATA_TOO_LARGE 0x09
182#define PCCC_ES_TRANS_TOO_LARGE 0x0A
183#define PCCC_ES_ACCESS_DENIED 0x0B
184#define PCCC_ES_NOT_AVAILABLE 0x0C
185#define PCCC_ES_ALREADY_EXISTS 0x0D
186#define PCCC_ES_NO_EXECUTION 0x0E
187#define PCCC_ES_HIST_OVERFLOW 0x0F
188#define PCCC_ES_NO_ACCESS 0x10
189#define PCCC_ES_ILLEGAL_DATA_TYPE 0x11
190#define PCCC_ES_INVALID_DATA 0x12
191#define PCCC_ES_BAD_REFERENCE 0x13
192#define PCCC_ES_EXECUTION_FAILURE 0x14
193#define PCCC_ES_CONVERSION_ERROR 0x15
194#define PCCC_ES_NO_COMMS 0x16
195#define PCCC_ES_TYPE_MISMATCH 0x17
196#define PCCC_ES_BAD_RESPONSE 0x18
197#define PCCC_ES_DUP_LABEL 0x19
198#define PCCC_ES_FILE_ALREADY_OPEN 0x1A
199#define PCCC_ES_PROGRAM_ALREADY_OWNED 0x1B
200#define PCCC_ES_RESERVED_1 0x1C
201#define PCCC_ES_RESERVED_2 0x1D
202#define PCCC_ES_PROTECTION_VIOLATION 0x1E
203#define PCCC_ES_TMP_INTERNAL_ERROR 0x1F
204#define PCCC_ES_RACK_FAULT 0x22
205#define PCCC_ES_TIMEOUT 0x23
206#define PCCC_ES_UNKNOWN 0x24
207
208/* PCCC Command Codes */
209#define PCCC_CMD_00 0x00
210#define PCCC_CMD_01 0x01
211#define PCCC_CMD_02 0x02
212#define PCCC_CMD_04 0x04
213#define PCCC_CMD_05 0x05
214#define PCCC_CMD_06 0x06
215#define PCCC_CMD_07 0x07
216#define PCCC_CMD_08 0x08
217#define PCCC_CMD_0F 0x0F
218
219/* PCCC Function Codes */
220#define PCCC_FNC_06_00 0x00
221#define PCCC_FNC_06_01 0x01
222#define PCCC_FNC_06_02 0x02
223#define PCCC_FNC_06_03 0x03
224#define PCCC_FNC_06_04 0x04
225#define PCCC_FNC_06_05 0x05
226#define PCCC_FNC_06_06 0x06
227#define PCCC_FNC_06_07 0x07
228#define PCCC_FNC_06_08 0x08
229#define PCCC_FNC_06_09 0x09
230#define PCCC_FNC_06_0A 0x0A
231
232#define PCCC_FNC_07_00 0x00
233#define PCCC_FNC_07_01 0x01
234#define PCCC_FNC_07_03 0x03
235#define PCCC_FNC_07_04 0x04
236#define PCCC_FNC_07_05 0x05
237#define PCCC_FNC_07_06 0x06
238
239#define PCCC_FNC_0F_00 0x00
240#define PCCC_FNC_0F_01 0x01
241#define PCCC_FNC_0F_02 0x02
242#define PCCC_FNC_0F_03 0x03
243#define PCCC_FNC_0F_04 0x04
244#define PCCC_FNC_0F_05 0x05
245#define PCCC_FNC_0F_06 0x06
246#define PCCC_FNC_0F_07 0x07
247#define PCCC_FNC_0F_08 0x08
248#define PCCC_FNC_0F_09 0x09
249#define PCCC_FNC_0F_0A 0x0A
250#define PCCC_FNC_0F_11 0x11
251#define PCCC_FNC_0F_12 0x12
252#define PCCC_FNC_0F_17 0x17
253#define PCCC_FNC_0F_18 0x18
254#define PCCC_FNC_0F_26 0x26
255#define PCCC_FNC_0F_29 0x29
256#define PCCC_FNC_0F_3A 0x3A
257#define PCCC_FNC_0F_41 0x41
258#define PCCC_FNC_0F_50 0x50
259#define PCCC_FNC_0F_52 0x52
260#define PCCC_FNC_0F_53 0x53
261#define PCCC_FNC_0F_55 0x55
262#define PCCC_FNC_0F_57 0x57
263#define PCCC_FNC_0F_5E 0x5E
264#define PCCC_FNC_0F_67 0x67
265#define PCCC_FNC_0F_68 0x68
266#define PCCC_FNC_0F_79 0x79
267#define PCCC_FNC_0F_80 0x80
268#define PCCC_FNC_0F_81 0x81
269#define PCCC_FNC_0F_82 0x82
270#define PCCC_FNC_0F_88 0x88
271#define PCCC_FNC_0F_8F 0x8F
272#define PCCC_FNC_0F_A1 0xA1
273#define PCCC_FNC_0F_A2 0xA2
274#define PCCC_FNC_0F_A3 0xA3
275#define PCCC_FNC_0F_A7 0xA7
276#define PCCC_FNC_0F_A9 0xA9
277#define PCCC_FNC_0F_AA 0xAA
278#define PCCC_FNC_0F_AB 0xAB
279#define PCCC_FNC_0F_AF 0xAF
280
281/* PCCC File Types */
282#define PCCC_FILE_TYPE_LOGIC 0x22
283#define PCCC_FILE_TYPE_FUNCTION_CS0_CS2 0x48
284#define PCCC_FILE_TYPE_CHANNEL_CONFIG 0x49
285#define PCCC_FILE_TYPE_FUNCTION_ES1 0x4A
286#define PCCC_FILE_TYPE_ONLINE_EDIT 0x65
287#define PCCC_FILE_TYPE_FUNCTION_IOS 0x6A
288#define PCCC_FILE_TYPE_DATA_OUTPUT 0x82
289#define PCCC_FILE_TYPE_DATA_INPUT 0x83
290#define PCCC_FILE_TYPE_DATA_STATUS 0x84
291#define PCCC_FILE_TYPE_DATA_BINARY 0x85
292#define PCCC_FILE_TYPE_DATA_TIMER 0x86
293#define PCCC_FILE_TYPE_DATA_COUNTER 0x87
294#define PCCC_FILE_TYPE_DATA_CONTROL 0x88
295#define PCCC_FILE_TYPE_DATA_INTEGER 0x89
296#define PCCC_FILE_TYPE_DATA_FLOAT 0x8A
297#define PCCC_FILE_TYPE_FORCE_OUTPUT 0xA1
298#define PCCC_FILE_TYPE_FORCE_INPUT 0xA2
299#define PCCC_FILE_TYPE_FUNCTION_ES0 0xE0
300#define PCCC_FILE_TYPE_FUNCTION_STI 0xE2
301#define PCCC_FILE_TYPE_FUNCTION_EII 0xE3
302#define PCCC_FILE_TYPE_FUNCTION_RTC 0xE4
303#define PCCC_FILE_TYPE_FUNCTION_BHI 0xE5
304#define PCCC_FILE_TYPE_FUNCTION_MMI 0xE6
305#define PCCC_FILE_TYPE_FUNCTION_LCD 0xEC
306#define PCCC_FILE_TYPE_FUNCTION_PTOX 0xED
307#define PCCC_FILE_TYPE_FUNCTION_PWMX 0xEE
308
309/* PCCC CPU Mode Codes */
310#define PCCC_CPU_3A_PROGRAM 0x01
311#define PCCC_CPU_3A_RUN 0x02
312
313#define PCCC_CPU_80_PROGRAM 0x01
314#define PCCC_CPU_80_RUN 0x06
315#define PCCC_CPU_80_TEST_CONT 0x07
316#define PCCC_CPU_80_TEST_SINGLE 0x08
317#define PCCC_CPU_80_TEST_DEBUG 0x09
318
319/* File Object */
320#define FILE_SAVE_PARAM_SAVE_METHOD_MASK 0x0F
321#define FILE_SAVE_PARAM_SAVE_STATUS_MASK 0x10
322#define FILE_SAVE_PARAM_RESERVED_MASK 0xE0
323
324/* IOI Path types */
325#define CI_SEGMENT_TYPE_MASK 0xE0
326
327#define CI_PORT_SEGMENT 0x00
328#define CI_LOGICAL_SEGMENT 0x20
329#define CI_NETWORK_SEGMENT 0x40
330#define CI_SYMBOLIC_SEGMENT 0x60
331#define CI_DATA_SEGMENT 0x80
332
333#define CI_PORT_SEG_EX_LINK_ADDRESS 0x10
334#define CI_PORT_SEG_PORT_ID_MASK 0x0F
335
336#define CI_LOGICAL_SEG_TYPE_MASK 0x1C
337#define CI_LOGICAL_SEG_CLASS_ID 0x00
338#define CI_LOGICAL_SEG_INST_ID 0x04
339#define CI_LOGICAL_SEG_MBR_ID 0x08
340#define CI_LOGICAL_SEG_CON_POINT 0x0C
341#define CI_LOGICAL_SEG_ATTR_ID 0x10
342#define CI_LOGICAL_SEG_SPECIAL 0x14
343#define CI_LOGICAL_SEG_SERV_ID 0x18
344#define CI_LOGICAL_SEG_EXT_LOGICAL 0x1C
345
346#define CI_LOGICAL_SEG_FORMAT_MASK 0x03
347#define CI_LOGICAL_SEG_8_BIT 0x00
348#define CI_LOGICAL_SEG_16_BIT 0x01
349#define CI_LOGICAL_SEG_32_BIT 0x02
350#define CI_LOGICAL_SEG_RES_2 0x03
351#define CI_LOGICAL_SEG_E_KEY 0x00
352
353#define CI_E_KEY_FORMAT_VAL 0x04
354#define CI_E_SERIAL_NUMBER_KEY_FORMAT_VAL 0x05
355
356#define CI_DATA_SEG_TYPE_MASK 0x1F
357#define CI_DATA_SEG_SIMPLE 0x00
358#define CI_DATA_SEG_SYMBOL 0x11
359
360#define CI_NETWORK_SEG_TYPE_MASK 0x1F
361#define CI_NETWORK_SEG_SCHEDULE 0x01
362#define CI_NETWORK_SEG_FIXED_TAG 0x02
363#define CI_NETWORK_SEG_PROD_INHI 0x03
364#define CI_NETWORK_SEG_SAFETY 0x10
365#define CI_NETWORK_SEG_PROD_INHI_US 0x11
366#define CI_NETWORK_SEG_EXTENDED 0x1F
367
368#define CI_CONCURRENT_EXTENDED_NETWORK_SEG 0x02
369
370#define CI_SYMBOL_SEG_FORMAT_MASK 0xE0
371#define CI_SYMBOL_SEG_SIZE_MASK 0x1F
372#define CI_SYMBOL_SEG_DOUBLE 0x20
373#define CI_SYMBOL_SEG_TRIPLE 0x40
374#define CI_SYMBOL_SEG_NUMERIC 0xC0
375
376#define CI_SYMBOL_NUMERIC_USINT 6
377#define CI_SYMBOL_NUMERIC_UINT 7
378#define CI_SYMBOL_NUMERIC_UDINT 8
379
380#define CI_TRANSPORT_CLASS_MASK 0x0F
381#define CI_PRODUCTION_TRIGGER_MASK 0x70
382#define CI_PRODUCTION_DIR_MASK 0x80
383
384#define CONN_TYPE_NULL 0
385#define CONN_TYPE_MULTICAST 1
386#define CONN_TYPE_P2P 2
387#define CONN_TYPE_RESERVED 3
388
389#define ENIP_CIP_INTERFACE 0
390
391#define CC_CRC_LENGTH 4
392
393/* Define common services */
394#define GENERIC_SC_LIST \
395 { SC_GET_ATT_ALL, "Get Attributes All" }, \
396 { SC_SET_ATT_ALL, "Set Attributes All" }, \
397 { SC_GET_ATT_LIST, "Get Attribute List" }, \
398 { SC_SET_ATT_LIST, "Set Attribute List" }, \
399 { SC_RESET, "Reset" }, \
400 { SC_START, "Start" }, \
401 { SC_STOP, "Stop" }, \
402 { SC_CREATE, "Create" }, \
403 { SC_DELETE, "Delete" }, \
404 { SC_MULT_SERV_PACK, "Multiple Service Packet" }, \
405 { SC_APPLY_ATTRIBUTES, "Apply Attributes" }, \
406 { SC_GET_ATT_SINGLE, "Get Attribute Single" }, \
407 { SC_SET_ATT_SINGLE, "Set Attribute Single" }, \
408 { SC_FIND_NEXT_OBJ_INST, "Find Next Object Instance" }, \
409 { SC_RESTOR, "Restore" }, \
410 { SC_SAVE, "Save" }, \
411 { SC_NO_OP, "Nop" }, \
412 { SC_GET_MEMBER, "Get Member" }, \
413 { SC_SET_MEMBER, "Set Member" }, \
414 { SC_INSERT_MEMBER, "Insert Member" }, \
415 { SC_REMOVE_MEMBER, "Remove Member" }, \
416 { SC_GROUP_SYNC, "Group Sync" }, \
417
418#define SEGMENT_VALUE_NOT_SET ((uint32_t)-1)
420 // First Class ID
421 uint32_t iClassA;
422 // Last Class ID
423 uint32_t iClass;
424
425 // First Instance ID
426 uint32_t iInstanceA;
427 // Last Instance ID
428 uint32_t iInstance;
429
430 uint32_t iAttribute;
431 uint32_t iMember;
432
433 // First Connection Point
434 uint32_t iConnPointA;
435 // Last Connection Point. The 2nd (last) Connection Point defines the Motion I/O Format.
436 uint32_t iConnPoint;
437
438 bool hasSimpleData;
439 bool hasSymbolData;
440
441 bool hasEkey;
442 uint16_t deviceType;
443 uint16_t productCode;
445
446enum cip_datatype {
447 cip_bool,
448 cip_sint,
449 cip_int,
450 cip_dint,
451 cip_lint,
452 cip_usint,
453 cip_usint_array,
454 cip_uint,
455 cip_uint_array,
456 cip_udint,
457 cip_ulint,
458 cip_real,
459 cip_lreal,
460 cip_stime,
461 cip_utime,
462 cip_itime,
463 cip_time,
464 cip_ftime,
465 cip_ltime,
466 cip_ntime,
467 cip_short_string,
468 cip_string,
469 cip_string2,
470 cip_stringi,
471 cip_byte,
472 cip_byte_array,
473 cip_word,
474 cip_dword,
475 cip_lword,
476 cip_date,
477 cip_time_of_day,
478 cip_date_and_time,
479 cip_dissector_func,
480 cip_engunit,
481 cip_stringN,
482};
483
484typedef int attribute_dissector_func(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
485 int offset, int total_len);
486
487#define CIP_ATTR_CLASS (true)
488#define CIP_ATTR_INSTANCE (false)
489typedef struct attribute_info {
490 unsigned class_id;
491 bool class_instance;
492 unsigned attribute;
493 int gaa_index; /* Index of attribute in GetAttributeAll response (< 0 means not in GetAttributeAll */
494 const char *text;
495 enum cip_datatype datatype;
496 int* phf;
497 attribute_dissector_func *pdissect;
499
500// offset - starts at command specific data.
501// returns - size of data that was parsed.
502typedef int service_dissector_func(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
503 int offset, bool request);
504typedef struct cip_service_info {
505 uint32_t class_id;
506 uint8_t service_id;
507 const char *service_name;
508 service_dissector_func *pdissect;
510
511// This describes a one-way connection. Each CIP Connection includes 2 of these.
512#define CIP_CONNECTION_SIZE_TYPE_FIXED (0)
513typedef struct cip_connID_info {
514 // Connection ID from Forward Open Request. This may get updated in the Forward Open Response.
515 uint32_t connID;
516
517 // From Common Packet Format, Sockaddr Info Item.
518 address ipaddress;
519 uint16_t port;
520
521 // Network Connection Parameters
522 uint32_t type; // See: cip_con_type_vals
523 uint32_t connection_size;
524 uint32_t connection_size_type; // 0 = Fixed, 1 = Variable
525
526 // Requested Packet Interval in microseconds.
527 uint32_t rpi;
528
529 // Actual Packet Interval in microseconds.
530 uint32_t api;
531
532 // These are used to track the previous timestamps for each direction. These are only used during a first pass calculation.
533 nstime_t timestamp;
535
536enum cip_safety_format_type {CIP_SAFETY_BASE_FORMAT, CIP_SAFETY_EXTENDED_FORMAT};
537enum cip_safety_open_type {CIP_SAFETY_OPEN_UNKNOWN, CIP_SAFETY_OPEN_TYPE1, CIP_SAFETY_OPEN_TYPE2A, CIP_SAFETY_OPEN_TYPE2B};
538enum cip_safety_originator_type {CIP_SAFETY_ORIGINATOR_UNKNOWN, CIP_SAFETY_ORIGINATOR_CONSUMER, CIP_SAFETY_ORIGINATOR_PRODUCER};
539
540typedef struct cip_connection_triad {
541 uint16_t ConnSerialNumber;
542 uint16_t VendorID;
543 uint32_t DeviceSerialNumber;
545
546typedef struct cip_safety_epath_info {
547 bool safety_seg;
548
549 enum cip_safety_format_type format;
550 enum cip_safety_open_type safety_open_type;
551
552 enum cip_safety_originator_type originator_type;
553
554 // These 3x variables are only used during a first pass calculation.
555 uint16_t running_rollover_value; /* Keep track of the rollover value over the course of the connection */
556 uint16_t running_timestamp_value; /* Keep track of the timestamp value over the course of the connection */
557 bool seen_non_zero_timestamp; /* True if we have seen a non-zero timestamp on this connection */
558
559 // The Target CIP Connection Triad from the Forward Open Response, Safety Application Reply Data.
560 cip_connection_triad_t target_triad;
561
562 // Network Time Expectation, in milliseconds.
563 float nte_value_ms;
565
566// Information for a given CIP Connection, for both directions (O->T and T->O)
567typedef struct cip_conn_info {
568 // Forward Open Data
570 uint8_t TransportClass_trigger;
571 uint32_t timeout_multiplier;
573 uint32_t FwdOpenPathLenBytes;
574 void* pFwdOpenPathData;
575 cip_simple_request_info_t connection_path;
576
577 // Information about specific packet numbers.
578 uint32_t open_req_frame;
579 uint32_t open_reply_frame;
580 uint32_t close_frame;
581
582 // Information about each direction of the overall connection.
585
586 // Unique ID generated that links together the CIP Connections.
587 // - If the full connection information is available (eg: FwdOpen found), then it will link both
588 // connections (one for each direction)
589 uint32_t connid;
590
591 bool is_concurrent_connection;
592
593 // True if this is a Null Forward Open. In this case, a new connection is not created.
594 bool IsNullFwdOpen;
596
597typedef struct cip_req_info {
598 dissector_handle_t dissector;
599
600 // This is the CIP Service Code. It does not include the Response bit.
601 uint8_t bService;
602
603 // Number of 16-bit words in pIOI.
604 unsigned IOILen;
605 void *pIOI;
606
607 unsigned RouteConnectionPathLen;
608 void *pRouteConnectionPath;
609
610 void *pData;
612 cip_conn_info_t* connInfo;
614
615/*
616** Exported functions
617*/
618
619/* Depending on if a Class or Symbol segment appears in Connection Path or
620 a Request Path, display '-' before or after the actual name. */
621#define NO_DISPLAY 0
622#define DISPLAY_CONNECTION_PATH 1
623#define DISPLAY_REQUEST_PATH 2
624extern void dissect_epath( tvbuff_t *tvb, packet_info *pinfo, proto_tree *path_tree, proto_item *epath_item, int offset, int path_length,
625 bool generate, bool packed, cip_simple_request_info_t* req_data, cip_safety_epath_info_t* safety,
626 int display_type, proto_item *msp_item,
627 bool is_msp_item);
628
629// Elementary Data Types.
630enum cip_elem_data_types {
631 CIP_STRING_TYPE = 0xD0,
632 CIP_STRING2_TYPE = 0xD5,
633 CIP_STRINGN_TYPE = 0xD9,
634 CIP_SHORT_STRING_TYPE = 0xDA
635};
636
637extern void add_cip_service_to_info_column(packet_info *pinfo, uint8_t service, const value_string* service_vals);
638extern const attribute_info_t * cip_get_attribute(unsigned class_id, unsigned instance, unsigned attribute);
639extern cip_service_info_t* cip_get_service_one_table(cip_service_info_t* services, size_t size, uint32_t class_id, uint8_t service_id);
640extern void cip_rpi_api_fmt(char *s, uint32_t value);
641
642extern int dissect_cip_attribute(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb, const attribute_info_t* attr, int offset, int total_len);
643extern void dissect_cip_data(proto_tree *item_tree, tvbuff_t *tvb, int offset, packet_info *pinfo, cip_req_info_t *preq_info, proto_item* msp_item, bool is_msp_item);
644extern void dissect_cip_date_and_time(proto_tree *tree, tvbuff_t *tvb, int offset, int hf_datetime);
645extern int dissect_cip_utime(proto_tree* tree, tvbuff_t* tvb, int offset, int hf_datetime);
646extern int dissect_cip_generic_service_rsp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);
647extern int dissect_cip_get_attribute_list_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item * item,
648 int offset, cip_simple_request_info_t* req_data);
649extern int dissect_cip_multiple_service_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item * item, int offset, bool request);
650extern int dissect_cip_response_status(proto_tree* tree, tvbuff_t* tvb, int offset, int hf_general_status, bool have_additional_status);
651extern void dissect_cip_run_idle(tvbuff_t* tvb, int offset, proto_tree* item_tree);
652extern int dissect_cip_segment_single(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tree *path_tree, proto_item *epath_item,
653 bool generate, bool packed, cip_simple_request_info_t* req_data, cip_safety_epath_info_t* safety,
654 int display_type, proto_item *msp_item,
655 bool is_msp_item);
656extern int dissect_cip_string_type(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb, int offset, int hf_type, int string_type);
657extern int dissect_cip_get_attribute_all_rsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
658 int offset, cip_simple_request_info_t* req_data);
659extern int dissect_cip_set_attribute_list_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item * item,
660 int offset, cip_simple_request_info_t* req_data);
661extern int dissect_cip_set_attribute_list_rsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item * item,
662 int offset, cip_simple_request_info_t* req_data);
663extern void dissect_deviceid(tvbuff_t *tvb, int offset, proto_tree *tree,
664 int hf_vendor, int hf_devtype, int hf_prodcode,
665 int hf_compatibility, int hf_comp_bit, int hf_majrev, int hf_minrev,
666 bool generate, unsigned encoding);
667extern int dissect_electronic_key_format(tvbuff_t* tvb, int offset, proto_tree* tree, bool generate, uint8_t key_format, unsigned encoding);
668extern int dissect_optional_attr_list(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
669 int offset, int total_len);
670extern int dissect_optional_service_list(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
671 int offset, int total_len);
672extern int dissect_padded_epath_len_usint(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
673 int offset, int total_len);
674extern int dissect_padded_epath_len_uint(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb,
675 int offset, int total_len);
676
677extern int dissect_cip_id_status(packet_info* pinfo, proto_tree* tree, proto_item* item, tvbuff_t* tvb,
678 int offset, int total_len);
679
680extern void load_cip_request_data(packet_info *pinfo, cip_simple_request_info_t *req_data);
681extern void reset_cip_request_info(cip_simple_request_info_t* req_data);
682extern bool should_dissect_cip_response(tvbuff_t *tvb, int offset, uint8_t gen_status);
683extern bool cip_connection_triad_match(const cip_connection_triad_t* left, const cip_connection_triad_t* right);
684extern int dissect_concurrent_connection_packet(packet_info* pinfo, tvbuff_t* tvb, int offset, proto_tree* tree);
685extern int dissect_concurrent_connection_network_segment(packet_info* pinfo, tvbuff_t* tvb, int offset, proto_tree* tree);
686
687/*
688** Exported variables
689*/
690extern const value_string cip_sc_rr[];
691extern const value_string cip_reset_type_vals[];
692extern const value_string cip_con_prio_vals[];
693extern const value_string cip_con_type_vals[];
694extern const value_string cip_con_time_mult_vals[];
695extern const value_string cip_class_names_vals[];
696extern const value_string cip_port_number_vals[];
697extern const value_string cip_id_state_vals[];
698extern const value_string cip_con_fw_vals[];
699extern value_string_ext cip_gs_vals_ext;
700extern value_string_ext cip_cm_ext_st_vals_ext;
701extern value_string_ext cip_vendor_vals_ext;
702extern value_string_ext cip_devtype_vals_ext;
703extern value_string_ext cip_class_names_vals_ext;
704
705/* Common class attributes and attribute dissection functions*/
706extern int hf_attr_class_revision;
707extern int hf_attr_class_max_instance;
708extern int hf_attr_class_num_instance;
709extern int hf_attr_class_opt_attr_num;
710extern int hf_attr_class_attr_num;
711extern int hf_attr_class_opt_service_num;
712extern int hf_attr_class_service_code;
713extern int hf_attr_class_num_class_attr;
714extern int hf_attr_class_num_inst_attr;
715extern int hf_cip_instance16;
716
717#define CLASS_ATTRIBUTE_1_NAME "Revision"
718#define CLASS_ATTRIBUTE_2_NAME "Max Instance"
719#define CLASS_ATTRIBUTE_3_NAME "Number of Instances"
720#define CLASS_ATTRIBUTE_4_NAME "Optional Attribute List"
721#define CLASS_ATTRIBUTE_5_NAME "Optional Service List"
722#define CLASS_ATTRIBUTE_6_NAME "Maximum ID Number Class Attributes"
723#define CLASS_ATTRIBUTE_7_NAME "Maximum ID Number Instance Attributes"
724
725/*
726 * Editor modelines
727 *
728 * Local Variables:
729 * c-basic-offset: 3
730 * tab-width: 8
731 * indent-tabs-mode: nil
732 * End:
733 *
734 * ex: set shiftwidth=3 tabstop=8 expandtab:
735 * :indentSize=3:tabSize=8:noTabs=true:
736 */
737
738#endif /* PACKET_CIP_H */
Holds a network or link-layer address of any supported type.
Definition address.h:62
Represents the metadata and indexing information for a single captured frame.
Definition packet_info.h:43
Definition proto.h:909
Extended metadata for a value_string array.
Definition value_string.h:325
Mapping between a 32-bit integer value and its string representation.
Definition value_string.h:33
Definition packet-cip.h:489
Definition packet-cip.h:567
Definition packet-cip.h:513
Definition packet-cip.h:540
Definition packet-cip.h:597
Definition packet-cip.h:546
Definition packet-cip.h:504
Definition packet-cip.h:419
Definition packet-epl-profile-parser.c:79
Definition packet.c:852
Definition nstime.h:26
Core tvbuff (testy virtual buffer) structure representing a region of packet data,...
Definition tvbuff-int.h:95