aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-hartip.c
diff options
context:
space:
mode:
authorChris Maynard <Christopher.Maynard@GTECH.COM>2013-02-19 01:56:42 +0000
committerChris Maynard <Christopher.Maynard@GTECH.COM>2013-02-19 01:56:42 +0000
commit3010f6a0cc5dfd6a129f0b0006125b0c9a001c5f (patch)
tree55f913b68a7127227141dbf761f0921fd8433364 /epan/dissectors/packet-hartip.c
parent425ede28b4b0899303b77a36de1ad315fca7a41a (diff)
Don't call expert_add_info_format() from within an if (tree) {} block.
Misc. whitespace changes, remove tabs, add modelines to match current scheme. svn path=/trunk/; revision=47742
Diffstat (limited to 'epan/dissectors/packet-hartip.c')
-rw-r--r--epan/dissectors/packet-hartip.c187
1 files changed, 93 insertions, 94 deletions
diff --git a/epan/dissectors/packet-hartip.c b/epan/dissectors/packet-hartip.c
index 49f5406745..4a5719426c 100644
--- a/epan/dissectors/packet-hartip.c
+++ b/epan/dissectors/packet-hartip.c
@@ -26,7 +26,6 @@
*/
#include "config.h"
-
#include <glib.h>
#include <epan/conversation.h>
#include <epan/packet.h>
@@ -36,7 +35,6 @@
#include <epan/prefs.h>
#include "packet-tcp.h"
-
static dissector_handle_t hartip_tcp_handle;
static dissector_handle_t hartip_udp_handle;
@@ -199,7 +197,6 @@ typedef struct _hartip_hdr {
#define RESPONSE_MSG_TYPE 1
#define ERROR_MSG_TYPE 2
-
static const value_string hartip_message_id_values[] = {
{ SESSION_INITIATE_ID, "Session Initiate" },
{ SESSION_CLOSE_ID, "Session Close" },
@@ -225,7 +222,6 @@ static const value_string hartip_master_type_values[] = {
{ 0, NULL }
};
-
/* Error Codes */
#define SESSION_CLOSED_ERROR 0
#define PRIMARY_SESSION_UNAVAILABLE_ERROR 1
@@ -238,7 +234,6 @@ static const value_string hartip_error_code_values[] = {
{ 0, NULL }
};
-
/* Handle for statistics tap. */
static int hartip_tap = -1;
@@ -261,7 +256,8 @@ static int st_node_responses = -1;
static int st_node_errors = -1;
static void
-hartip_stats_tree_init(stats_tree* st) {
+hartip_stats_tree_init(stats_tree* st)
+{
st_node_packets = stats_tree_create_node(st, st_str_packets, 0, TRUE);
st_node_requests = stats_tree_create_pivot(st, st_str_requests, st_node_packets);
st_node_responses = stats_tree_create_node(st, st_str_responses, st_node_packets, TRUE);
@@ -269,8 +265,9 @@ hartip_stats_tree_init(stats_tree* st) {
}
static int
-hartip_stats_tree_packet(stats_tree* st, packet_info* pinfo _U_, epan_dissect_t* edt _U_, const void* p) {
-
+hartip_stats_tree_packet(stats_tree* st, packet_info* pinfo _U_,
+ epan_dissect_t* edt _U_, const void* p)
+{
const hartip_tap_info *tapinfo = p;
const gchar *message_type_node_str, *message_id_node_str;
int message_type_node;
@@ -293,7 +290,8 @@ hartip_stats_tree_packet(stats_tree* st, packet_info* pinfo _U_, epan_dissect_t*
}
message_id_node_str = val_to_str(tapinfo->message_id,
- hartip_message_id_values, "Unknown message %d");
+ hartip_message_id_values,
+ "Unknown message %d");
tick_stat_node(st, (guint8*)st_str_packets, 0, FALSE);
tick_stat_node(st, (guint8*)message_type_node_str, st_node_packets, FALSE);
@@ -304,7 +302,7 @@ hartip_stats_tree_packet(stats_tree* st, packet_info* pinfo _U_, epan_dissect_t*
static gint
dissect_empty_body(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb,
- gint offset, gint bodylen)
+ gint offset, gint bodylen)
{
proto_item *ti;
@@ -318,8 +316,8 @@ dissect_empty_body(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb,
}
static gint
-dissect_session_init(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_session_init(proto_tree *body_tree, tvbuff_t *tvb, gint offset,
+ gint bodylen)
{
if (bodylen == 5) {
proto_tree_add_item(body_tree, hf_hartip_master_type, tvb, offset, 1, ENC_BIG_ENDIAN);
@@ -334,8 +332,7 @@ dissect_session_init(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_error(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_error(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen == 1) {
proto_tree_add_item(body_tree, hf_hartip_error_code, tvb, offset, 1, ENC_BIG_ENDIAN);
@@ -348,14 +345,14 @@ dissect_error(proto_tree *body_tree, tvbuff_t *tvb,
static gint
dissect_session_close(proto_tree *body_tree, packet_info* pinfo, tvbuff_t *tvb,
- gint offset, gint bodylen)
+ gint offset, gint bodylen)
{
return dissect_empty_body(body_tree, pinfo, tvb, offset, bodylen);
}
static gint
dissect_keep_alive(proto_tree *body_tree, packet_info* pinfo, tvbuff_t *tvb,
- gint offset, gint bodylen)
+ gint offset, gint bodylen)
{
return dissect_empty_body(body_tree, pinfo, tvb, offset, bodylen);
}
@@ -366,6 +363,7 @@ dissect_byte(proto_tree *tree, int hf, tvbuff_t *tvb, gint offset)
proto_tree_add_item(tree, hf, tvb, offset, 1, ENC_BIG_ENDIAN);
return 1;
}
+
static gint
dissect_short(proto_tree *tree, int hf, tvbuff_t *tvb, gint offset)
{
@@ -382,7 +380,7 @@ dissect_float(proto_tree *tree, int hf, tvbuff_t *tvb, gint offset)
static gint
dissect_string(proto_tree *tree, int hf, const char *name, int len,
- tvbuff_t *tvb, gint offset)
+ tvbuff_t *tvb, gint offset)
{
proto_item *ti;
char *str;
@@ -400,7 +398,7 @@ dissect_string(proto_tree *tree, int hf, const char *name, int len,
static gint
dissect_packAscii(proto_tree *tree, int hf, const char *name, int len,
- tvbuff_t *tvb, gint offset)
+ tvbuff_t *tvb, gint offset)
{
gushort usIdx;
gushort usGroupCnt;
@@ -436,7 +434,7 @@ dissect_packAscii(proto_tree *tree, int hf, const char *name, int len,
/*
* Now transfer to unpacked area, setting bit 6 to complement of bit 5.
*/
- for (usIdx = 0; usIdx < 4; usIdx++) {
+ for (usIdx = 0; usIdx < 4; usIdx++) {
usMask = (gushort)(((buf[usIdx] & 0x20) << 1) ^ 0x40);
DISSECTOR_ASSERT(i < 256);
str[i++] = (gchar)(buf[usIdx] | usMask);
@@ -450,7 +448,7 @@ dissect_packAscii(proto_tree *tree, int hf, const char *name, int len,
static gint
dissect_timestamp(proto_tree *tree, int hf, const char *name, int len,
- tvbuff_t *tvb, gint offset)
+ tvbuff_t *tvb, gint offset)
{
proto_item *ti;
guint32 t;
@@ -477,8 +475,7 @@ dissect_timestamp(proto_tree *tree, int hf, const char *name, int len,
}
static gint
-dissect_cmd0(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd0(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 22) {
offset += dissect_byte(body_tree, hf_hartip_pt_rsp_expansion_code, tvb, offset);
@@ -506,8 +503,7 @@ dissect_cmd0(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_cmd1(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd1(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 5) {
offset += dissect_byte(body_tree, hf_hartip_pt_rsp_pv_units, tvb, offset);
@@ -519,8 +515,7 @@ dissect_cmd1(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_cmd2(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd2(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 8) {
offset += dissect_float(body_tree, hf_hartip_pt_rsp_pv_loop_current, tvb, offset);
@@ -532,8 +527,7 @@ dissect_cmd2(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_cmd3(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd3(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 24) {
offset += dissect_float(body_tree, hf_hartip_pt_rsp_pv_loop_current, tvb, offset);
@@ -553,8 +547,7 @@ dissect_cmd3(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_cmd9(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd9(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 14) {
offset += dissect_byte(body_tree, hf_hartip_pt_rsp_extended_device_status, tvb, offset);
@@ -629,8 +622,7 @@ dissect_cmd9(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_cmd13(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd13(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 21) {
offset += dissect_packAscii(body_tree, hf_hartip_pt_rsp_tag, "Tag", 6, tvb, offset);
@@ -646,8 +638,7 @@ dissect_cmd13(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_cmd48(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_cmd48(proto_tree *body_tree, tvbuff_t *tvb, gint offset, gint bodylen)
{
if (bodylen >= 9) {
proto_tree_add_item(body_tree, hf_hartip_pt_rsp_device_sp_status, tvb, offset, 5, ENC_NA);
@@ -675,8 +666,8 @@ dissect_cmd48(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_parse_hart_cmds(proto_tree *body_tree, tvbuff_t *tvb,
- guint8 cmd, gint offset, gint bodylen)
+dissect_parse_hart_cmds(proto_tree *body_tree, tvbuff_t *tvb, guint8 cmd,
+ gint offset, gint bodylen)
{
switch(cmd)
{
@@ -708,8 +699,8 @@ dissect_parse_hart_cmds(proto_tree *body_tree, tvbuff_t *tvb,
}
static gint
-dissect_pass_through(proto_tree *body_tree, tvbuff_t *tvb,
- gint offset, gint bodylen)
+dissect_pass_through(proto_tree *body_tree, tvbuff_t *tvb, gint offset,
+ gint bodylen)
{
proto_item *ti;
guint8 delimiter;
@@ -732,7 +723,7 @@ dissect_pass_through(proto_tree *body_tree, tvbuff_t *tvb,
if (num_preambles > 0) {
proto_tree_add_item(body_tree, hf_hartip_pt_preambles, tvb, offset,
- num_preambles, ENC_NA);
+ num_preambles, ENC_NA);
offset += num_preambles;
length -= num_preambles;
}
@@ -740,7 +731,7 @@ dissect_pass_through(proto_tree *body_tree, tvbuff_t *tvb,
if (length > 0) {
delimiter = tvb_get_guint8(tvb, offset);
ti = proto_tree_add_uint(body_tree, hf_hartip_pt_delimiter, tvb, offset, 1,
- delimiter);
+ delimiter);
offset++;
length--;
@@ -807,7 +798,7 @@ dissect_pass_through(proto_tree *body_tree, tvbuff_t *tvb,
result = dissect_parse_hart_cmds(body_tree, tvb, cmd, offset, length);
if (result == 0 ) {
proto_tree_add_item(body_tree, hf_hartip_pt_payload, tvb, offset,
- (length - 1), ENC_NA);
+ (length - 1), ENC_NA);
}
offset += (length - 1);
length = 1;
@@ -824,8 +815,7 @@ hartip_set_conversation(packet_info *pinfo)
{
conversation_t *conversation = NULL;
- if (!pinfo->fd->flags.visited &&
- (pinfo->ptype == PT_UDP)) {
+ if (!pinfo->fd->flags.visited && (pinfo->ptype == PT_UDP)) {
/*
* This function is called for a session initiate send over UDP.
* The session initiate is sent to the server on port HARTIP_PORT.
@@ -838,20 +828,21 @@ hartip_set_conversation(packet_info *pinfo)
* for this protocol.
*/
conversation = find_conversation(pinfo->fd->num,
- &pinfo->src, &pinfo->dst, pinfo->ptype,
- pinfo->srcport, 0, NO_PORT_B);
+ &pinfo->src, &pinfo->dst, pinfo->ptype,
+ pinfo->srcport, 0, NO_PORT_B);
if( (conversation == NULL) ||
- (conversation->dissector_handle != hartip_udp_handle) ) {
+ (conversation->dissector_handle != hartip_udp_handle) ) {
conversation = conversation_new(pinfo->fd->num,
- &pinfo->src, &pinfo->dst, pinfo->ptype,
- pinfo->srcport, 0, NO_PORT2);
+ &pinfo->src, &pinfo->dst, pinfo->ptype,
+ pinfo->srcport, 0, NO_PORT2);
conversation_set_dissector(conversation, hartip_udp_handle);
}
}
}
static int
-dissect_hartip_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
+dissect_hartip_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+ gint offset)
{
proto_tree *hartip_tree, *hdr_tree, *body_tree;
proto_item *ti, *hart_item;
@@ -902,15 +893,12 @@ dissect_hartip_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint
proto_tree_add_item(hdr_tree, hf_hartip_hdr_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
- proto_item_append_text(hart_item, ", %s %s, Sequence Number %d",
- msg_id_str,
- msg_type_str,
- transaction_id);
+ proto_item_append_text(hart_item, ", %s %s, Sequence Number %d", msg_id_str,
+ msg_type_str, transaction_id);
- col_append_sep_fstr(pinfo->cinfo, COL_INFO, " | ", "%s %s, Sequence Number %d",
- msg_id_str,
- msg_type_str,
- transaction_id);
+ col_append_sep_fstr(pinfo->cinfo, COL_INFO, " | ",
+ "%s %s, Sequence Number %d",
+ msg_id_str, msg_type_str, transaction_id);
col_set_fence(pinfo->cinfo, COL_INFO);
ti = proto_tree_add_item(hdr_tree, hf_hartip_hdr_msg_length, tvb, offset, 2, ENC_BIG_ENDIAN);
@@ -918,41 +906,34 @@ dissect_hartip_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint
bodylen = length - HARTIP_HEADER_LENGTH;
- if (tree) {
- /* add body elements. */
- ti = proto_tree_add_text(hartip_tree, tvb, offset, bodylen, "HART_IP Body, %s, %s",
- msg_id_str,
- msg_type_str);
- body_tree = proto_item_add_subtree(ti, ett_hartip_body);
+ /* add body elements. */
+ ti = proto_tree_add_text(hartip_tree, tvb, offset, bodylen,
+ "HART_IP Body, %s, %s", msg_id_str, msg_type_str);
+ body_tree = proto_item_add_subtree(ti, ett_hartip_body);
- if (message_type == ERROR_MSG_TYPE) {
- offset += dissect_error(body_tree, tvb, offset, bodylen);
- } else {
- /* Dissect the various HARTIP messages. */
- switch(message_id) {
- case SESSION_INITIATE_ID:
- offset += dissect_session_init(body_tree, tvb, offset, bodylen);
- break;
- case SESSION_CLOSE_ID:
- offset += dissect_session_close(body_tree, pinfo, tvb, offset, bodylen);
- break;
- case KEEP_ALIVE_ID:
- offset += dissect_keep_alive(body_tree, pinfo, tvb, offset, bodylen);
- break;
- case PASS_THROUGH_ID:
- offset += dissect_pass_through(body_tree, tvb, offset, bodylen);
- break;
- default:
- proto_tree_add_item(body_tree, hf_hartip_data, tvb, offset,
- bodylen, ENC_NA);
- offset += bodylen;
- break;
- }
+ if (message_type == ERROR_MSG_TYPE) {
+ offset += dissect_error(body_tree, tvb, offset, bodylen);
+ } else {
+ /* Dissect the various HARTIP messages. */
+ switch(message_id) {
+ case SESSION_INITIATE_ID:
+ offset += dissect_session_init(body_tree, tvb, offset, bodylen);
+ break;
+ case SESSION_CLOSE_ID:
+ offset += dissect_session_close(body_tree, pinfo, tvb, offset, bodylen);
+ break;
+ case KEEP_ALIVE_ID:
+ offset += dissect_keep_alive(body_tree, pinfo, tvb, offset, bodylen);
+ break;
+ case PASS_THROUGH_ID:
+ offset += dissect_pass_through(body_tree, tvb, offset, bodylen);
+ break;
+ default:
+ proto_tree_add_item(body_tree, hf_hartip_data, tvb, offset, bodylen, ENC_NA);
+ offset += bodylen;
+ break;
}
}
- else {
- offset += length;
- }
return offset;
}
@@ -970,17 +951,20 @@ dissect_hartip_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
static int
-dissect_hartip_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+dissect_hartip_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+ void *data _U_)
{
if (!tvb_bytes_exist(tvb, 0, HARTIP_HEADER_LENGTH))
return 0;
- tcp_dissect_pdus(tvb, pinfo, tree, hartip_desegment, HARTIP_HEADER_LENGTH, get_dissect_hartip_len, dissect_hartip_pdu);
+ tcp_dissect_pdus(tvb, pinfo, tree, hartip_desegment, HARTIP_HEADER_LENGTH,
+ get_dissect_hartip_len, dissect_hartip_pdu);
return tvb_reported_length(tvb);
}
static int
-dissect_hartip_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+dissect_hartip_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
+ void *data _U_)
{
gint offset = 0;
@@ -1520,7 +1504,8 @@ proto_register_hartip(void)
{ "Analog Channel Fixed", "hart_ip.pt.rsp.analog_channel_fixed",
FT_UINT8, BASE_DEC, NULL, 0x0,
NULL, HFILL
- }}
+ }
+ }
};
static gint *ett[] = {
@@ -1553,5 +1538,19 @@ proto_reg_handoff_hartip(void)
dissector_add_uint("tcp.port", HARTIP_PORT, hartip_tcp_handle);
stats_tree_register("hart_ip", "hart_ip", "HART-IP", 0,
- hartip_stats_tree_packet, hartip_stats_tree_init, NULL );
+ hartip_stats_tree_packet, hartip_stats_tree_init, NULL);
}
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 2
+ * tab-width: 2
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=2 tabstop=2 expandtab:
+ * :indentSize=2:tabSize=2:noTabs=true:
+ */
+