xref: /libbtbb/lib/src/pcap-common.h (revision 0e05cc66941848f923f732577ce647fb6724596a)
1 /* -*- c -*- */
2 /*
3  * Copyright 2014 Christopher D. Kilgour techie AT whiterocker.com
4  *
5  * This file is part of libbtbb
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with libbtbb; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef PCAP_COMMON_DOT_H
23 #define PCAP_COMMON_DOT_H
24 
25 /* pull definitions for BT DLTs and pseudoheaders from libpcap, if possible */
26 #if defined(USE_PCAP)
27 #include <pcap/pcap.h>
28 #include <pcap/bluetooth.h>
29 #endif
30 
31 #if defined( __APPLE__ )
32 #include <CoreServices/CoreServices.h>
33 #define htobe32 EndianU32_NtoB
34 #define be32toh EndianU32_BtoN
35 #define le32toh EndianU32_LtoN
36 #define htobe64 EndianU64_NtoB
37 #define be64toh EndianU64_BtoN
38 #define htole16 EndianU16_NtoL
39 #define htole32 EndianU32_NtoL
40 #else
41 #include <endian.h>
42 #endif
43 
44 #if !defined( htole16 ) /* will be defined under Linux when endian.h already included */
45 #if defined( __GNUC__ )
46 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
47 inline uint16_t htole16(uint16_t host_16bits) { return host_16bits; }
48 inline uint16_t le16toh(uint16_t little_endian_16bits) { return little_endian_16bits; }
49 inline uint32_t htole32(uint32_t host_32bits) { return host_32bits; }
50 inline uint32_t le32toh(uint32_t little_endian_32bits) { return little_endian_32bits; }
51 inline uint64_t htole64(uint64_t host_64bits) { return host_64bits; }
52 inline uint64_t le64toh(uint64_t little_endian_64bits) { return little_endian_64bits; }
53 #else
54 #error "FIXME: need to support big-endian under GNU"
55 #endif /* __BYTE_ORDER__ */
56 #else /* not GNU C */
57 #error "FIXME: need to support non-GNU compiler"
58 #endif /* __GNUC__ */
59 #endif /* htole16 */
60 
61 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
62 
63 /* --------------------------------- BR/EDR ----------------------------- */
64 
65 #if !defined( DLT_BLUETOOTH_BREDR_BB )
66 #define DLT_BLUETOOTH_BREDR_BB 255
67 #endif
68 typedef struct __attribute__((packed)) _pcap_bluetooth_bredr_bb_header {
69         uint8_t rf_channel;
70         int8_t signal_power;
71         int8_t noise_power;
72         uint8_t access_code_offenses;
73         uint8_t payload_transport_rate;
74         uint8_t corrected_header_bits;
75         int16_t corrected_payload_bits;
76         uint32_t lap;
77         uint32_t ref_lap_uap;
78         uint32_t bt_header;
79         uint16_t flags;
80         uint8_t  br_edr_payload[0];
81 } pcap_bluetooth_bredr_bb_header;
82 
83 #define BREDR_GFSK              0x00
84 #define BREDR_PI_OVER_2_DQPSK   0x01
85 #define BREDR_8DPSK             0x02
86 #define BREDR_TRANSPORT_ANY     0x00
87 #define BREDR_TRANSPORT_SCO     0x01
88 #define BREDR_TRANSPORT_ESCO    0x02
89 #define BREDR_TRANSPORT_ACL     0x03
90 #define BREDR_TRANSPORT_CSB     0x04
91 
92 #define BREDR_DEWHITENED        0x0001
93 #define BREDR_SIGPOWER_VALID    0x0002
94 #define BREDR_NOISEPOWER_VALID  0x0004
95 #define BREDR_PAYLOAD_DECRYPTED 0x0008
96 #define BREDR_REFLAP_VALID      0x0010
97 #define BREDR_PAYLOAD_PRESENT   0x0020
98 #define BREDR_CHANNEL_ALIASED   0x0040
99 #define BREDR_REFUAP_VALID      0x0080
100 #define BREDR_HEC_CHECKED       0x0100
101 #define BREDR_HEC_VALID         0x0200
102 #define BREDR_CRC_CHECKED       0x0400
103 #define BREDR_CRC_VALID         0x0800
104 #define BREDR_MIC_CHECKED       0x1000
105 #define BREDR_MIC_VALID         0x2000
106 
107 #define BREDR_MAX_PAYLOAD       400
108 
109 /* --------------------------------- Low Energy ---------------------------- */
110 
111 #if !defined( DLT_BLUETOOTH_LE_LL_WITH_PHDR )
112 #define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256
113 #endif
114 typedef struct __attribute__((packed)) _pcap_bluetooth_le_ll_header {
115         uint8_t rf_channel;
116         int8_t signal_power;
117         int8_t noise_power;
118         uint8_t access_address_offenses;
119         uint32_t ref_access_address;
120         uint16_t flags;
121         uint8_t le_packet[0];
122 } pcap_bluetooth_le_ll_header;
123 
124 #define LE_DEWHITENED        0x0001
125 #define LE_SIGPOWER_VALID    0x0002
126 #define LE_NOISEPOWER_VALID  0x0004
127 #define LE_PACKET_DECRYPTED  0x0008
128 #define LE_REF_AA_VALID      0x0010
129 #define LE_AA_OFFENSES_VALID 0x0020
130 #define LE_CHANNEL_ALIASED   0x0040
131 #define LE_CRC_CHECKED       0x0400
132 #define LE_CRC_VALID         0x0800
133 #define LE_MIC_CHECKED       0x1000
134 #define LE_MIC_VALID         0x2000
135 
136 #define LE_MAX_PAYLOAD       48
137 
138 #endif /* PCAP_COMMON_DOT_H */
139