Add a few more menu items.
[obnox/wireshark/wip.git] / plugins / wimax / msg_clk_cmp.c
1 /* msg_clk_cmp.c
2  * WiMax MAC Management CLK_CMP Message decoders
3  *
4  * Copyright (c) 2007 by Intel Corporation.
5  *
6  * Author: Lu Pan <lu.pan@intel.com>
7  *
8  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1999 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 /* Include files */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <glib.h>
36 #include <epan/packet.h>
37 #include "wimax_mac.h"
38
39 static gint proto_mac_mgmt_msg_clk_cmp_decoder = -1;
40
41 static gint ett_mac_mgmt_msg_clk_cmp_decoder = -1;
42
43 /* CLK_CMP fields */
44 static gint hf_clk_cmp_message_type = -1;
45 static gint hf_clk_cmp_clock_count = -1;
46 static gint hf_clk_cmp_clock_id = -1;
47 static gint hf_clk_cmp_seq_number = -1;
48 static gint hf_clk_cmp_comparison_value = -1;
49 static gint hf_clk_cmp_invalid_tlv = -1;
50
51
52 /* Decode CLK_CMP messages. */
53 void dissect_mac_mgmt_msg_clk_cmp_decoder(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
54 {
55         guint offset = 0;
56         guint i;
57         guint clock_count;
58         guint tvb_len, payload_type;
59         proto_item *clk_cmp_item = NULL;
60         proto_tree *clk_cmp_tree = NULL;
61
62         /* Ensure the right payload type */
63         payload_type = tvb_get_guint8(tvb, 0);
64         if(payload_type != MAC_MGMT_MSG_CLK_CMP)
65         {
66                 return;
67         }
68
69         if (tree)
70         {       /* we are being asked for details */
71                 /* Get the tvb reported length */
72                 tvb_len =  tvb_reported_length(tvb);
73                 /* display MAC payload type CLK_CMP */
74                 clk_cmp_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_clk_cmp_decoder, tvb, offset, tvb_len, "Clock Comparison (CLK-CMP) (%u bytes)", tvb_len);
75                 /* add MAC CLK_CMP subtree */
76                 clk_cmp_tree = proto_item_add_subtree(clk_cmp_item, ett_mac_mgmt_msg_clk_cmp_decoder);
77                 /* display the Message Type */
78                 proto_tree_add_item(clk_cmp_tree, hf_clk_cmp_message_type, tvb, offset, 1, FALSE);
79                 /* set the offset for clock count */
80                 offset ++;
81                 /* get the clock count */
82                 clock_count = tvb_get_guint8(tvb, offset);
83                 /* display the clock count */
84                 proto_tree_add_item(clk_cmp_tree, hf_clk_cmp_clock_count, tvb, offset, 1, FALSE);
85                 /* set the offset for clock comparison */
86                 offset++;
87                 for (i = 0; i < clock_count; i++ )
88                 {       /* display the Clock ID */
89                         proto_tree_add_item(clk_cmp_tree, hf_clk_cmp_clock_id, tvb, offset++, 1, FALSE);
90                         /* display the sequence number */
91                         proto_tree_add_item(clk_cmp_tree, hf_clk_cmp_seq_number, tvb, offset++, 1, FALSE);
92                         /* display the comparison value */
93                         proto_tree_add_item(clk_cmp_tree, hf_clk_cmp_comparison_value, tvb, offset++, 1, FALSE);
94                 }
95         }
96 }
97
98 /* Register Wimax Mac Payload Protocol and Dissector */
99 void proto_register_mac_mgmt_msg_clk_cmp(void)
100 {
101         /* CLK_CMP fields display */
102         static hf_register_info hf_clk_cmp[] =
103         {
104                 {
105                         &hf_clk_cmp_message_type,
106                         {
107                                 "MAC Management Message Type", "wmx.macmgtmsgtype.clk_cmp",
108                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
109                         }
110                 },
111                 {
112                         &hf_clk_cmp_clock_count,
113                         {
114                                 "Clock Count", "wmx.clk_cmp.clock_count",
115                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
116                         }
117                 },
118                 {
119                         &hf_clk_cmp_clock_id,
120                         {
121                                 "Clock ID", "wmx.clk_cmp.clock_id",
122                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
123                         }
124                 },
125                 {
126                         &hf_clk_cmp_comparison_value,
127                         {
128                                 "Comparison Value", "wmx.clk_cmp.comparison_value",
129                                 FT_INT8, BASE_DEC, NULL, 0x0, NULL, HFILL
130                         }
131                 },
132                 {
133                         &hf_clk_cmp_invalid_tlv,
134                         {
135                                 "Invalid TLV", "wmx.clk_cmp.invalid_tlv",
136                                 FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL
137                         }
138                 },
139                 {
140                         &hf_clk_cmp_seq_number,
141                         {
142                                 "Sequence Number", "wmx.clk_cmp.seq_number",
143                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
144                         }
145                 }
146         };
147
148         /* Setup protocol subtree array */
149         static gint *ett[] =
150                 {
151                         &ett_mac_mgmt_msg_clk_cmp_decoder,
152                 };
153
154         proto_mac_mgmt_msg_clk_cmp_decoder = proto_register_protocol (
155                 "WiMax CLK-CMP Message", /* name       */
156                 "WiMax CLK-CMP (clk)",   /* short name */
157                 "wmx.clk"                /* abbrev     */
158                 );
159
160         proto_register_field_array(proto_mac_mgmt_msg_clk_cmp_decoder, hf_clk_cmp, array_length(hf_clk_cmp));
161         proto_register_subtree_array(ett, array_length(ett));
162 }