2 * Routines for Bluetooth BNEP dissection
4 * Copyright 2012, Michal Labedzki for Tieto Corporation
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <epan/packet.h>
30 #include <epan/prefs.h>
31 #include <epan/etypes.h>
32 #include <epan/expert.h>
34 #include "packet-btl2cap.h"
35 #include "packet-btsdp.h"
37 #define BNEP_TYPE_GENERAL_ETHERNET 0x00
38 #define BNEP_TYPE_CONTROL 0x01
39 #define BNEP_TYPE_COMPRESSED_ETHERNET 0x02
40 #define BNEP_TYPE_COMPRESSED_ETHERNET_SOURCE_ONLY 0x03
41 #define BNEP_TYPE_COMPRESSED_ETHERNET_DESTINATION_ONLY 0x04
42 #define RESERVED_802 0x7F
44 static int proto_btbnep
= -1;
45 static int hf_btbnep_bnep_type
= -1;
46 static int hf_btbnep_extension_flag
= -1;
47 static int hf_btbnep_extension_type
= -1;
48 static int hf_btbnep_extension_length
= -1;
49 static int hf_btbnep_dst
= -1;
50 static int hf_btbnep_src
= -1;
51 static int hf_btbnep_type
= -1;
52 static int hf_btbnep_addr
= -1;
53 static int hf_btbnep_lg
= -1;
54 static int hf_btbnep_ig
= -1;
55 static int hf_btbnep_control_type
= -1;
56 static int hf_btbnep_unknown_control_type
= -1;
57 static int hf_btbnep_uuid_size
= -1;
58 static int hf_btbnep_destination_service_uuid
= -1;
59 static int hf_btbnep_source_service_uuid
= -1;
60 static int hf_btbnep_setup_connection_response_message
= -1;
61 static int hf_btbnep_filter_net_type_response_message
= -1;
62 static int hf_btbnep_filter_multi_addr_response_message
= -1;
63 static int hf_btbnep_list_length
= -1;
64 static int hf_btbnep_network_type_start
= -1;
65 static int hf_btbnep_network_type_end
= -1;
66 static int hf_btbnep_multicast_address_start
= -1;
67 static int hf_btbnep_multicast_address_end
= -1;
69 static gint ett_btbnep
= -1;
70 static gint ett_addr
= -1;
72 static expert_field ei_btbnep_src_not_group_address
= EI_INIT
;
74 static gboolean top_dissect
= TRUE
;
76 static dissector_handle_t eth_handle
;
77 static dissector_handle_t data_handle
;
79 static const true_false_string ig_tfs
= {
80 "Group address (multicast/broadcast)",
81 "Individual address (unicast)"
84 static const true_false_string lg_tfs
= {
85 "Locally administered address (this is NOT the factory default)",
86 "Globally unique address (factory default)"
89 static const value_string bnep_type_vals
[] = {
90 { 0x00, "General Ethernet" },
92 { 0x02, "Compressed Ethernet" },
93 { 0x03, "Compressed Ethernet Source Only" },
94 { 0x04, "Compressed Ethernet Destination Only" },
95 { 0x7F, "Reserved for 802.2 LLC Packets for IEEE 802.15.1 WG" },
99 static const value_string control_type_vals
[] = {
100 { 0x00, "Command Not Understood" },
101 { 0x01, "Setup Connection Request" },
102 { 0x02, "Setup Connection Response" },
103 { 0x03, "Filter Net Type Set" },
104 { 0x04, "Filter Net Type Response" },
105 { 0x05, "Filter Multi Addr Set" },
106 { 0x06, "Filter Multi Addr Response" },
110 static const value_string extension_type_vals
[] = {
111 { 0x00, "Extension Control" },
115 static const value_string setup_connection_response_message_vals
[] = {
116 { 0x0000, "Operation Successful" },
117 { 0x0001, "Operation FAIL: Invalid Destination Service UUID" },
118 { 0x0002, "Operation FAIL: Invalid Source Service UUID" },
119 { 0x0003, "Operation FAIL: Invalid Service UUID Size" },
120 { 0x0004, "Operation FAIL: Connection Not Allowed" },
124 static const value_string filter_net_type_response_message_vals
[] = {
125 { 0x0000, "Operation Successful" },
126 { 0x0001, "Unsupported Request" },
127 { 0x0002, "Operation FAIL: Invalid Networking Protocol Type Range" },
128 { 0x0003, "Operation FAIL: Too many filters" },
129 { 0x0004, "Operation FAIL: Unable to fulfill request due to security reasons" },
133 static const value_string filter_multi_addr_response_message_vals
[] = {
134 { 0x0000, "Operation Successful" },
135 { 0x0001, "Unsupported Request" },
136 { 0x0002, "Operation FAIL: Invalid Multicast Address" },
137 { 0x0003, "Operation FAIL: Too many filters" },
138 { 0x0004, "Operation FAIL: Unable to fulfill request due to security reasons" },
142 void proto_register_btbnep(void);
143 void proto_reg_handoff_btbnep(void);
146 dissect_control(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, int offset
)
148 proto_item
*pitem
= NULL
;
150 guint8 unknown_control_type
;
154 guint16 response_message
;
158 proto_tree_add_item(tree
, hf_btbnep_control_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
159 control_type
= tvb_get_guint8(tvb
, offset
);
162 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s", val_to_str_const(control_type
, control_type_vals
, "Unknown type"));
164 switch(control_type
) {
165 case 0x00: /* Command Not Understood */
166 proto_tree_add_item(tree
, hf_btbnep_unknown_control_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
167 unknown_control_type
= tvb_get_guint8(tvb
, offset
);
170 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - Unknown(%s)", val_to_str_const(unknown_control_type
, control_type_vals
, "Unknown type"));
173 case 0x01: /* Setup Connection Request */
174 proto_tree_add_item(tree
, hf_btbnep_uuid_size
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
175 uuid_size
= tvb_get_guint8(tvb
, offset
);
178 pitem
= proto_tree_add_item(tree
, hf_btbnep_destination_service_uuid
, tvb
, offset
, uuid_size
, ENC_NA
);
179 uuid_dst
= tvb_get_ntohs(tvb
, offset
);
180 proto_item_append_text(pitem
, " (%s)", val_to_str_ext(uuid_dst
, &vs_service_classes_ext
, "Unknown uuid"));
183 pitem
= proto_tree_add_item(tree
, hf_btbnep_source_service_uuid
, tvb
, offset
, uuid_size
, ENC_NA
);
184 uuid_src
= tvb_get_ntohs(tvb
, offset
);
185 proto_item_append_text(pitem
, " (%s)", val_to_str_ext(uuid_src
, &vs_service_classes_ext
, "Unknown uuid"));
188 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - dst: <%s>, src: <%s>",
189 val_to_str_ext(uuid_dst
, &vs_service_classes_ext
, "Unknown uuid"),
190 val_to_str_ext(uuid_src
, &vs_service_classes_ext
, "Unknown uuid"));
192 case 0x02: /* Setup Connection Response */
193 proto_tree_add_item(tree
, hf_btbnep_setup_connection_response_message
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
194 response_message
= tvb_get_ntohs(tvb
, offset
);
196 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s",
197 val_to_str_const(response_message
, setup_connection_response_message_vals
, "Unknown response message"));
199 case 0x03: /* Filter Net Type Set */
200 proto_tree_add_item(tree
, hf_btbnep_list_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
201 list_length
= tvb_get_ntohs(tvb
, offset
);
204 for (i_item
= 0; i_item
< list_length
; i_item
+= 4) {
205 proto_tree_add_item(tree
, hf_btbnep_network_type_start
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
208 proto_tree_add_item(tree
, hf_btbnep_network_type_end
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
212 case 0x04: /* Filter Net Type Response */
213 proto_tree_add_item(tree
, hf_btbnep_filter_net_type_response_message
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
214 response_message
= tvb_get_ntohs(tvb
, offset
);
216 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s",
217 val_to_str_const(response_message
, filter_net_type_response_message_vals
, "Unknown response message"));
219 case 0x05: /*Filter Multi Addr Set*/
220 proto_tree_add_item(tree
, hf_btbnep_list_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
221 list_length
= tvb_get_ntohs(tvb
, offset
);
224 for (i_item
= 0; i_item
< list_length
; i_item
+= 12) {
225 proto_tree_add_item(tree
, hf_btbnep_multicast_address_start
, tvb
, offset
, 6, ENC_NA
);
228 proto_tree_add_item(tree
, hf_btbnep_multicast_address_end
, tvb
, offset
, 6, ENC_NA
);
232 case 0x06: /* Filter Multi Addr Response */
233 proto_tree_add_item(tree
, hf_btbnep_filter_multi_addr_response_message
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
234 response_message
= tvb_get_ntohs(tvb
, offset
);
236 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s",
237 val_to_str_const(response_message
, filter_multi_addr_response_message_vals
, "Unknown response message"));
246 dissect_extension(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, int offset
)
248 guint8 extension_flag
;
249 guint8 extension_type
;
250 guint16 extension_length
;
253 proto_tree_add_item(tree
, hf_btbnep_extension_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
254 proto_tree_add_item(tree
, hf_btbnep_extension_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
255 type
= tvb_get_guint8(tvb
, offset
);
256 extension_flag
= type
& 0x01;
257 extension_type
= type
>> 1;
260 proto_tree_add_item(tree
, hf_btbnep_extension_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
261 extension_length
= tvb_get_ntohs(tvb
, offset
);
264 if (extension_type
== 0x00) {
265 /* Extension Control */
266 offset
= dissect_control(tvb
, pinfo
, tree
, offset
);
268 offset
+= extension_length
;
271 if (extension_flag
) offset
= dissect_extension(tvb
, pinfo
, tree
, offset
);
277 dissect_btbnep(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
280 proto_tree
*btbnep_tree
;
283 guint extension_flag
;
285 proto_item
*addr_item
;
286 proto_tree
*addr_tree
= NULL
;
287 const guint8
*src_addr
;
288 const guint8
*dst_addr
;
290 pi
= proto_tree_add_item(tree
, proto_btbnep
, tvb
, offset
, -1, ENC_NA
);
291 btbnep_tree
= proto_item_add_subtree(pi
, ett_btbnep
);
293 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "BNEP");
294 col_clear(pinfo
->cinfo
, COL_INFO
);
296 switch (pinfo
->p2p_dir
) {
298 col_set_str(pinfo
->cinfo
, COL_INFO
, "Sent ");
301 col_set_str(pinfo
->cinfo
, COL_INFO
, "Rcvd ");
304 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unknown direction %d ",
309 proto_tree_add_item(btbnep_tree
, hf_btbnep_extension_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
310 proto_tree_add_item(btbnep_tree
, hf_btbnep_bnep_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
311 bnep_type
= tvb_get_guint8(tvb
, offset
);
312 extension_flag
= bnep_type
& 0x80;
313 bnep_type
= bnep_type
& 0x7F;
316 col_append_str(pinfo
->cinfo
, COL_INFO
, val_to_str_const(bnep_type
, bnep_type_vals
, "Unknown type"));
317 if (extension_flag
) col_append_str(pinfo
->cinfo
, COL_INFO
, "+E");
319 if (bnep_type
== BNEP_TYPE_GENERAL_ETHERNET
|| bnep_type
== BNEP_TYPE_COMPRESSED_ETHERNET_DESTINATION_ONLY
) {
320 dst_addr
= tvb_get_ptr(tvb
, offset
, 6);
321 SET_ADDRESS(&pinfo
->dl_dst
, AT_ETHER
, 6, dst_addr
);
322 SET_ADDRESS(&pinfo
->dst
, AT_ETHER
, 6, dst_addr
);
324 addr_item
= proto_tree_add_ether(btbnep_tree
, hf_btbnep_dst
, tvb
, offset
, 6, dst_addr
);
325 if (addr_item
) addr_tree
= proto_item_add_subtree(addr_item
, ett_addr
);
326 proto_tree_add_ether(addr_tree
, hf_btbnep_addr
, tvb
, offset
, 6, dst_addr
);
327 proto_tree_add_item(addr_tree
, hf_btbnep_lg
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
328 proto_tree_add_item(addr_tree
, hf_btbnep_ig
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
332 if (bnep_type
== BNEP_TYPE_GENERAL_ETHERNET
|| bnep_type
== BNEP_TYPE_COMPRESSED_ETHERNET_SOURCE_ONLY
) {
333 src_addr
= tvb_get_ptr(tvb
, offset
, 6);
334 SET_ADDRESS(&pinfo
->dl_src
, AT_ETHER
, 6, src_addr
);
335 SET_ADDRESS(&pinfo
->src
, AT_ETHER
, 6, src_addr
);
338 addr_item
= proto_tree_add_ether(btbnep_tree
, hf_btbnep_src
, tvb
, offset
, 6, src_addr
);
340 addr_tree
= proto_item_add_subtree(addr_item
, ett_addr
);
341 if (tvb_get_guint8(tvb
, offset
) & 0x01) {
342 expert_add_info(pinfo
, addr_item
, &ei_btbnep_src_not_group_address
);
345 proto_tree_add_ether(addr_tree
, hf_btbnep_addr
, tvb
, offset
, 6, src_addr
);
346 proto_tree_add_item(addr_tree
, hf_btbnep_lg
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
347 proto_tree_add_item(addr_tree
, hf_btbnep_ig
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
351 if (bnep_type
!= BNEP_TYPE_CONTROL
) {
352 type
= tvb_get_ntohs(tvb
, offset
);
354 proto_tree_add_item(btbnep_tree
, hf_btbnep_type
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
355 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - Type: %s", val_to_str_const(type
, etype_vals
, "unknown"));
359 offset
= dissect_control(tvb
, pinfo
, btbnep_tree
, offset
);
362 if (extension_flag
) {
363 offset
= dissect_extension(tvb
, pinfo
, btbnep_tree
, offset
);
366 if (bnep_type
!= BNEP_TYPE_CONTROL
) {
367 /* dissect normal network */
369 ethertype(type
, tvb
, offset
, pinfo
, tree
, btbnep_tree
,
370 hf_btbnep_type
, 0, 0);
374 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
375 call_dissector(data_handle
, next_tvb
, pinfo
, tree
);
383 proto_register_btbnep(void)
386 expert_module_t
* expert_btbnep
;
388 static hf_register_info hf
[] = {
389 { &hf_btbnep_bnep_type
,
390 { "BNEP Type", "btbnep.bnep_type",
391 FT_UINT8
, BASE_HEX
, VALS(bnep_type_vals
), 0x7F,
394 { &hf_btbnep_extension_flag
,
395 { "Extension Flag", "btbnep.extension_flag",
396 FT_BOOLEAN
, 8, NULL
, 0x80,
399 { &hf_btbnep_control_type
,
400 { "Control Type", "btbnep.control_type",
401 FT_UINT8
, BASE_HEX
, VALS(control_type_vals
), 0x00,
404 { &hf_btbnep_extension_type
,
405 { "Extension Type", "btbnep.extension_type",
406 FT_UINT8
, BASE_HEX
, VALS(extension_type_vals
), 0x00,
409 { &hf_btbnep_extension_length
,
410 { "Extension Length", "btbnep.extension_length",
411 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
414 { &hf_btbnep_unknown_control_type
,
415 { "Unknown Control Type", "btbnep.uknown_control_type",
416 FT_UINT8
, BASE_HEX
, VALS(control_type_vals
), 0x00,
419 { &hf_btbnep_uuid_size
,
420 { "UIDD Size", "btbnep.uuid_size",
421 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
424 { &hf_btbnep_destination_service_uuid
,
425 { "Destination Service UUID", "btbnep.destination_service_uuid",
426 FT_NONE
, BASE_NONE
, NULL
, 0x00,
429 { &hf_btbnep_source_service_uuid
,
430 { "Source Service UUID", "btbnep.source_service_uuid",
431 FT_NONE
, BASE_NONE
, NULL
, 0x00,
434 { &hf_btbnep_setup_connection_response_message
,
435 { "Response Message", "btbnep.setup_connection_response_message",
436 FT_UINT16
, BASE_HEX
, VALS(setup_connection_response_message_vals
), 0x00,
439 { &hf_btbnep_filter_net_type_response_message
,
440 { "Response Message", "btbnep.filter_net_type_response_message",
441 FT_UINT16
, BASE_HEX
, VALS(filter_net_type_response_message_vals
), 0x00,
444 { &hf_btbnep_filter_multi_addr_response_message
,
445 { "Response Message", "btbnep.filter_multi_addr_response_message",
446 FT_UINT16
, BASE_HEX
, VALS(filter_multi_addr_response_message_vals
), 0x00,
449 { &hf_btbnep_list_length
,
450 { "List Length", "btbnep.list_length",
451 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
454 /* http://www.iana.org/assignments/ethernet-numbers */
455 { &hf_btbnep_network_type_start
,
456 { "Network Protocol Type Range Start", "btbnep.network_type_start",
457 FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x00,
460 { &hf_btbnep_network_type_end
,
461 { "Network Protocol Type Range End", "btbnep.network_type_end",
462 FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x00,
465 { &hf_btbnep_multicast_address_start
,
466 { "Multicast Address Start", "btbnep.multicast_address_start",
467 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
470 { &hf_btbnep_multicast_address_end
,
471 { "Multicast Address End", "btbnep.multicast_address_end",
472 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
476 { "Destination", "btbnep.dst",
477 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
478 "Destination Hardware Address", HFILL
}
481 { "Source", "btbnep.src",
482 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
483 "Source Hardware Address", HFILL
}
486 { "Type", "btbnep.type",
487 FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x0,
491 { "Address", "btbnep.addr",
492 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
493 "Source or Destination Hardware Address", HFILL
}
496 { "LG bit", "btbnep.lg",
497 FT_BOOLEAN
, 24, TFS(&lg_tfs
), 0x020000,
498 "Specifies if this is a locally administered or globally unique (IEEE assigned) address", HFILL
}
501 { "IG bit", "btbnep.ig",
502 FT_BOOLEAN
, 24, TFS(&ig_tfs
), 0x010000,
503 "Specifies if this is an individual (unicast) or group (broadcast/multicast) address", HFILL
}
507 static gint
*ett
[] = {
512 static ei_register_info ei
[] = {
513 { &ei_btbnep_src_not_group_address
, { "btbnep.src.not_group_address", PI_PROTOCOL
, PI_WARN
, "Source MAC must not be a group address: IEEE 802.3-2002, Section 3.2.3(b)", EXPFILL
}},
516 proto_btbnep
= proto_register_protocol("Bluetooth BNEP Protocol", "BT BNEP", "btbnep");
517 new_register_dissector("btbnep", dissect_btbnep
, proto_btbnep
);
519 proto_register_field_array(proto_btbnep
, hf
, array_length(hf
));
520 proto_register_subtree_array(ett
, array_length(ett
));
521 expert_btbnep
= expert_register_protocol(proto_btbnep
);
522 expert_register_field_array(expert_btbnep
, ei
, array_length(ei
));
524 module
= prefs_register_protocol(proto_btbnep
, NULL
);
525 prefs_register_static_text_preference(module
, "bnep.version",
526 "Bluetooth Protocol BNEP version: 1.0",
527 "Version of protocol supported by this dissector.");
529 prefs_register_bool_preference(module
, "bnep.top_dissect",
530 "Dissecting the top protocols", "Dissecting the top protocols",
535 proto_reg_handoff_btbnep(void)
537 dissector_handle_t btbnep_handle
;
539 btbnep_handle
= find_dissector("btbnep");
540 eth_handle
= find_dissector("eth");
541 data_handle
= find_dissector("data");
543 dissector_add_uint("btl2cap.service", BTSDP_PAN_GN_SERVICE_UUID
, btbnep_handle
);
544 dissector_add_uint("btl2cap.service", BTSDP_PAN_NAP_SERVICE_UUID
, btbnep_handle
);
545 dissector_add_uint("btl2cap.service", BTSDP_PAN_GN_SERVICE_UUID
, btbnep_handle
);
547 dissector_add_uint("btl2cap.psm", BTL2CAP_PSM_BNEP
, btbnep_handle
);
548 dissector_add_handle("btl2cap.cid", btbnep_handle
);
552 * Editor modelines - http://www.wireshark.org/tools/modelines.html
557 * indent-tabs-mode: nil
560 * vi: set shiftwidth=4 tabstop=8 expandtab:
561 * :indentSize=4:tabSize=8:noTabs=true: