From Didier Gautheron:
[obnox/wireshark/wip.git] / plugins / wimax / msg_aas_beam.c
1 /* msg_aas_beam.c
2  * WiMax MAC Management AAS-BEAM-SELECT/REQ/RSP Messages decoders
3  *
4  * Copyright (c) 2007 by Intel Corporation.
5  *
6  * Author: Lu Pan
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 #define OFDM    /* disable it if not supporting OFDM */
30
31 /* Include files */
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36
37 #include <glib.h>
38 #include <epan/packet.h>
39 #include "wimax_mac.h"
40
41 extern gint proto_mac_mgmt_msg_aas_fbck_decoder;
42
43 #define AAS_BEAM_SELECT_AAS_BEAM_INDEX_MASK     0xFC
44 #define AAS_BEAM_SELECT_RESERVED_MASK           0x03
45 #define AAS_BEAM_FEEDBACK_REQUEST_NUMBER_MASK   0xE0
46 #define AAS_BEAM_MEASUREMENT_REPORT_TYPE_MASK   0x18
47 #define AAS_BEAM_RESOLUTION_PARAMETER_MASK      0x07
48
49 #define AAS_BEAM_BEAM_BIT_MASK_MASK             0xF0
50 #define AAS_BEAM_RESERVED_MASK                  0x0F
51
52 static gint proto_mac_mgmt_msg_aas_beam_decoder = -1;
53 static gint ett_mac_mgmt_msg_aas_beam_select_decoder = -1;
54 static gint ett_mac_mgmt_msg_aas_beam_req_decoder = -1;
55 /* static gint ett_mac_mgmt_msg_aas_beam_rsp_decoder = -1; */
56
57 #ifdef OFDM
58 static const value_string vals_report_types[] =
59 {
60     {0, "BEAM_REP_IE"},
61     {0,  NULL}
62 };
63
64 static const value_string vals_resolution_parameter[] =
65 {
66     {0, "report every 4th subcarrier"},
67     {1, "report every 8th subcarrier"},
68     {2, "report every 16th subcarrier"},
69     {3, "report every 32nd subcarrier"},
70     {4, "report every 64th subcarrier"},
71     {0,  NULL}
72 };
73 #endif
74
75 /* fix fields */
76 static gint hf_aas_beam_message_type = -1;
77 static gint hf_aas_beam_unknown_type = -1;
78 static gint hf_aas_beam_select_index = -1;
79 static gint hf_aas_beam_select_reserved = -1;
80 #ifdef OFDM
81 static gint hf_aas_beam_frame_number = -1;
82 static gint hf_aas_beam_feedback_request_number = -1;
83 static gint hf_aas_beam_measurement_report_type = -1;
84 static gint hf_aas_beam_resolution_parameter = -1;
85 static gint hf_aas_beam_beam_bit_mask = -1;
86 static int hf_aas_beam_freq_value_re = -1;
87 static int hf_aas_beam_freq_value_im = -1;
88 static int hf_aas_beam_rssi_value = -1;
89 static int hf_aas_beam_cinr_value = -1;
90 #endif
91
92
93 void dissect_mac_mgmt_msg_aas_beam_select_decoder(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
94 {
95         guint offset = 0;
96         guint tvb_len, payload_type;
97         proto_item *aas_beam_item = NULL;
98         proto_tree *aas_beam_tree = NULL;
99
100         if(tree)
101         {       /* we are being asked for details */
102                 /* get the message type */
103                 payload_type = tvb_get_guint8(tvb, offset);
104                 /* ensure the message type is AAS-BEAM-SELECT */
105                 if(payload_type != MAC_MGMT_MSG_AAS_BEAM_SELECT)
106                         return;
107                 /* Get the tvb reported length */
108                 tvb_len =  tvb_reported_length(tvb);
109                 /* display MAC message type */
110                 aas_beam_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_aas_beam_decoder, tvb, offset, tvb_len, "AAS Beam Select (AAS-BEAM-SELECT) (%u bytes)", tvb_len);
111                 /* add subtree */
112                 aas_beam_tree = proto_item_add_subtree(aas_beam_item, ett_mac_mgmt_msg_aas_beam_select_decoder);
113                 /* Display the AAS-BEAM-SELECT message type */
114                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_message_type, tvb, offset, 1, FALSE);
115                 /* move to next field */
116                 offset++;
117                 /* Decode and display the AAS-BEAM-SELECT message body */
118                 /* display the AAS Beam Index */
119                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_select_index, tvb, offset, 1, FALSE);
120                 /* display the reserved fields */
121                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_select_reserved, tvb, offset, 1, FALSE);
122         }
123 }
124
125 #ifdef OFDM
126 static void dissect_mac_mgmt_msg_aas_beam_req_decoder(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
127 {
128         guint offset = 0;
129         guint tvb_len, payload_type;
130         proto_item *aas_beam_item = NULL;
131         proto_tree *aas_beam_tree = NULL;
132
133         if(tree)
134         {       /* we are being asked for details */
135                 /* get the message type */
136                 payload_type = tvb_get_guint8(tvb, offset);
137                 /* ensure the message type is AAS-BEAM-REQ */
138                 if(payload_type != MAC_MGMT_MSG_AAS_BEAM_REQ)
139                         return;
140                 /* Get the tvb reported length */
141                 tvb_len =  tvb_reported_length(tvb);
142                 /* display MAC message type */
143                 aas_beam_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_aas_beam_decoder, tvb, offset, tvb_len, "AAS Beam Request (AAS-BEAM-REQ) (%u bytes)", tvb_len);
144                 /* add subtree */
145                 aas_beam_tree = proto_item_add_subtree(aas_beam_item, ett_mac_mgmt_msg_aas_beam_req_decoder);
146                 /* Display the AAS-BEAM-REQ message type */
147                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_message_type, tvb, offset, 1, FALSE);
148                 /* move to next field */
149                 offset++;
150                 /* Decode and display the AAS-BEAM-REQ message body */
151                 /* display the Frame Number */
152                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_frame_number, tvb, offset, 1, FALSE);
153                 /* move to next field */
154                 offset++;
155                 /* display the Feedback Request Number */
156                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_feedback_request_number, tvb, offset, 1, FALSE);
157                 /* display the Measurement Report Type */
158                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_measurement_report_type, tvb, offset, 1, FALSE);
159                 /* display the Resolution Parameter */
160                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_resolution_parameter, tvb, offset, 1, FALSE);
161                 /* move to next field */
162                 offset++;
163                 /* display the Beam Bit mask */
164                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_beam_bit_mask, tvb, offset, 1, FALSE);
165                 /* display the reserved fields */
166                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_select_reserved, tvb, offset, 1, FALSE);
167         }
168 }
169
170 static void dissect_mac_mgmt_msg_aas_beam_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
171 {
172         guint offset = 0;
173         guint tvb_len, payload_type, report_type;
174         guint number_of_frequencies, index;
175         proto_item *aas_beam_item = NULL;
176         proto_tree *aas_beam_tree = NULL;
177
178         if(tree)
179         {       /* we are being asked for details */
180                 /* get the message type */
181                 payload_type = tvb_get_guint8(tvb, offset);
182                 /* ensure the message type is AAS-BEAM-RSP */
183                 if(payload_type != MAC_MGMT_MSG_AAS_BEAM_RSP)
184                         return;
185                 /* Get the tvb reported length */
186                 tvb_len =  tvb_reported_length(tvb);
187                 /* display MAC message type */
188                 aas_beam_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_aas_beam_decoder, tvb, offset, tvb_len, "AAS Beam Response (AAS-BEAM-RSP) (%u bytes)", tvb_len);
189                 /* add subtree */
190                 aas_beam_tree = proto_item_add_subtree(aas_beam_item, ett_mac_mgmt_msg_aas_beam_req_decoder);
191                 /* Display the AAS-BEAM-RSP message type */
192                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_message_type, tvb, offset, 1, FALSE);
193                 /* move to next field */
194                 offset++;
195                 /* Decode and display the AAS-BEAM-RSP message body */
196                 /* display the Frame Number */
197                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_frame_number, tvb, offset, 1, FALSE);
198                 /* move to next field */
199                 offset++;
200                 /* get the Measurement Report Type */
201                 report_type = tvb_get_guint8(tvb, offset);
202                 /* display the Feedback Request Number */
203                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_feedback_request_number, tvb, offset, 1, FALSE);
204                 /* display the Measurement Report Type */
205                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_measurement_report_type, tvb, offset, 1, FALSE);
206                 /* display the Resolution Parameter */
207                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_resolution_parameter, tvb, offset, 1, FALSE);
208                 /* move to next field */
209                 offset++;
210                 /* display the Beam Bit mask */
211                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_beam_bit_mask, tvb, offset, 1, FALSE);
212                 /* display the reserved fields */
213                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_select_reserved, tvb, offset, 1, FALSE);
214                 /* move to next field */
215                 offset++;
216                 /* check the Measurement Report Type */
217                 if((report_type & AAS_BEAM_MEASUREMENT_REPORT_TYPE_MASK) == 0)
218                 {
219                         /* calculate the total number of frequencies */
220                         number_of_frequencies = (tvb_len - offset) / 2 - 1;
221                         /* display the frequency */
222                         for(index = 0; index < number_of_frequencies; index++)
223                         {       /* display the Frequency Value (real part) */
224                                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_freq_value_re, tvb, offset, 1, FALSE);
225                                 /* move to next field */
226                                 offset++;
227                                 /* display the Frequency Value (imaginary part) */
228                                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_freq_value_im, tvb, offset, 1, FALSE);
229                                 /* move to next field */
230                                 offset++;
231                         }
232                 }
233                 /* display the RSSI Mean Value */
234                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_rssi_value, tvb, offset, 1, FALSE);
235                 /* move to next field */
236                 offset++;
237                 /* display the CINR Mean Value */
238                 proto_tree_add_item(aas_beam_tree, hf_aas_beam_cinr_value, tvb, offset, 1, FALSE);
239         }
240 }
241 #endif
242
243 /* Register Wimax Mac Payload Protocol and Dissector */
244 void proto_register_mac_mgmt_msg_aas_beam(void)
245 {
246         /* AAS-BEAM display */
247         static hf_register_info hf_aas_beam[] =
248         {
249                 {
250                         &hf_aas_beam_message_type,
251                         {
252                                 "MAC Management Message Type", "wmx.macmgtmsgtype.aas_beam", 
253                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
254                         }
255                 },
256                 {
257                         &hf_aas_beam_select_index,
258                         {
259                                 "AAS Beam Index", "wmx.aas_beam.aas_beam_index", 
260                                 FT_UINT8, BASE_DEC, NULL, AAS_BEAM_SELECT_AAS_BEAM_INDEX_MASK, NULL, HFILL
261                         }
262                 },
263                 {
264                         &hf_aas_beam_beam_bit_mask,
265                         {
266                                 "Beam Bit Mask", "wmx.aas_beam.beam_bit_mask", 
267                                 FT_UINT8, BASE_HEX, NULL, AAS_BEAM_BEAM_BIT_MASK_MASK, NULL, HFILL
268                         }
269                 },
270 #ifdef OFDM
271                 {
272                         &hf_aas_beam_cinr_value,
273                         {
274                                 "CINR Mean Value", "wmx.aas_beam.cinr_mean_value", 
275                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
276                         }
277                 },
278                 {
279                         &hf_aas_beam_feedback_request_number,
280                         {
281                                 "Feedback Request Number", "wmx.aas_beam.feedback_request_number", 
282                                 FT_UINT8, BASE_DEC, NULL, AAS_BEAM_FEEDBACK_REQUEST_NUMBER_MASK, NULL, HFILL
283                         }
284                 },
285                 {
286                         &hf_aas_beam_frame_number,
287                         {
288                                 "Frame Number", "wmx.aas_beam.frame_number", 
289                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
290                         }
291                 },
292                 {
293                         &hf_aas_beam_freq_value_im,
294                         {
295                                 "Frequency Value (imaginary part)", "wmx.aas_beam.freq_value_im", 
296                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
297                         }
298                 },
299                 {
300                         &hf_aas_beam_freq_value_re,
301                         {
302                                 "Frequency Value (real part)", "wmx.aas_beam.freq_value_re", 
303                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
304                         }
305                 },
306                 {
307                         &hf_aas_beam_measurement_report_type,
308                         {
309                                 "Measurement Report Type", "wmx.aas_beam.measurement_report_type", 
310                                 FT_UINT8, BASE_DEC, VALS(vals_report_types), AAS_BEAM_MEASUREMENT_REPORT_TYPE_MASK, NULL, HFILL
311                         }
312                 },
313                 {
314                         &hf_aas_beam_select_reserved,
315                         {
316                                 "Reserved", "wmx.aas_beam.reserved", 
317                                 FT_UINT8, BASE_HEX, NULL, AAS_BEAM_SELECT_RESERVED_MASK, NULL, HFILL
318                         }
319                 },
320                 {
321                         &hf_aas_beam_resolution_parameter,
322                         {
323                                 "Resolution Parameter", "wmx.aas_beam.resolution_parameter", 
324                                 FT_UINT8, BASE_DEC, VALS(vals_resolution_parameter), AAS_BEAM_RESOLUTION_PARAMETER_MASK, NULL, HFILL
325                         }
326                 },
327                 {
328                         &hf_aas_beam_rssi_value,
329                         {
330                                 "RSSI Mean Value", "wmx.aas_beam.rssi_mean_value", 
331                                 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
332                         }
333                 },
334 #endif
335                 {
336                         &hf_aas_beam_unknown_type,
337                         {
338                                 "Unknown TLV type", "wmx.aas_beam.unknown_type", 
339                                 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL
340                         }
341                 }
342         };
343
344         /* Setup protocol subtree array */
345         static gint *ett[] =
346                 {
347                         &ett_mac_mgmt_msg_aas_beam_select_decoder,
348                         &ett_mac_mgmt_msg_aas_beam_req_decoder,
349                         /*      &ett_mac_mgmt_msg_aas_beam_rsp_decoder, */
350                 };
351
352         proto_mac_mgmt_msg_aas_beam_decoder = proto_mac_mgmt_msg_aas_fbck_decoder;
353
354         proto_register_field_array(proto_mac_mgmt_msg_aas_beam_decoder, hf_aas_beam, array_length(hf_aas_beam));
355         proto_register_subtree_array(ett, array_length(ett));
356
357         register_dissector("mac_mgmt_msg_aas_beam_select_handler", dissect_mac_mgmt_msg_aas_beam_select_decoder, -1);
358 #ifdef OFDM
359         register_dissector("mac_mgmt_msg_aas_beam_req_handler", dissect_mac_mgmt_msg_aas_beam_req_decoder, -1);
360         register_dissector("mac_mgmt_msg_aas_beam_rsp_handler", dissect_mac_mgmt_msg_aas_beam_rsp_decoder, -1);
361 #endif
362 }