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