2 * WiMax PDU Burst decoder
4 * Copyright (c) 2007 by Intel Corporation.
6 * Author: Lu Pan <lu.pan@intel.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1999 Gerald Combs
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.
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.
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.
34 #include <epan/packet.h>
37 extern gint proto_wimax
;
39 static dissector_handle_t mac_generic_decoder_handle
= NULL
;
40 static dissector_handle_t mac_header_type1_handle
= NULL
;
41 static dissector_handle_t mac_header_type2_handle
= NULL
;
42 static dissector_handle_t wimax_harq_map_handle
= NULL
;
44 /* MAC Header dissector prototypes */
45 extern gboolean
is_down_link(packet_info
*pinfo
);
46 extern gint
wimax_decode_dlmap_reduced_aas(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*base_tree
);
47 extern gint
wimax_decode_dlmapc(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*pdu_tree
);
49 #define WIMAX_PDU_PADDING_MASK 0xFF
50 #define WIMAX_INVALID_PDU_MASK 0xF0
51 #define WIMAX_MAP_TYPE_MASK 0xE0 /* 0b111 */
52 #define WIMAX_HARQ_MAP_MSG_IND 0xE0 /* 0b111 */
53 #define WIMAX_COMPRESSED_DL_MAP_IND 0xC0 /* 0b110 */
54 #define REDUCED_PRIVATE_MAP_MASK 0x0C /* 0b11 */
56 #define WIMAX_MAC_HEADER_SIZE 6
57 #define WIMAX_MAC_HEADER_INFO_FIELDS 5
58 #define WIMAX_MAC_HEADER_HT_FIELD 0x80
59 #define WIMAX_MAC_HEADER_EC_FIELD 0x40
60 #define WIMAX_MAC_HEADER_LENGTH_MSB_MASK 0x07
62 #define WIMAX_HARQ_MAP_MSG_LENGTH_MASK1 0x07FC
63 /* Global Variables. */
66 static gint proto_wimax_pdu_decoder
= -1;
67 static gint ett_wimax_pdu_decoder
= -1;
69 static int hf_wimax_value_bytes
= -1;
71 static void dissect_wimax_pdu_decoder(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
75 guint first_byte
, length
;
76 guint mac_hcs
, mac_hcs_calculated
;
77 proto_item
*pdu_item
= NULL
;
78 proto_tree
*pdu_tree
= NULL
;
81 /* generate the table of CRC32 remainders for all possible bytes */
82 wimax_mac_gen_crc32_table();
83 /* generate the table of CRC8 remainders for all possible bytes */
84 wimax_mac_gen_crc8_table();
87 /* parsing the PDU burst */
88 for(offset
= 0; offset
< tvb_reported_length(tvb
); )
98 /* get the length of the remainder */
99 length
= tvb_reported_length_remaining(tvb
, offset
);
100 /* get the first byte at offset */
101 first_byte
= tvb_get_guint8(tvb
, offset
);
102 /* check for padding */
103 if(first_byte
== WIMAX_PDU_PADDING_MASK
)
105 /* display message */
106 pdu_item
= proto_tree_add_protocol_format(tree
, proto_wimax_pdu_decoder
, tvb
, offset
, length
, "Padding (%u bytes)", length
);
108 pdu_tree
= proto_item_add_subtree(pdu_item
, ett_wimax_pdu_decoder
);
109 /* display the padding in Hex */
110 proto_tree_add_item(pdu_tree
, hf_wimax_value_bytes
, tvb
, offset
, length
, ENC_NA
);
113 else if((first_byte
& WIMAX_MAP_TYPE_MASK
) == WIMAX_HARQ_MAP_MSG_IND
)
114 { /* HARQ MAP message (no mac header) */
115 /* get the HARQ MAp Message Length */
116 length
= ((tvb_get_ntohs(tvb
, offset
) & WIMAX_HARQ_MAP_MSG_LENGTH_MASK1
) >> 2);
119 length
= 3; /* At least 3 bytes. This prevents endless loop */
121 call_dissector(wimax_harq_map_handle
, tvb_new_subset_length(tvb
,offset
,length
), pinfo
, tree
);
125 else if((first_byte
& WIMAX_MAP_TYPE_MASK
) == WIMAX_COMPRESSED_DL_MAP_IND
)
127 if(is_down_link(pinfo
))
128 { /* decode compressed dl-map without mac header */
129 if ((first_byte
& REDUCED_PRIVATE_MAP_MASK
) == REDUCED_PRIVATE_MAP_MASK
)
131 length
= wimax_decode_dlmap_reduced_aas(tvb
, pinfo
, tree
);
135 length
= wimax_decode_dlmapc(tvb
, pinfo
, tree
);
141 else if((first_byte
& WIMAX_INVALID_PDU_MASK
) == WIMAX_INVALID_PDU_MASK
)
143 /* update the info column */
144 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "Invalid PDU");
145 /* display message */
146 pdu_item
= proto_tree_add_protocol_format(tree
, proto_wimax_pdu_decoder
, tvb
, offset
, length
, "Invalid PDU (%u bytes)", length
);
148 pdu_tree
= proto_item_add_subtree(pdu_item
, ett_wimax_pdu_decoder
);
149 /* display the invalid MAC Header in Hex */
150 proto_tree_add_item(pdu_tree
, hf_wimax_value_bytes
, tvb
, offset
, length
, ENC_NA
);
153 /* calculate the MAC header HCS */
154 mac_hcs_calculated
= wimax_mac_calc_crc8(tvb_get_ptr(tvb
, offset
, WIMAX_MAC_HEADER_INFO_FIELDS
), WIMAX_MAC_HEADER_INFO_FIELDS
);
155 /* get the Header Check Sequence (HCS) in the header */
156 mac_hcs
= tvb_get_guint8(tvb
, offset
+ WIMAX_MAC_HEADER_SIZE
- 1);
158 if(mac_hcs
!= mac_hcs_calculated
)
160 /* update the info column */
161 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "MAC Header CRC error");
162 /* display message */
163 pdu_item
= proto_tree_add_protocol_format(tree
, proto_wimax_pdu_decoder
, tvb
, offset
, WIMAX_MAC_HEADER_SIZE
, "MAC Header CRC error %X (in header) and %X (calculated)", mac_hcs
, mac_hcs_calculated
);
165 pdu_tree
= proto_item_add_subtree(pdu_item
, ett_wimax_pdu_decoder
);
166 /* display the bad MAC Header in Hex */
167 proto_tree_add_item(pdu_tree
, hf_wimax_value_bytes
, tvb
, offset
, length
, ENC_NA
);
170 /* get the Header Type (HT) */
171 mac_ht
= ((first_byte
& WIMAX_MAC_HEADER_HT_FIELD
)?1:0);
172 /* get the Encryption Control (EC) */
173 mac_ec
= ((first_byte
& WIMAX_MAC_HEADER_EC_FIELD
)?1:0);
174 /* update the MAC length for Generic MAC frame */
176 { /* Generic MAC Header with payload */
177 /* get the MAC length */
178 length
= (tvb_get_guint8(tvb
, offset
+1) & WIMAX_MAC_HEADER_LENGTH_MSB_MASK
);
179 length
= ((length
<<8) | tvb_get_guint8(tvb
, offset
+2));
181 else /* MAC signaling Headers or Bandwidth Request Headers */
182 { /* set the mac length */
183 length
= WIMAX_MAC_HEADER_SIZE
;
185 /* display PDU frame info */
187 pdu_item = proto_tree_add_protocol_format(tree, proto_wimax_pdu_decoder, tvb, offset, length, "PDU Frame (%u bytes)", length);
189 pdu_item
= proto_tree_add_protocol_format(tree
, proto_wimax_pdu_decoder
, tvb
, offset
, length
, "PDU (%u bytes)", length
);
190 /* add PDU subtree */
191 pdu_tree
= proto_item_add_subtree(pdu_item
, ett_wimax_pdu_decoder
);
193 offset
+= 6; /* Add header size. */
194 /* Must skip the code below or tvb_new_subset_length()
195 * keeps allocating memory until it runs out. */
198 /* process the valid MAC header */
200 { /* MAC signaling Headers or Bandwidth Request Headers */
201 /* check the header type */
203 { /* MAC Signaling Header Type II Header */
204 proto_item_append_text(pdu_item
, " - Mac Type II Header: ");
205 call_dissector(mac_header_type2_handle
, tvb_new_subset_length(tvb
,offset
,length
), pinfo
, pdu_tree
);
208 { /* MAC Signaling Header Type I Header */
209 proto_item_append_text(pdu_item
, " - Mac Type I Header: ");
210 call_dissector(mac_header_type1_handle
, tvb_new_subset_length(tvb
,offset
,length
), pinfo
, pdu_tree
);
213 else /* Generic MAC Header with payload */
215 call_dissector(mac_generic_decoder_handle
, tvb_new_subset_length(tvb
,offset
,length
), pinfo
, pdu_tree
);
221 /* Register Wimax PDU Burst Protocol */
222 void proto_register_wimax_pdu(void)
225 static hf_register_info hf
[] =
228 &hf_wimax_value_bytes
,
230 "Values", "wmx.pdu.value",
231 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
237 /* Setup protocol subtree array */
240 &ett_wimax_pdu_decoder
,
243 proto_wimax_pdu_decoder
= proto_wimax
;
245 register_dissector("wimax_pdu_burst_handler", dissect_wimax_pdu_decoder
, -1);
246 proto_register_field_array(proto_wimax_pdu_decoder
, hf
, array_length(hf
));
247 proto_register_subtree_array(ett
, array_length(ett
));
251 proto_reg_handoff_wimax_pdu(void)
253 mac_generic_decoder_handle
= find_dissector("mac_header_generic_handler");
254 mac_header_type1_handle
= find_dissector("mac_header_type_1_handler");
255 mac_header_type2_handle
= find_dissector("mac_header_type_2_handler");
256 wimax_harq_map_handle
= find_dissector("wimax_harq_map_handler");