1 /****************************************************************************** 2 * 3 * Copyright 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 peripherals in a piconet. */ 43 #define OI_BT_MAX_ACTIVE_PERIPHERALS 7 44 45 /** 46 * @name Data types for working with UUIDs 47 * UUIDs are 16 bytes (128 bits). 48 * 49 * To avoid having to pass around 128-bit values all the time, 32-bit and 16-bit 50 * UUIDs are defined, along with a mapping from the shorter versions to the full 51 * version. 52 * 53 * @{ 54 */ 55 56 /** 57 * 16-bit representation of a 128-bit UUID 58 */ 59 typedef uint16_t OI_UUID16; 60 61 /** 62 * 32-bit representation of a 128-bit UUID 63 */ 64 typedef uint32_t OI_UUID32; 65 66 /** 67 * number of bytes in a 128 bit UUID 68 */ 69 #define OI_BT_UUID128_SIZE 16 70 71 /** 72 * number of bytes in IPv6 style addresses 73 */ 74 #define OI_BT_IPV6ADDR_SIZE 16 75 76 /** 77 * type definition for a 128-bit UUID 78 * 79 * To simplify conversion between 128-bit UUIDs and 16-bit and 32-bit UUIDs, 80 * the most significant 32 bits are stored with the same endian-ness as is 81 * native on the target (local) device. The remainder of the 128-bit UUID is 82 * stored as bytes in big-endian order. 83 */ 84 typedef struct { 85 /* most significant 32 bits of 128-bit UUID */ 86 uint32_t ms32bits; 87 /* remainder of 128-bit UUID, array of 8-bit values */ 88 uint8_t base[OI_BT_UUID128_SIZE - sizeof(uint32_t)]; 89 } OI_UUID128; 90 91 /** @} */ 92 93 /** number of bytes in a link key */ 94 #define OI_BT_LINK_KEY_SIZE 16 95 96 /** 97 * type definition for a baseband link key 98 * 99 * Because 128-bit integers may not be supported on all platforms, we define 100 * link keys as an array of bytes. Unlike the Bluetooth device address, 101 * the link key is stored in little-endian order, meaning that 102 * - array[0] contains bits 0 - 7, 103 * - array[1] contains bits 8 - 15, 104 * - array[2] contains bits 16 - 23, 105 * - array[3] contains bits 24 - 31, 106 * - array[4] contains bits 32 - 39, 107 * - array[5] contains bits 40 - 47, 108 * - array[6] contains bits 48 - 55, 109 * - array[7] contains bits 56 - 63, 110 * - array[8] contains bits 64 - 71, 111 * - array[9] contains bits 72 - 79, 112 * - array[10] contains bits 80 - 87, 113 * - array[11] contains bits 88 - 95, 114 * - array[12] contains bits 96 - 103, 115 * - array[13] contains bits 104- 111, 116 * - array[14] contains bits 112- 119, and 117 * - array[15] contains bits 120- 127. 118 */ 119 typedef struct { 120 /* link key represented as an array of 8-bit values */ 121 uint8_t key[OI_BT_LINK_KEY_SIZE]; 122 } OI_LINK_KEY; 123 124 /** Out-of-band data size - C and R values are 16-bytes each */ 125 #define OI_BT_OOB_NUM_BYTES 16 126 127 typedef struct { 128 /* same struct used for C and R values */ 129 uint8_t value[OI_BT_OOB_NUM_BYTES]; 130 } OI_OOB_DATA; 131 132 /** 133 * link key types 134 */ 135 typedef enum { 136 OI_LINK_KEY_TYPE_COMBO = 0, /* combination key */ 137 OI_LINK_KEY_TYPE_LOCAL_UNIT = 1, /* local unit key */ 138 OI_LINK_KEY_TYPE_REMOTE_UNIT = 2, /* remote unit key */ 139 OI_LINK_KEY_TYPE_DEBUG_COMBO = 3, /* debug combination key */ 140 OI_LINK_KEY_TYPE_UNAUTHENTICATED = 4, /* Unauthenticated */ 141 OI_LINK_KEY_TYPE_AUTHENTICATED = 5, /* Authenticated */ 142 OI_LINK_KEY_TYPE_CHANGED_COMBO = 6 /* Changed */ 143 144 } OI_BT_LINK_KEY_TYPE; 145 146 /* Number of bytes allocated for a PIN (personal indentification number) */ 147 #define OI_BT_PIN_CODE_SIZE 16 148 149 /* data type for a PIN (PINs are treated as strings.) */ 150 typedef struct { 151 /* PIN represented as an array of 8-bit values */ 152 uint8_t pin[OI_BT_PIN_CODE_SIZE]; 153 } OI_PIN_CODE; 154 155 /* maximum number of SCO connections per device: 3 as of version 2.0+EDR 156 of the Bluetooth specification (see sec 4.3 of vol 2 part B) */ 157 #define OI_BT_MAX_SCO_CONNECTIONS 3 158 159 /** data type for clock offset */ 160 typedef uint16_t OI_BT_CLOCK_OFFSET; 161 162 /** data type for a LM handle */ 163 typedef uint16_t OI_HCI_LM_HANDLE; 164 165 /** opaque data type for a SCO or ACL connection handle */ 166 typedef struct _OI_HCI_CONNECTION* OI_HCI_CONNECTION_HANDLE; 167 168 /** data type for HCI Error Code, as defined in oi_hcispec.h */ 169 typedef uint8_t OI_HCI_ERROR_CODE; 170 171 /** 172 * The Bluetooth device type is indicated by a 24-bit bitfield, represented as a 173 * 32-bit number in the stack. The bit layout and values for device class are 174 * specified in the file oi_bt_assigned_nos.h and in the Bluetooth "Assigned 175 * Numbers" specification at http://www.bluetooth.org/assigned-numbers/. 176 */ 177 typedef uint32_t OI_BT_DEVICE_CLASS; 178 /* Bits 0-1 contain format type. */ 179 #define OI_BT_DEV_CLASS_FORMAT_MASK 0x000003 180 /* Bits 2-7 contain minor device class value. */ 181 #define OI_BT_DEV_CLASS_MINOR_DEVICE_MASK 0x0000FC 182 /* Bits 8-12 contain major device class value. */ 183 #define OI_BT_DEV_CLASS_MAJOR_DEVICE_MASK 0x001F00 184 /* Bits 13-23 contain major service class value. */ 185 #define OI_BT_DEV_CLASS_MAJOR_SERVICE_MASK 0xFFE000 186 187 /** There is currently only one device class format defined, type 00. */ 188 #define OI_BT_DEV_CLASS_FORMAT_TYPE 00 189 190 /* Bit 13 in device class indicates limited discoverability mode (GAP v2.0+EDR, 191 * section 4.1.2.2) 192 */ 193 #define OI_BT_DEV_CLASS_LIMITED_DISCO_BIT BIT13 194 195 /** macro to test validity of the Device Class Format */ 196 #define OI_BT_VALID_DEVICE_CLASS_FORMAT(class) \ 197 (OI_BT_DEV_CLASS_FORMAT_TYPE == ((class) & OI_BT_DEV_CLASS_FORMAT_MASK)) 198 199 /* the time between baseband clock ticks, currently 625 microseconds (one slot) 200 */ 201 #define OI_BT_TICK 625 202 /* some macros to convert to/from baseband clock ticks - no floating point! */ 203 #define OI_SECONDS_TO_BT_TICKS(secs) ((secs)*1600) 204 #define OI_BT_TICKS_TO_SECONDS(ticks) ((ticks) / 1600) 205 #define OI_MSECS_TO_BT_TICKS(msecs) (((msecs)*8) / 5) 206 #define OI_BT_TICKS_TO_MSECS(ticks) (((ticks)*5) / 8) 207 208 /** EIR byte order */ 209 #define OI_EIR_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER 210 211 #ifdef __cplusplus 212 } 213 #endif 214 215 /**@}*/ 216 217 /*****************************************************************************/ 218 #endif /* _OI_BT_SPEC_H */ 219