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