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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
45 #include <epan/packet.h>
46 #include <epan/addr_resolv.h>
47 #include <epan/prefs.h>
48 #include <epan/strutil.h>
49 #include <epan/etypes.h>
50 #include <epan/expert.h>
51 #include <epan/dissectors/packet-dcerpc.h>
52 #include <epan/crc16.h>
54 #include "packet-pn.h"
56 /* Define the pn-rt proto */
57 static int proto_pn_rt = -1;
59 /* Define many header fields for pn-rt */
60 static int hf_pn_rt_frame_id = -1;
61 static int hf_pn_rt_cycle_counter = -1;
62 static int hf_pn_rt_transfer_status = -1;
63 static int hf_pn_rt_data_status = -1;
64 static int hf_pn_rt_data_status_ignore = -1;
65 static int hf_pn_rt_data_status_subframe_sender_mode = -1;
66 static int hf_pn_rt_data_status_ok = -1;
67 static int hf_pn_rt_data_status_operate = -1;
68 static int hf_pn_rt_data_status_res3 = -1;
69 static int hf_pn_rt_data_status_valid = -1;
70 static int hf_pn_rt_data_status_res1 = -1;
71 static int hf_pn_rt_data_status_primary = -1;
73 static int hf_pn_rt_sf_crc16 = -1;
74 static int hf_pn_rt_sf = -1;
75 static int hf_pn_rt_sf_position = -1;
76 static int hf_pn_rt_sf_position_control = -1;
77 static int hf_pn_rt_sf_data_length = -1;
78 static int hf_pn_rt_sf_cycle_counter = -1;
80 static int hf_pn_rt_frag = -1;
81 static int hf_pn_rt_frag_data_length = -1;
82 static int hf_pn_rt_frag_status = -1;
83 static int hf_pn_rt_frag_status_more_follows = -1;
84 static int hf_pn_rt_frag_status_error = -1;
85 static int hf_pn_rt_frag_status_fragment_number = -1;
86 static int hf_pn_rt_frag_data = -1;
90 * Define the trees for pn-rt
91 * We need one tree for pn-rt itself and one for the pn-rt data status subtree
93 static int ett_pn_rt = -1;
94 static int ett_pn_rt_data_status = -1;
95 static int ett_pn_rt_sf = -1;
96 static int ett_pn_rt_frag = -1;
97 static int ett_pn_rt_frag_status = -1;
100 * Here are the global variables associated with
101 * the various user definable characteristics of the dissection
103 /* Place summary in proto tree */
104 static gboolean pn_rt_summary_in_tree = TRUE;
106 /* heuristic to find the right pn-rt payload dissector */
107 static heur_dissector_list_t heur_subdissector_list;
110 static const value_string pn_rt_position_control[] = {
111 { 0x00, "CRC16 and CycleCounter shall not be checked" },
112 { 0x80, "CRC16 and CycleCounter valid" },
116 static const value_string pn_rt_frag_status_error[] = {
117 { 0x00, "No error" },
118 { 0x01, "An error occured, all earlier fragments shall be dropped" },
122 static const value_string pn_rt_frag_status_more_follows[] = {
123 { 0x00, "Last fragment" },
124 { 0x01, "More fragments follow" },
131 dissect_DataStatus(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 u8DataStatus)
133 proto_item *sub_item;
134 proto_tree *sub_tree;
136 sub_item = proto_tree_add_uint_format(tree, hf_pn_rt_data_status,
137 tvb, offset, 1, u8DataStatus,
138 "DataStatus: 0x%02x (Frame: %s and %s, Provider: %s and %s)",
140 (u8DataStatus & 0x04) ? "Valid" : "Invalid",
141 (u8DataStatus & 0x01) ? "Primary" : "Backup",
142 (u8DataStatus & 0x20) ? "Ok" : "Problem",
143 (u8DataStatus & 0x10) ? "Run" : "Stop");
144 sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_data_status);
145 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ignore, tvb, offset, 1, u8DataStatus);
146 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_subframe_sender_mode, tvb, offset, 1, u8DataStatus);
147 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ok, tvb, offset, 1, u8DataStatus);
148 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_operate, tvb, offset, 1, u8DataStatus);
149 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res3, tvb, offset, 1, u8DataStatus);
150 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_valid, tvb, offset, 1, u8DataStatus);
151 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res1, tvb, offset, 1, u8DataStatus);
152 proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_primary, tvb, offset, 1, u8DataStatus);
156 /* possibly dissect a CSF_SDU related PN-RT packet */
158 dissect_CSF_SDU_heur(tvbuff_t *tvb,
159 packet_info *pinfo, proto_tree *tree)
164 guint8 u8SFDataLength = 255;
165 guint8 u8SFCycleCounter;
166 guint8 u8SFDataStatus;
169 proto_item *sub_item;
170 proto_tree *sub_tree;
175 /* the sub tvb will NOT contain the frame_id here! */
176 u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
178 /* possible FrameID ranges for DFP */
179 if ((u16FrameID >= 0x0500 && u16FrameID < 0x05ff) ||
180 (u16FrameID >= 0x0600 && u16FrameID < 0x07ff) ||
181 (u16FrameID >= 0x4800 && u16FrameID < 0x4fff) ||
182 (u16FrameID >= 0x5800 && u16FrameID < 0x5fff) ||
183 (u16FrameID >= 0x6800 && u16FrameID < 0x6fff) ||
184 (u16FrameID >= 0x7800 && u16FrameID < 0x7fff)) {
185 /* can't check this CRC, as the checked data bytes are not available */
186 u16SFCRC16 = tvb_get_letohs(tvb, offset);
187 proto_tree_add_uint(tree, hf_pn_rt_sf_crc16, tvb, offset, 2, u16SFCRC16);
191 sub_item = proto_tree_add_item(tree, hf_pn_rt_sf, tvb, offset, 0, FALSE);
192 sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_sf);
193 u32SubStart = offset;
195 u8SFPosition = tvb_get_guint8(tvb, offset);
196 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_position_control, tvb, offset, 1, u8SFPosition);
197 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_position, tvb, offset, 1, u8SFPosition);
200 u8SFDataLength = tvb_get_guint8(tvb, offset);
201 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_data_length, tvb, offset, 1, u8SFDataLength);
204 if(u8SFDataLength == 0) {
205 proto_item_append_text(sub_item, ": Pos:%u, Length:%u", u8SFPosition, u8SFDataLength);
206 proto_item_set_len(sub_item, offset - u32SubStart);
210 u8SFCycleCounter = tvb_get_guint8(tvb, offset);
211 proto_tree_add_uint(sub_tree, hf_pn_rt_sf_cycle_counter, tvb, offset, 1, u8SFCycleCounter);
214 u8SFDataStatus = tvb_get_guint8(tvb, offset);
215 dissect_DataStatus(tvb, offset, sub_tree, u8SFDataStatus);
218 offset = dissect_pn_user_data(tvb, offset, pinfo, sub_tree, u8SFDataLength, "DataItem");
220 u16SFCRC16 = tvb_get_letohs(tvb, offset);
221 item = proto_tree_add_uint(sub_tree, hf_pn_rt_sf_crc16, tvb, offset, 2, u16SFCRC16);
223 if(u8SFPosition & 0x80) {
224 crc = crc16_plain_tvb_offset(tvb, u32SubStart, offset-u32SubStart);
225 if(crc != u16SFCRC16) {
226 proto_item_append_text(item, " [Preliminary check: incorrect, should be: %u]", crc);
227 expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Bad checksum");
229 proto_item_append_text(item, " [Preliminary check: Correct]");
232 proto_item_append_text(item, " [No preliminary check, Control bit not set]");
236 proto_item_append_text(sub_item, ": Pos:%u, Length:%u, Cycle:%u, Status: 0x%02x (%s,%s,%s,%s)",
237 u8SFPosition, u8SFDataLength, u8SFCycleCounter, u8SFDataStatus,
238 (u8SFDataStatus & 0x04) ? "Valid" : "Invalid",
239 (u8SFDataStatus & 0x01) ? "Primary" : "Backup",
240 (u8SFDataStatus & 0x20) ? "Ok" : "Problem",
241 (u8SFDataStatus & 0x10) ? "Run" : "Stop");
243 proto_item_set_len(sub_item, offset - u32SubStart);
254 /* possibly dissect a FRAG_PDU related PN-RT packet */
256 dissect_FRAG_PDU_heur(tvbuff_t *tvb,
257 packet_info *pinfo, proto_tree *tree)
261 proto_item *sub_item;
262 proto_tree *sub_tree;
263 guint8 u8FragDataLength;
264 proto_item *status_item;
265 proto_tree *status_tree;
269 /* the sub tvb will NOT contain the frame_id here! */
270 u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
272 /* possible FrameID ranges for FRAG_PDU */
273 if (u16FrameID >= 0xFF80 && u16FrameID < 0xFF8F) {
274 sub_item = proto_tree_add_item(tree, hf_pn_rt_frag, tvb, offset, 0, FALSE);
275 sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_frag);
277 u8FragDataLength = tvb_get_guint8(tvb, offset);
278 proto_tree_add_uint(sub_tree, hf_pn_rt_frag_data_length, tvb, offset, 1, u8FragDataLength);
281 status_item = proto_tree_add_item(sub_tree, hf_pn_rt_frag_status, tvb, offset, 1, FALSE);
282 status_tree = proto_item_add_subtree(status_item, ett_pn_rt_frag_status);
284 u8FragStatus = tvb_get_guint8(tvb, offset);
285 proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_more_follows, tvb, offset, 1, u8FragStatus);
286 proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_error, tvb, offset, 1, u8FragStatus);
287 proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_fragment_number, tvb, offset, 1, u8FragStatus);
289 proto_item_append_text(status_item, ": Number: %u, %s, %s",
291 val_to_str( (u8FragStatus & 0x80) >> 7, pn_rt_frag_status_more_follows, "Unknown"),
292 val_to_str( (u8FragStatus & 0x40) >> 6, pn_rt_frag_status_error, "Unknown"));
295 proto_tree_add_string_format(sub_tree, hf_pn_rt_frag_data, tvb, offset, tvb_length(tvb) - offset, "data",
296 "FragData: %d bytes", tvb_length(tvb) - offset);
298 /* note: the actual defragmentation implementation is still missing here */
299 dissect_pn_undecoded(tvb, offset, pinfo, sub_tree, tvb_length(tvb) - offset);
310 * dissect_pn_rt - The dissector for the Soft-Real-Time protocol
313 dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
319 guint8 u8TransferStatus;
320 guint16 u16CycleCounter;
321 const gchar *pszProtAddInfo;
322 const gchar *pszProtShort;
323 const gchar *pszProtSummary;
324 const gchar *pszProtComment;
325 proto_tree *pn_rt_tree, *ti;
326 gchar szFieldSummary[100];
331 /* The PN-RT protocol uses status values at the end of the Ethernet frame.
332 * Unfortunately it doesn't contain a length field in the PN-RT protocol itself,
333 * so we must depend on the tvb length. This is sometimes is a bit confusing
334 * whether the length of the tvb contains the optional FCS at the end or not
335 * therefore the following heuristic ... */
337 if(pinfo->fd->lnk_t == WTAP_ENCAP_IEEE_802_11_WITH_RADIO) {
338 /* 802.11: at least when using AiroPeek to capture,
339 * the 802.11 dissector already has stripped the FCS from the tvb.
340 * XXX - we might need to add other 802.11 encaps here as well */
341 tvb_len = tvb_length(tvb);
343 /* Ethernet: subtract (optional) FCS or trailer len
344 * (fcs_len -1 means we don't know if FCS is appended, we assume it's not) */
345 tvb_len = tvb_length(tvb) -
346 ((pinfo->pseudo_header->eth.fcs_len != -1) ? pinfo->pseudo_header->eth.fcs_len : 0);
348 tvb_set_reported_length(tvb, tvb_len);
350 /* Initialize variables */
355 * Set the columns now, so that they'll be set correctly if we throw
356 * an exception. We can set them (or append things) later again ....
358 if (check_col(pinfo->cinfo, COL_PROTOCOL))
359 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PN-RT");
360 if (check_col(pinfo->cinfo, COL_INFO))
361 col_set_str(pinfo->cinfo, COL_INFO, "PROFINET Real-Time");
364 dissect_pn_malformed(tvb, 0, pinfo, tree, tvb_len);
369 /* build some "raw" data */
370 u16FrameID = tvb_get_ntohs(tvb, 0);
371 if (u16FrameID <= 0x001F) {
372 pszProtShort = "PN-RT";
373 pszProtAddInfo = "reserved, ";
374 pszProtSummary = "Real-Time";
375 pszProtComment = "0x0000-0x001F: Reserved ID";
377 } else if (u16FrameID <= 0x0021) {
378 pszProtShort = "PN-PTCP";
379 pszProtAddInfo = "Synchronization, ";
380 pszProtSummary = "Real-Time";
381 pszProtComment = "0x0020-0x0021: Real-Time: Sync (with follow up)";
383 } else if (u16FrameID <= 0x007F) {
384 pszProtShort = "PN-RT";
385 pszProtAddInfo = "reserved, ";
386 pszProtSummary = "Real-Time";
387 pszProtComment = "0x0022-0x007F: Reserved ID";
389 } else if (u16FrameID <= 0x0081) {
390 pszProtShort = "PN-PTCP";
391 pszProtAddInfo = "Synchronization, ";
392 pszProtSummary = "Isochronous-Real-Time";
393 pszProtComment = "0x0080-0x0081: Real-Time: Sync (without follow up)";
395 } else if (u16FrameID <= 0x00FF) {
396 pszProtShort = "PN-RT";
397 pszProtAddInfo = "reserved, ";
398 pszProtSummary = "Real-Time";
399 pszProtComment = "0x0082-0x00FF: Reserved ID";
402 } else if (u16FrameID <= 0x04FF){
403 pszProtShort = "PN-RTC3";
404 pszProtAddInfo = "RTC3, ";
405 pszProtSummary = "Isochronous-Real-Time";
406 pszProtComment = "0x0100-0x04FF: Isochronous-Real-Time(class=3): non redundant, normal";
408 } else if (u16FrameID <= 0x05FF){
409 pszProtShort = "PN-RTC3";
410 pszProtAddInfo = "RTC3, ";
411 pszProtSummary = "Isochronous-Real-Time";
412 pszProtComment = "0x0500-0x05FF: Isochronous-Real-Time(class=3): non redundant, DFP";
414 } else if (u16FrameID <= 0x07FF){
415 pszProtShort = "PN-RTC3";
416 pszProtAddInfo = "RTC3, ";
417 pszProtSummary = "Isochronous-Real-Time";
418 pszProtComment = "0x0600-0x07FF: Isochronous-Real-Time(class=3): redundant, DFP";
420 } else if (u16FrameID <= 0x0FFF){
421 pszProtShort = "PN-RTC3";
422 pszProtAddInfo = "RTC3, ";
423 pszProtSummary = "Isochronous-Real-Time";
424 pszProtComment = "0x0800-0x0FFF: Isochronous-Real-Time(class=3): redundant, normal";
426 } else if (u16FrameID <= 0x47FF) {
427 pszProtShort = "PN-RT";
428 pszProtAddInfo = "reserved, ";
429 pszProtSummary = "Real-Time";
430 pszProtComment = "0x1000-0x47FF: Reserved ID";
432 } else if (u16FrameID <= 0x4FFF){
433 pszProtShort = "PN-RTC2";
434 pszProtAddInfo = "RTC2, ";
435 pszProtSummary = "cyclic Real-Time";
436 pszProtComment = "0x4800-0x4FFF: Real-Time(class=2): redundant, DFP";
438 } else if (u16FrameID < 0x57FF){
439 pszProtShort = "PN-RTC2";
440 pszProtAddInfo = "RTC2, ";
441 pszProtSummary = "cyclic Real-Time";
442 pszProtComment = "0x5000-0x57FF: Real-Time(class=2): redundant, normal";
444 } else if (u16FrameID <= 0x5FFF){
445 pszProtShort = "PN-RTC2";
446 pszProtAddInfo = "RTC2, ";
447 pszProtSummary = "cyclic Real-Time";
448 pszProtComment = "0x5800-0x5FFF: Real-Time(class=2): non redundant, DFP";
450 } else if (u16FrameID <= 0x67FF){
451 pszProtShort = "PN-RTC2";
452 pszProtAddInfo = "RTC2, ";
453 pszProtSummary = "cyclic Real-Time";
454 pszProtComment = "0x6000-0x67FF: Real-Time(class=2): non redundant, normal";
456 } else if (u16FrameID <= 0x6FFF){
457 pszProtShort = "PN-RTC2";
458 pszProtAddInfo = "RTC2, ";
459 pszProtSummary = "cyclic Real-Time";
460 pszProtComment = "0x6800-0x6FFF: Real-Time(class=2): redundant, DFP";
462 } else if (u16FrameID <= 0x77FF){
463 pszProtShort = "PN-RTC2";
464 pszProtAddInfo = "RTC2, ";
465 pszProtSummary = "cyclic Real-Time";
466 pszProtComment = "0x7000-0x77FF: Real-Time(class=2): redundant, normal";
468 } else if (u16FrameID <= 0x7FFF){
469 pszProtShort = "PN-RTC2";
470 pszProtAddInfo = "RTC2, ";
471 pszProtSummary = "cyclic Real-Time";
472 pszProtComment = "0x7800-0x7FFF: Real-Time(class=2): non redundant, DFP";
474 } else if (u16FrameID <= 0xBBFF){
475 pszProtShort = "PN-RTC2";
476 pszProtAddInfo = "RTC2, ";
477 pszProtSummary = "cyclic Real-Time";
478 pszProtComment = "0x8000-0xBBFF: Real-Time(class=2): non redundant, normal";
480 } else if (u16FrameID <= 0xBFFF){
481 pszProtShort = "PN-RTC2";
482 pszProtAddInfo = "RTC2, ";
483 pszProtSummary = "cyclic Real-Time";
484 pszProtComment = "0xBC00-0xBFFF: Real-Time(class=2 multicast): non redundant, normal";
486 } else if (u16FrameID <= 0xF7FF){
487 pszProtShort = "PN-RTC1/UDP";
488 pszProtAddInfo = "RTC1/UDP, ";
489 pszProtSummary = "cyclic Real-Time";
490 pszProtComment = "0xC000-0xF7FF: Real-Time(class=1/UDP): Cyclic";
492 } else if (u16FrameID <= 0xFBFF){
493 pszProtShort = "PN-RTC1/UDP";
494 pszProtAddInfo = "Multicast, ";
495 pszProtSummary = "cyclic Real-Time";
496 pszProtComment = "0xF800-0xFBFF: Real-Time(class=1/UDP multicast): Cyclic";
498 } else if (u16FrameID <= 0xFDFF){
499 pszProtShort = "PN-RTA";
500 pszProtAddInfo = "Reserved, ";
501 pszProtSummary = "acyclic Real-Time";
502 pszProtComment = "0xFC00-0xFDFF: Reserved";
504 if (u16FrameID == 0xfc01) {
505 pszProtShort = "PN-RTA";
506 pszProtAddInfo = "Alarm High, ";
507 pszProtSummary = "acyclic Real-Time";
508 pszProtComment = "Real-Time: Acyclic PN-IO Alarm high priority";
511 } else if (u16FrameID <= 0xFEFF){
512 pszProtShort = "PN-RTA";
513 pszProtAddInfo = "Reserved, ";
514 pszProtSummary = "acyclic Real-Time";
515 pszProtComment = "0xFE00-0xFEFF: Real-Time: Reserved";
517 if (u16FrameID == 0xFE01) {
518 pszProtShort = "PN-RTA";
519 pszProtAddInfo = "Alarm Low, ";
520 pszProtSummary = "acyclic Real-Time";
521 pszProtComment = "Real-Time: Acyclic PN-IO Alarm low priority";
523 if (u16FrameID == FRAME_ID_DCP_HELLO) {
524 pszProtShort = "PN-RTA";
526 pszProtSummary = "acyclic Real-Time";
527 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) hello";
529 if (u16FrameID == FRAME_ID_DCP_GETORSET) {
530 pszProtShort = "PN-RTA";
532 pszProtSummary = "acyclic Real-Time";
533 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) get/set";
535 if (u16FrameID == FRAME_ID_DCP_IDENT_REQ) {
536 pszProtShort = "PN-RTA";
538 pszProtSummary = "acyclic Real-Time";
539 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) identify multicast request";
541 if (u16FrameID == FRAME_ID_DCP_IDENT_RES) {
542 pszProtShort = "PN-RTA";
544 pszProtSummary = "acyclic Real-Time";
545 pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) identify response";
547 } else if (u16FrameID <= 0xFF01){
548 pszProtShort = "PN-PTCP";
549 pszProtAddInfo = "RTA Sync, ";
550 pszProtSummary = "acyclic Real-Time";
551 pszProtComment = "0xFF00-0xFF01: PTCP Announce";
553 } else if (u16FrameID <= 0xFF1F){
554 pszProtShort = "PN-PTCP";
555 pszProtAddInfo = "RTA Sync, ";
556 pszProtSummary = "acyclic Real-Time";
557 pszProtComment = "0xFF02-0xFF1F: Reserved";
559 } else if (u16FrameID <= 0xFF21){
560 pszProtShort = "PN-PTCP";
561 pszProtAddInfo = "Follow Up, ";
562 pszProtSummary = "acyclic Real-Time";
563 pszProtComment = "0xFF20-0xFF21: PTCP Follow Up";
565 } else if (u16FrameID <= 0xFF22){
566 pszProtShort = "PN-PTCP";
567 pszProtAddInfo = "Follow Up, ";
568 pszProtSummary = "acyclic Real-Time";
569 pszProtComment = "0xFF22-0xFF3F: Reserved";
571 } else if (u16FrameID <= 0xFF43){
572 pszProtShort = "PN-PTCP";
573 pszProtAddInfo = "Delay, ";
574 pszProtSummary = "acyclic Real-Time";
575 pszProtComment = "0xFF40-0xFF43: Acyclic Real-Time: Delay";
577 } else if (u16FrameID <= 0xFF7F){
578 pszProtShort = "PN-RT";
579 pszProtAddInfo = "Reserved, ";
580 pszProtSummary = "Real-Time";
581 pszProtComment = "0xFF44-0xFF7F: reserved ID";
583 } else if (u16FrameID <= 0xFF8F){
584 pszProtShort = "PN-RT";
585 pszProtAddInfo = "Fragmentation, ";
586 pszProtSummary = "Real-Time";
587 pszProtComment = "0xFF80-0xFF8F: Fragmentation";
590 pszProtShort = "PN-RT";
591 pszProtAddInfo = "Reserved, ";
592 pszProtSummary = "Real-Time";
593 pszProtComment = "0xFF90-0xFFFF: reserved ID";
597 /* decode optional cyclic fields at the packet end and build the summary line */
599 /* cyclic transfer has cycle counter, data status and transfer status fields at the end */
600 u16CycleCounter = tvb_get_ntohs(tvb, tvb_len - 4);
601 u8DataStatus = tvb_get_guint8(tvb, tvb_len - 2);
602 u8TransferStatus = tvb_get_guint8(tvb, tvb_len - 1);
604 g_snprintf (szFieldSummary, sizeof(szFieldSummary),
605 "%sID:0x%04x, Len:%4u, Cycle:%5u (%s,%s,%s,%s)",
606 pszProtAddInfo, u16FrameID, tvb_len - 2 - 4, u16CycleCounter,
607 (u8DataStatus & 0x04) ? "Valid" : "Invalid",
608 (u8DataStatus & 0x01) ? "Primary" : "Backup",
609 (u8DataStatus & 0x20) ? "Ok" : "Problem",
610 (u8DataStatus & 0x10) ? "Run" : "Stop");
612 /* user data length is packet len - frame id - optional cyclic status fields */
613 data_len = tvb_len - 2 - 4;
615 /* satisfy the gcc compiler, so it won't throw an "uninitialized" warning */
618 u8TransferStatus = 0;
620 /* acyclic transfer has no fields at the end */
621 g_snprintf (szFieldSummary, sizeof(szFieldSummary),
622 "%sID:0x%04x, Len:%4u",
623 pszProtAddInfo, u16FrameID, tvb_len - 2);
625 /* user data length is packet len - frame id field */
626 data_len = tvb_len - 2;
629 /* build protocol tree only, if tree is really used */
631 /* build pn_rt protocol tree with summary line */
632 if (pn_rt_summary_in_tree) {
633 ti = proto_tree_add_protocol_format(tree, proto_pn_rt, tvb, 0, tvb_len,
634 "PROFINET %s, %s", pszProtSummary, szFieldSummary);
636 ti = proto_tree_add_item(tree, proto_pn_rt, tvb, 0, tvb_len, FALSE);
638 pn_rt_tree = proto_item_add_subtree(ti, ett_pn_rt);
641 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_frame_id, tvb,
642 0, 2, u16FrameID, "FrameID: 0x%04x (%s)", u16FrameID, pszProtComment);
645 /* add cycle counter */
646 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_cycle_counter, tvb,
647 tvb_len - 4, 2, u16CycleCounter, "CycleCounter: %u", u16CycleCounter);
649 /* add data status subtree */
650 dissect_DataStatus(tvb, tvb_len - 2, tree, u8DataStatus);
652 /* add transfer status */
653 if (u8TransferStatus) {
654 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_transfer_status, tvb,
655 tvb_len - 1, 1, u8TransferStatus,
656 "TransferStatus: 0x%02x (ignore this frame)", u8TransferStatus);
658 proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_transfer_status, tvb,
659 tvb_len - 1, 1, u8TransferStatus,
660 "TransferStatus: 0x%02x (OK)", u8TransferStatus);
665 /* update column info now */
666 if (check_col(pinfo->cinfo, COL_INFO))
667 col_add_str(pinfo->cinfo, COL_INFO, szFieldSummary);
668 if (check_col(pinfo->cinfo, COL_PROTOCOL))
669 col_add_str(pinfo->cinfo, COL_PROTOCOL, pszProtShort);
671 pinfo->private_data = GUINT_TO_POINTER( (guint32) u16FrameID);
673 /* get frame user data tvb (without header and footer) */
674 next_tvb = tvb_new_subset(tvb, 2, data_len, data_len);
676 /* ask heuristics, if some sub-dissector is interested in this packet payload */
677 if(!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree)) {
678 /*if (check_col(pinfo->cinfo, COL_INFO))
679 col_set_str(pinfo->cinfo, COL_INFO, "Unknown");*/
681 /* Oh, well, we don't know this; dissect it as data. */
682 dissect_pn_undecoded(next_tvb, 0, pinfo, tree, tvb_length(next_tvb));
687 /* Register all the bits needed by the filtering engine */
689 proto_register_pn_rt(void)
691 static hf_register_info hf[] = {
692 { &hf_pn_rt_frame_id,
693 { "FrameID", "pn_rt.frame_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
694 { &hf_pn_rt_cycle_counter, {
695 "CycleCounter", "pn_rt.cycle_counter", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
696 { &hf_pn_rt_data_status, {
697 "DataStatus", "pn_rt.ds", FT_UINT8, BASE_HEX, 0, 0x0, NULL, HFILL }},
698 { &hf_pn_rt_data_status_ignore, {
699 "Ignore (1:Ignore/0:Evaluate)", "pn_rt.ds_ignore", FT_UINT8, BASE_HEX, 0, 0x80, NULL, HFILL }},
700 { &hf_pn_rt_data_status_subframe_sender_mode, {
701 "SubFrameSenderMode", "pn_rt.ds_subframe_sender_mode", FT_UINT8, BASE_HEX, 0, 0x40, NULL, HFILL }},
702 { &hf_pn_rt_data_status_ok, {
703 "StationProblemIndicator (1:Ok/0:Problem)", "pn_rt.ds_ok", FT_UINT8, BASE_HEX, 0, 0x20, NULL, HFILL }},
704 { &hf_pn_rt_data_status_operate, {
705 "ProviderState (1:Run/0:Stop)", "pn_rt.ds_operate", FT_UINT8, BASE_HEX, 0, 0x10, NULL, HFILL }},
706 { &hf_pn_rt_data_status_res3, {
707 "Reserved (should be zero)", "pn_rt.ds_res3", FT_UINT8, BASE_HEX, 0, 0x08, NULL, HFILL }},
708 { &hf_pn_rt_data_status_valid, {
709 "DataValid (1:Valid/0:Invalid)", "pn_rt.ds_valid", FT_UINT8, BASE_HEX, 0, 0x04, NULL, HFILL }},
710 { &hf_pn_rt_data_status_res1, {
711 "Reserved (should be zero)", "pn_rt.ds_res1", FT_UINT8, BASE_HEX, 0, 0x02, NULL, HFILL }},
712 { &hf_pn_rt_data_status_primary, {
713 "State (1:Primary/0:Backup)", "pn_rt.ds_primary", FT_UINT8, BASE_HEX, 0, 0x01, NULL, HFILL }},
714 { &hf_pn_rt_transfer_status,
715 { "TransferStatus", "pn_rt.transfer_status", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
717 "SubFrame", "pn_rt.sf", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
718 { &hf_pn_rt_sf_crc16, {
719 "CRC16", "pn_rt.sf.crc16", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
720 { &hf_pn_rt_sf_position, {
721 "Position", "pn_rt.sf.position", FT_UINT8, BASE_DEC, NULL, 0x7F, NULL, HFILL }},
722 { &hf_pn_rt_sf_position_control, {
723 "Control", "pn_rt.sf.position_control", FT_UINT8, BASE_DEC, VALS(pn_rt_position_control), 0x80, NULL, HFILL }},
724 { &hf_pn_rt_sf_data_length, {
725 "DataLength", "pn_rt.sf.data_length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
726 { &hf_pn_rt_sf_cycle_counter, {
727 "CycleCounter", "pn_rt.sf.cycle_counter", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
729 "PROFINET Real-Time Fragment", "pn_rt.frag", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
730 { &hf_pn_rt_frag_data_length, {
731 "FragDataLength", "pn_rt.frag_data_length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
732 { &hf_pn_rt_frag_status, {
733 "FragStatus", "pn_rt.frag_status", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
734 { &hf_pn_rt_frag_status_more_follows, {
735 "MoreFollows", "pn_rt.frag_status.more_follows", FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_more_follows), 0x80, NULL, HFILL }},
736 { &hf_pn_rt_frag_status_error, {
737 "Error", "pn_rt.frag_status.error", FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_error), 0x40, NULL, HFILL }},
738 { &hf_pn_rt_frag_status_fragment_number, {
739 "FragmentNumber (zero based)", "pn_rt.frag_status.fragment_number", FT_UINT8, BASE_DEC, NULL, 0x3F, NULL, HFILL }},
740 { &hf_pn_rt_frag_data, {
741 "FragData", "pn_rt.frag_data", FT_STRING, BASE_NONE, NULL, 0x00, NULL, HFILL }},
743 static gint *ett[] = {
745 &ett_pn_rt_data_status,
748 &ett_pn_rt_frag_status
750 module_t *pn_rt_module;
752 proto_pn_rt = proto_register_protocol("PROFINET Real-Time Protocol",
755 proto_register_field_array(proto_pn_rt, hf, array_length(hf));
756 proto_register_subtree_array(ett, array_length(ett));
758 /* Register our configuration options */
760 pn_rt_module = prefs_register_protocol(proto_pn_rt, NULL);
762 prefs_register_bool_preference(pn_rt_module, "summary_in_tree",
763 "Show PN-RT summary in protocol tree",
764 "Whether the PN-RT summary line should be shown in the protocol tree",
765 &pn_rt_summary_in_tree);
767 /* register heuristics anchor for payload dissectors */
768 register_heur_dissector_list("pn_rt", &heur_subdissector_list);
770 init_pn (proto_pn_rt);
774 /* The registration hand-off routine is called at startup */
776 proto_reg_handoff_pn_rt(void)
778 dissector_handle_t pn_rt_handle;
780 pn_rt_handle = create_dissector_handle(dissect_pn_rt, proto_pn_rt);
782 dissector_add("ethertype", ETHERTYPE_PROFINET, pn_rt_handle);
783 dissector_add("udp.port", 0x8892, pn_rt_handle);
785 heur_dissector_add("pn_rt", dissect_CSF_SDU_heur, proto_pn_rt);
786 heur_dissector_add("pn_rt", dissect_FRAG_PDU_heur, proto_pn_rt);