aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/profinet/packet-pn-rt.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2012-12-13 18:17:47 +0000
committerBill Meier <wmeier@newsguy.com>2012-12-13 18:17:47 +0000
commit5a8c275b26a2e997bb3781b3c474d25d7afda202 (patch)
treeac0ec96de11c76bae53d905c86d68cbcda1686d8 /plugins/profinet/packet-pn-rt.c
parente5fc8a400e7876efc78e845143253f64e7224b7c (diff)
General cleanup:
- Localize some variables; remove unneeded initializers; - Reformat some hf[] entries; - Whitespace; style; long lines. svn path=/trunk/; revision=46529
Diffstat (limited to 'plugins/profinet/packet-pn-rt.c')
-rw-r--r--plugins/profinet/packet-pn-rt.c527
1 files changed, 306 insertions, 221 deletions
diff --git a/plugins/profinet/packet-pn-rt.c b/plugins/profinet/packet-pn-rt.c
index 799d39691c..bf61f412a5 100644
--- a/plugins/profinet/packet-pn-rt.c
+++ b/plugins/profinet/packet-pn-rt.c
@@ -111,8 +111,8 @@ static const value_string pn_rt_position_control[] = {
{ 0, NULL }
};
static const value_string pn_rt_ds_redundancy[] = {
- { 0x00, "One primary AR of a given AR-set is present" },
- { 0x01, "None primary AR of a given AR-set is present" },
+ { 0x00, "One primary AR of a given AR-set is present" },
+ { 0x01, "None primary AR of a given AR-set is present" },
{ 0, NULL }
};
@@ -138,40 +138,41 @@ dissect_DataStatus(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 u8DataSta
tvb, offset, 1, u8DataStatus,
"DataStatus: 0x%02x (Frame: %s and %s, Provider: %s and %s)",
u8DataStatus,
- (u8DataStatus & 0x04) ? "Valid" : "Invalid",
+ (u8DataStatus & 0x04) ? "Valid" : "Invalid",
(u8DataStatus & 0x01) ? "Primary" : "Backup",
- (u8DataStatus & 0x20) ? "Ok" : "Problem",
- (u8DataStatus & 0x10) ? "Run" : "Stop");
+ (u8DataStatus & 0x20) ? "Ok" : "Problem",
+ (u8DataStatus & 0x10) ? "Run" : "Stop");
sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_data_status);
- proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ignore, tvb, offset, 1, u8DataStatus);
+ proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ignore, tvb, offset, 1, u8DataStatus);
proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_Reserved_2, tvb, offset, 1, u8DataStatus);
- proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ok, tvb, offset, 1, u8DataStatus);
- proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_operate, tvb, offset, 1, u8DataStatus);
- proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res3, tvb, offset, 1, u8DataStatus);
- proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_valid, tvb, offset, 1, u8DataStatus);
+ proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_ok, tvb, offset, 1, u8DataStatus);
+ proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_operate, tvb, offset, 1, u8DataStatus);
+ proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_res3, tvb, offset, 1, u8DataStatus);
+ proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_valid, tvb, offset, 1, u8DataStatus);
proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_redundancy, tvb, offset, 1, u8DataStatus);
- proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_primary, tvb, offset, 1, u8DataStatus);
+ proto_tree_add_uint(sub_tree, hf_pn_rt_data_status_primary, tvb, offset, 1, u8DataStatus);
}
-static gboolean IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static gboolean
+IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
- guint16 u16SFCRC16;
- guint8 u8SFPosition;
- guint8 u8SFDataLength = 255;
- int offset = 0;
- guint32 u32SubStart;
- guint16 crc;
- gint tvb_len =0;
- unsigned char virtualFramebuffer[16];
- guint16 u16FrameID;
+ guint16 u16SFCRC16;
+ guint8 u8SFPosition;
+ guint8 u8SFDataLength = 255;
+ int offset = 0;
+ guint32 u32SubStart;
+ guint16 crc;
+ gint tvb_len = 0;
+ unsigned char virtualFramebuffer[16];
+ guint16 u16FrameID;
/* the sub tvb will NOT contain the frame_id here! */
u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
/* try to bild a temporaray buffer for generating this CRC */
- memcpy(&virtualFramebuffer[0], pinfo->dst.data,6);
- memcpy(&virtualFramebuffer[6], pinfo->src.data,6);
+ memcpy(&virtualFramebuffer[0], pinfo->dst.data, 6);
+ memcpy(&virtualFramebuffer[6], pinfo->src.data, 6);
virtualFramebuffer[12] = 0x88;
virtualFramebuffer[13] = 0x92;
virtualFramebuffer[15] = (unsigned char) (u16FrameID &0xff);
@@ -181,9 +182,9 @@ static gboolean IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
crc = crc16_plain_finalize(crc);
/* can check this CRC only by having built a temporary data buffer out of the pinfo data */
u16SFCRC16 = tvb_get_letohs(tvb, offset);
- if(u16SFCRC16 != 0) /* no crc! */
+ if (u16SFCRC16 != 0) /* no crc! */
{
- if(u16SFCRC16 != crc)
+ if (u16SFCRC16 != crc)
{
proto_item_append_text(tree, ", no packed frame: SFCRC16 is 0x%x should be 0x%x", u16SFCRC16, crc);
return(FALSE);
@@ -193,11 +194,11 @@ static gboolean IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
offset += 2; /*Skip first crc */
tvb_len = tvb_length(tvb);
- if(offset + 4 > tvb_len)
+ if (offset + 4 > tvb_len)
return FALSE;
- if(tvb_get_letohs(tvb, offset) == 0)
+ if (tvb_get_letohs(tvb, offset) == 0)
return FALSE; /* no valid DFP frame */
- while(1) {
+ while (1) {
u32SubStart = offset;
u8SFPosition = tvb_get_guint8(tvb, offset);
@@ -206,21 +207,21 @@ static gboolean IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
u8SFDataLength = tvb_get_guint8(tvb, offset);
offset += 1;
- if(u8SFDataLength == 0) {
+ if (u8SFDataLength == 0) {
break;
}
offset += 2;
offset += u8SFDataLength;
- if(offset > tvb_len)
+ if (offset > tvb_len)
return /*TRUE; */FALSE;
u16SFCRC16 = tvb_get_letohs(tvb, offset);
- if(u16SFCRC16 != 0){
- if(u8SFPosition & 0x80) {
+ if (u16SFCRC16 != 0) {
+ if (u8SFPosition & 0x80) {
crc = crc16_plain_tvb_offset_seed(tvb, u32SubStart, offset-u32SubStart, 0);
- if(crc != u16SFCRC16) {
+ if (crc != u16SFCRC16) {
return FALSE;
} else {
}
@@ -234,39 +235,38 @@ static gboolean IsDFP_Frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* possibly dissect a CSF_SDU related PN-RT packet */
gboolean
-dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
- void *data _U_)
+dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
- guint16 u16FrameID;
- guint16 u16SFCRC16;
- guint8 u8SFPosition;
- guint8 u8SFDataLength = 255;
- guint8 u8SFCycleCounter;
- guint8 u8SFDataStatus;
- gint offset = 0;
- guint32 u32SubStart;
+ guint16 u16FrameID;
+ guint16 u16SFCRC16;
+ guint8 u8SFPosition;
+ guint8 u8SFDataLength = 255;
+ guint8 u8SFCycleCounter;
+ guint8 u8SFDataStatus;
+ gint offset = 0;
+ guint32 u32SubStart;
proto_item *sub_item;
proto_tree *sub_tree;
proto_item *item;
- guint16 crc;
+ guint16 crc;
/* the sub tvb will NOT contain the frame_id here! */
u16FrameID = GPOINTER_TO_UINT(pinfo->private_data);
/* possible FrameID ranges for DFP */
- if((u16FrameID < 0x100) || (u16FrameID > 0x0FFF))
+ if ((u16FrameID < 0x100) || (u16FrameID > 0x0FFF))
return (FALSE);
if (IsDFP_Frame(tvb, pinfo, tree)) {
/* can't check this CRC, as the checked data bytes are not available */
u16SFCRC16 = tvb_get_letohs(tvb, offset);
- if(u16SFCRC16 != 0)
+ if (u16SFCRC16 != 0)
proto_tree_add_uint(tree, hf_pn_rt_sf_crc16_ok, tvb, offset, 2, u16SFCRC16);
else
proto_tree_add_uint(tree, hf_pn_rt_sf_crc16_null, tvb, offset, 2, u16SFCRC16);
offset += 2;
- while(1) {
+ while (1) {
sub_item = proto_tree_add_item(tree, hf_pn_rt_sf, tvb, offset, 0, ENC_NA);
sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_sf);
u32SubStart = offset;
@@ -279,7 +279,7 @@ dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree_add_uint(sub_tree, hf_pn_rt_sf_data_length, tvb, offset, 1, u8SFDataLength);
offset += 1;
- if(u8SFDataLength == 0) {
+ if (u8SFDataLength == 0) {
proto_item_append_text(sub_item, ": Pos:%u, Length:%u", u8SFPosition, u8SFDataLength);
proto_item_set_len(sub_item, offset - u32SubStart);
break;
@@ -298,9 +298,9 @@ dissect_CSF_SDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
u16SFCRC16 = tvb_get_letohs(tvb, offset);
item = proto_tree_add_uint(sub_tree, hf_pn_rt_sf_crc16, tvb, offset, 2, u16SFCRC16);
- if(u16SFCRC16 != 0 /* "old check": u8SFPosition & 0x80 */) {
+ if (u16SFCRC16 != 0 /* "old check": u8SFPosition & 0x80 */) {
crc = crc16_plain_tvb_offset_seed(tvb, u32SubStart, offset-u32SubStart, 0);
- if(crc != u16SFCRC16) {
+ if (crc != u16SFCRC16) {
proto_item_append_text(item, " [Preliminary check: incorrect, should be: %u]", crc);
expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Bad checksum");
} else {
@@ -346,13 +346,15 @@ static void
pnio_defragment_init(void)
{
guint32 i;
- if( reasembled_frag_table != NULL ) {
+
+ if ( reasembled_frag_table != NULL ) {
g_hash_table_destroy( reasembled_frag_table );
reasembled_frag_table = NULL;
}
- for (i=0; i < 16;i++) /* init the reasemble help array */
+ for (i=0; i < 16; i++) /* init the reasemble help array */
start_frag_OR_ID[i] = 0;
+
fragment_table_init(&pdu_frag_table);
if (reasembled_frag_table == NULL)
{
@@ -362,25 +364,10 @@ pnio_defragment_init(void)
/* possibly dissect a FRAG_PDU related PN-RT packet */
static gboolean
-dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
- void *data _U_)
+dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
guint16 u16FrameID;
- guint32 u32FrameKey = 0;
- guint32 u32FragID = 0;
- guint16 pdu_length = 0;
- guint32 u32ReasembleID =0xfedc;
- int offset = 0;
- proto_item *sub_item;
- proto_tree *sub_tree;
- guint8 u8FragDataLength;
- proto_item *status_item;
- proto_tree *status_tree;
- guint8 u8FragStatus;
- gboolean bMoreFollows;
- guint8 uFragNumber;
- fragment_data *pdu_frag;
- tvbuff_t *pdu_tvb = NULL;
+ int offset = 0;
/* the sub tvb will NOT contain the frame_id here! */
@@ -388,6 +375,15 @@ dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* possible FrameID ranges for FRAG_PDU */
if (u16FrameID >= 0xFF80 && u16FrameID <= 0xFF8F) {
+ proto_item *sub_item;
+ proto_tree *sub_tree;
+ proto_item *status_item;
+ proto_tree *status_tree;
+ guint8 u8FragDataLength;
+ guint8 u8FragStatus;
+ gboolean bMoreFollows;
+ guint8 uFragNumber;
+
sub_item = proto_tree_add_item(tree, hf_pn_rt_frag, tvb, offset, 0, ENC_NA);
sub_tree = proto_item_add_subtree(sub_item, ett_pn_rt_frag);
@@ -404,45 +400,54 @@ dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_tree_add_uint(status_tree, hf_pn_rt_frag_status_fragment_number, tvb, offset, 1, u8FragStatus);
offset += 1;
uFragNumber = u8FragStatus & 0x3F; /* bits 0 to 5 */
- bMoreFollows = (u8FragStatus & 0x80) != 0;
+ bMoreFollows = (u8FragStatus & 0x80) != 0;
proto_item_append_text(status_item, ": Number: %u, %s",
uFragNumber,
val_to_str( (u8FragStatus & 0x80) >> 7, pn_rt_frag_status_more_follows, "Unknown"));
- proto_tree_add_string_format(sub_tree, hf_pn_rt_frag_data, tvb, offset, tvb_length(tvb) - offset, "data",
+ proto_tree_add_string_format(sub_tree, hf_pn_rt_frag_data, tvb, offset, tvb_length(tvb) - offset, "data",
"Fragment Length: %d bytes", tvb_length(tvb) - offset);
- col_append_fstr(pinfo->cinfo, COL_INFO," Fragment Length: %d bytes", tvb_length(tvb) - offset);
+ col_append_fstr(pinfo->cinfo, COL_INFO, " Fragment Length: %d bytes", tvb_length(tvb) - offset);
dissect_pn_user_data_bytes(tvb, offset, pinfo, sub_tree, tvb_length(tvb) - offset, FRAG_DATA);
- if((guint)(tvb_length(tvb) - offset) < (guint)(u8FragDataLength *8)){
+ if ((guint)(tvb_length(tvb) - offset) < (guint)(u8FragDataLength *8)) {
proto_item_append_text(status_item, ": FragDataLength out of Framerange -> discarding!");
return (TRUE);
}
/* defragmentation starts here */
- if(pnio_desegment)
+ if (pnio_desegment)
{
- u32FragID = (u16FrameID & 0xf);
- if(uFragNumber == 0)
+ guint32 u32FragID;
+ guint32 u32ReasembleID /*= 0xfedc ??*/;
+ fragment_data *pdu_frag;
+
+ u32FragID = (u16FrameID & 0xf);
+ if (uFragNumber == 0)
{ /* this is the first "new" fragment, so set up a new key Id */
+ guint32 u32FrameKey;
u32FrameKey = (pinfo->fd->num << 2) | u32FragID;
/* store it in the array */
start_frag_OR_ID[u32FragID] = u32FrameKey;
}
u32ReasembleID = start_frag_OR_ID[u32FragID];
- /* use frame data instead of "pnio fraglen" which sets 8 octet steps */
- pdu_frag = fragment_add_seq(tvb, offset, pinfo, u32ReasembleID, pdu_frag_table, uFragNumber, (tvb_length(tvb) - offset)/*u8FragDataLength*8*/, bMoreFollows);
+ /* use frame data instead of "pnio fraglen" which sets 8 octet steps */
+ pdu_frag = fragment_add_seq(tvb, offset, pinfo, u32ReasembleID, pdu_frag_table, uFragNumber,
+ (tvb_length(tvb) - offset)/*u8FragDataLength*8*/, bMoreFollows);
- if(pdu_frag && !bMoreFollows) /* PDU is complete! and last fragment */
+ if (pdu_frag && !bMoreFollows) /* PDU is complete! and last fragment */
{ /* store this frag as the completed frag in hash table */
- g_hash_table_insert(reasembled_frag_table,GUINT_TO_POINTER(pinfo->fd->num),pdu_frag);
+ g_hash_table_insert(reasembled_frag_table, GUINT_TO_POINTER(pinfo->fd->num), pdu_frag);
start_frag_OR_ID[u32FragID] = 0; /* reset the starting frame counter */
}
- if(!bMoreFollows) /* last fragment */
+ if (!bMoreFollows) /* last fragment */
{
- pdu_frag = g_hash_table_lookup(reasembled_frag_table,GUINT_TO_POINTER(pinfo->fd->num));
- if(pdu_frag) /* found a matching frag dissect it */
+ pdu_frag = g_hash_table_lookup(reasembled_frag_table, GUINT_TO_POINTER(pinfo->fd->num));
+ if (pdu_frag) /* found a matching frag dissect it */
{
- guint16 type;
+ guint16 type;
+ guint16 pdu_length;
+ tvbuff_t *pdu_tvb;
+
pdu_length = pdu_frag->len;
/* create the new tvb for defraged frame */
pdu_tvb = tvb_new_child_real_data(tvb, pdu_frag->data, pdu_length, pdu_length);
@@ -455,8 +460,8 @@ dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
call_dissector(data_handle, pdu_tvb, pinfo, tree);
}
}
- return TRUE;
- }
+ return TRUE;
+ }
else
return TRUE;
}
@@ -470,20 +475,20 @@ dissect_FRAG_PDU_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
static void
dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
- gint pdu_len;
- gint data_len;
- guint16 u16FrameID;
- guint8 u8DataStatus;
- guint8 u8TransferStatus;
- guint16 u16CycleCounter;
+ gint pdu_len;
+ gint data_len;
+ guint16 u16FrameID;
+ guint8 u8DataStatus;
+ guint8 u8TransferStatus;
+ guint16 u16CycleCounter;
const gchar *pszProtAddInfo;
const gchar *pszProtShort;
const gchar *pszProtSummary;
const gchar *pszProtComment;
- proto_tree *pn_rt_tree, *ti;
- gchar szFieldSummary[100];
- tvbuff_t *next_tvb;
- gboolean bCyclic;
+ proto_tree *pn_rt_tree, *ti;
+ gchar szFieldSummary[100];
+ tvbuff_t *next_tvb;
+ gboolean bCyclic;
/* If the link-layer dissector for the protocol above us knows whether
@@ -509,7 +514,7 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Initialize variables */
pn_rt_tree = NULL;
- ti = NULL;
+ ti = NULL;
/*
* Set the columns now, so that they'll be set correctly if we throw
@@ -561,35 +566,35 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
pszProtShort = "PN-RTC3";
pszProtAddInfo = "RTC3, ";
pszProtSummary = "Isochronous-Real-Time";
- pszProtComment = "0x0100-0x06FF: RED: Real-Time(class=3): non redundant, normal or DFP";
+ pszProtComment = "0x0100-0x06FF: RED: Real-Time(class=3): non redundant, normal or DFP";
bCyclic = TRUE;
- } else if (u16FrameID <= 0x0FFF){
+ } else if (u16FrameID <= 0x0FFF) {
pszProtShort = "PN-RTC3";
pszProtAddInfo = "RTC3, ";
pszProtSummary = "Isochronous-Real-Time";
- pszProtComment = "0x0700-0x0FFF: RED: Real-Time(class=3): redundant, normal or DFP";
+ pszProtComment = "0x0700-0x0FFF: RED: Real-Time(class=3): redundant, normal or DFP";
bCyclic = TRUE;
} else if (u16FrameID <= 0x7FFF) {
pszProtShort = "PN-RT";
pszProtAddInfo = "reserved, ";
pszProtSummary = "Real-Time";
- pszProtComment = "0x1000-0x7FFF: Reserved ID";
+ pszProtComment = "0x1000-0x7FFF: Reserved ID";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xBBFF){
+ } else if (u16FrameID <= 0xBBFF) {
pszProtShort = "PN-RTC1";
pszProtAddInfo = "RTC1, ";
pszProtSummary = "cyclic Real-Time";
pszProtComment = "0x8000-0xBBFF: Real-Time(class=1 unicast): non redundant, normal";
bCyclic = TRUE;
- } else if (u16FrameID <= 0xBFFF){
+ } else if (u16FrameID <= 0xBFFF) {
pszProtShort = "PN-RTC1";
pszProtAddInfo = "RTC1, ";
pszProtSummary = "cyclic Real-Time";
pszProtComment = "0xBC00-0xBFFF: Real-Time(class=1 multicast): non redundant, normal";
bCyclic = TRUE;
- } else if (u16FrameID <= 0xF7FF){
+ } else if (u16FrameID <= 0xF7FF) {
/* check if udp frame on PNIO port */
- if(pinfo->destport == 0x8892)
+ if (pinfo->destport == 0x8892)
{ /* UDP frame */
pszProtShort = "PN-RTCUDP,";
pszProtAddInfo = "RT_CLASS_UDP, ";
@@ -603,8 +608,8 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
pszProtSummary = "cyclic Real-Time";
bCyclic = TRUE;
- } else if (u16FrameID <= 0xFBFF){
- if(pinfo->destport == 0x8892)
+ } else if (u16FrameID <= 0xFBFF) {
+ if (pinfo->destport == 0x8892)
{ /* UDP frame */
pszProtShort = "PN-RTCUDP,";
pszProtAddInfo = "RT_CLASS_UDP, ";
@@ -618,7 +623,7 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
pszProtSummary = "cyclic Real-Time";
bCyclic = TRUE;
- } else if (u16FrameID <= 0xFDFF){
+ } else if (u16FrameID <= 0xFDFF) {
pszProtShort = "PN-RTA";
pszProtAddInfo = "Reserved, ";
pszProtSummary = "acyclic Real-Time";
@@ -631,7 +636,7 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
pszProtComment = "Real-Time: Acyclic PN-IO Alarm high priority";
}
- } else if (u16FrameID <= 0xFEFF){
+ } else if (u16FrameID <= 0xFEFF) {
pszProtShort = "PN-RTA";
pszProtAddInfo = "Reserved, ";
pszProtSummary = "acyclic Real-Time";
@@ -667,43 +672,43 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
pszProtSummary = "acyclic Real-Time";
pszProtComment = "Real-Time: DCP (Dynamic Configuration Protocol) identify response";
}
- } else if (u16FrameID <= 0xFF01){
+ } else if (u16FrameID <= 0xFF01) {
pszProtShort = "PN-PTCP";
pszProtAddInfo = "RTA Sync, ";
pszProtSummary = "acyclic Real-Time";
pszProtComment = "0xFF00-0xFF01: PTCP Announce";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xFF1F){
+ } else if (u16FrameID <= 0xFF1F) {
pszProtShort = "PN-PTCP";
pszProtAddInfo = "RTA Sync, ";
pszProtSummary = "acyclic Real-Time";
pszProtComment = "0xFF02-0xFF1F: Reserved";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xFF21){
+ } else if (u16FrameID <= 0xFF21) {
pszProtShort = "PN-PTCP";
pszProtAddInfo = "Follow Up, ";
pszProtSummary = "acyclic Real-Time";
pszProtComment = "0xFF20-0xFF21: PTCP Follow Up";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xFF22){
+ } else if (u16FrameID <= 0xFF22) {
pszProtShort = "PN-PTCP";
pszProtAddInfo = "Follow Up, ";
pszProtSummary = "acyclic Real-Time";
pszProtComment = "0xFF22-0xFF3F: Reserved";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xFF43){
+ } else if (u16FrameID <= 0xFF43) {
pszProtShort = "PN-PTCP";
pszProtAddInfo = "Delay, ";
pszProtSummary = "acyclic Real-Time";
pszProtComment = "0xFF40-0xFF43: Acyclic Real-Time: Delay";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xFF7F){
+ } else if (u16FrameID <= 0xFF7F) {
pszProtShort = "PN-RT";
pszProtAddInfo = "Reserved, ";
pszProtSummary = "Real-Time";
pszProtComment = "0xFF44-0xFF7F: reserved ID";
bCyclic = FALSE;
- } else if (u16FrameID <= 0xFF8F){
+ } else if (u16FrameID <= 0xFF8F) {
pszProtShort = "PN-RT";
pszProtAddInfo = "";
pszProtSummary = "Fragmentation";
@@ -720,17 +725,17 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* decode optional cyclic fields at the packet end and build the summary line */
if (bCyclic) {
/* cyclic transfer has cycle counter, data status and transfer status fields at the end */
- u16CycleCounter = tvb_get_ntohs(tvb, pdu_len - 4);
- u8DataStatus = tvb_get_guint8(tvb, pdu_len - 2);
+ u16CycleCounter = tvb_get_ntohs(tvb, pdu_len - 4);
+ u8DataStatus = tvb_get_guint8(tvb, pdu_len - 2);
u8TransferStatus = tvb_get_guint8(tvb, pdu_len - 1);
g_snprintf (szFieldSummary, sizeof(szFieldSummary),
- "%sID:0x%04x, Len:%4u, Cycle:%5u (%s,%s,%s,%s)",
+ "%sID:0x%04x, Len:%4u, Cycle:%5u (%s,%s,%s,%s)",
pszProtAddInfo, u16FrameID, pdu_len - 2 - 4, u16CycleCounter,
- (u8DataStatus & 0x04) ? "Valid" : "Invalid",
+ (u8DataStatus & 0x04) ? "Valid" : "Invalid",
(u8DataStatus & 0x01) ? "Primary" : "Backup",
- (u8DataStatus & 0x20) ? "Ok" : "Problem",
- (u8DataStatus & 0x10) ? "Run" : "Stop");
+ (u8DataStatus & 0x20) ? "Ok" : "Problem",
+ (u8DataStatus & 0x10) ? "Run" : "Stop");
/* user data length is packet len - frame id - optional cyclic status fields */
data_len = pdu_len - 2 - 4;
@@ -795,7 +800,7 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
next_tvb = tvb_new_subset(tvb, 2, data_len, data_len);
/* ask heuristics, if some sub-dissector is interested in this packet payload */
- if(!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, NULL)) {
+ if (!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, NULL)) {
/*col_set_str(pinfo->cinfo, COL_INFO, "Unknown");*/
/* Oh, well, we don't know this; dissect it as data. */
@@ -808,96 +813,176 @@ dissect_pn_rt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_pn_rt(void)
{
- static hf_register_info hf[] = {
- { &hf_pn_rt_frame_id, {
- "FrameID", "pn_rt.frame_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_cycle_counter, {
- "CycleCounter", "pn_rt.cycle_counter", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_data_status, {
- "DataStatus", "pn_rt.ds", FT_UINT8, BASE_HEX, 0, 0x0, NULL, HFILL }},
- { &hf_pn_rt_data_status_ignore, {
- "Ignore (1:Ignore/0:Evaluate)", "pn_rt.ds_ignore", FT_UINT8, BASE_HEX, 0, 0x80, NULL, HFILL }},
- { &hf_pn_rt_data_status_Reserved_2, {
- "Reserved_2 (should be zero)", "pn_rt.ds_Reserved_2", FT_UINT8, BASE_HEX, 0, 0x40, NULL, HFILL }},
- { &hf_pn_rt_data_status_ok, {
- "StationProblemIndicator (1:Ok/0:Problem)", "pn_rt.ds_ok", FT_UINT8, BASE_HEX, 0, 0x20, NULL, HFILL }},
- { &hf_pn_rt_data_status_operate, {
- "ProviderState (1:Run/0:Stop)", "pn_rt.ds_operate", FT_UINT8, BASE_HEX, 0, 0x10, NULL, HFILL }},
- { &hf_pn_rt_data_status_res3, {
- "Reserved_1 (should be zero)", "pn_rt.ds_res3", FT_UINT8, BASE_HEX, 0, 0x08, NULL, HFILL }},
- { &hf_pn_rt_data_status_valid, {
- "DataValid (1:Valid/0:Invalid)", "pn_rt.ds_valid", FT_UINT8, BASE_HEX, 0, 0x04, NULL, HFILL }},
- { &hf_pn_rt_data_status_redundancy, {
- "Redundancy", "pn_rt.ds_redundancy", FT_UINT8, BASE_HEX, VALS(pn_rt_ds_redundancy), 0x02, NULL, HFILL }},
- { &hf_pn_rt_data_status_primary, {
- "State (1:Primary/0:Backup)", "pn_rt.ds_primary", FT_UINT8, BASE_HEX, 0, 0x01, NULL, HFILL }},
- { &hf_pn_rt_transfer_status,
- { "TransferStatus", "pn_rt.transfer_status", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_sf, {
- "SubFrame", "pn_rt.sf", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_sf_crc16, {
- "SFCRC16", "pn_rt.sf.crc16", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_sf_crc16_ok, {
- "SFCRC16 checked [ok]", "pn_rt.sf.crc16_ok", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_sf_crc16_null, {
- "SFCRC16 not checked but ok", "pn_rt.sf.crc16_null", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_sf_position, {
- "Position", "pn_rt.sf.position", FT_UINT8, BASE_DEC, NULL, 0x7F, NULL, HFILL }},
- { &hf_pn_rt_sf_position_control, {
- "Control", "pn_rt.sf.position_control", FT_UINT8, BASE_DEC, VALS(pn_rt_position_control), 0x80, NULL, HFILL }},
- { &hf_pn_rt_sf_data_length, {
- "DataLength", "pn_rt.sf.data_length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_sf_cycle_counter, {
- "CycleCounter", "pn_rt.sf.cycle_counter", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_frag, {
- "PROFINET Fragment", "pn_rt.frag", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_frag_data_length, {
- "FragDataLength", "pn_rt.frag_data_length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_frag_status, {
- "FragStatus", "pn_rt.frag_status", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
- { &hf_pn_rt_frag_status_more_follows, {
- "MoreFollows", "pn_rt.frag_status.more_follows", FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_more_follows), 0x80, NULL, HFILL }},
- { &hf_pn_rt_frag_status_error, {
- "Reserved", "pn_rt.frag_status.error", FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_error), 0x40, NULL, HFILL }},
- { &hf_pn_rt_frag_status_fragment_number, {
- "FragmentNumber (zero based)", "pn_rt.frag_status.fragment_number", FT_UINT8, BASE_DEC, NULL, 0x3F, NULL, HFILL }},
- { &hf_pn_rt_frag_data, {
- "FragData", "pn_rt.frag_data", FT_STRING, BASE_NONE, NULL, 0x00, NULL, HFILL }},
- };
- static gint *ett[] = {
- &ett_pn_rt,
- &ett_pn_rt_data_status,
- &ett_pn_rt_sf,
- &ett_pn_rt_frag,
- &ett_pn_rt_frag_status
- };
- module_t *pn_rt_module;
-
- proto_pn_rt = proto_register_protocol("PROFINET Real-Time Protocol",
- "PN-RT", "pn_rt");
-
- proto_register_field_array(proto_pn_rt, hf, array_length(hf));
- proto_register_subtree_array(ett, array_length(ett));
-
- /* Register our configuration options */
-
- pn_rt_module = prefs_register_protocol(proto_pn_rt, NULL);
-
- prefs_register_bool_preference(pn_rt_module, "summary_in_tree",
- "Show PN-RT summary in protocol tree",
- "Whether the PN-RT summary line should be shown in the protocol tree",
- &pn_rt_summary_in_tree);
-
- prefs_register_bool_preference(pn_rt_module, "desegment",
- "reassemble PNIO Fragments",
- "Reassemble PNIO Fragments and get them decoded",
- &pnio_desegment);
-
- /* register heuristics anchor for payload dissectors */
- register_heur_dissector_list("pn_rt", &heur_subdissector_list);
-
- init_pn (proto_pn_rt);
- register_init_routine(pnio_defragment_init);
+ static hf_register_info hf[] = {
+ { &hf_pn_rt_frame_id,
+ { "FrameID", "pn_rt.frame_id",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_cycle_counter,
+ { "CycleCounter", "pn_rt.cycle_counter",
+ FT_UINT16, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status,
+ { "DataStatus", "pn_rt.ds",
+ FT_UINT8, BASE_HEX, 0, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_ignore,
+ { "Ignore (1:Ignore/0:Evaluate)", "pn_rt.ds_ignore", FT_UINT8, BASE_HEX, 0, 0x80,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_Reserved_2,
+ { "Reserved_2 (should be zero)", "pn_rt.ds_Reserved_2",
+ FT_UINT8, BASE_HEX, 0, 0x40,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_ok,
+ { "StationProblemIndicator (1:Ok/0:Problem)", "pn_rt.ds_ok",
+ FT_UINT8, BASE_HEX, 0, 0x20,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_operate,
+ { "ProviderState (1:Run/0:Stop)", "pn_rt.ds_operate",
+ FT_UINT8, BASE_HEX, 0, 0x10,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_res3,
+ { "Reserved_1 (should be zero)", "pn_rt.ds_res3",
+ FT_UINT8, BASE_HEX, 0, 0x08,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_valid,
+ { "DataValid (1:Valid/0:Invalid)", "pn_rt.ds_valid",
+ FT_UINT8, BASE_HEX, 0, 0x04,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_redundancy,
+ { "Redundancy", "pn_rt.ds_redundancy",
+ FT_UINT8, BASE_HEX, VALS(pn_rt_ds_redundancy), 0x02,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_data_status_primary,
+ { "State (1:Primary/0:Backup)", "pn_rt.ds_primary",
+ FT_UINT8, BASE_HEX, 0, 0x01,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_transfer_status,
+ { "TransferStatus", "pn_rt.transfer_status",
+ FT_UINT8, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf,
+ { "SubFrame", "pn_rt.sf",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_crc16,
+ { "SFCRC16", "pn_rt.sf.crc16",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_crc16_ok,
+ { "SFCRC16 checked [ok]", "pn_rt.sf.crc16_ok",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_crc16_null,
+ { "SFCRC16 not checked but ok", "pn_rt.sf.crc16_null",
+ FT_UINT16, BASE_HEX, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_position,
+ { "Position", "pn_rt.sf.position",
+ FT_UINT8, BASE_DEC, NULL, 0x7F,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_position_control,
+ { "Control", "pn_rt.sf.position_control",
+ FT_UINT8, BASE_DEC, VALS(pn_rt_position_control), 0x80,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_data_length,
+ { "DataLength", "pn_rt.sf.data_length",
+ FT_UINT8, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_sf_cycle_counter,
+ { "CycleCounter", "pn_rt.sf.cycle_counter",
+ FT_UINT8, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag,
+ { "PROFINET Fragment", "pn_rt.frag",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag_data_length,
+ { "FragDataLength", "pn_rt.frag_data_length",
+ FT_UINT8, BASE_DEC, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag_status,
+ { "FragStatus", "pn_rt.frag_status",
+ FT_NONE, BASE_NONE, NULL, 0x0,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag_status_more_follows,
+ { "MoreFollows", "pn_rt.frag_status.more_follows",
+ FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_more_follows), 0x80,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag_status_error,
+ { "Reserved", "pn_rt.frag_status.error",
+ FT_UINT8, BASE_HEX, VALS(pn_rt_frag_status_error), 0x40,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag_status_fragment_number,
+ { "FragmentNumber (zero based)", "pn_rt.frag_status.fragment_number",
+ FT_UINT8, BASE_DEC, NULL, 0x3F,
+ NULL, HFILL }},
+
+ { &hf_pn_rt_frag_data,
+ { "FragData", "pn_rt.frag_data",
+ FT_STRING, BASE_NONE, NULL, 0x00,
+ NULL, HFILL }},
+
+ };
+ static gint *ett[] = {
+ &ett_pn_rt,
+ &ett_pn_rt_data_status,
+ &ett_pn_rt_sf,
+ &ett_pn_rt_frag,
+ &ett_pn_rt_frag_status
+ };
+ module_t *pn_rt_module;
+
+ proto_pn_rt = proto_register_protocol("PROFINET Real-Time Protocol",
+ "PN-RT", "pn_rt");
+
+ proto_register_field_array(proto_pn_rt, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+
+ /* Register our configuration options */
+
+ pn_rt_module = prefs_register_protocol(proto_pn_rt, NULL);
+
+ prefs_register_bool_preference(pn_rt_module, "summary_in_tree",
+ "Show PN-RT summary in protocol tree",
+ "Whether the PN-RT summary line should be shown in the protocol tree",
+ &pn_rt_summary_in_tree);
+
+ prefs_register_bool_preference(pn_rt_module, "desegment",
+ "reassemble PNIO Fragments",
+ "Reassemble PNIO Fragments and get them decoded",
+ &pnio_desegment);
+
+ /* register heuristics anchor for payload dissectors */
+ register_heur_dissector_list("pn_rt", &heur_subdissector_list);
+
+ init_pn (proto_pn_rt);
+ register_init_routine(pnio_defragment_init);
}
@@ -905,17 +990,17 @@ proto_register_pn_rt(void)
void
proto_reg_handoff_pn_rt(void)
{
- dissector_handle_t pn_rt_handle;
+ dissector_handle_t pn_rt_handle;
- pn_rt_handle = create_dissector_handle(dissect_pn_rt, proto_pn_rt);
+ pn_rt_handle = create_dissector_handle(dissect_pn_rt, proto_pn_rt);
- dissector_add_uint("ethertype", ETHERTYPE_PROFINET, pn_rt_handle);
- dissector_add_uint("udp.port", 0x8892, pn_rt_handle);
+ dissector_add_uint("ethertype", ETHERTYPE_PROFINET, pn_rt_handle);
+ dissector_add_uint("udp.port", 0x8892, pn_rt_handle);
- heur_dissector_add("pn_rt", dissect_CSF_SDU_heur, proto_pn_rt);
- heur_dissector_add("pn_rt", dissect_FRAG_PDU_heur, proto_pn_rt);
- data_handle = find_dissector("data");
+ heur_dissector_add("pn_rt", dissect_CSF_SDU_heur, proto_pn_rt);
+ heur_dissector_add("pn_rt", dissect_FRAG_PDU_heur, proto_pn_rt);
+ data_handle = find_dissector("data");
- ethertype_subdissector_table = find_dissector_table("ethertype");
+ ethertype_subdissector_table = find_dissector_table("ethertype");
}