Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-bt3ds.c
blobd955b9b3216f1965bccbef7aa770ab3d9da9f990
1 /* packet-bt3ds.c
2 * Routines for Bluetooth 3DS dissection
4 * Copyright 2013, Michal Labedzki for Tieto Corporation
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/prefs.h>
17 #include <epan/expert.h>
19 #include "packet-btl2cap.h"
20 #include "packet-btsdp.h"
22 static int proto_bt3ds;
24 static int hf_message_opcode;
25 static int hf_association_notification;
26 static int hf_user_request_for_battery_level_display;
27 static int hf_reserved;
28 static int hf_battery_level;
30 static expert_field ei_message_opcode_reserved;
31 static expert_field ei_reserved;
32 static expert_field ei_battery_level_reserved;
33 static expert_field ei_unexpected_data;
35 static int ett_bt3ds;
37 static dissector_handle_t b3ds_handle;
39 static const value_string message_opcode_vals[] = {
40 { 0x00, "3DG Connection Announcement" },
41 { 0, NULL }
44 void proto_register_bt3ds(void);
45 void proto_reg_handoff_bt3ds(void);
47 static int
48 dissect_bt3ds(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
50 proto_item *main_item;
51 proto_tree *main_tree;
52 proto_item *sub_item;
53 int offset = 0;
54 uint8_t value;
56 main_item = proto_tree_add_item(tree, proto_bt3ds, tvb, offset, -1, ENC_NA);
57 main_tree = proto_item_add_subtree(main_item, ett_bt3ds);
59 col_set_str(pinfo->cinfo, COL_PROTOCOL, "3DS");
61 switch (pinfo->p2p_dir) {
62 case P2P_DIR_SENT:
63 col_set_str(pinfo->cinfo, COL_INFO, "Sent ");
64 break;
65 case P2P_DIR_RECV:
66 col_set_str(pinfo->cinfo, COL_INFO, "Rcvd ");
67 break;
68 default:
69 col_set_str(pinfo->cinfo, COL_INFO, "UnknownDirection ");
70 break;
73 sub_item = proto_tree_add_item(main_tree, hf_message_opcode, tvb, offset, 1, ENC_BIG_ENDIAN);
74 value = tvb_get_uint8(tvb, offset);
75 if (value > 0)
76 expert_add_info(pinfo, sub_item, &ei_message_opcode_reserved);
77 offset += 1;
79 col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(value, message_opcode_vals, "Unknown"));
81 sub_item = proto_tree_add_item(main_tree, hf_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
82 proto_tree_add_item(main_tree, hf_user_request_for_battery_level_display, tvb, offset, 1, ENC_BIG_ENDIAN);
83 proto_tree_add_item(main_tree, hf_association_notification, tvb, offset, 1, ENC_BIG_ENDIAN);
84 value = tvb_get_uint8(tvb, offset) >> 2;
85 if (value != 0)
86 expert_add_info(pinfo, sub_item, &ei_reserved);
87 offset += 1;
89 sub_item = proto_tree_add_item(main_tree, hf_battery_level, tvb, offset, 1, ENC_BIG_ENDIAN);
90 value = tvb_get_uint8(tvb, offset);
91 if (value >= 101 && value <= 254)
92 expert_add_info(pinfo, sub_item, &ei_battery_level_reserved);
93 else if (value == 255)
94 proto_item_append_text(sub_item, "Battery Level Reporting Not Supported");
96 offset += 1;
98 if (tvb_reported_length_remaining(tvb, offset) > 0) {
99 proto_tree_add_expert(main_tree, pinfo, &ei_unexpected_data, tvb, offset, -1);
100 offset += tvb_reported_length_remaining(tvb, offset);
103 return offset;
107 void
108 proto_register_bt3ds(void)
110 module_t *module;
111 expert_module_t *expert_bt3ds;
113 static ei_register_info ei[] = {
114 { &ei_message_opcode_reserved, { "bt3ds.expert.message_opcode.reserved", PI_PROTOCOL, PI_NOTE, "Value is reserved", EXPFILL }},
115 { &ei_reserved, { "bt3ds.expert.reserved", PI_PROTOCOL, PI_NOTE, "Value is reserved", EXPFILL }},
116 { &ei_battery_level_reserved, { "bt3ds.expert.battery_level.reserved", PI_PROTOCOL, PI_NOTE, "Value is reserved", EXPFILL }},
117 { &ei_unexpected_data, { "bt3ds.expert.unexpected_data", PI_PROTOCOL, PI_WARN, "Unexpected data", EXPFILL }}
120 static hf_register_info hf[] = {
121 { &hf_message_opcode,
122 { "Message Opcode", "bt3ds.message_opcode",
123 FT_UINT8, BASE_HEX, VALS(message_opcode_vals), 0x00,
124 NULL, HFILL }
126 { &hf_association_notification,
127 { "Association Notification", "bt3ds.association_notification",
128 FT_BOOLEAN, 8, NULL, 0x01,
129 NULL, HFILL }
131 { &hf_user_request_for_battery_level_display,
132 { "User Request for Battery Level Display", "bt3ds.user_request_for_battery_level_display",
133 FT_BOOLEAN, 8, NULL, 0x02,
134 NULL, HFILL }
136 { &hf_reserved,
137 { "Reserved", "bt3ds.reserved",
138 FT_UINT8, BASE_HEX, NULL, 0xFC,
139 NULL, HFILL }
141 { &hf_battery_level,
142 { "Battery Level", "bt3ds.battery_level",
143 FT_UINT8, BASE_DEC, NULL, 0x00,
144 "0-100% of current charge level of battery", HFILL }
148 static int *ett[] = {
149 &ett_bt3ds
152 proto_bt3ds = proto_register_protocol("Bluetooth 3DS Profile", "BT 3DS", "bt3ds");
153 b3ds_handle = register_dissector("bt3ds", dissect_bt3ds, proto_bt3ds);
155 proto_register_field_array(proto_bt3ds, hf, array_length(hf));
156 proto_register_subtree_array(ett, array_length(ett));
158 expert_bt3ds = expert_register_protocol(proto_bt3ds);
159 expert_register_field_array(expert_bt3ds, ei, array_length(ei));
161 module = prefs_register_protocol_subtree("Bluetooth", proto_bt3ds, NULL);
162 prefs_register_static_text_preference(module, "3ds.version",
163 "Bluetooth Profile 3DS version: 1.0",
164 "Version of profile supported by this dissector.");
168 void
169 proto_reg_handoff_bt3ds(void)
171 dissector_add_string("bluetooth.uuid", "1137", b3ds_handle);
172 dissector_add_string("bluetooth.uuid", "1138", b3ds_handle);
173 dissector_add_string("bluetooth.uuid", "1139", b3ds_handle);
175 dissector_add_uint("btl2cap.psm", BTL2CAP_PSM_3DS, b3ds_handle);
176 dissector_add_for_decode_as("btl2cap.cid", b3ds_handle);
180 * Editor modelines - https://www.wireshark.org/tools/modelines.html
182 * Local variables:
183 * c-basic-offset: 4
184 * tab-width: 8
185 * indent-tabs-mode: nil
186 * End:
188 * vi: set shiftwidth=4 tabstop=8 expandtab:
189 * :indentSize=4:tabSize=8:noTabs=true: