netanalyzer: add dissection of new header version 2 fields

Change-Id: I552d8be0fdf3f0949d469e66c27be37ec82c5ccf
Reviewed-on: https://code.wireshark.org/review/16584
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Holger Pfrommer 2016-07-22 14:27:15 +02:00 committed by Anders Broman
parent e3009b0b1c
commit a5166affc4
1 changed files with 200 additions and 84 deletions

View File

@ -1,6 +1,6 @@
/* packet-netanalyzer.c
* Dissector for Hilscher netANALYZER frames.
* Copyright 2008-2011, Hilscher GmbH, Holger Pfrommer hpfrommer[AT]hilscher.com
* Copyright 2008-2016, Hilscher GmbH, Holger Pfrommer hpfrommer[AT]hilscher.com
*
* Packet structure:
* +---------------------------+
@ -26,10 +26,11 @@
* The next bit, 0x00000100, is set if the packet arrived on the GPIO port rather tha the Ethernet port.
* The next bit, 0x00000200, is set if the packet was received in transparent capture mode.
* That should never be set for LINKTYPE_NETANALYZER and should always be set for LINKTYPE_NETANALYZER_TRANSPARENT.
* The next 4 bits, 0x00003C00, are a bitfield giving the version of the header field; the current version is 1.
* The next 4 bits, 0x00003C00, are a bitfield giving the version of the header field; version can be 1 or 2.
* The next 2 bits, 0x0000C000, are the capture port/GPIO number, from 0 to 3.
* The next 12 bits, 0x0FFF0000, are the frame length, in bytes.
* The topmost 4 bits, 0xF0000000, are reserved.
* The topmost 4 bits, 0xF0000000, for version 2 header, these bits are the type of the following packet
* (0: Ethernet, 1: PROFIBUS, 2: buffer state entry, 3: timetick, 4..15: reserved).
* The payload is an Ethernet frame, beginning with the MAC header and ending with the FCS, for LINKTYPE_NETANALYZER,
* and an Ethernet frame, beginning with the preamble and ending with the FCS, for LINKTYPE_NETANALYZER_TRANSPARENT.
*
@ -86,6 +87,7 @@ static const char *msk_strings[] = {
"Preamble longer than 7 bytes" /* 0x80 */
};
#define SRT_TYPE 28
#define SRT_PORT_NUM 6
#define SRT_VERSION 2
#define SRT_GPIO_FLAG 0
@ -93,6 +95,15 @@ static const char *msk_strings[] = {
#define MSK_LENGTH 0x0fff
#define MSK_TRANSPARENT_MODE 0x02
#define MSK_BUF_STATE 0x1
#define SRT_BUF_ID 4
#define MSK_BUF_ID 0xf0
#define VAL_TYPE_ETH 0
#define VAL_TYPE_PB 1
#define VAL_TYPE_BUF 2
#define VAL_TYPE_TICK 3
static const value_string gpio_number[] = {
{ 0x0, "GPIO 0" },
@ -103,8 +114,23 @@ static const value_string gpio_number[] = {
};
static const value_string gpio_edge_vals[] = {
{ 0x0, "rising edge" },
{ 0x1, "falling edge" },
{ 0x0, "Rising edge" },
{ 0x1, "Falling edge" },
{ 0, NULL }
};
static const value_string buf_state_vals[] = {
{ 0x0, "Buffer overflow, frames will be dropped until next buffer recovery" },
{ 0x1, "Buffer recovery, frame reception has recovered" },
{ 0, NULL }
};
static const value_string buf_source_vals[] = {
{ 0x0, "Backend RX FIFO" },
{ 0x1, "netX URX FIFO" },
{ 0x2, "netX INTRAM buffer" },
{ 0x3, "Host buffer" },
{ 0x4, "Capture driver (WinPcap)" },
{ 0, NULL }
};
@ -113,8 +139,10 @@ static dissector_handle_t eth_dissector_handle;
static gint proto_netanalyzer = -1;
static gint hf_netanalyzer_gpio = -1;
static gint hf_netanalyzer_gpio_number = -1;
static gint hf_netanalyzer_gpio_edge = -1;
static gint hf_netanalyzer_eth = -1;
static gint hf_netanalyzer_port = -1;
static gint hf_netanalyzer_length = -1;
static gint hf_netanalyzer_status = -1;
@ -126,16 +154,35 @@ static gint hf_netanalyzer_status_sfd_error = -1;
static gint hf_netanalyzer_status_short_frame = -1;
static gint hf_netanalyzer_status_short_preamble = -1;
static gint hf_netanalyzer_status_long_preamble = -1;
static gint hf_netanalyzer_buf = -1;
static gint hf_netanalyzer_buf_state = -1;
static gint hf_netanalyzer_buf_source = -1;
static gint hf_netanalyzer_timetick = -1;
static const int *hfx_netanalyzer_status[] = {
&hf_netanalyzer_status_rx_err,
&hf_netanalyzer_status_align_err,
&hf_netanalyzer_status_fcs,
&hf_netanalyzer_status_too_long,
&hf_netanalyzer_status_sfd_error,
&hf_netanalyzer_status_short_frame,
&hf_netanalyzer_status_short_preamble,
&hf_netanalyzer_status_long_preamble,
NULL
};
static gint ett_netanalyzer = -1;
static gint ett_netanalyzer_gpio = -1;
static gint ett_netanalyzer_status = -1;
static gint ett_netanalyzer_transparent = -1;
static gint ett_netanalyzer_buf = -1;
static expert_field ei_netanalyzer_header_version_wrong = EI_INIT;
static expert_field ei_netanalyzer_header_wrong = EI_INIT;
static expert_field ei_netanalyzer_gpio_def_none = EI_INIT;
static expert_field ei_netanalyzer_header_version_none = EI_INIT;
static expert_field ei_netanalyzer_header_none = EI_INIT;
static expert_field ei_netanalyzer_transparent_frame = EI_INIT;
static expert_field ei_netanalyzer_alignment_error = EI_INIT;
static expert_field ei_netanalyzer_not_implemented = EI_INIT;
/* common routine for Ethernet and transparent mode */
static int
@ -143,8 +190,6 @@ dissect_netanalyzer_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
proto_item *ti = NULL;
proto_tree *netanalyzer_header_tree = NULL;
proto_item *ti_status = NULL;
proto_tree *netanalyzer_status_tree = NULL;
guint32 packet_status;
guint32 port_num;
guint32 frame_length;
@ -153,7 +198,10 @@ dissect_netanalyzer_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint gpio_num;
guint gpio_edge;
guint version;
guint type;
guint idx;
guint buf_state;
guint buf_source;
if (tree)
{
@ -169,85 +217,119 @@ dissect_netanalyzer_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* decode version */
version = (tvb_get_guint8(tvb, 1) >> SRT_VERSION) & 0xf;
if (version != 1)
type = (tvb_get_guint32(tvb, 0, ENC_LITTLE_ENDIAN) >> SRT_TYPE) & 0xf;
if ((version == 1) || ((version == 2) && (type == VAL_TYPE_ETH)))
{
/* something is wrong */
expert_add_info(pinfo, ti, &ei_netanalyzer_header_version_wrong);
proto_tree_add_none_format(netanalyzer_header_tree, hf_netanalyzer_eth, tvb, 0, 0, "Ethernet frame");
/* decode port */
port_num = (tvb_get_guint8(tvb, 1) >> SRT_PORT_NUM) & 0x3;
proto_tree_add_uint(netanalyzer_header_tree, hf_netanalyzer_port, tvb, 0, 4, port_num);
proto_item_append_text(ti, " (Port: %u, ", port_num);
/* decode length */
frame_length = tvb_get_letohs(tvb, 2) & MSK_LENGTH;
proto_tree_add_uint(netanalyzer_header_tree, hf_netanalyzer_length, tvb, 0, 4, frame_length);
proto_item_append_text(ti, "Length: %u byte%s, ", frame_length, (frame_length == 1) ? "" : "s");
/* decode status */
proto_item_append_text(ti, "Status: ");
packet_status = tvb_get_guint8(tvb, 0);
if (packet_status == 0)
{
proto_tree_add_uint_format_value(netanalyzer_header_tree, hf_netanalyzer_status, tvb, 0, 1,
packet_status, "No Error");
proto_item_append_text(ti, "No Error)");
}
else
{
wmem_strbuf_t *strbuf;
gboolean first = TRUE;
proto_tree_add_bitmask(netanalyzer_header_tree, tvb, 0, hf_netanalyzer_status, ett_netanalyzer_status, hfx_netanalyzer_status, ENC_LITTLE_ENDIAN);
strbuf = wmem_strbuf_new_label(wmem_packet_scope());
for (idx = 0; idx < 8; idx++)
{
if (packet_status & (1 << idx))
{
if (first)
{
first = FALSE;
}
else
{
wmem_strbuf_append(strbuf, ", ");
}
wmem_strbuf_append(strbuf, msk_strings[idx]);
}
}
proto_item_append_text(ti, "%s)", wmem_strbuf_get_str(strbuf));
}
/* decode transparent mode */
if (tvb_get_guint8(tvb, 1) & MSK_TRANSPARENT_MODE)
{
proto_tree_add_expert(netanalyzer_header_tree, pinfo, &ei_netanalyzer_transparent_frame, tvb, 0, 4);
proto_item_append_text(ti, ", Transparent Mode");
if (packet_status & MSK_ALIGN_ERR)
{
proto_tree_add_expert(netanalyzer_header_tree, pinfo, &ei_netanalyzer_alignment_error, tvb, tvb_captured_length(tvb) - 1, 1);
}
}
}
else if ((version == 2) && (type == VAL_TYPE_PB))
{
/* currently not implemented */
expert_add_info(pinfo, ti, &ei_netanalyzer_not_implemented);
return FALSE;
}
/* decode port */
port_num = (tvb_get_guint8(tvb, 1) >> SRT_PORT_NUM) & 0x3;
proto_tree_add_uint(netanalyzer_header_tree, hf_netanalyzer_port, tvb, 0, 4, port_num);
proto_item_append_text(ti, " (Port: %u, ", port_num);
/* decode length */
frame_length = tvb_get_letohs(tvb, 2) & MSK_LENGTH;
proto_tree_add_uint(netanalyzer_header_tree, hf_netanalyzer_length, tvb, 0, 4, frame_length);
proto_item_append_text(ti, "Length: %u byte%s, ", frame_length, (frame_length == 1) ? "" : "s");
/* decode status */
proto_item_append_text(ti, "Status: ");
packet_status = tvb_get_guint8(tvb, 0);
if (packet_status == 0)
else if ((version == 2) && (type == VAL_TYPE_BUF))
{
ti_status = proto_tree_add_uint_format_value(netanalyzer_header_tree, hf_netanalyzer_status, tvb, 0, 1,
packet_status, "No Error");
proto_item_append_text(ti, "No Error)");
proto_tree_add_none_format(netanalyzer_header_tree, hf_netanalyzer_buf, tvb, 0, 0, "Buffer state entry");
col_set_str(pinfo->cinfo, COL_PROTOCOL, "netANALYZER");
buf_state = tvb_get_guint8(tvb, 0) & MSK_BUF_STATE;
if (buf_state == 0)
{
col_set_str(pinfo->cinfo, COL_INFO, "Buffer overflow");
}
else
{
col_set_str(pinfo->cinfo, COL_INFO, "Buffer recovery");
}
proto_item_append_text(ti, " (%s)", buf_state_vals[buf_state].strptr);
/* decode buffer state */
proto_tree_add_uint(ti, hf_netanalyzer_buf_state, tvb, 0, 1, buf_state);
port_num = (tvb_get_guint8(tvb, 1) >> SRT_PORT_NUM) & 0x3;
proto_tree_add_uint(ti, hf_netanalyzer_port, tvb, 0, 4, port_num);
buf_source = (tvb_get_guint8(tvb, 0) & MSK_BUF_ID) >> SRT_BUF_ID;
proto_tree_add_uint(ti, hf_netanalyzer_buf_source, tvb, 0, 1, buf_source);
return FALSE;
}
else if ((version == 2) && (type == VAL_TYPE_TICK))
{
col_set_str(pinfo->cinfo, COL_PROTOCOL, "netANALYZER");
col_set_str(pinfo->cinfo, COL_INFO, "Time tick");
proto_item_append_text(ti, " (Time tick)");
proto_tree_add_none_format(netanalyzer_header_tree, hf_netanalyzer_timetick, tvb, 0, 0, "Time tick");
return FALSE;
}
else
{
wmem_strbuf_t *strbuf;
gboolean first = TRUE;
ti_status = proto_tree_add_uint_format_value(netanalyzer_header_tree, hf_netanalyzer_status, tvb, 0, 1,
packet_status, "Error present (expand tree for details)");
strbuf = wmem_strbuf_new_label(wmem_epan_scope());
for (idx = 0; idx < 8; idx++)
{
if (packet_status & (1 << idx))
{
if (first)
{
first = FALSE;
}
else
{
wmem_strbuf_append(strbuf, ", ");
}
wmem_strbuf_append(strbuf, msk_strings[idx]);
}
}
proto_item_append_text(ti, "%s)", wmem_strbuf_get_str(strbuf));
}
netanalyzer_status_tree = proto_item_add_subtree(ti_status, ett_netanalyzer_status);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_rx_err, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_align_err, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_fcs, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_too_long, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_sfd_error, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_short_frame, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_short_preamble, tvb, 0, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(netanalyzer_status_tree, hf_netanalyzer_status_long_preamble, tvb, 0, 1, ENC_LITTLE_ENDIAN);
/* decode transparent mode */
if (tvb_get_guint8(tvb, 1) & MSK_TRANSPARENT_MODE)
{
proto_tree_add_expert(netanalyzer_header_tree, pinfo, &ei_netanalyzer_transparent_frame, tvb, 0, 4);
proto_item_append_text(ti, ", Transparent Mode");
if (packet_status & MSK_ALIGN_ERR)
{
proto_tree_add_expert(netanalyzer_header_tree, pinfo, &ei_netanalyzer_alignment_error, tvb, tvb_captured_length(tvb)-1, 1);
}
/* something is wrong */
expert_add_info(pinfo, ti, &ei_netanalyzer_header_wrong);
return FALSE;
}
}
else
{
guchar *szTemp;
/* GPIO pseudo packet */
/* check consistency */
if ( (tvb_get_guint8(tvb, 10) == 0x00) &&
(tvb_get_guint8(tvb, 11) == 0x02) &&
@ -264,8 +346,9 @@ dissect_netanalyzer_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* everything ok */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "netANALYZER");
offset = INFO_TYPE_OFFSET;
proto_tree_add_none_format(netanalyzer_header_tree, hf_netanalyzer_gpio, tvb, 0, 0, "GPIO event");
proto_item_append_text(ti, " (GPIO event)");
/* GPIO number */
offset++;
@ -314,7 +397,7 @@ dissect_netanalyzer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* d
else
{
/* something is wrong */
proto_tree_add_expert_format(tree, pinfo, &ei_netanalyzer_header_version_none, tvb, 4, -1,
proto_tree_add_expert_format(tree, pinfo, &ei_netanalyzer_header_none, tvb, 4, -1,
"netANALYZER - No netANALYZER header found");
}
return tvb_captured_length(tvb);
@ -349,7 +432,7 @@ dissect_netanalyzer_transparent(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
else
{
/* something is wrong */
proto_tree_add_expert_format(tree, pinfo, &ei_netanalyzer_header_version_none, tvb, 4, -1,
proto_tree_add_expert_format(tree, pinfo, &ei_netanalyzer_header_none, tvb, 4, -1,
"netANALYZER transparent mode - No netANALYZER header found");
}
return tvb_captured_length(tvb);
@ -359,15 +442,25 @@ dissect_netanalyzer_transparent(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
void proto_register_netanalyzer(void)
{
static hf_register_info hf[] = {
{ &hf_netanalyzer_gpio,
{ "GPIO event", "netanalyzer.gpio_event",
FT_NONE, BASE_NONE, NULL, 0x0,
"Shows the occurence of an digital switching event", HFILL }
},
{ &hf_netanalyzer_gpio_number,
{ "Event on", "netanalyzer.gpio_event.gpio_number",
{ "GPIO event on", "netanalyzer.gpio_event.gpio_number",
FT_UINT8, BASE_HEX, VALS(gpio_number), 0x0,
"Event on GPIO number", HFILL }
"GPIO event on GPIO number", HFILL }
},
{ &hf_netanalyzer_gpio_edge,
{ "Event type", "netanalyzer.gpio_event.gpio_edge",
{ "GPIO event type", "netanalyzer.gpio_event.gpio_edge",
FT_UINT8, BASE_HEX, VALS(gpio_edge_vals), 0x0,
"Edge of GPIO event", HFILL }
"GPIO edge of GPIO event", HFILL }
},
{ &hf_netanalyzer_eth,
{ "Ethernet frame", "netanalyzer.eth",
FT_NONE, BASE_NONE, NULL, 0x0,
"This is an Ethernet frame", HFILL }
},
{ &hf_netanalyzer_port,
{ "Reception Port", "netanalyzer.port",
@ -424,20 +517,43 @@ void proto_register_netanalyzer(void)
FT_BOOLEAN, 8, NULL, MSK_LONG_PREAMBLE,
NULL, HFILL }
},
{ &hf_netanalyzer_buf,
{ "Buffer state entry", "netanalyzer.buffer",
FT_NONE, BASE_NONE, NULL, 0x0,
"Info about reception buffer conditions", HFILL }
},
{ &hf_netanalyzer_buf_state,
{ "Buffer state", "netanalyzer.buffer.state",
FT_UINT8, BASE_DEC, VALS(buf_state_vals), 0x0,
"State of receive buffers", HFILL }
},
{ &hf_netanalyzer_buf_source,
{ "Buffer source", "netanalyzer.buffer.source",
FT_UINT8, BASE_DEC, VALS(buf_source_vals), 0x0,
"Source of buffer error", HFILL }
},
{ &hf_netanalyzer_timetick,
{ "Time tick", "netanalyzer.timetick",
FT_NONE, BASE_NONE, NULL, 0x0,
"Cyclic time tick of netANALYZER device", HFILL }
},
};
static gint *ett[] = {
&ett_netanalyzer,
&ett_netanalyzer_gpio,
&ett_netanalyzer_status,
&ett_netanalyzer_transparent,
&ett_netanalyzer_buf,
};
static ei_register_info ei[] = {
{ &ei_netanalyzer_header_version_wrong, { "netanalyzer.header_version.wrong", PI_PROTOCOL, PI_ERROR, "Wrong netANALYZER header version", EXPFILL }},
{ &ei_netanalyzer_header_wrong, { "netanalyzer.header.wrong", PI_PROTOCOL, PI_ERROR, "Wrong netANALYZER header", EXPFILL }},
{ &ei_netanalyzer_gpio_def_none, { "netanalyzer.gpio_def_none", PI_MALFORMED, PI_ERROR, "No valid netANALYZER GPIO definition found", EXPFILL }},
{ &ei_netanalyzer_header_version_none, { "netanalyzer.header_version.none", PI_MALFORMED, PI_ERROR, "No netANALYZER header found", EXPFILL }},
{ &ei_netanalyzer_header_none, { "netanalyzer.header.none", PI_MALFORMED, PI_ERROR, "No netANALYZER header found", EXPFILL }},
{ &ei_netanalyzer_transparent_frame, { "netanalyzer.transparent_frame", PI_PROTOCOL, PI_NOTE, "This frame was captured in transparent mode", EXPFILL }},
{ &ei_netanalyzer_alignment_error, { "netanalyzer.alignment_error", PI_PROTOCOL, PI_WARN, "Displayed frame data contains additional nibble due to alignment error (upper nibble is not valid)", EXPFILL }},
{ &ei_netanalyzer_not_implemented,{ "netanalyzer.not_implemented", PI_PROTOCOL, PI_ERROR, "This feature is currently not implemented in Wireshark", EXPFILL } },
};
expert_module_t* expert_netanalyzer;