Coverage Report

Created: 2025-12-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-btbredr_rf.c
Line
Count
Source
1
/* packet-btbredr_rf.c
2
 * Routines for Bluetooth Pseudoheader for BR/EDR Baseband
3
 *
4
 * Copyright 2020, Thomas Sailer <t.sailer@alumni.ethz.ch>
5
 * Copyright 2014, Michal Labedzki for Tieto Corporation
6
 * Copyright 2014, Dominic Spill <dominicgs@gmail.com>
7
 *
8
 * Wireshark - Network traffic analyzer
9
 * By Gerald Combs <gerald@wireshark.org>
10
 * Copyright 1998 Gerald Combs
11
 *
12
 * SPDX-License-Identifier: GPL-2.0-or-later
13
 */
14
15
#include "config.h"
16
17
#include <epan/packet.h>
18
#include <epan/expert.h>
19
#include <epan/proto_data.h>
20
#include <epan/reassemble.h>
21
22
#include <wiretap/wtap.h>
23
24
#include "packet-bluetooth.h"
25
#include "packet-btbredr_rf.h"
26
#include "packet-bthci_acl.h"
27
28
/*
29
 * Future Improvements:
30
 * - De-Whiten if the capture hardware did not already do it and we have the UAP
31
 */
32
33
static int proto_btbredr_rf;
34
static int proto_btbredr_fhs;
35
36
static int hf_rf_channel;
37
static int hf_uncertain_rf_channel;
38
static int hf_signal_power;
39
static int hf_invalid_signal_power;
40
static int hf_noise_power;
41
static int hf_invalid_noise_power;
42
static int hf_access_address_offenses;
43
static int hf_payload_transport_rate;
44
static int hf_payload_transport_rate_payload;
45
static int hf_payload_transport_rate_transport;
46
static int hf_payload_transport_rate_ignored;
47
static int hf_corrected_header_bits;
48
static int hf_corrected_payload_bits;
49
static int hf_lower_address_part;
50
static int hf_reference_lower_address_part;
51
static int hf_invalid_reference_lower_address_part;
52
static int hf_reference_upper_address_part;
53
static int hf_invalid_reference_upper_address_part;
54
static int hf_whitened_packet_header;
55
static int hf_invalid_packet_header;
56
static int hf_packet_header;
57
static int hf_packet_header_reserved;
58
static int hf_packet_header_lt_addr;
59
static int hf_packet_header_type;
60
static int hf_packet_header_type_any;
61
static int hf_packet_header_type_sco_br;
62
static int hf_packet_header_type_esco_br;
63
static int hf_packet_header_type_esco_edr;
64
static int hf_packet_header_type_acl_br;
65
static int hf_packet_header_type_acl_edr;
66
static int hf_packet_header_type_cpb_br;
67
static int hf_packet_header_type_cpb_edr;
68
static int hf_packet_header_flow_control;
69
static int hf_packet_header_acknowledge_indication;
70
static int hf_packet_header_sequence_number;
71
static int hf_packet_header_header_error_check;
72
static int hf_packet_header_broken_lt_addr;
73
static int hf_packet_header_broken_type;
74
static int hf_packet_header_broken_type_any;
75
static int hf_packet_header_broken_type_sco_br;
76
static int hf_packet_header_broken_type_esco_br;
77
static int hf_packet_header_broken_type_esco_edr;
78
static int hf_packet_header_broken_type_acl_br;
79
static int hf_packet_header_broken_type_acl_edr;
80
static int hf_packet_header_broken_type_cpb_br;
81
static int hf_packet_header_broken_type_cpb_edr;
82
static int hf_packet_header_broken_flow_control;
83
static int hf_packet_header_broken_acknowledge_indication;
84
static int hf_packet_header_broken_sequence_number;
85
static int hf_packet_header_broken_header_error_check;
86
static int hf_flags;
87
static int hf_flags_reserved_15_14;
88
static int hf_flags_mic_pass;
89
static int hf_flags_mic_checked;
90
static int hf_flags_crc_pass;
91
static int hf_flags_crc_checked;
92
static int hf_flags_hec_pass;
93
static int hf_flags_hec_checked;
94
static int hf_flags_reference_upper_address_part_valid;
95
static int hf_flags_rf_channel_aliasing;
96
static int hf_flags_br_edr_data_present;
97
static int hf_flags_reference_lower_address_part_valid;
98
static int hf_flags_bredr_payload_decrypted;
99
static int hf_flags_noise_power_valid;
100
static int hf_flags_signal_power_valid;
101
static int hf_flags_packet_header_and_br_edr_payload_dewhitened;
102
static int hf_whitened_data;
103
static int hf_encrypted_data;
104
static int hf_data;
105
static int hf_isochronous_data;
106
static int hf_asynchronous_data;
107
static int hf_l2cap_fragment;
108
static int hf_crc;
109
static int hf_payload_header2;
110
static int hf_payload_header2_llid;
111
static int hf_payload_header2_flow;
112
static int hf_payload_header2_length;
113
static int hf_payload_header2_rfu;
114
static int hf_payload_header1;
115
static int hf_payload_header1_llid;
116
static int hf_payload_header1_flow;
117
static int hf_payload_header1_length;
118
static int hf_l2cap_msg_fragments;
119
static int hf_l2cap_msg_fragment;
120
static int hf_l2cap_msg_fragment_overlap;
121
static int hf_l2cap_msg_fragment_overlap_conflicts;
122
static int hf_l2cap_msg_fragment_multiple_tails;
123
static int hf_l2cap_msg_fragment_too_long_fragment;
124
static int hf_l2cap_msg_fragment_error;
125
static int hf_l2cap_msg_fragment_count;
126
static int hf_l2cap_msg_reassembled_in;
127
static int hf_l2cap_msg_reassembled_length;
128
static int hf_fhs_parity;
129
static int hf_fhs_lap;
130
static int hf_fhs_eir;
131
static int hf_fhs_reserved;
132
static int hf_fhs_sr;
133
static int hf_fhs_sp;
134
static int hf_fhs_uap;
135
static int hf_fhs_nap;
136
static int hf_fhs_class;
137
static int hf_fhs_ltaddr;
138
static int hf_fhs_clk;
139
static int hf_fhs_pagescanmode;
140
141
#define FLAGS_MIC_PASS                                      0x2000
142
#define FLAGS_MIC_CHECKED                                   0x1000
143
4
#define FLAGS_CRC_PASS                                      0x0800
144
4
#define FLAGS_CRC_CHECKED                                   0x0400
145
#define FLAGS_HEC_PASS                                      0x0200
146
#define FLAGS_HEC_CHECKED                                   0x0100
147
27
#define FLAGS_REFERENCE_UPPER_ADDRESS_PART_VALID            0x0080
148
28
#define FLAGS_RF_CHANNEL_ALIASING                           0x0040
149
13
#define FLAGS_BR_EDR_DATA_PRESENT                           0x0020
150
14
#define FLAGS_REFERENCE_LOWER_ADDRESS_PART_VALID            0x0010
151
14
#define FLAGS_BREDR_PAYLOAD_DECRYPTED                       0x0008
152
47
#define FLAGS_NOISE_POWER_VALID                             0x0004
153
49
#define FLAGS_SIGNAL_POWER_VALID                            0x0002
154
35
#define FLAGS_PACKET_HEADER_AND_BR_EDR_PAYLOAD_DEWHITENED   0x0001
155
156
static int * const hfx_payload_transport_rate[] = {
157
    &hf_payload_transport_rate_payload,
158
    &hf_payload_transport_rate_transport,
159
    NULL
160
};
161
162
static expert_field ei_unexpected_data;
163
static expert_field ei_reserved_not_zero;
164
static expert_field ei_incorrect_packet_header_or_hec;
165
static expert_field ei_packet_header_with_hec_not_checked;
166
static expert_field ei_broken_packet_header_format;
167
static expert_field ei_incorrect_crc;
168
static expert_field ei_missing_fragment_start;
169
static expert_field ei_esco_incorrect_ltaddr;
170
static expert_field ei_esco_incorrect_length;
171
172
static int ett_btbredr_rf;
173
static int ett_flags;
174
static int ett_payload_transport_rate;
175
static int ett_packet_header;
176
static int ett_bluetooth_header;
177
static int ett_payload_header;
178
static int ett_l2cap_msg_fragment;
179
static int ett_l2cap_msg_fragments;
180
static int ett_btbredr_fhs;
181
182
static dissector_table_t  packet_type_sco_br_table;
183
static dissector_table_t  packet_type_esco_br_table;
184
static dissector_table_t  packet_type_esco_edr_table;
185
static dissector_table_t  packet_type_acl_br_table;
186
static dissector_table_t  packet_type_acl_edr_table;
187
static dissector_table_t  packet_type_cpb_br_table;
188
static dissector_table_t  packet_type_cpb_edr_table;
189
190
static dissector_handle_t btlmp_handle;
191
static dissector_handle_t btl2cap_handle;
192
193
static dissector_handle_t btbredr_rf_handle;
194
static dissector_handle_t btbredr_fhs_handle;
195
196
static wmem_tree_t *connection_info_tree;
197
static wmem_tree_t *device_info_tree;
198
199
typedef struct _device_info_t {
200
    uint32_t interface_id;
201
    uint32_t adapter_id;
202
    uint8_t  bd_addr[6];
203
    int8_t   dir;
204
} device_info_t;
205
206
0
#define BDADDR_CENTRAL  0
207
0
#define BDADDR_PERIPHERAL   1
208
209
typedef struct _btbredr_frame_info_t {
210
    unsigned retransmit : 1;      /* 0 = No, 1 = Retransmitted frame */
211
    unsigned ack : 1;             /* 0 = Nack, 1 = Ack */
212
    unsigned more_fragments : 1;  /* 0 = Last fragment, 1 = More fragments */
213
    unsigned missing_start : 1;   /* 0 = No, 1 = Missing fragment start */
214
    uint32_t l2cap_index;         /* Unique identifier for each L2CAP message */
215
} btbredr_frame_info_t;
216
217
typedef struct {
218
    bluetooth_data_t  *bluetooth_data;
219
    connection_info_t *connection_info;
220
    device_info_t     *device_info;
221
} btbredr_fhs_data_t;
222
223
static const uint8_t null_bd_addr[6] = { 0, 0, 0, 0, 0, 0 };
224
225
/* Reassembly */
226
static reassembly_table l2cap_msg_reassembly_table;
227
228
static const fragment_items l2cap_msg_frag_items = {
229
    /* Fragment subtrees */
230
    &ett_l2cap_msg_fragment,
231
    &ett_l2cap_msg_fragments,
232
    /* Fragment fields */
233
    &hf_l2cap_msg_fragments,
234
    &hf_l2cap_msg_fragment,
235
    &hf_l2cap_msg_fragment_overlap,
236
    &hf_l2cap_msg_fragment_overlap_conflicts,
237
    &hf_l2cap_msg_fragment_multiple_tails,
238
    &hf_l2cap_msg_fragment_too_long_fragment,
239
    &hf_l2cap_msg_fragment_error,
240
    &hf_l2cap_msg_fragment_count,
241
    /* Reassembled in field */
242
    &hf_l2cap_msg_reassembled_in,
243
    /* Reassembled length field */
244
    &hf_l2cap_msg_reassembled_length,
245
    /* Reassembled data field */
246
    NULL,
247
    /* Tag */
248
    "BT BR/EDR L2CAP fragments"
249
};
250
251
static const value_string payload_transport_rate_transport_vals[] = {
252
    { 0x00, "Any" },
253
    { 0x01, "SCO" },
254
    { 0x02, "eSCO" },
255
    { 0x03, "ACL" },
256
    { 0x04, "CPB" },
257
    { 0,    NULL }
258
};
259
260
10
#define TRANSPORT_ANY   0x00
261
20
#define TRANSPORT_SCO   0x10
262
59
#define TRANSPORT_eSCO  0x20
263
59
#define TRANSPORT_ACL   0x30
264
25
#define TRANSPORT_CPB   0x40
265
266
267
static const value_string payload_transport_rate_payload_vals[] = {
268
    { 0x00, "Basic Rate with GFSK demodulation" },
269
    { 0x01, "Enhanced Data Rate with PI/2-DQPSK demodulation" },
270
    { 0x02, "Enhanced Data Rate with 8DPSK demodulation" },
271
    { 0,    NULL }
272
};
273
274
static const value_string payload_transport_rate_payload_abbrev_vals[] = {
275
    { 0x00, "BR 1Mbps" },
276
    { 0x01, "EDR 2Mbps" },
277
    { 0x02, "EDR 3Mbps" },
278
    { 0,    NULL }
279
};
280
281
74
#define PAYLOAD_BR     0x00
282
45
#define PAYLOAD_EDR_2  0x01
283
44
#define PAYLOAD_EDR_3  0x02
284
285
21
#define PACKET_TYPE_UNKNOWN  -1
286
287
static const value_string packet_type_any_vals[] = {
288
    { 0x00, "NULL" },
289
    { 0x01, "POLL" },
290
    { 0x02, "FHS" },
291
    { 0x03, "DM1" },
292
    { 0x04, "DH1/2-DH1" },
293
    { 0x05, "HV1" },
294
    { 0x06, "HV2/2-EV3" },
295
    { 0x07, "HV3/EV3/3-EV3" },
296
    { 0x08, "DV/3-DH1" },
297
    { 0x09, "AUX1" },
298
    { 0x0A, "DM3/2-DH3" },
299
    { 0x0B, "DH3/3-DH3" },
300
    { 0x0C, "EV4/2-EV5" },
301
    { 0x0D, "EV5/3-EV5" },
302
    { 0x0E, "DM5/2-DH5" },
303
    { 0x0F, "DH5/3-DH5" },
304
    { 0,    NULL }
305
};
306
307
static const value_string packet_type_sco_br_vals[] = {
308
    { 0x00, "NULL" },
309
    { 0x01, "POLL" },
310
    { 0x02, "FHS" },
311
    { 0x03, "DM1" },
312
    { 0x04, "undefined" },
313
    { 0x05, "HV1" },
314
    { 0x06, "HV2" },
315
    { 0x07, "HV3" },
316
    { 0x08, "DV" },
317
    { 0x09, "undefined" },
318
    { 0x0A, "undefined" },
319
    { 0x0B, "undefined" },
320
    { 0x0C, "undefined" },
321
    { 0x0D, "undefined" },
322
    { 0x0E, "undefined" },
323
    { 0x0F, "undefined" },
324
    { 0,    NULL }
325
};
326
327
static const value_string packet_type_esco_br_vals[] = {
328
    { 0x00, "NULL" },
329
    { 0x01, "POLL" },
330
    { 0x02, "reserved" },
331
    { 0x03, "reserved" },
332
    { 0x04, "undefined" },
333
    { 0x05, "undefined" },
334
    { 0x06, "undefined" },
335
    { 0x07, "EV3" },
336
    { 0x08, "undefined" },
337
    { 0x09, "undefined" },
338
    { 0x0A, "undefined" },
339
    { 0x0B, "undefined" },
340
    { 0x0C, "EV4" },
341
    { 0x0D, "EV5" },
342
    { 0x0E, "undefined" },
343
    { 0x0F, "undefined" },
344
    { 0,    NULL }
345
};
346
347
static const value_string packet_type_esco_edr_vals[] = {
348
    { 0x00, "NULL" },
349
    { 0x01, "POLL" },
350
    { 0x02, "reserved" },
351
    { 0x03, "reserved" },
352
    { 0x04, "undefined" },
353
    { 0x05, "undefined" },
354
    { 0x06, "2-EV3" },
355
    { 0x07, "3-EV3" },
356
    { 0x08, "undefined" },
357
    { 0x09, "undefined" },
358
    { 0x0A, "undefined" },
359
    { 0x0B, "undefined" },
360
    { 0x0C, "2-EV5" },
361
    { 0x0D, "3-EV5" },
362
    { 0x0E, "undefined" },
363
    { 0x0F, "undefined" },
364
    { 0,    NULL }
365
};
366
367
static const value_string packet_type_acl_br_vals[] = {
368
    { 0x00, "NULL" },
369
    { 0x01, "POLL" },
370
    { 0x02, "FHS" },
371
    { 0x03, "DM1" },
372
    { 0x04, "DH1" },
373
    { 0x05, "undefined" },
374
    { 0x06, "undefined" },
375
    { 0x07, "undefined" },
376
    { 0x08, "undefined" },
377
    { 0x09, "AUX1" },
378
    { 0x0A, "DM3" },
379
    { 0x0B, "DH3" },
380
    { 0x0C, "undefined" },
381
    { 0x0D, "undefined" },
382
    { 0x0E, "DM5" },
383
    { 0x0F, "DH5" },
384
    { 0,    NULL }
385
};
386
387
static const value_string packet_type_acl_edr_vals[] = {
388
    { 0x00, "NULL" },
389
    { 0x01, "POLL" },
390
    { 0x02, "FHS" },
391
    { 0x03, "DM1" },
392
    { 0x04, "2-DH1" },
393
    { 0x05, "undefined" },
394
    { 0x06, "undefined" },
395
    { 0x07, "undefined" },
396
    { 0x08, "3-DH1" },
397
    { 0x09, "AUX1" },
398
    { 0x0A, "2-DH3" },
399
    { 0x0B, "3-DH3" },
400
    { 0x0C, "undefined" },
401
    { 0x0D, "undefined" },
402
    { 0x0E, "2-DH5" },
403
    { 0x0F, "3-DH5" },
404
    { 0,    NULL }
405
};
406
407
static const value_string packet_type_cpb_br_vals[] = {
408
    { 0x00, "NULL" },
409
    { 0x01, "reserved" },
410
    { 0x02, "reserved" },
411
    { 0x03, "DM1" },
412
    { 0x04, "DH1" },
413
    { 0x05, "undefined" },
414
    { 0x06, "undefined" },
415
    { 0x07, "undefined" },
416
    { 0x08, "undefined" },
417
    { 0x09, "undefined" },
418
    { 0x0A, "DM3" },
419
    { 0x0B, "DH3" },
420
    { 0x0C, "undefined" },
421
    { 0x0D, "undefined" },
422
    { 0x0E, "DM5" },
423
    { 0x0F, "DH5" },
424
    { 0,    NULL }
425
};
426
427
static const value_string packet_type_cpb_edr_vals[] = {
428
    { 0x00, "NULL" },
429
    { 0x01, "reserved" },
430
    { 0x02, "reserved" },
431
    { 0x03, "DM1" },
432
    { 0x04, "2-DH1" },
433
    { 0x05, "undefined" },
434
    { 0x06, "undefined" },
435
    { 0x07, "undefined" },
436
    { 0x08, "3-DH1" },
437
    { 0x09, "undefined" },
438
    { 0x0A, "2-DH3" },
439
    { 0x0B, "3-DH3" },
440
    { 0x0C, "undefined" },
441
    { 0x0D, "undefined" },
442
    { 0x0E, "2-DH5" },
443
    { 0x0F, "3-DH5" },
444
    { 0,    NULL }
445
};
446
447
static const val64_string fhs_scan_repetition_vals[] = {
448
    { 0x00, "R0" },
449
    { 0x01, "R1" },
450
    { 0x02, "R2" },
451
    { 0,    NULL }
452
};
453
454
static const value_string fhs_page_scan_mode_vals[] = {
455
    { 0x00, "Mandatory Scan Mode" },
456
    { 0,    NULL }
457
};
458
459
void proto_register_btbredr_rf(void);
460
void proto_reg_handoff_btbredr_rf(void);
461
462
static uint8_t
463
reverse_bits(uint8_t value)
464
14
{
465
14
    value = ((value >> 1) & 0x55) | ((value << 1) & 0xaa);
466
14
    value = ((value >> 2) & 0x33) | ((value << 2) & 0xcc);
467
14
    value = ((value >> 4) & 0x0f) | ((value << 4) & 0xf0);
468
14
    return value;
469
14
}
470
471
static bool
472
broken_check_hec(uint8_t uap, uint32_t header)
473
7
{
474
7
    uint8_t  hec;
475
7
    uint16_t header_data;
476
7
    uint8_t  lfsr;
477
7
    int8_t   i;
478
479
7
    hec = header & 0xFF;
480
7
    header_data = (header >> 8) & 0x3F;
481
482
7
    lfsr = uap;
483
484
77
    for (i = 9; i >= 0; i -= 1) {
485
70
        if (lfsr & 0x80)
486
21
            lfsr ^= 0x65;
487
488
70
        lfsr = (lfsr << 1) | (((lfsr >> 7) ^ (header_data >> i)) & 0x01);
489
70
    }
490
491
7
    lfsr = reverse_bits(lfsr);
492
493
7
    return lfsr == hec;
494
7
}
495
496
static bool
497
check_hec(uint8_t uap, uint32_t header)
498
7
{
499
7
    static const uint32_t crc_poly_rev_bt_hec = 0xe5;
500
7
    header &= 0x3ffff;
501
7
    header ^= reverse_bits(uap) & 0xff;
502
77
    for (unsigned i = 0; i < 10; ++i, header >>= 1)
503
70
        if (header & 1)
504
29
            header ^= (crc_poly_rev_bt_hec << 1);
505
7
    return !header;
506
7
}
507
508
static bool
509
check_crc(uint8_t uap, tvbuff_t *tvb, int offset, int len)
510
0
{
511
0
    static const uint16_t crc_poly_rev_bt_pdu = 0x8408;
512
0
    uint16_t crc = reverse_bits(uap);
513
0
    crc <<= 8;
514
0
    for (; len > 0; --len, ++offset) {
515
0
        crc ^= tvb_get_uint8(tvb, offset) & 0xff;
516
0
        for (unsigned i = 0; i < 8; ++i) {
517
0
            uint16_t x = crc & 1;
518
0
            crc >>= 1;
519
0
            crc ^= crc_poly_rev_bt_pdu & -x;
520
0
        }
521
0
    }
522
0
    return !crc;
523
0
}
524
525
static uint32_t
526
extract_lap(const uint8_t bd_addr[6])
527
0
{
528
0
    uint32_t lap = bd_addr[3];
529
0
    lap <<= 8;
530
0
    lap |= bd_addr[4];
531
0
    lap <<= 8;
532
0
    lap |= bd_addr[5];
533
0
    return lap;
534
0
}
535
536
static bool
537
is_reserved_lap(uint32_t lap)
538
27
{
539
27
    return (lap >= 0x9e8b00) && (lap <= 0x9e8b3f);
540
27
}
541
542
static connection_info_t *
543
lookup_connection_info(uint32_t interface_id, uint32_t adapter_id, uint32_t lap, uint32_t ltaddr, uint32_t pktnum)
544
0
{
545
0
    connection_info_t *cinfo;
546
0
    wmem_tree_key_t key[6];
547
0
    key[0].length = 1;
548
0
    key[0].key = &interface_id;
549
0
    key[1].length = 1;
550
0
    key[1].key = &adapter_id;
551
0
    key[2].length = 1;
552
0
    key[2].key = &lap;
553
0
    key[3].length = 1;
554
0
    key[3].key = &ltaddr;
555
0
    key[4].length = 1;
556
0
    key[4].key = &pktnum;
557
0
    key[5].length = 0;
558
0
    key[5].key = NULL;
559
0
    cinfo = (connection_info_t *) wmem_tree_lookup32_array_le(connection_info_tree, key);
560
0
    if (!cinfo)
561
0
        return NULL;
562
0
    if (cinfo->interface_id != interface_id || cinfo->adapter_id != adapter_id ||
563
0
        extract_lap(cinfo->bd_addr[BDADDR_CENTRAL]) != lap || cinfo->lt_addr != ltaddr)
564
0
        return NULL;
565
0
    return cinfo;
566
0
}
567
568
connection_info_t *
569
btbredr_rf_add_esco_link(connection_info_t *cinfo, packet_info *pinfo, uint8_t handle, uint32_t ltaddr, uint16_t pktszms, uint16_t pktszsm)
570
0
{
571
0
    connection_info_t *ecinfo;
572
0
    uint32_t lap;
573
0
    wmem_tree_key_t key[6];
574
0
    if (!cinfo || !pinfo || ltaddr >= 8 || !ltaddr)
575
0
        return NULL;
576
0
    lap = extract_lap(cinfo->bd_addr[BDADDR_CENTRAL]);
577
0
    ecinfo = lookup_connection_info(cinfo->interface_id, cinfo->adapter_id, lap, ltaddr, pinfo->num);
578
0
    if (ecinfo && (memcmp(cinfo->bd_addr[BDADDR_CENTRAL], ecinfo->bd_addr[BDADDR_CENTRAL], 6) ||
579
0
                   memcmp(cinfo->bd_addr[BDADDR_PERIPHERAL], ecinfo->bd_addr[BDADDR_PERIPHERAL], 6) ||
580
0
                   !ecinfo->esco || ecinfo->escohandle != handle || ecinfo->escosize[0] != pktszms ||
581
0
                   ecinfo->escosize[1] != pktszsm))
582
0
        ecinfo = NULL;
583
0
    if (ecinfo)
584
0
        return ecinfo;
585
0
    ecinfo = wmem_new0(wmem_file_scope(), connection_info_t);
586
0
    ecinfo->interface_id   = cinfo->interface_id;
587
0
    ecinfo->adapter_id     = cinfo->adapter_id;
588
0
    ecinfo->lt_addr        = ltaddr;
589
0
    ecinfo->timestamp      = cinfo->timestamp;
590
0
    ecinfo->btclock        = cinfo->btclock;
591
0
    memcpy(ecinfo->bd_addr[BDADDR_CENTRAL], cinfo->bd_addr[BDADDR_CENTRAL], 6);
592
0
    memcpy(ecinfo->bd_addr[BDADDR_PERIPHERAL], cinfo->bd_addr[BDADDR_PERIPHERAL], 6);
593
0
    ecinfo->escosize[0] = pktszms;
594
0
    ecinfo->escosize[1] = pktszsm;
595
0
    ecinfo->escohandle = handle;
596
0
    ecinfo->esco = 1;
597
0
    key[0].length = 1;
598
0
    key[0].key = &cinfo->interface_id;
599
0
    key[1].length = 1;
600
0
    key[1].key = &cinfo->adapter_id;
601
0
    key[2].length = 1;
602
0
    key[2].key = &lap;
603
0
    key[3].length = 1;
604
0
    key[3].key = &ltaddr;
605
0
    key[4].length = 1;
606
0
    key[4].key = &pinfo->num;
607
0
    key[5].length = 0;
608
0
    key[5].key = NULL;
609
0
    wmem_tree_insert32_array(connection_info_tree, key, ecinfo);
610
0
    return ecinfo;
611
0
}
612
613
void
614
btbredr_rf_remove_esco_link(connection_info_t *cinfo, packet_info *pinfo, uint8_t handle)
615
0
{
616
0
    connection_info_t *ecinfo;
617
0
    uint32_t lap;
618
0
    wmem_tree_key_t key[6];
619
0
    if (!cinfo || !pinfo)
620
0
        return;
621
0
    lap = extract_lap(cinfo->bd_addr[BDADDR_CENTRAL]);
622
0
    for (uint32_t ltaddr = 1; ltaddr < 8; ++ltaddr) {
623
0
        ecinfo = lookup_connection_info(cinfo->interface_id, cinfo->adapter_id, lap, ltaddr, pinfo->num);
624
0
        if (!ecinfo)
625
0
            continue;
626
0
        if (memcmp(cinfo->bd_addr[BDADDR_CENTRAL], ecinfo->bd_addr[BDADDR_CENTRAL], 6) ||
627
0
            memcmp(cinfo->bd_addr[BDADDR_PERIPHERAL], ecinfo->bd_addr[BDADDR_PERIPHERAL], 6) ||
628
0
            !ecinfo->esco || ecinfo->escohandle != handle)
629
0
            continue;
630
0
        key[0].length = 1;
631
0
        key[0].key = &cinfo->interface_id;
632
0
        key[1].length = 1;
633
0
        key[1].key = &cinfo->adapter_id;
634
0
        key[2].length = 1;
635
0
        key[2].key = &lap;
636
0
        key[3].length = 1;
637
0
        key[3].key = &ltaddr;
638
0
        key[4].length = 1;
639
0
        key[4].key = &pinfo->num;
640
0
        key[5].length = 0;
641
0
        key[5].key = NULL;
642
0
        wmem_tree_insert32_array(connection_info_tree, key, ecinfo);
643
0
    }
644
0
}
645
646
static int
647
dissect_btbredr_rf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
648
14
{
649
14
    proto_item           *btbredr_rf_item;
650
14
    proto_tree           *btbredr_rf_tree;
651
14
    proto_item           *flags_item;
652
14
    proto_tree           *flags_tree;
653
14
    proto_item           *header_item = NULL;
654
14
    proto_tree           *header_tree;
655
14
    proto_item           *reserved_item;
656
14
    proto_item           *hec_item = NULL;
657
14
    int                   offset = 0;
658
14
    int                   hf_x;
659
14
    int                   header_mode;
660
14
    uint32_t              interface_id;
661
14
    uint32_t              adapter_id;
662
14
    uint16_t              flags;
663
14
    uint32_t              lap;
664
14
    uint8_t               uap = 0;
665
14
    uint32_t              ltaddr = 0;
666
14
    uint8_t               payload_and_transport;
667
14
    int16_t               packet_type = PACKET_TYPE_UNKNOWN;
668
14
    const char           *packet_type_str = "Unknown";
669
14
    dissector_table_t     packet_type_table = NULL;
670
14
    bool                  decrypted;
671
14
    int                   isochronous_length = 0;
672
14
    bool                  isochronous_crc = false;
673
14
    bool                  isochronous_esco = false;
674
14
    int                   data_length = 0;
675
14
    int                   data_header = 0;
676
14
    bool                  data_crc = false;
677
14
    bool                  arqn = false;
678
14
    bool                  seqn = false;
679
14
    int                   direction = -1;
680
14
    btbredr_frame_info_t *frame_info = NULL;
681
14
    connection_info_t    *connection_info = NULL;
682
14
    device_info_t        *device_info = NULL;
683
14
    bluetooth_data_t     *bluetooth_data = (bluetooth_data_t *) data;
684
685
14
    if (bluetooth_data)
686
14
        interface_id = bluetooth_data->interface_id;
687
0
    else if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
688
0
        interface_id = pinfo->rec->rec_header.packet_header.interface_id;
689
0
    else
690
0
        interface_id = HCI_INTERFACE_DEFAULT;
691
692
14
    if (bluetooth_data)
693
14
        adapter_id = bluetooth_data->adapter_id;
694
0
    else
695
0
        adapter_id = HCI_ADAPTER_DEFAULT;
696
697
14
    btbredr_rf_item = proto_tree_add_item(tree, proto_btbredr_rf, tvb, offset, -1, ENC_NA);
698
14
    btbredr_rf_tree = proto_item_add_subtree(btbredr_rf_item, ett_btbredr_rf);
699
700
14
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "BT BR/EDR RF");
701
702
14
    if (tvb_captured_length(tvb) >= 21) {
703
13
        flags = tvb_get_uint16(tvb, 20, ENC_LITTLE_ENDIAN);
704
13
    } else {
705
1
        flags = 0;
706
1
    }
707
708
14
    if (flags & FLAGS_RF_CHANNEL_ALIASING)
709
7
        hf_x = hf_uncertain_rf_channel;
710
7
    else
711
7
        hf_x = hf_rf_channel;
712
14
    proto_tree_add_item(btbredr_rf_tree, hf_x, tvb, offset, 1, ENC_NA);
713
14
    offset += 1;
714
715
14
    if (flags & FLAGS_SIGNAL_POWER_VALID)
716
6
        hf_x = hf_signal_power;
717
8
    else
718
8
        hf_x = hf_invalid_signal_power;
719
14
    proto_tree_add_item(btbredr_rf_tree, hf_x, tvb, offset, 1, ENC_NA);
720
14
    offset += 1;
721
722
14
    if (flags & FLAGS_NOISE_POWER_VALID)
723
5
        hf_x = hf_noise_power;
724
9
    else
725
9
        hf_x = hf_invalid_noise_power;
726
14
    proto_tree_add_item(btbredr_rf_tree, hf_x, tvb, offset, 1, ENC_NA);
727
14
    offset += 1;
728
729
14
    proto_tree_add_item(btbredr_rf_tree, hf_access_address_offenses, tvb, offset, 1, ENC_NA);
730
14
    offset += 1;
731
732
14
    payload_and_transport = tvb_get_uint8(tvb, offset);
733
734
14
    col_add_fstr(pinfo->cinfo, COL_INFO, "Transport: %s (%s), RF Channel: %s%2u",
735
14
            val_to_str_const(payload_and_transport >> 4, payload_transport_rate_transport_vals, "Unknown"),
736
14
            val_to_str_const(payload_and_transport & 0xF, payload_transport_rate_payload_abbrev_vals, "Unknown"),
737
14
            (flags & FLAGS_RF_CHANNEL_ALIASING) ? "~" : "",
738
14
            tvb_get_uint8(tvb, 0));
739
740
14
    if (payload_and_transport == 0xFF)
741
3
        proto_tree_add_item(btbredr_rf_tree, hf_payload_transport_rate_ignored, tvb, offset, 1, ENC_NA);
742
11
    else
743
11
        proto_tree_add_bitmask(btbredr_rf_tree, tvb, offset, hf_payload_transport_rate, ett_payload_transport_rate, hfx_payload_transport_rate, ENC_LITTLE_ENDIAN);
744
14
    offset += 1;
745
746
14
    proto_tree_add_item(btbredr_rf_tree, hf_corrected_header_bits, tvb, offset, 1, ENC_NA);
747
14
    offset += 1;
748
749
14
    proto_tree_add_item(btbredr_rf_tree, hf_corrected_payload_bits, tvb, offset, 2, ENC_LITTLE_ENDIAN);
750
14
    offset += 2;
751
752
14
    proto_tree_add_item(btbredr_rf_tree, hf_lower_address_part, tvb, offset, 4, ENC_LITTLE_ENDIAN);
753
14
    lap = tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) & 0xffffff;
754
14
    offset += 4;
755
756
14
    if (!is_reserved_lap(lap)) {
757
14
        wmem_tree_key_t key[4];
758
14
        key[0].length = 1;
759
14
        key[0].key = &interface_id;
760
14
        key[1].length = 1;
761
14
        key[1].key = &adapter_id;
762
14
        key[2].length = 1;
763
14
        key[2].key = &lap;
764
14
        key[3].length = 0;
765
14
        key[3].key = NULL;
766
767
14
        device_info = (device_info_t *) wmem_tree_lookup32_array(device_info_tree, key);
768
14
    }
769
770
14
    if (device_info) {
771
0
        direction = (device_info->dir == pinfo->p2p_dir) ? BDADDR_CENTRAL : BDADDR_PERIPHERAL;
772
0
        uap = device_info->bd_addr[2];
773
0
    }
774
775
14
    if (flags & FLAGS_REFERENCE_LOWER_ADDRESS_PART_VALID)
776
9
        hf_x = hf_reference_lower_address_part;
777
5
    else
778
5
        hf_x = hf_invalid_reference_lower_address_part;
779
14
    proto_tree_add_item(btbredr_rf_tree, hf_x, tvb, offset, 3, ENC_LITTLE_ENDIAN);
780
14
    offset += 3;
781
782
14
    if (flags & FLAGS_REFERENCE_UPPER_ADDRESS_PART_VALID) {
783
10
        hf_x = hf_reference_upper_address_part;
784
10
        uap = tvb_get_uint8(tvb, offset);
785
10
    } else {
786
4
        hf_x = hf_invalid_reference_upper_address_part;
787
4
    }
788
14
    proto_tree_add_item(btbredr_rf_tree, hf_x, tvb, offset, 1, ENC_NA);
789
14
    offset += 1;
790
791
14
    {
792
14
        uint32_t hdr = tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN);
793
14
        bool have_uap = device_info || !!(flags & FLAGS_REFERENCE_UPPER_ADDRESS_PART_VALID);
794
14
        bool is_inquiry = is_reserved_lap(lap);
795
14
        bool is_inquiry_fhs = is_inquiry && (((hdr >> 3) & 0x0f) == 2);
796
14
        bool is_inquiry_broken_fhs = is_inquiry && (((hdr >> 11) & 0x0f) == 2);
797
14
        if (is_inquiry && !(is_inquiry_fhs || is_inquiry_broken_fhs))
798
0
            header_mode = -2;
799
14
        else if (!(flags & FLAGS_PACKET_HEADER_AND_BR_EDR_PAYLOAD_DEWHITENED))
800
5
            header_mode = -1;
801
9
        else if ((have_uap || is_inquiry_fhs) && check_hec(is_inquiry_fhs ? 0 : uap, hdr))
802
0
            header_mode = 1;
803
9
        else if ((have_uap || is_inquiry_broken_fhs) && broken_check_hec(is_inquiry_broken_fhs ? 0 : uap, hdr))
804
0
            header_mode = 2;
805
9
        else if (!have_uap)
806
1
            header_mode = -1;
807
8
        else
808
8
            header_mode = 0;
809
14
    }
810
811
14
    decrypted = !!(flags & FLAGS_BREDR_PAYLOAD_DECRYPTED);
812
813
14
    if (header_mode == -1) {
814
6
        proto_tree_add_item(btbredr_rf_tree, hf_whitened_packet_header, tvb, offset, 4, ENC_LITTLE_ENDIAN);
815
8
    } else if (header_mode == -2) {
816
0
        proto_tree_add_item(btbredr_rf_tree, hf_invalid_packet_header, tvb, offset, 4, ENC_LITTLE_ENDIAN);
817
8
    } else if (header_mode == 2) {
818
        // broken header format
819
0
        header_item = proto_tree_add_item(btbredr_rf_tree, hf_packet_header, tvb, offset, 4, ENC_LITTLE_ENDIAN);
820
0
        header_tree = proto_item_add_subtree(header_item, ett_bluetooth_header);
821
822
0
        proto_tree_add_item(header_tree, hf_packet_header_reserved, tvb, offset, 4, ENC_LITTLE_ENDIAN);
823
0
        proto_tree_add_item(header_tree, hf_packet_header_broken_lt_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
824
0
        ltaddr = (tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) >> 15) & 7;
825
0
        arqn = (tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) >> 9) & 1;
826
0
        seqn = (tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) >> 8) & 1;
827
828
0
        if (payload_and_transport == (TRANSPORT_SCO | PAYLOAD_BR)) {
829
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_sco_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
830
831
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
832
0
            packet_type_str = val_to_str_const(packet_type, packet_type_sco_br_vals, "Unknown");
833
0
            packet_type_table = packet_type_sco_br_table;
834
0
        } else if (payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_BR)) {
835
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_esco_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
836
837
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
838
0
            packet_type_str = val_to_str_const(packet_type, packet_type_esco_br_vals, "Unknown");
839
0
            packet_type_table = packet_type_esco_br_table;
840
0
        } else if (payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_EDR_3)) {
841
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_esco_edr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
842
843
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
844
0
            packet_type_str = val_to_str_const(packet_type, packet_type_esco_edr_vals, "Unknown");
845
0
            packet_type_table = packet_type_esco_edr_table;
846
0
        } else if (payload_and_transport == (TRANSPORT_ACL | PAYLOAD_BR)) {
847
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_acl_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
848
849
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
850
0
            packet_type_str = val_to_str_const(packet_type, packet_type_acl_br_vals, "Unknown");
851
0
            packet_type_table = packet_type_acl_br_table;
852
0
        } else if (payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_3)) {
853
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_acl_edr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
854
855
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
856
0
            packet_type_str = val_to_str_const(packet_type, packet_type_acl_edr_vals, "Unknown");
857
0
            packet_type_table = packet_type_acl_edr_table;
858
0
        } else if (payload_and_transport == (TRANSPORT_CPB | PAYLOAD_BR)) {
859
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_cpb_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
860
861
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
862
0
            packet_type_str = val_to_str_const(packet_type, packet_type_cpb_br_vals, "Unknown");
863
0
            packet_type_table = packet_type_cpb_br_table;
864
0
        } else if (payload_and_transport == (TRANSPORT_CPB | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_3)) {
865
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_cpb_edr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
866
867
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
868
0
            packet_type_str = val_to_str_const(packet_type, packet_type_cpb_edr_vals, "Unknown");
869
0
            packet_type_table = packet_type_cpb_edr_table;
870
0
        } else if ((payload_and_transport >> 4) == TRANSPORT_ANY) {
871
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type_any, tvb, offset, 4, ENC_LITTLE_ENDIAN);
872
873
0
            packet_type = (tvb_get_uint8(tvb, offset + 1) >> 3) & 0xF;
874
0
            packet_type_str = val_to_str_const(packet_type, packet_type_any_vals, "Unknown");
875
0
        } else {
876
0
            proto_tree_add_item(header_tree, hf_packet_header_broken_type, tvb, offset, 4, ENC_LITTLE_ENDIAN);
877
0
        }
878
879
0
        proto_tree_add_item(header_tree, hf_packet_header_broken_flow_control, tvb, offset, 4, ENC_LITTLE_ENDIAN);
880
0
        proto_tree_add_item(header_tree, hf_packet_header_broken_acknowledge_indication, tvb, offset, 4, ENC_LITTLE_ENDIAN);
881
0
        proto_tree_add_item(header_tree, hf_packet_header_broken_sequence_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
882
0
        hec_item = proto_tree_add_item(header_tree, hf_packet_header_broken_header_error_check, tvb, offset, 4, ENC_LITTLE_ENDIAN);
883
8
    } else if (header_mode >= 0) {
884
        // header format according to Core_v5.2.pdf Vol 2 Part B Chapter 6.4
885
7
        header_item = proto_tree_add_item(btbredr_rf_tree, hf_packet_header, tvb, offset, 4, ENC_LITTLE_ENDIAN);
886
7
        header_tree = proto_item_add_subtree(header_item, ett_bluetooth_header);
887
888
7
        proto_tree_add_item(header_tree, hf_packet_header_lt_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
889
7
        ltaddr = tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) & 7;
890
7
        arqn = (tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) >> 8) & 1;
891
7
        seqn = (tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN) >> 9) & 1;
892
893
7
        if (payload_and_transport == (TRANSPORT_SCO | PAYLOAD_BR)) {
894
0
            proto_tree_add_item(header_tree, hf_packet_header_type_sco_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
895
896
0
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
897
0
            packet_type_str = val_to_str_const(packet_type, packet_type_sco_br_vals, "Unknown");
898
0
            packet_type_table = packet_type_sco_br_table;
899
7
        } else if (payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_BR)) {
900
0
            proto_tree_add_item(header_tree, hf_packet_header_type_esco_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
901
902
0
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
903
0
            packet_type_str = val_to_str_const(packet_type, packet_type_esco_br_vals, "Unknown");
904
0
            packet_type_table = packet_type_esco_br_table;
905
7
        } else if (payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_EDR_3)) {
906
0
            proto_tree_add_item(header_tree, hf_packet_header_type_esco_edr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
907
908
0
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
909
0
            packet_type_str = val_to_str_const(packet_type, packet_type_esco_edr_vals, "Unknown");
910
0
            packet_type_table = packet_type_esco_edr_table;
911
7
        } else if (payload_and_transport == (TRANSPORT_ACL | PAYLOAD_BR)) {
912
2
            proto_tree_add_item(header_tree, hf_packet_header_type_acl_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
913
914
2
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
915
2
            packet_type_str = val_to_str_const(packet_type, packet_type_acl_br_vals, "Unknown");
916
2
            packet_type_table = packet_type_acl_br_table;
917
5
        } else if (payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_3)) {
918
0
            proto_tree_add_item(header_tree, hf_packet_header_type_acl_edr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
919
920
0
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
921
0
            packet_type_str = val_to_str_const(packet_type, packet_type_acl_edr_vals, "Unknown");
922
0
            packet_type_table = packet_type_acl_edr_table;
923
5
        } else if (payload_and_transport == (TRANSPORT_CPB | PAYLOAD_BR)) {
924
2
            proto_tree_add_item(header_tree, hf_packet_header_type_cpb_br, tvb, offset, 4, ENC_LITTLE_ENDIAN);
925
926
2
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
927
2
            packet_type_str = val_to_str_const(packet_type, packet_type_cpb_br_vals, "Unknown");
928
2
            packet_type_table = packet_type_cpb_br_table;
929
3
        } else if (payload_and_transport == (TRANSPORT_CPB | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_3)) {
930
0
            proto_tree_add_item(header_tree, hf_packet_header_type_cpb_edr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
931
932
0
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
933
0
            packet_type_str = val_to_str_const(packet_type, packet_type_cpb_edr_vals, "Unknown");
934
0
            packet_type_table = packet_type_cpb_edr_table;
935
3
        } else if ((payload_and_transport >> 4) == TRANSPORT_ANY) {
936
1
            proto_tree_add_item(header_tree, hf_packet_header_type_any, tvb, offset, 4, ENC_LITTLE_ENDIAN);
937
938
1
            packet_type = (tvb_get_uint8(tvb, offset) >> 3) & 0xF;
939
1
            packet_type_str = val_to_str_const(packet_type, packet_type_any_vals, "Unknown");
940
2
        } else {
941
2
            proto_tree_add_item(header_tree, hf_packet_header_type, tvb, offset, 4, ENC_LITTLE_ENDIAN);
942
2
        }
943
944
7
        proto_tree_add_item(header_tree, hf_packet_header_flow_control, tvb, offset, 4, ENC_LITTLE_ENDIAN);
945
7
        proto_tree_add_item(header_tree, hf_packet_header_acknowledge_indication, tvb, offset, 4, ENC_LITTLE_ENDIAN);
946
7
        proto_tree_add_item(header_tree, hf_packet_header_sequence_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
947
7
        hec_item = proto_tree_add_item(header_tree, hf_packet_header_header_error_check, tvb, offset, 4, ENC_LITTLE_ENDIAN);
948
7
        proto_tree_add_item(header_tree, hf_packet_header_reserved, tvb, offset, 4, ENC_LITTLE_ENDIAN);
949
7
    }
950
951
14
    switch (header_mode) {
952
0
    case -2:
953
0
        col_set_str(pinfo->cinfo, COL_INFO, (lap == 0x9e8b33) ? "GIAC" : "DIAC");
954
0
        break;
955
956
6
    case -1:
957
6
        expert_add_info(pinfo, hec_item, &ei_packet_header_with_hec_not_checked);
958
6
        break;
959
960
7
    case 0:
961
7
        expert_add_info(pinfo, hec_item, &ei_incorrect_packet_header_or_hec);
962
7
        break;
963
964
0
    case 2:
965
0
        expert_add_info(pinfo, header_item, &ei_broken_packet_header_format);
966
0
        break;
967
968
0
    default:
969
0
        break;
970
14
    }
971
972
13
    if (header_mode > 0 && ltaddr)
973
0
        connection_info = lookup_connection_info(interface_id, adapter_id, lap, ltaddr, pinfo->num);
974
975
13
    if (connection_info && direction >= 0) {
976
0
        set_address(&pinfo->dl_src, AT_ETHER, sizeof(connection_info->bd_addr[0]), connection_info->bd_addr[direction]);
977
0
        set_address(&pinfo->dl_dst, AT_ETHER, sizeof(connection_info->bd_addr[0]), connection_info->bd_addr[1 - direction]);
978
0
        set_address(&pinfo->net_src, AT_ETHER, sizeof(connection_info->bd_addr[0]), connection_info->bd_addr[direction]);
979
0
        set_address(&pinfo->net_dst, AT_ETHER, sizeof(connection_info->bd_addr[0]), connection_info->bd_addr[1 - direction]);
980
13
    } else {
981
13
        clear_address(&pinfo->dl_dst);
982
13
        clear_address(&pinfo->net_dst);
983
13
        if (header_mode > 0 && !ltaddr && device_info) {
984
0
            set_address(&pinfo->dl_src, AT_ETHER, sizeof(device_info->bd_addr), device_info->bd_addr);
985
0
            set_address(&pinfo->net_src, AT_ETHER, sizeof(device_info->bd_addr), device_info->bd_addr);
986
13
        } else {
987
13
            clear_address(&pinfo->dl_src);
988
13
            clear_address(&pinfo->net_src);
989
13
        }
990
13
    }
991
13
    copy_address_shallow(&pinfo->src, &pinfo->net_src);
992
13
    copy_address_shallow(&pinfo->dst, &pinfo->net_dst);
993
994
13
    offset += 4;
995
996
13
    flags_item = proto_tree_add_item(btbredr_rf_tree, hf_flags, tvb, offset, 2, ENC_LITTLE_ENDIAN);
997
13
    flags_tree = proto_item_add_subtree(flags_item, ett_flags);
998
999
13
    flags = tvb_get_uint16(tvb, offset, ENC_LITTLE_ENDIAN);
1000
1001
13
    reserved_item = proto_tree_add_item(flags_tree, hf_flags_reserved_15_14, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1002
13
    if (flags & 0xC000) {
1003
5
        expert_add_info(pinfo, reserved_item, &ei_reserved_not_zero);
1004
5
    }
1005
1006
13
    proto_tree_add_item(flags_tree, hf_flags_mic_pass, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1007
13
    proto_tree_add_item(flags_tree, hf_flags_mic_checked, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1008
13
    proto_tree_add_item(flags_tree, hf_flags_crc_pass, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1009
13
    proto_tree_add_item(flags_tree, hf_flags_crc_checked, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1010
13
    proto_tree_add_item(flags_tree, hf_flags_hec_pass, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1011
13
    proto_tree_add_item(flags_tree, hf_flags_hec_checked, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1012
13
    proto_tree_add_item(flags_tree, hf_flags_reference_upper_address_part_valid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1013
13
    proto_tree_add_item(flags_tree, hf_flags_rf_channel_aliasing, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1014
13
    proto_tree_add_item(flags_tree, hf_flags_br_edr_data_present, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1015
13
    proto_tree_add_item(flags_tree, hf_flags_reference_lower_address_part_valid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1016
13
    proto_tree_add_item(flags_tree, hf_flags_bredr_payload_decrypted, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1017
13
    proto_tree_add_item(flags_tree, hf_flags_noise_power_valid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1018
13
    proto_tree_add_item(flags_tree, hf_flags_signal_power_valid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1019
13
    proto_tree_add_item(flags_tree, hf_flags_packet_header_and_br_edr_payload_dewhitened, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1020
1021
13
    offset += 2;
1022
1023
13
    if ((flags & (FLAGS_SIGNAL_POWER_VALID | FLAGS_NOISE_POWER_VALID)) == (FLAGS_SIGNAL_POWER_VALID | FLAGS_NOISE_POWER_VALID)) {
1024
4
        col_append_fstr(pinfo->cinfo, COL_INFO, " (SP: %4i, NP: %4i)",
1025
4
                (int)tvb_get_int8(tvb, 1), (int)tvb_get_int8(tvb, 2));
1026
9
    } else if (flags & FLAGS_SIGNAL_POWER_VALID) {
1027
2
        col_append_fstr(pinfo->cinfo, COL_INFO, " (SP: %4i)",
1028
2
                (int)tvb_get_int8(tvb, 1));
1029
7
    } else if (flags & FLAGS_NOISE_POWER_VALID) {
1030
1
        col_append_fstr(pinfo->cinfo, COL_INFO, " (NP: %4i)",
1031
1
                (int)tvb_get_int8(tvb, 2));
1032
1
    }
1033
1034
13
   if (flags & FLAGS_PACKET_HEADER_AND_BR_EDR_PAYLOAD_DEWHITENED)
1035
8
        col_append_fstr(pinfo->cinfo, COL_INFO, ", Packet Type: %s", packet_type_str);
1036
1037
   // Packet Type Table
1038
13
   if (payload_and_transport == (TRANSPORT_SCO | PAYLOAD_BR)) {
1039
0
       switch (packet_type) {
1040
0
       case 0: // NULL
1041
0
       case 1: // POLL
1042
0
           isochronous_length = 0;
1043
0
           isochronous_crc = false;
1044
0
           data_length = 0;
1045
0
           data_header = 0;
1046
0
           data_crc = false;
1047
0
           break;
1048
1049
0
       case 2: // FHS
1050
0
           isochronous_length = 0;
1051
0
           isochronous_crc = false;
1052
0
           data_length = 18;
1053
0
           data_header = 0;
1054
0
           data_crc = true;
1055
0
           decrypted = true;
1056
0
           break;
1057
1058
0
       case 3: // DM1
1059
0
           isochronous_length = 0;
1060
0
           isochronous_crc = false;
1061
0
           data_length = 18;
1062
0
           data_header = 1;
1063
0
           data_crc = true;
1064
0
           break;
1065
1066
0
       case 5: // HV1
1067
0
           isochronous_length = 10;
1068
0
           isochronous_crc = false;
1069
0
           data_length = 0;
1070
0
           data_header = 0;
1071
0
           data_crc = false;
1072
0
           break;
1073
1074
0
       case 6: // HV2
1075
0
           isochronous_length = 20;
1076
0
           isochronous_crc = false;
1077
0
           data_length = 0;
1078
0
           data_header = 0;
1079
0
           data_crc = false;
1080
0
           break;
1081
1082
0
       case 7: // HV3
1083
0
           isochronous_length = 30;
1084
0
           isochronous_crc = false;
1085
0
           data_length = 0;
1086
0
           data_header = 0;
1087
0
           data_crc = false;
1088
0
           break;
1089
1090
0
       case 8: // DV
1091
0
           isochronous_length = 10;
1092
0
           isochronous_crc = false;
1093
0
           data_length = 10;
1094
0
           data_header = 1;
1095
0
           data_crc = true;
1096
0
           break;
1097
1098
0
       default:
1099
0
           break;
1100
0
       }
1101
13
   } else if (payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_BR)) {
1102
0
       switch (packet_type) {
1103
0
       case 0: // NULL
1104
0
       case 1: // POLL
1105
0
           isochronous_length = 0;
1106
0
           isochronous_crc = false;
1107
0
           data_length = 0;
1108
0
           data_header = 0;
1109
0
           data_crc = false;
1110
0
           break;
1111
1112
0
       case 7: // EV3
1113
0
           isochronous_length = 30;
1114
0
           isochronous_crc = true;
1115
0
           isochronous_esco = true;
1116
0
           data_length = 0;
1117
0
           data_header = 0;
1118
0
           data_crc = false;
1119
0
           break;
1120
1121
0
       case 12: // EV4
1122
0
           isochronous_length = 120;
1123
0
           isochronous_crc = true;
1124
0
           isochronous_esco = true;
1125
0
           data_length = 0;
1126
0
           data_header = 0;
1127
0
           data_crc = false;
1128
0
           break;
1129
1130
0
       case 13: // EV5
1131
0
           isochronous_length = 180;
1132
0
           isochronous_crc = true;
1133
0
           isochronous_esco = true;
1134
0
           data_length = 0;
1135
0
           data_header = 0;
1136
0
           data_crc = false;
1137
0
           break;
1138
1139
0
       default:
1140
0
           break;
1141
0
       }
1142
13
   } else if (payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_eSCO | PAYLOAD_EDR_3)) {
1143
1
       switch (packet_type) {
1144
0
       case 0: // NULL
1145
0
       case 1: // POLL
1146
0
           isochronous_length = 0;
1147
0
           isochronous_crc = false;
1148
0
           data_length = 0;
1149
0
           data_header = 0;
1150
0
           data_crc = false;
1151
0
           break;
1152
1153
0
       case 6: // 2-EV3
1154
0
           isochronous_length = 60;
1155
0
           isochronous_crc = true;
1156
0
           isochronous_esco = true;
1157
0
           data_length = 0;
1158
0
           data_header = 0;
1159
0
           data_crc = false;
1160
0
           break;
1161
1162
0
       case 7: // 3-EV3
1163
0
           isochronous_length = 90;
1164
0
           isochronous_crc = true;
1165
0
           isochronous_esco = true;
1166
0
           data_length = 0;
1167
0
           data_header = 0;
1168
0
           data_crc = false;
1169
0
           break;
1170
1171
0
       case 12: // 2-EV5
1172
0
           isochronous_length = 360;
1173
0
           isochronous_crc = true;
1174
0
           isochronous_esco = true;
1175
0
           data_length = 0;
1176
0
           data_header = 0;
1177
0
           data_crc = false;
1178
0
           break;
1179
1180
0
       case 13: // 3-EV5
1181
0
           isochronous_length = 540;
1182
0
           isochronous_crc = true;
1183
0
           isochronous_esco = true;
1184
0
           data_length = 0;
1185
0
           data_header = 0;
1186
0
           data_crc = false;
1187
0
           break;
1188
1189
1
       default:
1190
1
           break;
1191
1
       }
1192
12
   } else if (payload_and_transport == (TRANSPORT_ACL | PAYLOAD_BR)) {
1193
2
       switch (packet_type) {
1194
0
       case 0: // NULL
1195
0
       case 1: // POLL
1196
0
           isochronous_length = 0;
1197
0
           isochronous_crc = false;
1198
0
           data_length = 0;
1199
0
           data_header = 0;
1200
0
           data_crc = false;
1201
0
           break;
1202
1203
0
       case 2: // FHS
1204
0
           isochronous_length = 0;
1205
0
           isochronous_crc = false;
1206
0
           data_length = 18;
1207
0
           data_header = 0;
1208
0
           data_crc = true;
1209
0
           decrypted = true;
1210
0
           break;
1211
1212
0
       case 3: // DM1
1213
0
           isochronous_length = 0;
1214
0
           isochronous_crc = false;
1215
0
           data_length = 18;
1216
0
           data_header = 1;
1217
0
           data_crc = true;
1218
0
           break;
1219
1220
0
       case 4: // DH1
1221
0
           isochronous_length = 0;
1222
0
           isochronous_crc = false;
1223
0
           data_length = 28;
1224
0
           data_header = 1;
1225
0
           data_crc = true;
1226
0
           break;
1227
1228
0
       case 9: // AUX1
1229
0
           isochronous_length = 0;
1230
0
           isochronous_crc = false;
1231
0
           data_length = 30;
1232
0
           data_header = 1;
1233
0
           data_crc = false;
1234
0
           break;
1235
1236
0
       case 10: // DM3
1237
0
           isochronous_length = 0;
1238
0
           isochronous_crc = false;
1239
0
           data_length = 123;
1240
0
           data_header = 2;
1241
0
           data_crc = true;
1242
0
           break;
1243
1244
0
       case 11: // DH3
1245
0
           isochronous_length = 0;
1246
0
           isochronous_crc = false;
1247
0
           data_length = 185;
1248
0
           data_header = 2;
1249
0
           data_crc = true;
1250
0
           break;
1251
1252
0
       case 14: // DM5
1253
0
           isochronous_length = 0;
1254
0
           isochronous_crc = false;
1255
0
           data_length = 226;
1256
0
           data_header = 2;
1257
0
           data_crc = true;
1258
0
           break;
1259
1260
0
       case 15: // DH5
1261
0
           isochronous_length = 0;
1262
0
           isochronous_crc = false;
1263
0
           data_length = 341;
1264
0
           data_header = 2;
1265
0
           data_crc = true;
1266
0
           break;
1267
1268
2
       default:
1269
2
           break;
1270
2
       }
1271
10
   } else if (payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_3)) {
1272
0
       switch (packet_type) {
1273
0
       case 0: // NULL
1274
0
       case 1: // POLL
1275
0
           isochronous_length = 0;
1276
0
           isochronous_crc = false;
1277
0
           data_length = 0;
1278
0
           data_header = 0;
1279
0
           data_crc = false;
1280
0
           break;
1281
1282
0
       case 2: // FHS
1283
0
           isochronous_length = 0;
1284
0
           isochronous_crc = false;
1285
0
           data_length = 18;
1286
0
           data_header = 0;
1287
0
           data_crc = true;
1288
0
           decrypted = true;
1289
0
           break;
1290
1291
0
       case 3: // DM1
1292
0
           isochronous_length = 0;
1293
0
           isochronous_crc = false;
1294
0
           data_length = 18;
1295
0
           data_header = 1;
1296
0
           data_crc = true;
1297
0
           break;
1298
1299
0
       case 4: // 2-DH1
1300
0
           isochronous_length = 0;
1301
0
           isochronous_crc = false;
1302
0
           data_length = 56;
1303
0
           data_header = 2;
1304
0
           data_crc = true;
1305
0
           break;
1306
1307
0
       case 8: // 3-DH1
1308
0
           isochronous_length = 0;
1309
0
           isochronous_crc = false;
1310
0
           data_length = 85;
1311
0
           data_header = 2;
1312
0
           data_crc = true;
1313
0
           break;
1314
1315
0
       case 9: // AUX1
1316
0
           isochronous_length = 0;
1317
0
           isochronous_crc = false;
1318
0
           data_length = 30;
1319
0
           data_header = 1;
1320
0
           data_crc = false;
1321
0
           break;
1322
1323
0
       case 10: // 2-DH3
1324
0
           isochronous_length = 0;
1325
0
           isochronous_crc = false;
1326
0
           data_length = 369;
1327
0
           data_header = 2;
1328
0
           data_crc = true;
1329
0
           break;
1330
1331
0
       case 11: // 3-DH3
1332
0
           isochronous_length = 0;
1333
0
           isochronous_crc = false;
1334
0
           data_length = 554;
1335
0
           data_header = 2;
1336
0
           data_crc = true;
1337
0
           break;
1338
1339
0
       case 14: // 2-DH5
1340
0
           isochronous_length = 0;
1341
0
           isochronous_crc = false;
1342
0
           data_length = 681;
1343
0
           data_header = 2;
1344
0
           data_crc = true;
1345
0
           break;
1346
1347
0
       case 15: // 3-DH5
1348
0
           isochronous_length = 0;
1349
0
           isochronous_crc = false;
1350
0
           data_length = 1023;
1351
0
           data_header = 2;
1352
0
           data_crc = true;
1353
0
           break;
1354
1355
0
       default:
1356
0
           break;
1357
0
       }
1358
10
   } else if (payload_and_transport == (TRANSPORT_CPB | PAYLOAD_BR)) {
1359
3
       switch (packet_type) {
1360
0
       case 0: // NULL
1361
0
           isochronous_length = 0;
1362
0
           isochronous_crc = false;
1363
0
           data_length = 0;
1364
0
           data_header = 0;
1365
0
           data_crc = false;
1366
0
           break;
1367
1368
0
       case 3: // DM1
1369
0
           isochronous_length = 0;
1370
0
           isochronous_crc = false;
1371
0
           data_length = 18;
1372
0
           data_header = 1;
1373
0
           data_crc = true;
1374
0
           break;
1375
1376
0
       case 4: // DH1
1377
0
           isochronous_length = 0;
1378
0
           isochronous_crc = false;
1379
0
           data_length = 28;
1380
0
           data_header = 1;
1381
0
           data_crc = true;
1382
0
           break;
1383
1384
0
       case 10: // DM3
1385
0
           isochronous_length = 0;
1386
0
           isochronous_crc = false;
1387
0
           data_length = 123;
1388
0
           data_header = 2;
1389
0
           data_crc = true;
1390
0
           break;
1391
1392
0
       case 11: // DH3
1393
0
           isochronous_length = 0;
1394
0
           isochronous_crc = false;
1395
0
           data_length = 185;
1396
0
           data_header = 2;
1397
0
           data_crc = true;
1398
0
           break;
1399
1400
0
       case 14: // DM5
1401
0
           isochronous_length = 0;
1402
0
           isochronous_crc = false;
1403
0
           data_length = 226;
1404
0
           data_header = 2;
1405
0
           data_crc = true;
1406
0
           break;
1407
1408
2
       case 15: // DH5
1409
2
           isochronous_length = 0;
1410
2
           isochronous_crc = false;
1411
2
           data_length = 341;
1412
2
           data_header = 2;
1413
2
           data_crc = true;
1414
2
           break;
1415
1416
1
       default:
1417
1
           break;
1418
3
       }
1419
7
   } else if (payload_and_transport == (TRANSPORT_CPB | PAYLOAD_EDR_2) || payload_and_transport == (TRANSPORT_ACL | PAYLOAD_EDR_3)) {
1420
0
       switch (packet_type) {
1421
0
       case 0: // NULL
1422
0
           isochronous_length = 0;
1423
0
           isochronous_crc = false;
1424
0
           data_length = 0;
1425
0
           data_header = 0;
1426
0
           data_crc = false;
1427
0
           break;
1428
1429
0
       case 3: // DM1
1430
0
           isochronous_length = 0;
1431
0
           isochronous_crc = false;
1432
0
           data_length = 18;
1433
0
           data_header = 1;
1434
0
           data_crc = true;
1435
0
           break;
1436
1437
0
       case 4: // 2-DH1
1438
0
           isochronous_length = 0;
1439
0
           isochronous_crc = false;
1440
0
           data_length = 56;
1441
0
           data_header = 2;
1442
0
           data_crc = true;
1443
0
           break;
1444
1445
0
       case 8: // 3-DH1
1446
0
           isochronous_length = 0;
1447
0
           isochronous_crc = false;
1448
0
           data_length = 85;
1449
0
           data_header = 2;
1450
0
           data_crc = true;
1451
0
           break;
1452
1453
0
       case 10: // 2-DH3
1454
0
           isochronous_length = 0;
1455
0
           isochronous_crc = false;
1456
0
           data_length = 369;
1457
0
           data_header = 2;
1458
0
           data_crc = true;
1459
0
           break;
1460
1461
0
       case 11: // 3-DH3
1462
0
           isochronous_length = 0;
1463
0
           isochronous_crc = false;
1464
0
           data_length = 554;
1465
0
           data_header = 2;
1466
0
           data_crc = true;
1467
0
           break;
1468
1469
0
       case 14: // 2-DH5
1470
0
           isochronous_length = 0;
1471
0
           isochronous_crc = false;
1472
0
           data_length = 681;
1473
0
           data_header = 2;
1474
0
           data_crc = true;
1475
0
           break;
1476
1477
0
       case 15: // 3-DH5
1478
0
           isochronous_length = 0;
1479
0
           isochronous_crc = false;
1480
0
           data_length = 1023;
1481
0
           data_header = 2;
1482
0
           data_crc = true;
1483
0
           break;
1484
1485
0
       default:
1486
0
           break;
1487
0
       }
1488
7
   } else if ((payload_and_transport >> 4) == TRANSPORT_ANY) {
1489
1
       switch (packet_type) {
1490
1
       case 0: // NULL
1491
1
       case 1: // POLL
1492
1
           isochronous_length = 0;
1493
1
           isochronous_crc = false;
1494
1
           data_length = 0;
1495
1
           data_header = 0;
1496
1
           data_crc = false;
1497
1
           break;
1498
1499
0
       case 2: // FHS
1500
0
           isochronous_length = 0;
1501
0
           isochronous_crc = false;
1502
0
           data_length = 18;
1503
0
           data_header = 0;
1504
0
           data_crc = true;
1505
0
           decrypted = true;
1506
0
           break;
1507
1508
0
       case 3: // DM1
1509
0
           isochronous_length = 0;
1510
0
           isochronous_crc = false;
1511
0
           data_length = 18;
1512
0
           data_header = 1;
1513
0
           data_crc = true;
1514
0
           break;
1515
1516
0
       default:
1517
0
           break;
1518
1
       }
1519
1
   }
1520
1521
13
   if (flags & FLAGS_BR_EDR_DATA_PRESENT) {
1522
8
       if (flags & FLAGS_PACKET_HEADER_AND_BR_EDR_PAYLOAD_DEWHITENED) {
1523
7
           if (decrypted) {
1524
4
               tvbuff_t       *next_tvb;
1525
1526
4
               next_tvb = tvb_new_subset_remaining(tvb, offset);
1527
4
               if (packet_type_table && packet_type > PACKET_TYPE_UNKNOWN &&
1528
3
                   dissector_try_uint_with_data(packet_type_table, packet_type, next_tvb, pinfo, tree, true, bluetooth_data)) {
1529
0
                   offset = tvb_reported_length(tvb);
1530
4
               } else {
1531
4
                   if (isochronous_length > 0 &&
1532
0
                       (!isochronous_crc || (flags & (FLAGS_CRC_PASS | FLAGS_CRC_CHECKED)) == (FLAGS_CRC_PASS | FLAGS_CRC_CHECKED))) {
1533
0
                       int len = tvb_captured_length_remaining(tvb, offset);
1534
0
                       if (isochronous_crc)
1535
0
                           len -= 2;
1536
0
                       if (isochronous_length > len)
1537
0
                           isochronous_length = len;
1538
0
                       if (isochronous_length > 0) {
1539
                           //next_tvb = tvb_new_subset_length(tvb, offset, isochronous_length);
1540
0
                           proto_item *iso_item = proto_tree_add_item(btbredr_rf_tree, hf_isochronous_data, tvb, offset, isochronous_length, ENC_NA);
1541
0
                           if (isochronous_crc) {
1542
0
                               proto_item *crc_item = NULL;
1543
0
                               crc_item = proto_tree_add_item(btbredr_rf_tree, hf_crc, tvb, offset + isochronous_length, 2, ENC_LITTLE_ENDIAN);
1544
0
                               if ((flags & FLAGS_REFERENCE_UPPER_ADDRESS_PART_VALID) && !check_crc(uap, tvb, offset, isochronous_length + 2))
1545
0
                                   expert_add_info(pinfo, crc_item, &ei_incorrect_crc);
1546
0
                               offset += 2;
1547
0
                           }
1548
0
                           offset += isochronous_length;
1549
0
                           if (connection_info) {
1550
0
                               if (connection_info->esco != isochronous_esco)
1551
0
                                   expert_add_info(pinfo, iso_item, &ei_esco_incorrect_ltaddr);
1552
0
                               if (direction >= 0 && connection_info->esco &&
1553
0
                                   connection_info->escosize[direction] != isochronous_length)
1554
0
                                   expert_add_info(pinfo, iso_item, &ei_esco_incorrect_length);
1555
0
                           }
1556
0
                       }
1557
0
                   }
1558
4
                   if (data_length > 0 &&
1559
2
                       (!data_crc || (flags & (FLAGS_CRC_PASS | FLAGS_CRC_CHECKED)) == (FLAGS_CRC_PASS | FLAGS_CRC_CHECKED))) {
1560
2
                       int len = tvb_captured_length_remaining(tvb, offset);
1561
2
                       bool error = false;
1562
2
                       int llid = -1;
1563
2
                       if (data_crc)
1564
2
                           len -= 2;
1565
2
                       if (data_length > len)
1566
2
                           data_length = len;
1567
2
                       if (data_header > 0) {
1568
2
                           if (len < data_header) {
1569
0
                               error = true;
1570
2
                           } else if (data_header == 1) {
1571
0
                               uint8_t hdr = tvb_get_uint8(tvb, offset);
1572
0
                               llid = hdr & 3;
1573
0
                               hdr >>= 3;
1574
0
                               hdr &= 0x1f;
1575
0
                               ++hdr;
1576
0
                               if (hdr > len)
1577
0
                                   error = true;
1578
0
                               else
1579
0
                                   data_length = hdr;
1580
2
                           } else if (data_header == 2) {
1581
2
                               uint16_t hdr = tvb_get_uint16(tvb, offset, ENC_LITTLE_ENDIAN);
1582
2
                               llid = hdr & 3;
1583
2
                               hdr >>= 3;
1584
2
                               hdr &= 0x3ff;
1585
2
                               hdr += 2;
1586
2
                               if (hdr > len)
1587
2
                                   error = true;
1588
0
                               else
1589
0
                                   data_length = hdr;
1590
2
                           } else {
1591
0
                               error = true;
1592
0
                           }
1593
2
                       }
1594
2
                       if (data_length > 0 && !error) {
1595
0
                           bool handled = false;
1596
0
                           fragment_head *frag_l2cap_msg = NULL;
1597
0
                           if (data_header == 1) {
1598
0
                               proto_item *pheader_item = proto_tree_add_item(btbredr_rf_tree, hf_payload_header1, tvb, offset, 1, ENC_LITTLE_ENDIAN);
1599
0
                               proto_tree *pheader_tree = proto_item_add_subtree(pheader_item, ett_payload_header);
1600
0
                               proto_tree_add_item(pheader_tree, hf_payload_header1_llid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
1601
0
                               proto_tree_add_item(pheader_tree, hf_payload_header1_flow, tvb, offset, 1, ENC_LITTLE_ENDIAN);
1602
0
                               proto_tree_add_item(pheader_tree, hf_payload_header1_length, tvb, offset, 1, ENC_LITTLE_ENDIAN);
1603
0
                           } else if (data_header == 2) {
1604
0
                               proto_item *pheader_item = proto_tree_add_item(btbredr_rf_tree, hf_payload_header2, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1605
0
                               proto_tree *pheader_tree = proto_item_add_subtree(pheader_item, ett_payload_header);
1606
0
                               proto_tree_add_item(pheader_tree, hf_payload_header2_llid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1607
0
                               proto_tree_add_item(pheader_tree, hf_payload_header2_flow, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1608
0
                               proto_tree_add_item(pheader_tree, hf_payload_header2_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1609
0
                               proto_tree_add_item(pheader_tree, hf_payload_header2_rfu, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1610
0
                           }
1611
0
                           if (!pinfo->fd->visited) {
1612
0
                               frame_info = wmem_new0(wmem_file_scope(), btbredr_frame_info_t);
1613
0
                               p_add_proto_data(wmem_file_scope(), pinfo, proto_btbredr_rf, pinfo->curr_layer_num, frame_info);
1614
0
                               if (connection_info && direction >= 0) {
1615
0
                                   frame_info->retransmit = (seqn == connection_info->reassembly[direction].seqn);
1616
0
                                   frame_info->ack = arqn;
1617
0
                                   frame_info->l2cap_index = pinfo->num;
1618
0
                                   connection_info->reassembly[direction].seqn = seqn;
1619
0
                               }
1620
0
                           } else {
1621
0
                               frame_info = (btbredr_frame_info_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_btbredr_rf, pinfo->curr_layer_num);
1622
0
                           }
1623
0
                            if (packet_type == 2) {
1624
                               // FHS
1625
0
                               next_tvb = tvb_new_subset_length(tvb, offset + data_header, data_length - data_header);
1626
0
                               if (next_tvb) {
1627
0
                                   btbredr_fhs_data_t *fhs_data = wmem_new0(pinfo->pool, btbredr_fhs_data_t);
1628
0
                                   fhs_data->bluetooth_data  = bluetooth_data;
1629
0
                                   fhs_data->device_info     = device_info;
1630
0
                                   fhs_data->connection_info = connection_info;
1631
0
                                   call_dissector_with_data(btbredr_fhs_handle, next_tvb, pinfo, tree, fhs_data);
1632
0
                                   handled = true;
1633
0
                               }
1634
0
                           }
1635
0
                           switch (llid) {
1636
0
                           case 0x03: // LMP
1637
0
                               if (!btlmp_handle)
1638
0
                                   break;
1639
0
                               next_tvb = tvb_new_subset_length(tvb, offset + data_header, data_length - data_header);
1640
0
                               if (!next_tvb)
1641
0
                                   break;
1642
0
                               call_dissector_with_data(btlmp_handle, next_tvb, pinfo, tree, connection_info);
1643
0
                               handled = true;
1644
0
                               break;
1645
1646
0
                           case 0x02: // Start of or complete L2CAP message
1647
0
                               if (!btl2cap_handle)
1648
0
                                   break;
1649
0
                               if (frame_info && data_length > data_header) {
1650
0
                                   unsigned pdu_len = data_length - data_header;
1651
0
                                   unsigned l2cap_len = tvb_get_letohs(tvb, offset + data_header);
1652
0
                                   if (l2cap_len + 4 <= pdu_len) {
1653
0
                                       bthci_acl_data_t *acl_data = wmem_new(pinfo->pool, bthci_acl_data_t);
1654
0
                                       acl_data->interface_id = interface_id;
1655
0
                                       acl_data->adapter_id   = adapter_id;
1656
0
                                       acl_data->chandle      = 0; /* No connection handle at this layer */
1657
0
                                       acl_data->remote_bd_addr_oui = 0;
1658
0
                                       acl_data->remote_bd_addr_id  = 0;
1659
0
                                       acl_data->is_btle = true;
1660
0
                                       acl_data->is_btle_retransmit = false;
1661
0
                                       acl_data->adapter_disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
1662
0
                                       acl_data->disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
1663
0
                                       next_tvb = tvb_new_subset_length(tvb, offset + data_header, pdu_len);
1664
0
                                       call_dissector_with_data(btl2cap_handle, next_tvb, pinfo, tree, acl_data);
1665
0
                                       handled = true;
1666
0
                                       col_set_str(pinfo->cinfo, COL_INFO, "L2CAP Data");
1667
0
                                       if (!pinfo->fd->visited && connection_info && direction >= 0) {
1668
0
                                           connection_info->reassembly[direction].l2cap_index = pinfo->num;
1669
0
                                           connection_info->reassembly[direction].segment_len_rem = 0;
1670
0
                                       }
1671
0
                                       break;
1672
0
                                   }
1673
0
                                   pinfo->fragmented = true;
1674
0
                                   if (!frame_info->retransmit && connection_info && direction >= 0) {
1675
0
                                       if (!pinfo->fd->visited) {
1676
0
                                           connection_info->reassembly[direction].l2cap_index = pinfo->num;
1677
0
                                           connection_info->reassembly[direction].segment_len_rem = l2cap_len + 4 - pdu_len;
1678
0
                                           frame_info->more_fragments = 1;
1679
0
                                       }
1680
0
                                       frag_l2cap_msg = fragment_add_seq_next(&l2cap_msg_reassembly_table,
1681
0
                                                                              tvb, offset + data_header,
1682
0
                                                                              pinfo,
1683
0
                                                                              frame_info->l2cap_index,      /* uint32_t ID for fragments belonging together */
1684
0
                                                                              NULL,                         /* data* */
1685
0
                                                                              pdu_len,                      /* Fragment length */
1686
0
                                                                              frame_info->more_fragments);  /* More fragments */
1687
0
                                       process_reassembled_data(tvb, offset + data_header, pinfo,
1688
0
                                                                "Reassembled L2CAP",
1689
0
                                                                frag_l2cap_msg,
1690
0
                                                                &l2cap_msg_frag_items,
1691
0
                                                                NULL,
1692
0
                                                                btbredr_rf_tree);
1693
0
                                   }
1694
0
                                   proto_tree_add_item(btbredr_rf_tree, hf_l2cap_fragment, tvb, offset + data_header, pdu_len, ENC_NA);
1695
0
                                   handled = true;
1696
0
                                   col_set_str(pinfo->cinfo, COL_INFO, "L2CAP Fragment Start");
1697
0
                               }
1698
0
                               break;
1699
1700
0
                           case 0x01: /* Continuation fragment of an L2CAP message, or an Empty PDU */
1701
0
                               if (!btl2cap_handle)
1702
0
                                   break;
1703
0
                               if (!frame_info || data_length <= data_header) {
1704
0
                                   col_set_str(pinfo->cinfo, COL_INFO, "Empty PDU");
1705
0
                                   break;
1706
0
                               }
1707
0
                               pinfo->fragmented = true;
1708
0
                               if (!frame_info->retransmit && connection_info && direction >= 0) {
1709
0
                                   unsigned pdu_len = data_length - data_header;
1710
0
                                   if (!pinfo->fd->visited) {
1711
0
                                       if (connection_info->reassembly[direction].segment_len_rem > 0) {
1712
0
                                           if (connection_info->reassembly[direction].segment_len_rem >= pdu_len) {
1713
0
                                               connection_info->reassembly[direction].segment_len_rem -= pdu_len;
1714
0
                                               frame_info->l2cap_index = connection_info->reassembly[direction].l2cap_index;
1715
0
                                           } else {
1716
                                               /*
1717
                                                * Missing fragment for previous L2CAP and fragment start for this.
1718
                                                * Set more_fragments and increase l2cap_index to avoid reassembly.
1719
                                                */
1720
0
                                               frame_info->more_fragments = 1;
1721
0
                                               frame_info->missing_start = 1;
1722
0
                                               connection_info->reassembly[direction].l2cap_index = pinfo->num;
1723
0
                                               connection_info->reassembly[direction].segment_len_rem = 0;
1724
0
                                           }
1725
0
                                           frame_info->more_fragments = (connection_info->reassembly[direction].segment_len_rem > 0);
1726
0
                                       } else {
1727
                                           /*
1728
                                            * Missing fragment start.
1729
                                            * Set more_fragments and increase l2cap_index to avoid reassembly.
1730
                                            */
1731
0
                                           frame_info->more_fragments = 1;
1732
0
                                           frame_info->missing_start = 1;
1733
0
                                           connection_info->reassembly[direction].l2cap_index = pinfo->num;
1734
0
                                           connection_info->reassembly[direction].segment_len_rem = 0;
1735
0
                                       }
1736
0
                                   }
1737
0
                                   frag_l2cap_msg = fragment_add_seq_next(&l2cap_msg_reassembly_table,
1738
0
                                                                          tvb, offset + data_header,
1739
0
                                                                          pinfo,
1740
0
                                                                          frame_info->l2cap_index,      /* uint32_t ID for fragments belonging together */
1741
0
                                                                          NULL,                         /* data* */
1742
0
                                                                          pdu_len,                      /* Fragment length */
1743
0
                                                                          frame_info->more_fragments);  /* More fragments */
1744
0
                                   next_tvb = process_reassembled_data(tvb, offset, pinfo,
1745
0
                                                                       "Reassembled L2CAP",
1746
0
                                                                       frag_l2cap_msg,
1747
0
                                                                       &l2cap_msg_frag_items,
1748
0
                                                                       NULL,
1749
0
                                                                       btbredr_rf_tree);
1750
0
                               }
1751
0
                               if (next_tvb) {
1752
0
                                   bthci_acl_data_t *acl_data = wmem_new(pinfo->pool, bthci_acl_data_t);
1753
0
                                   acl_data->interface_id = interface_id;
1754
0
                                   acl_data->adapter_id   = adapter_id;
1755
0
                                   acl_data->chandle      = 0; /* No connection handle at this layer */
1756
0
                                   acl_data->remote_bd_addr_oui = 0;
1757
0
                                   acl_data->remote_bd_addr_id  = 0;
1758
0
                                   acl_data->is_btle = true;
1759
0
                                   acl_data->is_btle_retransmit = false;
1760
0
                                   acl_data->adapter_disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
1761
0
                                   acl_data->disconnect_in_frame = &bluetooth_max_disconnect_in_frame;
1762
0
                                   call_dissector_with_data(btl2cap_handle, next_tvb, pinfo, tree, acl_data);
1763
0
                                   handled = true;
1764
0
                                   col_set_str(pinfo->cinfo, COL_INFO, "L2CAP Data");
1765
0
                               } else {
1766
0
                                   proto_item *item = proto_tree_add_item(btbredr_rf_tree, hf_l2cap_fragment, tvb, offset + data_header, data_length - data_header, ENC_NA);
1767
0
                                   if (frame_info->missing_start)
1768
0
                                       expert_add_info(pinfo, item, &ei_missing_fragment_start);
1769
0
                                   handled = true;
1770
0
                                   col_set_str(pinfo->cinfo, COL_INFO, "L2CAP Fragment");
1771
0
                               }
1772
0
                               break;
1773
1774
0
                           default:
1775
0
                               break;
1776
0
                           }
1777
0
                           if (!handled)
1778
0
                               proto_tree_add_item(btbredr_rf_tree, hf_asynchronous_data, tvb, offset + data_header, data_length - data_header, ENC_NA);
1779
0
                           if (data_crc) {
1780
0
                               proto_item *crc_item = NULL;
1781
0
                               crc_item = proto_tree_add_item(btbredr_rf_tree, hf_crc, tvb, offset + data_length, 2, ENC_LITTLE_ENDIAN);
1782
0
                               if ((flags & FLAGS_REFERENCE_UPPER_ADDRESS_PART_VALID) && !check_crc(uap, tvb, offset, data_length + 2))
1783
0
                                   expert_add_info(pinfo, crc_item, &ei_incorrect_crc);
1784
0
                               offset += 2;
1785
0
                           }
1786
0
                           offset += data_length;
1787
0
                       }
1788
2
                   }
1789
4
                   if (tvb_captured_length_remaining(tvb, offset) > 0)
1790
4
                       proto_tree_add_item(btbredr_rf_tree, hf_data, tvb, offset, tvb_captured_length_remaining(tvb, offset), ENC_NA);
1791
4
               }
1792
4
           } else {
1793
3
               proto_tree_add_item(btbredr_rf_tree, hf_encrypted_data, tvb, offset, tvb_captured_length_remaining(tvb, offset), ENC_NA);
1794
3
               offset = tvb_reported_length(tvb);
1795
3
           }
1796
7
       } else {
1797
1
           proto_tree_add_item(btbredr_rf_tree, hf_whitened_data, tvb, offset, tvb_captured_length_remaining(tvb, offset), ENC_NA);
1798
1
           offset = tvb_reported_length(tvb);
1799
1
       }
1800
8
   } else {
1801
5
       if (tvb_captured_length_remaining(tvb, offset) > 0)
1802
4
           proto_tree_add_expert(btbredr_rf_tree, pinfo, &ei_unexpected_data, tvb, offset, tvb_captured_length_remaining(tvb, offset));
1803
5
       offset = tvb_reported_length(tvb);
1804
5
   }
1805
1806
13
   if (!pinfo->fd->visited) {
1807
13
       address *addr;
1808
1809
13
       addr = (address *) wmem_memdup(wmem_file_scope(), &pinfo->dl_src, sizeof(address));
1810
13
       addr->data =  wmem_memdup(wmem_file_scope(), pinfo->dl_src.data, pinfo->dl_src.len);
1811
13
       p_add_proto_data(wmem_file_scope(), pinfo, proto_bluetooth, BLUETOOTH_DATA_SRC, addr);
1812
1813
13
       addr = (address *) wmem_memdup(wmem_file_scope(), &pinfo->dl_dst, sizeof(address));
1814
13
       addr->data =  wmem_memdup(wmem_file_scope(), pinfo->dl_dst.data, pinfo->dl_dst.len);
1815
13
       p_add_proto_data(wmem_file_scope(), pinfo, proto_bluetooth, BLUETOOTH_DATA_DST, addr);
1816
13
   }
1817
1818
13
   return offset;
1819
13
}
1820
1821
static int
1822
dissect_btbredr_fhs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1823
0
{
1824
0
    proto_item         *btbredr_fhs_item;
1825
0
    proto_tree         *btbredr_fhs_tree;
1826
0
    int                 offset = 0;
1827
0
    uint32_t            interface_id;
1828
0
    uint32_t            adapter_id;
1829
0
    uint64_t            parity_lap_eir_sp_sr;
1830
0
    uint32_t            lap;
1831
0
    uint8_t             uap;
1832
0
    uint16_t            nap;
1833
0
    uint32_t            ltaddr_clk_pgscan;
1834
0
    uint32_t            ltaddr;
1835
0
    device_info_t      *device_info = NULL;
1836
0
    connection_info_t  *connection_info = NULL;
1837
0
    btbredr_fhs_data_t *fhs_data = (btbredr_fhs_data_t *) data;
1838
1839
0
    btbredr_fhs_item = proto_tree_add_item(tree, proto_btbredr_fhs, tvb, offset, -1, ENC_NA);
1840
0
    btbredr_fhs_tree = proto_item_add_subtree(btbredr_fhs_item, ett_btbredr_fhs);
1841
1842
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "BT BR/EDR FHS");
1843
1844
0
    if (fhs_data->bluetooth_data)
1845
0
        interface_id = fhs_data->bluetooth_data->interface_id;
1846
0
    else if (pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)
1847
0
        interface_id = pinfo->rec->rec_header.packet_header.interface_id;
1848
0
    else
1849
0
        interface_id = HCI_INTERFACE_DEFAULT;
1850
1851
0
    if (fhs_data->bluetooth_data)
1852
0
        adapter_id = fhs_data->bluetooth_data->adapter_id;
1853
0
    else
1854
0
        adapter_id = HCI_ADAPTER_DEFAULT;
1855
1856
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_parity, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1857
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_lap, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1858
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_eir, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1859
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_reserved, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1860
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_sr, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1861
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_sp, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1862
0
    parity_lap_eir_sp_sr = tvb_get_uint64(tvb, offset, ENC_LITTLE_ENDIAN);
1863
0
    lap = (parity_lap_eir_sp_sr >> 34) & 0xffffff;
1864
0
    offset += 8;
1865
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_uap, tvb, offset, 1, ENC_LITTLE_ENDIAN);
1866
0
    uap = tvb_get_uint8(tvb, offset);
1867
0
    offset += 1;
1868
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_nap, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1869
0
    nap = tvb_get_uint16(tvb, offset, ENC_LITTLE_ENDIAN);
1870
0
    offset += 2;
1871
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_class, tvb, offset, 3, ENC_LITTLE_ENDIAN);
1872
0
    offset += 3;
1873
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_ltaddr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1874
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_clk, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1875
0
    proto_tree_add_item(btbredr_fhs_tree, hf_fhs_pagescanmode, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1876
0
    ltaddr_clk_pgscan = tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN);
1877
0
    offset += 4;
1878
0
    ltaddr = ltaddr_clk_pgscan & 0x00000007;
1879
1880
0
    {
1881
0
        wmem_tree_key_t key[4];
1882
0
        key[0].length = 1;
1883
0
        key[0].key = &interface_id;
1884
0
        key[1].length = 1;
1885
0
        key[1].key = &adapter_id;
1886
0
        key[2].length = 1;
1887
0
        key[2].key = &lap;
1888
0
        key[3].length = 0;
1889
0
        key[3].key = NULL;
1890
1891
0
        device_info = (device_info_t *) wmem_tree_lookup32_array(device_info_tree, key);
1892
0
        if (!device_info && !pinfo->fd->visited) {
1893
0
            device_info = wmem_new0(wmem_file_scope(), device_info_t);
1894
0
            device_info->interface_id   = interface_id;
1895
0
            device_info->adapter_id     = adapter_id;
1896
0
            device_info->bd_addr[0]     = nap >> 8;
1897
0
            device_info->bd_addr[1]     = nap >> 0;
1898
0
            device_info->bd_addr[2]     = uap;
1899
0
            device_info->bd_addr[3]     = lap >> 16;
1900
0
            device_info->bd_addr[4]     = lap >> 8;
1901
0
            device_info->bd_addr[5]     = lap;
1902
0
            device_info->dir            = pinfo->p2p_dir;
1903
0
            wmem_tree_insert32_array(device_info_tree, key, device_info);
1904
0
        }
1905
0
    }
1906
0
    if (ltaddr) {
1907
0
        connection_info = lookup_connection_info(interface_id, adapter_id, lap, ltaddr, pinfo->num);
1908
0
        if (!pinfo->fd->visited) {
1909
0
            if (connection_info && fhs_data->device_info &&
1910
0
                !memcmp(connection_info->bd_addr[BDADDR_PERIPHERAL], null_bd_addr, 6))
1911
0
                memcpy(connection_info->bd_addr[BDADDR_PERIPHERAL], fhs_data->device_info->bd_addr, 6);
1912
0
            if (!connection_info && device_info) {
1913
0
                wmem_tree_key_t key[6];
1914
0
                key[0].length = 1;
1915
0
                key[0].key = &interface_id;
1916
0
                key[1].length = 1;
1917
0
                key[1].key = &adapter_id;
1918
0
                key[2].length = 1;
1919
0
                key[2].key = &lap;
1920
0
                key[3].length = 1;
1921
0
                key[3].key = &ltaddr;
1922
0
                key[4].length = 1;
1923
0
                key[4].key = &pinfo->num;
1924
0
                key[5].length = 0;
1925
0
                key[5].key = NULL;
1926
0
                connection_info = wmem_new0(wmem_file_scope(), connection_info_t);
1927
0
                connection_info->interface_id   = interface_id;
1928
0
                connection_info->adapter_id     = adapter_id;
1929
0
                connection_info->lt_addr        = ltaddr;
1930
0
                connection_info->timestamp      = pinfo->abs_ts;
1931
0
                connection_info->btclock        = (ltaddr_clk_pgscan >> 3) & 0x3ffffff;
1932
0
                memcpy(connection_info->bd_addr[BDADDR_CENTRAL], device_info->bd_addr, 6);
1933
0
                if (fhs_data->device_info)
1934
0
                    memcpy(connection_info->bd_addr[BDADDR_PERIPHERAL], fhs_data->device_info->bd_addr, 6);
1935
0
                wmem_tree_insert32_array(connection_info_tree, key, connection_info);
1936
0
             }
1937
0
        }
1938
0
    }
1939
0
    if (device_info) {
1940
0
        set_address(&pinfo->dl_src, AT_ETHER, sizeof(device_info->bd_addr), device_info->bd_addr);
1941
0
        set_address(&pinfo->net_src, AT_ETHER, sizeof(device_info->bd_addr), device_info->bd_addr);
1942
0
        copy_address_shallow(&pinfo->src, &pinfo->net_src);
1943
0
    }
1944
0
    if (fhs_data->device_info) {
1945
0
        set_address(&pinfo->dl_dst, AT_ETHER, sizeof(fhs_data->device_info->bd_addr), fhs_data->device_info->bd_addr);
1946
0
        set_address(&pinfo->net_dst, AT_ETHER, sizeof(fhs_data->device_info->bd_addr), fhs_data->device_info->bd_addr);
1947
0
        copy_address_shallow(&pinfo->dst, &pinfo->net_dst);
1948
0
    }
1949
0
    return offset;
1950
0
}
1951
1952
void
1953
proto_register_btbredr_rf(void)
1954
14
{
1955
14
    expert_module_t  *expert_module;
1956
1957
14
    static hf_register_info hf[] = {
1958
14
        {  &hf_rf_channel,
1959
14
            { "RF Channel",                                     "btbredr_rf.rf_channel",
1960
14
            FT_UINT8, BASE_DEC, NULL, 0x00,
1961
14
            NULL, HFILL }
1962
14
        },
1963
14
        {  &hf_uncertain_rf_channel,
1964
14
            { "Uncertain RF Channel",                           "btbredr_rf.uncertain_rf_channel",
1965
14
            FT_UINT8, BASE_DEC, NULL, 0x00,
1966
14
            NULL, HFILL }
1967
14
        },
1968
14
        {  &hf_signal_power,
1969
14
            { "Signal Power",                                   "btbredr_rf.signal_power",
1970
14
            FT_INT8, BASE_DEC, NULL, 0x00,
1971
14
            "Signal Power in dBm", HFILL }
1972
14
        },
1973
14
        {  &hf_invalid_signal_power,
1974
14
            { "Invalid Signal Power",                           "btbredr_rf.invalid.signal_power",
1975
14
            FT_INT8, BASE_DEC, NULL, 0x00,
1976
14
            NULL, HFILL }
1977
14
        },
1978
14
        {  &hf_noise_power,
1979
14
            { "Noise Power",                                    "btbredr_rf.noise_power",
1980
14
            FT_INT8, BASE_DEC, NULL, 0x00,
1981
14
            "Noise Power in dBm", HFILL }
1982
14
        },
1983
14
        {  &hf_invalid_noise_power,
1984
14
            { "Invalid Noise Power",                            "btbredr_rf.invalid.noise_power",
1985
14
            FT_INT8, BASE_DEC, NULL, 0x00,
1986
14
            NULL, HFILL }
1987
14
        },
1988
14
        {  &hf_access_address_offenses,
1989
14
            { "Access Address Offenses",                        "btbredr_rf.access_address_offenses",
1990
14
            FT_UINT8, BASE_DEC, NULL, 0x00,
1991
14
            NULL, HFILL }
1992
14
        },
1993
14
        {  &hf_payload_transport_rate,
1994
14
            { "Payload Transport Rate",                         "btbredr_rf.payload_transport_rate",
1995
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
1996
14
            NULL, HFILL }
1997
14
        },
1998
14
        {  &hf_payload_transport_rate_ignored,
1999
14
            { "Payload Transport Rate: Ignored",                "btbredr_rf.payload_transport_rate.ignored",
2000
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
2001
14
            "BT Packet Header is ignored and there is no payload", HFILL }
2002
14
        },
2003
14
        {  &hf_payload_transport_rate_transport,
2004
14
            { "Transport",                                      "btbredr_rf.payload_transport_rate.transport",
2005
14
            FT_UINT8, BASE_HEX, VALS(payload_transport_rate_transport_vals), 0xF0,
2006
14
            NULL, HFILL }
2007
14
        },
2008
14
        {  &hf_payload_transport_rate_payload,
2009
14
            { "Payload",                                        "btbredr_rf.payload_transport_rate.payload",
2010
14
            FT_UINT8, BASE_HEX, VALS(payload_transport_rate_payload_vals), 0x0F,
2011
14
            NULL, HFILL }
2012
14
        },
2013
14
        {  &hf_corrected_header_bits,
2014
14
            { "Corrected Header Bits",                          "btbredr_rf.corrected_header_bits",
2015
14
            FT_UINT8, BASE_DEC, NULL, 0x00,
2016
14
            NULL, HFILL }
2017
14
        },
2018
14
        {  &hf_corrected_payload_bits,
2019
14
            { "Corrected Payload Bits",                         "btbredr_rf.corrected_payload_bits",
2020
14
            FT_INT16, BASE_DEC, NULL, 0x00,
2021
14
            NULL, HFILL }
2022
14
        },
2023
14
        {  &hf_lower_address_part,
2024
14
            { "Lower Address Part",                             "btbredr_rf.lower_address_part",
2025
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
2026
14
            NULL, HFILL }
2027
14
        },
2028
14
        {  &hf_reference_lower_address_part,
2029
14
            { "Reference Lower Address Part",                   "btbredr_rf.reference_lower_address_part",
2030
14
            FT_UINT24, BASE_HEX, NULL, 0x00,
2031
14
            NULL, HFILL }
2032
14
        },
2033
14
        {  &hf_invalid_reference_lower_address_part,
2034
14
            { "Invalid Reference Lower Address Part",           "btbredr_rf.invalid.reference_lower_address_part",
2035
14
            FT_UINT24, BASE_HEX, NULL, 0x00,
2036
14
            NULL, HFILL }
2037
14
        },
2038
14
        {  &hf_reference_upper_address_part,
2039
14
            { "Reference Upper Address Part",                   "btbredr_rf.reference_upper_address_part",
2040
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
2041
14
            NULL, HFILL }
2042
14
        },
2043
14
        {  &hf_invalid_reference_upper_address_part,
2044
14
            { "Invalid Reference Upper Address Part",           "btbredr_rf.invalid.reference_upper_address_part",
2045
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
2046
14
            NULL, HFILL }
2047
14
        },
2048
14
        {  &hf_whitened_packet_header,
2049
14
            { "Whitened Packet Header",                         "btbredr_rf.whitened.packet_header",
2050
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
2051
14
            NULL, HFILL }
2052
14
        },
2053
14
        {  &hf_invalid_packet_header,
2054
14
            { "Invalid Packet Header",                          "btbredr_rf.invalid.packet_header",
2055
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
2056
14
            NULL, HFILL }
2057
14
        },
2058
14
        {  &hf_packet_header,
2059
14
            { "Packet Header",                                  "btbredr_rf.packet_header",
2060
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
2061
14
            NULL, HFILL }
2062
14
        },
2063
14
        {  &hf_packet_header_lt_addr,
2064
14
            { "LT_ADDR",                                        "btbredr_rf.packet_header.lt_addr",
2065
14
            FT_UINT32, BASE_HEX, NULL, 0x00000007,
2066
14
            NULL, HFILL }
2067
14
        },
2068
14
        {  &hf_packet_header_type,
2069
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2070
14
            FT_UINT32, BASE_HEX, NULL, 0x00000078,
2071
14
            NULL, HFILL }
2072
14
        },
2073
14
        {  &hf_packet_header_type_any,
2074
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2075
14
            FT_UINT32, BASE_HEX, VALS(packet_type_any_vals), 0x00000078,
2076
14
            NULL, HFILL }
2077
14
        },
2078
14
        {  &hf_packet_header_type_sco_br,
2079
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2080
14
            FT_UINT32, BASE_HEX, VALS(packet_type_sco_br_vals), 0x00000078,
2081
14
            NULL, HFILL }
2082
14
        },
2083
14
        {  &hf_packet_header_type_esco_br,
2084
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2085
14
            FT_UINT32, BASE_HEX, VALS(packet_type_esco_br_vals), 0x00000078,
2086
14
            NULL, HFILL }
2087
14
        },
2088
14
        {  &hf_packet_header_type_esco_edr,
2089
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2090
14
            FT_UINT32, BASE_HEX, VALS(packet_type_esco_edr_vals), 0x00000078,
2091
14
            NULL, HFILL }
2092
14
        },
2093
14
        {  &hf_packet_header_type_acl_br,
2094
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2095
14
            FT_UINT32, BASE_HEX, VALS(packet_type_acl_br_vals), 0x00000078,
2096
14
            NULL, HFILL }
2097
14
        },
2098
14
        {  &hf_packet_header_type_acl_edr,
2099
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2100
14
            FT_UINT32, BASE_HEX, VALS(packet_type_acl_edr_vals), 0x00000078,
2101
14
            NULL, HFILL }
2102
14
        },
2103
14
        {  &hf_packet_header_type_cpb_br,
2104
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2105
14
            FT_UINT32, BASE_HEX, VALS(packet_type_cpb_br_vals), 0x00000078,
2106
14
            NULL, HFILL }
2107
14
        },
2108
14
        {  &hf_packet_header_type_cpb_edr,
2109
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2110
14
            FT_UINT32, BASE_HEX, VALS(packet_type_cpb_edr_vals), 0x00000078,
2111
14
            NULL, HFILL }
2112
14
        },
2113
14
        {  &hf_packet_header_flow_control,
2114
14
            { "Flow Control",                                   "btbredr_rf.packet_header.flow_control",
2115
14
            FT_BOOLEAN, 32, NULL, 0x00000080,
2116
14
            NULL, HFILL }
2117
14
        },
2118
14
        {  &hf_packet_header_acknowledge_indication,
2119
14
            { "ARQN",                                           "btbredr_rf.packet_header.arqn",
2120
14
            FT_BOOLEAN, 32, NULL, 0x00000100,
2121
14
            "Acknowledge Indication", HFILL }
2122
14
        },
2123
14
        {  &hf_packet_header_sequence_number,
2124
14
            { "SEQN",                                           "btbredr_rf.packet_header.seqn",
2125
14
            FT_BOOLEAN, 32, NULL, 0x00000200,
2126
14
            "Sequence Number", HFILL }
2127
14
        },
2128
14
        {  &hf_packet_header_header_error_check,
2129
14
            { "HEC",                                            "btbredr_rf.packet_header.hec",
2130
14
            FT_UINT32, BASE_HEX, NULL, 0x0003FC00,
2131
14
            "Header Error Check", HFILL }
2132
14
        },
2133
14
        {  &hf_packet_header_reserved,
2134
14
            { "Reserved",                                       "btbredr_rf.packet_header.reserved",
2135
14
            FT_UINT32, BASE_HEX, NULL, 0xFFFC0000,
2136
14
            NULL, HFILL }
2137
14
        },
2138
14
        {  &hf_packet_header_broken_lt_addr,
2139
14
            { "LT_ADDR",                                        "btbredr_rf.packet_header.lt_addr",
2140
14
            FT_UINT32, BASE_HEX, NULL, 0x00038000,
2141
14
            NULL, HFILL }
2142
14
        },
2143
14
        {  &hf_packet_header_broken_type,
2144
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2145
14
            FT_UINT32, BASE_HEX, NULL, 0x00007800,
2146
14
            NULL, HFILL }
2147
14
        },
2148
14
        {  &hf_packet_header_broken_type_any,
2149
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2150
14
            FT_UINT32, BASE_HEX, VALS(packet_type_any_vals), 0x00007800,
2151
14
            NULL, HFILL }
2152
14
        },
2153
14
        {  &hf_packet_header_broken_type_sco_br,
2154
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2155
14
            FT_UINT32, BASE_HEX, VALS(packet_type_sco_br_vals), 0x00007800,
2156
14
            NULL, HFILL }
2157
14
        },
2158
14
        {  &hf_packet_header_broken_type_esco_br,
2159
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2160
14
            FT_UINT32, BASE_HEX, VALS(packet_type_esco_br_vals), 0x00007800,
2161
14
            NULL, HFILL }
2162
14
        },
2163
14
        {  &hf_packet_header_broken_type_esco_edr,
2164
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2165
14
            FT_UINT32, BASE_HEX, VALS(packet_type_esco_edr_vals), 0x00007800,
2166
14
            NULL, HFILL }
2167
14
        },
2168
14
        {  &hf_packet_header_broken_type_acl_br,
2169
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2170
14
            FT_UINT32, BASE_HEX, VALS(packet_type_acl_br_vals), 0x00007800,
2171
14
            NULL, HFILL }
2172
14
        },
2173
14
        {  &hf_packet_header_broken_type_acl_edr,
2174
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2175
14
            FT_UINT32, BASE_HEX, VALS(packet_type_acl_edr_vals), 0x00007800,
2176
14
            NULL, HFILL }
2177
14
        },
2178
14
        {  &hf_packet_header_broken_type_cpb_br,
2179
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2180
14
            FT_UINT32, BASE_HEX, VALS(packet_type_cpb_br_vals), 0x00007800,
2181
14
            NULL, HFILL }
2182
14
        },
2183
14
        {  &hf_packet_header_broken_type_cpb_edr,
2184
14
            { "Type",                                           "btbredr_rf.packet_header.type",
2185
14
            FT_UINT32, BASE_HEX, VALS(packet_type_cpb_edr_vals), 0x00007800,
2186
14
            NULL, HFILL }
2187
14
        },
2188
14
        {  &hf_packet_header_broken_flow_control,
2189
14
            { "Flow Control",                                   "btbredr_rf.packet_header.flow_control",
2190
14
            FT_BOOLEAN, 32, NULL, 0x00000400,
2191
14
            NULL, HFILL }
2192
14
        },
2193
14
        {  &hf_packet_header_broken_acknowledge_indication,
2194
14
            { "ARQN",                                           "btbredr_rf.packet_header.arqn",
2195
14
            FT_BOOLEAN, 32, NULL, 0x00000200,
2196
14
            "Acknowledge Indication", HFILL }
2197
14
        },
2198
14
        {  &hf_packet_header_broken_sequence_number,
2199
14
            { "SEQN",                                           "btbredr_rf.packet_header.seqn",
2200
14
            FT_BOOLEAN, 32, NULL, 0x00000100,
2201
14
            "Sequence Number", HFILL }
2202
14
        },
2203
14
        {  &hf_packet_header_broken_header_error_check,
2204
14
            { "HEC",                                            "btbredr_rf.packet_header.hec",
2205
14
            FT_UINT32, BASE_HEX, NULL, 0x000000FF,
2206
14
            "Header Error Check", HFILL }
2207
14
        },
2208
14
        {  &hf_whitened_data,
2209
14
            { "Whitened Data",                                  "btbredr_rf.whitened.data",
2210
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2211
14
            NULL, HFILL }
2212
14
        },
2213
14
        {  &hf_encrypted_data,
2214
14
            { "Encrypted Data",                                 "btbredr_rf.encrypted.data",
2215
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2216
14
            NULL, HFILL }
2217
14
        },
2218
14
        {  &hf_data,
2219
14
            { "Data",                                           "btbredr_rf.data",
2220
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2221
14
            NULL, HFILL }
2222
14
        },
2223
14
        {  &hf_isochronous_data,
2224
14
            { "Isochronous Data",                               "btbredr_rf.isochronous_data",
2225
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2226
14
            NULL, HFILL }
2227
14
        },
2228
14
        {  &hf_asynchronous_data,
2229
14
            { "Asynchronous Data",                              "btbredr_rf.asynchronous_data",
2230
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2231
14
            NULL, HFILL }
2232
14
        },
2233
14
        {  &hf_l2cap_fragment,
2234
14
            { "L2CAP Fragment",                                 "btbredr_rf.l2cap_data",
2235
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2236
14
            NULL, HFILL }
2237
14
        },
2238
14
        {  &hf_crc,
2239
14
            { "CRC",                                            "btbredr_rf.crc",
2240
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
2241
14
            NULL, HFILL }
2242
14
        },
2243
14
        {  &hf_flags,
2244
14
            { "Flags",                                          "btbredr_rf.flags",
2245
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
2246
14
            NULL, HFILL }
2247
14
        },
2248
14
        {  &hf_flags_reserved_15_14,
2249
14
            { "Reserved",                                       "btbredr_rf.flags.reserved.15_14",
2250
14
            FT_UINT16, BASE_HEX, NULL, 0xC000,
2251
14
            NULL, HFILL }
2252
14
        },
2253
14
        {  &hf_flags_mic_pass,
2254
14
            { "MIC Pass",                                       "btbredr_rf.flags.mic_pass",
2255
14
            FT_BOOLEAN, 16, NULL, 0x2000,
2256
14
            NULL, HFILL }
2257
14
        },
2258
14
        {  &hf_flags_mic_checked,
2259
14
            { "MIC Checked",                                    "btbredr_rf.flags.mic_check",
2260
14
            FT_BOOLEAN, 16, NULL, 0x1000,
2261
14
            NULL, HFILL }
2262
14
        },
2263
14
        {  &hf_flags_crc_pass,
2264
14
            { "CRC Pass",                                       "btbredr_rf.flags.crc_pass",
2265
14
            FT_BOOLEAN, 16, NULL, 0x0800,
2266
14
            NULL, HFILL }
2267
14
        },
2268
14
        {  &hf_flags_crc_checked,
2269
14
            { "CRC Checked",                                    "btbredr_rf.flags.crc_check",
2270
14
            FT_BOOLEAN, 16, NULL, 0x0400,
2271
14
            NULL, HFILL }
2272
14
        },
2273
14
        {  &hf_flags_hec_pass,
2274
14
            { "HEC Pass",                                       "btbredr_rf.flags.hec_pass",
2275
14
            FT_BOOLEAN, 16, NULL, 0x0200,
2276
14
            NULL, HFILL }
2277
14
        },
2278
14
        {  &hf_flags_hec_checked,
2279
14
            { "HEC Checked",                                    "btbredr_rf.flags.hec_check",
2280
14
            FT_BOOLEAN, 16, NULL, 0x0100,
2281
14
            NULL, HFILL }
2282
14
        },
2283
14
        {  &hf_flags_reference_upper_address_part_valid,
2284
14
            { "Reference Upper Address Part Valid",             "btbredr_rf.flags.reference_upper_address_part_valid",
2285
14
            FT_BOOLEAN, 16, NULL, 0x0080,
2286
14
            NULL, HFILL }
2287
14
        },
2288
14
        {  &hf_flags_rf_channel_aliasing,
2289
14
            { "RF Channel Aliasing",                            "btbredr_rf.flags.rf_channel_aliasing",
2290
14
            FT_BOOLEAN, 16, NULL, 0x0040,
2291
14
            NULL, HFILL }
2292
14
        },
2293
14
        {  &hf_flags_br_edr_data_present,
2294
14
            { "BR or EDR Data Present",                         "btbredr_rf.flags.bredr_data_present",
2295
14
            FT_BOOLEAN, 16, NULL, 0x0020,
2296
14
            NULL, HFILL }
2297
14
        },
2298
14
        {  &hf_flags_reference_lower_address_part_valid,
2299
14
            { "Reference Lower Address Part Valid",             "btbredr_rf.flags.reference_lower_address_part_valid",
2300
14
            FT_BOOLEAN, 16, NULL, 0x0010,
2301
14
            NULL, HFILL }
2302
14
        },
2303
14
        {  &hf_flags_bredr_payload_decrypted,
2304
14
            { "BR or EDR Payload Decrypted",                    "btbredr_rf.flags.bredr_payload_decrypted",
2305
14
            FT_BOOLEAN, 16, NULL, 0x0008,
2306
14
            NULL, HFILL }
2307
14
        },
2308
14
        {  &hf_flags_noise_power_valid,
2309
14
            { "Noise Power Valid",                              "btbredr_rf.flags.noise_power_valid",
2310
14
            FT_BOOLEAN, 16, NULL, 0x0004,
2311
14
            NULL, HFILL }
2312
14
        },
2313
14
        {  &hf_flags_signal_power_valid,
2314
14
            { "Signal Power Valid",                             "btbredr_rf.flags.signal_power_valid",
2315
14
            FT_BOOLEAN, 16, NULL, 0x0002,
2316
14
            NULL, HFILL }
2317
14
        },
2318
14
        {  &hf_flags_packet_header_and_br_edr_payload_dewhitened,
2319
14
            { "Packet Header and BR/EDR Payload Dewhitened",    "btbredr_rf.flags.pkt_hdr_and_br_edr_payload_dewhitened",
2320
14
            FT_BOOLEAN, 16, NULL, 0x0001,
2321
14
            NULL, HFILL }
2322
14
        },
2323
14
        {  &hf_payload_header2,
2324
14
            { "Payload Header",                                 "btbredr_rf.payload_header",
2325
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
2326
14
            NULL, HFILL }
2327
14
        },
2328
14
        {  &hf_payload_header2_llid,
2329
14
            { "LLID",                                           "btbredr_rf.payload_header.llid",
2330
14
            FT_UINT16, BASE_HEX, NULL, 0x0003,
2331
14
            NULL, HFILL }
2332
14
        },
2333
14
        {  &hf_payload_header2_flow,
2334
14
            { "Flow",                                           "btbredr_rf.payload_header.flow",
2335
14
            FT_UINT16, BASE_HEX, NULL, 0x0004,
2336
14
            NULL, HFILL }
2337
14
        },
2338
14
        {  &hf_payload_header2_length,
2339
14
            { "Length",                                         "btbredr_rf.payload_header.length",
2340
14
            FT_UINT16, BASE_HEX, NULL, 0x1ff8,
2341
14
            NULL, HFILL }
2342
14
        },
2343
14
        {  &hf_payload_header2_rfu,
2344
14
            { "RFU",                                            "btbredr_rf.payload_header.rfu",
2345
14
            FT_UINT16, BASE_HEX, NULL, 0xe000,
2346
14
            NULL, HFILL }
2347
14
        },
2348
14
        {  &hf_payload_header1,
2349
14
            { "Payload Header",                                 "btbredr_rf.payload_header",
2350
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
2351
14
            NULL, HFILL }
2352
14
        },
2353
14
        {  &hf_payload_header1_llid,
2354
14
            { "LLID",                                           "btbredr_rf.payload_header.llid",
2355
14
            FT_UINT8, BASE_HEX, NULL, 0x03,
2356
14
            NULL, HFILL }
2357
14
        },
2358
14
        {  &hf_payload_header1_flow,
2359
14
            { "Flow",                                           "btbredr_rf.payload_header.flow",
2360
14
            FT_UINT8, BASE_HEX, NULL, 0x04,
2361
14
            NULL, HFILL }
2362
14
        },
2363
14
        {  &hf_payload_header1_length,
2364
14
            { "Length",                                         "btbredr_rf.payload_header.length",
2365
14
            FT_UINT8, BASE_HEX, NULL, 0xf8,
2366
14
            NULL, HFILL }
2367
14
        },
2368
14
        {  &hf_l2cap_msg_fragments,
2369
14
            { "L2CAP fragments",                                "btbredr_rf.l2cap.fragments",
2370
14
            FT_NONE, BASE_NONE, NULL, 0x00,
2371
14
            NULL, HFILL }
2372
14
        },
2373
14
        {  &hf_l2cap_msg_fragment,
2374
14
            { "L2CAP fragment",                                 "btbredr_rf.l2cap.fragment",
2375
14
            FT_FRAMENUM, BASE_NONE, NULL, 0x00,
2376
14
            NULL, HFILL }
2377
14
        },
2378
14
        {  &hf_l2cap_msg_fragment_overlap,
2379
14
            { "L2CAP fragment overlap",                         "btbredr_rf.l2cap.fragment.overlap",
2380
14
            FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2381
14
            NULL, HFILL }
2382
14
        },
2383
14
        {  &hf_l2cap_msg_fragment_overlap_conflicts,
2384
14
            { "L2CAP fragment overlapping with conflicting data", "btbredr_rf.l2cap.fragment.overlap.conflicts",
2385
14
            FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2386
14
            NULL, HFILL }
2387
14
        },
2388
14
        {  &hf_l2cap_msg_fragment_multiple_tails,
2389
14
            { "L2CAP has multiple tail fragments",              "btbredr_rf.l2cap.fragment.multiple_tails",
2390
14
            FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2391
14
            NULL, HFILL }
2392
14
        },
2393
14
        {  &hf_l2cap_msg_fragment_too_long_fragment,
2394
14
            { "L2CAP fragment too long",                        "btbredr_rf.l2cap.fragment.too_long_fragment",
2395
14
            FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2396
14
            NULL, HFILL }
2397
14
        },
2398
14
        {  &hf_l2cap_msg_fragment_error,
2399
14
            { "L2CAP defragmentation error",                    "btbredr_rf.l2cap.fragment.error",
2400
14
            FT_FRAMENUM, BASE_NONE, NULL, 0x00,
2401
14
            NULL, HFILL }
2402
14
        },
2403
14
        {  &hf_l2cap_msg_fragment_count,
2404
14
            { "L2CAP fragment count",                           "btbredr_rf.l2cap.fragment.count",
2405
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
2406
14
            NULL, HFILL }
2407
14
        },
2408
14
        {  &hf_l2cap_msg_reassembled_in,
2409
14
            { "Reassembled in",                                 "btbredr_rf.l2cap.reassembled.in",
2410
14
            FT_FRAMENUM, BASE_NONE, NULL, 0x00,
2411
14
            NULL, HFILL }
2412
14
        },
2413
14
        {  &hf_l2cap_msg_reassembled_length,
2414
14
            { "Reassembled L2CAP length",                       "btbredr_rf.l2cap.reassembled.length",
2415
14
            FT_UINT32, BASE_DEC, NULL, 0x00,
2416
14
            NULL, HFILL }
2417
14
        }
2418
14
    };
2419
2420
14
    static hf_register_info hf_fhs[] = {
2421
14
        {  &hf_fhs_parity,
2422
14
            { "Parity Bits",                                    "btbredr_fhs.parity",
2423
14
            FT_UINT64, BASE_HEX, NULL, 0x00000003ffffffff,
2424
14
            NULL, HFILL }
2425
14
        },
2426
14
        {  &hf_fhs_lap,
2427
14
            { "Lower Address Part",                             "btbredr_fhs.lap",
2428
14
            FT_UINT64, BASE_HEX, NULL, 0x03fffffc00000000,
2429
14
            NULL, HFILL }
2430
14
        },
2431
14
        {  &hf_fhs_eir,
2432
14
            { "Extended Inquiry Response",                      "btbredr_fhs.eir",
2433
14
            FT_UINT64, BASE_DEC, NULL, 0x0400000000000000,
2434
14
            NULL, HFILL }
2435
14
        },
2436
14
        {  &hf_fhs_reserved,
2437
14
            { "Reserved",                                       "btbredr_fhs.reserved",
2438
14
            FT_UINT64, BASE_DEC, NULL, 0x0800000000000000,
2439
14
            NULL, HFILL }
2440
14
        },
2441
14
        {  &hf_fhs_sr,
2442
14
            { "Scan Repetition",                                "btbredr_fhs.sr",
2443
14
            FT_UINT64, BASE_DEC|BASE_VAL64_STRING, VALS64(fhs_scan_repetition_vals), 0x3000000000000000,
2444
14
            NULL, HFILL }
2445
14
        },
2446
14
        {  &hf_fhs_sp,
2447
14
            { "SP",                                             "btbredr_fhs.sp",
2448
14
            FT_UINT64, BASE_DEC, NULL, 0xc000000000000000,
2449
14
            "shall be set to 10", HFILL }
2450
14
        },
2451
14
        {  &hf_fhs_uap,
2452
14
            { "Upper Address Part",                             "btbredr_fhs.uap",
2453
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
2454
14
            NULL, HFILL }
2455
14
        },
2456
14
        {  &hf_fhs_nap,
2457
14
            { "Non-Significant Address Part",                   "btbredr_fhs.nap",
2458
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
2459
14
            NULL, HFILL }
2460
14
        },
2461
14
        {  &hf_fhs_class,
2462
14
            { "Class of Device",                                "btbredr_fhs.class",
2463
14
            FT_UINT24, BASE_HEX, NULL, 0x00,
2464
14
            NULL, HFILL }
2465
14
        },
2466
14
        {  &hf_fhs_ltaddr,
2467
14
            { "LT_ADDR",                                        "btbredr_fhs.ltaddr",
2468
14
            FT_UINT32, BASE_DEC, NULL, 0x00000007,
2469
14
            NULL, HFILL }
2470
14
        },
2471
14
        {  &hf_fhs_clk,
2472
14
            { "CLK",                                            "btbredr_fhs.clk",
2473
14
            FT_UINT32, BASE_HEX, NULL, 0x1ffffff8,
2474
14
            NULL, HFILL }
2475
14
        },
2476
14
        {  &hf_fhs_pagescanmode,
2477
14
            { "Page Scan Mode",                                 "btbredr_fhs.pagescanmode",
2478
14
            FT_UINT32, BASE_DEC, VALS(fhs_page_scan_mode_vals), 0xe0000000,
2479
14
            NULL, HFILL }
2480
14
        }
2481
14
    };
2482
2483
14
    static int *ett[] = {
2484
14
        &ett_btbredr_rf,
2485
14
        &ett_flags,
2486
14
        &ett_payload_transport_rate,
2487
14
        &ett_packet_header,
2488
14
        &ett_bluetooth_header,
2489
14
        &ett_payload_header,
2490
14
        &ett_l2cap_msg_fragment,
2491
14
        &ett_l2cap_msg_fragments,
2492
14
        &ett_btbredr_fhs
2493
14
    };
2494
2495
14
    static ei_register_info ei[] = {
2496
14
        { &ei_unexpected_data,                    { "btbredr_rf.unexpected_data",                    PI_PROTOCOL, PI_WARN, "Unexpected data, BR or EDR Data Present flag is set to False", EXPFILL }},
2497
14
        { &ei_reserved_not_zero,                  { "btbredr_rf.reserved_not_zero",                  PI_PROTOCOL, PI_WARN, "Reserved values are not zeros", EXPFILL }},
2498
14
        { &ei_incorrect_packet_header_or_hec,     { "btbredr_rf.incorrect_packet_header_or_hec",     PI_PROTOCOL, PI_WARN, "Incorrect Packet Header or HEC", EXPFILL }},
2499
14
        { &ei_packet_header_with_hec_not_checked, { "btbredr_rf.packet_header_with_hec_not_checked", PI_PROTOCOL, PI_NOTE, "Packet Header with HEC is not checked", EXPFILL }},
2500
14
        { &ei_broken_packet_header_format,        { "btbredr_rf.broken_packet_header_format",        PI_PROTOCOL, PI_WARN, "Broken Packet Header Format", EXPFILL }},
2501
14
        { &ei_incorrect_crc,                      { "btbredr_rf.incorrect_crc",                      PI_PROTOCOL, PI_WARN, "Incorrect CRC", EXPFILL }},
2502
14
        { &ei_missing_fragment_start,             { "btbredr_rf.missing_fragment_start",             PI_SEQUENCE, PI_WARN, "Missing Fragment Start", EXPFILL }},
2503
14
        { &ei_esco_incorrect_ltaddr,              { "btbredr_rf.esco_incorrect_ltaddr",              PI_PROTOCOL, PI_WARN, "Incorrect (e)SCO LT_ADDR", EXPFILL }},
2504
14
        { &ei_esco_incorrect_length,              { "btbredr_rf.esco_incorrect_length",              PI_PROTOCOL, PI_WARN, "Incorrect eSCO Packet Length", EXPFILL }}
2505
14
    };
2506
2507
14
    connection_info_tree = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
2508
14
    device_info_tree = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
2509
2510
14
    proto_btbredr_rf = proto_register_protocol("Bluetooth Pseudoheader for BR/EDR", "BT BR/EDR RF", "btbredr_rf");
2511
14
    proto_register_field_array(proto_btbredr_rf, hf, array_length(hf));
2512
14
    proto_register_subtree_array(ett, array_length(ett));
2513
14
    btbredr_rf_handle = register_dissector("btbredr_rf", dissect_btbredr_rf, proto_btbredr_rf);
2514
2515
14
    proto_btbredr_fhs = proto_register_protocol("Bluetooth BR/EDR FHS", "BT BR/EDR FHS", "btbredr_fhs");
2516
14
    proto_register_field_array(proto_btbredr_fhs, hf_fhs, array_length(hf_fhs));
2517
14
    btbredr_fhs_handle = register_dissector("btbredr_fhs", dissect_btbredr_fhs, proto_btbredr_fhs);
2518
2519
14
    packet_type_sco_br_table   = register_dissector_table("btbredr_rf.packet_type.sco.br",   "BT Packet Type for SCO BR",   proto_btbredr_rf, FT_UINT8, BASE_HEX);
2520
14
    packet_type_esco_br_table  = register_dissector_table("btbredr_rf.packet_type.esco.br",  "BT Packet Type for eSCO BR",  proto_btbredr_rf, FT_UINT8, BASE_HEX);
2521
14
    packet_type_esco_edr_table = register_dissector_table("btbredr_rf.packet_type.esco.edr", "BT Packet Type for eSCO EDR", proto_btbredr_rf, FT_UINT8, BASE_HEX);
2522
14
    packet_type_acl_br_table   = register_dissector_table("btbredr_rf.packet_type.acl.br",   "BT Packet Type for ACL BR",   proto_btbredr_rf, FT_UINT8, BASE_HEX);
2523
14
    packet_type_acl_edr_table  = register_dissector_table("btbredr_rf.packet_type.acl.edr",  "BT Packet Type for ACL EDR",  proto_btbredr_rf, FT_UINT8, BASE_HEX);
2524
14
    packet_type_cpb_br_table   = register_dissector_table("btbredr_rf.packet_type.cpb.br",   "BT Packet Type for CPB BR",   proto_btbredr_rf, FT_UINT8, BASE_HEX);
2525
14
    packet_type_cpb_edr_table  = register_dissector_table("btbredr_rf.packet_type.cpb.edr",  "BT Packet Type for CPB EDR",  proto_btbredr_rf, FT_UINT8, BASE_HEX);
2526
2527
14
    expert_module = expert_register_protocol(proto_btbredr_rf);
2528
14
    expert_register_field_array(expert_module, ei, array_length(ei));
2529
14
}
2530
2531
void
2532
proto_reg_handoff_btbredr_rf(void)
2533
14
{
2534
14
    btlmp_handle = find_dissector_add_dependency("btlmp", proto_btbredr_rf);
2535
14
    btl2cap_handle = find_dissector_add_dependency("btl2cap", proto_btbredr_rf);
2536
14
    dissector_add_uint("bluetooth.encap", WTAP_ENCAP_BLUETOOTH_BREDR_BB, btbredr_rf_handle);
2537
14
}
2538
2539
/*
2540
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
2541
 *
2542
 * Local variables:
2543
 * c-basic-offset: 4
2544
 * tab-width: 8
2545
 * indent-tabs-mode: nil
2546
 * End:
2547
 *
2548
 * vi: set shiftwidth=4 tabstop=8 expandtab:
2549
 * :indentSize=4:tabSize=8:noTabs=true:
2550
 */