summaryrefslogtreecommitdiff
path: root/plugins/profinet
diff options
context:
space:
mode:
authorT. Scholz <scholzt234@googlemail.com>2016-05-19 13:27:17 -0400
committerMichael Mann <mmann78@netscape.net>2016-05-26 12:43:26 +0000
commitc0e679e0a991103db30bb8d57e8172ab29671884 (patch)
tree0005d2ad144988e0837ba8e615842d8e824ab09a /plugins/profinet
parent32c1a2a3150113451240f7ec6699e17a08678506 (diff)
downloadwireshark-c0e679e0a991103db30bb8d57e8172ab29671884.tar.gz
Cyclic PROFINET PROFIsafe RTC1 data dissection
New implemented functions for profinet plug-in to read cyclic RTC1 data frames more detailed and further to dissect PROFIsafe on PROFINET frames. New functions include: - Reading the PROFINET "Ident OK" Frame for detailed module information, as ModuleIdentNr., SubModuleIdentNr., etc. total dynamically - Improved the existing dissection of fParameter with usage of GSDML-files, as the indexnumber for those parameters can change - Reading a GSDML-file for further module-information, such as PROFIsafe Module, etc. - Aded new pnio protocol preferences, in which the user can define its own network path to his GSDML-files, so that Wireshark is able to read those files for detailed information output. - Added new filter functions for PROFINET and PROFIsafe - All gained and saved information will be used to dissect the cyclic PROFINET frames Bug: 12216 Change-Id: I379da1d349fa099047953042f1aa30450bee5b30 Reviewed-on: https://code.wireshark.org/review/14119 Petri-Dish: Jim Young <jim.young.ws@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Birol Capa <birol.capa@siemens.com> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'plugins/profinet')
-rw-r--r--plugins/profinet/AUTHORS2
-rw-r--r--plugins/profinet/CMakeLists.txt1
-rw-r--r--plugins/profinet/Makefile.common3
-rw-r--r--plugins/profinet/packet-dcerpc-pn-io.c873
-rw-r--r--plugins/profinet/packet-pn-dcp.c88
-rw-r--r--plugins/profinet/packet-pn-rtc-one.c1093
-rw-r--r--plugins/profinet/packet-pn.c11
-rw-r--r--plugins/profinet/packet-pn.h84
8 files changed, 2042 insertions, 113 deletions
diff --git a/plugins/profinet/AUTHORS b/plugins/profinet/AUTHORS
index 62e9af2c2e..4319cbe273 100644
--- a/plugins/profinet/AUTHORS
+++ b/plugins/profinet/AUTHORS
@@ -1,3 +1,3 @@
Author :
Ulf Lamping <ulf.lamping@web.de>
-
+Tobias Scholz <scholzt234@googlemail.com> \ No newline at end of file
diff --git a/plugins/profinet/CMakeLists.txt b/plugins/profinet/CMakeLists.txt
index 89d7ab7f35..56bff2ad74 100644
--- a/plugins/profinet/CMakeLists.txt
+++ b/plugins/profinet/CMakeLists.txt
@@ -33,6 +33,7 @@ set(DISSECTOR_SRC
packet-pn-mrrt.c
packet-pn-ptcp.c
packet-pn-rt.c
+ packet-pn-rtc-one.c
)
set(DISSECTOR_SUPPORT_SRC
diff --git a/plugins/profinet/Makefile.common b/plugins/profinet/Makefile.common
index 92f5e79c84..49c63f0c1a 100644
--- a/plugins/profinet/Makefile.common
+++ b/plugins/profinet/Makefile.common
@@ -33,7 +33,8 @@ NONGENERATED_REGISTER_C_FILES = \
packet-pn-mrp.c \
packet-pn-mrrt.c \
packet-pn-ptcp.c \
- packet-pn-rt.c
+ packet-pn-rt.c \
+ packet-pn-rtc-one.c
# Non-generated sources
NONGENERATED_C_FILES = \
diff --git a/plugins/profinet/packet-dcerpc-pn-io.c b/plugins/profinet/packet-dcerpc-pn-io.c
index e172ad3ec9..1dc9ad79b9 100644
--- a/plugins/profinet/packet-dcerpc-pn-io.c
+++ b/plugins/profinet/packet-dcerpc-pn-io.c
@@ -42,23 +42,60 @@
* Please note: the PROFINET CBA protocol is independent of the PN-IO protocol!
*/
+/*
+ * Cyclic PNIO RTC1 Data Dissection:
+ *
+ * To dissect cyclic PNIO RTC1 frames, this plug-in has to collect important module
+ * information out of "Ident OK", "Connect Request" and "Write Response"
+ * frames first. This information will be used within "packet-pn-rtc-one.c" to
+ * dissect PNIO and PROFIsafe RTC1 frames.
+ *
+ * The data of Stationname-, -type and -id will be gained out of
+ * packet-pn-dcp.c. The header packet-pn.h will save those data.
+ *
+ * Overview for cyclic PNIO RTC1 data dissection functions:
+ * -> dissect_IOCRBlockReq_block (Save amount of IODataObjects, IOCS)
+ * -> dissect_DataDescription (Save important values for cyclic data)
+ * -> dissect_ExpectedSubmoduleBlockReq_block (Get GSD information)
+ * -> dissect_ModuleDiffBlock_block (Module has different ID)
+ * -> dissect_ProfiSafeParameterRequest (Save PROFIsafe parameters)
+ * -> dissect_RecordDataWrite (Call ProfiSafeParameterRequest)
+ * -> pnio_rtc1_cleanup (Reset routine of saved RTC1 information)
+ */
+
#include "config.h"
#include <string.h>
+#include <glib.h>
#include <epan/packet.h>
#include <epan/to_str.h>
+#include <epan/wmem/wmem.h>
+#include <epan/dissectors/packet-dcerpc.h>
#include <epan/expert.h>
#include <epan/dissector_filters.h>
#include <epan/proto_data.h>
-#include <epan/dissectors/packet-dcerpc.h>
+
+#include <wsutil/file_util.h>
+#include <epan/prefs.h>
#include "packet-pn.h"
+#include <stdio.h>
+#include <stdlib.h>
+
void proto_register_pn_io(void);
void proto_reg_handoff_pn_io(void);
+
+#define MAX_NAMELENGTH 200 /* max. length of the given paths */
+#define MAX_LINE_LENGTH 1024 /* used for fgets() */
+#define F_MESSAGE_TRAILER_4BYTE 4 /* PROFIsafe: Defines the Amount of Bytes for CRC and Status-/Controlbyte */
+#define PN_INPUT_CR 1 /* PROFINET Input Connect Request value */
+#define PN_INPUT_DATADESCRITPION 1 /* PROFINET Input Data Description value */
+
+
static int proto_pn_io = -1;
static int proto_pn_io_controller = -1;
static int proto_pn_io_supervisor = -1;
@@ -209,6 +246,7 @@ static int hf_pn_io_api_tree = -1;
static int hf_pn_io_module_tree = -1;
static int hf_pn_io_submodule_tree = -1;
static int hf_pn_io_io_data_object = -1;
+/* General module information */
static int hf_pn_io_io_cs = -1;
static int hf_pn_io_substitutionmode = -1;
@@ -596,20 +634,23 @@ static int hf_pn_io_check_sync_mode_reserved = -1;
static int hf_pn_io_check_sync_mode_sync_master = -1;
static int hf_pn_io_check_sync_mode_cable_delay = -1;
-static int hf_pn_io_profisafe_f_prm_flag1 = -1;
-static int hf_pn_io_profisafe_f_prm_flag1_chck_seq = -1;
-static int hf_pn_io_profisafe_f_prm_flag1_chck_ipar = -1;
-static int hf_pn_io_profisafe_f_prm_flag1_sil = -1;
-static int hf_pn_io_profisafe_f_prm_flag1_crc_len = -1;
-static int hf_pn_io_profisafe_f_prm_flag1_reserved = -1;
-static int hf_pn_io_profisafe_f_prm_flag2 = -1;
-static int hf_pn_io_profisafe_f_src_addr = -1;
-static int hf_pn_io_profisafe_f_dst_addr = -1;
-static int hf_pn_io_profisafe_f_wd_time = -1;
-static int hf_pn_io_profisafe_f_par_crc = -1;
-static int hf_pn_io_profisafe_f_prm_flag2_reserved = -1;
-static int hf_pn_io_profisafe_f_prm_flag2_f_block_id = -1;
-static int hf_pn_io_profisafe_f_prm_flag2_f_par_version = -1;
+/* PROFIsafe fParameters */
+static int hf_pn_io_ps_f_prm_flag1 = -1;
+static int hf_pn_io_ps_f_prm_flag1_chck_seq = -1;
+static int hf_pn_io_ps_f_prm_flag1_chck_ipar = -1;
+static int hf_pn_io_ps_f_prm_flag1_sil = -1;
+static int hf_pn_io_ps_f_prm_flag1_crc_len = -1;
+static int hf_pn_io_ps_f_prm_flag1_crc_seed = -1;
+static int hf_pn_io_ps_f_prm_flag1_reserved = -1;
+static int hf_pn_io_ps_f_prm_flag2 = -1;
+static int hf_pn_io_ps_f_wd_time = -1;
+static int hf_pn_io_ps_f_ipar_crc = -1;
+static int hf_pn_io_ps_f_par_crc = -1;
+static int hf_pn_io_ps_f_src_adr = -1;
+static int hf_pn_io_ps_f_dest_adr = -1;
+static int hf_pn_io_ps_f_prm_flag2_reserved = -1;
+static int hf_pn_io_ps_f_prm_flag2_f_block_id = -1;
+static int hf_pn_io_ps_f_prm_flag2_f_par_version = -1;
static int hf_pn_io_profidrive_request_reference = -1;
static int hf_pn_io_profidrive_request_id = -1;
@@ -707,6 +748,12 @@ static guint16 ver_pn_io_supervisor = 1;
static e_guid_t uuid_pn_io_parameterserver = { 0xDEA00004, 0x6C97, 0x11D1, { 0x82, 0x71, 0x00, 0xA0, 0x24, 0x42, 0xDF, 0x7D } };
static guint16 ver_pn_io_parameterserver = 1;
+
+/* PNIO Preference Variables */
+gboolean pnio_ps_selection = TRUE;
+static const char *pnio_ps_networkpath = "";
+
+
/* Allow heuristic dissection */
static heur_dissector_list_t heur_pn_subdissector_list;
@@ -2561,9 +2608,21 @@ static const value_string pn_io_f_crc_len[] = {
{ 0, NULL }
};
+static const value_string pn_io_f_crc_seed[] = {
+ { 0x00, "CRC-FP as seed value and counter" },
+ { 0x01, "'1' as seed value and CRC-FP+/MNR" },
+ { 0, NULL }
+};
+
+/* F_Block_ID dissection due to ver2.6 specifikation of PI */
static const value_string pn_io_f_block_id[] = {
- { 0x00, "Parameter set for F-Host/F-Device relationship" },
- { 0x01, "Additional F_Address parameter block" },
+ { 0x00, "No F_WD_Time_2, no F_iPar_CRC" },
+ { 0x01, "No F_WD_Time_2, F_iPar_CRC" },
+ { 0x02, "F_WD_Time_2, no F_iPar_CRC" },
+ { 0x03, "F_WD_Time_2, F_iPar_CRC" },
+ /* 0x04..0x07 reserved */
+ /* { 0x00, "Parameter set for F-Host/F-Device relationship" }, */
+ /* { 0x01, "Additional F_Address parameter block" }, */
/* 0x02..0x07 reserved */
{ 0, NULL }
};
@@ -5612,6 +5671,7 @@ dissect_MrpInstanceDataReal_block(tvbuff_t *tvb, int offset,
}
return offset;
}
+
static int
dissect_MrpInstanceDataCheck_block(tvbuff_t *tvb, int offset,
packet_info *pinfo, proto_tree *tree, proto_item *item _U_, guint8 *drep, guint8 u8BlockVersionHigh, guint8 u8BlockVersionLow, guint16 u16BodyLength _U_)
@@ -6790,6 +6850,7 @@ dissect_APIData_block(tvbuff_t *tvb, int offset,
return offset;
}
+
/* dissect the SLRData block */
static int
dissect_SRLData_block(tvbuff_t *tvb, int offset,
@@ -7183,6 +7244,14 @@ dissect_IOCRBlockReq_block(tvbuff_t *tvb, int offset,
proto_tree *sub_tree;
guint32 u32SubStart;
+ conversation_t *conversation;
+ stationInfo *station_info = NULL;
+ iocsObject *iocs_object;
+ iocsObject *cmp_iocs_object;
+ ioDataObject *io_data_object;
+ ioDataObject *cmp_io_data_object;
+ wmem_list_frame_t *frame;
+ wmem_list_t *iocs_list;
if (u8BlockVersionHigh != 1 || u8BlockVersionLow != 0) {
expert_add_info_format(pinfo, item, &ei_pn_io_block_version,
@@ -7242,6 +7311,29 @@ dissect_IOCRBlockReq_block(tvbuff_t *tvb, int offset,
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, api_tree, drep,
hf_pn_io_number_of_io_data_objects, &u16NumberOfIODataObjects);
+ /* Set global Variant for Number of IO Data Objects */
+ /* Notice: Handle Input & Output seperate!!! */
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Get current conversation endpoints using MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ /* Create new conversation, if no "Ident OK" frame as been dissected yet!
+ * Need to switch dl_src & dl_dst, as Connect Request is sent by controller and not by device.
+ * All conversations are based on Device MAC as addr1 */
+ conversation = conversation_new(pinfo->num, &pinfo->dl_dst, &pinfo->dl_src, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info == NULL) {
+ station_info = wmem_new0(wmem_file_scope(), stationInfo);
+ init_pnio_rtc1_station(station_info);
+ conversation_add_proto_data(conversation, proto_pn_dcp, station_info);
+ }
+ else {
+ station_info->ioDataObjectNr = u16NumberOfIODataObjects;
+ }
+ }
+
u16Tmp = u16NumberOfIODataObjects;
while (u16Tmp--) {
sub_item = proto_tree_add_item(api_tree, hf_pn_io_io_data_object, tvb, offset, 0, ENC_NA);
@@ -7262,11 +7354,55 @@ dissect_IOCRBlockReq_block(tvbuff_t *tvb, int offset,
u16SlotNr, u16SubslotNr, u16IODataObjectFrameOffset);
proto_item_set_len(sub_item, offset - u32SubStart);
+
+ if (pinfo->fd->flags.visited == FALSE && station_info != NULL) {
+ io_data_object = wmem_new(wmem_file_scope(), ioDataObject);
+ io_data_object->slotNr = u16SlotNr;
+ io_data_object->subSlotNr = u16SubslotNr;
+ io_data_object->frameOffset = u16IODataObjectFrameOffset;
+ /* initial - Will be added later with Write Request */
+ io_data_object->f_dest_adr = 0;
+ io_data_object->f_par_crc1 = 0;
+ io_data_object->f_src_adr = 0;
+ io_data_object->f_crc_seed = FALSE;
+ io_data_object->f_crc_len = 0;
+ /* Reset as a PNIO Connect Request of a known module appears */
+ io_data_object->last_sb_cb = 0;
+ io_data_object->lastToggleBit = 0;
+
+ if (u16IOCRType == PN_INPUT_CR) {
+ iocs_list = station_info->ioobject_data_in;
+ }
+ else {
+ iocs_list = station_info->ioobject_data_out;
+ }
+
+ for (frame = wmem_list_head(iocs_list); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ cmp_io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (cmp_io_data_object->slotNr == u16SlotNr && cmp_io_data_object->subSlotNr == u16SubslotNr) {
+ /* Found identical existing object */
+ break;
+ }
+ }
+
+ if (frame == NULL) {
+ /* new io_object data incoming */
+ wmem_list_append(iocs_list, io_data_object);
+ }
+ }
}
+
/* NumberOfIOCS */
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, api_tree, drep,
hf_pn_io_number_of_iocs, &u16NumberOfIOCS);
+ /* Set global Vairant for NumberOfIOCS */
+ if (pinfo->fd->flags.visited == FALSE) {
+ if (station_info != NULL) {
+ station_info->iocsNr = u16NumberOfIOCS;
+ }
+ }
+
u16Tmp = u16NumberOfIOCS;
while (u16Tmp--) {
sub_item = proto_tree_add_item(api_tree, hf_pn_io_io_cs, tvb, offset, 0, ENC_NA);
@@ -7287,6 +7423,34 @@ dissect_IOCRBlockReq_block(tvbuff_t *tvb, int offset,
u16SlotNr, u16SubslotNr, u16IOCSFrameOffset);
proto_item_set_len(sub_item, offset - u32SubStart);
+
+ if (pinfo->fd->flags.visited == FALSE) {
+ if (station_info != NULL) {
+ if (u16IOCRType == PN_INPUT_CR) {
+ iocs_list = station_info->iocs_data_in;
+ }
+ else {
+ iocs_list = station_info->iocs_data_out;
+ }
+
+ for (frame = wmem_list_head(iocs_list); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ cmp_iocs_object = (iocsObject*)wmem_list_frame_data(frame);
+ if (cmp_iocs_object->slotNr == u16SlotNr && cmp_iocs_object->subSlotNr == u16SubslotNr) {
+ /* Found identical existing object */
+ break;
+ }
+ }
+
+ if (frame == NULL) {
+ /* new iocs_object data incoming */
+ iocs_object = wmem_new(wmem_file_scope(), iocsObject);
+ iocs_object->slotNr = u16SlotNr;
+ iocs_object->subSlotNr = u16SubslotNr;
+ iocs_object->frameOffset = u16IOCSFrameOffset;
+ wmem_list_append(iocs_list, iocs_object);
+ }
+ }
+ }
}
proto_item_append_text(api_item, ": 0x%x, NumberOfIODataObjects: %u NumberOfIOCS: %u",
@@ -7432,6 +7596,7 @@ dissect_AlarmCRBlockRes_block(tvbuff_t *tvb, int offset,
return offset;
}
+
/* dissect the ARServerBlock */
static int
dissect_ARServerBlock(tvbuff_t *tvb, int offset,
@@ -7664,6 +7829,7 @@ dissect_PDSubFrameBlock_block(tvbuff_t *tvb, int offset,
/* bit 0..7 SFIOCRProperties.DistributedWatchDogFactor */
offset = /* it is the last one, so advance! */
dissect_dcerpc_uint32(tvb, offset, pinfo, sub_tree, drep, hf_pn_io_DistributedWatchDogFactor, &u32SFIOCRProperties);
+
/* SubframeData */
u16RemainingLength = u16BodyLength - PD_SUB_FRAME_BLOCK_FIOCR_PROPERTIES_LENGTH - PD_SUB_FRAME_BLOCK_FRAME_ID_LENGTH;
while (u16RemainingLength >= PD_SUB_FRAME_BLOCK_SUB_FRAME_DATA_LENGTH)
@@ -7842,7 +8008,7 @@ dissect_ARVendorBlockReq_block(tvbuff_t *tvb, int offset,
/* dissect the DataDescription */
static int
dissect_DataDescription(tvbuff_t *tvb, int offset,
- packet_info *pinfo, proto_tree *tree, guint8 *drep)
+ packet_info *pinfo, proto_tree *tree, guint8 *drep, ioDataObject *tmp_io_data_object)
{
guint16 u16DataDescription;
guint16 u16SubmoduleDataLength;
@@ -7852,6 +8018,11 @@ dissect_DataDescription(tvbuff_t *tvb, int offset,
proto_tree *sub_tree;
guint32 u32SubStart;
+ conversation_t *conversation;
+ stationInfo *station_info = NULL;
+ ioDataObject *io_data_object;
+ wmem_list_frame_t *frame;
+ wmem_list_t *ioobject_list;
sub_item = proto_tree_add_item(tree, hf_pn_io_data_description_tree, tvb, offset, 0, ENC_NA);
sub_tree = proto_item_add_subtree(sub_item, ett_pn_io_data_description);
@@ -7875,6 +8046,46 @@ dissect_DataDescription(tvbuff_t *tvb, int offset,
u16SubmoduleDataLength, u8LengthIOCS, u8LengthIOPS);
proto_item_set_len(sub_item, offset - u32SubStart);
+ /* Save new data for IO Data Objects */
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Get current conversation endpoints using MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+
+ if (station_info != NULL) {
+ if (u16DataDescription == PN_INPUT_DATADESCRITPION) {
+ /* INPUT HANDLING */
+ ioobject_list = station_info->ioobject_data_in;
+ }
+ else {
+ /* OUTPUT HANDLING */
+ ioobject_list = station_info->ioobject_data_out;
+ }
+
+ for (frame = wmem_list_head(ioobject_list); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (io_data_object->slotNr == tmp_io_data_object->slotNr && io_data_object->subSlotNr == tmp_io_data_object->subSlotNr) {
+ /* Write additional data from dissect_ExpectedSubmoduleBlockReq_block() to corresponding io_data_object */
+ io_data_object->moduleIdentNr = tmp_io_data_object->moduleIdentNr;
+ io_data_object->subModuleIdentNr = tmp_io_data_object->subModuleIdentNr;
+ io_data_object->length = u16SubmoduleDataLength;
+
+ io_data_object->moduleNameStr = wmem_strdup(wmem_file_scope(), tmp_io_data_object->moduleNameStr);
+ io_data_object->profisafeSupported = tmp_io_data_object->profisafeSupported;
+ io_data_object->discardIOXS = tmp_io_data_object->discardIOXS;
+ io_data_object->amountInGSDML = tmp_io_data_object->amountInGSDML;
+ io_data_object->fParameterIndexNr = tmp_io_data_object->fParameterIndexNr;
+
+ break;
+ }
+ }
+ }
+ }
+
return offset;
}
@@ -7902,6 +8113,60 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
proto_tree *submodule_tree;
guint32 u32SubStart;
+ /* Variable for the search of gsd file */
+ const char vendorIdStr[] = "VendorID=\"";
+ const char deviceIdStr[] = "DeviceID=\"";
+ const char moduleStr[] = "ModuleIdentNumber=\"";
+ const char subModuleStr[] = "SubmoduleIdentNumber=\"";
+ const char profisafeStr[] = "PROFIsafeSupported=\"true\"";
+ const char fParameterStr[] = "<F_ParameterRecordDataItem";
+ const char fParameterIndexStr[] = "Index=";
+ const char moduleNameInfo[] = "<Name";
+ const char moduleValueInfo[] = "Value=\"";
+
+ guint16 searchVendorID = 0;
+ guint16 searchDeviceID = 0;
+ gint32 filePosRecord;
+ gboolean vendorMatch;
+ gboolean deviceMatch;
+ conversation_t *conversation;
+ stationInfo *station_info = NULL;
+ ioDataObject *io_data_object = NULL; /* Used to transfer data to fct. "dissect_DataDescription()" */
+
+ /* Variable for the search of GSD-file */
+ guint32 read_vendor_id;
+ guint32 read_device_id;
+ guint32 read_module_id;
+ guint32 read_submodule_id;
+ gboolean gsdmlFoundFlag;
+ gchar tmp_moduletext[MAX_NAMELENGTH];
+ gchar *convertStr; /* GSD-file search */
+ gchar *pch; /* helppointer, to save temp. the found Networkpath of GSD-file */
+ gchar *puffer; /* used for fgets() during GSD-file search */
+ gchar *temp; /* used for fgets() during GSD-file search */
+ gchar *diropen = NULL; /* saves the final networkpath to open for GSD-files */
+ GDir *dir;
+ FILE *fp = NULL; /* filepointer */
+ const gchar *filename; /* saves the found GSD-file name */
+
+ /* Helppointer initial */
+ convertStr = (gchar*)wmem_alloc(wmem_packet_scope(), MAX_NAMELENGTH);
+ convertStr[0] = '\0';
+ pch = (gchar*)wmem_alloc(wmem_packet_scope(), MAX_LINE_LENGTH);
+ pch[0] = '\0';
+ puffer = (gchar*)wmem_alloc(wmem_packet_scope(), MAX_LINE_LENGTH);
+ puffer[0] = '\0';
+ temp = (gchar*)wmem_alloc(wmem_packet_scope(), MAX_LINE_LENGTH);
+ temp[0] = '\0';
+
+ /* Initial */
+ io_data_object = wmem_new0(wmem_file_scope(), ioDataObject);
+ io_data_object->profisafeSupported = FALSE;
+ io_data_object->moduleNameStr = wmem_strdup(wmem_file_scope(), "Unknown");
+ vendorMatch = FALSE;
+ deviceMatch = FALSE;
+ gsdmlFoundFlag = FALSE;
+
if (u8BlockVersionHigh != 1 || u8BlockVersionLow != 0) {
expert_add_info_format(pinfo, item, &ei_pn_io_block_version,
@@ -7914,6 +8179,102 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
proto_item_append_text(item, ": APIs:%u", u16NumberOfAPIs);
+
+ /* Get current conversation endpoints using MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info != NULL) {
+ station_info->gsdFound = FALSE;
+ station_info->gsdPathLength = FALSE;
+
+ /* Set searchVendorID and searchDeviceID for GSDfile search */
+ searchVendorID = station_info->u16Vendor_id;
+ searchDeviceID = station_info->u16Device_id;
+
+ /* Use the given GSD-file networkpath of the PNIO-Preference */
+ if(pnio_ps_networkpath[0] != '\0') { /* check the length of the given networkpath (array overflow protection) */
+ station_info->gsdPathLength = TRUE;
+
+ if ((dir = g_dir_open(pnio_ps_networkpath, 0, NULL)) != NULL) {
+ /* Find all GSD-files within directory */
+ while ((filename = g_dir_read_name(dir)) != NULL) {
+
+ /* ---- complete the path to open a GSD-file ---- */
+ diropen = wmem_strdup_printf(wmem_packet_scope(), "%s" G_DIR_SEPARATOR_S "%s", pnio_ps_networkpath, filename);
+
+ /* ---- Open the found GSD-file ---- */
+ fp = ws_fopen(diropen, "r");
+
+ if(fp != NULL) {
+ /* ---- Get VendorID & DeviceID ---- */
+ while(fp != NULL && fgets(puffer, MAX_LINE_LENGTH, fp) != NULL) {
+ /* ----- VendorID ------ */
+ if((strstr(puffer, vendorIdStr)) != NULL) {
+ memset (convertStr, 0, sizeof(*convertStr));
+ pch = strstr(puffer, vendorIdStr);
+ sscanf(pch, "VendorID=\"%[^\"]", convertStr);
+ read_vendor_id = (guint32) strtoul (convertStr, NULL, 0);
+
+ if(read_vendor_id == searchVendorID) {
+ vendorMatch = TRUE; /* found correct VendorID */
+ }
+ }
+
+ /* ----- DeviceID ------ */
+ if((strstr(puffer, deviceIdStr)) != NULL) {
+ memset(convertStr, 0, sizeof(*convertStr));
+ pch = strstr(puffer, deviceIdStr);
+ sscanf(pch, "DeviceID=\"%[^\"]", convertStr);
+ read_device_id = (guint32)strtoul(convertStr, NULL, 0);
+
+ if(read_device_id == searchDeviceID) {
+ deviceMatch = TRUE; /* found correct DeviceID */
+ }
+ }
+ }
+
+ if(fclose(fp) == 0) {
+ /* File close sucessfull */
+ fp = NULL;
+ }
+
+ if(vendorMatch == TRUE && deviceMatch == TRUE) {
+ break; /* Found correct GSD-file! -> Break the searchloop */
+ }
+ else {
+ /* Couldn't find the correct GSD-file to the corresponding device */
+ vendorMatch = FALSE;
+ deviceMatch = FALSE;
+ gsdmlFoundFlag = FALSE;
+ diropen = ""; /* reset array for next search */
+ }
+ }
+ }
+
+ g_dir_close(dir);
+ }
+
+ /* ---- Found the correct GSD-file -> set Flag and save the completed path ---- */
+ if((vendorMatch == TRUE) && (deviceMatch == TRUE)) {
+ gsdmlFoundFlag = TRUE;
+ station_info->gsdFound = TRUE;
+ station_info->gsdLocation = wmem_strdup(wmem_file_scope(), diropen);
+ }
+ else {
+ /* Copy searchpath to array for a detailed output message in cyclic data dissection */
+ station_info->gsdLocation = wmem_strdup_printf(wmem_file_scope(), "%s" G_DIR_SEPARATOR_S "*.xml", pnio_ps_networkpath);
+ }
+ }
+ else {
+ /* will be used later on in cyclic RTC1 data dissection for detailed output message */
+ station_info->gsdPathLength = FALSE;
+ }
+ }
+
while (u16NumberOfAPIs--) {
api_item = proto_tree_add_item(tree, hf_pn_io_api_tree, tvb, offset, 0, ENC_NA);
api_tree = proto_item_add_subtree(api_item, ett_pn_io_api);
@@ -7967,19 +8328,129 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset,
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, submodule_tree, drep,
hf_pn_io_submodule_properties_type, &u16SubmoduleProperties);
+ io_data_object->slotNr = u16SlotNr;
+ io_data_object->subSlotNr = u16SubslotNr;
+ io_data_object->moduleIdentNr = u32ModuleIdentNumber;
+ io_data_object->subModuleIdentNr = u32SubmoduleIdentNumber;
+ io_data_object->discardIOXS = u16SubmoduleProperties & 0x0020;
+
+ /* Search the moduleID and subModuleID, find if PROFIsafe and also search for F-Par. Indexnumber
+ * ---------------------------------------------------------------------------------------------
+ * Speical case: Module has several ModuleIdentNr. in one GSD-file
+ * Also with the given parameters of wireshark, some modules were completely equal. For this
+ * special case a compromise for this problem has been made, to set the module name will
+ * be more generally displayed.
+ * Also this searchloop will find the F-Parameter Indexnumber, so that Wireshark is able to
+ * dissect those F-Parameters correctly, as this index can change between the vendors.
+ */
+
+ io_data_object->amountInGSDML = 0;
+ io_data_object->fParameterIndexNr = 0;
+ io_data_object->profisafeSupported = FALSE;
+
+ if (diropen != NULL) {
+ fp = ws_fopen(diropen, "r");
+ }
+ if(gsdmlFoundFlag == TRUE && fp != NULL) {
+ fseek(fp, 0, SEEK_SET);
+
+ /* Find Indexnumber for fParameter */
+ while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
+ if((strstr(temp, fParameterStr)) != NULL) {
+ memset (convertStr, 0, sizeof(*convertStr));
+
+ pch = strstr(temp, fParameterIndexStr);
+ sscanf(pch, "Index=\"%[^\"]", convertStr);
+ io_data_object->fParameterIndexNr = (guint32)strtoul(convertStr, NULL, 0);
+
+ break; /* found Indexnumber -> break search loop */
+ }
+ }
+
+ memset (temp, 0, sizeof(*temp));
+ fseek(fp, 0, SEEK_SET); /* Set filepointer to the beginning */
+
+ while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
+ if((strstr(temp, moduleStr)) != NULL) { /* find the String "ModuleIdentNumber=" */
+ memset (convertStr, 0, sizeof(*convertStr));
+ pch = strstr(temp, moduleStr); /* search for "ModuleIdentNumber=\"" within GSD-file */
+ sscanf(pch, "ModuleIdentNumber=\"%[^\"]", convertStr); /* Change format of Value string-->numeric string */
+ read_module_id = (guint32)strtoul(convertStr, NULL, 0); /* Change numeric string --> unsigned long; read_module_id contains the Value of the ModuleIdentNumber */
+
+ /* If the found ModuleID matches with the wanted ModuleID, search for the Submodule and break */
+ if (read_module_id == io_data_object->moduleIdentNr) {
+ ++io_data_object->amountInGSDML; /* Save the amount of same (!) Module- & SubmoduleIdentNr in one GSD-file */
+
+ while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
+ if((strstr(temp, moduleNameInfo)) != NULL) { /* find the String "<Name" for the TextID */
+ sscanf(temp, "%*s TextId=\"%[^\"]", tmp_moduletext); /* saves the correct TextId for the next searchloop */
+
+ filePosRecord = (gint32)ftell(fp); /* save the current position of the filepointer (Offset) */
+
+ while (fgets(temp, MAX_LINE_LENGTH, fp) != NULL && io_data_object->amountInGSDML == 1) {
+ /* Find a String with the saved TextID and with a fitting value for it in the same line. This value is the name of the Module! */
+ if(((strstr(temp, tmp_moduletext)) != NULL) && ((strstr(temp, moduleValueInfo)) != NULL)) {
+ pch = strstr(temp, moduleValueInfo);
+ sscanf(pch, "Value=\"%[^\"]", io_data_object->moduleNameStr);
+ break; /* Found the name of the module */
+ }
+ }
+
+ fseek(fp, filePosRecord, SEEK_SET); /* set filepointer to the correct TextID */
+ }
+
+ /* Search for Submoduleidentnumber in GSD-file */
+ if((strstr(temp, subModuleStr)) != NULL) {
+ memset (convertStr, 0, sizeof(*convertStr));
+ pch = strstr(temp, subModuleStr);
+ sscanf(pch, "SubmoduleIdentNumber=\"%[^\"]", convertStr);
+ read_submodule_id = (guint32) strtoul (convertStr, NULL, 0); /* read_submodule_id contains the Value of the SubModuleIdentNumber */
+
+ /* Find "PROFIsafeSupported" flag of the module in GSD-file */
+ if(read_submodule_id == io_data_object->subModuleIdentNr) {
+ if((strstr(temp, profisafeStr)) != NULL) {
+ io_data_object->profisafeSupported = TRUE; /* flag is in the same line as SubmoduleIdentNr */
+ break;
+ }
+ else { /* flag is not in the same line as Submoduleidentnumber -> search for it */
+ while(fgets(temp, MAX_LINE_LENGTH, fp) != NULL) {
+ if((strstr(temp, profisafeStr)) != NULL) {
+ io_data_object->profisafeSupported = TRUE;
+ break; /* Found the PROFIsafeSupported flag of the module */
+ }
+
+ else if((strstr(temp, ">")) != NULL) {
+ break;
+ }
+ }
+ }
+ }
+ break; /* Found the PROFIsafe Module */
+ }
+ }
+ }
+ }
+ }
+
+ if (fclose(fp) == 0) {
+ /* File close successful */
+ fp = NULL;
+ }
+ }
+
switch (u16SubmoduleProperties & 0x03) {
case(0x00): /* no input and no output data (one Input DataDescription Block follows) */
- offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep);
+ offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep, io_data_object);
break;
case(0x01): /* input data (one Input DataDescription Block follows) */
- offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep);
+ offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep, io_data_object);
break;
case(0x02): /* output data (one Output DataDescription Block follows) */
- offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep);
+ offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep, io_data_object);
break;
case(0x03): /* input and output data (one Input and one Output DataDescription Block follows) */
- offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep);
- offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep);
+ offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep, io_data_object);
+ offset = dissect_DataDescription(tvb, offset, pinfo, sub_tree, drep, io_data_object);
break;
}
@@ -8022,6 +8493,11 @@ dissect_ModuleDiffBlock_block(tvbuff_t *tvb, int offset,
proto_tree *submodule_tree;
guint32 u32SubStart;
+ conversation_t *conversation;
+ stationInfo *station_info;
+ wmem_list_frame_t *frame;
+ moduleDiffInfo *module_diff_info;
+ moduleDiffInfo *cmp_module_diff_info;
if (u8BlockVersionHigh != 1 || u8BlockVersionLow != 0) {
expert_add_info_format(pinfo, item, &ei_pn_io_block_version,
@@ -8075,6 +8551,34 @@ dissect_ModuleDiffBlock_block(tvbuff_t *tvb, int offset,
val_to_str(u16ModuleState, pn_io_module_state, "(0x%x)"),
u16NumberOfSubmodules);
+
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Get current conversation endpoints using MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info != NULL) {
+ for (frame = wmem_list_head(station_info->diff_module); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ cmp_module_diff_info = (moduleDiffInfo*)wmem_list_frame_data(frame);
+ if (cmp_module_diff_info->slotNr == u16SlotNr) {
+ /* Found identical existing object */
+ break;
+ }
+ }
+
+ if (frame == NULL) {
+ /* new diffModuleInfo data incoming */
+ module_diff_info = wmem_new(wmem_file_scope(), moduleDiffInfo);
+ module_diff_info->slotNr = u16SlotNr;
+ module_diff_info->modulID = u32ModuleIdentNumber;
+ wmem_list_append(station_info->diff_module, module_diff_info);
+ }
+ }
+ }
+
proto_item_append_text(item, ", Submodules:%u", u16NumberOfSubmodules);
while (u16NumberOfSubmodules--) {
@@ -9224,7 +9728,7 @@ dissect_IPNIO_Read_resp(tvbuff_t *tvb, int offset,
/* F-Parameter record data object */
static int
dissect_ProfiSafeParameterRequest(tvbuff_t *tvb, int offset,
- packet_info *pinfo, proto_tree *tree, guint8 *drep)
+ packet_info *pinfo, proto_tree *tree, guint8 *drep, guint16 u16Index, wmem_list_frame_t *frame)
{
proto_item *f_item;
proto_tree *f_tree;
@@ -9236,79 +9740,204 @@ dissect_ProfiSafeParameterRequest(tvbuff_t *tvb, int offset,
guint16 dst_addr;
guint16 wd_time;
guint16 par_crc;
+ guint32 ipar_crc;
guint8 prm_flag1;
guint8 prm_flag1_chck_seq;
guint8 prm_flag1_chck_ipar;
guint8 prm_flag1_sil;
guint8 prm_flag1_crc_len;
+ guint8 prm_flag1_crc_seed;
guint8 prm_flag1_reserved;
guint8 prm_flag2;
guint8 prm_flag2_reserved;
guint8 prm_flag2_f_block_id;
guint8 prm_flag2_f_par_version;
+ conversation_t *conversation;
+ stationInfo *station_info;
+ ioDataObject *io_data_object;
+ wmem_list_frame_t *frame_out;
+
f_item = proto_tree_add_item(tree, hf_pn_io_block, tvb, offset, 0, ENC_NA);
f_tree = proto_item_add_subtree(f_item, ett_pn_io_profisafe_f_parameter);
proto_item_set_text(f_item, "F-Parameter: ");
-
- flags1_item = proto_tree_add_item(f_tree, hf_pn_io_profisafe_f_prm_flag1, tvb, offset, 1, ENC_BIG_ENDIAN);
+ flags1_item = proto_tree_add_item(f_tree, hf_pn_io_ps_f_prm_flag1, tvb, offset, 1, ENC_BIG_ENDIAN);
flags1_tree = proto_item_add_subtree(flags1_item, ett_pn_io_profisafe_f_parameter_prm_flag1);
+ /* dissection of F_Prm_Flag1 */
+ dissect_dcerpc_uint8(tvb, offset, pinfo, flags1_tree, drep,
+ hf_pn_io_ps_f_prm_flag1_chck_seq, &prm_flag1_chck_seq);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags1_tree, drep,
- hf_pn_io_profisafe_f_prm_flag1_chck_seq, &prm_flag1_chck_seq);
+ hf_pn_io_ps_f_prm_flag1_chck_ipar, &prm_flag1_chck_ipar);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags1_tree, drep,
- hf_pn_io_profisafe_f_prm_flag1_chck_ipar, &prm_flag1_chck_ipar);
+ hf_pn_io_ps_f_prm_flag1_sil, &prm_flag1_sil);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags1_tree, drep,
- hf_pn_io_profisafe_f_prm_flag1_sil, &prm_flag1_sil);
+ hf_pn_io_ps_f_prm_flag1_crc_len, &prm_flag1_crc_len);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags1_tree, drep,
- hf_pn_io_profisafe_f_prm_flag1_crc_len, &prm_flag1_crc_len);
+ hf_pn_io_ps_f_prm_flag1_crc_seed, &prm_flag1_crc_seed);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags1_tree, drep,
- hf_pn_io_profisafe_f_prm_flag1_reserved, &prm_flag1_reserved);
- prm_flag1 = prm_flag1_chck_seq|prm_flag1_chck_ipar|prm_flag1_sil|prm_flag1_reserved;
+ hf_pn_io_ps_f_prm_flag1_reserved, &prm_flag1_reserved);
+ prm_flag1 = prm_flag1_chck_seq|prm_flag1_chck_ipar|prm_flag1_sil|prm_flag1_crc_len|prm_flag1_crc_seed|prm_flag1_reserved;
offset++;
- flags2_item = proto_tree_add_item(f_tree, hf_pn_io_profisafe_f_prm_flag2, tvb, offset, 1, ENC_BIG_ENDIAN);
+ flags2_item = proto_tree_add_item(f_tree, hf_pn_io_ps_f_prm_flag2, tvb, offset, 1, ENC_BIG_ENDIAN);
flags2_tree = proto_item_add_subtree(flags2_item, ett_pn_io_profisafe_f_parameter_prm_flag2);
+ /* dissection of F_Prm_Flag2 */
dissect_dcerpc_uint8(tvb, offset, pinfo, flags2_tree, drep,
- hf_pn_io_profisafe_f_prm_flag2_reserved, &prm_flag2_reserved);
+ hf_pn_io_ps_f_prm_flag2_reserved, &prm_flag2_reserved);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags2_tree, drep,
- hf_pn_io_profisafe_f_prm_flag2_f_block_id, &prm_flag2_f_block_id);
+ hf_pn_io_ps_f_prm_flag2_f_block_id, &prm_flag2_f_block_id);
dissect_dcerpc_uint8(tvb, offset, pinfo, flags2_tree, drep,
- hf_pn_io_profisafe_f_prm_flag2_f_par_version, &prm_flag2_f_par_version);
+ hf_pn_io_ps_f_prm_flag2_f_par_version, &prm_flag2_f_par_version);
prm_flag2 = prm_flag2_reserved|prm_flag2_f_block_id|prm_flag2_f_par_version;
offset++;
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, f_item, drep,
- hf_pn_io_profisafe_f_src_addr, &src_addr);
+ hf_pn_io_ps_f_src_adr, &src_addr);
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, f_item, drep,
- hf_pn_io_profisafe_f_dst_addr, &dst_addr);
+ hf_pn_io_ps_f_dest_adr, &dst_addr);
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, f_item, drep,
- hf_pn_io_profisafe_f_wd_time, &wd_time);
+ hf_pn_io_ps_f_wd_time, &wd_time);
+
+ /* Dissection for F_iPar_CRC: see F_Prm_Flag2 -> F_Block_ID */
+ if( ((prm_flag2_f_block_id & 0x08)>>3) == TRUE && ((prm_flag2_f_block_id & 0x20)>>5) == FALSE ) {
+ offset = dissect_dcerpc_uint32(tvb, offset, pinfo, f_item, drep,
+ hf_pn_io_ps_f_ipar_crc, &ipar_crc);
+ }
+
offset = dissect_dcerpc_uint16(tvb, offset, pinfo, f_item, drep,
- hf_pn_io_profisafe_f_par_crc, &par_crc);
+ hf_pn_io_ps_f_par_crc, &par_crc);
+
+
+ /* Differniate between ipar_crc and no_ipar_crc */
+ if( ((prm_flag2_f_block_id & 0x08)>>3) == TRUE && ((prm_flag2_f_block_id & 0x20)>>5) == FALSE ) { /* include ipar_crc display */
+ col_append_fstr(pinfo->cinfo, COL_INFO,
+ ", F-Parameter record, prm_flag1:0x%02x, prm_flag2:0x%02x, src:0x%04x,"
+ " dst:0x%04x, wd_time:%d, ipar_crc:0x%04x, crc:0x%04x",
+ prm_flag1, prm_flag2, src_addr, dst_addr, wd_time, ipar_crc, par_crc);
+
+ proto_item_append_text(f_item, "prm_flag1:0x%02x, prm_flag2:0x%02x, src:0x%04x, dst:0x%04x, wd_time:%d, ipar_crc:0x%04x, par_crc:0x%04x",
+ prm_flag1, prm_flag2, src_addr, dst_addr, wd_time, ipar_crc, par_crc);
+ }
+ else { /* exclude ipar_crc display */
+ col_append_fstr(pinfo->cinfo, COL_INFO,
+ ", F-Parameter record, prm_flag1:0x%02x, prm_flag2:0x%02x, src:0x%04x,"
+ " dst:0x%04x, wd_time:%d, crc:0x%04x",
+ prm_flag1, prm_flag2, src_addr, dst_addr, wd_time, par_crc);
+
+ proto_item_append_text(f_item, "prm_flag1:0x%02x, prm_flag2:0x%02x, src:0x%04x, dst:0x%04x, wd_time:%d, par_crc:0x%04x",
+ prm_flag1, prm_flag2, src_addr, dst_addr, wd_time, par_crc);
+ }
+
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Get current conversation endpoints using MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
- col_append_fstr(pinfo->cinfo, COL_INFO,
- ", F-Parameter record, prm_flag1:0x%02x, prm_flag2:0x%02x, src:0x%04x,"
- " dst:0x%04x, wd_time:%d, crc:0x%04x",
- prm_flag1, prm_flag2, src_addr, dst_addr, wd_time, par_crc);
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info != NULL) {
+ if (frame != NULL) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+
+ io_data_object->f_par_crc1 = par_crc;
+ io_data_object->f_src_adr = src_addr;
+ io_data_object->f_dest_adr = dst_addr;
+ io_data_object->f_crc_seed = prm_flag1 & 0x40;
+ if ((prm_flag1 & 0x10) == FALSE && (prm_flag1 & 0x20) == FALSE) {
+ io_data_object->f_crc_len = 3;
+ }
+ if ((prm_flag1 & 0x10) == FALSE && (prm_flag1 & 0x20) == TRUE) {
+ io_data_object->f_crc_len = 4;
+ }
+ }
- proto_item_append_text(f_item, "prm_flag1:0x%02x, prm_flag2:0x%02x, src:0x%04x, dst:0x%04x, wd_time:%d, crc:0x%04x",
- prm_flag1, prm_flag2, src_addr, dst_addr, wd_time, par_crc);
+ /* Find same module within output data to saved data */
+ for (frame_out = wmem_list_head(station_info->ioobject_data_out); frame_out != NULL; frame_out = wmem_list_frame_next(frame_out)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame_out);
+ if (u16Index == io_data_object->fParameterIndexNr && /* Check F-Parameter Indexnumber */
+ io_data_object->profisafeSupported == TRUE && /* Arrayelement has to be PS-Module */
+ io_data_object->f_par_crc1 == 0) { /* Find following object with no f_par_crc1 */
+
+ io_data_object->f_par_crc1 = par_crc;
+ io_data_object->f_src_adr = src_addr;
+ io_data_object->f_dest_adr = dst_addr;
+ io_data_object->f_crc_seed = prm_flag1 & 0x40;
+ if ((prm_flag1 & 0x10) == FALSE && (prm_flag1 & 0x20) == FALSE) {
+ io_data_object->f_crc_len = 3;
+ }
+ if ((prm_flag1 & 0x10) == FALSE && (prm_flag1 & 0x20) == TRUE) {
+ io_data_object->f_crc_len = 4;
+ }
+
+ break;
+ }
+ }
+ }
+ }
return offset;
}
+
static int
dissect_RecordDataWrite(tvbuff_t *tvb, int offset,
packet_info *pinfo, proto_tree *tree, guint8 *drep, guint16 u16Index, guint32 u32RecDataLen)
{
+ conversation_t *conversation;
+ stationInfo *station_info;
+ wmem_list_frame_t *frame;
+ ioDataObject *io_data_object;
+
const gchar *userProfile;
pnio_ar_t *ar = NULL;
/* PROFISafe */
- if (u16Index == 0x0100) {
- return dissect_ProfiSafeParameterRequest(tvb, offset, pinfo, tree, drep);
+ /* Get current conversation endpoints using MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info != NULL) {
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Search within the entire existing list for current input object data */
+ for (frame = wmem_list_head(station_info->ioobject_data_in); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (u16Index == io_data_object->fParameterIndexNr && /* Check F-Parameter Indexnumber */
+ io_data_object->profisafeSupported == TRUE && /* Arrayelement has to be PS-Module */
+ io_data_object->f_par_crc1 == 0) { /* Find following object with no f_par_crc1 */
+
+ return dissect_ProfiSafeParameterRequest(tvb, offset, pinfo, tree, drep, u16Index, frame);
+ }
+ }
+ }
+ else {
+ /* User clicked another time the frame to see the data -> PROFIsafe data has already been saved
+ * Check whether the device contains an PROFIsafe supported submodule.
+ */
+
+ for (frame = wmem_list_head(station_info->ioobject_data_in); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (u16Index == io_data_object->fParameterIndexNr && /* Check F-Parameter Indexnumber */
+ io_data_object->profisafeSupported == TRUE) { /* Arrayelement has to be PS-Module */
+
+ return dissect_ProfiSafeParameterRequest(tvb, offset, pinfo, tree, drep, u16Index, frame);
+ }
+ }
+
+ for (frame = wmem_list_head(station_info->ioobject_data_out); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (u16Index == io_data_object->fParameterIndexNr && /* Check F-Parameter Indexnumber */
+ io_data_object->profisafeSupported == TRUE) { /* Arrayelement has to be PS-Module */
+
+ return dissect_ProfiSafeParameterRequest(tvb, offset, pinfo, tree, drep, u16Index, frame);
+ }
+ }
+ }
}
/* user specified format? */
@@ -9494,17 +10123,16 @@ static int
dissect_PNIO_C_SDU(tvbuff_t *tvb, int offset,
packet_info *pinfo, proto_tree *tree, guint8 *drep _U_)
{
- proto_tree *data_tree = NULL;
- /*gint iTotalLen = 0;*/
- /*gint iSubFrameLen = 0;*/
-
+ proto_tree *data_tree = NULL;
+ /* gint iTotalLen = 0; */
+ /* gint iSubFrameLen = 0; */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PNIO");
if (tree) {
proto_item *data_item;
data_item = proto_tree_add_protocol_format(tree, proto_pn_io, tvb, offset, tvb_captured_length(tvb),
- "PROFINET IO Cyclic Service Data Unit: %u bytes", tvb_captured_length(tvb));
+ "PROFINET IO Cyclic Service Data Unit: %u bytes", tvb_captured_length(tvb));
data_tree = proto_item_add_subtree(data_item, ett_pn_io_rtc);
}
@@ -9519,8 +10147,7 @@ dissect_PNIO_C_SDU(tvbuff_t *tvb, int offset,
/* actual: there may be an IOxS but most case there isn't so better display a data-stream */
/* offset = dissect_PNIO_IOxS(tvb, offset, pinfo, data_tree, drep, hf_pn_io_ioxs); */
offset = dissect_pn_user_data(tvb, offset, pinfo, tree, tvb_captured_length_remaining(tvb, offset),
- "User Data (including GAP and RTCPadding)");
-
+ "User Data (including GAP and RTCPadding)");
return offset;
}
@@ -9650,21 +10277,16 @@ dissect_PNIO_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* is this a (none DFP) PNIO class 3 data packet? */
/* frame id must be in valid range (cyclic Real-Time, class=3) */
- if ((u16FrameID >= 0x0100 && u16FrameID <= 0x6FF /*0x04ff*/) || /* non redundant */
- (u16FrameID >= 0x700/*0x0800*/ && u16FrameID <= 0x0fff)) { /* redundant */
+ if ((u16FrameID >= 0x0100 && u16FrameID <= 0x06FF) || /* RTC3 non redundant */
+ (u16FrameID >= 0x700 && u16FrameID <= 0x0fff)) { /* RTC3 redundant */
dissect_PNIO_C_SDU(tvb, 0, pinfo, tree, drep);
return TRUE;
}
- /* is this a (none DFP) PNIO class 2 data packet? */
- /* frame id must be in valid range (cyclic Real-Time, class=2) and
+ /* The following range is reserved for following developments */
+ /* frame id must be in valid range (Reserved) and
* first byte (CBA version field) has to be != 0x11 */
- if ((
- (u16FrameID >= 0x5000 && u16FrameID <= 0x57ff) || /* redundant */
- (u16FrameID >= 0x6000 && u16FrameID <= 0x67ff) || /* non redundant */
- (u16FrameID >= 0x7000 && u16FrameID <= 0x77ff) || /* redundant */
- (u16FrameID >= 0x8000 && u16FrameID <= 0xbfff)) /* non redundant */
- && u8CBAVersion != 0x11) {
+ if (u16FrameID >= 0x1000 && u16FrameID <= 0x7fff && u8CBAVersion != 0x11) {
dissect_PNIO_C_SDU(tvb, 0, pinfo, tree, drep);
return TRUE;
}
@@ -9672,8 +10294,16 @@ dissect_PNIO_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* 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 >= 0x8000 && u16FrameID < 0xbfff && u8CBAVersion != 0x11) {
+ dissect_PNIO_C_SDU_RTC1(tvb, 0, pinfo, tree, drep);
+ return TRUE;
+ }
+
+ /* is this a PNIO class 1 (legacy) data packet? */
+ /* frame id must be in valid range (cyclic Real-Time, class=1, legacy) and
+ * first byte (CBA version field) has to be != 0x11 */
if (u16FrameID >= 0xc000 && u16FrameID < 0xfbff && u8CBAVersion != 0x11) {
- dissect_PNIO_C_SDU(tvb, 0, pinfo, tree, drep);
+ dissect_PNIO_C_SDU_RTC1(tvb, 0, pinfo, tree, drep);
return TRUE;
}
@@ -10260,11 +10890,6 @@ proto_register_pn_io (void)
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
- { &hf_pn_io_io_data_object_frame_offset,
- { "IODataObjectFrameOffset", "pn_io.io_data_object_frame_offset",
- FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
- NULL, HFILL }
- },
{ &hf_pn_io_number_of_iocs,
{ "NumberOfIOCS", "pn_io.number_of_iocs",
FT_UINT16, BASE_DEC, NULL, 0x0,
@@ -10355,6 +10980,11 @@ proto_register_pn_io (void)
FT_NONE, BASE_NONE, NULL, 0x0,
NULL, HFILL }
},
+ { &hf_pn_io_io_data_object_frame_offset,
+ { "IODataObjectFrameOffset", "pn_io.io_data_object.frame_offset",
+ FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
{ &hf_pn_io_io_cs,
{ "IOCS", "pn_io.io_cs",
FT_NONE, BASE_NONE, NULL, 0x0,
@@ -12070,76 +12700,85 @@ proto_register_pn_io (void)
FT_UINT16, BASE_HEX, NULL, 0x0001,
NULL, HFILL }
},
-
- /* profisafe parameter */
- { &hf_pn_io_profisafe_f_prm_flag1,
- { "F_Prm_Flag1", "pn_io.profisafe.f_prm_flag1",
+ /* PROFIsafe F-Parameter */
+ { &hf_pn_io_ps_f_prm_flag1,
+ { "F_Prm_Flag1", "pn_io.ps.f_prm_flag1",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag1_chck_seq,
- { "F_Check_SeqNr", "pn_io.profisafe.f_prm_flag1.f_check_seqnr",
+ { &hf_pn_io_ps_f_prm_flag1_chck_seq,
+ { "F_Check_SeqNr", "pn_io.ps.f_prm_flag1.f_check_seqnr",
FT_UINT8, BASE_HEX, VALS(pn_io_f_check_seqnr), 0x01,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag1_chck_ipar,
- { "F_Check_iPar", "pn_io.profisafe.f_prm_flag1.f_check_ipar",
+ { &hf_pn_io_ps_f_prm_flag1_chck_ipar,
+ { "F_Check_iPar", "pn_io.ps.f_prm_flag1.f_check_ipar",
FT_UINT8, BASE_HEX, VALS(pn_io_f_check_ipar), 0x02,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag1_sil,
- { "F_SIL", "pn_io.profisafe.f_prm_flag1.f_sil",
+ { &hf_pn_io_ps_f_prm_flag1_sil,
+ { "F_SIL", "pn_io.ps.f_prm_flag1.f_sil",
FT_UINT8, BASE_HEX, VALS(pn_io_f_sil), 0xc,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag1_crc_len,
- { "F_CRC_Length", "pn_io.profisafe.f_prm_flag1.f_crc_len",
+ { &hf_pn_io_ps_f_prm_flag1_crc_len,
+ { "F_CRC_Length", "pn_io.ps.f_prm_flag1.f_crc_len",
FT_UINT8, BASE_HEX, VALS(pn_io_f_crc_len), 0x30,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag1_reserved,
- { "Reserved", "pn_io.profisafe.f_prm_flag1.reserved",
- FT_UINT8, BASE_HEX, NULL, 0xC0,
+ { &hf_pn_io_ps_f_prm_flag1_crc_seed,
+ { "F_CRC_Seed", "pn_io.ps.f_prm_flag1.f_crc_seed",
+ FT_UINT8, BASE_HEX, VALS(pn_io_f_crc_seed), 0x40,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag2,
- { "F_Prm_Flag2", "pn_io.profisafe.f_prm_flag2",
+ { &hf_pn_io_ps_f_prm_flag1_reserved,
+ { "Reserved", "pn_io.ps.f_prm_flag1.reserved",
+ FT_UINT8, BASE_HEX, NULL, 0x80,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_f_prm_flag2,
+ { "F_Prm_Flag2", "pn_io.ps.f_prm_flag2",
FT_UINT8, BASE_HEX, NULL, 0x0,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag2_reserved,
- { "Reserved", "pn_io.profisafe.f_prm_flag2.reserved",
+ { &hf_pn_io_ps_f_prm_flag2_reserved,
+ { "Reserved", "pn_io.ps.f_prm_flag2.reserved",
FT_UINT8, BASE_HEX, NULL, 0x07,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag2_f_block_id,
- { "F_BlockId", "pn_io.profisafe.f_prm_flag2.f_block_id",
+ { &hf_pn_io_ps_f_prm_flag2_f_block_id,
+ { "F_Block_ID", "pn_io.ps.f_prm_flag2.f_block_id",
FT_UINT8, BASE_HEX, VALS(pn_io_f_block_id), 0x38,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_prm_flag2_f_par_version,
- { "F_ParVersion", "pn_io.profisafe.f_prm_flag2.f_par_version",
+ { &hf_pn_io_ps_f_prm_flag2_f_par_version,
+ { "F_Par_Version", "pn_io.ps.f_prm_flag2.f_par_version",
FT_UINT8, BASE_HEX, VALS(pn_io_f_par_version), 0xC0,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_src_addr,
- { "F_Source_Address", "pn_io.profisafe.f_src_addr",
- FT_UINT16, BASE_HEX, NULL, 0x0,
- NULL, HFILL }
- },
- { &hf_pn_io_profisafe_f_dst_addr,
- { "F_Destination_Address", "pn_io.profisafe.f_dst_addr",
- FT_UINT16, BASE_HEX, NULL, 0x0,
+ { &hf_pn_io_ps_f_wd_time,
+ { "F_WD_Time", "pn_io.ps.f_wd_time",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_f_ipar_crc,
+ { "F_iPar_CRC", "pn_io.ps.f_ipar_crc",
+ FT_UINT32, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_wd_time,
- { "F_WD_Time", "pn_io.profisafe.f_wd_time",
+ { &hf_pn_io_ps_f_par_crc,
+ { "F_Par_CRC", "pn_io.ps.f_par_crc",
FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
- { &hf_pn_io_profisafe_f_par_crc,
- { "F_Par_CRC", "pn_io.profisafe.f_par_crc",
- FT_UINT16, BASE_HEX, NULL, 0x0,
+ { &hf_pn_io_ps_f_dest_adr,
+ { "F_Dest_Add", "pn_io.ps.f_dest_add",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_f_src_adr,
+ { "F_Source_Add", "pn_io.ps.f_source_add",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
NULL, HFILL }
},
/* profidrive parameter access */
@@ -12290,10 +12929,14 @@ proto_register_pn_io (void)
{ &ei_pn_io_nr_of_tx_port_groups, { "pn_io.nr_of_tx_port_groups.not_allowed", PI_PROTOCOL, PI_WARN, "Not allowed value of NumberOfTxPortGroups", EXPFILL }},
};
+ module_t *pnio_module;
expert_module_t* expert_pn_io;
proto_pn_io = proto_register_protocol ("PROFINET IO", "PNIO", "pn_io");
+ /* Register by name */
+ register_dissector("pnio", dissect_PNIO_heur, proto_pn_io);
+
/* Created to remove Decode As confusion */
proto_pn_io_controller = proto_register_protocol ("PROFINET IO (Controller)", "PNIO (Controller)", "pn_io_controller");
proto_pn_io_supervisor = proto_register_protocol ("PROFINET IO (Supervisor)", "PNIO (Supervisor)", "pn_io_supervisor");
@@ -12304,16 +12947,32 @@ proto_register_pn_io (void)
expert_pn_io = expert_register_protocol(proto_pn_io);
expert_register_field_array(expert_pn_io, ei, array_length(ei));
+ /* Register preferences */
+ pnio_module = prefs_register_protocol(proto_pn_io, NULL);
+ prefs_register_bool_preference(pnio_module, "pnio_ps_selection",
+ "Enable detailed PROFIsafe dissection",
+ "Whether the PNIO dissector is allowed to use detailed PROFIsafe dissection of cyclic data frames",
+ &pnio_ps_selection);
+ prefs_register_directory_preference(pnio_module, "pnio_ps_networkpath",
+ "Configuration GSD-File Networkpath", /* Title */
+ "Select your Networkpath to your GSD-Files.", /* Descreption */
+ &pnio_ps_networkpath); /* Variable to save the GSD-File networkpath */
+
/* subdissector code */
register_dissector("pn_io", dissect_PNIO_heur, proto_pn_io);
heur_pn_subdissector_list = register_heur_dissector_list("pn_io", proto_pn_io);
+ /* Initialise RTC1 dissection */
+ init_pn_io_rtc1(proto_pn_io);
+
+ /* Cleanup functions of PNIO protocol */
register_cleanup_routine(pnio_cleanup);
register_conversation_filter("pn_io", "PN-IO AR", pn_io_ar_conv_valid, pn_io_ar_conv_filter);
register_conversation_filter("pn_io", "PN-IO AR (with data)", pn_io_ar_conv_valid, pn_io_ar_conv_data_filter);
}
+
void
proto_reg_handoff_pn_io (void)
{
diff --git a/plugins/profinet/packet-pn-dcp.c b/plugins/profinet/packet-pn-dcp.c
index df681aa603..2c1edc3343 100644
--- a/plugins/profinet/packet-pn-dcp.c
+++ b/plugins/profinet/packet-pn-dcp.c
@@ -21,22 +21,42 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+/*
+ * Cyclic PNIO RTC1 Data Dissection:
+ *
+ * Added new functions to packet-pn-dcp.c. The profinet plug-in will now save
+ * the information (Stationname, -type, -id) of "Ident OK" frames. Those
+ * informations will later be used for detailled dissection of cyclic PNIO RTC1
+ * dataframes.
+ *
+ * The declaration of the new added structures are within packet-pn.h to
+ * use the information within packet-pn-rtc-one.c
+ *
+ * Overview for cyclic PNIO RTC1 data dissection functions:
+ * -> dissect_PNDCP_Suboption_Device (Save Stationname, -type, -id)
+ */
+
+
#include "config.h"
#include <string.h>
+#include <glib.h>
+
#include <epan/packet.h>
#include <epan/exceptions.h>
#include <epan/to_str.h>
+#include <epan/wmem/wmem.h>
#include <epan/expert.h>
-#include <epan/dissectors/packet-dcerpc.h>
+#include <epan/conversation.h>
#include "packet-pn.h"
+
void proto_register_pn_dcp(void);
void proto_reg_handoff_pn_dcp(void);
-static int proto_pn_dcp = -1;
+int proto_pn_dcp = -1;
static int hf_pn_dcp_service_id = -1;
static int hf_pn_dcp_service_type = -1;
@@ -95,7 +115,6 @@ static gint ett_pn_dcp_block = -1;
static expert_field ei_pn_dcp_block_error_unknown = EI_INIT;
static expert_field ei_pn_dcp_ip_conflict = EI_INIT;
-
#define PNDCP_SERVICE_ID_GET 0x03
#define PNDCP_SERVICE_ID_SET 0x04
#define PNDCP_SERVICE_ID_IDENTIFY 0x05
@@ -483,7 +502,8 @@ dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint8 device_instance_low;
guint16 oem_vendor_id;
guint16 oem_device_id;
-
+ conversation_t *conversation;
+ stationInfo *station_info;
/* SuboptionDevice... */
offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_device, &suboption);
@@ -523,8 +543,28 @@ dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
val_to_str(block_info, pn_dcp_block_info, "Unknown"));
}
proto_item_append_text(block_item, ", DeviceVendorValue: \"%s\"", typeofstation);
+
+
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Create a conversation between the MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info == NULL) {
+ station_info = wmem_new0(wmem_file_scope(), stationInfo);
+ init_pnio_rtc1_station(station_info);
+ conversation_add_proto_data(conversation, proto_pn_dcp, station_info);
+ }
+
+ station_info->typeofstation = wmem_strdup(wmem_file_scope(), typeofstation);
+ }
+
offset += block_length;
break;
+
case PNDCP_SUBOPTION_DEVICE_NAMEOFSTATION:
nameofstation = (char *)wmem_alloc(wmem_packet_scope(), block_length+1);
tvb_memcpy(tvb, (guint8 *) nameofstation, offset, block_length);
@@ -541,11 +581,51 @@ dissect_PNDCP_Suboption_Device(tvbuff_t *tvb, int offset, packet_info *pinfo,
val_to_str(block_info, pn_dcp_block_info, "Unknown"));
}
proto_item_append_text(block_item, ", \"%s\"", nameofstation);
+
+
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Create a conversation between the MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info == NULL) {
+ station_info = wmem_new0(wmem_file_scope(), stationInfo);
+ init_pnio_rtc1_station(station_info);
+ conversation_add_proto_data(conversation, proto_pn_dcp, station_info);
+ }
+
+ station_info->nameofstation = wmem_strdup(wmem_file_scope(), nameofstation);
+ }
+
offset += block_length;
break;
+
case PNDCP_SUBOPTION_DEVICE_DEV_ID:
offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_vendor_id, &vendor_id);
offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_device_id, &device_id);
+
+ if (pinfo->fd->flags.visited == FALSE) {
+ /* Create a conversation between the MAC addresses */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ if (conversation == NULL) {
+ conversation = conversation_new(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+ }
+
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info == NULL) {
+ station_info = wmem_new0(wmem_file_scope(), stationInfo);
+ init_pnio_rtc1_station(station_info);
+ conversation_add_proto_data(conversation, proto_pn_dcp, station_info);
+ }
+
+ station_info->u16Vendor_id = vendor_id;
+ station_info->u16Device_id = device_id;
+ }
+
+
pn_append_info(pinfo, dcp_item, ", Dev-ID");
proto_item_append_text(block_item, "Device/Device ID");
if (have_block_qualifier) {
diff --git a/plugins/profinet/packet-pn-rtc-one.c b/plugins/profinet/packet-pn-rtc-one.c
new file mode 100644
index 0000000000..cd1e27b3e5
--- /dev/null
+++ b/plugins/profinet/packet-pn-rtc-one.c
@@ -0,0 +1,1093 @@
+/* packet-pn-rtc-one.c
+ * Routines for PROFINET IO - RTC1 dissection.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1999 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * The PN-IO protocol is a field bus protocol related to decentralized
+ * periphery and is developed by the PROFIBUS Nutzerorganisation e.V. (PNO),
+ * see: www.profibus.com
+ *
+ *
+ * PN-IO is based on the common DCE-RPC and the "lightweight" PN-RT
+ * (ethernet type 0x8892) protocols.
+ *
+ * The context manager (CM) part is handling context information
+ * (like establishing, ...) and is using DCE-RPC as its underlying
+ * protocol.
+ *
+ * The actual cyclic data transfer and acyclic notification uses the
+ * "lightweight" PN-RT protocol.
+ *
+ * There are some other related PROFINET protocols (e.g. PN-DCP, which is
+ * handling addressing topics).
+ *
+ * Please note: the PROFINET CBA protocol is independent of the PN-IO protocol!
+ */
+
+/*
+ * Cyclic PNIO RTC1 Data Dissection:
+ *
+ * To dissect cyclic PNIO RTC1 frames, this plug-in has to collect important module
+ * information out of "Ident OK", "Connect Request" and "Write Response"
+ * frames first.
+ *
+ * The data of Stationname-, -type and -id will be gained out of
+ * packet-pn-dcp.c. The header packet-pn.h will transfer those data between
+ * those two files.
+ *
+ * This file is used as a "addon" for packet-dcerpc-pn-io.c. Within "packet-dcerpc-pn-io.c"
+ * the defined structures in "packet-pn.h" will be filled with all necessary information.
+ * Those informations will be used in thise file to dissect cyclic PNIO RTC1 and PROFIsafe
+ * frames. Furthermore since RTC1 is a special frame type of PNIO, this dissection uses the
+ * already defined protocol PNIO.
+ *
+ * Overview for cyclic PNIO RTC1 data dissection functions:
+ * -> dissect_PNIO_C_SDU_RTC1 (general dissection of RTC1)
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <epan/packet.h>
+#include <epan/dissectors/packet-dcerpc.h>
+#include <epan/proto.h>
+
+#include "packet-pn.h"
+
+
+#define MAX_LINE_LENGTH 1024 /* used for fgets() */
+#define F_MESSAGE_TRAILER_4BYTE 4 /* PROFIsafe: Defines the Amount of Bytes for CRC and Status-/Controlbyte */
+#define PN_INPUT_CR 1 /* PROFINET Input Connect Request value */
+#define PN_INPUT_DATADESCRITPION 1 /* PROFINET Input Data Description value */
+
+
+static int proto_pn_io_rtc1 = -1;
+
+/* General module information */
+static int hf_pn_io_frame_info_type = -1;
+static int hf_pn_io_frame_info_vendor = -1;
+static int hf_pn_io_frame_info_nameofstation = -1;
+static int hf_pn_io_frame_info_gsd_found = -1;
+static int hf_pn_io_frame_info_gsd_error = -1;
+static int hf_pn_io_frame_info_gsd_path = -1;
+static int hf_pn_io_io_data_object = -1;
+static int hf_pn_io_io_data_object_info_module_diff = -1;
+static int hf_pn_io_io_data_object_info_moduleidentnumber = -1;
+static int hf_pn_io_io_data_object_info_submoduleidentnumber = -1;
+
+static int hf_pn_io_iocs = -1;
+static int hf_pn_io_iops = -1;
+static int hf_pn_io_ioxs_extension = -1;
+static int hf_pn_io_ioxs_res14 = -1;
+static int hf_pn_io_ioxs_instance = -1;
+static int hf_pn_io_ioxs_datastate = -1;
+
+/* PROFIsafe statusbyte and controlbyte */
+static int hf_pn_io_ps_sb = -1;
+static int hf_pn_io_ps_sb_iparOK = -1;
+static int hf_pn_io_ps_sb_DeviceFault = -1;
+static int hf_pn_io_ps_sb_CECRC = -1;
+static int hf_pn_io_ps_sb_WDtimeout = -1;
+static int hf_pn_io_ps_sb_FVactivated = -1;
+static int hf_pn_io_ps_sb_Toggle_d = -1;
+static int hf_pn_io_ps_sb_ConsNr_reset = -1;
+static int hf_pn_io_ps_sb_res = -1;
+static int hf_pn_io_ps_sb_toggelBitChanged = -1;
+static int hf_pn_io_ps_sb_toggelBitChange_slot_nr = -1;
+static int hf_pn_io_ps_sb_toggelBitChange_subslot_nr = -1;
+
+static int hf_pn_io_ps_cb = -1;
+static int hf_pn_io_ps_cb_iparEN = -1;
+static int hf_pn_io_ps_cb_OAReq = -1;
+static int hf_pn_io_ps_cb_resetConsNr = -1;
+static int hf_pn_io_ps_cb_useTO2 = -1;
+static int hf_pn_io_ps_cb_activateFV = -1;
+static int hf_pn_io_ps_cb_Toggle_h = -1;
+static int hf_pn_io_ps_cb_Chf_ACK = -1;
+static int hf_pn_io_ps_cb_loopcheck = -1;
+static int hf_pn_io_ps_cb_toggelBitChanged = -1;
+static int hf_pn_io_ps_cb_toggelBitChange_slot_nr = -1;
+static int hf_pn_io_ps_cb_toggelBitChange_subslot_nr = -1;
+
+/* PROFIsafe */
+static int hf_pn_io_ps_f_dest_adr = -1;
+static int hf_pn_io_ps_f_data = -1;
+
+static gint ett_pn_io_rtc = -1;
+static gint ett_pn_io_ioxs = -1;
+static gint ett_pn_io_io_data_object = -1;
+
+
+static const value_string pn_io_ioxs_extension[] = {
+ { 0x00 /* 0*/, "No IOxS octet follows" },
+ { 0x01 /* 1*/, "One more IOxS octet follows" },
+ { 0, NULL }
+};
+
+static const value_string pn_io_ioxs_instance[] = {
+ { 0x00 /* 0*/, "Detected by subslot" },
+ { 0x01 /* 1*/, "Detected by slot" },
+ { 0x02 /* 2*/, "Detected by IO device" },
+ { 0x03 /* 3*/, "Detected by IO controller" },
+ { 0, NULL }
+};
+
+static const value_string pn_io_ioxs_datastate[] = {
+ { 0x00 /* 0*/, "Bad" },
+ { 0x01 /* 1*/, "Good" },
+ { 0, NULL }
+};
+
+
+static const int *ps_sb_fields[] = {
+ &hf_pn_io_ps_sb_res,
+ &hf_pn_io_ps_sb_ConsNr_reset,
+ &hf_pn_io_ps_sb_Toggle_d,
+ &hf_pn_io_ps_sb_FVactivated,
+ &hf_pn_io_ps_sb_WDtimeout,
+ &hf_pn_io_ps_sb_CECRC,
+ &hf_pn_io_ps_sb_DeviceFault,
+ &hf_pn_io_ps_sb_iparOK,
+ NULL
+};
+
+static const int *ps_cb_fields[] = {
+ &hf_pn_io_ps_cb_loopcheck,
+ &hf_pn_io_ps_cb_Chf_ACK,
+ &hf_pn_io_ps_cb_Toggle_h,
+ &hf_pn_io_ps_cb_activateFV,
+ &hf_pn_io_ps_cb_useTO2,
+ &hf_pn_io_ps_cb_resetConsNr,
+ &hf_pn_io_ps_cb_OAReq,
+ &hf_pn_io_ps_cb_iparEN,
+ NULL
+};
+
+static const int *ioxs_fields[] = {
+ &hf_pn_io_ioxs_datastate,
+ &hf_pn_io_ioxs_instance,
+ &hf_pn_io_ioxs_res14,
+ &hf_pn_io_ioxs_extension,
+ NULL
+};
+
+
+/* Dissector for PROFIsafe Status Byte */
+static int
+dissect_pn_io_ps_SB(tvbuff_t *tvb, int offset,
+packet_info *pinfo _U_, proto_tree *tree, guint8 *drep _U_, int hfindex, const int **fields)
+{
+
+ if (tree) {
+ guint8 u8StatusByte;
+ proto_item *sb_item;
+
+ u8StatusByte = tvb_get_guint8(tvb, offset);
+
+ /* Add Status Byte subtree */
+ sb_item = proto_tree_add_bitmask_with_flags(tree, tvb, offset, hfindex, ett_pn_io_ioxs, fields,
+ ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
+ proto_item_append_text(sb_item, " (%s)", ((u8StatusByte == 0x20) || (u8StatusByte == 0x00)) ? "normal" : "unnormal");
+ }
+
+ return offset + 1;
+}
+
+
+/* Dissector for PROFIsafe Control Byte */
+static int
+dissect_pn_io_ps_CB(tvbuff_t *tvb, int offset,
+packet_info *pinfo _U_, proto_tree *tree, guint8 *drep _U_, int hfindex, const int **fields)
+{
+
+ if (tree) {
+ guint8 u8ControlByte;
+ proto_item *cb_item;
+
+ u8ControlByte = tvb_get_guint8(tvb, offset);
+
+ /* Add Status Byte subtree */
+ cb_item = proto_tree_add_bitmask_with_flags(tree, tvb, offset, hfindex, ett_pn_io_ioxs, fields,
+ ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
+ proto_item_append_text(cb_item, " (%s)", ((u8ControlByte == 0x20) || (u8ControlByte == 0x00) ||
+ (u8ControlByte == 0xa0) || (u8ControlByte == 0x80)) ? "normal" : "unnormal");
+ }
+
+ return offset + 1;
+}
+
+
+/* Dissector for IOCS (As each IOCS stands for a specific Slot & Subslot) */
+static int
+dissect_PNIO_IOCS(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree,
+ guint8 *drep _U_, int hfindex, guint16 slotNr, guint16 subSlotNr, const int **fields)
+{
+
+ if (tree) {
+ guint8 u8IOxS;
+ proto_item *ioxs_item;
+
+ u8IOxS = tvb_get_guint8(tvb, offset);
+
+ /* Add ioxs subtree */
+ ioxs_item = proto_tree_add_bitmask_with_flags(tree, tvb, offset, hfindex,
+ ett_pn_io_ioxs, fields, ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
+ proto_item_append_text(ioxs_item,
+ " (%s%s), Slot: 0x%x, Subslot: 0x%x",
+ (u8IOxS & 0x01) ? "another IOxS follows " : "",
+ (u8IOxS & 0x80) ? "good" : "bad",
+ slotNr,
+ subSlotNr);
+ }
+
+ return offset + 1;
+}
+
+
+/* dissect the IOxS (IOCS, IOPS) field */
+static int
+dissect_PNIO_IOxS(tvbuff_t *tvb, int offset,
+packet_info *pinfo _U_, proto_tree *tree, guint8 *drep _U_, int hfindex, const int **fields)
+{
+
+ if (tree) {
+ guint8 u8IOxS;
+ proto_item *ioxs_item;
+
+ u8IOxS = tvb_get_guint8(tvb, offset);
+
+ /* Add ioxs subtree */
+ ioxs_item = proto_tree_add_bitmask_with_flags(tree, tvb, offset, hfindex,
+ ett_pn_io_ioxs, fields, ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
+ proto_item_append_text(ioxs_item,
+ " (%s%s)",
+ (u8IOxS & 0x01) ? "another IOxS follows " : "",
+ (u8IOxS & 0x80) ? "good" : "bad");
+ }
+
+ return offset + 1;
+}
+
+
+/* Universel dissector for flexibel PROFIsafe Data 8 to 64 Bits */
+static int
+dissect_pn_io_ps_uint(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
+ proto_tree *tree, guint8 *drep,
+int hfindex, guint8 bytelength, guint64 *pdata)
+{
+ guint64 data;
+ gboolean generalDissection;
+
+ generalDissection = FALSE;
+
+ switch (bytelength) {
+ case 1: /* 8 Bit Safety IO Data */
+ data = tvb_get_guint8(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 2: /* 16 Bit Safety IO Data */
+ data = tvb_get_letohs(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 3: /* 24 Bit Safety IO Data */
+ data = tvb_get_letoh24(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 4: /* 32 Bit Safety IO Data */
+ data = tvb_get_letohl(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 5: /* 40 Bit Safety IO Data */
+ data = tvb_get_letoh40(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 6: /* 48 Bit Safety IO Data */
+ data = tvb_get_letoh48(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 7: /* 56 Bit Safety IO Data */
+ data = tvb_get_letoh56(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ case 8: /* 64 Bit Safety IO Data */
+ data = tvb_get_letoh64(tvb, offset);
+ if (pdata)
+ *pdata = data;
+ break;
+
+ default: /* Safety IO Data is too big to save it into one variable */
+ dissect_pn_user_data(tvb, offset, pinfo, tree, bytelength, "Safety IO Data");
+ generalDissection = TRUE;
+ break;
+ }
+
+ if (tree && generalDissection == FALSE) {
+ proto_tree_add_item(tree, hfindex, tvb, offset, bytelength, DREP_ENC_INTEGER(drep));
+ }
+
+ return offset + bytelength;
+}
+
+
+/* dissect a PN-IO RTC1 Cyclic Service Data Unit */
+int
+dissect_PNIO_C_SDU_RTC1(tvbuff_t *tvb, int offset,
+ packet_info *pinfo, proto_tree *tree, guint8 *drep _U_)
+{
+ proto_tree *data_tree = NULL;
+
+ /* Count & offset for comparation of the arrays */
+ guint16 frameOffset;
+ guint32 objectCounter;
+ gboolean inputFlag;
+ gboolean outputFlag;
+ gboolean psInfoText; /* Used to display only once per frame the info text "PROFIsafe Device" */
+
+ proto_item *IODataObject_item;
+ proto_item *IODataObject_item_info;
+ proto_tree *IODataObject_tree;
+ proto_item *ModuleID_item;
+ proto_item *ModuleDiff_item;
+
+ wmem_strbuf_t *moduleName;
+
+ guint8 toggleBitSb;
+ guint8 toggleBitCb;
+ guint64 f_data;
+
+ guint8 statusbyte;
+ guint8 controlbyte;
+
+ guint16 number_io_data_objects_input_cr;
+ guint16 number_iocs_input_cr;
+ guint16 number_io_data_objects_output_cr;
+ guint16 number_iocs_output_cr;
+
+ conversation_t *conversation;
+ stationInfo *station_info = NULL;
+ iocsObject *iocs_object;
+ ioDataObject *io_data_object;
+ moduleDiffInfo *module_diff_info;
+ wmem_list_frame_t *frame;
+ wmem_list_frame_t *frame_diff;
+
+ /* Initial */
+ frameOffset = 0;
+ f_data = 0;
+ inputFlag = FALSE;
+ outputFlag = FALSE;
+ psInfoText = FALSE;
+ number_io_data_objects_input_cr = 0;
+ number_iocs_input_cr = 0;
+ number_io_data_objects_output_cr = 0;
+ number_iocs_output_cr = 0;
+
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "PNIO"); /* set protocol name */
+
+ if (tree) {
+ proto_item *data_item;
+ data_item = proto_tree_add_protocol_format(tree, proto_pn_io_rtc1, tvb, offset, tvb_captured_length(tvb),
+ "PROFINET IO Cyclic Service Data Unit: %u bytes", tvb_captured_length(tvb));
+ data_tree = proto_item_add_subtree(data_item, ett_pn_io_rtc);
+ }
+
+ /* dissect_dcerpc_uint16(tvb, offset, pinfo, data_tree, drep, hf_pn_io_packedframe_SFCRC, &u16SFCRC); */
+ if (!(dissect_CSF_SDU_heur(tvb, pinfo, data_tree, NULL) == FALSE))
+ return(tvb_captured_length(tvb));
+
+ /* Only dissect cyclic RTC1 frames, if PN Connect Request has been read */
+ conversation = find_conversation(pinfo->num, &pinfo->dl_src, &pinfo->dl_dst, PT_NONE, 0, 0, 0);
+
+ /* Detect input data package and output data package */
+ if (conversation != NULL) {
+ station_info = (stationInfo*)conversation_get_proto_data(conversation, proto_pn_dcp);
+ if (station_info != NULL) {
+ if (pnio_ps_selection == TRUE) {
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "PNIO_PS"); /* set PROFISsafe protocol name */
+ }
+
+ if (addresses_equal(&(pinfo->src), &(conversation->key_ptr->addr1)) && addresses_equal(&(pinfo->dst), &(conversation->key_ptr->addr2))) {
+ inputFlag = TRUE;
+ outputFlag = FALSE;
+ number_io_data_objects_input_cr = station_info->ioDataObjectNr;
+ number_iocs_input_cr = station_info->iocsNr;
+ }
+
+ if (addresses_equal(&(pinfo->dst), &(conversation->key_ptr->addr1)) && addresses_equal(&(pinfo->src), &(conversation->key_ptr->addr2))) {
+ outputFlag = TRUE;
+ inputFlag = FALSE;
+ number_io_data_objects_output_cr = station_info->ioDataObjectNr;
+ number_iocs_output_cr = station_info->iocsNr;
+ }
+ }
+ }
+
+ /* ------- Input (PNIO) / Response (PNIO_PS) Frame Handling ------- */
+ if (inputFlag) {
+ if (pnio_ps_selection == TRUE) {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_type, tvb,
+ offset, 0, "Response", "Response Frame (IO_Device -> IO_Controller)");
+ }
+ else {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_type, tvb,
+ offset, 0, "Input", "Input Frame (IO_Device -> IO_Controller)");
+ }
+
+ if (station_info != NULL) {
+ if (station_info->typeofstation != NULL) {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_vendor, tvb, 0,
+ 0, station_info->typeofstation, "\"%s\"", station_info->typeofstation);
+ }
+ if (station_info->nameofstation != NULL) {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_nameofstation, tvb, 0,
+ 0, station_info->nameofstation, "\"%s\"", station_info->nameofstation);
+ }
+
+ if (station_info->gsdPathLength == TRUE) { /* given path isn't too long for the array */
+ if (station_info->gsdFound == TRUE) { /* found a GSD-file */
+ if (station_info->gsdLocation != NULL) {
+ IODataObject_item_info = proto_tree_add_item(data_tree, hf_pn_io_frame_info_gsd_found, tvb, offset, 0, ENC_NA);
+ proto_item_append_text(IODataObject_item_info, ": \"%s\"", station_info->gsdLocation);
+ }
+ }
+ else {
+ if (station_info->gsdLocation != NULL) {
+ IODataObject_item_info = proto_tree_add_item(data_tree, hf_pn_io_frame_info_gsd_error, tvb, offset, 0, ENC_NA);
+ proto_item_append_text(IODataObject_item_info, " Please place relevant GSD-file under \"%s\"", station_info->gsdLocation);
+ }
+ }
+ }
+ else {
+ IODataObject_item_info = proto_tree_add_item(data_tree, hf_pn_io_frame_info_gsd_path, tvb, offset, 0, ENC_NA);
+ proto_item_append_text(IODataObject_item_info, " Please check your GSD-file networkpath. (No Path configured)");
+ }
+ }
+
+ /* ---- Input IOData-/IOCS-Object Handling ---- */
+ objectCounter = number_io_data_objects_input_cr + number_iocs_input_cr;
+ while (objectCounter--) {
+ /* ---- Input IO Data Object Handling ---- */
+ if (station_info != NULL) {
+ for (frame = wmem_list_head(station_info->ioobject_data_in); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (io_data_object->frameOffset == frameOffset) {
+ /* Found following object */
+
+ IODataObject_item = proto_tree_add_item(data_tree, hf_pn_io_io_data_object, tvb, offset, 0, ENC_NA);
+ IODataObject_tree = proto_item_add_subtree(IODataObject_item, ett_pn_io_io_data_object);
+
+ /* Control: the Device still uses the correct ModuleIdentNumber? */
+ for (frame_diff = wmem_list_head(station_info->diff_module); frame_diff != NULL; frame_diff = wmem_list_frame_next(frame_diff)) {
+ module_diff_info = (moduleDiffInfo*)wmem_list_frame_data(frame_diff);
+ if (io_data_object->moduleIdentNr != module_diff_info->modulID) {
+ ModuleDiff_item = proto_tree_add_item(IODataObject_tree, hf_pn_io_io_data_object_info_module_diff, tvb, 0, 0, ENC_NA);
+ proto_item_append_text(ModuleDiff_item, ": Device using ModuleIdentNumber 0x%08x instead of 0x%08x", module_diff_info->modulID, io_data_object->moduleIdentNr);
+ break;
+ }
+ }
+
+ proto_tree_add_uint(IODataObject_tree, hf_pn_io_io_data_object_info_moduleidentnumber, tvb, 0, 0, io_data_object->moduleIdentNr);
+ proto_tree_add_uint(IODataObject_tree, hf_pn_io_io_data_object_info_submoduleidentnumber, tvb, 0, 0, io_data_object->subModuleIdentNr);
+
+ /* PROFIsafe Supported Inputmodule handling */
+ if (io_data_object->profisafeSupported == TRUE && pnio_ps_selection == TRUE) {
+ if (io_data_object->profisafeSupported == TRUE && psInfoText == FALSE) {
+ /* Only add one information string per device to the infotext */
+ col_append_str(pinfo->cinfo, COL_INFO, ", PROFIsafe Device"); /* Add string to wireshark infotext */
+ psInfoText = TRUE;
+ }
+
+ proto_tree_add_uint(IODataObject_tree, hf_pn_io_ps_f_dest_adr, tvb, 0, 0, io_data_object->f_dest_adr);
+
+ /* Get Safety IO Data */
+ if ((io_data_object->length - F_MESSAGE_TRAILER_4BYTE) > 0) {
+ offset = dissect_pn_io_ps_uint(tvb, offset, pinfo, IODataObject_tree, drep, hf_pn_io_ps_f_data,
+ (io_data_object->length - F_MESSAGE_TRAILER_4BYTE), &f_data);
+ }
+
+ /* ---- Check for new PNIO data using togglebit ---- */
+ statusbyte = tvb_get_guint8(tvb, offset);
+ toggleBitSb = statusbyte & 0x20; /* get ToggleBit of StatusByte */
+
+ if (io_data_object->lastToggleBit != toggleBitSb) { /* ToggleBit has changed --> new Data incoming */
+ /* Special Filter for ToggleBit within Statusbyte */
+ ModuleID_item = proto_tree_add_uint_format_value(IODataObject_tree, hf_pn_io_ps_sb_toggelBitChanged, tvb, offset, 0,
+ toggleBitSb, "%u", toggleBitSb);
+ PROTO_ITEM_SET_HIDDEN(ModuleID_item);
+
+ ModuleID_item = proto_tree_add_uint_format_value(IODataObject_tree, hf_pn_io_ps_sb_toggelBitChange_slot_nr, tvb, offset, 0,
+ io_data_object->slotNr, "%u", io_data_object->slotNr);
+ PROTO_ITEM_SET_HIDDEN(ModuleID_item);
+
+ ModuleID_item = proto_tree_add_uint_format_value(IODataObject_tree, hf_pn_io_ps_sb_toggelBitChange_subslot_nr, tvb, offset, 0,
+ io_data_object->subSlotNr, "%u", io_data_object->subSlotNr);
+ PROTO_ITEM_SET_HIDDEN(ModuleID_item);
+ }
+
+ offset = dissect_pn_io_ps_SB(tvb, offset, pinfo, IODataObject_tree, drep, hf_pn_io_ps_sb, ps_sb_fields);
+ offset = dissect_pn_user_data(tvb, offset, pinfo, IODataObject_tree, io_data_object->f_crc_len, "CRC");
+
+ io_data_object->last_sb_cb = statusbyte; /* save the value of current statusbyte */
+ io_data_object->lastToggleBit = toggleBitSb; /* save the value of current togglebit within statusbyte */
+ } /* END of PROFIsafe Module Handling */
+
+ else {
+ /* Module is not PROFIsafe supported */
+ offset = dissect_pn_user_data(tvb, offset, pinfo, IODataObject_tree, io_data_object->length, "IO Data");
+ }
+
+ if (io_data_object->discardIOXS == FALSE) {
+ offset = dissect_PNIO_IOxS(tvb, offset, pinfo, IODataObject_tree, drep, hf_pn_io_iops, ioxs_fields);
+ proto_item_set_len(IODataObject_item, io_data_object->length + 1); /* Length = Databytes + IOXS Byte */
+ }
+ else {
+ proto_item_set_len(IODataObject_item, io_data_object->length); /* Length = Databytes */
+ }
+
+ proto_item_append_text(IODataObject_item, ": Slot: 0x%x Subslot: 0x%x",
+ io_data_object->slotNr, io_data_object->subSlotNr);
+
+
+ /* ModuleIdentNr appears not only once in GSD-file -> set module name more generally */
+ if (io_data_object->amountInGSDML > 1) { /* if ModuleIdentNr only appears once in GSD-file, use the found GSD-file-ModuleName, else ... */
+ if (io_data_object->slotNr == 0) {
+ moduleName = wmem_strbuf_new(wmem_packet_scope(), "Headstation");
+ }
+ else {
+ moduleName = wmem_strbuf_new(wmem_packet_scope(), "Module");
+ }
+
+ if (io_data_object->profisafeSupported == TRUE) {
+ /* PROFIsafe */
+ if (io_data_object->length >= 5) { /* 5 due to 3 CRC bytes & 1 status byte & (at least) 1 data byte */
+ wmem_strbuf_append(moduleName, ", DI");
+ }
+ else {
+ wmem_strbuf_append(moduleName, ", DO");
+ }
+ }
+ else {
+ /* PROFINET */
+ if (io_data_object->length > 0) {
+ wmem_strbuf_append(moduleName, ", DI");
+ }
+ else {
+ wmem_strbuf_append(moduleName, ", DO");
+ }
+ }
+
+ io_data_object->moduleNameStr = wmem_strdup(wmem_file_scope(), wmem_strbuf_get_str(moduleName));
+ }
+
+ proto_item_append_text(IODataObject_item, " ModuleName: \"%s\"", io_data_object->moduleNameStr);
+
+ /* emphasize the PROFIsafe supported Modul */
+ if (io_data_object->profisafeSupported == TRUE && pnio_ps_selection == TRUE) {
+ (proto_item_append_text(IODataObject_item, " (PROFIsafe Module)"));
+ }
+
+
+ /* Set frameOffset to its new value, to find the next object */
+ frameOffset = frameOffset + io_data_object->length; /* frameOffset = current value + data bytes */
+ if (io_data_object->discardIOXS == FALSE) {
+ frameOffset = frameOffset + 1; /* frameOffset = current value + iops byte */
+ }
+ }
+ }
+ }
+
+ /* ---- Input IOCS Object Handling ---- */
+ if (station_info != NULL) {
+ for (frame = wmem_list_head(station_info->iocs_data_in); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ iocs_object = (iocsObject*)wmem_list_frame_data(frame);
+ if (iocs_object->frameOffset == frameOffset) {
+ offset = dissect_PNIO_IOCS(tvb, offset, pinfo, data_tree, drep, hf_pn_io_iocs, iocs_object->slotNr,
+ iocs_object->subSlotNr, ioxs_fields);
+
+ /* Set frameOffset to its new value, to find the next object */
+ frameOffset = frameOffset + 1; /* frameOffset = current value + iops byte */
+
+ break;
+ }
+ }
+ }
+ }
+
+ /* Dissect padding */
+ offset = dissect_pn_user_data(tvb, offset, pinfo, tree, tvb_captured_length_remaining(tvb, offset), "GAP and RTCPadding");
+ } /* END of Input Frame Handling */
+
+ /* ----- Output (PNIO) / Request (PNIO_PS) Frame Handling ------ */
+ else if (outputFlag) {
+ if (pnio_ps_selection == TRUE) {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_type, tvb,
+ offset, 0, "Request", "Request Frame (IO_Controller -> IO_Device)");
+ }
+ else {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_type, tvb,
+ offset, 0, "Output", "Output Frame (IO_Controller -> IO_Device)");
+ }
+
+ if (station_info != NULL) {
+ if (station_info->typeofstation != NULL) {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_vendor, tvb, 0,
+ 0, station_info->typeofstation, "\"%s\"", station_info->typeofstation);
+ }
+ if (station_info->nameofstation != NULL) {
+ proto_tree_add_string_format_value(data_tree, hf_pn_io_frame_info_nameofstation, tvb, 0,
+ 0, station_info->nameofstation, "\"%s\"", station_info->nameofstation);
+ }
+
+ if (station_info->gsdPathLength == TRUE) { /* given path isn't too long for the array */
+ if (station_info->gsdFound == TRUE) { /* found a GSD-file */
+ if (station_info->gsdLocation != NULL) {
+ IODataObject_item_info = proto_tree_add_item(data_tree, hf_pn_io_frame_info_gsd_found, tvb, offset, 0, ENC_NA);
+ proto_item_append_text(IODataObject_item_info, ": \"%s\"", station_info->gsdLocation);
+ }
+ }
+ else {
+ if (station_info->gsdLocation != NULL) {
+ IODataObject_item_info = proto_tree_add_item(data_tree, hf_pn_io_frame_info_gsd_error, tvb, offset, 0, ENC_NA);
+ proto_item_append_text(IODataObject_item_info, " Please place relevant GSD-file under \"%s\"", station_info->gsdLocation);
+ }
+ }
+ }
+ else {
+ IODataObject_item_info = proto_tree_add_item(data_tree, hf_pn_io_frame_info_gsd_path, tvb, offset, 0, ENC_NA);
+ proto_item_append_text(IODataObject_item_info, " Please check your GSD-file networkpath. (No Path configured)");
+ }
+ }
+
+ /* ---- Output IOData-/IOCS-Object Handling ---- */
+ objectCounter = number_io_data_objects_output_cr + number_iocs_output_cr;
+ while (objectCounter--) {
+ /* ---- Output IO Data Object Handling ---- */
+ if (station_info != NULL) {
+ for (frame = wmem_list_head(station_info->ioobject_data_out); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ io_data_object = (ioDataObject*)wmem_list_frame_data(frame);
+ if (io_data_object != NULL && io_data_object->frameOffset == frameOffset) {
+ /* Found following object */
+
+ IODataObject_item = proto_tree_add_item(data_tree, hf_pn_io_io_data_object, tvb, offset, 0, ENC_NA);
+ IODataObject_tree = proto_item_add_subtree(IODataObject_item, ett_pn_io_io_data_object);
+
+ /* Control: the Device still uses the correct ModuleIdentNumber? */
+ for (frame_diff = wmem_list_head(station_info->diff_module); frame_diff != NULL; frame_diff = wmem_list_frame_next(frame_diff)) {
+ module_diff_info = (moduleDiffInfo*)wmem_list_frame_data(frame_diff);
+ if (io_data_object->moduleIdentNr != module_diff_info->modulID) {
+ ModuleDiff_item = proto_tree_add_item(IODataObject_tree, hf_pn_io_io_data_object_info_module_diff, tvb, 0, 0, ENC_NA);
+ proto_item_append_text(ModuleDiff_item, ": Device using ModuleIdentNumber 0x%08x instead of 0x%08x", module_diff_info->modulID, io_data_object->moduleIdentNr);
+ break;
+ }
+ }
+
+ proto_tree_add_uint(IODataObject_tree, hf_pn_io_io_data_object_info_moduleidentnumber, tvb, 0, 0, io_data_object->moduleIdentNr);
+ proto_tree_add_uint(IODataObject_tree, hf_pn_io_io_data_object_info_submoduleidentnumber, tvb, 0, 0, io_data_object->subModuleIdentNr);
+
+ if (io_data_object->profisafeSupported == TRUE && pnio_ps_selection == TRUE) {
+ if (io_data_object->profisafeSupported == TRUE && psInfoText == FALSE) {
+ /* Only add one information string per device to the infotext */
+ col_append_str(pinfo->cinfo, COL_INFO, ", PROFIsafe Device"); /* Add string to wireshark infotext */
+ psInfoText = TRUE;
+ }
+
+ proto_tree_add_uint(IODataObject_tree, hf_pn_io_ps_f_dest_adr, tvb, 0, 0, io_data_object->f_dest_adr);
+
+ /* Get Safety IO Data */
+ if ((io_data_object->length - F_MESSAGE_TRAILER_4BYTE) > 0) {
+ offset = dissect_pn_io_ps_uint(tvb, offset, pinfo, IODataObject_tree, drep, hf_pn_io_ps_f_data,
+ (io_data_object->length - F_MESSAGE_TRAILER_4BYTE), &f_data);
+ }
+
+ /* ---- Check for new PNIO data using togglebit ---- */
+ controlbyte = tvb_get_guint8(tvb, offset);
+ toggleBitCb = controlbyte & 0x20; /* get ToggleBit of Controlbyte */
+
+ if (io_data_object->lastToggleBit != toggleBitCb) { /* ToggleBit has changed --> new Data incoming */
+ /* Special Filter for ToggleBit within Controlbyte */
+ ModuleID_item = proto_tree_add_uint_format_value(IODataObject_tree, hf_pn_io_ps_cb_toggelBitChanged, tvb, offset, 0,
+ toggleBitCb, "%u", toggleBitCb);
+ PROTO_ITEM_SET_HIDDEN(ModuleID_item);
+
+ ModuleID_item = proto_tree_add_uint_format_value(IODataObject_tree, hf_pn_io_ps_cb_toggelBitChange_slot_nr, tvb, offset, 0,
+ io_data_object->slotNr, "%u", io_data_object->slotNr);
+ PROTO_ITEM_SET_HIDDEN(ModuleID_item);
+
+ ModuleID_item = proto_tree_add_uint_format_value(IODataObject_tree, hf_pn_io_ps_cb_toggelBitChange_subslot_nr, tvb, offset, 0,
+ io_data_object->subSlotNr, "%u", io_data_object->subSlotNr);
+ PROTO_ITEM_SET_HIDDEN(ModuleID_item);
+ }
+
+ offset = dissect_pn_io_ps_CB(tvb, offset, pinfo, IODataObject_tree, drep, hf_pn_io_ps_cb, ps_cb_fields);
+ offset = dissect_pn_user_data(tvb, offset, pinfo, IODataObject_tree, io_data_object->f_crc_len, "CRC");
+
+ io_data_object->last_sb_cb = controlbyte; /* save the value of current controlbyte */
+ io_data_object->lastToggleBit = toggleBitCb; /* save the value of current togglebit within controlbyte */
+ } /* End of PROFIsafe Module Handling */
+ else {
+ /* Module is not PROFIsafe supported */
+ offset = dissect_pn_user_data(tvb, offset, pinfo, IODataObject_tree, io_data_object->length, "IO Data");
+ }
+
+ if (io_data_object->discardIOXS == FALSE) {
+ offset = dissect_PNIO_IOxS(tvb, offset, pinfo, IODataObject_tree, drep, hf_pn_io_iops, ioxs_fields);
+ proto_item_set_len(IODataObject_item, io_data_object->length + 1); /* Length = Databytes + IOXS Byte */
+ }
+ else {
+ proto_item_set_len(IODataObject_item, io_data_object->length); /* Length = Databytes */
+ }
+
+ proto_item_append_text(IODataObject_item, ": Slot: 0x%x Subslot: 0x%x",
+ io_data_object->slotNr, io_data_object->subSlotNr);
+
+
+ /* ModuleIdentNr appears not only once in GSD-file -> set module name more generally */
+ if (io_data_object->amountInGSDML > 1) { /* if ModuleIdentNr only appears once in GSD-file, use the found GSD-file-ModuleName, else ... */
+ if (io_data_object->slotNr == 0) {
+ moduleName = wmem_strbuf_new(wmem_packet_scope(), "Headstation");
+ }
+ else {
+ moduleName = wmem_strbuf_new(wmem_packet_scope(), "Module");
+ }
+
+ if (io_data_object->profisafeSupported == TRUE) {
+ /* PROFIsafe */
+ if (io_data_object->length >= 5) { /* 5 due to 3 CRC bytes & 1 status byte & (at least) 1 data byte */
+ wmem_strbuf_append(moduleName, ", DO");
+ }
+ else {
+ wmem_strbuf_append(moduleName, ", DI");
+ }
+ }
+ else {
+ /* PROFINET */
+ if (io_data_object->length > 0) {
+ wmem_strbuf_append(moduleName, ", DO");
+ }
+ else {
+ wmem_strbuf_append(moduleName, ", DI");
+ }
+ }
+
+ io_data_object->moduleNameStr = wmem_strdup(wmem_file_scope(), wmem_strbuf_get_str(moduleName));
+ }
+
+ proto_item_append_text(IODataObject_item, " ModuleName: \"%s\"", io_data_object->moduleNameStr);
+
+ /* emphasize the PROFIsafe supported Modul */
+ if (io_data_object->profisafeSupported == TRUE && pnio_ps_selection == TRUE) {
+ proto_item_append_text(IODataObject_item, " (PROFIsafe Module)");
+ }
+
+ /* Set frameOffset to its new value, to find the next object */
+ frameOffset = frameOffset + io_data_object->length; /* frameOffset = current value + data bytes */
+ if (io_data_object->discardIOXS == FALSE) {
+ frameOffset = frameOffset + 1; /* frameOffset = current value + iops byte */
+ }
+ }
+ }
+ }
+
+ /* ---- Output IOCS Object Handling ---- */
+ if (station_info != NULL) {
+ for (frame = wmem_list_head(station_info->iocs_data_out); frame != NULL; frame = wmem_list_frame_next(frame)) {
+ iocs_object = (iocsObject*)wmem_list_frame_data(frame);
+ if (iocs_object->frameOffset == frameOffset) {
+ offset = dissect_PNIO_IOCS(tvb, offset, pinfo, data_tree, drep, hf_pn_io_iocs, iocs_object->slotNr,
+ iocs_object->subSlotNr, ioxs_fields);
+
+ /* Set frameOffset to its new value, to find the next object */
+ frameOffset = frameOffset + 1; /* frameOffset = current value + iops byte */
+
+ break;
+ }
+ }
+ }
+ }
+
+ /* Dissect padding */
+ offset = dissect_pn_user_data(tvb, offset, pinfo, tree, tvb_captured_length_remaining(tvb, offset), "GAP and RTCPadding");
+ } /* END of Output Frame Handling */
+
+ return offset;
+}
+
+
+void
+init_pn_io_rtc1(int proto)
+{
+ static hf_register_info hf[] = {
+ { &hf_pn_io_io_data_object,
+ { "IODataObject", "pn_io.io_data_object",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_io_data_object_info_module_diff,
+ { "Difference", "pn_io.io_data_object.diff_module",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_io_data_object_info_moduleidentnumber,
+ { "ModuleIdentNumber", "pn_io.io_data_object.module_nr",
+ FT_UINT32, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_io_data_object_info_submoduleidentnumber,
+ { "SubmoduleIdentNumber", "pn_io.io_data_object.submodule_nr",
+ FT_UINT32, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_frame_info_type,
+ { "PN Frame Type", "pn_io.frame_info.type",
+ FT_STRING, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_frame_info_vendor,
+ { "DeviceVendorValue", "pn_io.frame_info.vendor",
+ FT_STRING, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_frame_info_nameofstation,
+ { "NameOfStation", "pn_io.frame_info.nameofstation",
+ FT_STRING, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_frame_info_gsd_found,
+ { "GSD-file found", "pn_io.frame_info.gsd_found",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_frame_info_gsd_error,
+ { "GSD-file not found.", "pn_io.frame_info.gsd_error",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_frame_info_gsd_path,
+ { "GSD-file networkpath failure!", "pn_io.frame_info.gsd_path",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_iocs,
+ { "IOCS", "pn_io.ioxs",
+ FT_UINT8, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_iops,
+ { "IOPS", "pn_io.ioxs",
+ FT_UINT8, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ioxs_extension,
+ { "Extension", "pn_io.ioxs.extension",
+ FT_UINT8, BASE_HEX, VALS(pn_io_ioxs_extension), 0x01,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ioxs_res14,
+ { "Reserved", "pn_io.ioxs.res14",
+ FT_UINT8, BASE_HEX, NULL, 0x1E,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ioxs_instance,
+ { "Instance", "pn_io.ioxs.instance",
+ FT_UINT8, BASE_HEX, VALS(pn_io_ioxs_instance), 0x60,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ioxs_datastate,
+ { "DataState", "pn_io.ioxs.datastate",
+ FT_UINT8, BASE_HEX, VALS(pn_io_ioxs_datastate), 0x80,
+ NULL, HFILL }
+ },
+ /* PROFIsafe parameter */
+ /* Status Byte & Control Byte for PROFIsafe --- dissector handle */
+ { &hf_pn_io_ps_sb,
+ { "Status Byte", "pn_io.ps.sb",
+ FT_UINT8, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_toggelBitChanged,
+ { "Status Byte", "pn_io.ps.sb.toggle_d_changed",
+ FT_UINT8, BASE_HEX, NULL, 0x00,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_toggelBitChange_slot_nr,
+ { "Slot_Number", "pn_io.ps.sb.toggle_d_changed.slot",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_toggelBitChange_subslot_nr,
+ { "Sub_Slot_Number", "pn_io.ps.sb.toggle_d_changed.subslot",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb,
+ { "Control Byte", "pn_io.ps.cb",
+ FT_UINT8, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_toggelBitChanged,
+ { "Control Byte", "pn_io.ps.cb.toggle_h_changed",
+ FT_UINT8, BASE_HEX, NULL, 0x00,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_toggelBitChange_slot_nr,
+ { "Slot_Number", "pn_io.ps.cb.toggle_h_changed.slot",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_toggelBitChange_subslot_nr,
+ { "Sub_Slot_Number", "pn_io.ps.cb.toggle_h_changed.subslot",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ /* Structures for dissecting Status Byte & Control Byte PROFIsafe ---dissector details */
+ { &hf_pn_io_ps_sb_iparOK,
+ { "iPar_OK - F-Device has new iParameter values assigned", "pn_io.ps.sb.iPar_OK",
+ FT_UINT8, BASE_HEX, NULL, 0x01,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_DeviceFault,
+ { "Device_Fault - Failure exists in F-Device or F-Module", "pn_io.ps.sb.DeviceFault",
+ FT_UINT8, BASE_HEX, NULL, 0x02,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_CECRC,
+ { "CE_CRC - CRC Communication fault", "pn_io.ps.sb.CE_CRC",
+ FT_UINT8, BASE_HEX, NULL, 0x04,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_WDtimeout,
+ { "WD_timeout - WatchDog timeout Communication fault", "pn_io.ps.sb.WD_timeout",
+ FT_UINT8, BASE_HEX, NULL, 0x08,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_FVactivated,
+ { "FV_activated - Fail-safe values (FV) activated", "pn_io.ps.sb.FV_activated",
+ FT_UINT8, BASE_HEX, NULL, 0x10,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_Toggle_d,
+ { "Toggle_d - Device-based Toggle Bit", "pn_io.ps.sb.Toggle_d",
+ FT_UINT8, BASE_HEX, NULL, 0x20,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_ConsNr_reset,
+ { "cons_nr_R - F-Device has reset its consecutive number counter", "pn_io.ps.sb.cons_nr_R",
+ FT_UINT8, BASE_HEX, NULL, 0x40,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_sb_res,
+ { "Bit7 - reserved for future releases", "pn_io.ps.sb.bit7",
+ FT_UINT8, BASE_HEX, NULL, 0x80,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_iparEN,
+ { "iPar_EN - iParameter assignment deblocked", "pn_io.ps.cb.iparEN",
+ FT_UINT8, BASE_HEX, NULL, 0x01,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_OAReq,
+ { "OA_Req - Operator acknowledge requested", "pn_io.ps.cb.OA_Req",
+ FT_UINT8, BASE_HEX, NULL, 0x02,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_resetConsNr,
+ { "R_cons_nr - Set the Virtual Consecutive Number within the F-Device to be \"0\"", "pn_io.ps.cb.R_cons_nr",
+ FT_UINT8, BASE_HEX, NULL, 0x04,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_useTO2,
+ { "Bit3 - Reserved or Use the secondary watchdog (Use_TO2)", "pn_io.ps.cb.bit3",
+ FT_UINT8, BASE_HEX, NULL, 0x08,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_activateFV,
+ { "activate_FV - Fail-safe values (FV) to be activated", "pn_io.ps.cb.activate_FV",
+ FT_UINT8, BASE_HEX, NULL, 0x10,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_Toggle_h,
+ { "Toggle_h - Host-based Toggle Bit", "pn_io.ps.cb.Toggle_h",
+ FT_UINT8, BASE_HEX, NULL, 0x20,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_Chf_ACK,
+ { "Bit6 - Reserved or Operator acknowledge after cleared channel fault (ChF_Ack)", "pn_io.ps.cb.bit6",
+ FT_UINT8, BASE_HEX, NULL, 0x40,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_cb_loopcheck,
+ { "Bit7 - Reserved or Loop-back check (Loopcheck, shall be set to 1)", "pn_io.ps.cb.bit7",
+ FT_UINT8, BASE_HEX, NULL, 0x80,
+ NULL, HFILL }
+ },
+ /* PROFIsafe */
+ { &hf_pn_io_ps_f_dest_adr,
+ { "F_Dest_Add", "pn_io.ps.f_dest_add",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_pn_io_ps_f_data,
+ { "SafetyIO Data", "pn_io.ps.f_data",
+ FT_UINT64, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_pn_io_rtc,
+ &ett_pn_io_ioxs,
+ &ett_pn_io_io_data_object
+ };
+
+ proto_pn_io_rtc1 = proto;
+ proto_register_field_array(proto, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+}
+
+
+/*
+* Editor modelines - http://www.wireshark.org/tools/modelines.html
+*
+* Local variables:
+* c-basic-offset: 4
+* tab-width: 8
+* indent-tabs-mode: nil
+* End:
+*
+* vi: set shiftwidth=4 tabstop=8 expandtab:
+* :indentSize=4:tabSize=8:noTabs=true:
+*/
diff --git a/plugins/profinet/packet-pn.c b/plugins/profinet/packet-pn.c
index ba4c90d072..5d6c38ad5c 100644
--- a/plugins/profinet/packet-pn.c
+++ b/plugins/profinet/packet-pn.c
@@ -27,6 +27,7 @@
#include <epan/packet.h>
#include <epan/expert.h>
+#include <epan/wmem/wmem.h>
#include <epan/dissectors/packet-dcerpc.h>
#include "packet-pn.h"
@@ -42,6 +43,16 @@ static int hf_pn_malformed = -1;
static expert_field ei_pn_undecoded_data = EI_INIT;
+/* Initialize PNIO RTC1 stationInfo memory */
+void
+init_pnio_rtc1_station(stationInfo *station_info) {
+ station_info->iocs_data_in = wmem_list_new(wmem_file_scope());
+ station_info->iocs_data_out = wmem_list_new(wmem_file_scope());
+ station_info->ioobject_data_in = wmem_list_new(wmem_file_scope());
+ station_info->ioobject_data_out = wmem_list_new(wmem_file_scope());
+ station_info->diff_module = wmem_list_new(wmem_file_scope());
+}
+
/* dissect an 8 bit unsigned integer */
int
dissect_pn_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
diff --git a/plugins/profinet/packet-pn.h b/plugins/profinet/packet-pn.h
index 825dbafee7..9ac7c9eb6d 100644
--- a/plugins/profinet/packet-pn.h
+++ b/plugins/profinet/packet-pn.h
@@ -20,13 +20,94 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+/*
+ * Cyclic PNIO RTC1 Data Dissection:
+ *
+ * Added new structures to packet-pn.h to transfer the gained data of
+ * packet-pn-dcp.c and packet-dcerpc-pn-io.c to packet-pn-rtc-one.c for
+ * detailled dissection of cyclic PNIO RTC1 dataframes.
+ *
+ */
+
#define FRAME_ID_DCP_HELLO 0xfefc
#define FRAME_ID_DCP_GETORSET 0xfefd
#define FRAME_ID_DCP_IDENT_REQ 0xfefe
#define FRAME_ID_DCP_IDENT_RES 0xfeff
+/* ---- Structures for pnio_rtc1 ---- */
+extern int proto_pn_dcp;
+extern gboolean pnio_ps_selection; /* given by pnio preferences */
+
+/* Structure for general station information */
+typedef struct tagStationInfo {
+ /* general information */
+ gchar *typeofstation;
+ gchar *nameofstation;
+ guint16 u16Vendor_id;
+ guint16 u16Device_id;
+ /* frame structure */
+ guint16 ioDataObjectNr;
+ guint16 iocsNr;
+ /* GSDfile station information */
+ gboolean gsdFound;
+ gboolean gsdPathLength;
+ gchar *gsdLocation;
+ /* IOCS object data */
+ wmem_list_t *iocs_data_in;
+ wmem_list_t *iocs_data_out;
+ /* IOData object data */
+ wmem_list_t *ioobject_data_in;
+ wmem_list_t *ioobject_data_out;
+ /* Different ModuleIdentnumber */
+ wmem_list_t *diff_module;
+} stationInfo;
+
+/* Structure for IOCS Frames */
+typedef struct tagIocsObject {
+ guint16 slotNr;
+ guint16 subSlotNr;
+ guint16 frameOffset;
+} iocsObject;
+
+/* Structure for IO Data Objects */
+typedef struct tagIoDataObject {
+ guint16 slotNr;
+ guint16 subSlotNr;
+ guint32 moduleIdentNr;
+ guint32 subModuleIdentNr;
+ guint16 frameOffset;
+ guint16 length;
+ guint16 amountInGSDML;
+ guint32 fParameterIndexNr;
+ guint16 f_par_crc1;
+ guint16 f_src_adr;
+ guint16 f_dest_adr;
+ gboolean f_crc_seed;
+ guint8 f_crc_len;
+ address srcAddr;
+ address dstAddr;
+ gboolean profisafeSupported;
+ gboolean discardIOXS;
+ gchar *moduleNameStr;
+ tvbuff_t *tvb_slot;
+ tvbuff_t *tvb_subslot;
+ /* Status- or Controlbyte data*/
+ guint8 last_sb_cb;
+ guint8 lastToggleBit;
+} ioDataObject;
+
+/* Structure for Modules with different ModuleIdentnumber */
+typedef struct tagModuleDiffInfo {
+ guint16 slotNr;
+ guint32 modulID;
+} moduleDiffInfo;
+
+
extern void init_pn(int proto);
+extern void init_pn_io_rtc1(int proto);
+
+extern void init_pnio_rtc1_station(stationInfo *station_info);
extern int dissect_pn_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, int hfindex, guint8 *pdata);
@@ -77,6 +158,9 @@ extern int dissect_pn_padding(tvbuff_t *tvb, int offset, packet_info *pinfo,
extern int dissect_pn_align4(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
+extern int dissect_PNIO_C_SDU_RTC1(tvbuff_t *tvb, int offset, packet_info *pinfo,
+ proto_tree *tree, guint8 *drep _U_);
+
extern void pn_append_info(packet_info *pinfo, proto_item *dcp_item, const char *text);
extern gboolean dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);