diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2009-03-16 21:40:00 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2009-03-16 21:40:00 +0000 |
commit | dcdda036103ed6eeec15e3ccccfa3c3b97c563fa (patch) | |
tree | f538da4838f490d29f4f547a98fc7318f331341c /plugins/profinet | |
parent | adfaba2cb4711adbf81a75f101fb3cdf032841a0 (diff) | |
download | wireshark-dcdda036103ed6eeec15e3ccccfa3c3b97c563fa.tar.gz wireshark-dcdda036103ed6eeec15e3ccccfa3c3b97c563fa.tar.bz2 wireshark-dcdda036103ed6eeec15e3ccccfa3c3b97c563fa.zip |
update to the latest PROTINET changes:
- add SubFrameBlock dissection
- add subframe heuristics and dissection
- update frame id "layout"
- raise plugin version to 0.2.4
crc16 algorithm copied from Linux sources (GPL V2 only!)
svn path=/trunk/; revision=27748
Diffstat (limited to 'plugins/profinet')
-rw-r--r-- | plugins/profinet/Makefile.common | 2 | ||||
-rw-r--r-- | plugins/profinet/crc16.c | 71 | ||||
-rw-r--r-- | plugins/profinet/crc16.h | 21 | ||||
-rw-r--r-- | plugins/profinet/moduleinfo.h | 2 | ||||
-rw-r--r-- | plugins/profinet/moduleinfo.nmake | 2 | ||||
-rw-r--r-- | plugins/profinet/packet-dcerpc-pn-io.c | 105 | ||||
-rw-r--r-- | plugins/profinet/packet-pn-rt.c | 325 |
7 files changed, 467 insertions, 61 deletions
diff --git a/plugins/profinet/Makefile.common b/plugins/profinet/Makefile.common index 34acbcfa12..76c6cec9ac 100644 --- a/plugins/profinet/Makefile.common +++ b/plugins/profinet/Makefile.common @@ -28,6 +28,7 @@ PLUGIN_NAME = profinet # the dissector sources (without any helpers) DISSECTOR_SRC = \ + crc16.c \ packet-dcerpc-pn-io.c \ packet-dcom-cba.c \ packet-dcom-cba-acco.c \ @@ -39,6 +40,7 @@ DISSECTOR_SRC = \ # corresponding headers DISSECTOR_INCLUDES = \ + crc16.h \ packet-dcom-cba-acco.h \ packet-pn.h diff --git a/plugins/profinet/crc16.c b/plugins/profinet/crc16.c new file mode 100644 index 0000000000..3bc0edf426 --- /dev/null +++ b/plugins/profinet/crc16.c @@ -0,0 +1,71 @@ +/* + * crc16.c + * + * This source code is licensed under the GNU General Public License, + * Version 2. See the file COPYING for more details. + */ + + /* This code is directly based on linux code lib/crc16.c / .h (GPL V2 ONLY!) + * $Id$ + */ + +#include <glib.h> +#include "crc16.h" + +/** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ +guint16 const crc16_table[256] = { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 +}; + + +static guint crc16_byte(guint16 crc, const guint8 data) +{ + return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff]; +} + +/** + * crc16 - compute the CRC-16 for the data buffer + * @crc: previous CRC value + * @buffer: data pointer + * @len: number of bytes in the buffer + * + * Returns the updated CRC value. + */ +guint16 crc16(guint16 crc, guint8 const *buffer, size_t len) +{ + while (len--) + crc = crc16_byte(crc, *buffer++); + return crc; +} + diff --git a/plugins/profinet/crc16.h b/plugins/profinet/crc16.h new file mode 100644 index 0000000000..dbaa720623 --- /dev/null +++ b/plugins/profinet/crc16.h @@ -0,0 +1,21 @@ +/* + * crc16.h + * + * This source code is licensed under the GNU General Public License, + * Version 2. See the file COPYING for more details. + */ + +/* This code is directly based on linux code lib/crc16.c / .h (GPL V2 ONLY!) + * $Id$ + */ + + +/** + * crc16 - compute the CRC-16 for the data buffer + * @crc: previous CRC value + * @buffer: data pointer + * @len: number of bytes in the buffer + * + * Returns the updated CRC value. + */ +extern guint16 crc16(guint16 crc, guint8 const *buffer, size_t len); diff --git a/plugins/profinet/moduleinfo.h b/plugins/profinet/moduleinfo.h index dfba53dbc5..896e46a39c 100644 --- a/plugins/profinet/moduleinfo.h +++ b/plugins/profinet/moduleinfo.h @@ -13,5 +13,5 @@ #endif /* Version number of package */ -#define VERSION "0.2.3" +#define VERSION "0.2.4" diff --git a/plugins/profinet/moduleinfo.nmake b/plugins/profinet/moduleinfo.nmake index 6b83ba0349..88169543e4 100644 --- a/plugins/profinet/moduleinfo.nmake +++ b/plugins/profinet/moduleinfo.nmake @@ -8,7 +8,7 @@ PACKAGE=profinet # The version MODULE_VERSION_MAJOR=0 MODULE_VERSION_MINOR=2 -MODULE_VERSION_MICRO=2 +MODULE_VERSION_MICRO=4 MODULE_VERSION_EXTRA=0 # diff --git a/plugins/profinet/packet-dcerpc-pn-io.c b/plugins/profinet/packet-dcerpc-pn-io.c index df55805356..c7dab777be 100644 --- a/plugins/profinet/packet-dcerpc-pn-io.c +++ b/plugins/profinet/packet-dcerpc-pn-io.c @@ -256,6 +256,13 @@ static int hf_pn_io_address_resolution_properties = -1; static int hf_pn_io_mci_timeout_factor = -1; static int hf_pn_io_provider_station_name = -1; +static int hf_pn_io_subframe_wd_factor = -1; +static int hf_pn_io_subframe_data = -1; +static int hf_pn_io_subframe_data_position = -1; +static int hf_pn_io_subframe_data_reserved1 = -1; +static int hf_pn_io_subframe_data_data_length = -1; +static int hf_pn_io_subframe_data_reserved2 = -1; + static int hf_pn_io_user_structure_identifier = -1; static int hf_pn_io_channel_number = -1; @@ -478,6 +485,7 @@ static gint ett_pn_io_check_sync_mode = -1; static gint ett_pn_io_ir_frame_data = -1; static gint ett_pn_io_ar_info = -1; static gint ett_pn_io_ir_begin_end_port = -1; +static gint ett_pn_io_subframe_data =-1; static e_uuid_t uuid_pn_io_device = { 0xDEA00001, 0x6C97, 0x11D1, { 0x82, 0x71, 0x00, 0xA0, 0x24, 0x42, 0xDF, 0x7D } }; static guint16 ver_pn_io_device = 1; @@ -543,6 +551,7 @@ static const value_string pn_io_block_type[] = { { 0x0105, "PrmServerBlockReq"}, { 0x8105, "PrmServerBlockRes"}, { 0x0106, "MCRBlockReq"}, + { 0x0107, "SubFrameBlock"}, { 0x0110, "IODBlockReq"}, { 0x8110, "IODBlockRes"}, { 0x0111, "IODBlockReq"}, @@ -5267,6 +5276,65 @@ dissect_MCRBlockReq_block(tvbuff_t *tvb, int offset, +/* dissect the SubFrameBlock */ +static int +dissect_SubFrameBlock_block(tvbuff_t *tvb, int offset, + packet_info *pinfo, proto_tree *tree, proto_item *item, guint8 *drep, guint8 u8BlockVersionHigh, guint8 u8BlockVersionLow, + guint16 u16BodyLength) +{ + guint16 u16IOCRReference; + guint16 u16SubFrameWDFactor; + guint32 u32SubFrameData; + guint16 u16Tmp; + proto_item *sub_item; + proto_tree *sub_tree; + + + if(u8BlockVersionHigh != 1 || u8BlockVersionLow != 0) { + expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN, + "Block version %u.%u not implemented yet!", u8BlockVersionHigh, u8BlockVersionLow); + return offset; + } + offset = dissect_pn_padding(tvb, offset, pinfo, tree, 2); + + /* IOCRReference */ + offset = dissect_dcerpc_uint16(tvb, offset, pinfo, tree, drep, + hf_pn_io_iocr_reference, &u16IOCRReference); + + /* SubFrameWDFactor 16 */ + offset = dissect_dcerpc_uint16(tvb, offset, pinfo, tree, drep, + hf_pn_io_subframe_wd_factor, &u16SubFrameWDFactor); + + /* SubFrameData n*32 */ + u16BodyLength -= 6; + u16Tmp = u16BodyLength; + do { + sub_item = proto_tree_add_item(tree, hf_pn_io_subframe_data, tvb, offset, 4, FALSE); + sub_tree = proto_item_add_subtree(sub_item, ett_pn_io_subframe_data); + /* 31-16 reserved_2 */ + dissect_dcerpc_uint32(tvb, offset, pinfo, sub_tree, drep, + hf_pn_io_subframe_data_reserved2, &u32SubFrameData); + /* 15- 8 DataLength */ + dissect_dcerpc_uint32(tvb, offset, pinfo, sub_tree, drep, + hf_pn_io_subframe_data_data_length, &u32SubFrameData); + /* 7 reserved_1 */ + dissect_dcerpc_uint32(tvb, offset, pinfo, sub_tree, drep, + hf_pn_io_subframe_data_reserved1, &u32SubFrameData); + /* 6-0 Position */ + offset = dissect_dcerpc_uint32(tvb, offset, pinfo, sub_tree, drep, + hf_pn_io_subframe_data_position, &u32SubFrameData); + + proto_item_append_text(sub_item, ", Length:%u, Pos:%u", + (u32SubFrameData & 0x0000FF00) >> 8, u32SubFrameData & 0x0000007F); + } while(u16Tmp -= 4); + + proto_item_append_text(item, ", CRRef:%u, WDFactor:%u, %u*Data", + u16IOCRReference, u16SubFrameWDFactor, u16BodyLength/4); + + return offset; +} + + /* dissect the DataDescription */ static int dissect_DataDescription(tvbuff_t *tvb, int offset, @@ -5842,6 +5910,9 @@ dissect_block(tvbuff_t *tvb, int offset, case(0x0106): dissect_MCRBlockReq_block(tvb, offset, pinfo, sub_tree, sub_item, drep, u8BlockVersionHigh, u8BlockVersionLow); break; + case(0x0107): + dissect_SubFrameBlock_block(tvb, offset, pinfo, sub_tree, sub_item, drep, u8BlockVersionHigh, u8BlockVersionLow, u16BodyLength); + break; case(0x0110): case(0x0111): case(0x0112): @@ -6701,15 +6772,20 @@ dissect_PNIO_heur(tvbuff_t *tvb, /* is this a PNIO class 3 data packet? */ /* frame id must be in valid range (cyclic Real-Time, class=3) */ - if (u16FrameID >= 0x0100 && u16FrameID < 0x7fff) { + if (u16FrameID >= 0x0100 && u16FrameID <= 0x0fff) { + /* XXX - how to detect DFP vs. normal? */ dissect_PNIO_C_SDU(tvb, 0, pinfo, tree, drep); return TRUE; } - /* is this a PNIO class 2 data packet? */ + /* is this a (none DFP) PNIO class 2 data packet? */ /* frame id must be in valid range (cyclic Real-Time, class=2) and * first byte (CBA version field) has to be != 0x11 */ - if (u16FrameID >= 0x8000 && u16FrameID < 0xbf00 && u8CBAVersion != 0x11) { + if (u16FrameID >= 0x5000 && u16FrameID <= 0x57ff && /* RED, redundant */ + u16FrameID >= 0x6000 && u16FrameID <= 0x67ff && /* RED, non redundant */ + u16FrameID >= 0x7000 && u16FrameID <= 0x77ff && /* ORANGE, redundant */ + u16FrameID >= 0x8000 && u16FrameID <= 0xbfff && /* ORANGE, non redundant */ + u8CBAVersion != 0x11) { dissect_PNIO_C_SDU(tvb, 0, pinfo, tree, drep); return TRUE; } @@ -6717,7 +6793,7 @@ dissect_PNIO_heur(tvbuff_t *tvb, /* is this a PNIO class 1 data packet? */ /* frame id must be in valid range (cyclic Real-Time, class=1) and * first byte (CBA version field) has to be != 0x11 */ - if (u16FrameID >= 0xc000 && u16FrameID < 0xfb00 && u8CBAVersion != 0x11) { + if (u16FrameID >= 0xc000 && u16FrameID < 0xfbff && u8CBAVersion != 0x11) { dissect_PNIO_C_SDU(tvb, 0, pinfo, tree, drep); return TRUE; } @@ -7177,9 +7253,23 @@ proto_register_pn_io (void) { &hf_pn_io_mci_timeout_factor, { "MCITimeoutFactor", "pn_io.mci_timeout_factor", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }}, { &hf_pn_io_provider_station_name, - { "ProviderStationName", "pn_io.provider_station_name", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }}, + { "ProviderStationName", "pn_io.provider_station_name", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }}, { &hf_pn_io_user_structure_identifier, - { "UserStructureIdentifier", "pn_io.user_structure_identifier", FT_UINT16, BASE_HEX, VALS(pn_io_user_structure_identifier), 0x0, "", HFILL }}, + { "UserStructureIdentifier", "pn_io.user_structure_identifier", FT_UINT16, BASE_HEX, VALS(pn_io_user_structure_identifier), 0x0, "", HFILL }}, + + + { &hf_pn_io_subframe_wd_factor, + { "SubFrameWDFactor", "pn_io.subframe_wd_factor", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }}, + { &hf_pn_io_subframe_data, + { "SubFrameData", "pn_io.subframe_data", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }}, + { &hf_pn_io_subframe_data_reserved2, + { "Reserved1", "pn_io.subframe_data.reserved1", FT_UINT32, BASE_DEC, NULL, 0xFFFF0000, "", HFILL }}, + { &hf_pn_io_subframe_data_data_length, + { "DataLength", "pn_io.subframe_data.data_length", FT_UINT32, BASE_DEC, NULL, 0x0000FF00, "", HFILL }}, + { &hf_pn_io_subframe_data_reserved1, + { "Reserved1", "pn_io.subframe_data.reserved1", FT_UINT32, BASE_DEC, NULL, 0x00000080, "", HFILL }}, + { &hf_pn_io_subframe_data_position, + { "Position", "pn_io.subframe_data.position", FT_UINT32, BASE_DEC, NULL, 0x0000007F, "", HFILL }}, { &hf_pn_io_channel_number, { "ChannelNumber", "pn_io.channel_number", FT_UINT16, BASE_HEX, VALS(pn_io_channel_number), 0x0, "", HFILL }}, @@ -7562,7 +7652,8 @@ proto_register_pn_io (void) &ett_pn_io_check_sync_mode, &ett_pn_io_ir_frame_data, &ett_pn_io_ar_info, - &ett_pn_io_ir_begin_end_port + &ett_pn_io_ir_begin_end_port, + &ett_pn_io_subframe_data }; proto_pn_io = proto_register_protocol ("PROFINET IO", "PNIO", "pn_io"); diff --git a/plugins/profinet/packet-pn-rt.c b/plugins/profinet/packet-pn-rt.c index 5da7d49b33..2c4a39afcd 100644 --- a/plugins/profinet/packet-pn-rt.c +++ b/plugins/profinet/packet-pn-rt.c @@ -47,9 +47,11 @@ #include <epan/prefs.h> #include <epan/strutil.h> #include <epan/etypes.h> +#include <epan/expert.h> #include <epan/dissectors/packet-dcerpc.h> #include "packet-pn.h" +#include "crc16.h" /* Define the pn-rt proto */ static int proto_pn_rt = -1; @@ -67,12 +69,21 @@ static int hf_pn_rt_data_status_valid = -1; static int hf_pn_rt_data_status_res1 = -1; static int hf_pn_rt_data_status_primary = -1; +static int hf_pn_rt_sf_crc16 = -1; +static int hf_pn_rt_sf = -1; +static int hf_pn_rt_sf_position = -1; +static int hf_pn_rt_sf_position_control = -1; +static int hf_pn_rt_sf_data_length = -1; +static int hf_pn_rt_sf_cycle_counter = -1; + + /* * Define the trees for pn-rt * We need one tree for pn-rt itself and one for the pn-rt data status subtree */ static int ett_pn_rt = -1; static int ett_pn_rt_data_status = -1; +static int ett_pn_rt_sf = -1; /* * Here are the global variables associated with @@ -85,6 +96,134 @@ static gboolean pn_rt_summary_in_tree = TRUE; static heur_dissector_list_t heur_subdissector_list; +static const value_string pn_rt_position_control[] = { + { 0x00, "CRC16 and CycleCounter shall not be checked" }, + { 0x80, "CRC16 and CycleCounter valid" }, + { 0, NULL } +}; + + + +static void +dissect_DataStatus(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 u8DataStatus) +{ + proto_item *sub_item; + proto_tree *sub_tree; + + sub_item = proto_tree_add_uint_format(tree, hf_pn_rt_data_status, + tvb, offset, 1, u8DataStatus, + "DataStatus: 0x%02x (Frame: %s and %s, Provider: %s and %s)", + u8DataStatus, + (u8DataStatus & 0x04) ? "Valid" : "Invalid", + (u8DataStatus & 0x01) ? "Primary" : "Backup", + (u8DataStatus & 0x20) ? "Ok" : "Problem", + (u8DataStatus & 0x10) ? "Run" : "Stop"); + sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_data_status); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res67, tvb, offset, 1, u8DataStatus); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ok, tvb, offset, 1, u8DataStatus); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_operate, tvb, offset, 1, u8DataStatus); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res3, tvb, offset, 1, u8DataStatus); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_valid, tvb, offset, 1, u8DataStatus); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res1, tvb, offset, 1, u8DataStatus); + proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_primary, tvb, offset, 1, u8DataStatus); +} + + +/* possibly dissect a SubFrame related PN-RT packet */ +static gboolean +dissect_SubFrame_heur(tvbuff_t *tvb, + packet_info *pinfo, proto_tree *tree) +{ + guint16 u16FrameID; + guint16 u16SFCRC16; + guint8 u8SFPosition; + guint8 u8SFDataLength = 255; + guint8 u8SFCycleCounter; + guint8 u8SFDataStatus; + int offset = 0; + guint32 u32SubStart; + proto_item *sub_item; + proto_tree *sub_tree; + proto_item *item; + const char *crc_buf; + unsigned long crc; + + + /* the sub tvb will NOT contain the frame_id here! */ + u16FrameID = GPOINTER_TO_UINT(pinfo->private_data); + + /* XXX - add more of the possible FrameID ranges */ + if (u16FrameID >= 0x7800 && u16FrameID < 0x7fff) { + /* can't check this CRC, as the checked data bytes are not available */ + u16SFCRC16 = tvb_get_letohs(tvb, offset); + proto_tree_add_uint(tree, hf_pn_rt_sf_crc16, tvb, offset, 2, u16SFCRC16); + offset += 2; + + while(1) { + sub_item = proto_tree_add_item(tree, hf_pn_rt_sf, tvb, offset, 0, FALSE); + sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_sf); + u32SubStart = offset; + + u8SFPosition = tvb_get_guint8(tvb, offset); + proto_tree_add_uint(sub_tree, hf_pn_rt_sf_position_control, tvb, offset, 1, u8SFPosition); + proto_tree_add_uint(sub_tree, hf_pn_rt_sf_position, tvb, offset, 1, u8SFPosition); + offset += 1; + + u8SFDataLength = tvb_get_guint8(tvb, offset); + proto_tree_add_uint(sub_tree, hf_pn_rt_sf_data_length, tvb, offset, 1, u8SFDataLength); + offset += 1; + + if(u8SFDataLength == 0) { + proto_item_append_text(sub_item, ": Pos:%u, Length:%u", u8SFPosition, u8SFDataLength); + proto_item_set_len(sub_item, offset - u32SubStart); + break; + } + + u8SFCycleCounter = tvb_get_guint8(tvb, offset); + proto_tree_add_uint(sub_tree, hf_pn_rt_sf_cycle_counter, tvb, offset, 1, u8SFCycleCounter); + offset += 1; + + u8SFDataStatus = tvb_get_guint8(tvb, offset); + dissect_DataStatus(tvb, offset, sub_tree, u8SFDataStatus); + offset += 1; + + offset = dissect_pn_user_data(tvb, offset, pinfo, sub_tree, u8SFDataLength, "DataItem"); + + u16SFCRC16 = tvb_get_letohs(tvb, offset); + item = proto_tree_add_uint(sub_tree, hf_pn_rt_sf_crc16, tvb, offset, 2, u16SFCRC16); + + if(u8SFPosition & 0x80) { + crc_buf = (const char *) tvb_get_ptr(tvb, u32SubStart, offset-u32SubStart); + crc = crc16(0, crc_buf, offset-u32SubStart); + + if(crc != u16SFCRC16) { + proto_item_append_text(item, " [Preliminary check: incorrect, should be: %u]", crc); + expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Bad checksum"); + } else { + proto_item_append_text(item, " [Preliminary check: Correct]"); + } + } else { + proto_item_append_text(item, " [No preliminary check, Control bit not set]"); + } + offset += 2; + + proto_item_append_text(sub_item, ": Pos:%u, Length:%u, Cycle:%u, Status: 0x%02x (%s,%s,%s,%s)", + u8SFPosition, u8SFDataLength, u8SFCycleCounter, u8SFDataStatus, + (u8SFDataStatus & 0x04) ? "Valid" : "Invalid", + (u8SFDataStatus & 0x01) ? "Primary" : "Backup", + (u8SFDataStatus & 0x20) ? "Ok" : "Problem", + (u8SFDataStatus & 0x10) ? "Run" : "Stop"); + + proto_item_set_len(sub_item, offset - u32SubStart); + } + + return TRUE; + } + + return FALSE; + +} + /* * dissect_pn_rt - The dissector for the Soft-Real-Time protocol @@ -102,8 +241,6 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) const gchar *pszProtShort; const gchar *pszProtSummary; const gchar *pszProtComment; - proto_item *item = NULL; - proto_tree *ds_tree = NULL; proto_tree *pn_rt_tree, *ti; gchar szFieldSummary[100]; tvbuff_t *next_tvb; @@ -131,7 +268,6 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Initialize variables */ pn_rt_tree = NULL; - ds_tree = NULL; ti = NULL; /* @@ -151,59 +287,119 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* build some "raw" data */ u16FrameID = tvb_get_ntohs(tvb, 0); - if (u16FrameID < 0x0040) { + if (u16FrameID <= 0x001F) { + pszProtShort = "PN-RT"; + pszProtAddInfo = "reserved, "; + pszProtSummary = "Real-Time"; + pszProtComment = "0x0000-0x001F: Reserved ID"; + bCyclic = FALSE; + } else if (u16FrameID <= 0x0021) { pszProtShort = "PN-PTCP"; pszProtAddInfo = "Synchronization, "; pszProtSummary = "Real-Time"; - pszProtComment = "0x0000-0x003F: Real-Time: Sync (with follow up)"; + pszProtComment = "0x0020-0x0021: Real-Time: Sync (with follow up)"; bCyclic = FALSE; - } else if (u16FrameID < 0x0080) { + } else if (u16FrameID <= 0x007F) { pszProtShort = "PN-RT"; pszProtAddInfo = "reserved, "; pszProtSummary = "Real-Time"; - pszProtComment = "0x0040-0x007F: Reserved ID"; + pszProtComment = "0x0022-0x007F: Reserved ID"; bCyclic = FALSE; - } else if (u16FrameID < 0x0100) { + } else if (u16FrameID <= 0x0081) { pszProtShort = "PN-PTCP"; pszProtAddInfo = "Synchronization, "; pszProtSummary = "Isochronous-Real-Time"; - pszProtComment = "0x0080-0x00FF: Real-Time: Sync (without follow up)"; + pszProtComment = "0x0080-0x0081: Real-Time: Sync (without follow up)"; bCyclic = FALSE; - } else if (u16FrameID < 0x8000){ + } else if (u16FrameID <= 0x00FF) { + pszProtShort = "PN-RT"; + pszProtAddInfo = "reserved, "; + pszProtSummary = "Real-Time"; + pszProtComment = "0x0082-0x00FF: Reserved ID"; + bCyclic = FALSE; + } else if (u16FrameID <= 0x0FFF){ pszProtShort = "PN-RTC3"; pszProtAddInfo = "RTC3, "; pszProtSummary = "Isochronous-Real-Time"; - pszProtComment = "0x0100-0x7FFF: Isochronous-Real-Time(class=3): Cyclic"; + pszProtComment = "0x0100-0x0FFF: Isochronous-Real-Time(class=3): RED, non redundant, redundant, normal, DFP"; + bCyclic = TRUE; + } else if (u16FrameID <= 0x47FF) { + pszProtShort = "PN-RT"; + pszProtAddInfo = "reserved, "; + pszProtSummary = "Real-Time"; + pszProtComment = "0x1000-0x47FF: Reserved ID"; bCyclic = TRUE; - } else if (u16FrameID < 0xbf00){ + } else if (u16FrameID <= 0x4FFF){ pszProtShort = "PN-RTC2"; pszProtAddInfo = "RTC2, "; pszProtSummary = "cyclic Real-Time"; - pszProtComment = "0x8000-0xBEFF: Real-Time(class=2): Cyclic"; + pszProtComment = "0x4800-0x4FFF: Real-Time(class=2): RED, redundant, DFP"; bCyclic = TRUE; - } else if (u16FrameID < 0xc000){ + } else if (u16FrameID < 0x57FF){ pszProtShort = "PN-RTC2"; - pszProtAddInfo = "Multicast, "; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0x5000-0x57FF: Real-Time(class=2): RED, redundant, normal"; + bCyclic = TRUE; + } else if (u16FrameID <= 0x5FFF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0x5800-0x5FFF: Real-Time(class=2): RED, non redundant, DFP"; + bCyclic = TRUE; + } else if (u16FrameID <= 0x67FF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0x6000-0x67FF: Real-Time(class=2): RED, non redundant, normal"; + bCyclic = TRUE; + } else if (u16FrameID <= 0x6FFF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0x6800-0x6FFF: Real-Time(class=2): ORANGE, redundant, DFP"; + bCyclic = TRUE; + } else if (u16FrameID <= 0x77FF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0x7000-0x77FF: Real-Time(class=2): ORANGE, redundant, normal"; + bCyclic = TRUE; + } else if (u16FrameID <= 0x7FFF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; pszProtSummary = "cyclic Real-Time"; - pszProtComment = "0xBF00-0xBFFF: Real-Time(class=2 multicast): Cyclic"; + pszProtComment = "0x7800-0x7FFF: Real-Time(class=2): ORANGE, non redundant, DFP"; bCyclic = TRUE; - } else if (u16FrameID < 0xfb00){ - pszProtShort = "PN-RTC1"; - pszProtAddInfo = "RTC1, "; + } else if (u16FrameID <= 0xBBFF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0x8000-0xBBFF: Real-Time(class=2): ORANGE, non redundant, normal"; + bCyclic = TRUE; + } else if (u16FrameID <= 0xBFFF){ + pszProtShort = "PN-RTC2"; + pszProtAddInfo = "RTC2, "; + pszProtSummary = "cyclic Real-Time"; + pszProtComment = "0xBC00-0xBFFF: Real-Time(class=2 multicast): ORANGE, non redundant, normal"; + bCyclic = TRUE; + } else if (u16FrameID <= 0xF7FF){ + pszProtShort = "PN-RTC1/UDP"; + pszProtAddInfo = "RTC1/UDP, "; pszProtSummary = "cyclic Real-Time"; - pszProtComment = "0xC000-0xFAFF: Real-Time(class=1): Cyclic"; + pszProtComment = "0xC000-0xF7FF: Real-Time(class=1/UDP): Cyclic"; bCyclic = TRUE; - } else if (u16FrameID < 0xfc00){ - pszProtShort = "PN-RTC1"; + } else if (u16FrameID <= 0xFBFF){ + pszProtShort = "PN-RTC1/UDP"; pszProtAddInfo = "Multicast, "; pszProtSummary = "cyclic Real-Time"; - pszProtComment = "0xFB00-0xFBFF: Real-Time(class=1 multicast): Cyclic"; + pszProtComment = "0xF800-0xFBFF: Real-Time(class=1/UDP multicast): Cyclic"; bCyclic = TRUE; - } else if (u16FrameID < 0xfe00){ + } else if (u16FrameID <= 0xFDFF){ pszProtShort = "PN-RTA"; pszProtAddInfo = "Reserved, "; pszProtSummary = "acyclic Real-Time"; - pszProtComment = "0xFC00-0xFDFF: Real-Time: Acyclic high priority"; + pszProtComment = "0xFC00-0xFDFF: Reserved"; bCyclic = FALSE; if (u16FrameID == 0xfc01) { pszProtShort = "PN-RTA"; @@ -211,23 +407,30 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) pszProtSummary = "acyclic Real-Time"; pszProtComment = "Real-Time: Acyclic PN-IO Alarm high priority"; } - } else if (u16FrameID < 0xff00){ + + } else if (u16FrameID <= 0xFEFF){ pszProtShort = "PN-RTA"; pszProtAddInfo = "Reserved, "; pszProtSummary = "acyclic Real-Time"; - pszProtComment = "0xFE00-0xFEFF: Real-Time: Acyclic low priority"; + pszProtComment = "0xFE00-0xFEFF: Real-Time: Reserved"; bCyclic = FALSE; - if (u16FrameID == 0xfe01) { + if (u16FrameID == 0xFE01) { pszProtShort = "PN-RTA"; pszProtAddInfo = "Alarm Low, "; pszProtSummary = "acyclic Real-Time"; pszProtComment = "Real-Time: Acyclic PN-IO Alarm low priority"; } + if (u16FrameID == FRAME_ID_DCP_HELLO) { + pszProtShort = "PN-RTA"; + pszProtAddInfo = ""; + pszProtSummary = "acyclic Real-Time"; + pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) hello"; + } if (u16FrameID == FRAME_ID_DCP_GETORSET) { pszProtShort = "PN-RTA"; pszProtAddInfo = ""; pszProtSummary = "acyclic Real-Time"; - pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol)"; + pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) get/set"; } if (u16FrameID == FRAME_ID_DCP_IDENT_REQ) { pszProtShort = "PN-RTA"; @@ -241,29 +444,47 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) pszProtSummary = "acyclic Real-Time"; pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) identify response"; } - } else if (u16FrameID < 0xff20){ + } else if (u16FrameID <= 0xFF01){ + pszProtShort = "PN-PTCP"; + pszProtAddInfo = "RTA Sync, "; + pszProtSummary = "acyclic Real-Time"; + pszProtComment = "0xFF00-0xFF01: PTCP Announce"; + bCyclic = FALSE; + } else if (u16FrameID <= 0xFF1F){ pszProtShort = "PN-PTCP"; pszProtAddInfo = "RTA Sync, "; pszProtSummary = "acyclic Real-Time"; - pszProtComment = "0xFF00-0xFF1F: Acyclic Real-Time: RTA sync"; + pszProtComment = "0xFF02-0xFF1F: Reserved"; + bCyclic = FALSE; + } else if (u16FrameID <= 0xFF21){ + pszProtShort = "PN-PTCP"; + pszProtAddInfo = "Follow Up, "; + pszProtSummary = "acyclic Real-Time"; + pszProtComment = "0xFF20-0xFF21: PTCP Follow Up"; bCyclic = FALSE; - } else if (u16FrameID < 0xff40){ + } else if (u16FrameID <= 0xFF22){ pszProtShort = "PN-PTCP"; pszProtAddInfo = "Follow Up, "; pszProtSummary = "acyclic Real-Time"; - pszProtComment = "0xFF20-0xFF3F: Acyclic Real-Time: Follow Up"; + pszProtComment = "0xFF22-0xFF3F: Reserved"; bCyclic = FALSE; - } else if (u16FrameID < 0xff43){ + } else if (u16FrameID <= 0xFF43){ pszProtShort = "PN-PTCP"; pszProtAddInfo = "Delay, "; pszProtSummary = "acyclic Real-Time"; - pszProtComment = "0xFF40-0xFF42: Acyclic Real-Time: Delay"; + pszProtComment = "0xFF40-0xFF43: Acyclic Real-Time: Delay"; + bCyclic = FALSE; + } else if (u16FrameID <= 0xFF7F){ + pszProtShort = "PN-RT"; + pszProtAddInfo = "Reserved, "; + pszProtSummary = "Real-Time"; + pszProtComment = "0xFF44-0xFF7F: reserved ID"; bCyclic = FALSE; } else { pszProtShort = "PN-RT"; pszProtAddInfo = "Reserved, "; pszProtSummary = "Real-Time"; - pszProtComment = "0xFF43-0xFFFF: reserved ID"; + pszProtComment = "0xFF80-0xFFFF: Fragmentation"; bCyclic = FALSE; } @@ -320,22 +541,7 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) tvb_len - 4, 2, u16CycleCounter, "CycleCounter: %u", u16CycleCounter); /* add data status subtree */ - item = proto_tree_add_uint_format(pn_rt_tree, hf_pn_rt_data_status, - tvb, tvb_len - 2, 1, u8DataStatus, - "DataStatus: 0x%02x (Frame: %s and %s, Provider: %s and %s)", - u8DataStatus, - (u8DataStatus & 0x04) ? "Valid" : "Invalid", - (u8DataStatus & 0x01) ? "Primary" : "Backup", - (u8DataStatus & 0x20) ? "Ok" : "Problem", - (u8DataStatus & 0x10) ? "Run" : "Stop"); - ds_tree = proto_item_add_subtree(item, ett_pn_rt_data_status); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_res67, tvb, tvb_len - 2, 1, u8DataStatus); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_ok, tvb, tvb_len - 2, 1, u8DataStatus); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_operate, tvb, tvb_len - 2, 1, u8DataStatus); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_res3, tvb, tvb_len - 2, 1, u8DataStatus); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_valid, tvb, tvb_len - 2, 1, u8DataStatus); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_res1, tvb, tvb_len - 2, 1, u8DataStatus); - proto_tree_add_uint(ds_tree, hf_pn_rt_data_status_primary, tvb, tvb_len - 2, 1, u8DataStatus); + dissect_DataStatus(tvb, tvb_len - 2, tree, u8DataStatus); /* add transfer status */ if (u8TransferStatus) { @@ -399,10 +605,23 @@ proto_register_pn_rt(void) "State (1:Primary/0:Backup)", "pn_rt.ds_primary", FT_UINT8, BASE_HEX, 0, 0x01, "", HFILL }}, { &hf_pn_rt_transfer_status, { "TransferStatus", "pn_rt.transfer_status", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, + { &hf_pn_rt_sf, { + "SubFrame", "pn_rt.sf", FT_NONE, BASE_HEX, NULL, 0x0, "", HFILL }}, + { &hf_pn_rt_sf_crc16, { + "CRC16", "pn_rt.sf.crc16", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }}, + { &hf_pn_rt_sf_position, { + "Position", "pn_rt.sf.position", FT_UINT8, BASE_DEC, NULL, 0x7F, "", HFILL }}, + { &hf_pn_rt_sf_position_control, { + "Control", "pn_rt.sf.position_control", FT_UINT8, BASE_DEC, VALS(pn_rt_position_control), 0x80, "", HFILL }}, + { &hf_pn_rt_sf_data_length, { + "DataLength", "pn_rt.sf.data_length", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, + { &hf_pn_rt_sf_cycle_counter, { + "CycleCounter", "pn_rt.sf.cycle_counter", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, }; static gint *ett[] = { &ett_pn_rt, &ett_pn_rt_data_status, + &ett_pn_rt_sf }; module_t *pn_rt_module; @@ -438,5 +657,7 @@ proto_reg_handoff_pn_rt(void) dissector_add("ethertype", ETHERTYPE_PROFINET, pn_rt_handle); dissector_add("udp.port", 0x8892, pn_rt_handle); + + heur_dissector_add("pn_rt", dissect_SubFrame_heur, proto_pn_rt); } |