Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / plugins / epan / wimax / msg_dsd.c
blob06de174b955f1ddf5ce4394dc786468eb71929ee
1 /* msg_dsd.c
2 * WiMax MAC Management DSD-REQ/RSP Messages 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
15 /* Include files */
17 #include "config.h"
20 #define DEBUG
23 #include <epan/packet.h>
24 #include "wimax_tlv.h"
25 #include "wimax_mac.h"
26 #include "wimax_utils.h"
28 void proto_register_mac_mgmt_msg_dsd(void);
29 void proto_reg_handoff_mac_mgmt_msg_dsd(void);
31 static dissector_handle_t dsd_req_handle;
32 static dissector_handle_t dsd_rsp_handle;
34 static int proto_mac_mgmt_msg_dsd_decoder;
35 static int ett_mac_mgmt_msg_dsd_req_decoder;
36 static int ett_mac_mgmt_msg_dsd_rsp_decoder;
37 /* static int ett_dsd_ul_sfe_decoder; */
38 /* static int ett_dsd_dl_sfe_decoder; */
39 /* static int ett_dsd_hmac_tuple; */
40 /* static int ett_dsd_cmac_tuple; */
42 /* fix fields */
43 static int hf_dsd_transaction_id;
44 static int hf_dsd_service_flow_id;
45 static int hf_dsd_confirmation_code;
46 static int hf_dsd_invalid_tlv;
47 static int hf_dsd_unknown_type;
50 static int dissect_mac_mgmt_msg_dsd_req_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
52 unsigned offset = 0;
53 unsigned tvb_len, tlv_len, tlv_value_offset;
54 int tlv_type;
55 proto_item *dsd_item;
56 proto_tree *dsd_tree;
57 proto_tree *tlv_tree = NULL;
58 tlv_info_t tlv_info;
60 { /* we are being asked for details */
61 /* Get the tvb reported length */
62 tvb_len = tvb_reported_length(tvb);
63 /* display MAC message type */
64 dsd_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, -1,
65 "Dynamic Service Deletion Request (DSD-REQ)");
66 /* add MAC DSx subtree */
67 dsd_tree = proto_item_add_subtree(dsd_item, ett_mac_mgmt_msg_dsd_req_decoder);
68 /* Decode and display the DSD message */
69 /* display the Transaction ID */
70 proto_tree_add_item(dsd_tree, hf_dsd_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
71 /* move to next field */
72 offset += 2;
73 /* display the Service Flow ID */
74 proto_tree_add_item(dsd_tree, hf_dsd_service_flow_id, tvb, offset, 4, ENC_BIG_ENDIAN);
75 /* move to next field */
76 offset += 4;
77 /* process DSD REQ message TLV Encode Information */
78 while(offset < tvb_len)
79 { /* get the TLV information */
80 init_tlv_info(&tlv_info, tvb, offset);
81 /* get the TLV type */
82 tlv_type = get_tlv_type(&tlv_info);
83 /* get the TLV length */
84 tlv_len = get_tlv_length(&tlv_info);
85 if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
86 { /* invalid tlv info */
87 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "DSD-REQ TLV error");
88 proto_tree_add_item(dsd_tree, hf_dsd_invalid_tlv, tvb, offset, (tvb_len - offset), ENC_NA);
89 break;
91 /* get the TLV value offset */
92 tlv_value_offset = get_tlv_value_offset(&tlv_info);
93 #ifdef DEBUG /* for debug only */
94 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);
95 #endif
96 /* process TLV */
97 switch (tlv_type)
99 case HMAC_TUPLE: /* Table 348d */
100 /* decode and display the HMAC Tuple */
101 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");
102 wimax_hmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
103 break;
104 case CMAC_TUPLE: /* Table 348b */
105 /* decode and display the CMAC Tuple */
106 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");
107 wimax_cmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
108 break;
109 default:
110 /* display the unknown tlv in hex */
111 add_tlv_subtree(&tlv_info, dsd_tree, hf_dsd_unknown_type, tvb, offset, ENC_NA);
112 break;
114 offset += (tlv_len+tlv_value_offset);
115 } /* end of while loop */
117 return tvb_captured_length(tvb);
120 static int dissect_mac_mgmt_msg_dsd_rsp_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
122 unsigned offset = 0;
123 unsigned tvb_len, tlv_len, tlv_value_offset;
124 int tlv_type;
125 proto_item *dsd_item;
126 proto_tree *dsd_tree;
127 proto_tree *tlv_tree = NULL;
128 tlv_info_t tlv_info;
130 { /* we are being asked for details */
131 /* Get the tvb reported length */
132 tvb_len = tvb_reported_length(tvb);
133 /* display MAC message type */
134 dsd_item = proto_tree_add_protocol_format(tree, proto_mac_mgmt_msg_dsd_decoder, tvb, offset, -1,
135 "Dynamic Service Deletion Response (DSD-RSP)");
136 /* add MAC DSx subtree */
137 dsd_tree = proto_item_add_subtree(dsd_item, ett_mac_mgmt_msg_dsd_rsp_decoder);
138 /* Decode and display the DSD message */
139 /* display the Transaction ID */
140 proto_tree_add_item(dsd_tree, hf_dsd_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
141 /* move to next field */
142 offset += 2;
143 /* display the Confirmation Code */
144 proto_tree_add_item(dsd_tree, hf_dsd_confirmation_code, tvb, offset, 1, ENC_BIG_ENDIAN);
145 /* move to next field */
146 offset++;
147 /* display the Service Flow ID */
148 proto_tree_add_item(dsd_tree, hf_dsd_service_flow_id, tvb, offset, 4, ENC_BIG_ENDIAN);
149 /* move to next field */
150 offset += 4;
151 /* process DSD RSP message TLV Encode Information */
152 while(offset < tvb_len)
153 { /* get the TLV information */
154 init_tlv_info(&tlv_info, tvb, offset);
155 /* get the TLV type */
156 tlv_type = get_tlv_type(&tlv_info);
157 /* get the TLV length */
158 tlv_len = get_tlv_length(&tlv_info);
159 if(tlv_type == -1 || tlv_len > MAX_TLV_LEN || tlv_len < 1)
160 { /* invalid tlv info */
161 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "DSD RSP TLV error");
162 proto_tree_add_item(dsd_tree, hf_dsd_invalid_tlv, tvb, offset, (tvb_len - offset), ENC_NA);
163 break;
165 /* get the TLV value offset */
166 tlv_value_offset = get_tlv_value_offset(&tlv_info);
167 #ifdef DEBUG /* for debug only */
168 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);
169 #endif
170 /* process TLV */
171 switch (tlv_type)
173 case HMAC_TUPLE: /* Table 348d */
174 /* decode and display the HMAC Tuple */
175 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");
176 wimax_hmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
177 break;
178 case CMAC_TUPLE: /* Table 348b */
179 /* decode and display the CMAC Tuple */
180 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");
181 wimax_cmac_tuple_decoder(tlv_tree, tvb, offset+tlv_value_offset, tlv_len);
182 break;
183 default:
184 add_tlv_subtree(&tlv_info, dsd_tree, hf_dsd_unknown_type, tvb, offset, ENC_NA);
185 break;
187 offset += (tlv_len+tlv_value_offset);
188 } /* end of while loop */
190 return tvb_captured_length(tvb);
193 /* Register Wimax Mac Payload Protocol and Dissector */
194 void proto_register_mac_mgmt_msg_dsd(void)
196 /* DSx display */
197 static hf_register_info hf[] =
200 &hf_dsd_confirmation_code,
202 "Confirmation code", "wmx.dsd.confirmation_code",
203 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
207 &hf_dsd_service_flow_id,
209 "Service Flow ID", "wmx.dsd.service_flow_id",
210 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL
214 &hf_dsd_transaction_id,
216 "Transaction ID", "wmx.dsd.transaction_id",
217 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL
221 &hf_dsd_invalid_tlv,
223 "Invalid TLV", "wmx.dsd.invalid_tlv",
224 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL
228 &hf_dsd_unknown_type,
230 "Unknown type", "wmx.dsd.unknown_type",
231 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL
236 /* Setup protocol subtree array */
237 static int *ett[] =
239 &ett_mac_mgmt_msg_dsd_req_decoder,
240 &ett_mac_mgmt_msg_dsd_rsp_decoder,
241 /* &ett_dsd_ul_sfe_decoder, */
242 /* &ett_dsd_dl_sfe_decoder, */
243 /* &ett_dsd_hmac_tuple, */
244 /* &ett_dsd_cmac_tuple, */
247 proto_mac_mgmt_msg_dsd_decoder = proto_register_protocol (
248 "WiMax DSD Messages", /* name */
249 "WiMax DSD", /* short name */
250 "wmx.dsd" /* abbrev */
253 proto_register_field_array(proto_mac_mgmt_msg_dsd_decoder, hf, array_length(hf));
254 proto_register_subtree_array(ett, array_length(ett));
256 dsd_req_handle = register_dissector("mac_mgmt_msg_dsd_req_handler", dissect_mac_mgmt_msg_dsd_req_decoder, proto_mac_mgmt_msg_dsd_decoder);
257 dsd_rsp_handle = register_dissector("mac_mgmt_msg_dsd_rsp_handler", dissect_mac_mgmt_msg_dsd_rsp_decoder, proto_mac_mgmt_msg_dsd_decoder);
260 void
261 proto_reg_handoff_mac_mgmt_msg_dsd(void)
263 dissector_add_uint("wmx.mgmtmsg", MAC_MGMT_MSG_DSD_REQ, dsd_req_handle);
264 dissector_add_uint("wmx.mgmtmsg", MAC_MGMT_MSG_DSD_RSP, dsd_rsp_handle);
269 * Editor modelines - https://www.wireshark.org/tools/modelines.html
271 * Local variables:
272 * c-basic-offset: 8
273 * tab-width: 8
274 * indent-tabs-mode: t
275 * End:
277 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
278 * :indentSize=8:tabSize=8:noTabs=false: