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)
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1999 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
33 #ifdef HAVE_NETINET_IN_H
34 #include <netinet/in.h>
37 #include <epan/packet.h>
38 #include <epan/reassemble.h>
39 #include <epan/addr_resolv.h>
40 #include <epan/prefs.h>
41 #include <epan/strutil.h>
42 #include <epan/etypes.h>
43 #include <epan/expert.h>
44 #include <epan/dissectors/packet-dcerpc.h>
45 #include <epan/crc16-tvb.h>
47 #include <wsutil/crc16.h>
48 #include <wsutil/crc16-plain.h>
49 #include "packet-pn.h"
51 /* Define the pn-rt proto */
52 static int proto_pn_rt = -1;
53 static gboolean pnio_desegment = TRUE;
55 /* Define many header fields for pn-rt */
56 static int hf_pn_rt_frame_id = -1;
57 static int hf_pn_rt_cycle_counter = -1;
58 static int hf_pn_rt_transfer_status = -1;
59 static int hf_pn_rt_data_status = -1;
60 static int hf_pn_rt_data_status_ignore = -1;
61 static int hf_pn_rt_data_status_Reserved_2 = -1;
62 static int hf_pn_rt_data_status_ok = -1;
63 static int hf_pn_rt_data_status_operate = -1;
64 static int hf_pn_rt_data_status_res3 = -1;
65 static int hf_pn_rt_data_status_valid = -1;
66 static int hf_pn_rt_data_status_redundancy = -1;
67 static int hf_pn_rt_data_status_primary = -1;
69 static int hf_pn_rt_sf_crc16 = -1;
70 static int hf_pn_rt_sf_crc16_ok = -1;
71 static int hf_pn_rt_sf_crc16_null = -1;
72 static int hf_pn_rt_sf = -1;
73 static int hf_pn_rt_sf_position = -1;
74 /* static int hf_pn_rt_sf_position_control = -1; */
75 static int hf_pn_rt_sf_data_length = -1;
76 static int hf_pn_rt_sf_cycle_counter = -1;
78 static int hf_pn_rt_frag = -1;
79 static int hf_pn_rt_frag_data_length = -1;
80 static int hf_pn_rt_frag_status = -1;
81 static int hf_pn_rt_frag_status_more_follows = -1;
82 static int hf_pn_rt_frag_status_error = -1;
83 static int hf_pn_rt_frag_status_fragment_number = -1;
84 static int hf_pn_rt_frag_data = -1;
88 * Define the trees for pn-rt
89 * We need one tree for pn-rt itself and one for the pn-rt data status subtree
91 static int ett_pn_rt = -1;
92 static int ett_pn_rt_data_status = -1;
93 static int ett_pn_rt_sf = -1;
94 static int ett_pn_rt_frag = -1;
95 static int ett_pn_rt_frag_status = -1;
98 * Here are the global variables associated with
99 * the various user definable characteristics of the dissection
101 /* Place summary in proto tree */
102 static gboolean pn_rt_summary_in_tree = TRUE;
104 /* heuristic to find the right pn-rt payload dissector */
105 static heur_dissector_list_t heur_subdissector_list;
108 static const value_string pn_rt_position_control[] = {
109 { 0x00, "CRC16 and CycleCounter shall not be checked" },
110 { 0x80, "CRC16 and CycleCounter valid" },
113 static const value_string pn_rt_ds_redundancy[] = {
114 { 0x00, "One primary AR of a given AR-set is present" },
115 { 0x01, "None primary AR of a given AR-set is present" },
119 static const value_string pn_rt_frag_status_error[] = {
120 { 0x00, "reserved" },
121 { 0x01, "reserved: invalid should be zero" },
125 static const value_string pn_rt_frag_status_more_follows[] = {
126 { 0x00, "Last fragment" },
127 { 0x01, "More fragments follow" },
132 dissect_DataStatus(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 u8DataStatus)
134 proto_item *sub_item;
135 proto_tree *sub_tree;
137 sub_item = proto_tree_add_uint_format(tree, hf_pn_rt_data_status,
138 tvb, offset, 1, u8DataStatus,
139 "DataStatus: 0x%02x (Frame: %s and %s, Provider: %s and %s)",
141 (u8DataStatus & 0x04) ? "Valid" : "Invalid",
142 (u8DataStatus & 0x01) ? "Primary" : "Backup",
143 (u8DataStatus & 0x20) ? "Ok" : "Problem",
144 (u8DataStatus & 0x10) ? "Run" : "Stop");
145 sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_data_status);
146 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ignore, tvb, offset, 1, u8DataStatus);
147 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_Reserved_2, tvb, offset, 1, u8DataStatus);
148 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ok, tvb, offset, 1, u8DataStatus);
149 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_operate, tvb, offset, 1, u8DataStatus);
150 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res3, tvb, offset, 1, u8DataStatus);
151 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_valid, tvb, offset, 1, u8DataStatus);
152 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_redundancy, tvb, offset, 1, u8DataStatus);
153 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_primary, tvb, offset, 1, u8DataStatus);
158 IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
162 guint8 u8SFDataLength = 255;
167 unsigned char virtualFramebuffer[16];
170 /* the sub tvb will NOT contain the frame_id here! */
171 u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
173 /* try to bild a temporaray buffer for generating this CRC */
174 memcpy(&virtualFramebuffer[0], pinfo->dst.data, 6);
175 memcpy(&virtualFramebuffer[6], pinfo->src.data, 6);
176 virtualFramebuffer[12] = 0x88;
177 virtualFramebuffer[13] = 0x92;
178 virtualFramebuffer[15] = (unsigned char) (u16FrameID &0xff);
179 virtualFramebuffer[14] = (unsigned char) (u16FrameID>>8);
180 crc = crc16_plain_init();
181 crc = crc16_plain_update(crc, &virtualFramebuffer[0], 16);
182 crc = crc16_plain_finalize(crc);
183 /* can check this CRC only by having built a temporary data buffer out of the pinfo data */
184 u16SFCRC16 = tvb_get_letohs(tvb, offset);
185 if (u16SFCRC16 != 0) /* no crc! */
187 if (u16SFCRC16 != crc)
189 proto_item_append_text(tree, ", no packed frame: SFCRC16 is 0x%x should be 0x%x", u16SFCRC16, crc);
193 /* end of first CRC check */
195 offset += 2; /*Skip first crc */
196 tvb_len = tvb_length(tvb);
197 if (offset + 4 > tvb_len)
199 if (tvb_get_letohs(tvb, offset) == 0)
200 return FALSE; /* no valid DFP frame */
202 u32SubStart = offset;
204 u8SFPosition = tvb_get_guint8(tvb, offset);
207 u8SFDataLength = tvb_get_guint8(tvb, offset);
210 if (u8SFDataLength == 0) {
216 offset += u8SFDataLength;
217 if (offset > tvb_len)
218 return /*TRUE; */FALSE;
220 u16SFCRC16 = tvb_get_letohs(tvb, offset);
221 if (u16SFCRC16 != 0) {
222 if (u8SFPosition & 0x80) {
223 crc = crc16_plain_tvb_offset_seed(tvb, u32SubStart, offset-u32SubStart, 0);
224 if (crc != u16SFCRC16) {
236 /* possibly dissect a CSF_SDU related PN-RT packet */
238 dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
243 guint8 u8SFDataLength = 255;
244 guint8 u8SFCycleCounter;
245 guint8 u8SFDataStatus;
248 proto_item *sub_item;
249 proto_tree *sub_tree;
254 /* the sub tvb will NOT contain the frame_id here! */
255 u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
257 /* possible FrameID ranges for DFP */
258 if ((u16FrameID < 0x100) || (u16FrameID > 0x0FFF))
260 if (IsDFP_Frame(tvb, pinfo, tree)) {
261 /* can't check this CRC, as the checked data bytes are not available */
262 u16SFCRC16 = tvb_get_letohs(tvb, offset);
264 proto_tree_add_uint(tree, hf_pn_rt_sf_crc16_ok, tvb, offset, 2, u16SFCRC16);
266 proto_tree_add_uint(tree, hf_pn_rt_sf_crc16_null, tvb, offset, 2, u16SFCRC16);
270 sub_item = proto_tree_add_item(tree, hf_pn_rt_sf, tvb, offset, 0, ENC_NA);
271 sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_sf);
272 u32SubStart = offset;
274 u8SFPosition = tvb_get_guint8(tvb, offset);
275 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_position, tvb, offset, 1, u8SFPosition);
278 u8SFDataLength = tvb_get_guint8(tvb, offset);
279 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_data_length, tvb, offset, 1, u8SFDataLength);
282 if (u8SFDataLength == 0) {
283 proto_item_append_text(sub_item, ": Pos:%u, Length:%u", u8SFPosition, u8SFDataLength);
284 proto_item_set_len(sub_item, offset - u32SubStart);
288 u8SFCycleCounter = tvb_get_guint8(tvb, offset);
289 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_cycle_counter, tvb, offset, 1, u8SFCycleCounter);
292 u8SFDataStatus = tvb_get_guint8(tvb, offset);
293 dissect_DataStatus(tvb, offset, sub_tree, u8SFDataStatus);
296 offset = dissect_pn_user_data(tvb, offset, pinfo, sub_tree, u8SFDataLength, "DataItem");
298 u16SFCRC16 = tvb_get_letohs(tvb, offset);
299 item = proto_tree_add_uint(sub_tree, hf_pn_rt_sf_crc16, tvb, offset, 2, u16SFCRC16);
301 if (u16SFCRC16 != 0 /* "old check": u8SFPosition & 0x80 */) {
302 crc = crc16_plain_tvb_offset_seed(tvb, u32SubStart, offset-u32SubStart, 0);
303 if (crc != u16SFCRC16) {
304 proto_item_append_text(item, " [Preliminary check: incorrect, should be: %u]", crc);
305 expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Bad checksum");
307 proto_item_append_text(item, " [Preliminary check: Correct]");
310 proto_item_append_text(item, " [No check, supplied CRC == zero]");
314 proto_item_append_text(sub_item, ": Pos:%u, Length:%u, Cycle:%u, Status: 0x%02x (%s,%s,%s,%s)",
315 u8SFPosition, u8SFDataLength, u8SFCycleCounter, u8SFDataStatus,
316 (u8SFDataStatus & 0x04) ? "Valid" : "Invalid",
317 (u8SFDataStatus & 0x01) ? "Primary" : "Backup",
318 (u8SFDataStatus & 0x20) ? "Ok" : "Problem",
319 (u8SFDataStatus & 0x10) ? "Run" : "Stop");
321 proto_item_set_len(sub_item, offset - u32SubStart);
331 dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
333 /* for reasemble processing we need some inits.. */
334 /* Register PNIO defrag table init routine. */
336 static GHashTable *pdu_frag_table = NULL;
337 static GHashTable *reasembled_frag_table = NULL;
339 static dissector_handle_t data_handle;
340 static dissector_table_t ethertype_subdissector_table;
342 static guint32 start_frag_OR_ID[16];
346 pnio_defragment_init(void)
350 if ( reasembled_frag_table != NULL ) {
351 g_hash_table_destroy( reasembled_frag_table );
352 reasembled_frag_table = NULL;
355 for (i=0; i < 16; i++) /* init the reasemble help array */
356 start_frag_OR_ID[i] = 0;
358 fragment_table_init(&pdu_frag_table);
359 if (reasembled_frag_table == NULL)
361 reasembled_frag_table = g_hash_table_new(NULL, NULL);
365 /* possibly dissect a FRAG_PDU related PN-RT packet */
367 dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
373 /* the sub tvb will NOT contain the frame_id here! */
374 u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
376 /* possible FrameID ranges for FRAG_PDU */
377 if (u16FrameID >= 0xFF80 && u16FrameID <= 0xFF8F) {
378 proto_item *sub_item;
379 proto_tree *sub_tree;
380 proto_item *status_item;
381 proto_tree *status_tree;
382 guint8 u8FragDataLength;
384 gboolean bMoreFollows;
387 sub_item = proto_tree_add_item(tree, hf_pn_rt_frag, tvb, offset, 0, ENC_NA);
388 sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_frag);
390 u8FragDataLength = tvb_get_guint8(tvb, offset);
391 proto_tree_add_uint(sub_tree, hf_pn_rt_frag_data_length, tvb, offset, 1, u8FragDataLength);
394 status_item = proto_tree_add_item(sub_tree, hf_pn_rt_frag_status, tvb, offset, 1, ENC_NA);
395 status_tree = proto_item_add_subtree(status_item, ett_pn_rt_frag_status);
397 u8FragStatus = tvb_get_guint8(tvb, offset);
398 proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_more_follows, tvb, offset, 1, u8FragStatus);
399 proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_error, tvb, offset, 1, u8FragStatus);
400 proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_fragment_number, tvb, offset, 1, u8FragStatus);
402 uFragNumber = u8FragStatus & 0x3F; /* bits 0 to 5 */
403 bMoreFollows = (u8FragStatus & 0x80) != 0;
404 proto_item_append_text(status_item, ": Number: %u, %s",
406 val_to_str( (u8FragStatus & 0x80) >> 7, pn_rt_frag_status_more_follows, "Unknown"));
408 proto_tree_add_string_format(sub_tree, hf_pn_rt_frag_data, tvb, offset, tvb_length(tvb) - offset, "data",
409 "Fragment Length: %d bytes", tvb_length(tvb) - offset);
410 col_append_fstr(pinfo->cinfo, COL_INFO, " Fragment Length: %d bytes", tvb_length(tvb) - offset);
412 dissect_pn_user_data_bytes(tvb, offset, pinfo, sub_tree, tvb_length(tvb) - offset, FRAG_DATA);
413 if ((guint)(tvb_length(tvb) - offset) < (guint)(u8FragDataLength *8)) {
414 proto_item_append_text(status_item, ": FragDataLength out of Framerange -> discarding!");
417 /* defragmentation starts here */
421 guint32 u32ReasembleID /*= 0xfedc ??*/;
422 fragment_data *pdu_frag;
424 u32FragID = (u16FrameID & 0xf);
425 if (uFragNumber == 0)
426 { /* this is the first "new" fragment, so set up a new key Id */
428 u32FrameKey = (pinfo->fd->num << 2) | u32FragID;
429 /* store it in the array */
430 start_frag_OR_ID[u32FragID] = u32FrameKey;
432 u32ReasembleID = start_frag_OR_ID[u32FragID];
433 /* use frame data instead of "pnio fraglen" which sets 8 octet steps */
434 pdu_frag = fragment_add_seq(tvb, offset, pinfo, u32ReasembleID, pdu_frag_table, uFragNumber,
435 (tvb_length(tvb) - offset)/*u8FragDataLength*8*/, bMoreFollows);
437 if (pdu_frag && !bMoreFollows) /* PDU is complete! and last fragment */
438 { /* store this frag as the completed frag in hash table */
439 g_hash_table_insert(reasembled_frag_table, GUINT_TO_POINTER(pinfo->fd->num), pdu_frag);
440 start_frag_OR_ID[u32FragID] = 0; /* reset the starting frame counter */
442 if (!bMoreFollows) /* last fragment */
444 pdu_frag = g_hash_table_lookup(reasembled_frag_table, GUINT_TO_POINTER(pinfo->fd->num));
445 if (pdu_frag) /* found a matching frag dissect it */
451 pdu_length = pdu_frag->len;
452 /* create the new tvb for defraged frame */
453 pdu_tvb = tvb_new_child_real_data(tvb, pdu_frag->data, pdu_length, pdu_length);
454 /* add the defragmented data to the data source list */
455 add_new_data_source(pinfo, pdu_tvb, "Reassembled Profinet Frame");
456 /* PDU is complete: look for the Ethertype and give it to the appropriate dissection routine */
457 type = tvb_get_ntohs(pdu_tvb, 0);
458 pdu_tvb = tvb_new_subset_remaining(pdu_tvb, 2);
459 if (!dissector_try_uint(ethertype_subdissector_table, type, pdu_tvb, pinfo, tree))
460 call_dissector(data_handle, pdu_tvb, pinfo, tree);
473 * dissect_pn_rt - The dissector for the Soft-Real-Time protocol
476 dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
482 guint8 u8TransferStatus;
483 guint16 u16CycleCounter;
484 const gchar *pszProtAddInfo;
485 const gchar *pszProtShort;
486 const gchar *pszProtSummary;
487 const gchar *pszProtComment;
488 proto_tree *pn_rt_tree, *ti;
489 gchar szFieldSummary[100];
494 /* If the link-layer dissector for the protocol above us knows whether
495 * the packet, as handed to it, includes a link-layer FCS, what it
496 * hands to us should not include the FCS; if that's not the case,
497 * that's a bug in that dissector, and should be fixed there.
499 * If the link-layer dissector for the protocol above us doesn't know
500 * whether the packet, as handed to us, includes a link-layer FCS,
501 * there are limits as to what can be done there; the dissector
502 * ultimately needs a "yes, it has an FCS" preference setting, which
503 * both the Ethernet and 802.11 dissectors do. If that's not the case
504 * for a dissector, that's a deficiency in that dissector, and should
507 * Therefore, we assume we are not handed a packet that includes an
508 * FCS. If we are ever handed such a packet, either the link-layer
509 * dissector needs to be fixed or the link-layer dissector's preference
510 * needs to be set for your capture (even if that means adding such
511 * a preference). This dissector (and other dissectors for protcols
512 * running atop the link layer) should not attempt to process the
513 * FCS themselves, as that will just break things. */
515 /* Initialize variables */
520 * Set the columns now, so that they'll be set correctly if we throw
521 * an exception. We can set them (or append things) later again ....
524 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PN-RT");
525 col_set_str(pinfo->cinfo, COL_INFO, "PROFINET Real-Time");
527 pdu_len = tvb_reported_length(tvb);
529 dissect_pn_malformed(tvb, 0, pinfo, tree, pdu_len);
533 /* build some "raw" data */
534 u16FrameID = tvb_get_ntohs(tvb, 0);
535 if (u16FrameID <= 0x001F) {
536 pszProtShort = "PN-RT";
537 pszProtAddInfo = "reserved, ";
538 pszProtSummary = "Real-Time";
539 pszProtComment = "0x0000-0x001F: Reserved ID";
541 } else if (u16FrameID <= 0x0021) {
542 pszProtShort = "PN-PTCP";
543 pszProtAddInfo = "Synchronization, ";
544 pszProtSummary = "Real-Time";
545 pszProtComment = "0x0020-0x0021: Real-Time: Sync (with follow up)";
547 } else if (u16FrameID <= 0x007F) {
548 pszProtShort = "PN-RT";
549 pszProtAddInfo = "reserved, ";
550 pszProtSummary = "Real-Time";
551 pszProtComment = "0x0022-0x007F: Reserved ID";
553 } else if (u16FrameID <= 0x0081) {
554 pszProtShort = "PN-PTCP";
555 pszProtAddInfo = "Synchronization, ";
556 pszProtSummary = "Isochronous-Real-Time";
557 pszProtComment = "0x0080-0x0081: Real-Time: Sync (without follow up)";
559 } else if (u16FrameID <= 0x00FF) {
560 pszProtShort = "PN-RT";
561 pszProtAddInfo = "reserved, ";
562 pszProtSummary = "Real-Time";
563 pszProtComment = "0x0082-0x00FF: Reserved ID";
565 } else if (u16FrameID <= 0x6FF) {
566 pszProtShort = "PN-RTC3";
567 pszProtAddInfo = "RTC3, ";
568 pszProtSummary = "Isochronous-Real-Time";
569 pszProtComment = "0x0100-0x06FF: RED: Real-Time(class=3): non redundant, normal or DFP";
571 } else if (u16FrameID <= 0x0FFF) {
572 pszProtShort = "PN-RTC3";
573 pszProtAddInfo = "RTC3, ";
574 pszProtSummary = "Isochronous-Real-Time";
575 pszProtComment = "0x0700-0x0FFF: RED: Real-Time(class=3): redundant, normal or DFP";
577 } else if (u16FrameID <= 0x7FFF) {
578 pszProtShort = "PN-RT";
579 pszProtAddInfo = "reserved, ";
580 pszProtSummary = "Real-Time";
581 pszProtComment = "0x1000-0x7FFF: Reserved ID";
583 } else if (u16FrameID <= 0xBBFF) {
584 pszProtShort = "PN-RTC1";
585 pszProtAddInfo = "RTC1, ";
586 pszProtSummary = "cyclic Real-Time";
587 pszProtComment = "0x8000-0xBBFF: Real-Time(class=1 unicast): non redundant, normal";
589 } else if (u16FrameID <= 0xBFFF) {
590 pszProtShort = "PN-RTC1";
591 pszProtAddInfo = "RTC1, ";
592 pszProtSummary = "cyclic Real-Time";
593 pszProtComment = "0xBC00-0xBFFF: Real-Time(class=1 multicast): non redundant, normal";
595 } else if (u16FrameID <= 0xF7FF) {
596 /* check if udp frame on PNIO port */
597 if (pinfo->destport == 0x8892)
599 pszProtShort = "PN-RTCUDP,";
600 pszProtAddInfo = "RT_CLASS_UDP, ";
601 pszProtComment = "0xC000-0xF7FF: Real-Time(UDP unicast): Cyclic";
604 { /* layer 2 frame */
605 pszProtShort = "PN-RT";
606 pszProtAddInfo = "RTC1(legacy), ";
607 pszProtComment = "0xC000-0xF7FF: Real-Time(class=1 unicast): Cyclic";
609 pszProtSummary = "cyclic Real-Time";
611 } else if (u16FrameID <= 0xFBFF) {
612 if (pinfo->destport == 0x8892)
614 pszProtShort = "PN-RTCUDP,";
615 pszProtAddInfo = "RT_CLASS_UDP, ";
616 pszProtComment = "0xF800-0xFBFF:: Real-Time(UDP multicast): Cyclic";
619 { /* layer 2 frame */
620 pszProtShort = "PN-RT";
621 pszProtAddInfo = "RTC1(legacy), ";
622 pszProtComment = "0xF800-0xFBFF: Real-Time(class=1 multicast): Cyclic";
624 pszProtSummary = "cyclic Real-Time";
626 } else if (u16FrameID <= 0xFDFF) {
627 pszProtShort = "PN-RTA";
628 pszProtAddInfo = "Reserved, ";
629 pszProtSummary = "acyclic Real-Time";
630 pszProtComment = "0xFC00-0xFDFF: Reserved";
632 if (u16FrameID == 0xfc01) {
633 pszProtShort = "PN-RTA";
634 pszProtAddInfo = "Alarm High, ";
635 pszProtSummary = "acyclic Real-Time";
636 pszProtComment = "Real-Time: Acyclic PN-IO Alarm high priority";
639 } else if (u16FrameID <= 0xFEFF) {
640 pszProtShort = "PN-RTA";
641 pszProtAddInfo = "Reserved, ";
642 pszProtSummary = "acyclic Real-Time";
643 pszProtComment = "0xFE00-0xFEFF: Real-Time: Reserved";
645 if (u16FrameID == 0xFE01) {
646 pszProtShort = "PN-RTA";
647 pszProtAddInfo = "Alarm Low, ";
648 pszProtSummary = "acyclic Real-Time";
649 pszProtComment = "Real-Time: Acyclic PN-IO Alarm low priority";
651 if (u16FrameID == FRAME_ID_DCP_HELLO) {
652 pszProtShort = "PN-RTA";
654 pszProtSummary = "acyclic Real-Time";
655 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) hello";
657 if (u16FrameID == FRAME_ID_DCP_GETORSET) {
658 pszProtShort = "PN-RTA";
660 pszProtSummary = "acyclic Real-Time";
661 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) get/set";
663 if (u16FrameID == FRAME_ID_DCP_IDENT_REQ) {
664 pszProtShort = "PN-RTA";
666 pszProtSummary = "acyclic Real-Time";
667 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) identify multicast request";
669 if (u16FrameID == FRAME_ID_DCP_IDENT_RES) {
670 pszProtShort = "PN-RTA";
672 pszProtSummary = "acyclic Real-Time";
673 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) identify response";
675 } else if (u16FrameID <= 0xFF01) {
676 pszProtShort = "PN-PTCP";
677 pszProtAddInfo = "RTA Sync, ";
678 pszProtSummary = "acyclic Real-Time";
679 pszProtComment = "0xFF00-0xFF01: PTCP Announce";
681 } else if (u16FrameID <= 0xFF1F) {
682 pszProtShort = "PN-PTCP";
683 pszProtAddInfo = "RTA Sync, ";
684 pszProtSummary = "acyclic Real-Time";
685 pszProtComment = "0xFF02-0xFF1F: Reserved";
687 } else if (u16FrameID <= 0xFF21) {
688 pszProtShort = "PN-PTCP";
689 pszProtAddInfo = "Follow Up, ";
690 pszProtSummary = "acyclic Real-Time";
691 pszProtComment = "0xFF20-0xFF21: PTCP Follow Up";
693 } else if (u16FrameID <= 0xFF22) {
694 pszProtShort = "PN-PTCP";
695 pszProtAddInfo = "Follow Up, ";
696 pszProtSummary = "acyclic Real-Time";
697 pszProtComment = "0xFF22-0xFF3F: Reserved";
699 } else if (u16FrameID <= 0xFF43) {
700 pszProtShort = "PN-PTCP";
701 pszProtAddInfo = "Delay, ";
702 pszProtSummary = "acyclic Real-Time";
703 pszProtComment = "0xFF40-0xFF43: Acyclic Real-Time: Delay";
705 } else if (u16FrameID <= 0xFF7F) {
706 pszProtShort = "PN-RT";
707 pszProtAddInfo = "Reserved, ";
708 pszProtSummary = "Real-Time";
709 pszProtComment = "0xFF44-0xFF7F: reserved ID";
711 } else if (u16FrameID <= 0xFF8F) {
712 pszProtShort = "PN-RT";
714 pszProtSummary = "Fragmentation";
715 pszProtComment = "0xFF80-0xFF8F: Fragmentation";
718 pszProtShort = "PN-RT";
719 pszProtAddInfo = "Reserved, ";
720 pszProtSummary = "Real-Time";
721 pszProtComment = "0xFF90-0xFFFF: reserved ID";
725 /* decode optional cyclic fields at the packet end and build the summary line */
727 /* cyclic transfer has cycle counter, data status and transfer status fields at the end */
728 u16CycleCounter = tvb_get_ntohs(tvb, pdu_len - 4);
729 u8DataStatus = tvb_get_guint8(tvb, pdu_len - 2);
730 u8TransferStatus = tvb_get_guint8(tvb, pdu_len - 1);
732 g_snprintf (szFieldSummary, sizeof(szFieldSummary),
733 "%sID:0x%04x, Len:%4u, Cycle:%5u (%s,%s,%s,%s)",
734 pszProtAddInfo, u16FrameID, pdu_len - 2 - 4, u16CycleCounter,
735 (u8DataStatus & 0x04) ? "Valid" : "Invalid",
736 (u8DataStatus & 0x01) ? "Primary" : "Backup",
737 (u8DataStatus & 0x20) ? "Ok" : "Problem",
738 (u8DataStatus & 0x10) ? "Run" : "Stop");
740 /* user data length is packet len - frame id - optional cyclic status fields */
741 data_len = pdu_len - 2 - 4;
743 /* satisfy the gcc compiler, so it won't throw an "uninitialized" warning */
746 u8TransferStatus = 0;
748 /* acyclic transfer has no fields at the end */
749 g_snprintf (szFieldSummary, sizeof(szFieldSummary),
750 "%sID:0x%04x, Len:%4u",
751 pszProtAddInfo, u16FrameID, pdu_len - 2);
753 /* user data length is packet len - frame id field */
754 data_len = pdu_len - 2;
757 /* build protocol tree only, if tree is really used */
759 /* build pn_rt protocol tree with summary line */
760 if (pn_rt_summary_in_tree) {
761 ti = proto_tree_add_protocol_format(tree, proto_pn_rt, tvb, 0, pdu_len,
762 "PROFINET %s, %s", pszProtSummary, szFieldSummary);
764 ti = proto_tree_add_item(tree, proto_pn_rt, tvb, 0, pdu_len, ENC_NA);
766 pn_rt_tree = proto_item_add_subtree(ti, ett_pn_rt);
769 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_frame_id, tvb,
770 0, 2, u16FrameID, "FrameID: 0x%04x (%s)", u16FrameID, pszProtComment);
773 /* add cycle counter */
774 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_cycle_counter, tvb,
775 pdu_len - 4, 2, u16CycleCounter, "CycleCounter: %u", u16CycleCounter);
777 /* add data status subtree */
778 dissect_DataStatus(tvb, pdu_len - 2, pn_rt_tree, u8DataStatus);
780 /* add transfer status */
781 if (u8TransferStatus) {
782 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_transfer_status, tvb,
783 pdu_len - 1, 1, u8TransferStatus,
784 "TransferStatus: 0x%02x (ignore this frame)", u8TransferStatus);
786 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_transfer_status, tvb,
787 pdu_len - 1, 1, u8TransferStatus,
788 "TransferStatus: 0x%02x (OK)", u8TransferStatus);
793 /* update column info now */
794 col_add_str(pinfo->cinfo, COL_INFO, szFieldSummary);
795 col_set_str(pinfo->cinfo, COL_PROTOCOL, pszProtShort);
797 pinfo->private_data = GUINT_TO_POINTER( (guint32) u16FrameID);
799 /* get frame user data tvb (without header and footer) */
800 next_tvb = tvb_new_subset(tvb, 2, data_len, data_len);
802 /* ask heuristics, if some sub-dissector is interested in this packet payload */
803 if (!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, NULL)) {
804 /*col_set_str(pinfo->cinfo, COL_INFO, "Unknown");*/
806 /* Oh, well, we don't know this; dissect it as data. */
807 dissect_pn_undecoded(next_tvb, 0, pinfo, tree, tvb_length(next_tvb));
812 /* Register all the bits needed by the filtering engine */
814 proto_register_pn_rt(void)
816 static hf_register_info hf[] = {
817 { &hf_pn_rt_frame_id,
818 { "FrameID", "pn_rt.frame_id",
819 FT_UINT16, BASE_DEC, NULL, 0x0,
822 { &hf_pn_rt_cycle_counter,
823 { "CycleCounter", "pn_rt.cycle_counter",
824 FT_UINT16, BASE_DEC, NULL, 0x0,
827 { &hf_pn_rt_data_status,
828 { "DataStatus", "pn_rt.ds",
829 FT_UINT8, BASE_HEX, 0, 0x0,
832 { &hf_pn_rt_data_status_ignore,
833 { "Ignore (1:Ignore/0:Evaluate)", "pn_rt.ds_ignore", FT_UINT8, BASE_HEX, 0, 0x80,
836 { &hf_pn_rt_data_status_Reserved_2,
837 { "Reserved_2 (should be zero)", "pn_rt.ds_Reserved_2",
838 FT_UINT8, BASE_HEX, 0, 0x40,
841 { &hf_pn_rt_data_status_ok,
842 { "StationProblemIndicator (1:Ok/0:Problem)", "pn_rt.ds_ok",
843 FT_UINT8, BASE_HEX, 0, 0x20,
846 { &hf_pn_rt_data_status_operate,
847 { "ProviderState (1:Run/0:Stop)", "pn_rt.ds_operate",
848 FT_UINT8, BASE_HEX, 0, 0x10,
851 { &hf_pn_rt_data_status_res3,
852 { "Reserved_1 (should be zero)", "pn_rt.ds_res3",
853 FT_UINT8, BASE_HEX, 0, 0x08,
856 { &hf_pn_rt_data_status_valid,
857 { "DataValid (1:Valid/0:Invalid)", "pn_rt.ds_valid",
858 FT_UINT8, BASE_HEX, 0, 0x04,
861 { &hf_pn_rt_data_status_redundancy,
862 { "Redundancy", "pn_rt.ds_redundancy",
863 FT_UINT8, BASE_HEX, VALS(pn_rt_ds_redundancy), 0x02,
866 { &hf_pn_rt_data_status_primary,
867 { "State (1:Primary/0:Backup)", "pn_rt.ds_primary",
868 FT_UINT8, BASE_HEX, 0, 0x01,
871 { &hf_pn_rt_transfer_status,
872 { "TransferStatus", "pn_rt.transfer_status",
873 FT_UINT8, BASE_DEC, NULL, 0x0,
877 { "SubFrame", "pn_rt.sf",
878 FT_NONE, BASE_NONE, NULL, 0x0,
881 { &hf_pn_rt_sf_crc16,
882 { "SFCRC16", "pn_rt.sf.crc16",
883 FT_UINT16, BASE_HEX, NULL, 0x0,
886 { &hf_pn_rt_sf_crc16_ok,
887 { "SFCRC16 checked [ok]", "pn_rt.sf.crc16_ok",
888 FT_UINT16, BASE_HEX, NULL, 0x0,
891 { &hf_pn_rt_sf_crc16_null,
892 { "SFCRC16 not checked but ok", "pn_rt.sf.crc16_null",
893 FT_UINT16, BASE_HEX, NULL, 0x0,
896 { &hf_pn_rt_sf_position,
897 { "Position", "pn_rt.sf.position",
898 FT_UINT8, BASE_DEC, NULL, 0x7F,
902 { &hf_pn_rt_sf_position_control,
903 { "Control", "pn_rt.sf.position_control",
904 FT_UINT8, BASE_DEC, VALS(pn_rt_position_control), 0x80,
908 { &hf_pn_rt_sf_data_length,
909 { "DataLength", "pn_rt.sf.data_length",
910 FT_UINT8, BASE_DEC, NULL, 0x0,
913 { &hf_pn_rt_sf_cycle_counter,
914 { "CycleCounter", "pn_rt.sf.cycle_counter",
915 FT_UINT8, BASE_DEC, NULL, 0x0,
919 { "PROFINET Fragment", "pn_rt.frag",
920 FT_NONE, BASE_NONE, NULL, 0x0,
923 { &hf_pn_rt_frag_data_length,
924 { "FragDataLength", "pn_rt.frag_data_length",
925 FT_UINT8, BASE_DEC, NULL, 0x0,
928 { &hf_pn_rt_frag_status,
929 { "FragStatus", "pn_rt.frag_status",
930 FT_NONE, BASE_NONE, NULL, 0x0,
933 { &hf_pn_rt_frag_status_more_follows,
934 { "MoreFollows", "pn_rt.frag_status.more_follows",
935 FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_more_follows), 0x80,
938 { &hf_pn_rt_frag_status_error,
939 { "Reserved", "pn_rt.frag_status.error",
940 FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_error), 0x40,
943 { &hf_pn_rt_frag_status_fragment_number,
944 { "FragmentNumber (zero based)", "pn_rt.frag_status.fragment_number",
945 FT_UINT8, BASE_DEC, NULL, 0x3F,
948 { &hf_pn_rt_frag_data,
949 { "FragData", "pn_rt.frag_data",
950 FT_STRING, BASE_NONE, NULL, 0x00,
954 static gint *ett[] = {
956 &ett_pn_rt_data_status,
959 &ett_pn_rt_frag_status
961 module_t *pn_rt_module;
963 proto_pn_rt = proto_register_protocol("PROFINET Real-Time Protocol",
966 proto_register_field_array(proto_pn_rt, hf, array_length(hf));
967 proto_register_subtree_array(ett, array_length(ett));
969 /* Register our configuration options */
971 pn_rt_module = prefs_register_protocol(proto_pn_rt, NULL);
973 prefs_register_bool_preference(pn_rt_module, "summary_in_tree",
974 "Show PN-RT summary in protocol tree",
975 "Whether the PN-RT summary line should be shown in the protocol tree",
976 &pn_rt_summary_in_tree);
978 prefs_register_bool_preference(pn_rt_module, "desegment",
979 "reassemble PNIO Fragments",
980 "Reassemble PNIO Fragments and get them decoded",
983 /* register heuristics anchor for payload dissectors */
984 register_heur_dissector_list("pn_rt", &heur_subdissector_list);
986 init_pn (proto_pn_rt);
987 register_init_routine(pnio_defragment_init);
991 /* The registration hand-off routine is called at startup */
993 proto_reg_handoff_pn_rt(void)
995 dissector_handle_t pn_rt_handle;
997 pn_rt_handle = create_dissector_handle(dissect_pn_rt, proto_pn_rt);
999 dissector_add_uint("ethertype", ETHERTYPE_PROFINET, pn_rt_handle);
1000 dissector_add_uint("udp.port", 0x8892, pn_rt_handle);
1002 heur_dissector_add("pn_rt", dissect_CSF_SDU_heur, proto_pn_rt);
1003 heur_dissector_add("pn_rt", dissect_FRAG_PDU_heur, proto_pn_rt);
1004 data_handle = find_dissector("data");
1006 ethertype_subdissector_table = find_dissector_table("ethertype");