OSDN Git Service

Initial Contribution
[android-x86/external-bluetooth-bluez.git] / libs / include / bluetooth / bluetooth.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
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>
8  *
9  *
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.
14  *
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.
19  *
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
23  *
24  */
25
26 #ifndef __BLUETOOTH_H
27 #define __BLUETOOTH_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <stdio.h>
34 #include <stdint.h>
35 #include <string.h>
36 #include <endian.h>
37 #include <byteswap.h>
38
39 #ifndef AF_BLUETOOTH
40 #define AF_BLUETOOTH    31
41 #define PF_BLUETOOTH    AF_BLUETOOTH
42 #endif
43
44 #ifndef SOL_BLUETOOTH
45 #define SOL_BLUETOOTH   274
46 #endif
47
48 #define BTPROTO_L2CAP   0
49 #define BTPROTO_HCI     1
50 #define BTPROTO_SCO     2
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
56
57 #define SOL_HCI         0
58 #define SOL_L2CAP       6
59 #define SOL_SCO         17
60 #define SOL_RFCOMM      18
61
62 /* Connection and socket states */
63 enum {
64         BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
65         BT_OPEN,
66         BT_BOUND,
67         BT_LISTEN,
68         BT_CONNECT,
69         BT_CONNECT2,
70         BT_CONFIG,
71         BT_DISCONN,
72         BT_CLOSED
73 };
74
75 /* Byte order conversions */
76 #if __BYTE_ORDER == __LITTLE_ENDIAN
77 #define htobs(d)  (d)
78 #define htobl(d)  (d)
79 #define btohs(d)  (d)
80 #define btohl(d)  (d)
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)
86 #else
87 #error "Unknown byte order"
88 #endif
89
90 /* Bluetooth unaligned access */
91 #define bt_get_unaligned(ptr)                   \
92 ({                                              \
93         struct __attribute__((packed)) {        \
94                 typeof(*(ptr)) __v;             \
95         } *__p = (void *) (ptr);                \
96         __p->__v;                               \
97 })
98
99 #define bt_put_unaligned(val, ptr)              \
100 do {                                            \
101         struct __attribute__((packed)) {        \
102                 typeof(*(ptr)) __v;             \
103         } *__p = (void *) (ptr);                \
104         __p->__v = (val);                       \
105 } while(0)
106
107 /* BD Address */
108 typedef struct {
109         uint8_t b[6];
110 } __attribute__((packed)) bdaddr_t;
111
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}})
115
116 /* Copy, swap, convert BD Address */
117 static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
118 {
119         return memcmp(ba1, ba2, sizeof(bdaddr_t));
120 }
121 static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
122 {
123         memcpy(dst, src, sizeof(bdaddr_t));
124 }
125
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);
133
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, ...);
138
139 void *bt_malloc(size_t size);
140 void bt_free(void *ptr);
141
142 int bt_error(uint16_t code);
143 char *bt_compidtostr(int id);
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif /* __BLUETOOTH_H */