#include <prefs.h> not required
[obnox/wireshark/wip.git] / plugins / wimax / msg_reg_rsp.c
1 /* msg_reg_rsp.c
2  * WiMax MAC Management REG-RSP Message decoder
3  *
4  * Copyright (c) 2007 by Intel Corporation.
5  *
6  * Author: John R. Underwood <junderx@yahoo.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 #define WIMAX_16E_2005
36
37 #define         FRAG_LAST                       0x1
38
39 #include "moduleinfo.h"
40
41 #include <glib.h>
42 #include <epan/packet.h>
43 #include "wimax_tlv.h"
44 #include "wimax_mac.h"
45 #include "wimax_utils.h"
46
47 extern gint proto_mac_mgmt_msg_reg_req_decoder;
48 extern gboolean include_cor2_changes;
49
50 extern gint man_ofdma;
51
52 extern void dissect_extended_tlv(proto_tree *reg_req_tree, gint tlv_type, tvbuff_t *tvb, guint tlv_offset, guint tlv_len, packet_info *pinfo, guint offset, gint proto_registry);
53 extern void dissect_mac_mgmt_msg_dsc_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
54
55 /* forward reference */
56 void dissect_mac_mgmt_msg_reg_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
57
58
59 static gint proto_mac_mgmt_msg_reg_rsp_decoder = -1;
60 static gint ett_mac_mgmt_msg_reg_rsp_decoder   = -1;
61 static gint ett_reg_rsp_message_tree           = -1;
62
63 /* Setup protocol subtree array */
64 static gint *ett[] =
65 {
66         &ett_mac_mgmt_msg_reg_rsp_decoder,
67         &ett_reg_rsp_message_tree
68 };
69
70 /* NCT messages */
71
72 /* REG-RSP fields */
73 static gint hf_reg_rsp_message_type                      = -1;
74 static gint hf_reg_rsp_status                            = -1;
75 static gint hf_tlv_type                                  = -1;
76 static gint hf_tlv_value                                 = -1;
77 static gint hf_reg_rsp_secondary_mgmt_cid                = -1;
78 static gint hf_reg_invalid_tlv                           = -1;
79 static gint hf_reg_rsp_new_cid_after_ho                  = -1;
80 static gint hf_reg_rsp_service_flow_id                   = -1;
81 static gint hf_reg_rsp_system_resource_retain_time       = -1;
82 static gint hf_reg_total_provisioned_sf                 = -1;
83
84 /* STRING RESOURCES */
85
86 static const value_string vals_reg_rsp_status [] = {
87     {0,         "OK"},
88     {1,         "Message authentication failure"},
89     {0,                                 NULL}
90 };
91
92
93 /* REG-RSP fields display */
94 static hf_register_info hf[] =
95 {
96         {
97                 &hf_reg_rsp_message_type,
98                 {
99                         "MAC Management Message Type", "wmx.macmgtmsgtype.reg_rsp",
100                         FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL
101                 }
102         },
103         {
104                 &hf_reg_invalid_tlv,
105                 {
106                         "Invalid TLV", "wmx.reg_rsp.invalid_tlv", 
107                         FT_BYTES, BASE_HEX, NULL, 0, "", HFILL
108                 }
109         },
110         {
111                 &hf_reg_rsp_new_cid_after_ho,
112                 {
113                         "New CID after handover to new BS", "wmx.reg_rsp.new_cid_after_ho",
114                         FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL
115                 }
116         },
117         {
118                 &hf_reg_rsp_status,
119                 {
120                         "Response", "wmx.reg_rsp.response", 
121                         FT_UINT8, BASE_HEX, VALS(vals_reg_rsp_status), 0x0, "", HFILL
122                 }
123         },
124         {
125                 &hf_reg_rsp_secondary_mgmt_cid,
126                 {
127                         "Secondary Management CID", "wmx.reg_rsp.secondary_mgmt_cid",
128                         FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL
129                 }
130         },
131         {
132                 &hf_reg_total_provisioned_sf,
133                 {
134                         "Total Number of Provisional Service Flow", "wmx.reg_rsp.total_provisional_sf",
135                         FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL
136                 }
137         },
138         {
139                 &hf_reg_rsp_service_flow_id,
140                 {
141                         "Service flow ID", "wmx.reg_rsp.service_flow_id",
142                         FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL
143                 }
144         },
145         {
146                 &hf_reg_rsp_system_resource_retain_time,
147                 {
148                         "System Resource Retain Time", "wmx.reg_rsp.system_resource_retain_time",
149                         FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL
150                 }
151         },
152         {
153                 &hf_tlv_type,
154                 {
155                         "Unknown TLV Type", "wmx.reg_rsp.unknown_tlv_type", 
156                         FT_BYTES, BASE_NONE, NULL, 0x00, "", HFILL
157                 }
158         },
159         {
160                 &hf_tlv_value,
161                 {
162                         "Value", "wmx.reg_rsp.tlv_value", 
163                         FT_BYTES, BASE_NONE, NULL, 0x00, "", HFILL
164                 }
165         }
166 };
167
168 /* Register Wimax Mac Payload Protocol and Dissector */
169 void proto_register_mac_mgmt_msg_reg_rsp(void)
170 {
171         if (proto_mac_mgmt_msg_reg_rsp_decoder == -1)
172         {
173                 proto_mac_mgmt_msg_reg_rsp_decoder = proto_mac_mgmt_msg_reg_req_decoder;
174
175                 proto_register_field_array(proto_mac_mgmt_msg_reg_rsp_decoder, hf, array_length(hf));
176                 proto_register_subtree_array(ett, array_length(ett));
177         }
178 }
179
180 /* Decode REG-RSP messages. */
181 void dissect_mac_mgmt_msg_reg_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
182 {
183         guint offset = 0;
184         guint tlv_offset;
185         guint tvb_len, payload_type;
186         proto_item *reg_rsp_item = NULL;
187         proto_tree *reg_rsp_tree = NULL;
188         proto_item *tlv_item = NULL;
189         proto_tree *tlv_tree = NULL;
190         proto_tree *sub_tree = NULL;
191         gboolean hmac_found = FALSE;
192         tlv_info_t tlv_info;
193         gint tlv_type;
194         guint tlv_len;
195         guint this_offset = 0;
196         tlv_info_t sub_tlv_info;
197         gint sub_tlv_type;
198         gint sub_tlv_len;
199         guint sub_tlv_offset;
200
201         /* Ensure the right payload type */
202         payload_type = tvb_get_guint8(tvb, offset);
203         if (payload_type != MAC_MGMT_MSG_REG_RSP)
204         {
205                 return;
206         }
207
208         if (tree)
209         {       /* we are being asked for details */
210
211                 /* Get the tvb reported length */
212                 tvb_len =  tvb_reported_length(tvb);
213                 /* display MAC payload type REG-RSP */
214                 reg_rsp_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, offset, tvb_len, "MAC Management Message, REG-RSP (7)");
215                 /* add MAC REG-RSP subtree */
216                 reg_rsp_tree = proto_item_add_subtree(reg_rsp_item, ett_mac_mgmt_msg_reg_rsp_decoder);
217                 /* display the Message Type */
218                 proto_tree_add_item(reg_rsp_tree, hf_reg_rsp_message_type, tvb, offset, 1, FALSE);
219                 proto_tree_add_item(reg_rsp_tree, hf_reg_rsp_status, tvb, offset + 1, 1, FALSE);
220                 offset += 2;
221
222                 while (offset < tvb_len)
223                 {
224                         /* Get the TLV data. */
225                         init_tlv_info(&tlv_info, tvb, offset);
226                         /* get the TLV type */
227                         tlv_type = get_tlv_type(&tlv_info);
228                         /* get the TLV length */
229                         tlv_len = get_tlv_length(&tlv_info);
230                         if (tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
231                         {       /* invalid tlv info */
232                                 if (pinfo->cinfo)
233                                 {
234                                         col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "REG-RSP TLV error");
235                                 }
236                                 proto_tree_add_item(reg_rsp_tree, hf_reg_invalid_tlv, tvb, offset, (tvb_len - offset), FALSE);
237                                 break;
238                         }
239                         /* get the offset to the TLV data */
240                         tlv_offset = offset + get_tlv_value_offset(&tlv_info);
241
242                         switch (tlv_type) {
243                                 case REG_ARQ_PARAMETERS:
244                                 case REG_SS_MGMT_SUPPORT:
245                                 case REG_IP_MGMT_MODE:
246                                 case REG_IP_VERSION:
247                                 case REG_UL_TRANSPORT_CIDS_SUPPORTED:
248                                 case REG_IP_PHS_SDU_ENCAP:
249                                 case REG_MAX_CLASSIFIERS_SUPPORTED:
250                                 case REG_PHS_SUPPORT:
251                                 case REG_ARQ_SUPPORT:
252                                 case REG_DSX_FLOW_CONTROL:
253                                 case REG_MCA_FLOW_CONTROL:
254                                 case REG_MCAST_POLLING_CIDS:
255                                 case REG_NUM_DL_TRANS_CID:
256                                 case REG_MAC_ADDRESS:
257 #ifdef WIMAX_16E_2005
258                                 case REG_TLV_T_20_MAX_MAC_DATA_PER_FRAME_SUPPORT:
259                                 case REG_TLV_T_21_PACKING_SUPPORT:
260                                 case REG_TLV_T_22_MAC_EXTENDED_RTPS_SUPPORT:
261                                 case REG_TLV_T_23_MAX_NUM_BURSTS_TRANSMITTED_CONCURRENTLY_TO_THE_MS:
262                                 case REG_TLV_T_26_METHOD_FOR_ALLOCATING_IP_ADDR_SECONDARY_MGMNT_CONNECTION:
263                                 case REG_TLV_T_27_HANDOVER_SUPPORTED:
264                                 case REG_TLV_T_29_HO_PROCESS_OPTIMIZATION_MS_TIMER:
265                                 case REG_TLV_T_31_MOBILITY_FEATURES_SUPPORTED:
266                                 case REG_TLV_T_40_ARQ_ACK_TYPE:
267                                 case REG_TLV_T_41_MS_HO_CONNECTIONS_PARAM_PROCESSING_TIME:
268                                 case REG_TLV_T_42_MS_HO_TEK_PROCESSING_TIME:
269                                 case REG_TLV_T_43_MAC_HEADER_AND_EXTENDED_SUBHEADER_SUPPORT:
270                                 case REG_POWER_SAVING_CLASS_CAPABILITY:
271 #endif
272                                         dissect_extended_tlv(reg_rsp_tree, tlv_type, tvb, tlv_offset, tlv_len, pinfo, offset, proto_mac_mgmt_msg_reg_rsp_decoder);
273                                         break;
274                                 case REG_RSP_SECONDARY_MGMT_CID:
275                                         tlv_tree = add_tlv_subtree(&tlv_info, ett_reg_rsp_message_tree, reg_rsp_tree, hf_reg_rsp_secondary_mgmt_cid, tvb, tlv_offset, tlv_len, FALSE);
276                                         proto_tree_add_item(tlv_tree, hf_reg_rsp_secondary_mgmt_cid, tvb, tlv_offset, tlv_len, FALSE);
277                                         break;
278
279                                 case REG_RSP_TLV_T_36_TOTAL_PROVISIONED_SERVICE_FLOW_DSAs:
280                                         tlv_tree = add_tlv_subtree(&tlv_info, ett_reg_rsp_message_tree, reg_rsp_tree, hf_reg_total_provisioned_sf, tvb, tlv_offset, tlv_len, FALSE);
281                                         proto_tree_add_item(tlv_tree, hf_reg_total_provisioned_sf, tvb, tlv_offset, tlv_len, FALSE);
282                                         break;
283
284                                 case REG_RSP_TLV_T_24_CID_UPDATE_ENCODINGS:
285                                         /* Display CID update encodings */
286                                         /* add subtree */
287                                         sub_tree = add_protocol_subtree(&tlv_info, ett_reg_rsp_message_tree, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "CID update encodings (%u byte(s))", tlv_len);
288                                         /* Use a local copy of tlv_offset */
289                                         this_offset = tlv_offset;
290                                         while(this_offset < tlv_len) {
291                                                 /* Get the sub TLV data. */
292                                                 init_tlv_info(&sub_tlv_info, tvb, this_offset);
293                                                 /* get the sub TLV type */
294                                                 sub_tlv_type = get_tlv_type(&sub_tlv_info);
295                                                 /* get the TLV length */
296                                                 sub_tlv_len = get_tlv_length(&sub_tlv_info);
297                                                 if (tlv_type == -1 || sub_tlv_len > MAX_TLV_LEN || sub_tlv_len < 1)
298                                                 {       /* invalid tlv info */
299                                                         if (pinfo->cinfo)
300                                                         {
301                                                                 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "REG-RSP TLV error");
302                                                         }
303                                                         proto_tree_add_item(reg_rsp_tree, hf_reg_invalid_tlv, tvb, offset, (tvb_len - offset), FALSE);
304                                                         break;
305                                                 }
306                                                 /* get the offset to the sub TLV data */
307                                                 sub_tlv_offset = this_offset + get_tlv_value_offset(&sub_tlv_info);
308                                                 switch (sub_tlv_type) {
309                                                         case REG_RSP_TLV_T_24_1_CID_UPDATE_ENCODINGS_NEW_CID:
310                                                                 tlv_tree = add_tlv_subtree(&sub_tlv_info, ett_reg_rsp_message_tree, sub_tree, hf_reg_rsp_new_cid_after_ho, tvb, sub_tlv_offset, sub_tlv_len, FALSE);
311                                                                 proto_tree_add_item(tlv_tree, hf_reg_rsp_new_cid_after_ho, tvb, sub_tlv_offset, sub_tlv_len, FALSE);
312                                                                 break;
313                                                         case REG_RSP_TLV_T_24_2_CID_UPDATE_ENCODINGS_SFID:
314                                                                 tlv_tree = add_tlv_subtree(&sub_tlv_info, ett_reg_rsp_message_tree, sub_tree, hf_reg_rsp_service_flow_id, tvb, sub_tlv_offset, sub_tlv_len, FALSE);
315                                                                 proto_tree_add_item(tlv_tree, hf_reg_rsp_service_flow_id, tvb, sub_tlv_offset, sub_tlv_len, FALSE);
316                                                                 break;
317                                                         case REG_RSP_TLV_T_24_3_CID_UPDATE_ENCODINGS_CONNECTION_INFO:
318                                                                 tlv_tree = add_protocol_subtree(&sub_tlv_info, ett_reg_rsp_message_tree, sub_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, sub_tlv_offset, sub_tlv_len, "CID Update Encodings Connection Info (%u byte(s))", tlv_len);
319                                                                 /* Decode the DSC_RSP subTLV's */
320                                                                 dissect_mac_mgmt_msg_dsc_rsp_decoder(tvb_new_subset(tvb, sub_tlv_offset, sub_tlv_len, sub_tlv_len), pinfo, tlv_tree);
321                                                                 break;
322                                                         default:
323                                                                 tlv_tree = add_tlv_subtree(&sub_tlv_info, ett_reg_rsp_message_tree, sub_tree, hf_tlv_type, tvb, sub_tlv_offset, sub_tlv_len, FALSE);
324                                                                 proto_tree_add_item(tlv_tree, hf_tlv_type, tvb, sub_tlv_offset, sub_tlv_len, FALSE);
325                                                                 break;
326                                                 }
327                                                 this_offset = sub_tlv_len + sub_tlv_offset;
328                                         }
329                                         break;
330                                 case REG_RSP_TLV_T_28_HO_SYSTEM_RESOURCE_RETAIN_TIME:
331                                         tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_reg_rsp_decoder, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "System Resource Retain Time (%u byte(s))", tlv_len);
332                                         tlv_item = proto_tree_add_item(tlv_tree, hf_reg_rsp_system_resource_retain_time, tvb, tlv_offset, tlv_len, FALSE);
333                                         if (include_cor2_changes) {
334                                                 proto_item_append_text(tlv_item, " (in units of 100 milliseconds)");
335                                         } else {
336                                                 proto_item_append_text(tlv_item, " (multiple of 100 milliseconds)");
337                                         }
338                                         break;
339                                 case DSx_UPLINK_FLOW:
340                                         /* display Uplink Service Flow Encodings info */
341                                         /* add subtree */
342                                         tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_reg_rsp_decoder, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "Uplink Service Flow Encodings (%u byte(s))", tlv_len);
343                                         /* decode and display the DL Service Flow Encodings */
344                                         wimax_service_flow_encodings_decoder(tvb_new_subset(tvb, tlv_offset, tlv_len, tlv_len), pinfo, tlv_tree);
345                                         break;
346                                 case DSx_DOWNLINK_FLOW:
347                                         /* display Downlink Service Flow Encodings info */
348                                         /* add subtree */
349                                         tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_reg_rsp_decoder, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "Downlink Service Flow Encodings (%u byte(s))", tlv_len);
350                                         /* decode and display the DL Service Flow Encodings */
351                                         wimax_service_flow_encodings_decoder(tvb_new_subset(tvb, tlv_offset, tlv_len, tlv_len), pinfo, tlv_tree);
352                                         break;
353                                 case HMAC_TUPLE:        /* Table 348d */
354                                         /* decode and display the HMAC Tuple */
355                                         tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_reg_rsp_decoder, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "HMAC Tuple (%u byte(s))", tlv_len);
356                                         wimax_hmac_tuple_decoder(tlv_tree, tvb, offset+2, tlv_len);
357                                         hmac_found = TRUE;
358                                         break;
359                                 case CMAC_TUPLE:        /* Table 348b */
360                                         /* decode and display the CMAC Tuple */
361                                         tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_reg_rsp_decoder, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "CMAC Tuple (%u byte(s))", tlv_len);
362                                         wimax_cmac_tuple_decoder(tlv_tree, tvb, offset+2, tlv_len);
363                                         break;
364                                 case SHORT_HMAC_TUPLE:
365                                 case SHORT_HMAC_TUPLE_COR2:
366                                         if ((!include_cor2_changes && (tlv_type == SHORT_HMAC_TUPLE)) ||
367                                                 (include_cor2_changes && (tlv_type == SHORT_HMAC_TUPLE_COR2))) {
368                                                 /* decode and display the Short HMAC Tuple */
369                                                 tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_reg_rsp_decoder, reg_rsp_tree, proto_mac_mgmt_msg_reg_rsp_decoder, tvb, tlv_offset, tlv_len, "Short HMAC Tuple (%u byte(s))", tlv_len);
370                                                 wimax_short_hmac_tuple_decoder(tlv_tree, tvb, tlv_offset, tlv_len);
371                                         } else {
372                                                 /* Unknown TLV Type */
373                                                 tlv_tree = add_tlv_subtree(&tlv_info, ett_reg_rsp_message_tree, reg_rsp_tree, hf_tlv_type, tvb, tlv_offset, tlv_len, FALSE);
374                                                 proto_tree_add_item(tlv_tree, hf_tlv_type, tvb, tlv_offset, tlv_len, FALSE);
375                                         }
376                                         break;
377                                 case VENDOR_SPECIFIC_INFO:
378                                 case VENDOR_ID_ENCODING:
379                                 case MAC_VERSION_ENCODING:
380                                         wimax_common_tlv_encoding_decoder(tvb_new_subset(tvb, offset, (tvb_len - offset), (tvb_len - offset)), pinfo, reg_rsp_tree);
381                                         break;
382                                 default:
383                                         tlv_tree = add_tlv_subtree(&tlv_info, ett_reg_rsp_message_tree, reg_rsp_tree, hf_tlv_type, tvb, tlv_offset, tlv_len, FALSE);
384                                         proto_tree_add_item(tlv_tree, hf_tlv_type, tvb, tlv_offset, tlv_len, FALSE);
385                                         break;
386                         }
387
388                         offset = tlv_len + tlv_offset;
389                 }       /* end of TLV process while loop */
390                 if (!hmac_found)
391                         proto_item_append_text(reg_rsp_tree, " (HMAC Tuple is missing !)");
392         }
393 }
394