6fa8c820f4aec998e16f67e0408abdf0c47f2833
[obnox/wireshark/wip.git] / epan / dissectors / packet-vicp.c
1 /* packet-vicp.c
2  * LeCroy VICP (GPIB-over-Ethernet-but-lets-not-do-LXI) dissector
3  *
4  * Written by Frank Kingswood <frank.kingswood@artimi.com>
5  * Copyright 2008, Artimi Ltd.
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <epan/packet.h>
33 #include <epan/emem.h>
34 #include <epan/ptvcursor.h>
35
36 /* registration object IDs */
37 static int proto_vicp = -1;
38 static int hf_vicp_operation = -1;
39 static int hf_vicp_version = -1;
40 static int hf_vicp_sequence = -1;
41 static int hf_vicp_unused = -1;
42 static int hf_vicp_length = -1;
43 static int hf_vicp_data = -1;
44 static gint ett_vicp = -1;
45
46 #define VICP_PORT 1861
47
48 static void dissect_vicp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
49 {
50    proto_item *ti;
51    proto_tree *vicp_tree;
52    ptvcursor_t* cursor;
53
54    unsigned len;
55
56    if (tvb_reported_length_remaining(tvb, 0) < 8)
57    {
58       /* Payload too small for VICP */
59       return;
60    }
61
62    if (check_col(pinfo->cinfo, COL_PROTOCOL))
63       col_set_str(pinfo->cinfo, COL_PROTOCOL, "VICP");
64
65    if (check_col(pinfo->cinfo, COL_INFO)) 
66       col_clear(pinfo->cinfo, COL_INFO);
67
68    ti = proto_tree_add_item(tree, proto_vicp, tvb, 0, -1, FALSE);
69    vicp_tree = proto_item_add_subtree(ti, ett_vicp);
70    cursor = ptvcursor_new(vicp_tree, tvb, 0);
71
72    ptvcursor_add(cursor, hf_vicp_operation, 1, FALSE);
73    ptvcursor_add(cursor, hf_vicp_version,   1, FALSE);
74    ptvcursor_add(cursor, hf_vicp_sequence,  1, FALSE);
75    ptvcursor_add(cursor, hf_vicp_unused,    1, FALSE);
76
77    len=tvb_get_ntohl(tvb, ptvcursor_current_offset(cursor));
78    ptvcursor_add(cursor, hf_vicp_length, 4, FALSE);
79
80    if(len==0)
81       proto_tree_add_text(vicp_tree, tvb, 0, 0, "No data");
82    else
83       ptvcursor_add(cursor, hf_vicp_data, len, FALSE);
84
85    ptvcursor_free(cursor);
86 }
87
88 void proto_register_vicp(void)
89 {
90    static hf_register_info hf[] =
91    {
92       {  &hf_vicp_operation,
93          { "Operation","vicp.operation",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL }
94       },
95       {  &hf_vicp_version,
96          { "Protocol version","vicp.version",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL }
97       },
98       {  &hf_vicp_sequence,
99          { "Sequence number","vicp.sequence",FT_UINT8,BASE_DEC,NULL,0x0,NULL,HFILL }
100       },
101       {  &hf_vicp_unused,
102          { "Unused","vicp.unused",FT_UINT8,BASE_HEX,NULL,0x0,NULL,HFILL }
103       },
104       {  &hf_vicp_length,
105          { "Data length","vicp.length",FT_UINT32,BASE_DEC,NULL,0x0,NULL,HFILL }
106       },
107       {  &hf_vicp_data,
108          { "Data","vicp.data",FT_BYTES,BASE_NONE,NULL,0x0,NULL,HFILL }
109       }
110    };
111
112    static gint *ett[] =
113    {  &ett_vicp
114    };
115
116    proto_vicp = proto_register_protocol("LeCroy VICP", "VICP", "vicp");
117    proto_register_field_array(proto_vicp, hf, array_length(hf));
118    proto_register_subtree_array(ett, array_length(ett));
119 }
120
121 void proto_reg_handoff_vicp(void)
122 {  dissector_handle_t vicp_handle;
123
124    vicp_handle = create_dissector_handle(dissect_vicp, proto_vicp);
125    dissector_add("tcp.port", VICP_PORT, vicp_handle);
126 }