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-2010 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
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
89 /* BR/EDR only (default policy)
90 * AMP controllers cannot be used.
91 * Channel move requests from the remote device are denied.
92 * If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
94 #define BT_CHANNEL_POLICY_BREDR_ONLY 0
97 * Allow use of AMP controllers.
98 * If the L2CAP channel is currently on AMP, move it to BR/EDR.
99 * Channel move requests from the remote device are allowed.
101 #define BT_CHANNEL_POLICY_BREDR_PREFERRED 1
104 * Allow use of AMP controllers
105 * If the L2CAP channel is currently on BR/EDR and AMP controller
106 * resources are available, initiate a channel move to AMP.
107 * Channel move requests from the remote device are allowed.
108 * If the L2CAP socket has not been connected yet, try to create
109 * and configure the channel directly on an AMP controller rather
112 #define BT_CHANNEL_POLICY_AMP_PREFERRED 2
122 #ifdef __TIZEN_PATCH__
123 #define BT_LE_CONN_PARAM 14
124 struct le_conn_param {
128 uint16_t to_multiplier;
132 #define BT_VOICE_TRANSPARENT 0x0003
133 #define BT_VOICE_CVSD_16BIT 0x0060
135 /* Connection and socket states */
137 BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
148 /* Byte order conversions */
149 #if __BYTE_ORDER == __LITTLE_ENDIAN
152 #define htobll(d) (d)
155 #define btohll(d) (d)
156 #elif __BYTE_ORDER == __BIG_ENDIAN
157 #define htobs(d) bswap_16(d)
158 #define htobl(d) bswap_32(d)
159 #define htobll(d) bswap_64(d)
160 #define btohs(d) bswap_16(d)
161 #define btohl(d) bswap_32(d)
162 #define btohll(d) bswap_64(d)
164 #error "Unknown byte order"
167 /* Bluetooth unaligned access */
168 #define bt_get_unaligned(ptr) \
170 struct __attribute__((packed)) { \
171 __typeof__(*(ptr)) __v; \
172 } *__p = (__typeof__(__p)) (ptr); \
176 #define bt_put_unaligned(val, ptr) \
178 struct __attribute__((packed)) { \
179 __typeof__(*(ptr)) __v; \
180 } *__p = (__typeof__(__p)) (ptr); \
184 #if __BYTE_ORDER == __LITTLE_ENDIAN
185 static inline uint64_t bt_get_le64(const void *ptr)
187 return bt_get_unaligned((const uint64_t *) ptr);
190 static inline uint64_t bt_get_be64(const void *ptr)
192 return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
195 static inline uint32_t bt_get_le32(const void *ptr)
197 return bt_get_unaligned((const uint32_t *) ptr);
200 static inline uint32_t bt_get_be32(const void *ptr)
202 return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
205 static inline uint16_t bt_get_le16(const void *ptr)
207 return bt_get_unaligned((const uint16_t *) ptr);
210 static inline uint16_t bt_get_be16(const void *ptr)
212 return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
215 static inline void bt_put_le64(uint64_t val, const void *ptr)
217 bt_put_unaligned(val, (uint64_t *) ptr);
220 static inline void bt_put_be64(uint64_t val, const void *ptr)
222 bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
225 static inline void bt_put_le32(uint32_t val, const void *ptr)
227 bt_put_unaligned(val, (uint32_t *) ptr);
230 static inline void bt_put_be32(uint32_t val, const void *ptr)
232 bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
235 static inline void bt_put_le16(uint16_t val, const void *ptr)
237 bt_put_unaligned(val, (uint16_t *) ptr);
240 static inline void bt_put_be16(uint16_t val, const void *ptr)
242 bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
245 #elif __BYTE_ORDER == __BIG_ENDIAN
246 static inline uint64_t bt_get_le64(const void *ptr)
248 return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
251 static inline uint64_t bt_get_be64(const void *ptr)
253 return bt_get_unaligned((const uint64_t *) ptr);
256 static inline uint32_t bt_get_le32(const void *ptr)
258 return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
261 static inline uint32_t bt_get_be32(const void *ptr)
263 return bt_get_unaligned((const uint32_t *) ptr);
266 static inline uint16_t bt_get_le16(const void *ptr)
268 return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
271 static inline uint16_t bt_get_be16(const void *ptr)
273 return bt_get_unaligned((const uint16_t *) ptr);
276 static inline void bt_put_le64(uint64_t val, const void *ptr)
278 bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
281 static inline void bt_put_be64(uint64_t val, const void *ptr)
283 bt_put_unaligned(val, (uint64_t *) ptr);
286 static inline void bt_put_le32(uint32_t val, const void *ptr)
288 bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
291 static inline void bt_put_be32(uint32_t val, const void *ptr)
293 bt_put_unaligned(val, (uint32_t *) ptr);
296 static inline void bt_put_le16(uint16_t val, const void *ptr)
298 bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
301 static inline void bt_put_be16(uint16_t val, const void *ptr)
303 bt_put_unaligned(val, (uint16_t *) ptr);
306 #error "Unknown byte order"
312 } __attribute__((packed)) bdaddr_t;
314 /* BD Address type */
315 #define BDADDR_BREDR 0x00
316 #define BDADDR_LE_PUBLIC 0x01
317 #define BDADDR_LE_RANDOM 0x02
319 #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
320 #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
321 #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
323 /* Copy, swap, convert BD Address */
324 static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
326 return memcmp(ba1, ba2, sizeof(bdaddr_t));
328 static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
330 memcpy(dst, src, sizeof(bdaddr_t));
333 void baswap(bdaddr_t *dst, const bdaddr_t *src);
334 bdaddr_t *strtoba(const char *str);
335 char *batostr(const bdaddr_t *ba);
336 int ba2str(const bdaddr_t *ba, char *str);
337 int str2ba(const char *str, bdaddr_t *ba);
338 int ba2oui(const bdaddr_t *ba, char *oui);
339 int bachk(const char *str);
341 int baprintf(const char *format, ...);
342 int bafprintf(FILE *stream, const char *format, ...);
343 int basprintf(char *str, const char *format, ...);
344 int basnprintf(char *str, size_t size, const char *format, ...);
346 void *bt_malloc(size_t size);
347 void bt_free(void *ptr);
349 int bt_error(uint16_t code);
350 const char *bt_compidtostr(int id);
356 static inline void bswap_128(const void *src, void *dst)
358 const uint8_t *s = (const uint8_t *) src;
359 uint8_t *d = (uint8_t *) dst;
362 for (i = 0; i < 16; i++)
366 #if __BYTE_ORDER == __BIG_ENDIAN
368 #define ntoh64(x) (x)
370 static inline void ntoh128(const uint128_t *src, uint128_t *dst)
372 memcpy(dst, src, sizeof(uint128_t));
375 static inline void btoh128(const uint128_t *src, uint128_t *dst)
382 static inline uint64_t ntoh64(uint64_t n)
385 uint64_t tmp = ntohl(n & 0x00000000ffffffff);
393 static inline void ntoh128(const uint128_t *src, uint128_t *dst)
398 static inline void btoh128(const uint128_t *src, uint128_t *dst)
400 memcpy(dst, src, sizeof(uint128_t));
405 #define hton64(x) ntoh64(x)
406 #define hton128(x, y) ntoh128(x, y)
407 #define htob128(x, y) btoh128(x, y)
413 #endif /* __BLUETOOTH_H */