1 /* 2 * Copyright (C) 2014 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 #define BTSTACK_FILE__ "hci_cmd.c" 39 40 /* 41 * hci_cmd.c 42 * 43 * Created by Matthias Ringwald on 7/23/09. 44 */ 45 46 #include "btstack_config.h" 47 48 #include "hci.h" 49 #include "hci_cmd.h" 50 #include "btstack_debug.h" 51 52 #include <string.h> 53 54 55 #ifdef ENABLE_SDP 56 #include "classic/sdp_util.h" 57 #endif 58 59 // calculate combined ogf/ocf value 60 #define OPCODE(ogf, ocf) ((ocf) | ((ogf) << 10)) 61 62 #define INVALID_VAR_LEN 0xffffu 63 // hci_le_set_cig_parameters_test has 10 arrayed parameters 64 #define MAX_NR_ARRAY_FIELDS 10 65 #define INVALID_ARRAY_LEN 0xff 66 67 /** 68 * construct HCI Command based on template 69 * 70 * Format: 71 * 1,2,3,4: one to four byte value 72 * H: HCI connection handle 73 * B: Bluetooth Baseband Address (BD_ADDR) 74 * D: 8 byte data block 75 * E: Extended Inquiry Result 76 * N: Name up to 248 chars, \0 terminated 77 * P: 16 byte data block. Pairing code, Simple Pairing Hash and Randomizer 78 * A: 31 bytes advertising data 79 * S: Service Record (Data Element Sequence) 80 * Q: 32 byte data block, e.g. for X and Y coordinates of P-256 public key 81 * J: 8-bit length of variable size element 82 * V: variable size element, len was given with param 'J' 83 * a: number of elements in following arrayed parameters(s), specified as '[...]' 84 * b: bit field indicating number of arrayed parameters(s), specified as '[...]' 85 * [: start of arrayed param sequence 86 * ]: end of arrayed param sequence 87 */ 88 uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr){ 89 90 hci_cmd_buffer[0] = cmd->opcode & 0xffu; 91 hci_cmd_buffer[1] = cmd->opcode >> 8; 92 uint16_t pos = 3; 93 94 const char *format = cmd->format; 95 uint16_t word; 96 uint32_t longword; 97 uint8_t * ptr; 98 uint16_t var_len = INVALID_VAR_LEN; 99 100 const char * array_format = NULL; 101 void * array_data[MAX_NR_ARRAY_FIELDS]; 102 uint8_t array_num_elements = INVALID_ARRAY_LEN; 103 uint8_t array_num_fields; 104 uint8_t array_element_index; 105 106 bool done_format = false; 107 while (!done_format) { 108 bool done_array; 109 switch(*format) { 110 case 0: 111 done_format = true; 112 break; 113 case '1': // 8 bit value 114 word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE 115 hci_cmd_buffer[pos++] = word & 0xffu; 116 break; 117 case '2': // 16 bit value 118 word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE 119 hci_cmd_buffer[pos++] = word & 0xffu; 120 hci_cmd_buffer[pos++] = word >> 8; 121 break; 122 case 'H': // hci_handle 123 word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE 124 hci_cmd_buffer[pos++] = word & 0xffu; 125 hci_cmd_buffer[pos++] = word >> 8; 126 break; 127 case '3': 128 longword = va_arg(argptr, uint32_t); // LCOV_EXCL_BR_LINE 129 hci_cmd_buffer[pos++] = longword; 130 hci_cmd_buffer[pos++] = longword >> 8; 131 hci_cmd_buffer[pos++] = longword >> 16; 132 break; 133 case '4': 134 longword = va_arg(argptr, uint32_t); // LCOV_EXCL_BR_LINE 135 hci_cmd_buffer[pos++] = longword; 136 hci_cmd_buffer[pos++] = longword >> 8; 137 hci_cmd_buffer[pos++] = longword >> 16; 138 hci_cmd_buffer[pos++] = longword >> 24; 139 break; 140 case 'B': // bt-addr 141 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 142 hci_cmd_buffer[pos++] = ptr[5]; 143 hci_cmd_buffer[pos++] = ptr[4]; 144 hci_cmd_buffer[pos++] = ptr[3]; 145 hci_cmd_buffer[pos++] = ptr[2]; 146 hci_cmd_buffer[pos++] = ptr[1]; 147 hci_cmd_buffer[pos++] = ptr[0]; 148 break; 149 case 'D': // 8 byte data block 150 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 151 (void)memcpy(&hci_cmd_buffer[pos], ptr, 8); 152 pos += 8; 153 break; 154 case 'E': // Extended Inquiry Information 240 octets 155 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 156 (void)memcpy(&hci_cmd_buffer[pos], ptr, 240); 157 pos += 240; 158 break; 159 case 'N': { // UTF-8 string, null terminated 160 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 161 uint16_t len = strlen((const char*) ptr); 162 if (len > 248u) { 163 len = 248; 164 } 165 (void)memcpy(&hci_cmd_buffer[pos], ptr, len); 166 if (len < 248u) { 167 // fill remaining space with zeroes 168 memset(&hci_cmd_buffer[pos+len], 0u, 248u-len); 169 } 170 pos += 248; 171 break; 172 } 173 case 'P': // 16 byte PIN code or link key in little endian 174 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 175 (void)memcpy(&hci_cmd_buffer[pos], ptr, 16); 176 pos += 16; 177 break; 178 case 'K': // 16 byte OOB Data or Link Key in big endian 179 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 180 reverse_bytes(ptr, &hci_cmd_buffer[pos], 16); 181 pos += 16; 182 break; 183 #ifdef ENABLE_BLE 184 case 'A': // 31 bytes advertising data 185 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 186 (void)memcpy(&hci_cmd_buffer[pos], ptr, 31); 187 pos += 31; 188 break; 189 case 'J': // 8 bit variable length indicator for 'V' 190 word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE 191 var_len = word & 0xffu; 192 hci_cmd_buffer[pos++] = var_len; 193 break; 194 case 'V': 195 btstack_assert(var_len != INVALID_VAR_LEN); 196 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 197 (void)memcpy(&hci_cmd_buffer[pos], ptr, var_len); 198 pos += var_len; 199 var_len = INVALID_VAR_LEN; 200 break; 201 case 'a': 202 btstack_assert(array_num_elements == INVALID_ARRAY_LEN); 203 word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE 204 hci_cmd_buffer[pos++] = word & 0xff; 205 array_num_elements = word & 0xffu; 206 break; 207 case 'b': 208 btstack_assert(array_num_elements == INVALID_ARRAY_LEN); 209 word = va_arg(argptr, int); // LCOV_EXCL_BR_LINE 210 hci_cmd_buffer[pos++] = word & 0xff; 211 array_num_elements = count_set_bits_uint32(word & 0xffu); 212 break; 213 case '[': 214 btstack_assert(array_num_elements != INVALID_ARRAY_LEN); 215 // process array 216 format++; 217 array_format = format; 218 array_num_fields = 0; 219 done_array = false; 220 while (!done_array){ 221 switch (*format){ 222 case 0: 223 done_array = true; 224 done_format = true; 225 break; 226 case ']': 227 done_array = true; 228 break; 229 case '1': 230 case '2': 231 // all arrayed parameters are passed in as arrays 232 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 233 array_data[array_num_fields++] = ptr; 234 format++; 235 break; 236 default: 237 btstack_unreachable(); 238 break; 239 } 240 } 241 for (array_element_index = 0; array_element_index < array_num_elements ; array_element_index++){ 242 uint8_t array_field_index; 243 for (array_field_index = 0; array_field_index < array_num_fields ; array_field_index++){ 244 switch (array_format[array_field_index]){ 245 case '1': 246 hci_cmd_buffer[pos++] = ((const uint8_t *) array_data[array_field_index])[array_element_index]; 247 break; 248 case '2': 249 little_endian_store_16(hci_cmd_buffer, pos, ((const uint16_t *) array_data[array_field_index])[array_element_index]); 250 pos += 2; 251 break; 252 default: 253 btstack_unreachable(); 254 break; 255 } 256 } 257 } 258 break; 259 #endif 260 #ifdef ENABLE_LE_SECURE_CONNECTIONS 261 case 'Q': 262 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 263 reverse_bytes(ptr, &hci_cmd_buffer[pos], 32); 264 pos += 32; 265 break; 266 #endif 267 #ifdef ENABLE_SDP 268 // used by daemon 269 case 'S': { // Service Record (Data Element Sequence) 270 ptr = va_arg(argptr, uint8_t *); // LCOV_EXCL_BR_LINE 271 uint16_t len = de_get_len(ptr); 272 (void)memcpy(&hci_cmd_buffer[pos], ptr, len); 273 pos += len; 274 break; 275 } 276 #endif 277 default: 278 btstack_unreachable(); 279 break; 280 } 281 format++; 282 }; 283 hci_cmd_buffer[2] = pos - 3; 284 return pos; 285 } 286 287 /** 288 * Link Control Commands 289 */ 290 291 /** 292 * @param lap 293 * @param inquiry_length 294 * @param num_responses 295 */ 296 const hci_cmd_t hci_inquiry = { 297 HCI_OPCODE_HCI_INQUIRY, "311" 298 }; 299 300 /** 301 */ 302 const hci_cmd_t hci_inquiry_cancel = { 303 HCI_OPCODE_HCI_INQUIRY_CANCEL, "" 304 }; 305 306 /** 307 * @param bd_addr 308 * @param packet_type 309 * @param page_scan_repetition_mode 310 * @param reserved 311 * @param clock_offset 312 * @param allow_role_switch 313 */ 314 const hci_cmd_t hci_create_connection = { 315 HCI_OPCODE_HCI_CREATE_CONNECTION, "B21121" 316 }; 317 318 /** 319 * @param handle 320 * @param reason (0x05, 0x13-0x15, 0x1a, 0x29, see Errors Codes in BT Spec Part D) 321 */ 322 const hci_cmd_t hci_disconnect = { 323 HCI_OPCODE_HCI_DISCONNECT, "H1" 324 }; 325 326 /** 327 * @param bd_addr 328 */ 329 const hci_cmd_t hci_create_connection_cancel = { 330 HCI_OPCODE_HCI_CREATE_CONNECTION_CANCEL, "B" 331 }; 332 333 /** 334 * @param bd_addr 335 * @param role (become master, stay slave) 336 */ 337 const hci_cmd_t hci_accept_connection_request = { 338 HCI_OPCODE_HCI_ACCEPT_CONNECTION_REQUEST, "B1" 339 }; 340 341 /** 342 * @param bd_addr 343 * @param reason (e.g. CONNECTION REJECTED DUE TO LIMITED RESOURCES (0x0d)) 344 */ 345 const hci_cmd_t hci_reject_connection_request = { 346 HCI_OPCODE_HCI_REJECT_CONNECTION_REQUEST, "B1" 347 }; 348 349 /** 350 * @param bd_addr 351 * @param link_key 352 */ 353 const hci_cmd_t hci_link_key_request_reply = { 354 HCI_OPCODE_HCI_LINK_KEY_REQUEST_REPLY, "BP" 355 }; 356 357 /** 358 * @param bd_addr 359 */ 360 const hci_cmd_t hci_link_key_request_negative_reply = { 361 HCI_OPCODE_HCI_LINK_KEY_REQUEST_NEGATIVE_REPLY, "B" 362 }; 363 364 /** 365 * @param bd_addr 366 * @param pin_length 367 * @param pin (c-string) 368 */ 369 const hci_cmd_t hci_pin_code_request_reply = { 370 HCI_OPCODE_HCI_PIN_CODE_REQUEST_REPLY, "B1P" 371 }; 372 373 /** 374 * @param bd_addr 375 */ 376 const hci_cmd_t hci_pin_code_request_negative_reply = { 377 HCI_OPCODE_HCI_PIN_CODE_REQUEST_NEGATIVE_REPLY, "B" 378 }; 379 380 /** 381 * @param handle 382 * @param packet_type 383 */ 384 const hci_cmd_t hci_change_connection_packet_type = { 385 HCI_OPCODE_HCI_CHANGE_CONNECTION_PACKET_TYPE, "H2" 386 }; 387 388 /** 389 * @param handle 390 */ 391 const hci_cmd_t hci_authentication_requested = { 392 HCI_OPCODE_HCI_AUTHENTICATION_REQUESTED, "H" 393 }; 394 395 /** 396 * @param handle 397 * @param encryption_enable 398 */ 399 const hci_cmd_t hci_set_connection_encryption = { 400 HCI_OPCODE_HCI_SET_CONNECTION_ENCRYPTION, "H1" 401 }; 402 403 /** 404 * @param handle 405 */ 406 const hci_cmd_t hci_change_connection_link_key = { 407 HCI_OPCODE_HCI_CHANGE_CONNECTION_LINK_KEY, "H" 408 }; 409 410 /** 411 * @param bd_addr 412 * @param page_scan_repetition_mode 413 * @param reserved 414 * @param clock_offset 415 */ 416 const hci_cmd_t hci_remote_name_request = { 417 HCI_OPCODE_HCI_REMOTE_NAME_REQUEST, "B112" 418 }; 419 420 421 /** 422 * @param bd_addr 423 */ 424 const hci_cmd_t hci_remote_name_request_cancel = { 425 HCI_OPCODE_HCI_REMOTE_NAME_REQUEST_CANCEL, "B" 426 }; 427 428 /** 429 * @param handle 430 */ 431 const hci_cmd_t hci_read_remote_supported_features_command = { 432 HCI_OPCODE_HCI_READ_REMOTE_SUPPORTED_FEATURES_COMMAND, "H" 433 }; 434 435 /** 436 * @param handle 437 */ 438 const hci_cmd_t hci_read_remote_extended_features_command = { 439 HCI_OPCODE_HCI_READ_REMOTE_EXTENDED_FEATURES_COMMAND, "H1" 440 }; 441 442 /** 443 * @param handle 444 */ 445 const hci_cmd_t hci_read_remote_version_information = { 446 HCI_OPCODE_HCI_READ_REMOTE_VERSION_INFORMATION, "H" 447 }; 448 449 /** 450 * @param handle 451 * @param transmit_bandwidth 8000(64kbps) 452 * @param receive_bandwidth 8000(64kbps) 453 * @param max_latency >= 7ms for eSCO, 0xFFFF do not care 454 * @param voice_settings e.g. CVSD, Input Coding: Linear, Input Data Format: 2’s complement, data 16bit: 00011000000 == 0x60 455 * @param retransmission_effort e.g. 0xFF do not care 456 * @param packet_type at least EV3 for eSCO 457 */ 458 const hci_cmd_t hci_setup_synchronous_connection = { 459 HCI_OPCODE_HCI_SETUP_SYNCHRONOUS_CONNECTION, "H442212" 460 }; 461 462 /** 463 * @param bd_addr 464 * @param transmit_bandwidth 465 * @param receive_bandwidth 466 * @param max_latency 467 * @param voice_settings 468 * @param retransmission_effort 469 * @param packet_type 470 */ 471 const hci_cmd_t hci_accept_synchronous_connection = { 472 HCI_OPCODE_HCI_ACCEPT_SYNCHRONOUS_CONNECTION, "B442212" 473 }; 474 475 /** 476 * @param bd_addr 477 * @param IO_capability 478 * @param OOB_data_present 479 * @param authentication_requirements 480 */ 481 const hci_cmd_t hci_io_capability_request_reply = { 482 HCI_OPCODE_HCI_IO_CAPABILITY_REQUEST_REPLY, "B111" 483 }; 484 485 /** 486 * @param bd_addr 487 */ 488 const hci_cmd_t hci_user_confirmation_request_reply = { 489 HCI_OPCODE_HCI_USER_CONFIRMATION_REQUEST_REPLY, "B" 490 }; 491 492 /** 493 * @param bd_addr 494 */ 495 const hci_cmd_t hci_user_confirmation_request_negative_reply = { 496 HCI_OPCODE_HCI_USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, "B" 497 }; 498 499 /** 500 * @param bd_addr 501 * @param numeric_value 502 */ 503 const hci_cmd_t hci_user_passkey_request_reply = { 504 HCI_OPCODE_HCI_USER_PASSKEY_REQUEST_REPLY, "B4" 505 }; 506 507 /** 508 * @param bd_addr 509 */ 510 const hci_cmd_t hci_user_passkey_request_negative_reply = { 511 HCI_OPCODE_HCI_USER_PASSKEY_REQUEST_NEGATIVE_REPLY, "B" 512 }; 513 514 /** 515 * @param bd_addr 516 * @param c Simple Pairing Hash C 517 * @param r Simple Pairing Randomizer R 518 */ 519 const hci_cmd_t hci_remote_oob_data_request_reply = { 520 HCI_OPCODE_HCI_REMOTE_OOB_DATA_REQUEST_REPLY, "BKK" 521 }; 522 523 /** 524 * @param bd_addr 525 */ 526 const hci_cmd_t hci_remote_oob_data_request_negative_reply = { 527 HCI_OPCODE_HCI_REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, "B" 528 }; 529 530 /** 531 * @param bd_addr 532 * @param reason (Part D, Error codes) 533 */ 534 const hci_cmd_t hci_io_capability_request_negative_reply = { 535 HCI_OPCODE_HCI_IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, "B1" 536 }; 537 538 /** 539 * @param handle 540 * @param transmit_bandwidth 541 * @param receive_bandwidth 542 * @param transmit_coding_format_type 543 * @param transmit_coding_format_company 544 * @param transmit_coding_format_codec 545 * @param receive_coding_format_type 546 * @param receive_coding_format_company 547 * @param receive_coding_format_codec 548 * @param transmit_coding_frame_size 549 * @param receive_coding_frame_size 550 * @param input_bandwidth 551 * @param output_bandwidth 552 * @param input_coding_format_type 553 * @param input_coding_format_company 554 * @param input_coding_format_codec 555 * @param output_coding_format_type 556 * @param output_coding_format_company 557 * @param output_coding_format_codec 558 * @param input_coded_data_size 559 * @param outupt_coded_data_size 560 * @param input_pcm_data_format 561 * @param output_pcm_data_format 562 * @param input_pcm_sample_payload_msb_position 563 * @param output_pcm_sample_payload_msb_position 564 * @param input_data_path 565 * @param output_data_path 566 * @param input_transport_unit_size 567 * @param output_transport_unit_size 568 * @param max_latency 569 * @param packet_type 570 * @param retransmission_effort 571 */ 572 const hci_cmd_t hci_enhanced_setup_synchronous_connection = { 573 HCI_OPCODE_HCI_ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, "H4412212222441221222211111111221" 574 }; 575 576 /** 577 * @param bd_addr 578 * @param transmit_bandwidth 579 * @param receive_bandwidth 580 * @param transmit_coding_format_type 581 * @param transmit_coding_format_company 582 * @param transmit_coding_format_codec 583 * @param receive_coding_format_type 584 * @param receive_coding_format_company 585 * @param receive_coding_format_codec 586 * @param transmit_coding_frame_size 587 * @param receive_coding_frame_size 588 * @param input_bandwidth 589 * @param output_bandwidth 590 * @param input_coding_format_type 591 * @param input_coding_format_company 592 * @param input_coding_format_codec 593 * @param output_coding_format_type 594 * @param output_coding_format_company 595 * @param output_coding_format_codec 596 * @param input_coded_data_size 597 * @param outupt_coded_data_size 598 * @param input_pcm_data_format 599 * @param output_pcm_data_format 600 * @param input_pcm_sample_payload_msb_position 601 * @param output_pcm_sample_payload_msb_position 602 * @param input_data_path 603 * @param output_data_path 604 * @param input_transport_unit_size 605 * @param output_transport_unit_size 606 * @param max_latency 607 * @param packet_type 608 * @param retransmission_effort 609 */ 610 const hci_cmd_t hci_enhanced_accept_synchronous_connection = { 611 HCI_OPCODE_HCI_ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, "B4412212222441221222211111111221" 612 }; 613 614 /** 615 * @param bd_addr 616 * @param c_192 Simple Pairing Hash C derived from P-192 public key 617 * @param r_192 Simple Pairing Randomizer derived from P-192 public key 618 * @param c_256 Simple Pairing Hash C derived from P-256 public key 619 * @param r_256 Simple Pairing Randomizer derived from P-256 public key 620 */ 621 const hci_cmd_t hci_remote_oob_extended_data_request_reply = { 622 HCI_OPCODE_HCI_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, "BKKKK" 623 }; 624 625 /** 626 * Link Policy Commands 627 */ 628 629 /** 630 * @param handle 631 * @param sniff_max_interval 632 * @param sniff_min_interval 633 * @param sniff_attempt 634 * @param sniff_timeout 635 */ 636 const hci_cmd_t hci_sniff_mode = { 637 HCI_OPCODE_HCI_SNIFF_MODE, "H2222" 638 }; 639 640 /** 641 * @param handle 642 */ 643 const hci_cmd_t hci_exit_sniff_mode = { 644 HCI_OPCODE_HCI_EXIT_SNIFF_MODE, "H" 645 }; 646 647 /** 648 * @param handle 649 * @param flags 650 * @param service_type 651 * @param token_rate (bytes/s) 652 * @param peak_bandwith (bytes/s) 653 * @param latency (us) 654 * @param delay_variation (us) 655 */ 656 const hci_cmd_t hci_qos_setup = { 657 HCI_OPCODE_HCI_QOS_SETUP, "H114444" 658 }; 659 660 /** 661 * @param handle 662 */ 663 const hci_cmd_t hci_role_discovery = { 664 HCI_OPCODE_HCI_ROLE_DISCOVERY, "H" 665 }; 666 667 /** 668 * @param bd_addr 669 * @param role (0=master,1=slave) 670 */ 671 const hci_cmd_t hci_switch_role_command= { 672 HCI_OPCODE_HCI_SWITCH_ROLE_COMMAND, "B1" 673 }; 674 675 /** 676 * @param handle 677 */ 678 const hci_cmd_t hci_read_link_policy_settings = { 679 HCI_OPCODE_HCI_READ_LINK_POLICY_SETTINGS, "H" 680 }; 681 682 /** 683 * @param handle 684 * @param settings 685 */ 686 const hci_cmd_t hci_write_link_policy_settings = { 687 HCI_OPCODE_HCI_WRITE_LINK_POLICY_SETTINGS, "H2" 688 }; 689 690 /** 691 * @param handle 692 * @param max_latency 693 * @param min_remote_timeout 694 * @param min_local_timeout 695 */ 696 const hci_cmd_t hci_sniff_subrating = { 697 HCI_OPCODE_HCI_SNIFF_SUBRATING, "H222" 698 }; 699 700 /** 701 * @param policy 702 */ 703 const hci_cmd_t hci_write_default_link_policy_setting = { 704 HCI_OPCODE_HCI_WRITE_DEFAULT_LINK_POLICY_SETTING, "2" 705 }; 706 707 /** 708 * @param handle 709 * @param unused 710 * @param flow_direction 711 * @param service_type 712 * @param token_rate 713 * @param token_bucket_size 714 * @param peak_bandwidth 715 * @param access_latency 716 */ 717 const hci_cmd_t hci_flow_specification = { 718 HCI_OPCODE_HCI_FLOW_SPECIFICATION, "H1114444" 719 }; 720 721 722 /** 723 * Controller & Baseband Commands 724 */ 725 726 727 /** 728 * @param event_mask_lover_octets 729 * @param event_mask_higher_octets 730 */ 731 const hci_cmd_t hci_set_event_mask = { 732 HCI_OPCODE_HCI_SET_EVENT_MASK, "44" 733 }; 734 735 /** 736 */ 737 const hci_cmd_t hci_reset = { 738 HCI_OPCODE_HCI_RESET, "" 739 }; 740 741 /** 742 * @param handle 743 */ 744 const hci_cmd_t hci_flush = { 745 HCI_OPCODE_HCI_FLUSH, "H" 746 }; 747 748 /** 749 * @param handle 750 */ 751 const hci_cmd_t hci_read_pin_type = { 752 HCI_OPCODE_HCI_READ_PIN_TYPE, "" 753 }; 754 755 /** 756 * @param handle 757 */ 758 const hci_cmd_t hci_write_pin_type = { 759 HCI_OPCODE_HCI_WRITE_PIN_TYPE, "1" 760 }; 761 762 /** 763 * @param bd_addr 764 * @param delete_all_flags 765 */ 766 const hci_cmd_t hci_delete_stored_link_key = { 767 HCI_OPCODE_HCI_DELETE_STORED_LINK_KEY, "B1" 768 }; 769 770 #ifdef ENABLE_CLASSIC 771 /** 772 * @param local_name (UTF-8, Null Terminated, max 248 octets) 773 */ 774 const hci_cmd_t hci_write_local_name = { 775 HCI_OPCODE_HCI_WRITE_LOCAL_NAME, "N" 776 }; 777 #endif 778 779 /** 780 */ 781 const hci_cmd_t hci_read_local_name = { 782 HCI_OPCODE_HCI_READ_LOCAL_NAME, "" 783 }; 784 785 /** 786 */ 787 const hci_cmd_t hci_read_page_timeout = { 788 HCI_OPCODE_HCI_READ_PAGE_TIMEOUT, "" 789 }; 790 791 /** 792 * @param page_timeout (* 0.625 ms) 793 */ 794 const hci_cmd_t hci_write_page_timeout = { 795 HCI_OPCODE_HCI_WRITE_PAGE_TIMEOUT, "2" 796 }; 797 798 /** 799 * @param scan_enable (no, inq, page, inq+page) 800 */ 801 const hci_cmd_t hci_write_scan_enable = { 802 HCI_OPCODE_HCI_WRITE_SCAN_ENABLE, "1" 803 }; 804 805 /** 806 */ 807 const hci_cmd_t hci_read_page_scan_activity = { 808 HCI_OPCODE_HCI_READ_PAGE_SCAN_ACTIVITY, "" 809 }; 810 811 /** 812 * @param page_scan_interval (* 0.625 ms) 813 * @param page_scan_window (* 0.625 ms, must be <= page_scan_interval) 814 */ 815 const hci_cmd_t hci_write_page_scan_activity = { 816 HCI_OPCODE_HCI_WRITE_PAGE_SCAN_ACTIVITY, "22" 817 }; 818 819 /** 820 */ 821 const hci_cmd_t hci_read_inquiry_scan_activity = { 822 HCI_OPCODE_HCI_READ_INQUIRY_SCAN_ACTIVITY, "" 823 }; 824 825 /** 826 * @param inquiry_scan_interval (* 0.625 ms) 827 * @param inquiry_scan_window (* 0.625 ms, must be <= inquiry_scan_interval) 828 */ 829 const hci_cmd_t hci_write_inquiry_scan_activity = { 830 HCI_OPCODE_HCI_WRITE_INQUIRY_SCAN_ACTIVITY, "22" 831 }; 832 833 /** 834 * @param authentication_enable 835 */ 836 const hci_cmd_t hci_write_authentication_enable = { 837 HCI_OPCODE_HCI_WRITE_AUTHENTICATION_ENABLE, "1" 838 }; 839 840 /** 841 * @param class_of_device 842 */ 843 const hci_cmd_t hci_write_class_of_device = { 844 HCI_OPCODE_HCI_WRITE_CLASS_OF_DEVICE, "3" 845 }; 846 847 /** 848 */ 849 const hci_cmd_t hci_read_num_broadcast_retransmissions = { 850 HCI_OPCODE_HCI_READ_NUM_BROADCAST_RETRANSMISSIONS, "" 851 }; 852 853 /** 854 * @param num_broadcast_retransmissions (e.g. 0 for a single broadcast) 855 */ 856 const hci_cmd_t hci_write_num_broadcast_retransmissions = { 857 HCI_OPCODE_HCI_WRITE_NUM_BROADCAST_RETRANSMISSIONS, "1" 858 }; 859 860 /** 861 * @param connection_handle 862 * @param type 0 = current transmit level, 1 = max transmit level 863 */ 864 const hci_cmd_t hci_read_transmit_power_level = { 865 HCI_OPCODE_HCI_READ_TRANSMIT_POWER_LEVEL, "11" 866 }; 867 868 /** 869 * @param synchronous_flow_control_enable - if yes, num completed packet everts are sent for SCO packets 870 */ 871 const hci_cmd_t hci_write_synchronous_flow_control_enable = { 872 HCI_OPCODE_HCI_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, "1" 873 }; 874 875 #ifdef ENABLE_HCI_CONTROLLER_TO_HOST_FLOW_CONTROL 876 877 /** 878 * @param flow_control_enable - 0: off, 1: ACL only, 2: SCO only, 3: ACL + SCO 879 */ 880 const hci_cmd_t hci_set_controller_to_host_flow_control = { 881 HCI_OPCODE_HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL, "1" 882 }; 883 884 /** 885 * @param host_acl_data_packet_length 886 * @param host_synchronous_data_packet_length 887 * @param host_total_num_acl_data_packets 888 * @param host_total_num_synchronous_data_packets 889 */ 890 const hci_cmd_t hci_host_buffer_size = { 891 HCI_OPCODE_HCI_HOST_BUFFER_SIZE, "2122" 892 }; 893 894 895 #if 0 896 // 897 // command sent manually sent by hci_host_num_completed_packets 898 // 899 /** 900 * @note only single handle supported by BTstack command generator 901 * @param number_of_handles must be 1 902 * @param connection_handle 903 * @param host_num_of_completed_packets for the given connection handle 904 */ 905 const hci_cmd_t hci_host_number_of_completed_packets = { 906 HCI_OPCODE_HCI_HOST_NUMBER_OF_COMPLETED_PACKETS, "1H2" 907 }; 908 #endif 909 910 #endif 911 912 /** 913 * @param handle 914 */ 915 const hci_cmd_t hci_read_link_supervision_timeout = { 916 HCI_OPCODE_HCI_READ_LINK_SUPERVISION_TIMEOUT, "H" 917 }; 918 919 /** 920 * @param handle 921 * @param timeout (0x0001 - 0xFFFF Time -> Range: 0.625ms - 40.9 sec) 922 */ 923 const hci_cmd_t hci_write_link_supervision_timeout = { 924 HCI_OPCODE_HCI_WRITE_LINK_SUPERVISION_TIMEOUT, "H2" 925 }; 926 927 /** 928 * @param num_current_iac must be 2 929 * @param iac_lap1 930 * @param iac_lap2 931 */ 932 const hci_cmd_t hci_write_current_iac_lap_two_iacs = { 933 HCI_OPCODE_HCI_WRITE_CURRENT_IAC_LAP_TWO_IACS, "133" 934 }; 935 936 /** 937 * @param inquiry_scan_type (0x00 = standard, 0x01 = interlaced) 938 */ 939 const hci_cmd_t hci_write_inquiry_scan_type = { 940 HCI_OPCODE_HCI_WRITE_INQUIRY_SCAN_TYPE, "1" 941 }; 942 943 /** 944 * @param inquiry_mode (0x00 = standard, 0x01 = with RSSI, 0x02 = extended) 945 */ 946 const hci_cmd_t hci_write_inquiry_mode = { 947 HCI_OPCODE_HCI_WRITE_INQUIRY_MODE, "1" 948 }; 949 950 /** 951 * @param page_scan_type (0x00 = standard, 0x01 = interlaced) 952 */ 953 const hci_cmd_t hci_write_page_scan_type = { 954 HCI_OPCODE_HCI_WRITE_PAGE_SCAN_TYPE, "1" 955 }; 956 957 /** 958 * @param fec_required 959 * @param exstended_inquiry_response 960 */ 961 const hci_cmd_t hci_write_extended_inquiry_response = { 962 HCI_OPCODE_HCI_WRITE_EXTENDED_INQUIRY_RESPONSE, "1E" 963 }; 964 965 /** 966 * @param mode (0 = off, 1 = on) 967 */ 968 const hci_cmd_t hci_write_simple_pairing_mode = { 969 HCI_OPCODE_HCI_WRITE_SIMPLE_PAIRING_MODE, "1" 970 }; 971 972 /** 973 */ 974 const hci_cmd_t hci_read_local_oob_data = { 975 HCI_OPCODE_HCI_READ_LOCAL_OOB_DATA, "" 976 // return status, C, R 977 }; 978 979 /** 980 * @param mode (0 = off, 1 = on) 981 */ 982 const hci_cmd_t hci_write_default_erroneous_data_reporting = { 983 HCI_OPCODE_HCI_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, "1" 984 }; 985 986 /** 987 */ 988 const hci_cmd_t hci_read_le_host_supported = { 989 HCI_OPCODE_HCI_READ_LE_HOST_SUPPORTED, "" 990 // return: status, le supported host, simultaneous le host 991 }; 992 993 /** 994 * @param le_supported_host 995 * @param simultaneous_le_host 996 */ 997 const hci_cmd_t hci_write_le_host_supported = { 998 HCI_OPCODE_HCI_WRITE_LE_HOST_SUPPORTED, "11" 999 // return: status 1000 }; 1001 1002 /** 1003 * @param secure_connections_host_support 1004 */ 1005 const hci_cmd_t hci_write_secure_connections_host_support = { 1006 HCI_OPCODE_HCI_WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, "1" 1007 // return: status 1008 }; 1009 1010 /** 1011 */ 1012 const hci_cmd_t hci_read_local_extended_oob_data = { 1013 HCI_OPCODE_HCI_READ_LOCAL_EXTENDED_OOB_DATA, "" 1014 // return status, C_192, R_192, R_256, C_256 1015 }; 1016 1017 1018 /** 1019 * Testing Commands 1020 */ 1021 1022 1023 /** 1024 */ 1025 const hci_cmd_t hci_read_loopback_mode = { 1026 HCI_OPCODE_HCI_READ_LOOPBACK_MODE, "" 1027 // return: status, loopback mode (0 = off, 1 = local loopback, 2 = remote loopback) 1028 }; 1029 1030 /** 1031 * @param loopback_mode 1032 */ 1033 const hci_cmd_t hci_write_loopback_mode = { 1034 HCI_OPCODE_HCI_WRITE_LOOPBACK_MODE, "1" 1035 // return: status 1036 }; 1037 1038 /** 1039 */ 1040 const hci_cmd_t hci_enable_device_under_test_mode = { 1041 HCI_OPCODE_HCI_ENABLE_DEVICE_UNDER_TEST_MODE, "" 1042 // return: status 1043 }; 1044 1045 /** 1046 * @param simple_pairing_debug_mode 1047 */ 1048 const hci_cmd_t hci_write_simple_pairing_debug_mode = { 1049 HCI_OPCODE_HCI_WRITE_SIMPLE_PAIRING_DEBUG_MODE, "1" 1050 // return: status 1051 }; 1052 1053 /** 1054 * @param handle 1055 * @param dm1_acl_u_mode 1056 * @param esco_loopback_mode 1057 */ 1058 const hci_cmd_t hci_write_secure_connections_test_mode = { 1059 HCI_OPCODE_HCI_WRITE_SECURE_CONNECTIONS_TEST_MODE, "H11" 1060 // return: status 1061 }; 1062 1063 1064 /** 1065 * Informational Parameters 1066 */ 1067 1068 const hci_cmd_t hci_read_local_version_information = { 1069 HCI_OPCODE_HCI_READ_LOCAL_VERSION_INFORMATION, "" 1070 }; 1071 const hci_cmd_t hci_read_local_supported_commands = { 1072 HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_COMMANDS, "" 1073 }; 1074 const hci_cmd_t hci_read_local_supported_features = { 1075 HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_FEATURES, "" 1076 }; 1077 const hci_cmd_t hci_read_buffer_size = { 1078 HCI_OPCODE_HCI_READ_BUFFER_SIZE, "" 1079 }; 1080 const hci_cmd_t hci_read_bd_addr = { 1081 HCI_OPCODE_HCI_READ_BD_ADDR, "" 1082 }; 1083 1084 /** 1085 * Status Paramters 1086 */ 1087 1088 /** 1089 * @param handle 1090 */ 1091 const hci_cmd_t hci_read_rssi = { 1092 HCI_OPCODE_HCI_READ_RSSI, "H" 1093 }; 1094 1095 /** 1096 * @param handle 1097 */ 1098 const hci_cmd_t hci_read_encryption_key_size = { 1099 HCI_OPCODE_HCI_READ_ENCRYPTION_KEY_SIZE, "H" 1100 }; 1101 1102 1103 #ifdef ENABLE_BLE 1104 /** 1105 * Low Energy Commands 1106 */ 1107 1108 /** 1109 * @param event_mask_lower_octets 1110 * @param event_mask_higher_octets 1111 */ 1112 const hci_cmd_t hci_le_set_event_mask = { 1113 HCI_OPCODE_HCI_LE_SET_EVENT_MASK, "44" 1114 // return: status 1115 }; 1116 1117 const hci_cmd_t hci_le_read_buffer_size = { 1118 HCI_OPCODE_HCI_LE_READ_BUFFER_SIZE, "" 1119 // return: status, le acl data packet len (16), total num le acl data packets(8) 1120 }; 1121 const hci_cmd_t hci_le_read_supported_features = { 1122 HCI_OPCODE_HCI_LE_READ_SUPPORTED_FEATURES, "" 1123 // return: LE_Features See [Vol 6] Part B, Section 4.6 1124 }; 1125 1126 /** 1127 * @param random_bd_addr 1128 */ 1129 const hci_cmd_t hci_le_set_random_address = { 1130 HCI_OPCODE_HCI_LE_SET_RANDOM_ADDRESS, "B" 1131 // return: status 1132 }; 1133 1134 /** 1135 * @param advertising_interval_min ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec) 1136 * @param advertising_interval_max ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec) 1137 * @param advertising_type (enum from 0: ADV_IND, ADC_DIRECT_IND, ADV_SCAN_IND, ADV_NONCONN_IND) 1138 * @param own_address_type (enum from 0: public device address, random device address) 1139 * @param direct_address_type () 1140 * @param direct_address (public or random address of device to be connecteed) 1141 * @param advertising_channel_map (flags: chan_37(1), chan_38(2), chan_39(4)) 1142 * @param advertising_filter_policy (enum from 0: scan any conn any, scan whitelist, con any, scan any conn whitelist, scan whitelist, con whitelist) 1143 */ 1144 const hci_cmd_t hci_le_set_advertising_parameters = { 1145 HCI_OPCODE_HCI_LE_SET_ADVERTISING_PARAMETERS, "22111B11" 1146 // return: status 1147 }; 1148 1149 const hci_cmd_t hci_le_read_advertising_channel_tx_power = { 1150 HCI_OPCODE_HCI_LE_READ_ADVERTISING_CHANNEL_TX_POWER, "" 1151 // return: status, level [-20,10] signed int (8), units dBm 1152 }; 1153 1154 /** 1155 * @param advertising_data_length 1156 * @param advertising_data (31 bytes) 1157 */ 1158 const hci_cmd_t hci_le_set_advertising_data= { 1159 HCI_OPCODE_HCI_LE_SET_ADVERTISING_DATA, "1A" 1160 // return: status 1161 }; 1162 1163 /** 1164 * @param scan_response_data_length 1165 * @param scan_response_data (31 bytes) 1166 */ 1167 const hci_cmd_t hci_le_set_scan_response_data= { 1168 HCI_OPCODE_HCI_LE_SET_SCAN_RESPONSE_DATA, "1A" 1169 // return: status 1170 }; 1171 1172 /** 1173 * @param advertise_enable (off: 0, on: 1) 1174 */ 1175 const hci_cmd_t hci_le_set_advertise_enable = { 1176 HCI_OPCODE_HCI_LE_SET_ADVERTISE_ENABLE, "1" 1177 // return: status 1178 }; 1179 1180 /** 1181 * @param le_scan_type (passive (0), active (1)) 1182 * @param le_scan_interval ([0x0004,0x4000], unit: 0.625 msec) 1183 * @param le_scan_window ([0x0004,0x4000], unit: 0.625 msec) 1184 * @param own_address_type (public (0), random (1)) 1185 * @param scanning_filter_policy (any (0), only whitelist (1)) 1186 */ 1187 const hci_cmd_t hci_le_set_scan_parameters = { 1188 HCI_OPCODE_HCI_LE_SET_SCAN_PARAMETERS, "12211" 1189 // return: status 1190 }; 1191 1192 /** 1193 * @param le_scan_enable (disabled (0), enabled (1)) 1194 * @param filter_duplices (disabled (0), enabled (1)) 1195 */ 1196 const hci_cmd_t hci_le_set_scan_enable = { 1197 HCI_OPCODE_HCI_LE_SET_SCAN_ENABLE, "11" 1198 // return: status 1199 }; 1200 1201 /** 1202 * @param le_scan_interval ([0x0004, 0x4000], unit: 0.625 msec) 1203 * @param le_scan_window ([0x0004, 0x4000], unit: 0.625 msec) 1204 * @param initiator_filter_policy (peer address type + peer address (0), whitelist (1)) 1205 * @param peer_address_type (public (0), random (1)) 1206 * @param peer_address 1207 * @param own_address_type (public (0), random (1)) 1208 * @param conn_interval_min ([0x0006, 0x0c80], unit: 1.25 msec) 1209 * @param conn_interval_max ([0x0006, 0x0c80], unit: 1.25 msec) 1210 * @param conn_latency (number of connection events [0x0000, 0x01f4]) 1211 * @param supervision_timeout ([0x000a, 0x0c80], unit: 10 msec) 1212 * @param minimum_CE_length ([0x0000, 0xffff], unit: 0.625 msec) 1213 * @param maximum_CE_length ([0x0000, 0xffff], unit: 0.625 msec) 1214 */ 1215 const hci_cmd_t hci_le_create_connection= { 1216 HCI_OPCODE_HCI_LE_CREATE_CONNECTION, "2211B1222222" 1217 // return: none -> le create connection complete event 1218 }; 1219 1220 const hci_cmd_t hci_le_create_connection_cancel = { 1221 HCI_OPCODE_HCI_LE_CREATE_CONNECTION_CANCEL, "" 1222 // return: status 1223 }; 1224 1225 const hci_cmd_t hci_le_read_white_list_size = { 1226 HCI_OPCODE_HCI_LE_READ_WHITE_LIST_SIZE, "" 1227 // return: status, number of entries in controller whitelist 1228 }; 1229 1230 const hci_cmd_t hci_le_clear_white_list = { 1231 HCI_OPCODE_HCI_LE_CLEAR_WHITE_LIST, "" 1232 // return: status 1233 }; 1234 1235 /** 1236 * @param address_type (public (0), random (1)) 1237 * @param bd_addr 1238 */ 1239 const hci_cmd_t hci_le_add_device_to_white_list = { 1240 HCI_OPCODE_HCI_LE_ADD_DEVICE_TO_WHITE_LIST, "1B" 1241 // return: status 1242 }; 1243 1244 /** 1245 * @param address_type (public (0), random (1)) 1246 * @param bd_addr 1247 */ 1248 const hci_cmd_t hci_le_remove_device_from_white_list = { 1249 HCI_OPCODE_HCI_LE_REMOVE_DEVICE_FROM_WHITE_LIST, "1B" 1250 // return: status 1251 }; 1252 1253 /** 1254 * @param conn_handle 1255 * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec) 1256 * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec) 1257 * @param conn_latency ([0x0000,0x03e8], number of connection events) 1258 * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec) 1259 * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec) 1260 * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec) 1261 */ 1262 const hci_cmd_t hci_le_connection_update = { 1263 HCI_OPCODE_HCI_LE_CONNECTION_UPDATE, "H222222" 1264 // return: none -> le connection update complete event 1265 }; 1266 1267 /** 1268 * @param channel_map_lower_32bits 1269 * @param channel_map_higher_5bits 1270 */ 1271 const hci_cmd_t hci_le_set_host_channel_classification = { 1272 HCI_OPCODE_HCI_LE_SET_HOST_CHANNEL_CLASSIFICATION, "41" 1273 // return: status 1274 }; 1275 1276 /** 1277 * @param conn_handle 1278 */ 1279 const hci_cmd_t hci_le_read_channel_map = { 1280 HCI_OPCODE_HCI_LE_READ_CHANNEL_MAP, "H" 1281 // return: status, connection handle, channel map (5 bytes, 37 used) 1282 }; 1283 1284 /** 1285 * @param conn_handle 1286 */ 1287 const hci_cmd_t hci_le_read_remote_used_features = { 1288 HCI_OPCODE_HCI_LE_READ_REMOTE_USED_FEATURES, "H" 1289 // return: none -> le read remote used features complete event 1290 }; 1291 1292 /** 1293 * @param key ((128) for AES-128) 1294 * @param plain_text (128) 1295 */ 1296 const hci_cmd_t hci_le_encrypt = { 1297 HCI_OPCODE_HCI_LE_ENCRYPT, "PP" 1298 // return: status, encrypted data (128) 1299 }; 1300 1301 const hci_cmd_t hci_le_rand = { 1302 HCI_OPCODE_HCI_LE_RAND, "" 1303 // return: status, random number (64) 1304 }; 1305 1306 /** 1307 * @param conn_handle 1308 * @param random_number_lower_32bits 1309 * @param random_number_higher_32bits 1310 * @param encryption_diversifier (16) 1311 * @param long_term_key (128) 1312 */ 1313 const hci_cmd_t hci_le_start_encryption = { 1314 HCI_OPCODE_HCI_LE_START_ENCRYPTION, "H442P" 1315 // return: none -> encryption changed or encryption key refresh complete event 1316 }; 1317 1318 /** 1319 * @param connection_handle 1320 * @param long_term_key (128) 1321 */ 1322 const hci_cmd_t hci_le_long_term_key_request_reply = { 1323 HCI_OPCODE_HCI_LE_LONG_TERM_KEY_REQUEST_REPLY, "HP" 1324 // return: status, connection handle 1325 }; 1326 1327 /** 1328 * @param conn_handle 1329 */ 1330 const hci_cmd_t hci_le_long_term_key_negative_reply = { 1331 HCI_OPCODE_HCI_LE_LONG_TERM_KEY_NEGATIVE_REPLY, "H" 1332 // return: status, connection handle 1333 }; 1334 1335 /** 1336 * @param conn_handle 1337 */ 1338 const hci_cmd_t hci_le_read_supported_states = { 1339 HCI_OPCODE_HCI_LE_READ_SUPPORTED_STATES, "H" 1340 // return: status, LE states (64) 1341 }; 1342 1343 /** 1344 * @param rx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2) 1345 */ 1346 const hci_cmd_t hci_le_receiver_test = { 1347 HCI_OPCODE_HCI_LE_RECEIVER_TEST, "1" 1348 // return: status 1349 }; 1350 1351 /** 1352 * @param tx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2) 1353 * @param test_payload_lengh ([0x00,0x25]) 1354 * @param packet_payload ([0,7] different patterns) 1355 */ 1356 const hci_cmd_t hci_le_transmitter_test = { 1357 HCI_OPCODE_HCI_LE_TRANSMITTER_TEST, "111" 1358 // return: status 1359 }; 1360 1361 /** 1362 * @param end_test_cmd 1363 */ 1364 const hci_cmd_t hci_le_test_end = { 1365 HCI_OPCODE_HCI_LE_TEST_END, "1" 1366 // return: status, number of packets (8) 1367 }; 1368 1369 /** 1370 * @param conn_handle 1371 * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec) 1372 * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec) 1373 * @param conn_latency ([0x0000,0x03e8], number of connection events) 1374 * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec) 1375 * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec) 1376 * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec) 1377 */ 1378 const hci_cmd_t hci_le_remote_connection_parameter_request_reply = { 1379 HCI_OPCODE_HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, "H222222" 1380 // return: status, connection handle 1381 }; 1382 1383 /** 1384 * @param con_handle 1385 * @param reason 1386 */ 1387 const hci_cmd_t hci_le_remote_connection_parameter_request_negative_reply = { 1388 HCI_OPCODE_HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, "H1" 1389 // return: status, connection handle 1390 }; 1391 1392 /** 1393 * @param con_handle 1394 * @param tx_octets 1395 * @param tx_time 1396 */ 1397 const hci_cmd_t hci_le_set_data_length = { 1398 HCI_OPCODE_HCI_LE_SET_DATA_LENGTH, "H22" 1399 // return: status, connection handle 1400 }; 1401 1402 /** 1403 */ 1404 const hci_cmd_t hci_le_read_suggested_default_data_length = { 1405 HCI_OPCODE_HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, "" 1406 // return: status, suggested max tx octets, suggested max tx time 1407 }; 1408 1409 /** 1410 * @param suggested_max_tx_octets 1411 * @param suggested_max_tx_time 1412 */ 1413 const hci_cmd_t hci_le_write_suggested_default_data_length = { 1414 HCI_OPCODE_HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, "22" 1415 // return: status 1416 }; 1417 1418 /** 1419 */ 1420 const hci_cmd_t hci_le_read_local_p256_public_key = { 1421 HCI_OPCODE_HCI_LE_READ_LOCAL_P256_PUBLIC_KEY, "" 1422 // LE Read Local P-256 Public Key Complete is generated on completion 1423 }; 1424 1425 /** 1426 * @param public key 1427 * @param private key 1428 */ 1429 const hci_cmd_t hci_le_generate_dhkey = { 1430 HCI_OPCODE_HCI_LE_GENERATE_DHKEY, "QQ" 1431 // LE Generate DHKey Complete is generated on completion 1432 }; 1433 1434 /** 1435 * @param Peer_Identity_Address_Type 1436 * @param Peer_Identity_Address 1437 * @param Peer_IRK 1438 * @param Local_IRK 1439 */ 1440 const hci_cmd_t hci_le_add_device_to_resolving_list = { 1441 HCI_OPCODE_HCI_LE_ADD_DEVICE_TO_RESOLVING_LIST, "1BPP" 1442 }; 1443 1444 /** 1445 * @param Peer_Identity_Address_Type 1446 * @param Peer_Identity_Address 1447 */ 1448 const hci_cmd_t hci_le_remove_device_from_resolving_list = { 1449 HCI_OPCODE_HCI_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, "1B" 1450 }; 1451 1452 /** 1453 */ 1454 const hci_cmd_t hci_le_clear_resolving_list = { 1455 HCI_OPCODE_HCI_LE_CLEAR_RESOLVING_LIST, "" 1456 }; 1457 1458 /** 1459 */ 1460 const hci_cmd_t hci_le_read_resolving_list_size = { 1461 HCI_OPCODE_HCI_LE_READ_RESOLVING_LIST_SIZE, "" 1462 }; 1463 1464 /** 1465 * @param Peer_Identity_Address_Type 1466 * @param Peer_Identity_Address 1467 */ 1468 const hci_cmd_t hci_le_read_peer_resolvable_address = { 1469 HCI_OPCODE_HCI_LE_READ_PEER_RESOLVABLE_ADDRESS, "" 1470 }; 1471 1472 /** 1473 * @param Peer_Identity_Address_Type 1474 * @param Peer_Identity_Address 1475 */ 1476 const hci_cmd_t hci_le_read_local_resolvable_address = { 1477 HCI_OPCODE_HCI_LE_READ_LOCAL_RESOLVABLE_ADDRESS, "" 1478 }; 1479 1480 /** 1481 * @param Address_Resolution_Enable 1482 */ 1483 const hci_cmd_t hci_le_set_address_resolution_enabled= { 1484 HCI_OPCODE_HCI_LE_SET_ADDRESS_RESOLUTION_ENABLED, "1" 1485 }; 1486 1487 /** 1488 * @param RPA_Timeout in seconds, range 0x0001 to 0x0E10, default: 900 s 1489 */ 1490 const hci_cmd_t hci_le_set_resolvable_private_address_timeout= { 1491 HCI_OPCODE_HCI_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, "2" 1492 }; 1493 1494 /** 1495 */ 1496 const hci_cmd_t hci_le_read_maximum_data_length = { 1497 HCI_OPCODE_HCI_LE_READ_MAXIMUM_DATA_LENGTH, "" 1498 // return: status, supported max tx octets, supported max tx time, supported max rx octets, supported max rx time 1499 }; 1500 1501 /** 1502 * @param con_handle 1503 */ 1504 const hci_cmd_t hci_le_read_phy = { 1505 HCI_OPCODE_HCI_LE_READ_PHY, "H" 1506 // return: status, connection handler, tx phy, rx phy 1507 }; 1508 1509 /** 1510 * @param all_phys 1511 * @param tx_phys 1512 * @param rx_phys 1513 */ 1514 const hci_cmd_t hci_le_set_default_phy = { 1515 HCI_OPCODE_HCI_LE_SET_DEFAULT_PHY, "111" 1516 // return: status 1517 }; 1518 1519 /** 1520 * @param con_handle 1521 * @param all_phys 1522 * @param tx_phys 1523 * @param rx_phys 1524 * @param phy_options 1525 */ 1526 const hci_cmd_t hci_le_set_phy = { 1527 HCI_OPCODE_HCI_LE_SET_PHY, "H1111" 1528 // LE PHY Update Complete is generated on completion 1529 }; 1530 1531 1532 #endif 1533 1534 // Broadcom / Cypress specific HCI commands 1535 1536 /** 1537 * @brief Enable Wide-Band Speech / mSBC decoding for PCM 1538 * @param enable_wbs is 0 for disable, 1 for enable 1539 * @param uuid_wbs is 2 for EV2/EV3 1540 */ 1541 const hci_cmd_t hci_bcm_enable_wbs = { 1542 HCI_OPCODE_HCI_BCM_ENABLE_WBS, "12" 1543 // return: status 1544 }; 1545 1546 /** 1547 * @brief Configure SCO Routing (BCM) 1548 * @param sco_routing is 0 for PCM, 1 for Transport, 2 for Codec and 3 for I2S 1549 * @param pcm_interface_rate is 0 for 128KBps, 1 for 256 KBps, 2 for 512KBps, 3 for 1024KBps, and 4 for 2048Kbps 1550 * @param frame_type is 0 for short and 1 for long 1551 * @param sync_mode is 0 for slave and 1 for master 1552 * @param clock_mode is 0 for slabe and 1 for master 1553 */ 1554 const hci_cmd_t hci_bcm_write_sco_pcm_int = { 1555 HCI_OPCODE_HCI_BCM_WRITE_SCO_PCM_INT, "11111" 1556 // return: status 1557 }; 1558 1559 /** 1560 * @brief Configure the I2S/PCM interface (BCM) 1561 * @param i2s_enable is 0 for off, 1 for on 1562 * @param is_master is 0 for slave, is 1 for master 1563 * @param sample_rate is 0 for 8 kHz, 1 for 16 kHz, 2 for 4 kHz 1564 * @param clock_rate is 0 for 128 kz, 1 for 256 kHz, 2 for 512 khz, 3 for 1024 kHz, 4 for 2048 khz 1565 * @param clock_mode is 0 for slabe and 1 for master 1566 */ 1567 const hci_cmd_t hci_bcm_write_i2spcm_interface_param = { 1568 HCI_OPCODE_HCI_BCM_WRITE_I2SPCM_INTERFACE_PARAM, "1111" 1569 // return: status 1570 }; 1571 1572 1573 /** 1574 * @brief Activates selected Sleep Mode 1575 * @param sleep_mode: 0=no sleep, 1=UART, 2=UART with Messaging, 3=USB, 4=H4IBSS, USB with Host Wake, 6=SDIO, 7=UART CS-N, 8=SPI, 9=H5, 10=H4DS, 12=UART with BREAK 1576 * @param idle_threshold_host (modes 1,2,5,7) time until considered idle, unit roughly 300 ms 1577 * @param idle_threshold_controller (modes 1-7,9) time until considered idle, unit roughly 300 ms 1578 * @param bt_wake_active_mode (modes 1,2,7) 0 = BT_WAKE line is active high, 1 = BT_WAKE is active low 1579 * @param host_wake_active_mode (modes 1,2,5,7) 0 = HOST_WAKE line is active high, 1 = HOST_WAKE is active low 1580 * @param allow_host_sleep_during_sco (modes 1,2,3,5,7) 1581 * @param combine_sleep_mode_and_lpm (modes 1,2,3,5,7) 1582 * @param enable_tristate_control_of_uart_tx_line (modes 1,2,7) 1583 * @param active_connection_handling_on_suspend (modes 3,5) 1584 * @param resume_timeout (modes 3,5) 1585 * @param enable_break_to_host (mode 12) 1586 * @param pulsed_host_wake (modes 1,12) 1587 */ 1588 const hci_cmd_t hci_bcm_set_sleep_mode = { 1589 HCI_OPCODE_HCI_BCM_SET_SLEEP_MODE, "111111111111" 1590 }; 1591 1592 /** 1593 * @brief Set TX Power Table 1594 * @param is_le 0=classic, 1=LE 1595 * @param chip_max_tx_pwr_db chip level max TX power in dBM 1596 */ 1597 const hci_cmd_t hci_bcm_write_tx_power_table = { 1598 HCI_OPCODE_HCI_BCM_WRITE_TX_POWER_TABLE, "11" 1599 }; 1600 1601 const hci_cmd_t hci_bcm_set_tx_pwr = { 1602 HCI_OPCODE_HCI_BCM_SET_TX_PWR, "11H" 1603 }; 1604 1605 /** 1606 * @brief This command starts receiving packets using packet transmission parameters such as 1607 * frequency channel, packet type, and packet length. It is used for Packet RX. 1608 * @see https://processors.wiki.ti.com/index.php/CC256x_Testing_Guide#Continuous_RX 1609 * @param frequency 1610 * @param ADPLL loop mode 1611 */ 1612 const hci_cmd_t hci_ti_drpb_tester_con_rx = { 1613 0xFD17, "11" 1614 }; 1615 1616 /** 1617 * 1618 * 1619 * @brief This command tests the RF transceiver in continuous transmission mode. 1620 * The transmitter is activated by configuring the transmission parameters such as pattern, 1621 * modulation, and frequency. 1622 * @see processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands#HCI_VS_DRPb_Tester_Con_TX.280xFD84.29 1623 * @param modulation 1624 * @param test_pattern 1625 * @param frequency 1626 * @param power_level 1627 * @param reserved1 1628 * @param reserved2 1629 */ 1630 const hci_cmd_t hci_ti_drpb_tester_con_tx = { 1631 0xFD84, "111144" 1632 }; 1633 1634 /** 1635 * @brief This command starts sending/receiving packets using packet transmission parameters such as 1636 * frequency channel, packet type, and packet length. It is used for Packet TX/RX. 1637 * @see processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands#HCI_VS_DRPb_Tester_Packet_TX_RX_.280xFD85.29 1638 * @param frequency_mode 1639 * @param tx_single_frequency 1640 * @param rx_single_frequency 1641 * @param acl_packet_type 1642 * @paarm acl_packet_data_pattern 1643 * @param reserved 1644 * @param power_level 1645 * @param disable_whitening 1646 * @param prbs9_initialization_value 1647 */ 1648 const hci_cmd_t hci_ti_drpb_tester_packet_tx_rx = { 1649 0xFD85, "1111112112" 1650 }; 1651 1652 1653 /** 1654 * @param best effort access percentage 1655 * @param guaranteed access percentage 1656 * @param poll period 1657 * @param slave burst after tx 1658 * @param slave master search count 1659 * @param master burst after tx enable 1660 * @param master burst after rx limit 1661 */ 1662 const hci_cmd_t hci_ti_configure_ddip = { 1663 HCI_OPCODE_HCI_TI_VS_CONFIGURE_DDIP, "1111111" 1664 }; 1665 1666 /** 1667 * @brief This command is used to associate the requested ACL handle with Wide Band Speech configuration. 1668 * @param enable 0=disable, 1=enable 1669 * @param a3dp_role (NL5500, WL128x only) 0=source,1=sink 1670 * @param code_upload (NL5500, WL128x only) 0=do not load a3dp code, 1=load a3dp code 1671 * @param reserved for future use 1672 */ 1673 const hci_cmd_t hci_ti_avrp_enable = { 1674 0xFD92, "1112" 1675 }; 1676 1677 /** 1678 * @brief This command is used to associate the requested ACL handle with Wide Band Speech configuration. 1679 * @param acl_con_handle 1680 */ 1681 const hci_cmd_t hci_ti_wbs_associate = { 1682 0xFD78, "H" 1683 }; 1684 1685 /** 1686 * @brief This command is used to disassociate Wide Band Speech configuration from any ACL handle. 1687 */ 1688 const hci_cmd_t hci_ti_wbs_disassociate = { 1689 0xFD79, "" 1690 }; 1691 1692 /** 1693 * @brief This command configures the codec interface parameters and the PCM clock rate, which is relevant when 1694 the Bluetooth core generates the clock. This command must be used by the host to use the PCM 1695 interface. 1696 * @param clock_rate in kHz 1697 * @param clock_direction 0=master/output, 1=slave/input 1698 * @param frame_sync_frequency in Hz 1699 * @param frame_sync_duty_cycle 0=50% (I2S Format), 0x0001-0xffff number of cycles of PCM clock 1700 * @param frame_sync_edge 0=driven/sampled at rising edge, 1=driven/sampled at falling edge of PCM clock 1701 * @param frame_sync_polariy 0=active high, 1=active low 1702 * @param reserved1 1703 * @param channel_1_data_out_size sample size in bits 1704 * @param channel_1_data_out_offset number of PCM clock cycles between rising of frame sync and data start 1705 * @param channel_1_data_out_edge 0=data driven at rising edge, 1=data driven at falling edge of PCM clock 1706 * @param channel_1_data_in_size sample size in bits 1707 * @param channel_1_data_in_offset number of PCM clock cycles between rising of frame sync and data start 1708 * @param channel_1_data_in_edge 0=data sampled at rising edge, 1=data sampled at falling edge of PCM clock 1709 * @param fsync_multiplier this field is only relevant to CC256XB from service pack 0.2 !!! -> use 0x00 1710 * @param channel_2_data_out_size sample size in bits 1711 * @param channel_2_data_out_offset number of PCM clock cycles between rising of frame sync and data start 1712 * @param channel_2_data_out_edge 0=data driven at rising edge, 1=data driven at falling edge of PCM clock 1713 * @param channel_2_data_in_size sample size in bits 1714 * @param channel_2_data_in_offset number of PCM clock cycles between rising of frame sync and data start 1715 * @param channel_2_data_in_edge 0=data sampled at rising edge, 1=data sampled at falling edge of PCM clock 1716 * @param reserved2 1717 * 1718 */ 1719 const hci_cmd_t hci_ti_write_codec_config = { 1720 0xFD06, "214211122122112212211" 1721 }; 1722 1723 /** 1724 * @brief This command is used only for internal testing. 1725 * @see https://processors.wiki.ti.com/index.php/CC256x_Testing_Guide#Continuous_TX 1726 * @param frequency 1727 * @param ADPLL loop mode 1728 */ 1729 const hci_cmd_t hci_ti_drpb_enable_rf_calibration = { 1730 0xFD80, "141" 1731 }; 1732 1733 /** 1734 * @brief This command command is only required for the continuous TX test of modulated 1735 * (GFSK, π/4-DQPSK or 8DPSK) signal. This command should be skipped when performing continuous TX test for CW. 1736 * @see https://processors.wiki.ti.com/index.php/CC256x_Testing_Guide#Continuous_RX 1737 * @param frequency 1738 * @param ADPLL loop mode 1739 */ 1740 const hci_cmd_t hci_ti_write_hardware_register = { 1741 0xFF01, "42" 1742 }; 1743