1 /* msg_dsd.c
2 * WiMax MAC Management DSD-REQ/RSP Messages decoder
3 *
4 * Copyright (c) 2007 by Intel Corporation.
5 *
6 * Author: Lu Pan <lu.pan@intel.com>
7 *
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1999 Gerald Combs
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 */
14
15 /* Include files */
16
17 #include "config.h"
18
19 /*
20 #define DEBUG
21 */
22
23 #include <epan/packet.h>
24 #include "wimax_tlv.h"
25 #include "wimax_mac.h"
26 #include "wimax_utils.h"
27
28 void proto_register_mac_mgmt_msg_dsd(void);
29 void proto_reg_handoff_mac_mgmt_msg_dsd(void);
30
31 static gint proto_mac_mgmt_msg_dsd_decoder = -1;
32 static gint ett_mac_mgmt_msg_dsd_req_decoder = -1;
33 static gint ett_mac_mgmt_msg_dsd_rsp_decoder = -1;
34 /* static gint ett_dsd_ul_sfe_decoder = -1; */
35 /* static gint ett_dsd_dl_sfe_decoder = -1; */
36 /* static gint ett_dsd_hmac_tuple = -1; */
37 /* static gint ett_dsd_cmac_tuple = -1; */
38
39 /* fix fields */
40 static gint hf_dsd_transaction_id = -1;
41 static gint hf_dsd_service_flow_id = -1;
42 static gint hf_dsd_confirmation_code = -1;
43 static gint hf_dsd_invalid_tlv = -1;
44 static gint hf_dsd_unknown_type = -1;
45
46
dissect_mac_mgmt_msg_dsd_req_decoder(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)47 static int dissect_mac_mgmt_msg_dsd_req_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
48 {
49 guint offset = 0;
50 guint tvb_len, tlv_len, tlv_value_offset;
51 gint tlv_type;
52 proto_item *dsd_item;
53 proto_tree *dsd_tree;
54 proto_tree *tlv_tree = NULL;
55 tlv_info_t tlv_info;
56
57 { /* we are being asked for details */
58 /* Get the tvb reported length */
59 tvb_len = tvb_reported_length(tvb);
60 /* display MAC message type */
61 dsd_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, -1,
62 "Dynamic Service Deletion Request (DSD-REQ)");
63 /* add MAC DSx subtree */
64 dsd_tree = proto_item_add_subtree(dsd_item, ett_mac_mgmt_msg_dsd_req_decoder);
65 /* Decode and display the DSD message */
66 /* display the Transaction ID */
67 proto_tree_add_item(dsd_tree, hf_dsd_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
68 /* move to next field */
69 offset += 2;
70 /* display the Service Flow ID */
71 proto_tree_add_item(dsd_tree, hf_dsd_service_flow_id, tvb, offset, 4, ENC_BIG_ENDIAN);
72 /* move to next field */
73 offset += 4;
74 /* process DSD REQ message TLV Encode Information */
75 while(offset < tvb_len)
76 { /* get the TLV information */
77 init_tlv_info(&tlv_info, tvb, offset);
78 /* get the TLV type */
79 tlv_type = get_tlv_type(&tlv_info);
80 /* get the TLV length */
81 tlv_len = get_tlv_length(&tlv_info);
82 if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
83 { /* invalid tlv info */
84 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "DSD-REQ TLV error");
85 proto_tree_add_item(dsd_tree, hf_dsd_invalid_tlv, tvb, offset, (tvb_len - offset), ENC_NA);
86 break;
87 }
88 /* get the TLV value offset */
89 tlv_value_offset = get_tlv_value_offset(&tlv_info);
90 #ifdef DEBUG /* for debug only */
91 proto_tree_add_protocol_format(dsd_tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, tlv_len + tlv_value_offset, "DSD-REQ TLV Type: %u (%u bytes, offset=%u, tvb_len=%u)", tlv_type, tlv_len + tlv_value_offset, offset, tvb_len);
92 #endif
93 /* process TLV */
94 switch (tlv_type)
95 {
96 case HMAC_TUPLE: /* Table 348d */
97 /* decode and display the HMAC Tuple */
98 tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_dsd_req_decoder, dsd_tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, tlv_len, "HMAC Tuple");
99 wimax_hmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
100 break;
101 case CMAC_TUPLE: /* Table 348b */
102 /* decode and display the CMAC Tuple */
103 tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_dsd_req_decoder, dsd_tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, tlv_len, "CMAC Tuple");
104 wimax_cmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
105 break;
106 default:
107 /* display the unknown tlv in hex */
108 add_tlv_subtree(&tlv_info, dsd_tree, hf_dsd_unknown_type, tvb, offset, ENC_NA);
109 break;
110 }
111 offset += (tlv_len+tlv_value_offset);
112 } /* end of while loop */
113 }
114 return tvb_captured_length(tvb);
115 }
116
dissect_mac_mgmt_msg_dsd_rsp_decoder(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)117 static int dissect_mac_mgmt_msg_dsd_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
118 {
119 guint offset = 0;
120 guint tvb_len, tlv_len, tlv_value_offset;
121 gint tlv_type;
122 proto_item *dsd_item;
123 proto_tree *dsd_tree;
124 proto_tree *tlv_tree = NULL;
125 tlv_info_t tlv_info;
126
127 { /* we are being asked for details */
128 /* Get the tvb reported length */
129 tvb_len = tvb_reported_length(tvb);
130 /* display MAC message type */
131 dsd_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, -1,
132 "Dynamic Service Deletion Response (DSD-RSP)");
133 /* add MAC DSx subtree */
134 dsd_tree = proto_item_add_subtree(dsd_item, ett_mac_mgmt_msg_dsd_rsp_decoder);
135 /* Decode and display the DSD message */
136 /* display the Transaction ID */
137 proto_tree_add_item(dsd_tree, hf_dsd_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
138 /* move to next field */
139 offset += 2;
140 /* display the Confirmation Code */
141 proto_tree_add_item(dsd_tree, hf_dsd_confirmation_code, tvb, offset, 1, ENC_BIG_ENDIAN);
142 /* move to next field */
143 offset++;
144 /* display the Service Flow ID */
145 proto_tree_add_item(dsd_tree, hf_dsd_service_flow_id, tvb, offset, 4, ENC_BIG_ENDIAN);
146 /* move to next field */
147 offset += 4;
148 /* process DSD RSP message TLV Encode Information */
149 while(offset < tvb_len)
150 { /* get the TLV information */
151 init_tlv_info(&tlv_info, tvb, offset);
152 /* get the TLV type */
153 tlv_type = get_tlv_type(&tlv_info);
154 /* get the TLV length */
155 tlv_len = get_tlv_length(&tlv_info);
156 if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
157 { /* invalid tlv info */
158 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "DSD RSP TLV error");
159 proto_tree_add_item(dsd_tree, hf_dsd_invalid_tlv, tvb, offset, (tvb_len - offset), ENC_NA);
160 break;
161 }
162 /* get the TLV value offset */
163 tlv_value_offset = get_tlv_value_offset(&tlv_info);
164 #ifdef DEBUG /* for debug only */
165 proto_tree_add_protocol_format(dsd_tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, tlv_len + tlv_value_offset, "DSD-RSP TLV Type: %u (%u bytes, offset=%u, tvb_len=%u)", tlv_type, tlv_len + tlv_value_offset, offset, tvb_len);
166 #endif
167 /* process TLV */
168 switch (tlv_type)
169 {
170 case HMAC_TUPLE: /* Table 348d */
171 /* decode and display the HMAC Tuple */
172 tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_dsd_req_decoder, dsd_tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, tlv_len, "HMAC Tuple");
173 wimax_hmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
174 break;
175 case CMAC_TUPLE: /* Table 348b */
176 /* decode and display the CMAC Tuple */
177 tlv_tree = add_protocol_subtree(&tlv_info, ett_mac_mgmt_msg_dsd_req_decoder, dsd_tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, tlv_len, "CMAC Tuple");
178 wimax_cmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
179 break;
180 default:
181 add_tlv_subtree(&tlv_info, dsd_tree, hf_dsd_unknown_type, tvb, offset, ENC_NA);
182 break;
183 }
184 offset += (tlv_len+tlv_value_offset);
185 } /* end of while loop */
186 }
187 return tvb_captured_length(tvb);
188 }
189
190 /* Register Wimax Mac Payload Protocol and Dissector */
proto_register_mac_mgmt_msg_dsd(void)191 void proto_register_mac_mgmt_msg_dsd(void)
192 {
193 /* DSx display */
194 static hf_register_info hf[] =
195 {
196 {
197 &hf_dsd_confirmation_code,
198 {
199 "Confirmation code", "wmx.dsd.confirmation_code",
200 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
201 }
202 },
203 {
204 &hf_dsd_service_flow_id,
205 {
206 "Service Flow ID", "wmx.dsd.service_flow_id",
207 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL
208 }
209 },
210 {
211 &hf_dsd_transaction_id,
212 {
213 "Transaction ID", "wmx.dsd.transaction_id",
214 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL
215 }
216 },
217 {
218 &hf_dsd_invalid_tlv,
219 {
220 "Invalid TLV", "wmx.dsd.invalid_tlv",
221 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL
222 }
223 },
224 {
225 &hf_dsd_unknown_type,
226 {
227 "Unknown type", "wmx.dsd.unknown_type",
228 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL
229 }
230 }
231 };
232
233 /* Setup protocol subtree array */
234 static gint *ett[] =
235 {
236 &ett_mac_mgmt_msg_dsd_req_decoder,
237 &ett_mac_mgmt_msg_dsd_rsp_decoder,
238 /* &ett_dsd_ul_sfe_decoder, */
239 /* &ett_dsd_dl_sfe_decoder, */
240 /* &ett_dsd_hmac_tuple, */
241 /* &ett_dsd_cmac_tuple, */
242 };
243
244 proto_mac_mgmt_msg_dsd_decoder = proto_register_protocol (
245 "WiMax DSD Messages", /* name */
246 "WiMax DSD", /* short name */
247 "wmx.dsd" /* abbrev */
248 );
249
250 proto_register_field_array(proto_mac_mgmt_msg_dsd_decoder, hf, array_length(hf));
251 proto_register_subtree_array(ett, array_length(ett));
252 }
253
254 void
proto_reg_handoff_mac_mgmt_msg_dsd(void)255 proto_reg_handoff_mac_mgmt_msg_dsd(void)
256 {
257 dissector_handle_t dsd_handle;
258
259 dsd_handle = create_dissector_handle(dissect_mac_mgmt_msg_dsd_req_decoder, proto_mac_mgmt_msg_dsd_decoder);
260 dissector_add_uint("wmx.mgmtmsg", MAC_MGMT_MSG_DSD_REQ, dsd_handle);
261
262 dsd_handle = create_dissector_handle(dissect_mac_mgmt_msg_dsd_rsp_decoder, proto_mac_mgmt_msg_dsd_decoder);
263 dissector_add_uint("wmx.mgmtmsg", MAC_MGMT_MSG_DSD_RSP, dsd_handle);
264 }
265
266
267 /*
268 * Editor modelines - https://www.wireshark.org/tools/modelines.html
269 *
270 * Local variables:
271 * c-basic-offset: 8
272 * tab-width: 8
273 * indent-tabs-mode: t
274 * End:
275 *
276 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
277 * :indentSize=8:tabSize=8:noTabs=false:
278 */
279