2 * Routines for gvcp (GigEVision Control Protocol) dissection
3 * Copyright 2010, Adrian Daerr <adrian.daerr@gmx.de>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 * Credits to Falco Hirschenberger for his description of GVCP
28 * ( http://gitorious.org/opengigevision )
30 * GVCP is part of the GigE-Vision interface (a closed standard) to
31 * so-called industrial cameras.
33 * see also: http://en.wikipedia.org/wiki/GigE_vision
35 * This dissector is based on traffic analysis alone, as the
36 * description of the GVCP is accessible only to members of the
37 * Automated Imaging Association. The resulting packet description is
38 * therefore likely to be incomplete or inaccurate.
41 * - fill holes (missing opcodes / field meanings / ...)
42 * - conversation level:
43 * . validity of anwers (is CMD packet properly ACK'ed by follow-up packet?)
44 * . reassemble, unzip, store and parse XML file, so that addresses
45 * may be translated back into register names
50 #include <epan/packet.h>
51 #include <epan/wmem/wmem.h>
53 #define GVCP_PORT 3956
55 static int proto_gvcp
= -1;
56 static int hf_gvcp_type
= -1;
57 static int hf_gvcp_opcode
= -1;
58 static int hf_gvcp_payloadsize
= -1;
59 static int hf_gvcp_sequenceno
= -1;
60 static int hf_gvcp_address
= -1;
61 static int hf_gvcp_value
= -1;
62 static int hf_gvcp_address2
= -1;
63 static int hf_gvcp_value2
= -1;
64 static int hf_gvcp_remainder
= -1;
65 static int hf_gvcp_nwritten
= -1;
66 static int hf_gvcp_nbytes
= -1;
67 static int hf_gvcp_unknown16
= -1;
68 static int hf_gvcp_data
= -1;
69 static int hf_gvcp_ip
= -1;
70 static int hf_gvcp_ether
= -1;
71 static int hf_gvcp_netmask
= -1;
72 static gint ett_gvcp
= -1;
74 static const value_string opcode_names
[] = {
75 { 0x02, "Discovery ping" },
76 { 0x03, "Discovery pong" },
77 { 0x04, "Assign IP" },
78 { 0x05, "Ack IP change" },
79 { 0x40, "Resend request" },
80 { 0x80, "Register read request" },
81 { 0x81, "Register read answer" },
82 { 0x82, "Register write request" },
83 { 0x83, "Register write answer" },
84 { 0x84, "MemBlock read request" },
85 { 0x85, "MemBlock read answer" },
86 { 0x86, "MemBlock write request" },
87 { 0x87, "MemBlock write answer" },
92 static const value_string opcode_short_names
[] = {
93 { 0x02, "Disc_Ping" },
94 { 0x03, "Disc_Pong" },
95 { 0x04, "Assign IP" },
98 { 0x80, "Reg_Rd_Req" },
99 { 0x81, "Reg_Rd_Ans" },
100 { 0x82, "Reg_Wr_Req" },
101 { 0x83, "Reg_Wr_Ans" },
102 { 0x84, "Blk_Rd_Req" },
103 { 0x85, "Blk_Rd_Ans" },
104 { 0x86, "Blk_Wr_Req" },
105 { 0x87, "Blk_Wr_Ans" },
111 dissect_gvcp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
113 guint16 packet_type
, packet_opcode
, packet_plsize
;
116 /* Check that there's enough data */
117 if (tvb_length(tvb
) < 8)
120 /* Do some tests on what seems to be PDU field to determine if we
121 really have a GVCP packet here, otherwise return 0 to give
122 another dissector a chance to dissect it. */
123 packet_type
= tvb_get_ntohs(tvb
, 0);
125 /* packets from the PC to the camera on GVCP_PORT seem to always
126 start with 0x4201 or 0x4200 */
127 if ( pinfo
->destport
== GVCP_PORT
&&
128 (packet_type
!= 0x4200 && packet_type
!= 0x4201) )
131 /* packets from the camera GVCP_PORT to the PC seem to start
132 with 0x0000, but can be different on error condition (e.g. 0x8005) */
134 if ( pinfo
->srcport
== GVCP_PORT
&& tvb_get_ntohs(tvb
, 0) != 0x0 )
138 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "GVCP");
139 /* Clear out stuff in the info column */
140 col_clear(pinfo
->cinfo
,COL_INFO
);
142 /* dissect 8 byte header */
143 packet_opcode
= tvb_get_ntohs(tvb
, 2);
144 packet_plsize
= tvb_get_ntohs(tvb
, 4);
146 /* allocate growable info string */
147 info
= wmem_strbuf_new(wmem_packet_scope(), val_to_str(packet_opcode
, opcode_names
, "Unknown opcode (0x%04x)"));
149 /* check that GVCP header+payload match total packet size */
150 if (tvb_reported_length(tvb
) < 8+(guint32
)packet_plsize
) {
151 wmem_strbuf_append_printf(info
, " (truncated? %u bytes missing)",
152 (8 + packet_plsize
) - tvb_reported_length(tvb
));
153 col_add_str(pinfo
->cinfo
, COL_INFO
, wmem_strbuf_get_str(info
));
154 return tvb_length(tvb
);/* or should we assume this is not GVCP, return 0?*/
156 if (tvb_reported_length(tvb
) > 8+(guint32
)packet_plsize
) {
157 wmem_strbuf_append_printf(info
, " (%u excess bytes)",
158 tvb_reported_length(tvb
) - (8 + packet_plsize
));
159 col_add_str(pinfo
->cinfo
, COL_INFO
, wmem_strbuf_get_str(info
));
160 return tvb_length(tvb
);/* or should we assume this is not GVCP, return 0?*/
162 if (packet_plsize
& 3) {/* payload is always a multiple of 4 bytes */
163 wmem_strbuf_append(info
, " (payload is not multiple of 4 bytes)");
164 col_add_str(pinfo
->cinfo
, COL_INFO
, wmem_strbuf_get_str(info
));
165 return tvb_length(tvb
);/* or should we assume this is not GVCP, return 0?*/
168 /* switch just concerned with building a meaningfull Info column string */
170 switch (packet_opcode
) {
171 case 0x04: /* Assign new temporary IP */
172 if (packet_plsize
< 24) {/* 56 bytes seem to be normal */
173 wmem_strbuf_append(info
, " <missing args>");
174 } else { /* packet contain new network configuration */
175 wmem_strbuf_append_printf(info
, "%d.%d.%d.%d to %s",
176 tvb_get_guint8(tvb
, 28), tvb_get_guint8(tvb
, 29),
177 tvb_get_guint8(tvb
, 30), tvb_get_guint8(tvb
, 31),
178 tvb_bytes_to_str_punct(tvb
, 10, 6, ':'));
181 case 0x80: /* Register Read Request */
182 case 0x81: /* Register Read Answer */
183 if (packet_plsize
== 0) {
184 wmem_strbuf_append(info
, " <missing arg(s)>");
185 } else { /* packet contains address(es) to read from */
186 wmem_strbuf_append_printf(info
, " 0x%08x", tvb_get_ntohl(tvb
, 8));
187 if (packet_plsize
>= 8) {
188 wmem_strbuf_append_printf(info
, ", 0x%08x", tvb_get_ntohl(tvb
, 12));
189 if (packet_plsize
>= 12)
190 wmem_strbuf_append(info
, ", ...");
194 case 0x82: /* Register Write Request */
195 if (packet_plsize
< 8) {
196 wmem_strbuf_append(info
, " <missing arg(s)>");
197 } else { /* packet contains address/value pairs to read from */
198 wmem_strbuf_append_printf(info
, " *0x%08x = 0x%08x", tvb_get_ntohl(tvb
, 8),
199 tvb_get_ntohl(tvb
, 12));
200 if (packet_plsize
>= 16) {
201 wmem_strbuf_append_printf(info
, ", *0x%08x = 0x%08x",
202 tvb_get_ntohl(tvb
, 16), tvb_get_ntohl(tvb
, 20));
203 if (packet_plsize
>= 24)
204 wmem_strbuf_append(info
, ", ...");
208 case 0x83: /* Register Write Answer */
209 if (packet_plsize
< 4) {
210 wmem_strbuf_append(info
, " <missing arg>");
212 wmem_strbuf_append_printf(info
, " %d register%s written",
213 tvb_get_ntohl(tvb
, 8),
214 tvb_get_ntohl(tvb
, 8)==1?"":"s");
217 case 0x84: /* Block Read Request */
218 if (packet_plsize
< 8) {
219 wmem_strbuf_append(info
, " <missing args>");
220 } else { /* packet contains address/size pair to read from */
221 wmem_strbuf_append_printf(info
, " 0x%08x (%d bytes, X=0x%04x)",
222 tvb_get_ntohl(tvb
, 8), tvb_get_ntohs(tvb
, 14),
223 tvb_get_ntohs(tvb
, 12));
224 if (packet_plsize
> 8) {
225 wmem_strbuf_append(info
, "; excess payload");
229 case 0x85: /* Block Read Answer */
230 if (packet_plsize
< 8) {
231 wmem_strbuf_append(info
, " <missing args>");
232 } else { /* packet contains desired data */
233 wmem_strbuf_append_printf(info
, " %d bytes from 0x%08x", packet_plsize
- 4,
234 tvb_get_ntohl(tvb
, 8));
237 case 0x86: /* Block Write Request */
238 if (packet_plsize
< 8) {
239 wmem_strbuf_append(info
, " <missing args>");
240 } else { /* packet contains desired data */
241 wmem_strbuf_append_printf(info
, " *0x%08x = <%d bytes>",
242 tvb_get_ntohl(tvb
, 8), packet_plsize
- 4);
245 case 0x87: /* Block Write Answer */
246 if (packet_plsize
< 4) {
247 wmem_strbuf_append(info
, " <missing arg>");
249 wmem_strbuf_append_printf(info
, " %d bytes written", tvb_get_ntohl(tvb
, 8));
254 col_add_str(pinfo
->cinfo
, COL_INFO
, wmem_strbuf_get_str(info
));
256 if (tree
) { /* we are being asked for details */
257 proto_item
*ti
= NULL
;
258 proto_tree
*gvcp_tree
= NULL
;
260 ti
= proto_tree_add_item(tree
, proto_gvcp
, tvb
, 0, -1, ENC_NA
);
261 gvcp_tree
= proto_item_add_subtree(ti
, ett_gvcp
);
262 proto_tree_add_item(gvcp_tree
, hf_gvcp_type
, tvb
, 0, 2, ENC_BIG_ENDIAN
);
263 proto_tree_add_item(gvcp_tree
, hf_gvcp_opcode
, tvb
, 2, 2, ENC_BIG_ENDIAN
);
264 proto_tree_add_item(gvcp_tree
, hf_gvcp_payloadsize
, tvb
, 4, 2, ENC_BIG_ENDIAN
);
265 proto_tree_add_item(gvcp_tree
, hf_gvcp_sequenceno
, tvb
, 6, 2, ENC_BIG_ENDIAN
);
267 /* opcode specific fields */
268 switch (packet_opcode
) {
269 case 0x04: /* Assign new temporary network configuration */
270 if (packet_plsize
>= 48) {
271 proto_tree_add_item(gvcp_tree
, hf_gvcp_ether
, tvb
, 10, 6, ENC_NA
);
272 proto_tree_add_item(gvcp_tree
, hf_gvcp_ip
, tvb
, 28, 4, ENC_BIG_ENDIAN
);
273 proto_tree_add_item(gvcp_tree
, hf_gvcp_netmask
, tvb
, 44, 4, ENC_BIG_ENDIAN
);
276 case 0x80: /* Register Read Request */
277 if (packet_plsize
>= 4) {
278 proto_tree_add_item(gvcp_tree
, hf_gvcp_address
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
279 if (packet_plsize
>= 8) {
280 proto_tree_add_item(gvcp_tree
, hf_gvcp_address2
, tvb
, 12, 4, ENC_BIG_ENDIAN
);
281 if (packet_plsize
>= 12)
282 proto_tree_add_item(gvcp_tree
, hf_gvcp_remainder
, tvb
, 16, -1, ENC_NA
);
286 case 0x81: /* Register Read Answer */
287 if (packet_plsize
>= 4) {
288 proto_tree_add_item(gvcp_tree
, hf_gvcp_value
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
289 if (packet_plsize
>= 8) {
290 proto_tree_add_item(gvcp_tree
, hf_gvcp_value2
, tvb
, 12, 4, ENC_BIG_ENDIAN
);
291 if (packet_plsize
>= 12)
292 proto_tree_add_item(gvcp_tree
, hf_gvcp_remainder
, tvb
, 16, -1, ENC_NA
);
296 case 0x82: /* Register Write Request */
297 if (packet_plsize
>= 8) {
298 proto_tree_add_item(gvcp_tree
, hf_gvcp_address
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
299 proto_tree_add_item(gvcp_tree
, hf_gvcp_value
, tvb
, 12, 4, ENC_BIG_ENDIAN
);
300 if (packet_plsize
>= 16) {
301 proto_tree_add_item(gvcp_tree
, hf_gvcp_address2
, tvb
, 16, 4, ENC_BIG_ENDIAN
);
302 proto_tree_add_item(gvcp_tree
, hf_gvcp_value2
, tvb
, 20, 4, ENC_BIG_ENDIAN
);
303 if (packet_plsize
>= 24)
304 proto_tree_add_item(gvcp_tree
, hf_gvcp_remainder
, tvb
, 24, -1, ENC_NA
);
308 case 0x83: /* Register Write Answer */
309 if (packet_plsize
>= 4)
310 proto_tree_add_item(gvcp_tree
, hf_gvcp_nwritten
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
312 case 0x84: /* Block Read Request */
313 if (packet_plsize
>= 8) {
314 proto_tree_add_item(gvcp_tree
, hf_gvcp_address
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
315 proto_tree_add_item(gvcp_tree
, hf_gvcp_unknown16
, tvb
, 12, 2, ENC_BIG_ENDIAN
);
316 proto_tree_add_item(gvcp_tree
, hf_gvcp_nbytes
, tvb
, 14, 2, ENC_BIG_ENDIAN
);
319 case 0x85: /* Block Read Answer */
320 case 0x86: /* Block Write Request */
321 if (packet_plsize
>= 8) {
322 proto_tree_add_item(gvcp_tree
, hf_gvcp_address
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
323 proto_tree_add_item(gvcp_tree
, hf_gvcp_data
, tvb
, 12, -1, ENC_NA
);
326 case 0x87: /* Block Write Answer */
327 if (packet_plsize
>= 4)
328 proto_tree_add_item(gvcp_tree
, hf_gvcp_nbytes
, tvb
, 10, 2, ENC_BIG_ENDIAN
);
331 if (packet_plsize
> 0)
332 proto_tree_add_item(gvcp_tree
, hf_gvcp_data
, tvb
, 8, -1, ENC_NA
);
338 return tvb_length(tvb
);
342 proto_register_gvcp(void)
344 static hf_register_info hf
[] = {
346 { "GVCP Type", "gvcp.type",
352 { "GVCP Opcode", "gvcp.opcode",
354 VALS(opcode_names
), 0x0,
357 { &hf_gvcp_payloadsize
,
358 { "GVCP Payload bytes", "gvcp.size",
363 { &hf_gvcp_sequenceno
,
364 { "GVCP Sequence number", "gvcp.seqn",
370 { "Address", "gvcp.address",
376 { "Value", "gvcp.value",
382 { "Address 2", "gvcp.address2",
388 { "Value 2", "gvcp.value2",
393 { &hf_gvcp_remainder
,
394 { "Remaining arguments", "gvcp.remainder",
400 { "Number of registers written", "gvcp.nwritten",
406 { "Number of bytes", "gvcp.nbytes",
411 { &hf_gvcp_unknown16
,
412 { "2-byte unknown meaning", "gvcp.unknown16",
418 { "Data", "gvcp.data",
424 { "Link layer address (ethernet)", "gvcp.ether",
430 { "IPv4 address", "gvcp.ip",
436 { "Netmask", "gvcp.netmask",
443 /* Setup protocol subtree array */
444 static gint
*ett
[] = {
448 proto_gvcp
= proto_register_protocol ("GigE Vision Control Protocol", /*name*/
449 "GVCP", /* short name */
450 "gvcp" /* abbrev */);
452 proto_register_field_array(proto_gvcp
, hf
, array_length(hf
));
453 proto_register_subtree_array(ett
, array_length(ett
));
458 proto_reg_handoff_gvcp(void)
460 dissector_handle_t gvcp_handle
;
462 gvcp_handle
= new_create_dissector_handle(dissect_gvcp
, proto_gvcp
);
463 dissector_add_uint("udp.port", GVCP_PORT
, gvcp_handle
);