2 * Routines for pn-rt (PROFINET Real-Time) packet dissection.
3 * This is the base for other PROFINET protocols like IO, CBA, DCP, ...
4 * (the "content subdissectors" will register themselves using a heuristic)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1999 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/reassemble.h>
17 #include <epan/prefs.h>
18 #include <epan/etypes.h>
19 #include <epan/expert.h>
20 #include <epan/crc16-tvb.h>
22 #include <wsutil/array.h>
23 #include <epan/dissectors/packet-dcerpc.h>
25 #include <wsutil/crc16-plain.h>
26 #include "packet-pn.h"
29 void proto_register_pn_rt(void);
30 void proto_reg_handoff_pn_rt(void);
32 #define PROFINET_UDP_PORT 0x8892
34 /* Define the pn-rt proto */
35 static int proto_pn_rt
;
36 static bool pnio_desegment
= true;
38 static dissector_handle_t pn_rt_handle
;
40 /* Define many header fields for pn-rt */
41 static int hf_pn_rt_frame_id
;
42 static int hf_pn_rt_cycle_counter
;
43 static int hf_pn_rt_transfer_status
;
44 static int hf_pn_rt_data_status
;
45 static int hf_pn_rt_data_status_ignore
;
46 static int hf_pn_rt_frame_info_type
;
47 static int hf_pn_rt_frame_info_function_meaning_input_conv
;
48 static int hf_pn_rt_frame_info_function_meaning_output_conv
;
49 static int hf_pn_rt_data_status_Reserved_2
;
50 static int hf_pn_rt_data_status_ok
;
51 static int hf_pn_rt_data_status_operate
;
52 static int hf_pn_rt_data_status_res3
;
53 static int hf_pn_rt_data_status_valid
;
54 static int hf_pn_rt_data_status_redundancy
;
55 static int hf_pn_rt_data_status_redundancy_output_cr
;
56 static int hf_pn_rt_data_status_redundancy_input_cr_state_is_backup
;
57 static int hf_pn_rt_data_status_redundancy_input_cr_state_is_primary
;
58 static int hf_pn_rt_data_status_primary
;
60 static int hf_pn_rt_sf_crc16
;
61 static int hf_pn_rt_sf_crc16_status
;
62 static int hf_pn_rt_sf
;
63 static int hf_pn_rt_sf_position
;
64 /* static int hf_pn_rt_sf_position_control; */
65 static int hf_pn_rt_sf_data_length
;
66 static int hf_pn_rt_sf_cycle_counter
;
68 static int hf_pn_rt_frag
;
69 static int hf_pn_rt_frag_data_length
;
70 static int hf_pn_rt_frag_status
;
71 static int hf_pn_rt_frag_status_more_follows
;
72 static int hf_pn_rt_frag_status_error
;
73 static int hf_pn_rt_frag_status_fragment_number
;
74 static int hf_pn_rt_frag_data
;
78 * Define the trees for pn-rt
79 * We need one tree for pn-rt itself and one for the pn-rt data status subtree
82 static int ett_pn_rt_data_status
;
83 static int ett_pn_rt_sf
;
84 static int ett_pn_rt_frag
;
85 static int ett_pn_rt_frag_status
;
87 static expert_field ei_pn_rt_sf_crc16
;
90 * Here are the global variables associated with
91 * the various user definable characteristics of the dissection
93 /* Place summary in proto tree */
94 static bool pn_rt_summary_in_tree
= true;
96 /* heuristic to find the right pn-rt payload dissector */
97 static heur_dissector_list_t heur_subdissector_list
;
101 static const value_string pn_rt_position_control
[] = {
102 { 0x00, "CRC16 and CycleCounter shall not be checked" },
103 { 0x80, "CRC16 and CycleCounter valid" },
108 static const true_false_string tfs_pn_rt_ds_redundancy_output_cr
=
109 { "Unknown", "Redundancy has no meaning for OutputCRs, it is set to the fixed value of zero" };
111 static const true_false_string tfs_pn_rt_ds_redundancy_input_cr_state_is_backup
=
112 { "None primary AR of a given AR-set is present", "Default - One primary AR of a given AR-set is present" };
114 static const true_false_string tfs_pn_rt_ds_redundancy_input_cr_state_is_primary
=
115 { "The ARState from the IO device point of view is Backup", "Default - The ARState from the IO device point of view is Primary" };
117 static const value_string pn_rt_frame_info_function_meaning_input_conv
[] = {
118 {0x00, "Backup Acknowledge without actual data" },
119 {0x02, "Primary Missing without actual data" },
120 {0x04, "Backup Acknowledge with actual data independent from the Arstate" },
121 {0x05, "Primary Acknowledge"},
122 {0x06, "Primary Missing with actual data independent from the Arstate" },
123 {0x07, "Primary Fault" },
127 static const value_string pn_rt_frame_info_function_meaning_output_conv
[] = {
128 { 0x04, "Backup Request" },
129 { 0x05, "Primary Request" },
133 static const true_false_string tfs_pn_rt_ds_redundancy
=
134 { "None primary AR of a given AR-set is present", "Redundancy has no meaning for OutputCRs / One primary AR of a given AR-set is present" };
136 static const value_string pn_rt_frag_status_error
[] = {
137 { 0x00, "reserved" },
138 { 0x01, "reserved: invalid should be zero" },
142 static const value_string pn_rt_frag_status_more_follows
[] = {
143 { 0x00, "Last fragment" },
144 { 0x01, "More fragments follow" },
148 /* Copied and renamed from proto.c because global value_strings don't work for plugins */
149 static const value_string plugin_proto_checksum_vals
[] = {
150 { PROTO_CHECKSUM_E_BAD
, "Bad" },
151 { PROTO_CHECKSUM_E_GOOD
, "Good" },
152 { PROTO_CHECKSUM_E_UNVERIFIED
, "Unverified" },
153 { PROTO_CHECKSUM_E_NOT_PRESENT
, "Not present" },
159 dissect_DataStatus(tvbuff_t
*tvb
, int offset
, proto_tree
*tree
, packet_info
*pinfo
, uint8_t u8DataStatus
)
161 proto_item
*sub_item
;
162 proto_tree
*sub_tree
;
164 uint8_t u8Redundancy
;
166 conversation_t
*conversation
;
167 bool inputFlag
= false;
168 bool outputFlag
= false;
169 apduStatusSwitch
*apdu_status_switch
;
171 u8State
= (u8DataStatus
& 0x01);
172 u8Redundancy
= (u8DataStatus
>> 1) & 0x01;
173 u8DataValid
= (u8DataStatus
>> 2) & 0x01;
175 /* if PN Connect Request has been read, IOC mac is dl_src and IOD mac is dl_dst */
176 conversation
= find_conversation(pinfo
->num
, &pinfo
->dl_src
, &pinfo
->dl_dst
, CONVERSATION_UDP
, 0, 0, 0);
178 if (conversation
!= NULL
) {
179 apdu_status_switch
= (apduStatusSwitch
*)conversation_get_proto_data(conversation
, proto_pn_io_apdu_status
);
180 if (apdu_status_switch
!= NULL
&& apdu_status_switch
->isRedundancyActive
) {
181 /* IOC -> IOD: OutputCR */
182 if (addresses_equal(&(pinfo
->dst
), conversation_key_addr1(conversation
->key_ptr
)) && addresses_equal(&(pinfo
->src
), conversation_key_addr2(conversation
->key_ptr
))) {
186 /* IOD -> IOC: InputCR */
187 if (addresses_equal(&(pinfo
->src
), conversation_key_addr1(conversation
->key_ptr
)) && addresses_equal(&(pinfo
->dst
), conversation_key_addr2(conversation
->key_ptr
))) {
194 /* input conversation is found */
197 proto_tree_add_string_format_value(tree
, hf_pn_rt_frame_info_type
, tvb
,
198 offset
, 0, "Input", "Input Frame (IO_Device -> IO_Controller)");
200 /* output conversation is found. */
203 proto_tree_add_string_format_value(tree
, hf_pn_rt_frame_info_type
, tvb
,
204 offset
, 0, "Output", "Output Frame (IO_Controller -> IO_Device)");
207 sub_item
= proto_tree_add_uint_format(tree
, hf_pn_rt_data_status
,
208 tvb
, offset
, 1, u8DataStatus
,
209 "DataStatus: 0x%02x (Frame: %s and %s, Provider: %s and %s)",
211 (u8DataStatus
& 0x04) ? "Valid" : "Invalid",
212 (u8DataStatus
& 0x01) ? "Primary" : "Backup",
213 (u8DataStatus
& 0x20) ? "Ok" : "Problem",
214 (u8DataStatus
& 0x10) ? "Run" : "Stop");
215 sub_tree
= proto_item_add_subtree(sub_item
, ett_pn_rt_data_status
);
216 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_ignore
, tvb
, offset
, 1, u8DataStatus
);
217 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_Reserved_2
, tvb
, offset
, 1, u8DataStatus
);
218 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_ok
, tvb
, offset
, 1, u8DataStatus
);
219 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_operate
, tvb
, offset
, 1, u8DataStatus
);
220 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_res3
, tvb
, offset
, 1, u8DataStatus
);
221 /* input conversation is found */
224 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_valid
, tvb
, offset
, 1, u8DataStatus
);
225 proto_tree_add_uint(tree
, hf_pn_rt_frame_info_function_meaning_input_conv
, tvb
, offset
, 1, u8DataStatus
);
226 if (u8State
== 0 && u8Redundancy
== 0 && u8DataValid
== 1)
228 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_input_cr_state_is_backup
, tvb
, offset
, 1, u8DataStatus
);
230 else if (u8State
== 0 && u8Redundancy
== 0 && u8DataValid
== 0)
232 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_input_cr_state_is_backup
, tvb
, offset
, 1, u8DataStatus
);
234 else if (u8State
== 0 && u8Redundancy
== 1 && u8DataValid
== 1)
236 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_input_cr_state_is_backup
, tvb
, offset
, 1, u8DataStatus
);
238 else if (u8State
== 0 && u8Redundancy
== 1 && u8DataValid
== 0)
240 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_input_cr_state_is_backup
, tvb
, offset
, 1, u8DataStatus
);
242 else if (u8State
== 1 && u8Redundancy
== 0 && u8DataValid
== 1)
244 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_input_cr_state_is_primary
, tvb
, offset
, 1, u8DataStatus
);
246 else if (u8State
== 1 && u8Redundancy
== 1 && u8DataValid
== 1)
248 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_input_cr_state_is_primary
, tvb
, offset
, 1, u8DataStatus
);
251 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_primary
, tvb
, offset
, 1, u8DataStatus
);
254 // output conversation is found.
257 proto_tree_add_uint(tree
, hf_pn_rt_frame_info_function_meaning_output_conv
, tvb
, offset
, 1, u8DataStatus
);
259 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_valid
, tvb
, offset
, 1, u8DataStatus
);
260 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy_output_cr
, tvb
, offset
, 1, u8DataStatus
);
261 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_primary
, tvb
, offset
, 1, u8DataStatus
);
266 // If no conversation is found
267 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_valid
, tvb
, offset
, 1, u8DataStatus
);
268 proto_tree_add_boolean(sub_tree
, hf_pn_rt_data_status_redundancy
, tvb
, offset
, 1, u8DataStatus
);
269 proto_tree_add_uint(sub_tree
, hf_pn_rt_data_status_primary
, tvb
, offset
, 1, u8DataStatus
);
274 IsDFP_Frame(tvbuff_t
*tvb
, packet_info
*pinfo
, uint16_t u16FrameID
)
277 uint8_t u8SFPosition
;
278 uint8_t u8SFDataLength
= 255;
280 uint32_t u32SubStart
;
283 unsigned char virtualFramebuffer
[16];
285 /* try to build a temporary buffer for generating this CRC */
286 if (!pinfo
->src
.data
|| !pinfo
->dst
.data
||
287 pinfo
->dst
.type
!= AT_ETHER
|| pinfo
->src
.type
!= AT_ETHER
) {
288 /* if we don't have src/dst mac addresses then we assume it's not
289 * to avoid various crashes */
292 memcpy(&virtualFramebuffer
[0], pinfo
->dst
.data
, 6);
293 memcpy(&virtualFramebuffer
[6], pinfo
->src
.data
, 6);
294 virtualFramebuffer
[12] = 0x88;
295 virtualFramebuffer
[13] = 0x92;
296 virtualFramebuffer
[15] = (unsigned char) (u16FrameID
&0xff);
297 virtualFramebuffer
[14] = (unsigned char) (u16FrameID
>>8);
298 crc
= crc16_plain_init();
299 crc
= crc16_plain_update(crc
, &virtualFramebuffer
[0], 16);
300 crc
= crc16_plain_finalize(crc
);
301 /* can check this CRC only by having built a temporary data buffer out of the pinfo data */
302 u16SFCRC16
= tvb_get_letohs(tvb
, offset
);
303 if (u16SFCRC16
!= 0) /* no crc! */
305 if (u16SFCRC16
!= crc
)
310 /* end of first CRC check */
312 offset
+= 2; /*Skip first crc */
313 tvb_len
= tvb_captured_length(tvb
);
314 if (offset
+ 4 > tvb_len
)
316 if (tvb_get_letohs(tvb
, offset
) == 0)
317 return false; /* no valid DFP frame */
319 u32SubStart
= offset
;
321 u8SFPosition
= tvb_get_uint8(tvb
, offset
);
324 u8SFDataLength
= tvb_get_uint8(tvb
, offset
);
327 if (u8SFDataLength
== 0) {
333 offset
+= u8SFDataLength
;
334 if (offset
> tvb_len
)
335 return /*true; */false;
337 u16SFCRC16
= tvb_get_letohs(tvb
, offset
);
338 if (u16SFCRC16
!= 0) {
339 if (u8SFPosition
& 0x80) {
340 crc
= crc16_plain_tvb_offset_seed(tvb
, u32SubStart
, offset
-u32SubStart
, 0);
341 if (crc
!= u16SFCRC16
) {
353 /* possibly dissect a CSF_SDU related PN-RT packet */
355 dissect_CSF_SDU_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
357 /* the sub tvb will NOT contain the frame_id here! */
358 uint16_t u16FrameID
= GPOINTER_TO_UINT(data
);
360 uint8_t u8SFPosition
;
361 uint8_t u8SFDataLength
= 255;
362 uint8_t u8SFCycleCounter
;
363 uint8_t u8SFDataStatus
;
365 uint32_t u32SubStart
;
366 proto_item
*sub_item
;
367 proto_tree
*sub_tree
;
371 /* possible FrameID ranges for DFP */
372 if ((u16FrameID
< 0x0100) || (u16FrameID
> 0x3FFF))
374 if (IsDFP_Frame(tvb
, pinfo
, u16FrameID
)) {
375 /* can't check this CRC, as the checked data bytes are not available */
376 u16SFCRC16
= tvb_get_letohs(tvb
, offset
);
377 if (u16SFCRC16
!= 0) {
378 /* Checksum verify will always succeed */
379 /* XXX - should we combine the two calls to always show "unverified"? */
380 proto_tree_add_checksum(tree
, tvb
, offset
, hf_pn_rt_sf_crc16
, hf_pn_rt_sf_crc16_status
, &ei_pn_rt_sf_crc16
, pinfo
, u16SFCRC16
,
381 ENC_LITTLE_ENDIAN
, PROTO_CHECKSUM_VERIFY
);
384 proto_tree_add_checksum(tree
, tvb
, offset
, hf_pn_rt_sf_crc16
, hf_pn_rt_sf_crc16_status
, &ei_pn_rt_sf_crc16
, pinfo
, 0,
385 ENC_LITTLE_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
390 sub_item
= proto_tree_add_item(tree
, hf_pn_rt_sf
, tvb
, offset
, 0, ENC_NA
);
391 sub_tree
= proto_item_add_subtree(sub_item
, ett_pn_rt_sf
);
392 u32SubStart
= offset
;
394 u8SFPosition
= tvb_get_uint8(tvb
, offset
);
395 proto_tree_add_uint(sub_tree
, hf_pn_rt_sf_position
, tvb
, offset
, 1, u8SFPosition
);
398 u8SFDataLength
= tvb_get_uint8(tvb
, offset
);
399 proto_tree_add_uint(sub_tree
, hf_pn_rt_sf_data_length
, tvb
, offset
, 1, u8SFDataLength
);
402 if (u8SFDataLength
== 0) {
403 proto_item_append_text(sub_item
, ": Pos:%u, Length:%u", u8SFPosition
, u8SFDataLength
);
404 proto_item_set_len(sub_item
, offset
- u32SubStart
);
408 u8SFCycleCounter
= tvb_get_uint8(tvb
, offset
);
409 proto_tree_add_uint(sub_tree
, hf_pn_rt_sf_cycle_counter
, tvb
, offset
, 1, u8SFCycleCounter
);
412 u8SFDataStatus
= tvb_get_uint8(tvb
, offset
);
413 dissect_DataStatus(tvb
, offset
, sub_tree
, pinfo
, u8SFDataStatus
);
416 offset
= dissect_pn_user_data(tvb
, offset
, pinfo
, sub_tree
, u8SFDataLength
, "DataItem");
418 u16SFCRC16
= tvb_get_letohs(tvb
, offset
);
420 if (u16SFCRC16
!= 0 /* "old check": u8SFPosition & 0x80 */) {
421 crc
= crc16_plain_tvb_offset_seed(tvb
, u32SubStart
, offset
-u32SubStart
, 0);
422 proto_tree_add_checksum(tree
, tvb
, offset
, hf_pn_rt_sf_crc16
, hf_pn_rt_sf_crc16_status
, &ei_pn_rt_sf_crc16
, pinfo
, crc
,
423 ENC_LITTLE_ENDIAN
, PROTO_CHECKSUM_VERIFY
);
425 proto_tree_add_checksum(tree
, tvb
, offset
, hf_pn_rt_sf_crc16
, hf_pn_rt_sf_crc16_status
, &ei_pn_rt_sf_crc16
, pinfo
, 0,
426 ENC_LITTLE_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
430 proto_item_append_text(sub_item
, ": Pos:%u, Length:%u, Cycle:%u, Status: 0x%02x (%s,%s,%s,%s)",
431 u8SFPosition
, u8SFDataLength
, u8SFCycleCounter
, u8SFDataStatus
,
432 (u8SFDataStatus
& 0x04) ? "Valid" : "Invalid",
433 (u8SFDataStatus
& 0x01) ? "Primary" : "Backup",
434 (u8SFDataStatus
& 0x20) ? "Ok" : "Problem",
435 (u8SFDataStatus
& 0x10) ? "Run" : "Stop");
437 proto_item_set_len(sub_item
, offset
- u32SubStart
);
444 dissect_pn_user_data(tvb
, offset
, pinfo
, tree
, tvb_captured_length_remaining(tvb
, offset
),
445 "PROFINET IO Cyclic Service Data Unit");
452 /* for reassemble processing we need some inits.. */
453 /* Register PNIO defrag table init routine. */
455 static reassembly_table pdu_reassembly_table
;
456 static GHashTable
*reassembled_frag_table
;
458 static dissector_table_t ethertype_subdissector_table
;
460 static uint32_t start_frag_OR_ID
[16];
464 pnio_defragment_init(void)
467 for (i
=0; i
< 16; i
++) /* init the reassemble help array */
468 start_frag_OR_ID
[i
] = 0;
469 reassembled_frag_table
= g_hash_table_new(NULL
, NULL
);
473 pnio_defragment_cleanup(void)
475 g_hash_table_destroy(reassembled_frag_table
);
478 /* possibly dissect a FRAG_PDU related PN-RT packet */
480 dissect_FRAG_PDU_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
482 /* the sub tvb will NOT contain the frame_id here! */
483 uint16_t u16FrameID
= GPOINTER_TO_UINT(data
);
487 /* possible FrameID ranges for FRAG_PDU */
488 if (u16FrameID
>= 0xFF80 && u16FrameID
<= 0xFF8F) {
489 proto_item
*sub_item
;
490 proto_tree
*sub_tree
;
491 proto_item
*status_item
;
492 proto_tree
*status_tree
;
493 uint8_t u8FragDataLength
;
494 uint8_t u8FragStatus
;
498 sub_item
= proto_tree_add_item(tree
, hf_pn_rt_frag
, tvb
, offset
, 0, ENC_NA
);
499 sub_tree
= proto_item_add_subtree(sub_item
, ett_pn_rt_frag
);
501 u8FragDataLength
= tvb_get_uint8(tvb
, offset
);
502 proto_tree_add_uint(sub_tree
, hf_pn_rt_frag_data_length
, tvb
, offset
, 1, u8FragDataLength
);
505 status_item
= proto_tree_add_item(sub_tree
, hf_pn_rt_frag_status
, tvb
, offset
, 1, ENC_NA
);
506 status_tree
= proto_item_add_subtree(status_item
, ett_pn_rt_frag_status
);
508 u8FragStatus
= tvb_get_uint8(tvb
, offset
);
509 proto_tree_add_uint(status_tree
, hf_pn_rt_frag_status_more_follows
, tvb
, offset
, 1, u8FragStatus
);
510 proto_tree_add_uint(status_tree
, hf_pn_rt_frag_status_error
, tvb
, offset
, 1, u8FragStatus
);
511 proto_tree_add_uint(status_tree
, hf_pn_rt_frag_status_fragment_number
, tvb
, offset
, 1, u8FragStatus
);
513 uFragNumber
= u8FragStatus
& 0x3F; /* bits 0 to 5 */
514 bMoreFollows
= (u8FragStatus
& 0x80) != 0;
515 proto_item_append_text(status_item
, ": Number: %u, %s",
517 val_to_str_const( (u8FragStatus
& 0x80) >> 7, pn_rt_frag_status_more_follows
, "Unknown"));
519 /* Is this a string or a bunch of bytes? Should it be FT_BYTES? */
520 proto_tree_add_string_format(sub_tree
, hf_pn_rt_frag_data
, tvb
, offset
, tvb_captured_length_remaining(tvb
, offset
), "data",
521 "Fragment Length: %d bytes", tvb_captured_length_remaining(tvb
, offset
));
522 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " Fragment Length: %d bytes", tvb_captured_length_remaining(tvb
, offset
));
524 dissect_pn_user_data_bytes(tvb
, offset
, pinfo
, sub_tree
, tvb_captured_length_remaining(tvb
, offset
), FRAG_DATA
);
525 if ((unsigned)tvb_captured_length_remaining(tvb
, offset
) < (unsigned)(u8FragDataLength
*8)) {
526 proto_item_append_text(status_item
, ": FragDataLength out of Framerange -> discarding!");
529 /* defragmentation starts here */
533 uint32_t u32ReasembleID
/*= 0xfedc ??*/;
534 fragment_head
*pdu_frag
;
536 u32FragID
= (u16FrameID
& 0xf);
537 if (uFragNumber
== 0)
538 { /* this is the first "new" fragment, so set up a new key Id */
539 uint32_t u32FrameKey
;
540 u32FrameKey
= (pinfo
->num
<< 2) | u32FragID
;
541 /* store it in the array */
542 start_frag_OR_ID
[u32FragID
] = u32FrameKey
;
544 u32ReasembleID
= start_frag_OR_ID
[u32FragID
];
545 /* use frame data instead of "pnio fraglen" which sets 8 octet steps */
546 pdu_frag
= fragment_add_seq(&pdu_reassembly_table
, tvb
, offset
,
547 pinfo
, u32ReasembleID
, NULL
, uFragNumber
,
548 (tvb_captured_length_remaining(tvb
, offset
))/*u8FragDataLength*8*/, bMoreFollows
, 0);
550 if (pdu_frag
&& !bMoreFollows
) /* PDU is complete! and last fragment */
551 { /* store this fragment as the completed fragment in hash table */
552 g_hash_table_insert(reassembled_frag_table
, GUINT_TO_POINTER(pinfo
->num
), pdu_frag
);
553 start_frag_OR_ID
[u32FragID
] = 0; /* reset the starting frame counter */
555 if (!bMoreFollows
) /* last fragment */
557 pdu_frag
= (fragment_head
*)g_hash_table_lookup(reassembled_frag_table
, GUINT_TO_POINTER(pinfo
->num
));
558 if (pdu_frag
) /* found a matching fragment; dissect it */
563 /* create the new tvb for defragmented frame */
564 pdu_tvb
= tvb_new_chain(tvb
, pdu_frag
->tvb_data
);
565 /* add the defragmented data to the data source list */
566 add_new_data_source(pinfo
, pdu_tvb
, "Reassembled Profinet Frame");
567 /* PDU is complete: look for the Ethertype and give it to the appropriate dissection routine */
568 type
= tvb_get_ntohs(pdu_tvb
, 0);
569 pdu_tvb
= tvb_new_subset_remaining(pdu_tvb
, 2);
570 if (!dissector_try_uint(ethertype_subdissector_table
, type
, pdu_tvb
, pinfo
, tree
))
571 call_data_dissector(pdu_tvb
, pinfo
, tree
);
584 * dissect_pn_rt - The dissector for the Soft-Real-Time protocol
587 dissect_pn_rt(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
592 uint8_t u8DataStatus
;
593 uint8_t u8TransferStatus
;
594 uint16_t u16CycleCounter
;
595 const char *pszProtAddInfo
;
596 const char *pszProtShort
;
597 const char *pszProtSummary
;
598 const char *pszProtComment
;
599 proto_tree
*pn_rt_tree
, *ti
;
600 char szFieldSummary
[100];
603 heur_dtbl_entry_t
*hdtbl_entry
;
604 conversation_t
* conversation
;
605 uint8_t isTimeAware
= false;
607 /* If the link-layer dissector for the protocol above us knows whether
608 * the packet, as handed to it, includes a link-layer FCS, what it
609 * hands to us should not include the FCS; if that's not the case,
610 * that's a bug in that dissector, and should be fixed there.
612 * If the link-layer dissector for the protocol above us doesn't know
613 * whether the packet, as handed to us, includes a link-layer FCS,
614 * there are limits as to what can be done there; the dissector
615 * ultimately needs a "yes, it has an FCS" preference setting, which
616 * both the Ethernet and 802.11 dissectors do. If that's not the case
617 * for a dissector, that's a deficiency in that dissector, and should
620 * Therefore, we assume we are not handed a packet that includes an
621 * FCS. If we are ever handed such a packet, either the link-layer
622 * dissector needs to be fixed or the link-layer dissector's preference
623 * needs to be set for your capture (even if that means adding such
624 * a preference). This dissector (and other dissectors for protcols
625 * running atop the link layer) should not attempt to process the
626 * FCS themselves, as that will just break things. */
628 /* Initialize variables */
633 * Set the columns now, so that they'll be set correctly if we throw
634 * an exception. We can set them (or append things) later again ....
637 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "PN-RT");
638 col_set_str(pinfo
->cinfo
, COL_INFO
, "PROFINET Real-Time");
640 pdu_len
= tvb_reported_length(tvb
);
642 dissect_pn_malformed(tvb
, 0, pinfo
, tree
, pdu_len
);
646 /* TimeAwareness Information needed for differentiating RTC3 - RTSteam frames */
647 conversation
= find_conversation(pinfo
->num
, &pinfo
->dl_src
, &pinfo
->dl_dst
, CONVERSATION_NONE
, 0, 0, 0);
649 if (conversation
!= NULL
) {
650 isTimeAware
= GPOINTER_TO_UINT(conversation_get_proto_data(conversation
, proto_pn_io_time_aware_status
));
653 /* build some "raw" data */
654 u16FrameID
= tvb_get_ntohs(tvb
, 0);
655 if (u16FrameID
<= 0x001F) {
656 pszProtShort
= "PN-RT";
657 pszProtAddInfo
= "reserved, ";
658 pszProtSummary
= "Real-Time";
659 pszProtComment
= "0x0000-0x001F: Reserved ID";
661 } else if (u16FrameID
<= 0x0021) {
662 pszProtShort
= "PN-PTCP";
663 pszProtAddInfo
= "Synchronization, ";
664 pszProtSummary
= "Real-Time";
665 pszProtComment
= "0x0020-0x0021: Real-Time: Sync (with follow up)";
667 } else if (u16FrameID
<= 0x007F) {
668 pszProtShort
= "PN-RT";
669 pszProtAddInfo
= "reserved, ";
670 pszProtSummary
= "Real-Time";
671 pszProtComment
= "0x0022-0x007F: Reserved ID";
673 } else if (u16FrameID
<= 0x0081) {
674 pszProtShort
= "PN-PTCP";
675 pszProtAddInfo
= "Synchronization, ";
676 pszProtSummary
= "Isochronous-Real-Time";
677 pszProtComment
= "0x0080-0x0081: Real-Time: Sync (without follow up)";
679 } else if (u16FrameID
<= 0x00FF) {
680 pszProtShort
= "PN-RT";
681 pszProtAddInfo
= "reserved, ";
682 pszProtSummary
= "Real-Time";
683 pszProtComment
= "0x0082-0x00FF: Reserved ID";
685 } else if (u16FrameID
<= 0x6FF && !isTimeAware
) {
686 pszProtShort
= "PN-RTC3";
687 pszProtAddInfo
= "RTC3, ";
688 pszProtSummary
= "Isochronous-Real-Time";
689 pszProtComment
= "0x0100-0x06FF: RED: Real-Time(class=3): non redundant, normal or DFP";
691 } else if (u16FrameID
<= 0x0FFF && !isTimeAware
) {
692 pszProtShort
= "PN-RTC3";
693 pszProtAddInfo
= "RTC3, ";
694 pszProtSummary
= "Isochronous-Real-Time";
695 pszProtComment
= "0x0700-0x0FFF: RED: Real-Time(class=3): redundant, normal or DFP";
697 } else if (u16FrameID
<= 0x7FFF && !isTimeAware
) {
698 pszProtShort
= "PN-RT";
699 pszProtAddInfo
= "reserved, ";
700 pszProtSummary
= "Real-Time";
701 pszProtComment
= "0x1000-0x7FFF: Reserved ID";
703 } else if (u16FrameID
<= 0x0FFF && isTimeAware
) {
704 pszProtShort
= "PN-RT";
705 pszProtAddInfo
= "reserved, ";
706 pszProtSummary
= "Real-Time";
707 pszProtComment
= "0x0100-0x0FFF: Reserved ID";
709 } else if (u16FrameID
<= 0x2FFF && isTimeAware
) {
710 pszProtShort
= "PN-RTCS";
711 pszProtAddInfo
= "RT_STREAM, ";
712 pszProtSummary
= "Real-Time";
713 pszProtComment
= "0x1000-0x2FFF: RT_CLASS_STREAM";
715 } else if (u16FrameID
<= 0x37FF && isTimeAware
) {
716 pszProtShort
= "PN-RT";
717 pszProtAddInfo
= "reserved, ";
718 pszProtSummary
= "Real-Time";
719 pszProtComment
= "0x3000-0x37FF: Reserved ID";
721 } else if (u16FrameID
<= 0x3FFF && isTimeAware
) {
722 pszProtShort
= "PN-RTCS";
723 pszProtAddInfo
= "RT_STREAM, ";
724 pszProtSummary
= "Real-Time";
725 pszProtComment
= "0x3800-0x3FFF: RT_CLASS_STREAM";
727 } else if (u16FrameID
<= 0xBBFF) {
728 pszProtShort
= "PN-RTC1";
729 pszProtAddInfo
= "RTC1, ";
730 pszProtSummary
= "cyclic Real-Time";
731 pszProtComment
= "0x8000-0xBBFF: Real-Time(class=1 unicast): non redundant, normal";
733 } else if (u16FrameID
<= 0xBFFF) {
734 pszProtShort
= "PN-RTC1";
735 pszProtAddInfo
= "RTC1, ";
736 pszProtSummary
= "cyclic Real-Time";
737 pszProtComment
= "0xBC00-0xBFFF: Real-Time(class=1 multicast): non redundant, normal";
739 } else if (u16FrameID
<= 0xF7FF) {
740 /* check if udp frame on PNIO port */
741 if (pinfo
->destport
== 0x8892)
743 pszProtShort
= "PN-RTCUDP,";
744 pszProtAddInfo
= "RT_CLASS_UDP, ";
745 pszProtComment
= "0xC000-0xF7FF: Real-Time(UDP unicast): Cyclic";
748 { /* layer 2 frame */
749 pszProtShort
= "PN-RT";
750 pszProtAddInfo
= "RTC1(legacy), ";
751 pszProtComment
= "0xC000-0xF7FF: Real-Time(class=1 unicast): Cyclic";
753 pszProtSummary
= "cyclic Real-Time";
755 } else if (u16FrameID
<= 0xFBFF) {
756 if (pinfo
->destport
== 0x8892)
758 pszProtShort
= "PN-RTCUDP,";
759 pszProtAddInfo
= "RT_CLASS_UDP, ";
760 pszProtComment
= "0xF800-0xFBFF:: Real-Time(UDP multicast): Cyclic";
763 { /* layer 2 frame */
764 pszProtShort
= "PN-RT";
765 pszProtAddInfo
= "RTC1(legacy), ";
766 pszProtComment
= "0xF800-0xFBFF: Real-Time(class=1 multicast): Cyclic";
768 pszProtSummary
= "cyclic Real-Time";
770 } else if (u16FrameID
<= 0xFDFF) {
771 pszProtShort
= "PN-RTA";
772 pszProtAddInfo
= "Reserved, ";
773 pszProtSummary
= "acyclic Real-Time";
774 pszProtComment
= "0xFC00-0xFDFF: Reserved";
776 if (u16FrameID
== 0xfc01) {
777 pszProtShort
= "PN-RTA";
778 pszProtAddInfo
= "Alarm High, ";
779 pszProtSummary
= "acyclic Real-Time";
780 pszProtComment
= "Real-Time: Acyclic PN-IO Alarm high priority";
783 } else if (u16FrameID
<= 0xFEFF) {
784 pszProtShort
= "PN-RTA";
785 pszProtAddInfo
= "Reserved, ";
786 pszProtSummary
= "acyclic Real-Time";
787 pszProtComment
= "0xFE00-0xFEFF: Real-Time: Reserved";
789 if (u16FrameID
== 0xFE01) {
790 pszProtShort
= "PN-RTA";
791 pszProtAddInfo
= "Alarm Low, ";
792 pszProtSummary
= "acyclic Real-Time";
793 pszProtComment
= "Real-Time: Acyclic PN-IO Alarm low priority";
795 if (u16FrameID
== 0xFE02) {
796 pszProtShort
= "PN-RSI";
798 pszProtSummary
= "acyclic Real-Time";
799 pszProtComment
= "Real-Time: Acyclic PN-IO RSI";
801 if (u16FrameID
== FRAME_ID_DCP_HELLO
) {
802 pszProtShort
= "PN-RTA";
804 pszProtSummary
= "acyclic Real-Time";
805 pszProtComment
= "Real-Time: DCP (Dynamic Configuration Protocol) hello";
807 if (u16FrameID
== FRAME_ID_DCP_GETORSET
) {
808 pszProtShort
= "PN-RTA";
810 pszProtSummary
= "acyclic Real-Time";
811 pszProtComment
= "Real-Time: DCP (Dynamic Configuration Protocol) get/set";
813 if (u16FrameID
== FRAME_ID_DCP_IDENT_REQ
) {
814 pszProtShort
= "PN-RTA";
816 pszProtSummary
= "acyclic Real-Time";
817 pszProtComment
= "Real-Time: DCP (Dynamic Configuration Protocol) identify multicast request";
819 if (u16FrameID
== FRAME_ID_DCP_IDENT_RES
) {
820 pszProtShort
= "PN-RTA";
822 pszProtSummary
= "acyclic Real-Time";
823 pszProtComment
= "Real-Time: DCP (Dynamic Configuration Protocol) identify response";
825 } else if (u16FrameID
<= 0xFF01) {
826 pszProtShort
= "PN-PTCP";
827 pszProtAddInfo
= "RTA Sync, ";
828 pszProtSummary
= "acyclic Real-Time";
829 pszProtComment
= "0xFF00-0xFF01: PTCP Announce";
831 } else if (u16FrameID
<= 0xFF1F) {
832 pszProtShort
= "PN-PTCP";
833 pszProtAddInfo
= "RTA Sync, ";
834 pszProtSummary
= "acyclic Real-Time";
835 pszProtComment
= "0xFF02-0xFF1F: Reserved";
837 } else if (u16FrameID
<= 0xFF21) {
838 pszProtShort
= "PN-PTCP";
839 pszProtAddInfo
= "Follow Up, ";
840 pszProtSummary
= "acyclic Real-Time";
841 pszProtComment
= "0xFF20-0xFF21: PTCP Follow Up";
843 } else if (u16FrameID
<= 0xFF22) {
844 pszProtShort
= "PN-PTCP";
845 pszProtAddInfo
= "Follow Up, ";
846 pszProtSummary
= "acyclic Real-Time";
847 pszProtComment
= "0xFF22-0xFF3F: Reserved";
849 } else if (u16FrameID
<= 0xFF43) {
850 pszProtShort
= "PN-PTCP";
851 pszProtAddInfo
= "Delay, ";
852 pszProtSummary
= "acyclic Real-Time";
853 pszProtComment
= "0xFF40-0xFF43: Acyclic Real-Time: Delay";
855 } else if (u16FrameID
<= 0xFF7F) {
856 pszProtShort
= "PN-RT";
857 pszProtAddInfo
= "Reserved, ";
858 pszProtSummary
= "Real-Time";
859 pszProtComment
= "0xFF44-0xFF7F: reserved ID";
861 } else if (u16FrameID
<= 0xFF8F) {
862 pszProtShort
= "PN-RT";
864 pszProtSummary
= "Fragmentation";
865 pszProtComment
= "0xFF80-0xFF8F: Fragmentation";
868 pszProtShort
= "PN-RT";
869 pszProtAddInfo
= "Reserved, ";
870 pszProtSummary
= "Real-Time";
871 pszProtComment
= "0xFF90-0xFFFF: reserved ID";
875 /* decode optional cyclic fields at the packet end and build the summary line */
877 /* cyclic transfer has cycle counter, data status and transfer status fields at the end */
878 u16CycleCounter
= tvb_get_ntohs(tvb
, pdu_len
- 4);
879 u8DataStatus
= tvb_get_uint8(tvb
, pdu_len
- 2);
880 u8TransferStatus
= tvb_get_uint8(tvb
, pdu_len
- 1);
882 snprintf (szFieldSummary
, sizeof(szFieldSummary
),
883 "%sID:0x%04x, Len:%4u, Cycle:%5u (%s,%s,%s,%s)",
884 pszProtAddInfo
, u16FrameID
, pdu_len
- 2 - 4, u16CycleCounter
,
885 (u8DataStatus
& 0x04) ? "Valid" : "Invalid",
886 (u8DataStatus
& 0x01) ? "Primary" : "Backup",
887 (u8DataStatus
& 0x20) ? "Ok" : "Problem",
888 (u8DataStatus
& 0x10) ? "Run" : "Stop");
890 /* user data length is packet len - frame id - optional cyclic status fields */
891 data_len
= pdu_len
- 2 - 4;
893 /* satisfy the gcc compiler, so it won't throw an "uninitialized" warning */
896 u8TransferStatus
= 0;
898 /* acyclic transfer has no fields at the end */
899 snprintf (szFieldSummary
, sizeof(szFieldSummary
),
900 "%sID:0x%04x, Len:%4u",
901 pszProtAddInfo
, u16FrameID
, pdu_len
- 2);
903 /* user data length is packet len - frame id field */
904 data_len
= pdu_len
- 2;
907 /* build protocol tree only, if tree is really used */
909 /* build pn_rt protocol tree with summary line */
910 if (pn_rt_summary_in_tree
) {
911 ti
= proto_tree_add_protocol_format(tree
, proto_pn_rt
, tvb
, 0, pdu_len
,
912 "PROFINET %s, %s", pszProtSummary
, szFieldSummary
);
914 ti
= proto_tree_add_item(tree
, proto_pn_rt
, tvb
, 0, pdu_len
, ENC_NA
);
916 pn_rt_tree
= proto_item_add_subtree(ti
, ett_pn_rt
);
919 proto_tree_add_uint_format(pn_rt_tree
, hf_pn_rt_frame_id
, tvb
,
920 0, 2, u16FrameID
, "FrameID: 0x%04x (%s)", u16FrameID
, pszProtComment
);
923 /* add cycle counter */
924 proto_tree_add_uint_format(pn_rt_tree
, hf_pn_rt_cycle_counter
, tvb
,
925 pdu_len
- 4, 2, u16CycleCounter
, "CycleCounter: %u", u16CycleCounter
);
927 /* add data status subtree */
928 dissect_DataStatus(tvb
, pdu_len
- 2, pn_rt_tree
, pinfo
, u8DataStatus
);
930 /* add transfer status */
931 if (u8TransferStatus
) {
932 proto_tree_add_uint_format(pn_rt_tree
, hf_pn_rt_transfer_status
, tvb
,
933 pdu_len
- 1, 1, u8TransferStatus
,
934 "TransferStatus: 0x%02x (ignore this frame)", u8TransferStatus
);
936 proto_tree_add_uint_format(pn_rt_tree
, hf_pn_rt_transfer_status
, tvb
,
937 pdu_len
- 1, 1, u8TransferStatus
,
938 "TransferStatus: 0x%02x (OK)", u8TransferStatus
);
943 /* update column info now */
944 if (u16FrameID
== 0xFE02)
946 snprintf(szFieldSummary
, sizeof(szFieldSummary
), "%s", "");
948 col_add_str(pinfo
->cinfo
, COL_INFO
, szFieldSummary
);
949 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, pszProtShort
);
951 /* get frame user data tvb (without header and footer) */
952 next_tvb
= tvb_new_subset_length(tvb
, 2, data_len
);
954 /* ask heuristics, if some sub-dissector is interested in this packet payload */
955 if (!dissector_try_heuristic(heur_subdissector_list
, next_tvb
, pinfo
, tree
, &hdtbl_entry
, GUINT_TO_POINTER( (uint32_t) u16FrameID
))) {
956 /*col_set_str(pinfo->cinfo, COL_INFO, "Unknown");*/
958 /* Oh, well, we don't know this; dissect it as data. */
959 dissect_pn_undecoded(next_tvb
, 0, pinfo
, tree
, tvb_captured_length(next_tvb
));
961 return tvb_captured_length(tvb
);
965 /* Register all the bits needed by the filtering engine */
967 proto_register_pn_rt(void)
969 static hf_register_info hf
[] = {
970 { &hf_pn_rt_frame_id
,
971 { "FrameID", "pn_rt.frame_id",
972 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
975 { &hf_pn_rt_cycle_counter
,
976 { "CycleCounter", "pn_rt.cycle_counter",
977 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
980 { &hf_pn_rt_data_status
,
981 { "DataStatus", "pn_rt.ds",
982 FT_UINT8
, BASE_HEX
, 0, 0x0,
985 { &hf_pn_rt_data_status_ignore
,
986 { "Ignore (1:Ignore/0:Evaluate)", "pn_rt.ds_ignore", FT_UINT8
, BASE_HEX
, 0, 0x80,
989 { &hf_pn_rt_frame_info_type
,
990 { "PN Frame Type", "pn_rt.ds_frame_info_type", FT_STRING
, BASE_NONE
, NULL
, 0x0,
993 { &hf_pn_rt_frame_info_function_meaning_input_conv
,
994 { "Function/Meaning", "pn_rt.ds_frame_info_meaning",
995 FT_UINT8
, BASE_HEX
, VALS(pn_rt_frame_info_function_meaning_input_conv
), 0x7,
998 { &hf_pn_rt_frame_info_function_meaning_output_conv
,
999 { "Function/Meaning", "pn_rt.ds_frame_info_meaning",
1000 FT_UINT8
, BASE_HEX
, VALS(pn_rt_frame_info_function_meaning_output_conv
), 0x7,
1003 { &hf_pn_rt_data_status_Reserved_2
,
1004 { "Reserved_2 (should be zero)", "pn_rt.ds_Reserved_2",
1005 FT_UINT8
, BASE_HEX
, 0, 0x40,
1008 { &hf_pn_rt_data_status_ok
,
1009 { "StationProblemIndicator (1:Ok/0:Problem)", "pn_rt.ds_ok",
1010 FT_UINT8
, BASE_HEX
, 0, 0x20,
1013 { &hf_pn_rt_data_status_operate
,
1014 { "ProviderState (1:Run/0:Stop)", "pn_rt.ds_operate",
1015 FT_UINT8
, BASE_HEX
, 0, 0x10,
1018 { &hf_pn_rt_data_status_res3
,
1019 { "Reserved_3 (should be zero)", "pn_rt.ds_res3",
1020 FT_UINT8
, BASE_HEX
, 0, 0x08,
1023 { &hf_pn_rt_data_status_valid
,
1024 { "DataValid (1:Valid/0:Invalid)", "pn_rt.ds_valid",
1025 FT_UINT8
, BASE_HEX
, 0, 0x04,
1028 { &hf_pn_rt_data_status_redundancy
,
1029 { "Redundancy", "pn_rt.ds_redundancy",
1030 FT_BOOLEAN
, 8, TFS(&tfs_pn_rt_ds_redundancy
), 0x02,
1033 { &hf_pn_rt_data_status_redundancy_output_cr
,
1034 { "Redundancy", "pn_rt.ds_redundancy",
1035 FT_BOOLEAN
, 8, TFS(&tfs_pn_rt_ds_redundancy_output_cr
), 0x02,
1038 { &hf_pn_rt_data_status_redundancy_input_cr_state_is_backup
,
1039 { "Redundancy", "pn_rt.ds_redundancy",
1040 FT_BOOLEAN
, 8, TFS(&tfs_pn_rt_ds_redundancy_input_cr_state_is_backup
), 0x02,
1043 { &hf_pn_rt_data_status_redundancy_input_cr_state_is_primary
,
1044 { "Redundancy", "pn_rt.ds_redundancy",
1045 FT_BOOLEAN
, 8, TFS(&tfs_pn_rt_ds_redundancy_input_cr_state_is_primary
), 0x02,
1048 { &hf_pn_rt_data_status_primary
,
1049 { "State (1:Primary/0:Backup)", "pn_rt.ds_primary",
1050 FT_UINT8
, BASE_HEX
, 0, 0x01,
1053 { &hf_pn_rt_transfer_status
,
1054 { "TransferStatus", "pn_rt.transfer_status",
1055 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1059 { "SubFrame", "pn_rt.sf",
1060 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1063 { &hf_pn_rt_sf_crc16
,
1064 { "SFCRC16", "pn_rt.sf.crc16",
1065 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1068 { &hf_pn_rt_sf_crc16_status
,
1069 { "SFCRC16 status", "pn_rt.sf.crc16.status",
1070 FT_UINT8
, BASE_NONE
, VALS(plugin_proto_checksum_vals
), 0x0,
1073 { &hf_pn_rt_sf_position
,
1074 { "Position", "pn_rt.sf.position",
1075 FT_UINT8
, BASE_DEC
, NULL
, 0x7F,
1079 { &hf_pn_rt_sf_position_control
,
1080 { "Control", "pn_rt.sf.position_control",
1081 FT_UINT8
, BASE_DEC
, VALS(pn_rt_position_control
), 0x80,
1085 { &hf_pn_rt_sf_data_length
,
1086 { "DataLength", "pn_rt.sf.data_length",
1087 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1090 { &hf_pn_rt_sf_cycle_counter
,
1091 { "CycleCounter", "pn_rt.sf.cycle_counter",
1092 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1096 { "PROFINET Fragment", "pn_rt.frag",
1097 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1100 { &hf_pn_rt_frag_data_length
,
1101 { "FragDataLength", "pn_rt.frag_data_length",
1102 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1105 { &hf_pn_rt_frag_status
,
1106 { "FragStatus", "pn_rt.frag_status",
1107 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1110 { &hf_pn_rt_frag_status_more_follows
,
1111 { "MoreFollows", "pn_rt.frag_status.more_follows",
1112 FT_UINT8
, BASE_HEX
, VALS(pn_rt_frag_status_more_follows
), 0x80,
1115 { &hf_pn_rt_frag_status_error
,
1116 { "Reserved", "pn_rt.frag_status.error",
1117 FT_UINT8
, BASE_HEX
, VALS(pn_rt_frag_status_error
), 0x40,
1120 { &hf_pn_rt_frag_status_fragment_number
,
1121 { "FragmentNumber (zero based)", "pn_rt.frag_status.fragment_number",
1122 FT_UINT8
, BASE_DEC
, NULL
, 0x3F,
1125 /* Is this a string or a bunch of bytes? Should it be FT_BYTES? */
1126 { &hf_pn_rt_frag_data
,
1127 { "FragData", "pn_rt.frag_data",
1128 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1132 static int *ett
[] = {
1134 &ett_pn_rt_data_status
,
1137 &ett_pn_rt_frag_status
1140 static ei_register_info ei
[] = {
1141 { &ei_pn_rt_sf_crc16
, { "pn_rt.sf.crc16_bad", PI_CHECKSUM
, PI_ERROR
, "Bad checksum", EXPFILL
}},
1144 module_t
*pn_rt_module
;
1145 expert_module_t
* expert_pn_rt
;
1147 proto_pn_rt
= proto_register_protocol("PROFINET Real-Time Protocol",
1149 pn_rt_handle
= register_dissector("pn_rt", dissect_pn_rt
, proto_pn_rt
);
1151 proto_register_field_array(proto_pn_rt
, hf
, array_length(hf
));
1152 proto_register_subtree_array(ett
, array_length(ett
));
1153 expert_pn_rt
= expert_register_protocol(proto_pn_rt
);
1154 expert_register_field_array(expert_pn_rt
, ei
, array_length(ei
));
1156 /* Register our configuration options */
1158 pn_rt_module
= prefs_register_protocol(proto_pn_rt
, NULL
);
1160 prefs_register_bool_preference(pn_rt_module
, "summary_in_tree",
1161 "Show PN-RT summary in protocol tree",
1162 "Whether the PN-RT summary line should be shown in the protocol tree",
1163 &pn_rt_summary_in_tree
);
1165 prefs_register_bool_preference(pn_rt_module
, "desegment",
1166 "reassemble PNIO Fragments",
1167 "Reassemble PNIO Fragments and get them decoded",
1170 /* register heuristics anchor for payload dissectors */
1171 heur_subdissector_list
= register_heur_dissector_list_with_description("pn_rt", "PROFINET RT payload", proto_pn_rt
);
1173 init_pn (proto_pn_rt
);
1174 register_init_routine(pnio_defragment_init
);
1175 register_cleanup_routine(pnio_defragment_cleanup
);
1176 reassembly_table_register(&pdu_reassembly_table
,
1177 &addresses_reassembly_table_functions
);
1181 /* The registration hand-off routine is called at startup */
1183 proto_reg_handoff_pn_rt(void)
1185 dissector_add_uint("ethertype", ETHERTYPE_PROFINET
, pn_rt_handle
);
1186 dissector_add_uint_with_preference("udp.port", PROFINET_UDP_PORT
, pn_rt_handle
);
1188 heur_dissector_add("pn_rt", dissect_CSF_SDU_heur
, "PROFINET CSF_SDU IO", "pn_csf_sdu_pn_rt", proto_pn_rt
, HEURISTIC_ENABLE
);
1189 heur_dissector_add("pn_rt", dissect_FRAG_PDU_heur
, "PROFINET Frag PDU IO", "pn_frag_pn_rt", proto_pn_rt
, HEURISTIC_ENABLE
);
1191 ethertype_subdissector_table
= find_dissector_table("ethertype");
1196 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1201 * indent-tabs-mode: nil
1204 * vi: set shiftwidth=4 tabstop=8 expandtab:
1205 * :indentSize=4:tabSize=8:noTabs=true: