xref: /libbtbb/lib/src/pcap-common.h (revision 75e6dc72782e4ce1b5a81ac6bc4f6fb95b6250ee)
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 // since we no longer rely on or assume the existence of libpcap,
26 // hardcode these DLTs
27 #define DLT_PPI 192
28 
29 #if defined( __APPLE__ )
30 #include <CoreServices/CoreServices.h>
31 #define htobe32 EndianU32_NtoB
32 #define be32toh EndianU32_BtoN
33 #define le32toh EndianU32_LtoN
34 #define htobe64 EndianU64_NtoB
35 #define be64toh EndianU64_BtoN
36 #define htole16 EndianU16_NtoL
37 #define htole32 EndianU32_NtoL
38 #else
39 #include <endian.h>
40 #endif
41 
42 #if !defined( htole16 ) /* will be defined under Linux when endian.h already included */
43 #if defined( __GNUC__ )
44 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
htole16(uint16_t host_16bits)45 inline uint16_t htole16(uint16_t host_16bits) { return host_16bits; }
le16toh(uint16_t little_endian_16bits)46 inline uint16_t le16toh(uint16_t little_endian_16bits) { return little_endian_16bits; }
htole32(uint32_t host_32bits)47 inline uint32_t htole32(uint32_t host_32bits) { return host_32bits; }
le32toh(uint32_t little_endian_32bits)48 inline uint32_t le32toh(uint32_t little_endian_32bits) { return little_endian_32bits; }
htole64(uint64_t host_64bits)49 inline uint64_t htole64(uint64_t host_64bits) { return host_64bits; }
le64toh(uint64_t little_endian_64bits)50 inline uint64_t le64toh(uint64_t little_endian_64bits) { return little_endian_64bits; }
51 #else
52 #error "FIXME: need to support big-endian under GNU"
53 #endif /* __BYTE_ORDER__ */
54 #else /* not GNU C */
55 #error "FIXME: need to support non-GNU compiler"
56 #endif /* __GNUC__ */
57 #endif /* htole16 */
58 
59 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
60 
61 /* --------------------------------- BR/EDR ----------------------------- */
62 
63 
64 #define BREDR_DEWHITENED        0x0001
65 #define BREDR_SIGPOWER_VALID    0x0002
66 #define BREDR_NOISEPOWER_VALID  0x0004
67 #define BREDR_PAYLOAD_DECRYPTED 0x0008
68 #define BREDR_REFLAP_VALID      0x0010
69 #define BREDR_PAYLOAD_PRESENT   0x0020
70 #define BREDR_CHANNEL_ALIASED   0x0040
71 #define BREDR_REFUAP_VALID      0x0080
72 #define BREDR_HEC_CHECKED       0x0100
73 #define BREDR_HEC_VALID         0x0200
74 #define BREDR_CRC_CHECKED       0x0400
75 #define BREDR_CRC_VALID         0x0800
76 #define BREDR_MIC_CHECKED       0x1000
77 #define BREDR_MIC_VALID         0x2000
78 
79 #define BREDR_MAX_PAYLOAD       400
80 #if !defined( DLT_BLUETOOTH_BREDR_BB )
81 #define DLT_BLUETOOTH_BREDR_BB 255
82 #endif
83 
84 typedef struct __attribute__((packed)) _pcap_bluetooth_bredr_bb_header {
85         uint8_t rf_channel;
86         int8_t signal_power;
87         int8_t noise_power;
88         uint8_t access_code_offenses;
89         uint8_t payload_transport_rate;
90         uint8_t corrected_header_bits;
91         int16_t corrected_payload_bits;
92         uint32_t lap;
93         uint32_t ref_lap_uap;
94         uint32_t bt_header;
95         uint16_t flags;
96 	uint8_t bredr_payload[BREDR_MAX_PAYLOAD];
97 } pcap_bluetooth_bredr_bb_header;
98 
99 /* --------------------------------- Low Energy ---------------------------- */
100 
101 #if !defined( DLT_BLUETOOTH_LE_LL )
102 #define DLT_BLUETOOTH_LE_LL 251
103 #endif
104 
105 #if !defined( DLT_BLUETOOTH_LE_LL_WITH_PHDR )
106 #define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256
107 #endif
108 typedef struct __attribute__((packed)) _pcap_bluetooth_le_ll_header {
109         uint8_t rf_channel;
110         int8_t signal_power;
111         int8_t noise_power;
112         uint8_t access_address_offenses;
113         uint32_t ref_access_address;
114         uint16_t flags;
115         uint8_t le_packet[0];
116 } pcap_bluetooth_le_ll_header;
117 
118 #define LE_DEWHITENED        0x0001
119 #define LE_SIGPOWER_VALID    0x0002
120 #define LE_NOISEPOWER_VALID  0x0004
121 #define LE_PACKET_DECRYPTED  0x0008
122 #define LE_REF_AA_VALID      0x0010
123 #define LE_AA_OFFENSES_VALID 0x0020
124 #define LE_CHANNEL_ALIASED   0x0040
125 #define LE_CRC_CHECKED       0x0400
126 #define LE_CRC_VALID         0x0800
127 #define LE_MIC_CHECKED       0x1000
128 #define LE_MIC_VALID         0x2000
129 
130 #define LE_MAX_PAYLOAD       255
131 
132 #endif /* PCAP_COMMON_DOT_H */
133