Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mdp.c
blobcc149df2aa5e38a8f2b77c88e30f70098dc27d47
1 /* packet-mdp.c
2 * Routines for the disassembly of the "Meraki Discovery Protocol (MDP)"
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
12 #include <epan/packet.h>
14 #define MDP_TLV_TYPE 0
15 #define MDP_TLV_LENGTH 1
16 #define MDP_TLV_DEVICE_INFO 2
17 #define MDP_TLV_NETWORK_INFO 3
18 #define MDP_TLV_LONGITUDE 4
19 #define MDP_TLV_LATITUDE 5
20 #define MDP_TLV_TYPE_SIX 6
21 #define MDP_TLV_TYPE_SEVEN 7
22 #define MDP_TLV_END 255
24 void proto_register_mdp(void);
25 void proto_reg_handoff_mdp(void);
27 static int proto_mdp;
28 static int hf_mdp_preamble_data;
29 static int hf_mdp_device_info;
30 static int hf_mdp_network_info;
31 static int hf_mdp_type;
32 static int hf_mdp_length;
33 static int hf_mdp_longitude;
34 static int hf_mdp_latitude;
35 static int hf_mdp_type_six;
36 static int hf_mdp_type_seven;
37 static int hf_mdp_data;
39 static int ett_mdp;
40 static int ett_mdp_tlv;
42 static dissector_handle_t mdp_handle;
44 /* Format Identifier */
45 static const value_string type_vals[] = {
46 { MDP_TLV_DEVICE_INFO, "Device Info" },
47 { MDP_TLV_NETWORK_INFO, "Network Info" },
48 { MDP_TLV_LONGITUDE, "Longitude" },
49 { MDP_TLV_LATITUDE, "Latitude" },
50 { MDP_TLV_TYPE_SIX, "Type 6 UID" },
51 { MDP_TLV_TYPE_SEVEN, "Type 7 UID" },
52 { MDP_TLV_END, "End" },
53 { 0, NULL }
56 static int
57 dissect_mdp(tvbuff_t *mdp_tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
59 proto_tree *mdp_tree, *tlv_tree;
60 proto_item *mdp_item, *tlv_item;
61 uint32_t mdp_type, mdp_length;
62 int offset = 0;
64 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MDP");
65 col_set_str(pinfo->cinfo, COL_INFO, "MDP");
67 mdp_item = proto_tree_add_item(tree, proto_mdp, mdp_tvb, 0, -1, ENC_NA);
68 mdp_tree = proto_item_add_subtree(mdp_item, ett_mdp);
70 proto_tree_add_item(mdp_tree, hf_mdp_preamble_data, mdp_tvb, 0, 28, ENC_NA);
71 offset += 28;
73 while(tvb_reported_length_remaining(mdp_tvb, offset) != 0){
74 tlv_tree = proto_tree_add_subtree(mdp_tree, mdp_tvb, offset + MDP_TLV_TYPE, -1, ett_mdp_tlv, &tlv_item, "");
75 proto_tree_add_item_ret_uint(tlv_tree, hf_mdp_type, mdp_tvb, offset + MDP_TLV_TYPE, 1, ENC_BIG_ENDIAN, &mdp_type);
76 proto_item_set_text(tlv_tree, "%s", val_to_str_const(mdp_type, type_vals, "Unknown type"));
77 proto_tree_add_item_ret_uint(tlv_tree, hf_mdp_length, mdp_tvb, offset + MDP_TLV_LENGTH, 1, ENC_BIG_ENDIAN, &mdp_length);
79 offset += 2;
81 switch(mdp_type){
82 case MDP_TLV_DEVICE_INFO:
83 proto_tree_add_item(tlv_tree, hf_mdp_device_info, mdp_tvb, offset, mdp_length, ENC_UTF_8 | ENC_NA);
84 break;
85 case MDP_TLV_NETWORK_INFO:
86 proto_tree_add_item(tlv_tree, hf_mdp_network_info, mdp_tvb, offset, mdp_length, ENC_UTF_8 | ENC_NA);
87 break;
88 case MDP_TLV_LONGITUDE:
89 proto_tree_add_item(tlv_tree, hf_mdp_longitude, mdp_tvb, offset, mdp_length, ENC_UTF_8 | ENC_NA);
90 break;
91 case MDP_TLV_LATITUDE:
92 proto_tree_add_item(tlv_tree, hf_mdp_latitude, mdp_tvb, offset, mdp_length, ENC_UTF_8 | ENC_NA);
93 break;
94 case MDP_TLV_TYPE_SIX:
95 proto_tree_add_item(tlv_tree, hf_mdp_type_six, mdp_tvb, offset, mdp_length, ENC_UTF_8 | ENC_NA);
96 break;
97 case MDP_TLV_TYPE_SEVEN:
98 proto_tree_add_item(tlv_tree, hf_mdp_type_seven, mdp_tvb, offset, mdp_length, ENC_UTF_8 | ENC_NA);
99 break;
100 case MDP_TLV_END:
101 break;
102 default:
103 proto_tree_add_item(mdp_tree, hf_mdp_data, mdp_tvb, offset, mdp_length, ENC_NA);
104 break;
106 proto_item_set_len(tlv_item, mdp_length + 2);
107 offset += mdp_length;
109 return tvb_captured_length(mdp_tvb);
112 void
113 proto_register_mdp(void)
116 static hf_register_info hf[] = {
117 { &hf_mdp_preamble_data, {"Preamble Data","mdp.preamble_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
118 { &hf_mdp_device_info, {"Device Info", "mdp.device_info", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
119 { &hf_mdp_network_info, {"Network Info", "mdp.network_info", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
120 { &hf_mdp_longitude, {"Longitude", "mdp.longitude", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
121 { &hf_mdp_latitude, {"Latitude", "mdp.latitude", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
122 { &hf_mdp_type, {"Type", "mdp.type", FT_UINT8, BASE_DEC, VALS(type_vals), 0x0, NULL, HFILL }},
123 { &hf_mdp_type_six, {"Type 6 UID", "mdp.type_six", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
124 { &hf_mdp_type_seven, {"Type 7 UID", "mdp.type_seven", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
125 { &hf_mdp_length, {"Length", "mdp.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
126 { &hf_mdp_data, {"Unknown Data", "mdp.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}
129 static int *ett[] = {
130 &ett_mdp,
131 &ett_mdp_tlv
134 proto_mdp = proto_register_protocol("Meraki Discovery Protocol", "MDP", "mdp");
135 proto_register_field_array(proto_mdp, hf, array_length(hf));
136 proto_register_subtree_array(ett, array_length(ett));
138 mdp_handle = register_dissector("mdp", dissect_mdp, proto_mdp);
141 void
142 proto_reg_handoff_mdp(void)
144 dissector_add_uint("ethertype", 0x0712, mdp_handle);
145 dissector_add_uint("ethertype", 0x0713, mdp_handle);
149 * Editor modelines - https://www.wireshark.org/tools/modelines.html
151 * Local variables:
152 * c-basic-offset: 4
153 * tab-width: 8
154 * indent-tabs-mode: nil
155 * End:
157 * vi: set shiftwidth=4 tabstop=8 expandtab:
158 * :indentSize=4:tabSize=8:noTabs=true: