3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2002-2008 Marcel Holtmann <marcel@holtmann.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #define AF_BLUETOOTH 31
41 #define PF_BLUETOOTH AF_BLUETOOTH
45 #define SOL_BLUETOOTH 274
48 #define BTPROTO_L2CAP 0
51 #define BTPROTO_RFCOMM 3
52 #define BTPROTO_BNEP 4
53 #define BTPROTO_CMTP 5
54 #define BTPROTO_HIDP 6
55 #define BTPROTO_AVDTP 7
62 /* Connection and socket states */
64 BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
75 /* Byte order conversions */
76 #if __BYTE_ORDER == __LITTLE_ENDIAN
81 #elif __BYTE_ORDER == __BIG_ENDIAN
82 #define htobs(d) bswap_16(d)
83 #define htobl(d) bswap_32(d)
84 #define btohs(d) bswap_16(d)
85 #define btohl(d) bswap_32(d)
87 #error "Unknown byte order"
90 /* Bluetooth unaligned access */
91 #define bt_get_unaligned(ptr) \
93 struct __attribute__((packed)) { \
95 } *__p = (void *) (ptr); \
99 #define bt_put_unaligned(val, ptr) \
101 struct __attribute__((packed)) { \
102 typeof(*(ptr)) __v; \
103 } *__p = (void *) (ptr); \
110 } __attribute__((packed)) bdaddr_t;
112 #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
113 #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
114 #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
116 /* Copy, swap, convert BD Address */
117 static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
119 return memcmp(ba1, ba2, sizeof(bdaddr_t));
121 static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
123 memcpy(dst, src, sizeof(bdaddr_t));
126 void baswap(bdaddr_t *dst, const bdaddr_t *src);
127 bdaddr_t *strtoba(const char *str);
128 char *batostr(const bdaddr_t *ba);
129 int ba2str(const bdaddr_t *ba, char *str);
130 int str2ba(const char *str, bdaddr_t *ba);
131 int ba2oui(const bdaddr_t *ba, char *oui);
132 int bachk(const char *str);
134 int baprintf(const char *format, ...);
135 int bafprintf(FILE *stream, const char *format, ...);
136 int basprintf(char *str, const char *format, ...);
137 int basnprintf(char *str, size_t size, const char *format, ...);
139 void *bt_malloc(size_t size);
140 void bt_free(void *ptr);
142 int bt_error(uint16_t code);
143 char *bt_compidtostr(int id);
149 #endif /* __BLUETOOTH_H */