Rename the routines that handle dissector tables with unsigned integer
[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 <glib.h>
31
32 #include <epan/packet.h>
33 #include <ipproto.h>
34
35 /* Initialize the protocol and registered fields */
36 static int proto_ax4000 = -1;
37 static int hf_ax4000_port = -1;
38 static int hf_ax4000_chassis = -1;
39 static int hf_ax4000_fill = -1;
40 static int hf_ax4000_index = -1;
41 static int hf_ax4000_timestamp = -1;
42 static int hf_ax4000_seq = -1;
43 static int hf_ax4000_crc = -1;
44
45 /* Initialize the subtree pointers */
46 static gint ett_ax4000 = -1;
47
48 /* Code to actually dissect the packets */
49 static void
50 dissect_ax4000(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
51 {
52         proto_item *ti;
53         proto_tree *ax4000_tree;
54         
55         guint8  ax_port;
56         guint8  ax_chassis;
57         guint16 ax_index;
58         guint32 ax_seq;
59         guint32 ax_timestamp;
60
61         /* Make entries in Protocol column and Info column on summary display */
62         col_set_str(pinfo->cinfo, COL_PROTOCOL, "AX4000");
63         col_clear(pinfo->cinfo, COL_INFO);
64
65         ax_port = tvb_get_guint8(tvb, 0);
66         ax_chassis = tvb_get_guint8(tvb, 1);
67         ax_index = tvb_get_ntohs(tvb, 2) & 0x0FFF;
68         ax_timestamp = tvb_get_letohl(tvb, 6);
69         ax_seq = tvb_get_letohl(tvb, 10);
70         
71         col_append_fstr(pinfo->cinfo, COL_INFO,
72                         "Chss:%u Prt:%u Idx:%u Seq:0x%08x TS:%.6f[msec]",
73                         ax_chassis, ax_port, ax_index, ax_seq, ax_timestamp*1e-5);
74         
75         if (tree) {
76                 /* create display subtree for the protocol */
77                 ti = proto_tree_add_item(tree, proto_ax4000, tvb, 0, -1, FALSE);
78
79                 ax4000_tree = proto_item_add_subtree(ti, ett_ax4000);
80
81                 proto_tree_add_uint(ax4000_tree,
82                     hf_ax4000_port, tvb, 0, 1, ax_port);
83                 proto_tree_add_uint(ax4000_tree,
84                     hf_ax4000_chassis, tvb, 1, 1, ax_chassis);
85                 proto_tree_add_item(ax4000_tree,
86                     hf_ax4000_fill, tvb, 2, 1, FALSE);
87                 proto_tree_add_uint(ax4000_tree,
88                     hf_ax4000_index, tvb, 2, 2, ax_index);
89                 proto_tree_add_uint(ax4000_tree,
90                     hf_ax4000_timestamp, tvb, 6, 4, ax_timestamp);
91                 proto_tree_add_uint(ax4000_tree,
92                     hf_ax4000_seq, tvb, 10, 4, ax_seq);
93                 proto_tree_add_uint(ax4000_tree,
94                     hf_ax4000_crc, tvb, 14, 2, tvb_get_letohs(tvb, 14));
95         }
96
97 }
98
99 /* Register the protocol with Wireshark */
100
101 /* this format is require because a script is used to build the C function
102    that calls all the protocol registration.
103 */
104
105 void
106 proto_register_ax4000(void)
107 {
108         static hf_register_info hf[] = {
109                 { &hf_ax4000_port,
110                         { "Port Number", "ax4000.port",
111                         FT_UINT8, BASE_DEC, NULL, 0x0,
112                         NULL, HFILL }
113                 },
114                 { &hf_ax4000_chassis,
115                         { "Chassis Number", "ax4000.chassis",
116                         FT_UINT8, BASE_DEC, NULL, 0x0,
117                         NULL, HFILL }
118                 },
119                 { &hf_ax4000_fill,
120                         { "Fill Type", "ax4000.fill",
121                         FT_UINT8, BASE_DEC, NULL, 0xc0,
122                         NULL, HFILL }
123                 },
124                 { &hf_ax4000_index,
125                         { "Index", "ax4000.index",
126                         FT_UINT16, BASE_DEC, NULL, 0x0FFF,
127                         NULL, HFILL }
128                 },
129                 { &hf_ax4000_timestamp,
130                         { "Timestamp", "ax4000.timestamp",
131                         FT_UINT32, BASE_HEX, NULL, 0x0,
132                         NULL, HFILL }
133                 },
134                 { &hf_ax4000_seq,
135                         { "Sequence Number", "ax4000.seq",
136                         FT_UINT32, BASE_HEX, NULL, 0x0,
137                         NULL, HFILL }
138                 },
139                 { &hf_ax4000_crc,
140                         { "CRC (unchecked)", "ax4000.crc",
141                         FT_UINT16, BASE_HEX, NULL, 0x0,
142                         NULL, HFILL }
143                 }
144         };
145
146         /* Setup protocol subtree array */
147         static gint *ett[] = {
148                 &ett_ax4000
149         };
150
151         /* Register the protocol name and description */
152         proto_ax4000 = proto_register_protocol("AX/4000 Test Block",
153             "AX4000", "ax4000");
154
155         /* Required function calls to register the header fields and subtrees used */
156         proto_register_field_array(proto_ax4000, hf, array_length(hf));
157         proto_register_subtree_array(ett, array_length(ett));
158 }
159
160 #define AX4000_TCP_PORT 3357 /* assigned by IANA */
161 #define AX4000_UDP_PORT 3357 /* assigned by IANA */
162
163 void
164 proto_reg_handoff_ax4000(void)
165 {
166         dissector_handle_t ax4000_handle;
167
168         ax4000_handle = create_dissector_handle(dissect_ax4000,
169             proto_ax4000);
170         dissector_add_uint("ip.proto", IP_PROTO_AX4000, ax4000_handle);
171         dissector_add_uint("tcp.port", AX4000_TCP_PORT, ax4000_handle);
172         dissector_add_uint("udp.port", AX4000_UDP_PORT, ax4000_handle);
173 }