18f3e7eeaSChristopher Kilgour /* -*- c -*- */
28f3e7eeaSChristopher Kilgour /*
38f3e7eeaSChristopher Kilgour * Copyright 2014 Christopher D. Kilgour techie AT whiterocker.com
48f3e7eeaSChristopher Kilgour *
58f3e7eeaSChristopher Kilgour * This file is part of libbtbb
68f3e7eeaSChristopher Kilgour *
78f3e7eeaSChristopher Kilgour * This program is free software; you can redistribute it and/or modify
88f3e7eeaSChristopher Kilgour * it under the terms of the GNU General Public License as published by
98f3e7eeaSChristopher Kilgour * the Free Software Foundation; either version 2, or (at your option)
108f3e7eeaSChristopher Kilgour * any later version.
118f3e7eeaSChristopher Kilgour *
128f3e7eeaSChristopher Kilgour * This program is distributed in the hope that it will be useful,
138f3e7eeaSChristopher Kilgour * but WITHOUT ANY WARRANTY; without even the implied warranty of
148f3e7eeaSChristopher Kilgour * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158f3e7eeaSChristopher Kilgour * GNU General Public License for more details.
168f3e7eeaSChristopher Kilgour *
178f3e7eeaSChristopher Kilgour * You should have received a copy of the GNU General Public License
188f3e7eeaSChristopher Kilgour * along with libbtbb; see the file COPYING. If not, write to
198f3e7eeaSChristopher Kilgour * the Free Software Foundation, Inc., 51 Franklin Street,
208f3e7eeaSChristopher Kilgour * Boston, MA 02110-1301, USA.
218f3e7eeaSChristopher Kilgour */
228f3e7eeaSChristopher Kilgour #ifndef PCAP_COMMON_DOT_H
238f3e7eeaSChristopher Kilgour #define PCAP_COMMON_DOT_H
248f3e7eeaSChristopher Kilgour
25b6703d5dSMike Ryan // since we no longer rely on or assume the existence of libpcap,
26b6703d5dSMike Ryan // hardcode these DLTs
276887217eSMike Ryan #define DLT_PPI 192
288f3e7eeaSChristopher Kilgour
298f3e7eeaSChristopher Kilgour #if defined( __APPLE__ )
308f3e7eeaSChristopher Kilgour #include <CoreServices/CoreServices.h>
318f3e7eeaSChristopher Kilgour #define htobe32 EndianU32_NtoB
328f3e7eeaSChristopher Kilgour #define be32toh EndianU32_BtoN
338f3e7eeaSChristopher Kilgour #define le32toh EndianU32_LtoN
348f3e7eeaSChristopher Kilgour #define htobe64 EndianU64_NtoB
358f3e7eeaSChristopher Kilgour #define be64toh EndianU64_BtoN
368f3e7eeaSChristopher Kilgour #define htole16 EndianU16_NtoL
378f3e7eeaSChristopher Kilgour #define htole32 EndianU32_NtoL
388f3e7eeaSChristopher Kilgour #else
398f3e7eeaSChristopher Kilgour #include <endian.h>
408f3e7eeaSChristopher Kilgour #endif
418f3e7eeaSChristopher Kilgour
428f3e7eeaSChristopher Kilgour #if !defined( htole16 ) /* will be defined under Linux when endian.h already included */
438f3e7eeaSChristopher Kilgour #if defined( __GNUC__ )
448f3e7eeaSChristopher Kilgour #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
htole16(uint16_t host_16bits)458f3e7eeaSChristopher Kilgour inline uint16_t htole16(uint16_t host_16bits) { return host_16bits; }
le16toh(uint16_t little_endian_16bits)468f3e7eeaSChristopher Kilgour inline uint16_t le16toh(uint16_t little_endian_16bits) { return little_endian_16bits; }
htole32(uint32_t host_32bits)478f3e7eeaSChristopher Kilgour inline uint32_t htole32(uint32_t host_32bits) { return host_32bits; }
le32toh(uint32_t little_endian_32bits)488f3e7eeaSChristopher Kilgour inline uint32_t le32toh(uint32_t little_endian_32bits) { return little_endian_32bits; }
htole64(uint64_t host_64bits)498f3e7eeaSChristopher Kilgour inline uint64_t htole64(uint64_t host_64bits) { return host_64bits; }
le64toh(uint64_t little_endian_64bits)508f3e7eeaSChristopher Kilgour inline uint64_t le64toh(uint64_t little_endian_64bits) { return little_endian_64bits; }
518f3e7eeaSChristopher Kilgour #else
528f3e7eeaSChristopher Kilgour #error "FIXME: need to support big-endian under GNU"
538f3e7eeaSChristopher Kilgour #endif /* __BYTE_ORDER__ */
548f3e7eeaSChristopher Kilgour #else /* not GNU C */
558f3e7eeaSChristopher Kilgour #error "FIXME: need to support non-GNU compiler"
568f3e7eeaSChristopher Kilgour #endif /* __GNUC__ */
578f3e7eeaSChristopher Kilgour #endif /* htole16 */
588f3e7eeaSChristopher Kilgour
590e05cc66SDominic Spill #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
600e05cc66SDominic Spill
618f3e7eeaSChristopher Kilgour /* --------------------------------- BR/EDR ----------------------------- */
628f3e7eeaSChristopher Kilgour
638f3e7eeaSChristopher Kilgour
648f3e7eeaSChristopher Kilgour #define BREDR_DEWHITENED 0x0001
658f3e7eeaSChristopher Kilgour #define BREDR_SIGPOWER_VALID 0x0002
668f3e7eeaSChristopher Kilgour #define BREDR_NOISEPOWER_VALID 0x0004
678f3e7eeaSChristopher Kilgour #define BREDR_PAYLOAD_DECRYPTED 0x0008
688f3e7eeaSChristopher Kilgour #define BREDR_REFLAP_VALID 0x0010
698f3e7eeaSChristopher Kilgour #define BREDR_PAYLOAD_PRESENT 0x0020
708f3e7eeaSChristopher Kilgour #define BREDR_CHANNEL_ALIASED 0x0040
718f3e7eeaSChristopher Kilgour #define BREDR_REFUAP_VALID 0x0080
728f3e7eeaSChristopher Kilgour #define BREDR_HEC_CHECKED 0x0100
738f3e7eeaSChristopher Kilgour #define BREDR_HEC_VALID 0x0200
748f3e7eeaSChristopher Kilgour #define BREDR_CRC_CHECKED 0x0400
758f3e7eeaSChristopher Kilgour #define BREDR_CRC_VALID 0x0800
768f3e7eeaSChristopher Kilgour #define BREDR_MIC_CHECKED 0x1000
778f3e7eeaSChristopher Kilgour #define BREDR_MIC_VALID 0x2000
788f3e7eeaSChristopher Kilgour
790e05cc66SDominic Spill #define BREDR_MAX_PAYLOAD 400
808243a598SSean Rivera #if !defined( DLT_BLUETOOTH_BREDR_BB )
818243a598SSean Rivera #define DLT_BLUETOOTH_BREDR_BB 255
828243a598SSean Rivera #endif
838243a598SSean Rivera
848243a598SSean Rivera typedef struct __attribute__((packed)) _pcap_bluetooth_bredr_bb_header {
858243a598SSean Rivera uint8_t rf_channel;
868243a598SSean Rivera int8_t signal_power;
878243a598SSean Rivera int8_t noise_power;
888243a598SSean Rivera uint8_t access_code_offenses;
898243a598SSean Rivera uint8_t payload_transport_rate;
908243a598SSean Rivera uint8_t corrected_header_bits;
918243a598SSean Rivera int16_t corrected_payload_bits;
928243a598SSean Rivera uint32_t lap;
938243a598SSean Rivera uint32_t ref_lap_uap;
948243a598SSean Rivera uint32_t bt_header;
958243a598SSean Rivera uint16_t flags;
968243a598SSean Rivera uint8_t bredr_payload[BREDR_MAX_PAYLOAD];
978243a598SSean Rivera } pcap_bluetooth_bredr_bb_header;
980e05cc66SDominic Spill
998f3e7eeaSChristopher Kilgour /* --------------------------------- Low Energy ---------------------------- */
1008f3e7eeaSChristopher Kilgour
101*75e6dc72SMichael Farrell #if !defined( DLT_BLUETOOTH_LE_LL )
102*75e6dc72SMichael Farrell #define DLT_BLUETOOTH_LE_LL 251
103*75e6dc72SMichael Farrell #endif
104*75e6dc72SMichael Farrell
1058f3e7eeaSChristopher Kilgour #if !defined( DLT_BLUETOOTH_LE_LL_WITH_PHDR )
1068f3e7eeaSChristopher Kilgour #define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256
107fa150dd3SDominic Spill #endif
1088f3e7eeaSChristopher Kilgour typedef struct __attribute__((packed)) _pcap_bluetooth_le_ll_header {
1098f3e7eeaSChristopher Kilgour uint8_t rf_channel;
1108f3e7eeaSChristopher Kilgour int8_t signal_power;
1118f3e7eeaSChristopher Kilgour int8_t noise_power;
1128f3e7eeaSChristopher Kilgour uint8_t access_address_offenses;
1138f3e7eeaSChristopher Kilgour uint32_t ref_access_address;
1148f3e7eeaSChristopher Kilgour uint16_t flags;
1158f3e7eeaSChristopher Kilgour uint8_t le_packet[0];
1168f3e7eeaSChristopher Kilgour } pcap_bluetooth_le_ll_header;
1178f3e7eeaSChristopher Kilgour
1188f3e7eeaSChristopher Kilgour #define LE_DEWHITENED 0x0001
1198f3e7eeaSChristopher Kilgour #define LE_SIGPOWER_VALID 0x0002
1208f3e7eeaSChristopher Kilgour #define LE_NOISEPOWER_VALID 0x0004
1218f3e7eeaSChristopher Kilgour #define LE_PACKET_DECRYPTED 0x0008
1228f3e7eeaSChristopher Kilgour #define LE_REF_AA_VALID 0x0010
1238f3e7eeaSChristopher Kilgour #define LE_AA_OFFENSES_VALID 0x0020
1248f3e7eeaSChristopher Kilgour #define LE_CHANNEL_ALIASED 0x0040
1258f3e7eeaSChristopher Kilgour #define LE_CRC_CHECKED 0x0400
1268f3e7eeaSChristopher Kilgour #define LE_CRC_VALID 0x0800
1278f3e7eeaSChristopher Kilgour #define LE_MIC_CHECKED 0x1000
1288f3e7eeaSChristopher Kilgour #define LE_MIC_VALID 0x2000
1298f3e7eeaSChristopher Kilgour
130fa8f3df8SMike Ryan #define LE_MAX_PAYLOAD 255
1310e05cc66SDominic Spill
1328f3e7eeaSChristopher Kilgour #endif /* PCAP_COMMON_DOT_H */
133