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