1 /* wimax_harq_map_decoder.c
2 * WiMax HARQ Map Message decoder
4 * Copyright (c) 2007 by Intel Corporation.
6 * Author: Lu Pan <lu.pan@intel.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1999 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include <epan/packet.h>
20 #include <epan/expert.h>
22 #include "wimax-int.h"
23 #include "wimax_compact_dlmap_ie_decoder.h"
24 #include "wimax_compact_ulmap_ie_decoder.h"
26 extern int proto_wimax
;
28 static int proto_wimax_harq_map_decoder
;
29 static int ett_wimax_harq_map_decoder
;
32 #define LSB_NIBBLE_MASK 0x0F
35 #define WIMAX_HARQ_MAP_INDICATOR_MASK 0xE00000
36 #define WIMAX_HARQ_UL_MAP_APPENDED_MASK 0x100000
37 #define WIMAX_HARQ_MAP_RESERVED_MASK 0x080000
38 #define WIMAX_HARQ_MAP_MSG_LENGTH_MASK 0x07FC00
39 #define WIMAX_HARQ_MAP_DL_IE_COUNT_MASK 0x0003F0
40 #define WIMAX_HARQ_MAP_MSG_LENGTH_SHIFT 10
41 #define WIMAX_HARQ_MAP_DL_IE_COUNT_SHIFT 4
43 /* HARQ MAP display indexies */
44 static int hf_harq_map_indicator
;
45 static int hf_harq_ul_map_appended
;
46 static int hf_harq_map_reserved
;
47 static int hf_harq_map_msg_length
;
48 static int hf_harq_dl_ie_count
;
49 static int hf_harq_map_msg_crc
;
50 static int hf_harq_map_msg_crc_status
;
52 static expert_field ei_harq_map_msg_crc
;
55 /* Copied and renamed from proto.c because global value_strings don't work for plugins */
56 static const value_string plugin_proto_checksum_vals
[] = {
57 { PROTO_CHECKSUM_E_BAD
, "Bad" },
58 { PROTO_CHECKSUM_E_GOOD
, "Good" },
59 { PROTO_CHECKSUM_E_UNVERIFIED
, "Unverified" },
60 { PROTO_CHECKSUM_E_NOT_PRESENT
, "Not present" },
65 /* HARQ MAP message decoder */
66 static int dissector_wimax_harq_map_decoder(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
68 unsigned i
, offset
= 0;
69 unsigned tvb_len
, length
, dl_ie_count
;
71 proto_item
*harq_map_item
= NULL
;
72 proto_tree
*harq_map_tree
= NULL
;
73 unsigned nibble_offset
;
74 proto_item
*parent_item
= NULL
;
75 unsigned ulmap_appended
;
76 uint32_t harq_map_msg_crc
, calculated_crc
;
77 uint32_t first_24bits
;
79 /* check the tvb reported length */
80 tvb_len
= tvb_reported_length(tvb
);
82 { /* do nothing if tvb is empty */
85 /* Ensure the right payload type */
86 first_24bits
= tvb_get_ntoh24(tvb
, offset
);
87 if((first_24bits
& WIMAX_HARQ_MAP_INDICATOR_MASK
) != WIMAX_HARQ_MAP_INDICATOR_MASK
)
88 { /* do nothing if tvb is not a HARQ MAP message */
91 /* update the info column */
92 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "HARQ-MAP Message: ");
94 { /* we are being asked for details */
96 parent_item
= proto_tree_get_parent(tree
);
97 /* display HARQ-MAP Message and create subtree */
98 harq_map_item
= proto_tree_add_protocol_format(tree
, proto_wimax_harq_map_decoder
, tvb
, offset
, tvb_len
, "HARQ-MAP Message (%u bytes)", tvb_len
);
99 harq_map_tree
= proto_item_add_subtree(harq_map_item
, ett_wimax_harq_map_decoder
);
100 /* display the HARQ MAP Indicator */
101 proto_tree_add_item(harq_map_tree
, hf_harq_map_indicator
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
102 /* display the HARQ MAp UL-MAP Appended */
103 proto_tree_add_item(harq_map_tree
, hf_harq_ul_map_appended
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
104 /* display the reserved bit */
105 proto_tree_add_item(harq_map_tree
, hf_harq_map_reserved
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
106 /* display the HARQ MAP message length */
107 proto_tree_add_item(harq_map_tree
, hf_harq_map_msg_length
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
108 /* display the DL IE count */
109 proto_tree_add_item(harq_map_tree
, hf_harq_dl_ie_count
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
110 /* get the message length */
111 /* XXX - make sure the length isn't smaller than the minimum */
112 length
= ((first_24bits
& WIMAX_HARQ_MAP_MSG_LENGTH_MASK
) >> WIMAX_HARQ_MAP_MSG_LENGTH_SHIFT
);
113 /* get the DL IE count */
114 dl_ie_count
= ((first_24bits
& WIMAX_HARQ_MAP_DL_IE_COUNT_MASK
) >> WIMAX_HARQ_MAP_DL_IE_COUNT_SHIFT
);
115 /* get the UL MAP appended */
116 ulmap_appended
= (first_24bits
& WIMAX_HARQ_UL_MAP_APPENDED_MASK
);
118 /* set the offsets to Compact DL-MAP IEs */
121 /* process the compact dl_map ies */
122 for(i
=0; i
<dl_ie_count
; i
++)
123 { /* add the DL-MAp IEs info */
124 proto_item_append_text(parent_item
, " - DL-MAP IEs");
125 /* decode Compact DL-MAP IEs */
126 ie_length
= wimax_compact_dlmap_ie_decoder(harq_map_tree
, pinfo
, tvb
, offset
, nibble_offset
);
127 offset
+= ((nibble_offset
+ ie_length
) >> 1);
128 nibble_offset
= ((nibble_offset
+ ie_length
) & 1);
130 /* check if there exist the compact ul_map IEs */
132 { /* add the UL-MAp IEs info */
133 proto_item_append_text(parent_item
, ",UL-MAP IEs");
134 /* process the compact ul_map ies */
135 while(offset
< (length
- (int)sizeof(harq_map_msg_crc
)))
136 { /* decode Compact UL-MAP IEs */
137 ie_length
= wimax_compact_ulmap_ie_decoder(harq_map_tree
, pinfo
, tvb
, offset
, nibble_offset
);
138 /* Prevent endless loop with erroneous data. */
141 offset
+= ((nibble_offset
+ ie_length
) >> 1);
142 nibble_offset
= ((nibble_offset
+ ie_length
) & 1);
145 /* handle the padding */
148 /* add the Padding info */
149 proto_item_append_text(parent_item
, ",Padding");
150 proto_tree_add_protocol_format(harq_map_tree
, proto_wimax_harq_map_decoder
, tvb
, offset
, 1, "Padding Nibble: 0x%x", (tvb_get_uint8(tvb
, offset
) & LSB_NIBBLE_MASK
));
152 /* add the CRC info */
153 proto_item_append_text(parent_item
, ",CRC");
154 /* calculate the HARQ MAM Message CRC */
155 if (length
>= (int)sizeof(harq_map_msg_crc
)) {
156 calculated_crc
= wimax_mac_calc_crc32(tvb_get_ptr(tvb
, 0, length
- (int)sizeof(harq_map_msg_crc
)), length
- (int)sizeof(harq_map_msg_crc
));
157 proto_tree_add_checksum(tree
, tvb
, length
- (int)sizeof(harq_map_msg_crc
), hf_harq_map_msg_crc
, hf_harq_map_msg_crc_status
, &ei_harq_map_msg_crc
,
158 pinfo
, calculated_crc
, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_VERIFY
);
161 return tvb_captured_length(tvb
);
164 /* Register Wimax HARQ MAP Protocol */
165 void wimax_proto_register_wimax_harq_map(void)
167 /* HARQ MAP display */
168 static hf_register_info hf_harq_map
[] =
171 &hf_harq_map_indicator
,
172 {"HARQ MAP Indicator", "wmx.harq_map.indicator", FT_UINT24
, BASE_HEX
, NULL
, WIMAX_HARQ_MAP_INDICATOR_MASK
, NULL
, HFILL
}
175 &hf_harq_ul_map_appended
,
176 {"HARQ UL-MAP Appended", "wmx.harq_map.ul_map_appended", FT_UINT24
, BASE_HEX
, NULL
, WIMAX_HARQ_UL_MAP_APPENDED_MASK
, NULL
, HFILL
}
179 &hf_harq_map_reserved
,
180 {"Reserved", "wmx.harq_map.reserved", FT_UINT24
, BASE_HEX
, NULL
, WIMAX_HARQ_MAP_RESERVED_MASK
, NULL
, HFILL
}
183 &hf_harq_map_msg_length
,
184 {"Map Message Length", "wmx.harq_map.msg_length", FT_UINT24
, BASE_DEC
, NULL
, WIMAX_HARQ_MAP_MSG_LENGTH_MASK
, NULL
, HFILL
}
187 &hf_harq_dl_ie_count
,
188 {"DL IE Count", "wmx.harq_map.dl_ie_count", FT_UINT24
, BASE_DEC
, NULL
, WIMAX_HARQ_MAP_DL_IE_COUNT_MASK
, NULL
, HFILL
}
191 &hf_harq_map_msg_crc
,
192 {"HARQ MAP Message CRC", "wmx.harq_map.msg_crc", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
195 &hf_harq_map_msg_crc_status
,
196 {"HARQ MAP Message CRC Status", "wmx.harq_map.msg_crc.status", FT_UINT8
, BASE_NONE
, VALS(plugin_proto_checksum_vals
), 0x0, NULL
, HFILL
}
200 /* Setup protocol subtree array */
203 &ett_wimax_harq_map_decoder
,
206 static ei_register_info ei
[] = {
207 { &ei_harq_map_msg_crc
, { "wmx.harq_map.bad_checksum", PI_CHECKSUM
, PI_ERROR
, "Bad checksum", EXPFILL
}},
210 expert_module_t
* expert_harq_map
;
212 proto_wimax_harq_map_decoder
= proto_wimax
;
214 proto_register_subtree_array(ett
, array_length(ett
));
215 proto_register_field_array(proto_wimax_harq_map_decoder
, hf_harq_map
, array_length(hf_harq_map
));
216 expert_harq_map
= expert_register_protocol(proto_wimax_harq_map_decoder
);
217 expert_register_field_array(expert_harq_map
, ei
, array_length(ei
));
219 register_dissector("wimax_harq_map_handler", dissector_wimax_harq_map_decoder
, proto_wimax_harq_map_decoder
);
223 * Editor modelines - https://www.wireshark.org/tools/modelines.html
228 * indent-tabs-mode: t
231 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
232 * :indentSize=8:tabSize=8:noTabs=false: