some compilers dont like unnamed unions and structs
[obnox/wireshark/wip.git] / epan / dissectors / packet-ax4000.c
1 /* packet-ax4000.c
2  * Routines for Spirent AX/4000 Test Block dissection
3  * Copyright 2004, SEKINE Hideki <sekineh@gf7.so-net.ne.jp>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  * 
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.
20  * 
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <glib.h>
35
36 #include <epan/packet.h>
37 #include <ipproto.h>
38
39 /* Initialize the protocol and registered fields */
40 static int proto_ax4000 = -1;
41 static int hf_ax4000_port = -1;
42 static int hf_ax4000_chassis = -1;
43 static int hf_ax4000_fill = -1;
44 static int hf_ax4000_index = -1;
45 static int hf_ax4000_timestamp = -1;
46 static int hf_ax4000_seq = -1;
47 static int hf_ax4000_crc = -1;
48
49 /* Initialize the subtree pointers */
50 static gint ett_ax4000 = -1;
51
52 /* Code to actually dissect the packets */
53 static void
54 dissect_ax4000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
55 {
56         proto_item *ti;
57         proto_tree *ax4000_tree;
58         
59         guint8 ax_port;
60         guint8 ax_chassis;
61         guint16 ax_index;
62         guint32 ax_seq;
63         guint32 ax_timestamp;
64
65         /* Make entries in Protocol column and Info column on summary display */
66         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
67                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AX4000");
68     
69         ax_port = tvb_get_guint8(tvb, 0);
70         ax_chassis = tvb_get_guint8(tvb, 1);
71         ax_index = tvb_get_ntohs(tvb, 2) & 0x0FFF;
72         ax_timestamp = tvb_get_letohl(tvb, 6);
73         ax_seq = tvb_get_letohl(tvb, 10);
74         
75         if (check_col(pinfo->cinfo, COL_INFO)) {
76                 col_set_str(pinfo->cinfo, COL_INFO, "");
77                 col_append_fstr(pinfo->cinfo, COL_INFO,
78                         "Chss:%u Prt:%u Idx:%u Seq:0x%08x TS:%.6f[msec]",
79                         ax_chassis, ax_port, ax_index, ax_seq, ax_timestamp*1e-5);
80         }
81         
82         if (tree) {
83                 /* create display subtree for the protocol */
84                 ti = proto_tree_add_item(tree, proto_ax4000, tvb, 0, -1, FALSE);
85
86                 ax4000_tree = proto_item_add_subtree(ti, ett_ax4000);
87
88                 proto_tree_add_uint(ax4000_tree,
89                     hf_ax4000_port, tvb, 0, 1, ax_port);
90                 proto_tree_add_uint(ax4000_tree,
91                     hf_ax4000_chassis, tvb, 1, 1, ax_chassis);
92                 proto_tree_add_item(ax4000_tree,
93                     hf_ax4000_fill, tvb, 2, 1, FALSE);
94                 proto_tree_add_uint(ax4000_tree,
95                     hf_ax4000_index, tvb, 2, 2, ax_index);
96                 proto_tree_add_uint(ax4000_tree,
97                     hf_ax4000_timestamp, tvb, 6, 4, ax_timestamp);
98                 proto_tree_add_uint(ax4000_tree,
99                     hf_ax4000_seq, tvb, 10, 4, ax_seq);
100                 proto_tree_add_uint(ax4000_tree,
101                     hf_ax4000_crc, tvb, 14, 2, tvb_get_letohs(tvb, 14));
102         }
103
104 /* If this protocol has a sub-dissector call it here, see section 1.8 */
105 }
106
107 /* Register the protocol with Wireshark */
108
109 /* this format is require because a script is used to build the C function
110    that calls all the protocol registration.
111 */
112
113 void
114 proto_register_ax4000(void)
115 {                 
116         static hf_register_info hf[] = {
117                 { &hf_ax4000_port,
118                         { "Port Number", "ax4000.port",
119                         FT_UINT8, BASE_DEC, NULL, 0x0,          
120                         "", HFILL }
121                 },
122                 { &hf_ax4000_chassis,
123                         { "Chassis Number", "ax4000.chassis",
124                         FT_UINT8, BASE_DEC, NULL, 0x0,          
125                         "", HFILL }
126                 },
127                 { &hf_ax4000_fill,
128                         { "Fill Type", "ax4000.fill",
129                         FT_UINT8, BASE_DEC, NULL, 0xc0,          
130                         "", HFILL }
131                 },
132                 { &hf_ax4000_index,
133                         { "Index", "ax4000.index",
134                         FT_UINT16, BASE_DEC, NULL, 0x0FFF,          
135                         "", HFILL }
136                 },
137                 { &hf_ax4000_timestamp,
138                         { "Timestamp", "ax4000.timestamp",
139                         FT_UINT32, BASE_HEX, NULL, 0x0,          
140                         "", HFILL }
141                 },
142                 { &hf_ax4000_seq,
143                         { "Sequence Number", "ax4000.seq",
144                         FT_UINT32, BASE_HEX, NULL, 0x0,          
145                         "", HFILL }
146                 },
147                 { &hf_ax4000_crc,
148                         { "CRC (unchecked)", "ax4000.crc",
149                         FT_UINT16, BASE_HEX, NULL, 0x0,          
150                         "", HFILL }
151                 }
152         };
153
154         /* Setup protocol subtree array */
155         static gint *ett[] = {
156                 &ett_ax4000
157         };
158
159         /* Register the protocol name and description */
160         proto_ax4000 = proto_register_protocol("AX/4000 Test Block",
161             "AX4000", "ax4000");
162
163         /* Required function calls to register the header fields and subtrees used */
164         proto_register_field_array(proto_ax4000, hf, array_length(hf));
165         proto_register_subtree_array(ett, array_length(ett));
166 }
167
168 #define AX4000_TCP_PORT 3357 /* assigned by IANA */
169 #define AX4000_UDP_PORT 3357 /* assigned by IANA */
170
171 void
172 proto_reg_handoff_ax4000(void)
173 {
174         dissector_handle_t ax4000_handle;
175
176         ax4000_handle = create_dissector_handle(dissect_ax4000,
177             proto_ax4000);
178         dissector_add("ip.proto", IP_PROTO_AX4000, ax4000_handle);
179         dissector_add("tcp.port", AX4000_TCP_PORT, ax4000_handle);
180         dissector_add("udp.port", AX4000_UDP_PORT, ax4000_handle);
181 }