Merge "Lua: Added a utility function file_exists()."
[metze/wireshark/wip.git] / plugins / wimax / mac_mgmt_msg_decoder.c
1 /* mac_mgmt_msg_decoder.c
2  * WiMax MAC Management Message 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  */
28
29 /* Include files */
30
31 #include "config.h"
32
33 #include <glib.h>
34 #include <epan/packet.h>
35 #include <epan/expert.h>
36 #include "wimax_mac.h"
37
38 void proto_register_mac_mgmt_msg(void);
39 void proto_reg_handoff_mac_mgmt_msg(void);
40
41 static gint proto_mac_mgmt_msg_decoder = -1;
42 static gint ett_mac_mgmt_msg_decoder = -1;
43
44 static gint hf_mac_mgmt_msg_type = -1;
45 static gint hf_mac_mgmt_msg_values = -1;
46
47 static expert_field ei_empty_payload = EI_INIT;
48
49 static dissector_table_t  subdissector_message_table;
50
51 /* WIMAX MAC Management message type info */
52 static const value_string mgt_msg_abbrv_vals[] = {
53    {    MAC_MGMT_MSG_UCD,       "UCD" },
54    {    MAC_MGMT_MSG_DCD,       "DCD" },
55    {    MAC_MGMT_MSG_DL_MAP,    "DL-MAP" },
56    {    MAC_MGMT_MSG_UL_MAP,    "UL-MAP" },
57    {    MAC_MGMT_MSG_RNG_REQ,   "RNG-REQ" },
58    {    MAC_MGMT_MSG_RNG_RSP,   "RNG-RSP" },
59    {    MAC_MGMT_MSG_REG_REQ,   "REG-REQ" },
60    {    MAC_MGMT_MSG_REG_RSP,   "REG-RSP" },
61    {    8,      "Reserved8" },
62    {    MAC_MGMT_MSG_PKM_REQ,   "PKM-REQ" },
63    {    MAC_MGMT_MSG_PKM_RSP,   "PKM-RSP" },
64    {    MAC_MGMT_MSG_DSA_REQ,   "DSA-REQ" },
65    {    MAC_MGMT_MSG_DSA_RSP,   "DSA-RSP" },
66    {    MAC_MGMT_MSG_DSA_ACK,   "DSA-ACK" },
67    {    MAC_MGMT_MSG_DSC_REQ,   "DSC-REQ" },
68    {    MAC_MGMT_MSG_DSC_RSP,   "DSC-RSP" },
69    {    MAC_MGMT_MSG_DSC_ACK,   "DSC-ACK" },
70    {    MAC_MGMT_MSG_DSD_REQ,   "DSD-REQ" },
71    {    MAC_MGMT_MSG_DSD_RSP,   "DSD-RSP" },
72    {    19,         "Reserved19" },
73    {    20,         "Reserved20" },
74    {    MAC_MGMT_MSG_MCA_REQ,       "MCA-REQ" },
75    {    MAC_MGMT_MSG_MCA_RSP,       "MCA-RSP" },
76    {    MAC_MGMT_MSG_DBPC_REQ,      "DBPC-REQ" },
77    {    MAC_MGMT_MSG_DBPC_RSP,      "DBPC-RSP" },
78    {    MAC_MGMT_MSG_RES_CMD,       "RES-CMD" },
79    {    MAC_MGMT_MSG_SBC_REQ,       "SBC-REQ" },
80    {    MAC_MGMT_MSG_SBC_RSP,       "SBC-RSP" },
81    {    MAC_MGMT_MSG_CLK_CMP,       "CLK-CMP" },
82    {    MAC_MGMT_MSG_DREG_CMD,      "DREG-CMD" },
83    {    MAC_MGMT_MSG_DSX_RVD,       "DSX-RVD" },
84    {    MAC_MGMT_MSG_TFTP_CPLT,     "TFTP-CPLT" },
85    {    MAC_MGMT_MSG_TFTP_RSP,      "TFTP-RSP" },
86    {    MAC_MGMT_MSG_ARQ_FEEDBACK,          "ARQ-FEEDBACK" },
87    {    MAC_MGMT_MSG_ARQ_DISCARD,           "ARQ-DISCARD" },
88    {    MAC_MGMT_MSG_ARQ_RESET,     "ARQ-RESET" },
89    {    MAC_MGMT_MSG_REP_REQ,       "REP-REQ" },
90    {    MAC_MGMT_MSG_REP_RSP,       "REP-RSP" },
91    {    MAC_MGMT_MSG_FPC,               "FPC" },
92    {    MAC_MGMT_MSG_MSH_NCFG,      "MSH-NCFG" },
93    {    MAC_MGMT_MSG_MSH_NENT,      "MSH-NENT" },
94    {    MAC_MGMT_MSG_MSH_DSCH,      "MSH-DSCH" },
95    {    MAC_MGMT_MSG_MSH_CSCH,      "MSH-CSCH" },
96    {    MAC_MGMT_MSG_MSH_CSCF,      "MSH-CSCF" },
97    {    MAC_MGMT_MSG_AAS_FBCK_REQ,      "AAS-FBCK_REQ" },
98    {    MAC_MGMT_MSG_AAS_FBCK_RSP,      "AAS-FBCK_RSP" },
99    {    MAC_MGMT_MSG_AAS_BEAM_SELECT, "AAS-BEAM_SELECT" },
100    {    MAC_MGMT_MSG_AAS_BEAM_REQ,      "AAS-BEAM_REQ" },
101    {    MAC_MGMT_MSG_AAS_BEAM_RSP,      "AAS-BEAM_RSP" },
102    {    MAC_MGMT_MSG_DREG_REQ,      "DREG-REQ" },
103    {    MAC_MGMT_MSG_MOB_SLP_REQ,       "MOB-SLP-REQ" },
104    {    MAC_MGMT_MSG_MOB_SLP_RSP,       "MOB-SLP-RSP" },
105    {    MAC_MGMT_MSG_MOB_TRF_IND,       "MOB-TRF-IND" },
106    {    MAC_MGMT_MSG_MOB_NBR_ADV,       "MOB-NBR-ADV" },
107    {    MAC_MGMT_MSG_MOB_SCN_REQ,       "MOB-SCN-REQ" },
108    {    MAC_MGMT_MSG_MOB_SCN_RSP,       "MOB-SCN-RSP" },
109    {    MAC_MGMT_MSG_MOB_BSHO_REQ,      "MOB-BSHO-REQ" },
110    {    MAC_MGMT_MSG_MOB_MSHO_REQ,      "MOB-MSHO-REQ" },
111    {    MAC_MGMT_MSG_MOB_BSHO_RSP,      "MOB-BSHO-RSP" },
112    {    MAC_MGMT_MSG_MOB_HO_IND,        "MOB-HO-IND" },
113    {    MAC_MGMT_MSG_MOB_SCN_REP,       "MOB-SCN-REP" },
114    {    MAC_MGMT_MSG_MOB_PAG_ADV,       "MOB-PAG-ADV" },
115    {    MAC_MGMT_MSG_MBS_MAP,       "MBS-MAP" },
116    {    MAC_MGMT_MSG_PMC_REQ,       "PMC-REQ" },
117    {    MAC_MGMT_MSG_PMC_RSP,       "PMC-RSP" },
118    {    MAC_MGMT_MSG_PRC_LT_CTRL,       "PRC-LT-CTRL" },
119    {    MAC_MGMT_MSG_MOB_ASC_REP,       "MOB-ASC-REP" },
120
121    { 0, NULL }
122 };
123
124 static value_string_ext mgt_msg_abbrv_vals_ext = VALUE_STRING_EXT_INIT(mgt_msg_abbrv_vals);
125
126 static void dissect_mac_mgmt_msg_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
127 {
128         guint offset = 0;
129         guint message_type;
130         proto_item *message_item;
131         proto_tree *message_tree;
132         const char* mgt_msg_str;
133
134         message_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_decoder, tvb, offset, -1,
135                                         "MAC Management Message Type (%u bytes)", tvb_reported_length(tvb));
136         message_tree = proto_item_add_subtree(message_item, ett_mac_mgmt_msg_decoder);
137
138         if (tvb_reported_length(tvb) == 0)
139         {
140                 expert_add_info(pinfo, message_item, &ei_empty_payload);
141                 return;
142         }
143
144         /* Get the payload type */
145         message_type = tvb_get_guint8(tvb, offset);
146         proto_tree_add_item(message_tree, hf_mac_mgmt_msg_type, tvb, offset, 1, ENC_NA);
147         mgt_msg_str = val_to_str_ext_const(message_type, &mgt_msg_abbrv_vals_ext, "Unknown");
148
149         /* Display message type in Info column */
150         col_append_sep_str(pinfo->cinfo, COL_INFO, ", ", mgt_msg_str);
151
152         /* add the payload type into the info column */
153         if (try_val_to_str_ext(message_type, &mgt_msg_abbrv_vals_ext) == NULL)
154         {
155                 /* display the MAC payload in Hex */
156                 proto_tree_add_item(message_tree, hf_mac_mgmt_msg_values, tvb, offset, -1, ENC_NA);
157                 return;
158         }
159
160         /* add the MAC header info to parent*/
161         proto_item_append_text(proto_tree_get_parent(tree), ", %s", mgt_msg_str);
162
163         /* Decode and display the MAC payload */
164         if (!dissector_try_uint(subdissector_message_table, message_type, 
165                 tvb_new_subset_remaining(tvb, 1), pinfo, tree))
166         {
167                 proto_tree_add_item(message_tree, hf_mac_mgmt_msg_values, tvb, offset, -1, ENC_NA);
168         }
169 }
170
171 /* Register Wimax Mac Payload Protocol and Dissector */
172 void proto_register_mac_mgmt_msg(void)
173 {
174         /* Payload display */
175         static hf_register_info hf[] =
176         {
177                 {
178                         &hf_mac_mgmt_msg_type,
179                         {
180                                 "MAC Management Message Type", "wmx.macmgtmsgtype",
181                                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &mgt_msg_abbrv_vals_ext, 0x0,
182                                 NULL, HFILL
183                         }
184                 },
185                 {
186                         &hf_mac_mgmt_msg_values,
187                         {
188                                 "Values", "wmx.values",
189                                 FT_BYTES, BASE_NONE, NULL, 0x0,
190                                 NULL, HFILL
191                         }
192                 },
193         };
194
195         /* Setup protocol subtree array */
196         static gint *ett[] =
197                 {
198                         &ett_mac_mgmt_msg_decoder,
199                 };
200
201         static ei_register_info ei[] = {
202                 { &ei_empty_payload, { "wmx.empty_payload", PI_PROTOCOL, PI_ERROR, "Error: Mac payload tvb is empty !", EXPFILL }},
203         };
204
205         expert_module_t* expert_mac_mgmt;
206
207         proto_mac_mgmt_msg_decoder = proto_register_protocol (
208                 "WiMax MAC Management Message", /* name       */
209                 "MGMT MSG",                     /* short name */
210                 "wmx.mgmt"                   /* abbrev     */
211                 );
212
213         proto_register_field_array(proto_mac_mgmt_msg_decoder, hf, array_length(hf));
214         proto_register_subtree_array(ett, array_length(ett));
215         expert_mac_mgmt = expert_register_protocol(proto_mac_mgmt_msg_decoder);
216         expert_register_field_array(expert_mac_mgmt, ei, array_length(ei));
217
218         subdissector_message_table = register_dissector_table("wmx.mgmtmsg",
219                 "WiMax MAC Management Message", FT_UINT8, BASE_DEC);
220
221         /* Register dissector by name */
222         register_dissector("wmx_mac_mgmt_msg_decoder", dissect_mac_mgmt_msg_decoder,
223                            proto_mac_mgmt_msg_decoder);
224 }
225
226 void proto_reg_handoff_mac_mgmt_msg(void)
227 {
228         dissector_handle_t mgt_msg_handle;
229
230         /* Find the dissectors that appear to be supported through a third-party plugin
231                 Keep here until third-party plugin can register through the new "wmx.mgmtmsg"
232                 subdissector */
233
234         /* find the Multicast Assignment request message handler */
235         mgt_msg_handle = find_dissector("mac_mgmt_msg_mca_req_handler");
236         if (mgt_msg_handle)
237                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MCA_REQ, mgt_msg_handle );
238
239         /* find the Multicast Assignment response message handler */
240         mgt_msg_handle = find_dissector("mac_mgmt_msg_mca_rsp_handler");
241         if (mgt_msg_handle)
242                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MCA_RSP, mgt_msg_handle );
243
244         /* find the DL Burst Profile Change request message handler */
245         mgt_msg_handle = find_dissector("mac_mgmt_msg_dbpc_req_handler");
246         if (mgt_msg_handle)
247                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_DBPC_REQ, mgt_msg_handle );
248
249         /* find the DL Burst Profile Change response message handler */
250         mgt_msg_handle = find_dissector("mac_mgmt_msg_dbpc_rsp_handler");
251         if (mgt_msg_handle)
252                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_DBPC_RSP, mgt_msg_handle );
253
254         /* find the Config File TFTP Complete message handler */
255         mgt_msg_handle = find_dissector("mac_mgmt_msg_tftp_cplt_handler");
256         if (mgt_msg_handle)
257                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_TFTP_CPLT, mgt_msg_handle );
258
259         /* find the Config File TFTP Complete response message handler */
260         mgt_msg_handle = find_dissector("mac_mgmt_msg_tftp_rsp_handler");
261         if (mgt_msg_handle)
262                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_TFTP_RSP, mgt_msg_handle );
263
264         /* find the Mesh Network Configuration message handler */
265         mgt_msg_handle = find_dissector("mac_mgmt_msg_ncfg_handler");
266         if (mgt_msg_handle)
267                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MSH_NCFG, mgt_msg_handle );
268
269         /* find the Mesh Network Entry message handler */
270         mgt_msg_handle = find_dissector("mac_mgmt_msg_nent_handler");
271         if (mgt_msg_handle)
272                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MSH_NENT, mgt_msg_handle );
273
274         /* find the Mesh Distributed Schedule message handler */
275         mgt_msg_handle = find_dissector("mac_mgmt_msg_dsch_handler");
276         if (mgt_msg_handle)
277                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MSH_DSCH, mgt_msg_handle );
278
279         /* find the Mesh Centralized Schedule message handler */
280         mgt_msg_handle = find_dissector("mac_mgmt_msg_csch_handler");
281         if (mgt_msg_handle)
282                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MSH_CSCH, mgt_msg_handle );
283
284         /* find the Mesh Centralized Schedule Configuration message handler */
285         mgt_msg_handle = find_dissector("mac_mgmt_msg_cscf_handler");
286         if (mgt_msg_handle)
287                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MSH_CSCF, mgt_msg_handle );
288
289         /* find the AAS Beam request message handler */
290         mgt_msg_handle = find_dissector("mac_mgmt_msg_aas_beam_req_handler");
291         if (mgt_msg_handle)
292                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_AAS_BEAM_REQ, mgt_msg_handle );
293
294         /* find the AAS Beam response message handler */
295         mgt_msg_handle = find_dissector("mac_mgmt_msg_aas_beam_rsp_handler");
296         if (mgt_msg_handle)
297                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_AAS_BEAM_RSP, mgt_msg_handle );
298
299         /* find the Sleep Request message handler */
300         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_slp_req_handler");
301         if (mgt_msg_handle)
302                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_SLP_REQ, mgt_msg_handle );
303
304         /* find the Sleep Response message handler */
305         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_slp_rsp_handler");
306         if (mgt_msg_handle)
307                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_SLP_RSP, mgt_msg_handle );
308
309         /* find the Traffic Indication message handler */
310         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_trf_ind_handler");
311         if (mgt_msg_handle)
312                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_TRF_IND, mgt_msg_handle );
313
314         /* find the Neighbor Advertisement message handler */
315         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_nbr_adv_handler");
316         if (mgt_msg_handle)
317                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_NBR_ADV, mgt_msg_handle );
318
319         /* find the Scanning Interval Allocation Reqest message handler */
320         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_scn_req_handler");
321         if (mgt_msg_handle)
322                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_SCN_REQ, mgt_msg_handle );
323
324         /* find the Scanning Interval Allocation Response message handler */
325         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_scn_rsp_handler");
326         if (mgt_msg_handle)
327                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_SCN_RSP, mgt_msg_handle );
328
329         /* find the BS HO Request message handler */
330         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_bsho_req_handler");
331         if (mgt_msg_handle)
332                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_BSHO_REQ, mgt_msg_handle );
333
334         /* find the MS HO Request message handler */
335         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_msho_req_handler");
336         if (mgt_msg_handle)
337                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_MSHO_REQ, mgt_msg_handle );
338
339         /* find the BS HO Response message handler */
340         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_bsho_rsp_handler");
341         if (mgt_msg_handle)
342                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_BSHO_RSP, mgt_msg_handle );
343
344         /* find the HO Indication message handler */
345         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_ho_ind_handler");
346         if (mgt_msg_handle)
347                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_HO_IND, mgt_msg_handle );
348
349         /* find the Scanning Result Report message handler */
350         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_scn_rep_handler");
351         if (mgt_msg_handle)
352                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_SCN_REP, mgt_msg_handle );
353
354         /* find the BS Broadcast Paging message handler */
355         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_pag_adv_handler");
356         if (mgt_msg_handle)
357                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_PAG_ADV, mgt_msg_handle );
358
359         /* find the MBS MAP message handler */
360         mgt_msg_handle = find_dissector("mac_mgmt_msg_mbs_map_handler");
361         if (mgt_msg_handle)
362                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MBS_MAP, mgt_msg_handle );
363
364         /* find the Association Result Report message handler */
365         mgt_msg_handle = find_dissector("mac_mgmt_msg_mob_asc_rep_handler");
366         if (mgt_msg_handle)
367                 dissector_add_uint( "wmx.mgmtmsg", MAC_MGMT_MSG_MOB_ASC_REP, mgt_msg_handle );
368 }