• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 The Android Open Source Project
4  *  Copyright 2002 - 2004 Open Interface North America, Inc. All rights
5  *                        reserved.
6  *
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at:
10  *
11  *  http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *
19  ******************************************************************************/
20 #ifndef _OI_BT_SPEC_H
21 #define _OI_BT_SPEC_H
22 /**
23  * @file
24  *
25  * This file contains common definitions from the Bluetooth specification.
26  *
27  */
28 
29 /*******************************************************************************
30   $Revision: #1 $
31  ******************************************************************************/
32 
33 #include "oi_stddefs.h"
34 
35 /** \addtogroup Misc Miscellaneous APIs */
36 /**@{*/
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /** The maximum number of active slaves in a piconet. */
43 #define OI_BT_MAX_ACTIVE_SLAVES 7
44 
45 /** the number of bytes in a Bluetooth device address (BD_ADDR) */
46 #define OI_BD_ADDR_BYTE_SIZE 6
47 
48 /**
49  * 48-bit Bluetooth device address
50  *
51  * Because 48-bit integers may not be supported on all platforms, the
52  * address is defined as an array of bytes. This array is big-endian,
53  * meaning that
54  *  - array[0] contains bits 47-40,
55  *  - array[1] contains bits 39-32,
56  *  - array[2] contains bits 31-24,
57  *  - array[3] contains bits 23-16,
58  *  - array[4] contains bits 15-8, and
59  *  - array[5] contains bits 7-0.
60  */
61 typedef struct {
62   /* Bluetooth device address represented as an array of 8-bit values */
63   uint8_t addr[OI_BD_ADDR_BYTE_SIZE];
64 } OI_BD_ADDR;
65 
66 /**
67  * @name Data types for working with UUIDs
68  * UUIDs are 16 bytes (128 bits).
69  *
70  * To avoid having to pass around 128-bit values all the time, 32-bit and 16-bit
71  * UUIDs are defined, along with a mapping from the shorter versions to the full
72  * version.
73  *
74  * @{
75  */
76 
77 /**
78  * 16-bit representation of a 128-bit UUID
79  */
80 typedef uint16_t OI_UUID16;
81 
82 /**
83  * 32-bit representation of a 128-bit UUID
84  */
85 typedef uint32_t OI_UUID32;
86 
87 /**
88  * number of bytes in a 128 bit UUID
89  */
90 #define OI_BT_UUID128_SIZE 16
91 
92 /**
93  * number of bytes in IPv6 style addresses
94  */
95 #define OI_BT_IPV6ADDR_SIZE 16
96 
97 /**
98  * type definition for a 128-bit UUID
99  *
100  * To simplify conversion between 128-bit UUIDs and 16-bit and 32-bit UUIDs,
101  * the most significant 32 bits are stored with the same endian-ness as is
102  * native on the target (local) device. The remainder of the 128-bit UUID is
103  * stored as bytes in big-endian order.
104  */
105 typedef struct {
106   /* most significant 32 bits of 128-bit UUID */
107   uint32_t ms32bits;
108   /* remainder of 128-bit UUID, array of 8-bit values */
109   uint8_t base[OI_BT_UUID128_SIZE - sizeof(uint32_t)];
110 } OI_UUID128;
111 
112 /** @} */
113 
114 /** number of bytes in a link key */
115 #define OI_BT_LINK_KEY_SIZE 16
116 
117 /**
118  * type definition for a baseband link key
119  *
120  * Because 128-bit integers may not be supported on all platforms, we define
121  * link keys as an array of bytes. Unlike the Bluetooth device address,
122  * the link key is stored in little-endian order, meaning that
123  *  - array[0]  contains bits 0  - 7,
124  *  - array[1]  contains bits 8  - 15,
125  *  - array[2]  contains bits 16 - 23,
126  *  - array[3]  contains bits 24 - 31,
127  *  - array[4]  contains bits 32 - 39,
128  *  - array[5]  contains bits 40 - 47,
129  *  - array[6]  contains bits 48 - 55,
130  *  - array[7]  contains bits 56 - 63,
131  *  - array[8]  contains bits 64 - 71,
132  *  - array[9]  contains bits 72 - 79,
133  *  - array[10] contains bits 80 - 87,
134  *  - array[11] contains bits 88 - 95,
135  *  - array[12] contains bits 96 - 103,
136  *  - array[13] contains bits 104- 111,
137  *  - array[14] contains bits 112- 119, and
138  *  - array[15] contains bits 120- 127.
139  */
140 typedef struct {
141   /* link key represented as an array of 8-bit values */
142   uint8_t key[OI_BT_LINK_KEY_SIZE];
143 } OI_LINK_KEY;
144 
145 /** Out-of-band data size - C and R values are 16-bytes each */
146 #define OI_BT_OOB_NUM_BYTES 16
147 
148 typedef struct {
149   /* same struct used for C and R values */
150   uint8_t value[OI_BT_OOB_NUM_BYTES];
151 } OI_OOB_DATA;
152 
153 /**
154  * link key types
155  */
156 typedef enum {
157   OI_LINK_KEY_TYPE_COMBO = 0,           /* combination key */
158   OI_LINK_KEY_TYPE_LOCAL_UNIT = 1,      /* local unit key */
159   OI_LINK_KEY_TYPE_REMOTE_UNIT = 2,     /* remote unit key */
160   OI_LINK_KEY_TYPE_DEBUG_COMBO = 3,     /* debug combination key */
161   OI_LINK_KEY_TYPE_UNAUTHENTICATED = 4, /* Unauthenticated */
162   OI_LINK_KEY_TYPE_AUTHENTICATED = 5,   /* Authenticated */
163   OI_LINK_KEY_TYPE_CHANGED_COMBO = 6    /* Changed */
164 
165 } OI_BT_LINK_KEY_TYPE;
166 
167 /* Number of bytes allocated for a PIN (personal indentification number) */
168 #define OI_BT_PIN_CODE_SIZE 16
169 
170 /* data type for a PIN (PINs are treated as strings.) */
171 typedef struct {
172   /* PIN represented as an array of 8-bit values */
173   uint8_t pin[OI_BT_PIN_CODE_SIZE];
174 } OI_PIN_CODE;
175 
176 /* maximum number of SCO connections per device: 3 as of version 2.0+EDR
177     of the Bluetooth specification (see sec 4.3 of vol 2 part B) */
178 #define OI_BT_MAX_SCO_CONNECTIONS 3
179 
180 /** data type for clock offset */
181 typedef uint16_t OI_BT_CLOCK_OFFSET;
182 
183 /** data type for a LM handle */
184 typedef uint16_t OI_HCI_LM_HANDLE;
185 
186 /** opaque data type for a SCO or ACL connection handle */
187 typedef struct _OI_HCI_CONNECTION* OI_HCI_CONNECTION_HANDLE;
188 
189 /** data type for HCI Error Code, as defined in oi_hcispec.h */
190 typedef uint8_t OI_HCI_ERROR_CODE;
191 
192 /**
193  * The Bluetooth device type is indicated by a 24-bit bitfield, represented as a
194  * 32-bit number in the stack. The bit layout and values for device class are
195  * specified in the file oi_bt_assigned_nos.h and in the Bluetooth "Assigned
196  * Numbers" specification at http://www.bluetooth.org/assigned-numbers/.
197  */
198 typedef uint32_t OI_BT_DEVICE_CLASS;
199 /* Bits 0-1 contain format type. */
200 #define OI_BT_DEV_CLASS_FORMAT_MASK 0x000003
201 /* Bits 2-7 contain minor device class value. */
202 #define OI_BT_DEV_CLASS_MINOR_DEVICE_MASK 0x0000FC
203 /* Bits 8-12 contain major device class value. */
204 #define OI_BT_DEV_CLASS_MAJOR_DEVICE_MASK 0x001F00
205 /* Bits 13-23 contain major service class value. */
206 #define OI_BT_DEV_CLASS_MAJOR_SERVICE_MASK 0xFFE000
207 
208 /** There is currently only one device class format defined, type 00. */
209 #define OI_BT_DEV_CLASS_FORMAT_TYPE 00
210 
211 /* Bit 13 in device class indicates limited discoverability mode (GAP v2.0+EDR,
212  * section 4.1.2.2)
213  */
214 #define OI_BT_DEV_CLASS_LIMITED_DISCO_BIT BIT13
215 
216 /** macro to test validity of the Device Class Format */
217 #define OI_BT_VALID_DEVICE_CLASS_FORMAT(class) \
218   (OI_BT_DEV_CLASS_FORMAT_TYPE == ((class) & OI_BT_DEV_CLASS_FORMAT_MASK))
219 
220 /* the time between baseband clock ticks, currently 625 microseconds (one slot)
221  */
222 #define OI_BT_TICK 625
223 /* some macros to convert to/from baseband clock ticks - no floating point! */
224 #define OI_SECONDS_TO_BT_TICKS(secs) ((secs)*1600)
225 #define OI_BT_TICKS_TO_SECONDS(ticks) ((ticks) / 1600)
226 #define OI_MSECS_TO_BT_TICKS(msecs) (((msecs)*8) / 5)
227 #define OI_BT_TICKS_TO_MSECS(ticks) (((ticks)*5) / 8)
228 
229 /** EIR byte order */
230 #define OI_EIR_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 
236 /**@}*/
237 
238 /*****************************************************************************/
239 #endif /* _OI_BT_SPEC_H */
240