xref: /libbtbb/wireshark/plugins/btbredr/packet-btbredr.c (revision 25d64f63a355f4c01d10cf4f69da1c2246b040d9)
1 /* packet-btbredr.c
2  * Routines for Bluetooth baseband dissection
3  * Copyright 2014, Dominic Spill <[email protected]>
4  * Copyright 2009, Michael Ossmann <[email protected]>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <[email protected]>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23  */
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #else
28 #include <wireshark/config.h>
29 #endif
30 
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 
34 #include <stdio.h>
35 
36 /* function prototypes */
37 void proto_reg_handoff_btbredr(void);
38 
39 /* initialize the protocol and registered fields */
40 static int proto_btbredr = -1;
41 static int hf_btbredr_meta = -1;
42 static int hf_btbredr_channel = -1;
43 static int hf_btbredr_signal = -1;
44 static int hf_btbredr_noise = -1;
45 static int hf_btbredr_ac_offenses = -1;
46 static int hf_btbredr_mod = -1;
47 static int hf_btbredr_transport = -1;
48 static int hf_btbredr_corrected_header = -1;
49 static int hf_btbredr_corrected_payload = -1;
50 static int hf_btbredr_lap = -1;
51 static int hf_btbredr_ref_lap = -1;
52 static int hf_btbredr_ref_uap = -1;
53 static int hf_btbredr_pkthdr = -1;
54 static int hf_btbredr_ltaddr = -1;
55 static int hf_btbredr_type = -1;
56 static int hf_btbredr_flags = -1;
57 static int hf_btbredr_flow = -1;
58 static int hf_btbredr_arqn = -1;
59 static int hf_btbredr_seqn = -1;
60 static int hf_btbredr_hec = -1;
61 static int hf_btbredr_payload = -1;
62 static int hf_btbredr_pldhdr = -1;
63 static int hf_btbredr_llid = -1;
64 static int hf_btbredr_pldflow = -1;
65 static int hf_btbredr_length = -1;
66 static int hf_btbredr_pldbody = -1;
67 static int hf_btbredr_crc = -1;
68 static int hf_btbredr_fhs_parity = -1;
69 static int hf_btbredr_fhs_lap = -1;
70 static int hf_btbredr_fhs_eir = -1;
71 static int hf_btbredr_fhs_sr = -1;
72 static int hf_btbredr_fhs_uap = -1;
73 static int hf_btbredr_fhs_nap = -1;
74 static int hf_btbredr_fhs_class = -1;
75 static int hf_btbredr_fhs_ltaddr = -1;
76 static int hf_btbredr_fhs_clk = -1;
77 static int hf_btbredr_fhs_psmode = -1;
78 
79 /* field values */
80 static const true_false_string direction = {
81 	"Slave to Master",
82 	"Master to Slave"
83 };
84 
85 static const true_false_string clock_bits = {
86 	"27",
87 	"6"
88 };
89 
90 static const true_false_string valid_flags = {
91 	"Invalid",
92 	"Valid"
93 };
94 
95 static const value_string modulation[] = {
96     { 0x0, "Basic Rate (GFSK)" },
97     { 0x1, "Enhanced Data Rate (PI/2-DQPSK)" },
98     { 0x2, "Enhanced Data Rate (8DPSK)" }
99 };
100 
101 static const value_string transports[] = {
102     { 0x0, "unknown" },
103     { 0x1, "SCO" },
104     { 0x2, "eSCO" },
105     { 0x3, "ACL" },
106     { 0x4, "CSB" }
107 };
108 
109 static const value_string packet_types[] = {
110 	/* generic names for unknown logical transport */
111 	{ 0x0, "NULL" },
112 	{ 0x1, "POLL" },
113 	{ 0x2, "FHS" },
114 	{ 0x3, "DM1" },
115 	{ 0x4, "DH1/2-DH1" },
116 	{ 0x5, "HV1" },
117 	{ 0x6, "HV2/2-EV3" },
118 	{ 0x7, "HV3/EV3/3-EV3" },
119 	{ 0x8, "DV/3-DH1" },
120 	{ 0x9, "AUX1" },
121 	{ 0xa, "DM3/2-DH3" },
122 	{ 0xb, "DH3/3-DH3" },
123 	{ 0xc, "EV4/2-EV5" },
124 	{ 0xd, "EV5/3-EV5" },
125 	{ 0xe, "DM5/2-DH5" },
126 	{ 0xf, "DH5/3-DH5" },
127 	{ 0, NULL }
128 };
129 
130 static const value_string sr_modes[] = {
131 	{ 0x0, "R0" },
132 	{ 0x1, "R1" },
133 	{ 0x2, "R2" },
134 	{ 0x3, "Reserved" },
135 	{ 0, NULL }
136 };
137 
138 static const range_string ps_modes[] = {
139 	{ 0x0, 0x0, "Mandatory scan mode" },
140 	{ 0x1, 0x7, "Reserved" },
141 	{ 0, 0, NULL }
142 };
143 
144 static const value_string llid_codes[] = {
145 	{ 0x0, "undefined" },
146 	{ 0x1, "Continuation fragment of an L2CAP message (ACL-U)" },
147 	{ 0x2, "Start of an L2CAP message or no fragmentation (ACL-U)" },
148 	{ 0x3, "LMP message (ACL-C)" },
149 	{ 0, NULL }
150 };
151 
152 /* initialize the subtree pointers */
153 static gint ett_btbredr = -1;
154 static gint ett_btbredr_meta = -1;
155 static gint ett_btbredr_pkthdr = -1;
156 static gint ett_btbredr_flags = -1;
157 static gint ett_btbredr_payload = -1;
158 static gint ett_btbredr_pldhdr = -1;
159 
160 /* subdissectors */
161 static dissector_handle_t btlmp_handle = NULL;
162 static dissector_handle_t btl2cap_handle = NULL;
163 
164 /* packet header flags */
165 static const int *flag_fields[] = {
166 	&hf_btbredr_flow,
167 	&hf_btbredr_arqn,
168 	&hf_btbredr_seqn,
169 	NULL
170 };
171 
172 /* one byte payload header */
173 int
174 dissect_payload_header1(proto_tree *tree, tvbuff_t *tvb, int offset)
175 {
176 	proto_item *hdr_item;
177 	proto_tree *hdr_tree;
178 
179 	DISSECTOR_ASSERT(tvb_reported_length_remaining(tvb, offset) >= 1);
180 
181 	hdr_item = proto_tree_add_item(tree, hf_btbredr_pldhdr, tvb, offset, 1, ENC_NA);
182 	hdr_tree = proto_item_add_subtree(hdr_item, ett_btbredr_pldhdr);
183 
184 	proto_tree_add_item(hdr_tree, hf_btbredr_llid, tvb, offset, 1, ENC_NA);
185 	proto_tree_add_item(hdr_tree, hf_btbredr_pldflow, tvb, offset, 1, ENC_NA);
186 	proto_tree_add_item(hdr_tree, hf_btbredr_length, tvb, offset, 1, ENC_NA);
187 
188 	/* payload length */
189 	return tvb_get_guint8(tvb, offset) >> 3;
190 }
191 
192 void
193 dissect_fhs(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
194 {
195 	proto_item *fhs_item, *psmode_item;
196 	proto_tree *fhs_tree;
197     const gchar *description;
198 	guint8 psmode;
199 
200 	if(tvb_reported_length_remaining(tvb, offset) != 20) {
201 		col_add_str(pinfo->cinfo, COL_INFO, "Encrypted or malformed payload data");
202 		return;
203 	}
204 
205 	fhs_item = proto_tree_add_item(tree, hf_btbredr_payload, tvb, offset, -1, ENC_NA);
206 	fhs_tree = proto_item_add_subtree(fhs_item, ett_btbredr_payload);
207 
208 	/* Use proto_tree_add_bits_item() to get around 32bit limit on bitmasks */
209 	proto_tree_add_bits_item(fhs_tree, hf_btbredr_fhs_parity, tvb, offset*8, 34, ENC_LITTLE_ENDIAN);
210 	/* proto_tree_add_item(fhs_tree, hf_btbredr_fhs_parity, tvb, offset, 5, ENC_LITTLE_ENDIAN); */
211 	offset += 4;
212 
213 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_lap, tvb, offset, 4, ENC_LITTLE_ENDIAN);
214 	offset += 3;
215 
216 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_eir, tvb, offset, 1, ENC_NA);
217 	/* skipping 1 undefined bit */
218 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_sr, tvb, offset, 1, ENC_NA);
219 	/* skipping 2 reserved bits */
220 	offset += 1;
221 
222 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_uap, tvb, offset, 1, ENC_NA);
223 	offset += 1;
224 
225 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_nap, tvb, offset, 2, ENC_LITTLE_ENDIAN);
226 	offset += 2;
227 
228 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_class, tvb, offset, 3, ENC_LITTLE_ENDIAN);
229 	offset += 3;
230 
231 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_ltaddr, tvb, offset, 1, ENC_NA);
232 	proto_tree_add_item(fhs_tree, hf_btbredr_fhs_clk, tvb, offset, 4, ENC_LITTLE_ENDIAN);
233 	offset += 3;
234 
235 	psmode = tvb_get_guint8(tvb, offset);
236 	description = try_rval_to_str(psmode, ps_modes);
237 	psmode_item = proto_tree_add_item(fhs_tree, hf_btbredr_fhs_psmode, tvb, offset, 1, ENC_NA);
238 	if (description)
239         proto_item_append_text(psmode_item, " (%s)", description);
240 	offset += 1;
241 
242 	proto_tree_add_item(fhs_tree, hf_btbredr_crc, tvb, offset, 2, ENC_LITTLE_ENDIAN);
243 	offset += 2;
244 }
245 
246 void
247 dissect_dm1(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, int offset)
248 {
249 	int len;	/* payload length indicated by payload header */
250 	int llid;	/* logical link id */
251 	int l2len;	/* length indicated by l2cap header */
252 	proto_item *dm1_item;
253 	proto_tree *dm1_tree;
254 	tvbuff_t *pld_tvb;
255 
256 	/*
257 	 * FIXME
258 	 * I'm probably doing a terrible, terrible thing here, but it gets my
259 	 * initial test cases working.
260 	 */
261 	guint16 fake_acl_data;
262 
263 	if(tvb_reported_length_remaining(tvb, offset) < 3) {
264 		col_add_str(pinfo->cinfo, COL_INFO, "Encrypted or malformed payload data");
265 		return;
266 	}
267 
268 	dm1_item = proto_tree_add_item(tree, hf_btbredr_payload, tvb, offset, -1, ENC_NA);
269 	dm1_tree = proto_item_add_subtree(dm1_item, ett_btbredr_payload);
270 
271 	len = dissect_payload_header1(dm1_tree, tvb, offset);
272 	llid = tvb_get_guint8(tvb, offset) & 0x3;
273 	offset += 1;
274 
275 	if(tvb_reported_length_remaining(tvb, offset) < len + 2) {
276 		col_add_str(pinfo->cinfo, COL_INFO, "Encrypted or malformed payload data");
277 		return;
278 	}
279 
280 	if (llid == 3 && btlmp_handle) {
281 		/* LMP */
282 		pld_tvb = tvb_new_subset(tvb, offset, len, len);
283 		call_dissector(btlmp_handle, pld_tvb, pinfo, dm1_tree);
284 	} else if (llid == 2 && btl2cap_handle) {
285 		/* unfragmented L2CAP or start of fragment */
286 		l2len = tvb_get_letohs(tvb, offset);
287 		if (l2len + 4 == len) {
288 			/* unfragmented */
289 			pld_tvb = tvb_new_subset(tvb, offset, len, len);
290 			call_dissector_with_data(btl2cap_handle, pld_tvb, pinfo, dm1_tree, &fake_acl_data);
291 		} else {
292 			/* start of fragment */
293 			proto_tree_add_item(dm1_tree, hf_btbredr_pldbody, tvb, offset, len, ENC_NA);
294 		}
295 	} else {
296 		proto_tree_add_item(dm1_tree, hf_btbredr_pldbody, tvb, offset, len, ENC_NA);
297 	}
298 	offset += len;
299 
300 	proto_tree_add_item(dm1_tree, hf_btbredr_crc, tvb, offset, 2, ENC_LITTLE_ENDIAN);
301 	offset += 2;
302 }
303 
304 /* dissect a packet */
305 static int
306 dissect_btbredr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
307 {
308 	proto_item *btbredr_item, *meta_item, *pkthdr_item;
309 	proto_tree *btbredr_tree, *meta_tree, *pkthdr_tree;
310 	int offset;
311 	/* Avoid error: 'type' may be used uninitialized in this function */
312 	guint8 type = 0xff;
313 	const gchar *info;
314 
315 	/* sanity check: length */
316 	if (tvb_reported_length(tvb) > 0 && tvb_reported_length(tvb) < 9)
317 		/* bad length: look for a different dissector */
318 		return 0;
319 
320 	/* maybe should verify HEC */
321 
322 	/* make entries in protocol column and info column on summary display */
323 	col_set_str(pinfo->cinfo, COL_PROTOCOL, "Bluetooth");
324 
325 	if (tvb_reported_length(tvb) == 0) {
326 		info = "ID";
327 	} else {
328 		type = (tvb_get_guint8(tvb, 16) >> 3) & 0x0f;
329 		info = val_to_str(type, packet_types, "Unknown type: 0x%x");
330 	}
331 
332 	col_clear(pinfo->cinfo, COL_INFO);
333 	col_add_str(pinfo->cinfo, COL_INFO, info);
334 
335 	/* see if we are being asked for details */
336 	if (tree) {
337 
338 		/* create display subtree for the protocol */
339 		offset = 0;
340 		btbredr_item = proto_tree_add_item(tree, proto_btbredr, tvb, offset, -1, ENC_NA);
341 		btbredr_tree = proto_item_add_subtree(btbredr_item, ett_btbredr);
342 
343 		/* ID packets have no header, no payload */
344 		if (tvb_reported_length(tvb) == 0)
345 			return 1;
346 
347 		/* meta data */
348 		meta_item = proto_tree_add_item(btbredr_tree, hf_btbredr_meta, tvb, offset, 3, ENC_NA);
349 		meta_tree = proto_item_add_subtree(meta_item, ett_btbredr_meta);
350 
351 		proto_tree_add_item(meta_tree, hf_btbredr_channel, tvb, offset, 1, ENC_NA);
352 		offset += 1;
353 		proto_tree_add_item(meta_tree, hf_btbredr_signal, tvb, offset, 1, ENC_NA);
354 		offset += 1;
355 		proto_tree_add_item(meta_tree, hf_btbredr_noise, tvb, offset, 1, ENC_NA);
356 		offset += 1;
357 		proto_tree_add_item(meta_tree, hf_btbredr_ac_offenses, tvb, offset, 1, ENC_NA);
358 		offset += 1;
359 
360 		proto_tree_add_item(meta_tree, hf_btbredr_mod, tvb, offset, 1, ENC_NA);
361 		proto_tree_add_item(meta_tree, hf_btbredr_transport, tvb, offset, 1, ENC_NA);
362 		offset += 1;
363 
364 		proto_tree_add_item(meta_tree, hf_btbredr_corrected_header, tvb, offset, 1, ENC_NA);
365 		offset += 1;
366 		proto_tree_add_item(meta_tree, hf_btbredr_corrected_payload, tvb, offset, 2, ENC_LITTLE_ENDIAN);
367 		offset += 2;
368 
369 		proto_tree_add_item(meta_tree, hf_btbredr_lap, tvb, offset, 4, ENC_LITTLE_ENDIAN);
370 		offset += 4;
371 		proto_tree_add_item(meta_tree, hf_btbredr_ref_lap, tvb, offset, 3, ENC_LITTLE_ENDIAN);
372 		offset += 3;
373 		proto_tree_add_item(meta_tree, hf_btbredr_ref_uap, tvb, offset, 1, ENC_NA);
374 		offset += 1;
375 
376 
377 		/* packet header */
378 		pkthdr_item = proto_tree_add_item(btbredr_tree, hf_btbredr_pkthdr, tvb, offset, 3, ENC_NA);
379 		pkthdr_tree = proto_item_add_subtree(pkthdr_item, ett_btbredr_pkthdr);
380 
381 		proto_tree_add_item(pkthdr_tree, hf_btbredr_ltaddr, tvb, offset, 1, ENC_NA);
382 		proto_tree_add_item(pkthdr_tree, hf_btbredr_type, tvb, offset, 1, ENC_NA);
383 		offset += 1;
384 		proto_tree_add_bitmask(pkthdr_tree, tvb, offset, hf_btbredr_flags,
385 			ett_btbredr_flags, flag_fields, ENC_NA);
386 		offset += 1;
387 		proto_tree_add_item(pkthdr_tree, hf_btbredr_hec, tvb, offset, 1, ENC_NA);
388 		offset += 2;
389 
390 		/* payload */
391 		switch (type) {
392 		case 0x0: /* NULL */
393 		case 0x1: /* POLL */
394 			break;
395 		case 0x2: /* FHS */
396 			dissect_fhs(btbredr_tree, tvb, pinfo, offset);
397 			break;
398 		case 0x3: /* DM1 */
399 			dissect_dm1(btbredr_tree, tvb, pinfo, offset);
400 			break;
401 		case 0x4: /* DH1/2-DH1 */
402 			dissect_dm1(btbredr_tree, tvb, pinfo, offset);
403 			break;
404 		case 0x5: /* HV1 */
405 		case 0x6: /* HV2/2-EV3 */
406 		case 0x7: /* HV3/EV3/3-EV3 */
407 		case 0x8: /* DV/3-DH1 */
408 		case 0x9: /* AUX1 */
409 		case 0xa: /* DM3/2-DH3 */
410 		case 0xb: /* DH3/3-DH3 */
411 		case 0xc: /* EV4/2-EV5 */
412 		case 0xd: /* EV5/3-EV5 */
413 		case 0xe: /* DM5/2-DH5 */
414 		case 0xf: /* DH5/3-DH5 */
415 			proto_tree_add_item(btbredr_tree, hf_btbredr_payload, tvb, offset, -1, ENC_NA);
416 			break;
417 		default:
418 			break;
419 		}
420 	}
421 
422 	/* Return the amount of data this dissector was able to dissect */
423 	return tvb_reported_length(tvb);
424 }
425 
426 /* register the protocol with Wireshark */
427 void
428 proto_register_btbredr(void)
429 {
430 	/* list of fields */
431 	static hf_register_info hf[] = {
432 		{ &hf_btbredr_meta,
433 			{ "Meta Data", "btbredr.meta",
434 			FT_NONE, BASE_NONE, NULL, 0x0,
435 			"Meta Data About the Packet", HFILL }
436 		},
437 		{ &hf_btbredr_channel,
438 			{ "Channel", "btbredr.channel",
439 			FT_UINT8, BASE_DEC, NULL, 0x0,
440 			"Channel (0-78)", HFILL }
441 		},
442 		{ &hf_btbredr_signal,
443 			{ "Signal", "btbredr.signal",
444 			FT_INT8, BASE_DEC, NULL, 0x0,
445 			"Signal Power", HFILL }
446 		},
447 		{ &hf_btbredr_noise,
448 			{ "Noise", "btbredr.noise",
449 			FT_INT8, BASE_DEC, NULL, 0x0,
450 			"Noise Power", HFILL }
451 		},
452 		{ &hf_btbredr_ac_offenses,
453 			{ "AC Offenses", "btbredr.ac_offenses",
454 			FT_UINT8, BASE_DEC, NULL, 0x0,
455 			"Access Code Offenses", HFILL }
456 		},
457 		{ &hf_btbredr_mod,
458 			{ "Transport Rate", "btbredr.mod",
459 			FT_UINT8, BASE_HEX, VALS(&modulation), 0x02,
460 			"Transport Data Rate", HFILL }
461 		},
462 		{ &hf_btbredr_transport,
463 			{ "Transport", "btbredr.transport",
464 			FT_UINT8, BASE_HEX, VALS(&transports), 0x70,
465 			"Logical Transport", HFILL }
466 		},
467 		{ &hf_btbredr_corrected_header,
468 			{ "Corrected Header", "btbredr.corrected_header",
469 			FT_UINT8, BASE_DEC, NULL, 0x0,
470 			"Corrected Header Bits", HFILL }
471 		},
472 		{ &hf_btbredr_corrected_payload,
473 			{ "Corrected Payload", "btbredr.corrected_payload",
474 			FT_UINT16, BASE_DEC, NULL, 0x0,
475 			"Corrected Payload Bits", HFILL }
476 		},
477 		{ &hf_btbredr_lap,
478 			{ "LAP", "btbredr.lap",
479 			FT_UINT32, BASE_HEX, NULL, 0x0,
480 			"Lower Address Part", HFILL }
481 		},
482 		{ &hf_btbredr_ref_lap,
483 			{ "Ref. LAP", "btbredr.ref_lap",
484 			FT_UINT32, BASE_HEX, NULL, 0x0,
485 			"Reference LAP", HFILL }
486 		},
487 		{ &hf_btbredr_ref_uap,
488 			{ "Ref. UAP", "btbredr.ref_uap",
489 			FT_UINT8, BASE_HEX, NULL, 0x0,
490 			"Reference UAP", HFILL }
491 		},
492 		{ &hf_btbredr_pkthdr,
493 			{ "Packet Header", "btbredr.pkthdr",
494 			FT_NONE, BASE_NONE, NULL, 0x0,
495 			"Bluetooth Baseband Packet Header", HFILL }
496 		},
497 		{ &hf_btbredr_ltaddr,
498 			{ "LT_ADDR", "btbredr.lt_addr",
499 			FT_UINT8, BASE_HEX, NULL, 0x07,
500 			"Logical Transport Address", HFILL }
501 		},
502 		{ &hf_btbredr_type,
503 			{ "TYPE", "btbredr.type",
504 			FT_UINT8, BASE_HEX, VALS(packet_types), 0x78,
505 			"Packet Type", HFILL }
506 		},
507 		{ &hf_btbredr_flags,
508 			{ "Flags", "btbredr.flags",
509 			FT_UINT8, BASE_HEX, NULL, 0x0,
510 			"Packet Header Flags", HFILL }
511 		},
512 		{ &hf_btbredr_flow,
513 			{ "FLOW", "btbredr.flow",
514 			FT_BOOLEAN, 8, NULL, 0x01,
515 			"Flow control indication", HFILL }
516 		},
517 		{ &hf_btbredr_arqn,
518 			{ "ARQN", "btbredr.arqn",
519 			FT_BOOLEAN, 8, NULL, 0x02,
520 			"Acknowledgment indication", HFILL }
521 		},
522 		{ &hf_btbredr_seqn,
523 			{ "SEQN", "btbredr.seqn",
524 			FT_BOOLEAN, 8, NULL, 0x04,
525 			"Sequence number", HFILL }
526 		},
527 		{ &hf_btbredr_hec,
528 			{ "HEC", "btbredr.lt_addr",
529 			FT_UINT8, BASE_HEX, NULL, 0x0,
530 			"Header Error Check", HFILL }
531 		},
532 		{ &hf_btbredr_payload,
533 			{ "Payload", "btbredr.payload",
534 			FT_NONE, BASE_NONE, NULL, 0x0,
535 			NULL, HFILL }
536 		},
537 		{ &hf_btbredr_llid,
538 			{ "LLID", "btbredr.llid",
539 			FT_UINT8, BASE_HEX, VALS(llid_codes), 0x03,
540 			"Logical Link ID", HFILL }
541 		},
542 		{ &hf_btbredr_pldflow,
543 			{ "Flow", "btbredr.flow",
544 			FT_BOOLEAN, 8, NULL, 0x04,
545 			"Payload Flow indication", HFILL }
546 		},
547 		{ &hf_btbredr_length,
548 			{ "Length", "btbredr.length",
549 			FT_UINT8, BASE_DEC, NULL, 0xf8,
550 			"Payload Length", HFILL }
551 		},
552 		{ &hf_btbredr_pldhdr,
553 			{ "Payload Header", "btbredr.pldhdr",
554 			FT_NONE, BASE_NONE, NULL, 0x0,
555 			NULL, HFILL }
556 		},
557 		{ &hf_btbredr_pldbody,
558 			{ "Payload Body", "btbredr.pldbody",
559 			FT_BYTES, BASE_NONE, NULL, 0x0,
560 			NULL, HFILL }
561 		},
562 		{ &hf_btbredr_crc,
563 			{ "CRC", "btbredr.crc",
564 			FT_UINT16, BASE_HEX, NULL, 0x0,
565 			"Payload CRC", HFILL }
566 		},
567 		{ &hf_btbredr_fhs_parity,
568 			{ "Parity", "btbredr.parity",
569 			/* FIXME this doesn't work because bitmasks can only be 32 bits */
570 			FT_UINT64, BASE_HEX, NULL, /*0x00000003ffffffffULL,*/ 0x0,
571 			"LAP parity", HFILL }
572 		},
573 		{ &hf_btbredr_fhs_lap,
574 			{ "LAP", "btbredr.lap",
575 			FT_UINT24, BASE_HEX, NULL, 0x03fffffc,
576 			"Lower Address Part", HFILL }
577 		},
578 		{ &hf_btbredr_fhs_eir,
579 			{ "EIR", "btbredr.eir",
580 			FT_BOOLEAN, 8, NULL, 0x04,
581 			"Extended Inquiry Response packet may follow", HFILL }
582 		},
583 		{ &hf_btbredr_fhs_sr,
584 			{ "SR", "btbredr.sr",
585 			FT_UINT8, BASE_HEX, VALS(sr_modes), 0x30,
586 			"Scan Repetition", HFILL }
587 		},
588 		{ &hf_btbredr_fhs_uap,
589 			{ "UAP", "btbredr.uap",
590 			FT_UINT8, BASE_HEX, NULL, 0x0,
591 			"Upper Address Part", HFILL }
592 		},
593 		{ &hf_btbredr_fhs_nap,
594 			{ "NAP", "btbredr.nap",
595 			FT_UINT16, BASE_HEX, NULL, 0x0,
596 			"Non-Significant Address Part", HFILL }
597 		},
598 		{ &hf_btbredr_fhs_class, /* FIXME break out further */
599 			{ "Class of Device", "btbredr.class",
600 			FT_UINT24, BASE_HEX, NULL, 0x0,
601 			NULL, HFILL }
602 		},
603 		{ &hf_btbredr_fhs_ltaddr,
604 			{ "LT_ADDR", "btbredr.lt_addr",
605 			FT_UINT8, BASE_HEX, NULL, 0x07,
606 			"Logical Transport Address", HFILL }
607 		},
608 		{ &hf_btbredr_fhs_clk,
609 			{ "CLK", "btbredr.clk",
610 			FT_UINT32, BASE_HEX, NULL, 0x1ffffff8,
611 			"Clock bits 2 through 27", HFILL }
612 		},
613 		{ &hf_btbredr_fhs_psmode,
614 			{ "Page Scan Mode", "btbredr.psmode",
615 			FT_UINT8, BASE_HEX, NULL, 0xe0,
616 			NULL, HFILL }
617 		},
618 	};
619 
620 	/* protocol subtree arrays */
621 	static gint *ett[] = {
622 		&ett_btbredr,
623 		&ett_btbredr_meta,
624 		&ett_btbredr_pkthdr,
625 		&ett_btbredr_flags,
626 		&ett_btbredr_payload,
627 		&ett_btbredr_pldhdr,
628 	};
629 
630 	/* register the protocol name and description */
631 	proto_btbredr = proto_register_protocol(
632 		"Bluetooth BR/EDR Baseband",	/* full name */
633 		"BT BR/EDR Baseband",			/* short name */
634 		"btbredr"			/* abbreviation (e.g. for filters) */
635 		);
636 
637 	/* register the header fields and subtrees used */
638 	proto_register_field_array(proto_btbredr, hf, array_length(hf));
639 	proto_register_subtree_array(ett, array_length(ett));
640 }
641 
642 /* Remove this once recent Wireshark/TCPdump releases are more common */
643 #ifndef WTAP_ENCAP_BLUETOOTH_BREDR_BB
644 #define WTAP_ENCAP_BLUETOOTH_BREDR_BB 161
645 #endif
646 
647 void
648 proto_reg_handoff_btbredr(void)
649 {
650 	dissector_handle_t btbredr_handle;
651 	btbredr_handle = new_create_dissector_handle(dissect_btbredr,
652 												 proto_btbredr);
653 	dissector_add_uint("wtap_encap",
654 					   WTAP_ENCAP_BLUETOOTH_BREDR_BB,
655 					   btbredr_handle);
656 
657 	btlmp_handle = find_dissector("btlmp");
658 	btl2cap_handle = find_dissector("btl2cap");
659 }
660 
661 /*
662  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
663  *
664  * Local variables:
665  * c-basic-offset: 4
666  * tab-width: 8
667  * indent-tabs-mode: nil
668  * End:
669  *
670  * vi: set shiftwidth=4 tabstop=8 expandtab:
671  * :indentSize=4:tabSize=8:noTabs=true:
672  */
673