1 /* 2 * Copyright (C) 2015 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /* 39 * bluetooth.h 40 * 41 * Numbers defined or derived from the official Bluetooth specification 42 */ 43 44 #ifndef __BLUETOOTH_H 45 #define __BLUETOOTH_H 46 47 #include <stdint.h> 48 49 /** 50 * HCI Transport 51 */ 52 53 /** 54 * packet types - used in BTstack and over the H4 UART interface 55 */ 56 #define HCI_COMMAND_DATA_PACKET 0x01 57 #define HCI_ACL_DATA_PACKET 0x02 58 #define HCI_SCO_DATA_PACKET 0x03 59 #define HCI_EVENT_PACKET 0x04 60 61 /** 62 * HCI Layer 63 */ 64 65 // 66 // Error Codes 67 // 68 69 // from Bluetooth Core Specification 70 #define ERROR_CODE_UNKNOWN_HCI_COMMAND 0x01 71 #define ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02 72 #define ERROR_CODE_HARDWARE_FAILURE 0x03 73 #define ERROR_CODE_PAGE_TIMEOUT 0x04 74 #define ERROR_CODE_AUTHENTICATION_FAILURE 0x05 75 #define ERROR_CODE_PIN_OR_KEY_MISSING 0x06 76 #define ERROR_CODE_MEMORY_CAPACITY_EXCEEDED 0x07 77 #define ERROR_CODE_CONNECTION_TIMEOUT 0x08 78 #define ERROR_CODE_CONNECTION_LIMIT_EXCEEDED 0x09 79 #define ERROR_CODE_SYNCHRONOUS_CONNECTION_LIMIT_TO_A_DEVICE_EXCEEDED 0x0A 80 #define ERROR_CODE_ACL_CONNECTION_ALREADY_EXISTS 0x0B 81 #define ERROR_CODE_COMMAND_DISALLOWED 0x0C 82 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES 0x0D 83 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS 0x0E 84 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_UNACCEPTABLE_BD_ADDR 0x0F 85 #define ERROR_CODE_CONNECTION_ACCEPT_TIMEOUT_EXCEEDED 0x10 86 #define ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE 0x11 87 #define ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS 0x12 88 #define ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION 0x13 89 #define ERROR_CODE_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES 0x14 90 #define ERROR_CODE_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_POWER_OFF 0x15 91 #define ERROR_CODE_CONNECTION_TERMINATED_BY_LOCAL_HOST 0x16 92 #define ERROR_CODE_REPEATED_ATTEMPTS 0x17 93 #define ERROR_CODE_PAIRING_NOT_ALLOWED 0x18 94 #define ERROR_CODE_UNKNOWN_LMP_PDU 0x19 95 #define ERROR_CODE_UNSUPPORTED_REMOTE_FEATURE_UNSUPPORTED_LMP_FEATURE 0x1A 96 #define ERROR_CODE_SCO_OFFSET_REJECTED 0x1B 97 #define ERROR_CODE_SCO_INTERVAL_REJECTED 0x1C 98 #define ERROR_CODE_SCO_AIR_MODE_REJECTED 0x1D 99 #define ERROR_CODE_INVALID_LMP_PARAMETERS_INVALID_LL_PARAMETERS 0x1E 100 #define ERROR_CODE_UNSPECIFIED_ERROR 0x1F 101 #define ERROR_CODE_UNSUPPORTED_LMP_PARAMETER_VALUE_UNSUPPORTED_LL_PARAMETER_VALUE 0x20 102 #define ERROR_CODE_ROLE_CHANGE_NOT_ALLOWED 0x21 103 #define ERROR_CODE_LMP_RESPONSE_TIMEOUT_LL_RESPONSE_TIMEOUT 0x22 104 #define ERROR_CODE_LMP_ERROR_TRANSACTION_COLLISION 0x23 105 #define ERROR_CODE_LMP_PDU_NOT_ALLOWED 0x24 106 #define ERROR_CODE_ENCRYPTION_MODE_NOT_ACCEPTABLE 0x25 107 #define ERROR_CODE_LINK_KEY_CANNOT_BE_CHANGED 0x26 108 #define ERROR_CODE_REQUESTED_QOS_NOT_SUPPORTED 0x27 109 #define ERROR_CODE_INSTANT_PASSED 0x28 110 #define ERROR_CODE_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29 111 #define ERROR_CODE_DIFFERENT_TRANSACTION_COLLISION 0x2A 112 #define ERROR_CODE_RESERVED 0x2B 113 #define ERROR_CODE_QOS_UNACCEPTABLE_PARAMETER 0x2C 114 #define ERROR_CODE_QOS_REJECTED 0x2D 115 #define ERROR_CODE_CHANNEL_CLASSIFICATION_NOT_SUPPORTED 0x2E 116 #define ERROR_CODE_INSUFFICIENT_SECURITY 0x2F 117 #define ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE 0x30 118 // #define ERROR_CODE_RESERVED 119 #define ERROR_CODE_ROLE_SWITCH_PENDING 0x32 120 // #define ERROR_CODE_RESERVED 121 #define ERROR_CODE_RESERVED_SLOT_VIOLATION 0x34 122 #define ERROR_CODE_ROLE_SWITCH_FAILED 0x35 123 #define ERROR_CODE_EXTENDED_INQUIRY_RESPONSE_TOO_LARGE 0x36 124 #define ERROR_CODE_SECURE_SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST 0x37 125 #define ERROR_CODE_HOST_BUSY_PAIRING 0x38 126 #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_NO_SUITABLE_CHANNEL_FOUND 0x39 127 #define ERROR_CODE_CONTROLLER_BUSY 0x3A 128 #define ERROR_CODE_UNACCEPTABLE_CONNECTION_PARAMETERS 0x3B 129 #define ERROR_CODE_DIRECTED_ADVERTISING_TIMEOUT 0x3C 130 #define ERROR_CODE_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE 0x3D 131 #define ERROR_CODE_CONNECTION_FAILED_TO_BE_ESTABLISHED 0x3E 132 #define ERROR_CODE_MAC_CONNECTION_FAILED 0x3F 133 #define ERROR_CODE_COARSE_CLOCK_ADJUSTMENT_REJECTED_BUT_WILL_TRY_TO_ADJUST_USING_CLOCK_DRAGGING 0x40 134 135 136 /** 137 * Default INQ Mode 138 */ 139 #define HCI_INQUIRY_LAP 0x9E8B33L // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC) 140 141 /** 142 * SSP IO Capabilities 143 */ 144 #define SSP_IO_CAPABILITY_DISPLAY_ONLY 0 145 #define SSP_IO_CAPABILITY_DISPLAY_YES_NO 1 146 #define SSP_IO_CAPABILITY_KEYBOARD_ONLY 2 147 #define SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT 3 148 #define SSP_IO_CAPABILITY_UNKNOWN 0xff 149 150 151 /** 152 * SSP Authentication Requirements, see IO Capability Request Reply Commmand 153 */ 154 155 // Numeric comparison with automatic accept allowed. 156 #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_NO_BONDING 0x00 157 158 // Use IO Capabilities to deter- mine authentication procedure 159 #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_NO_BONDING 0x01 160 161 // Numeric compar- ison with automatic accept allowed. 162 #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_DEDICATED_BONDING 0x02 163 164 // Use IO Capabilities to determine authentication procedure 165 #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_DEDICATED_BONDING 0x03 166 167 // Numeric Compari- son with automatic accept allowed. 168 #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_GENERAL_BONDING 0x04 169 170 // . Use IO capabilities to determine authentication procedure. 171 #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_GENERAL_BONDING 0x05 172 173 174 // Events from host controller to host 175 176 /** 177 * @format 1 178 * @param status 179 */ 180 #define HCI_EVENT_INQUIRY_COMPLETE 0x01 181 // no format yet, can contain multiple results 182 183 /** 184 * @format 1B11132 185 * @param num_responses 186 * @param bd_addr 187 * @param page_scan_repetition_mode 188 * @param reserved1 189 * @param reserved2 190 * @param class_of_device 191 * @param clock_offset 192 */ 193 #define HCI_EVENT_INQUIRY_RESULT 0x02 194 195 /** 196 * @format 12B11 197 * @param status 198 * @param connection_handle 199 * @param bd_addr 200 * @param link_type 201 * @param encryption_enabled 202 */ 203 #define HCI_EVENT_CONNECTION_COMPLETE 0x03 204 /** 205 * @format B31 206 * @param bd_addr 207 * @param class_of_device 208 * @param link_type 209 */ 210 #define HCI_EVENT_CONNECTION_REQUEST 0x04 211 /** 212 * @format 121 213 * @param status 214 * @param connection_handle 215 * @param reason 216 */ 217 #define HCI_EVENT_DISCONNECTION_COMPLETE 0x05 218 /** 219 * @format 12 220 * @param status 221 * @param connection_handle 222 */ 223 #define HCI_EVENT_AUTHENTICATION_COMPLETE_EVENT 0x06 224 /** 225 * @format 1BN 226 * @param status 227 * @param bd_addr 228 * @param remote_name 229 */ 230 #define HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07 231 /** 232 * @format 121 233 * @param status 234 * @param connection_handle 235 * @param encryption_enabled 236 */ 237 #define HCI_EVENT_ENCRYPTION_CHANGE 0x08 238 /** 239 * @format 12 240 * @param status 241 * @param connection_handle 242 */ 243 #define HCI_EVENT_CHANGE_CONNECTION_LINK_KEY_COMPLETE 0x09 244 /** 245 * @format 121 246 * @param status 247 * @param connection_handle 248 * @param key_flag 249 */ 250 #define HCI_EVENT_MASTER_LINK_KEY_COMPLETE 0x0A 251 #define HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE 0x0B 252 #define HCI_EVENT_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C 253 #define HCI_EVENT_QOS_SETUP_COMPLETE 0x0D 254 255 /** 256 * @format 12R 257 * @param num_hci_command_packets 258 * @param command_opcode 259 * @param return_parameters 260 */ 261 #define HCI_EVENT_COMMAND_COMPLETE 0x0E 262 /** 263 * @format 112 264 * @param status 265 * @param num_hci_command_packets 266 * @param command_opcode 267 */ 268 #define HCI_EVENT_COMMAND_STATUS 0x0F 269 270 /** 271 * @format 121 272 * @param hardware_code 273 */ 274 #define HCI_EVENT_HARDWARE_ERROR 0x10 275 276 #define HCI_EVENT_FLUSH_OCCURED 0x11 277 278 /** 279 * @format 1B1 280 * @param status 281 * @param bd_addr 282 * @param role 283 */ 284 #define HCI_EVENT_ROLE_CHANGE 0x12 285 286 #define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13 287 #define HCI_EVENT_MODE_CHANGE_EVENT 0x14 288 #define HCI_EVENT_RETURN_LINK_KEYS 0x15 289 #define HCI_EVENT_PIN_CODE_REQUEST 0x16 290 #define HCI_EVENT_LINK_KEY_REQUEST 0x17 291 #define HCI_EVENT_LINK_KEY_NOTIFICATION 0x18 292 #define HCI_EVENT_DATA_BUFFER_OVERFLOW 0x1A 293 #define HCI_EVENT_MAX_SLOTS_CHANGED 0x1B 294 #define HCI_EVENT_READ_CLOCK_OFFSET_COMPLETE 0x1C 295 #define HCI_EVENT_PACKET_TYPE_CHANGED 0x1D 296 297 /** 298 * @format 1B11321 299 * @param num_responses 300 * @param bd_addr 301 * @param page_scan_repetition_mode 302 * @param reserved 303 * @param class_of_device 304 * @param clock_offset 305 * @param rssi 306 */ 307 #define HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22 308 309 /** 310 * @format 1HB111221 311 * @param status 312 * @param handle 313 * @param bd_addr 314 * @param link_type 315 * @param transmission_interval 316 * @param retransmission_interval 317 * @param rx_packet_length 318 * @param tx_packet_length 319 * @param air_mode 320 */ 321 #define HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE 0x2C 322 323 // TODO: serialize extended_inquiry_response and provide parser 324 /** 325 * @format 1B11321 326 * @param num_responses 327 * @param bd_addr 328 * @param page_scan_repetition_mode 329 * @param reserved 330 * @param class_of_device 331 * @param clock_offset 332 * @param rssi 333 */ 334 #define HCI_EVENT_EXTENDED_INQUIRY_RESPONSE 0x2F 335 336 /** 337 * @format 1H 338 * @param status 339 * @param handle 340 */ 341 #define HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30 342 343 #define HCI_EVENT_IO_CAPABILITY_REQUEST 0x31 344 #define HCI_EVENT_IO_CAPABILITY_RESPONSE 0x32 345 #define HCI_EVENT_USER_CONFIRMATION_REQUEST 0x33 346 #define HCI_EVENT_USER_PASSKEY_REQUEST 0x34 347 #define HCI_EVENT_REMOTE_OOB_DATA_REQUEST 0x35 348 #define HCI_EVENT_SIMPLE_PAIRING_COMPLETE 0x36 349 350 #define HCI_EVENT_LE_META 0x3E 351 352 /** 353 * @format 11211B2221 354 * @param subevent_code 355 * @param status 356 * @param connection_handle 357 * @param role 358 * @param peer_address_type 359 * @param peer_address 360 * @param conn_interval 361 * @param conn_latency 362 * @param supervision_timeout 363 * @param master_clock_accuracy 364 */ 365 #define HCI_SUBEVENT_LE_CONNECTION_COMPLETE 0x01 366 #define HCI_SUBEVENT_LE_ADVERTISING_REPORT 0x02 367 #define HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE 0x03 368 #define HCI_SUBEVENT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04 369 #define HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST 0x05 370 371 // last used HCI_EVENT in 2.1 is 0x3d 372 // last used HCI_EVENT in 4.1 is 0x57 373 374 /** 375 * L2CAP Layer 376 */ 377 378 // Fixed PSM numbers 379 #define PSM_SDP 0x01 380 #define PSM_RFCOMM 0x03 381 #define PSM_BNEP 0x0F 382 #define PSM_HID_CONTROL 0x11 383 #define PSM_HID_INTERRUPT 0x13 384 385 386 387 388 #endif