oi_bt_spec.h 7.7 KB

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