38 #include <netinet/in.h>
41 #define AF_BLUETOOTH 31
42 #define PF_BLUETOOTH AF_BLUETOOTH
45 #define BTPROTO_L2CAP 0
48 #define BTPROTO_RFCOMM 3
49 #define BTPROTO_BNEP 4
50 #define BTPROTO_CMTP 5
51 #define BTPROTO_HIDP 6
52 #define BTPROTO_AVDTP 7
60 #define SOL_BLUETOOTH 274
68 #define BT_SECURITY_SDP 0
69 #define BT_SECURITY_LOW 1
70 #define BT_SECURITY_MEDIUM 2
71 #define BT_SECURITY_HIGH 3
73 #define BT_DEFER_SETUP 7
75 #define BT_FLUSHABLE 8
77 #define BT_FLUSHABLE_OFF 0
78 #define BT_FLUSHABLE_ON 1
84 #define BT_POWER_FORCE_ACTIVE_OFF 0
85 #define BT_POWER_FORCE_ACTIVE_ON 1
87 #define BT_CHANNEL_POLICY 10
94 #define BT_CHANNEL_POLICY_BREDR_ONLY 0
101 #define BT_CHANNEL_POLICY_BREDR_PREFERRED 1
112 #define BT_CHANNEL_POLICY_AMP_PREFERRED 2
122 #define BT_VOICE_TRANSPARENT 0x0003
123 #define BT_VOICE_CVSD_16BIT 0x0060
139 #if __BYTE_ORDER == __LITTLE_ENDIAN
142 #define htobll(d) (d)
145 #define btohll(d) (d)
146 #elif __BYTE_ORDER == __BIG_ENDIAN
147 #define htobs(d) bswap_16(d)
148 #define htobl(d) bswap_32(d)
149 #define htobll(d) bswap_64(d)
150 #define btohs(d) bswap_16(d)
151 #define btohl(d) bswap_32(d)
152 #define btohll(d) bswap_64(d)
154 #error "Unknown byte order"
158 #define bt_get_unaligned(ptr) \
160 struct __attribute__((packed)) { \
161 __typeof__(*(ptr)) __v; \
162 } *__p = (__typeof__(__p)) (ptr); \
166 #define bt_put_unaligned(val, ptr) \
168 struct __attribute__((packed)) { \
169 __typeof__(*(ptr)) __v; \
170 } *__p = (__typeof__(__p)) (ptr); \
174 #if __BYTE_ORDER == __LITTLE_ENDIAN
235 #elif __BYTE_ORDER == __BIG_ENDIAN
236 static inline uint64_t
bt_get_le64(
const void *ptr)
241 static inline uint64_t
bt_get_be64(
const void *ptr)
246 static inline uint32_t
bt_get_le32(
const void *ptr)
251 static inline uint32_t
bt_get_be32(
const void *ptr)
256 static inline uint16_t
bt_get_le16(
const void *ptr)
261 static inline uint16_t
bt_get_be16(
const void *ptr)
266 static inline void bt_put_le64(uint64_t val,
const void *ptr)
271 static inline void bt_put_be64(uint64_t val,
const void *ptr)
276 static inline void bt_put_le32(uint32_t val,
const void *ptr)
281 static inline void bt_put_be32(uint32_t val,
const void *ptr)
286 static inline void bt_put_le16(uint16_t val,
const void *ptr)
291 static inline void bt_put_be16(uint16_t val,
const void *ptr)
296 #error "Unknown byte order"
305 #define BDADDR_BREDR 0x00
306 #define BDADDR_LE_PUBLIC 0x01
307 #define BDADDR_LE_RANDOM 0x02
309 #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
310 #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
311 #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
314 static inline int bacmp(
const bdaddr_t *ba1,
const bdaddr_t *ba2)
316 return memcmp(ba1, ba2,
sizeof(bdaddr_t));
318 static inline void bacpy(bdaddr_t *dst,
const bdaddr_t *src)
320 memcpy(dst, src,
sizeof(bdaddr_t));
323 void baswap(bdaddr_t *dst,
const bdaddr_t *src);
324 bdaddr_t *
strtoba(
const char *str);
325 char *
batostr(
const bdaddr_t *ba);
326 int ba2str(
const bdaddr_t *ba,
char *str);
327 int str2ba(
const char *str, bdaddr_t *ba);
328 int ba2oui(
const bdaddr_t *ba,
char *oui);
329 int bachk(
const char *str);
331 int baprintf(
const char *format, ...);
332 int bafprintf(FILE *stream,
const char *format, ...);
333 int basprintf(
char *str,
const char *format, ...);
334 int basnprintf(
char *str,
size_t size,
const char *format, ...);
346 static inline void bswap_128(
const void *src,
void *dst)
348 const uint8_t *s = (
const uint8_t *) src;
349 uint8_t *d = (uint8_t *) dst;
352 for (i = 0; i < 16; i++)
356 #if __BYTE_ORDER == __BIG_ENDIAN
358 #define ntoh64(x) (x)
372 static inline uint64_t
ntoh64(uint64_t n)
375 uint64_t tmp = ntohl(n & 0x00000000ffffffff);
395 #define hton64(x) ntoh64(x)
396 #define hton128(x, y) ntoh128(x, y)
397 #define htob128(x, y) btoh128(x, y)
static int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
int basnprintf(char *str, size_t size, const char *format,...)
static void bt_put_be32(uint32_t val, const void *ptr)
int bachk(const char *str)
static uint64_t bt_get_be64(const void *ptr)
int basprintf(char *str, const char *format,...)
static void bt_put_le64(uint64_t val, const void *ptr)
static void bt_put_be16(uint16_t val, const void *ptr)
int ba2oui(const bdaddr_t *ba, char *oui)
int str2ba(const char *str, bdaddr_t *ba)
static uint64_t bt_get_le64(const void *ptr)
static void btoh128(const uint128_t *src, uint128_t *dst)
static void bacpy(bdaddr_t *dst, const bdaddr_t *src)
static uint32_t bt_get_le32(const void *ptr)
bdaddr_t * strtoba(const char *str)
int bafprintf(FILE *stream, const char *format,...)
void * bt_malloc(size_t size)
int ba2str(const bdaddr_t *ba, char *str)
static void bswap_128(const void *src, void *dst)
static uint16_t bt_get_le16(const void *ptr)
static void bt_put_be64(uint64_t val, const void *ptr)
void baswap(bdaddr_t *dst, const bdaddr_t *src)
static void bt_put_le32(uint32_t val, const void *ptr)
char * batostr(const bdaddr_t *ba)
int baprintf(const char *format,...)
static void ntoh128(const uint128_t *src, uint128_t *dst)
static uint16_t bt_get_be16(const void *ptr)
static uint32_t bt_get_be32(const void *ptr)
int bt_error(uint16_t code)
#define bt_put_unaligned(val, ptr)
static void bt_put_le16(uint16_t val, const void *ptr)
const char * bt_compidtostr(int id)
#define bt_get_unaligned(ptr)