Convert 'encoding' parameter of certain proto_tree_add_item() calls in plugin dissectors:
[obnox/wireshark/wip.git] / plugins / wimax / msg_dsa.c
1 /* msg_dsa.c
2  * WiMax MAC Management DSA-REQ/RSP/ACK Messages decoder
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 /*
36 #define DEBUG
37 */
38
39 #include <glib.h>
40 #include <epan/packet.h>
41 #include "wimax_tlv.h"
42 #include "wimax_mac.h"
43 #include "wimax_utils.h"
44
45 extern gint proto_wimax;
46
47 gint proto_mac_mgmt_msg_dsa_decoder = -1;
48 static gint ett_mac_mgmt_msg_dsa_req_decoder = -1;
49 static gint ett_mac_mgmt_msg_dsa_rsp_decoder = -1;
50 static gint ett_mac_mgmt_msg_dsa_ack_decoder = -1;
51
52 static const value_string vals_dsa_msgs[] = {
53         { MAC_MGMT_MSG_DSA_REQ, "Dynamic Service Addition Request (DSA-REQ)" },
54         { MAC_MGMT_MSG_DSA_RSP, "Dynamic Service Addition Response (DSA-RSP)" },
55         { MAC_MGMT_MSG_DSA_ACK, "Dynamic Service Addition Acknowledge (DSA-ACK)" },
56         { 0,                    NULL }
57 };
58
59 /* fix fields */
60 static gint hf_dsa_req_message_type = -1;
61 static gint hf_dsa_transaction_id = -1;
62 static gint hf_dsa_rsp_message_type = -1;
63 static gint hf_dsa_confirmation_code = -1;
64 static gint hf_dsa_ack_message_type = -1;
65
66
67 void dissect_mac_mgmt_msg_dsa_req_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
68 {
69         guint offset = 0;
70         guint tvb_len, payload_type;
71         proto_item *dsa_item = NULL;
72         proto_tree *dsa_tree = NULL;
73
74         if(tree)
75         {       /* we are being asked for details */
76                 /* get the message type */
77                 payload_type = tvb_get_guint8(tvb, offset);
78                 /* ensure the message type is DSA REQ */
79                 if(payload_type != MAC_MGMT_MSG_DSA_REQ)
80                         return;
81                 /* Get the tvb reported length */
82                 tvb_len =  tvb_reported_length(tvb);
83                 /* display MAC message type */
84                 dsa_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsa_decoder, tvb, offset, tvb_len, 
85                                                           "%s (%u bytes)", val_to_str(payload_type, vals_dsa_msgs, "Unknown"), tvb_len);
86                 /* add MAC DSx subtree */
87                 dsa_tree = proto_item_add_subtree(dsa_item, ett_mac_mgmt_msg_dsa_req_decoder);
88                 /* Decode and display the Uplink Channel Descriptor (UCD) */
89                 /* display the Message Type */
90                 proto_tree_add_item(dsa_tree, hf_dsa_req_message_type, tvb, offset, 1, ENC_BIG_ENDIAN);
91                 /* move to next field */
92                 offset++;
93                 /* display the Transaction ID */
94                 proto_tree_add_item(dsa_tree, hf_dsa_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
95                 /* move to next field */
96                 offset += 2;
97                 /* process DSA-REQ message TLV Encode Information */
98                 wimax_common_tlv_encoding_decoder(tvb_new_subset(tvb, offset, (tvb_len - offset), (tvb_len - offset)), pinfo, dsa_tree);
99         }
100 }
101
102 void dissect_mac_mgmt_msg_dsa_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
103 {
104         guint offset = 0;
105         guint tvb_len, payload_type;
106         proto_item *dsa_item = NULL;
107         proto_tree *dsa_tree = NULL;
108
109         if(tree)
110         {       /* we are being asked for details */
111                 /* get the message type */
112                 payload_type = tvb_get_guint8(tvb, offset);
113                 /* ensure the message type is DSA RSP */
114                 if(payload_type != MAC_MGMT_MSG_DSA_RSP)
115                         return;
116                 /* Get the tvb reported length */
117                 tvb_len =  tvb_reported_length(tvb);
118                 /* display MAC message type */
119                 dsa_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsa_decoder, tvb, offset, tvb_len,
120                                                           "%s (%u bytes)", val_to_str(payload_type, vals_dsa_msgs, "Unknown"), tvb_len);
121                 /* add MAC DSx subtree */
122                 dsa_tree = proto_item_add_subtree(dsa_item, ett_mac_mgmt_msg_dsa_rsp_decoder);
123                 /* Decode and display the Uplink Channel Descriptor (UCD) */
124                 /* display the Message Type */
125                 proto_tree_add_item(dsa_tree, hf_dsa_rsp_message_type, tvb, offset, 1, ENC_BIG_ENDIAN);
126                 /* move to next field */
127                 offset++;
128                 /* display the Transaction ID */
129                 proto_tree_add_item(dsa_tree, hf_dsa_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
130                 /* move to next field */
131                 offset += 2;
132                 /* display the Confirmation Code */
133                 proto_tree_add_item(dsa_tree, hf_dsa_confirmation_code, tvb, offset, 1, ENC_BIG_ENDIAN);
134                 /* move to next field */
135                 offset++;
136                 /* process DSA RSP message TLV Encode Information */
137                 wimax_common_tlv_encoding_decoder(tvb_new_subset(tvb, offset, (tvb_len - offset), (tvb_len - offset)), pinfo, dsa_tree);
138         }
139 }
140
141 void dissect_mac_mgmt_msg_dsa_ack_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
142 {
143         guint offset = 0;
144         guint tvb_len, payload_type;
145         proto_item *dsa_item = NULL;
146         proto_tree *dsa_tree = NULL;
147
148         if(tree)
149         {       /* we are being asked for details */
150                 /* get the message type */
151                 payload_type = tvb_get_guint8(tvb, offset);
152                 /* ensure the message type is DSA ACK */
153                 if(payload_type != MAC_MGMT_MSG_DSA_ACK)
154                         return;
155                 /* Get the tvb reported length */
156                 tvb_len =  tvb_reported_length(tvb);
157                 /* display MAC message type */
158                 dsa_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsa_decoder, tvb, offset, tvb_len,
159                                                           "%s (%u bytes)", val_to_str(payload_type, vals_dsa_msgs, "Unknown"), tvb_len);
160                 /* add MAC DSx subtree */
161                 dsa_tree = proto_item_add_subtree(dsa_item, ett_mac_mgmt_msg_dsa_ack_decoder);
162                 /* Decode and display the Uplink Channel Descriptor (UCD) */
163                 /* display the Message Type */
164                 proto_tree_add_item(dsa_tree, hf_dsa_ack_message_type, tvb, offset, 1, ENC_BIG_ENDIAN);
165                 /* move to next field */
166                 offset++;
167                 /* display the Transaction ID */
168                 proto_tree_add_item(dsa_tree, hf_dsa_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
169                 /* move to next field */
170                 offset += 2;
171                 /* display the Confirmation Code */
172                 proto_tree_add_item(dsa_tree, hf_dsa_confirmation_code, tvb, offset, 1, ENC_BIG_ENDIAN);
173                 /* move to next field */
174                 offset++;
175                 /* process DSA-REQ message TLV Encode Information */
176                 wimax_common_tlv_encoding_decoder(tvb_new_subset(tvb, offset, (tvb_len - offset), (tvb_len - offset)), pinfo, dsa_tree);
177         }
178 }
179
180 /* Register Wimax Mac Payload Protocol and Dissector */
181 void proto_register_mac_mgmt_msg_dsa(void)
182 {
183         /* DSx display */
184         static hf_register_info hf[] =
185         {
186                 {
187                         &hf_dsa_ack_message_type,
188                         {
189                                 "MAC Management Message Type", "wmx.macmgtmsgtype.dsa_ack",
190                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
191                         }
192                 },
193                 {
194                         &hf_dsa_req_message_type,
195                         {
196                                 "MAC Management Message Type", "wmx.macmgtmsgtype.dsa_req",
197                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
198                         }
199                 },
200                 {
201                         &hf_dsa_rsp_message_type,
202                         {
203                                 "MAC Management Message Type", "wmx.macmgtmsgtype.dsa_rsp",
204                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
205                         }
206                 },
207                 {
208                         &hf_dsa_confirmation_code,
209                         {
210                                 "Confirmation code", "wmx.dsa.confirmation_code",
211                                 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
212                         }
213                 },
214                 {
215                         &hf_dsa_transaction_id,
216                         {
217                                 "Transaction ID", "wmx.dsa.transaction_id",
218                                 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL
219                         }
220                 }
221         };
222
223         /* Setup protocol subtree array */
224         static gint *ett[] =
225                 {
226                         &ett_mac_mgmt_msg_dsa_req_decoder,
227                         &ett_mac_mgmt_msg_dsa_rsp_decoder,
228                         &ett_mac_mgmt_msg_dsa_ack_decoder,
229                 };
230
231         proto_mac_mgmt_msg_dsa_decoder = proto_register_protocol (
232                 "WiMax DSA/C/D Messages", /* name       */
233                 "WiMax DSA/C/D (ds)",     /* short name */
234                 "wmx.ds"                  /* abbrev     */
235                 );
236
237         proto_register_field_array(proto_mac_mgmt_msg_dsa_decoder, hf, array_length(hf));
238         proto_register_subtree_array(ett, array_length(ett));
239 }