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 /* 39 * hci_cmd.c 40 * 41 * Created by Matthias Ringwald on 7/23/09. 42 */ 43 44 #include "btstack_config.h" 45 46 #include "classic/sdp_util.h" 47 #include "hci.h" 48 #include "hci_cmd.h" 49 #include "btstack_debug.h" 50 51 #include <string.h> 52 53 // calculate combined ogf/ocf value 54 #define OPCODE(ogf, ocf) (ocf | ogf << 10) 55 56 /** 57 * construct HCI Command based on template 58 * 59 * Format: 60 * 1,2,3,4: one to four byte value 61 * H: HCI connection handle 62 * B: Bluetooth Baseband Address (BD_ADDR) 63 * D: 8 byte data block 64 * E: Extended Inquiry Result 65 * N: Name up to 248 chars, \0 terminated 66 * P: 16 byte data block. Pairing code, Simple Pairing Hash and Randomizer 67 * A: 31 bytes advertising data 68 * S: Service Record (Data Element Sequence) 69 * Q: 32 byte data block, e.g. for X and Y coordinates of P-256 public key 70 */ 71 uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr){ 72 73 hci_cmd_buffer[0] = cmd->opcode & 0xff; 74 hci_cmd_buffer[1] = cmd->opcode >> 8; 75 int pos = 3; 76 77 const char *format = cmd->format; 78 uint16_t word; 79 uint32_t longword; 80 uint8_t * ptr; 81 while (*format) { 82 switch(*format) { 83 case '1': // 8 bit value 84 case '2': // 16 bit value 85 case 'H': // hci_handle 86 word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs 87 hci_cmd_buffer[pos++] = word & 0xff; 88 if (*format == '2') { 89 hci_cmd_buffer[pos++] = word >> 8; 90 } else if (*format == 'H') { 91 // TODO implement opaque client connection handles 92 // pass module handle for now 93 hci_cmd_buffer[pos++] = word >> 8; 94 } 95 break; 96 case '3': 97 case '4': 98 longword = va_arg(argptr, uint32_t); 99 // longword = va_arg(argptr, int); 100 hci_cmd_buffer[pos++] = longword; 101 hci_cmd_buffer[pos++] = longword >> 8; 102 hci_cmd_buffer[pos++] = longword >> 16; 103 if (*format == '4'){ 104 hci_cmd_buffer[pos++] = longword >> 24; 105 } 106 break; 107 case 'B': // bt-addr 108 ptr = va_arg(argptr, uint8_t *); 109 hci_cmd_buffer[pos++] = ptr[5]; 110 hci_cmd_buffer[pos++] = ptr[4]; 111 hci_cmd_buffer[pos++] = ptr[3]; 112 hci_cmd_buffer[pos++] = ptr[2]; 113 hci_cmd_buffer[pos++] = ptr[1]; 114 hci_cmd_buffer[pos++] = ptr[0]; 115 break; 116 case 'D': // 8 byte data block 117 ptr = va_arg(argptr, uint8_t *); 118 memcpy(&hci_cmd_buffer[pos], ptr, 8); 119 pos += 8; 120 break; 121 case 'E': // Extended Inquiry Information 240 octets 122 ptr = va_arg(argptr, uint8_t *); 123 memcpy(&hci_cmd_buffer[pos], ptr, 240); 124 pos += 240; 125 break; 126 case 'N': { // UTF-8 string, null terminated 127 ptr = va_arg(argptr, uint8_t *); 128 uint16_t len = strlen((const char*) ptr); 129 if (len > 248) { 130 len = 248; 131 } 132 memcpy(&hci_cmd_buffer[pos], ptr, len); 133 if (len < 248) { 134 // fill remaining space with zeroes 135 memset(&hci_cmd_buffer[pos+len], 0, 248-len); 136 } 137 pos += 248; 138 break; 139 } 140 case 'P': // 16 byte PIN code or link key 141 ptr = va_arg(argptr, uint8_t *); 142 memcpy(&hci_cmd_buffer[pos], ptr, 16); 143 pos += 16; 144 break; 145 #ifdef ENABLE_BLE 146 case 'A': // 31 bytes advertising data 147 ptr = va_arg(argptr, uint8_t *); 148 memcpy(&hci_cmd_buffer[pos], ptr, 31); 149 pos += 31; 150 break; 151 #endif 152 #ifdef ENABLE_SDP 153 case 'S': { // Service Record (Data Element Sequence) 154 ptr = va_arg(argptr, uint8_t *); 155 uint16_t len = de_get_len(ptr); 156 memcpy(&hci_cmd_buffer[pos], ptr, len); 157 pos += len; 158 break; 159 } 160 #endif 161 #ifdef ENABLE_LE_SECURE_CONNECTIONS 162 case 'Q': 163 ptr = va_arg(argptr, uint8_t *); 164 reverse_bytes(ptr, &hci_cmd_buffer[pos], 32); 165 pos += 32; 166 break; 167 #endif 168 default: 169 break; 170 } 171 format++; 172 }; 173 hci_cmd_buffer[2] = pos - 3; 174 return pos; 175 } 176 177 /** 178 * Link Control Commands 179 */ 180 181 /** 182 * @param lap 183 * @param inquiry_length 184 * @param num_responses 185 */ 186 const hci_cmd_t hci_inquiry = { 187 OPCODE(OGF_LINK_CONTROL, 0x01), "311" 188 }; 189 190 /** 191 */ 192 const hci_cmd_t hci_inquiry_cancel = { 193 OPCODE(OGF_LINK_CONTROL, 0x02), "" 194 }; 195 196 /** 197 * @param bd_addr 198 * @param packet_type 199 * @param page_scan_repetition_mode 200 * @param reserved 201 * @param clock_offset 202 * @param allow_role_switch 203 */ 204 const hci_cmd_t hci_create_connection = { 205 OPCODE(OGF_LINK_CONTROL, 0x05), "B21121" 206 }; 207 208 /** 209 * @param handle 210 * @param reason (0x05, 0x13-0x15, 0x1a, 0x29, see Errors Codes in BT Spec Part D) 211 */ 212 const hci_cmd_t hci_disconnect = { 213 OPCODE(OGF_LINK_CONTROL, 0x06), "H1" 214 }; 215 216 /** 217 * @param bd_addr 218 */ 219 const hci_cmd_t hci_create_connection_cancel = { 220 OPCODE(OGF_LINK_CONTROL, 0x08), "B" 221 }; 222 223 /** 224 * @param bd_addr 225 * @param role (become master, stay slave) 226 */ 227 const hci_cmd_t hci_accept_connection_request = { 228 OPCODE(OGF_LINK_CONTROL, 0x09), "B1" 229 }; 230 231 /** 232 * @param bd_addr 233 * @param reason (e.g. CONNECTION REJECTED DUE TO LIMITED RESOURCES (0x0d)) 234 */ 235 const hci_cmd_t hci_reject_connection_request = { 236 OPCODE(OGF_LINK_CONTROL, 0x0a), "B1" 237 }; 238 239 /** 240 * @param bd_addr 241 * @param link_key 242 */ 243 const hci_cmd_t hci_link_key_request_reply = { 244 OPCODE(OGF_LINK_CONTROL, 0x0b), "BP" 245 }; 246 247 /** 248 * @param bd_addr 249 */ 250 const hci_cmd_t hci_link_key_request_negative_reply = { 251 OPCODE(OGF_LINK_CONTROL, 0x0c), "B" 252 }; 253 254 /** 255 * @param bd_addr 256 * @param pin_length 257 * @param pin (c-string) 258 */ 259 const hci_cmd_t hci_pin_code_request_reply = { 260 OPCODE(OGF_LINK_CONTROL, 0x0d), "B1P" 261 }; 262 263 /** 264 * @param bd_addr 265 */ 266 const hci_cmd_t hci_pin_code_request_negative_reply = { 267 OPCODE(OGF_LINK_CONTROL, 0x0e), "B" 268 }; 269 270 /** 271 * @param handle 272 * @param packet_type 273 */ 274 const hci_cmd_t hci_change_connection_packet_type = { 275 OPCODE(OGF_LINK_CONTROL, 0x0f), "H2" 276 }; 277 278 /** 279 * @param handle 280 */ 281 const hci_cmd_t hci_authentication_requested = { 282 OPCODE(OGF_LINK_CONTROL, 0x11), "H" 283 }; 284 285 /** 286 * @param handle 287 * @param encryption_enable 288 */ 289 const hci_cmd_t hci_set_connection_encryption = { 290 OPCODE(OGF_LINK_CONTROL, 0x13), "H1" 291 }; 292 293 /** 294 * @param handle 295 */ 296 const hci_cmd_t hci_change_connection_link_key = { 297 OPCODE(OGF_LINK_CONTROL, 0x15), "H" 298 }; 299 300 /** 301 * @param bd_addr 302 * @param page_scan_repetition_mode 303 * @param reserved 304 * @param clock_offset 305 */ 306 const hci_cmd_t hci_remote_name_request = { 307 OPCODE(OGF_LINK_CONTROL, 0x19), "B112" 308 }; 309 310 311 /** 312 * @param bd_addr 313 */ 314 const hci_cmd_t hci_remote_name_request_cancel = { 315 OPCODE(OGF_LINK_CONTROL, 0x1A), "B" 316 }; 317 318 /** 319 * @param handle 320 */ 321 const hci_cmd_t hci_read_remote_supported_features_command = { 322 OPCODE(OGF_LINK_CONTROL, 0x1B), "H" 323 }; 324 325 /** 326 * @param handle 327 * @param transmit_bandwidth 8000(64kbps) 328 * @param receive_bandwidth 8000(64kbps) 329 * @param max_latency >= 7ms for eSCO, 0xFFFF do not care 330 * @param voice_settings e.g. CVSD, Input Coding: Linear, Input Data Format: 2’s complement, data 16bit: 00011000000 == 0x60 331 * @param retransmission_effort e.g. 0xFF do not care 332 * @param packet_type at least EV3 for eSCO 333 */ 334 const hci_cmd_t hci_setup_synchronous_connection = { 335 OPCODE(OGF_LINK_CONTROL, 0x0028), "H442212" 336 }; 337 338 /** 339 * @param bd_addr 340 * @param transmit_bandwidth 341 * @param receive_bandwidth 342 * @param max_latency 343 * @param voice_settings 344 * @param retransmission_effort 345 * @param packet_type 346 */ 347 const hci_cmd_t hci_accept_synchronous_connection = { 348 OPCODE(OGF_LINK_CONTROL, 0x0029), "B442212" 349 }; 350 351 /** 352 * @param bd_addr 353 * @param IO_capability 354 * @param OOB_data_present 355 * @param authentication_requirements 356 */ 357 const hci_cmd_t hci_io_capability_request_reply = { 358 OPCODE(OGF_LINK_CONTROL, 0x2b), "B111" 359 }; 360 361 /** 362 * @param bd_addr 363 */ 364 const hci_cmd_t hci_user_confirmation_request_reply = { 365 OPCODE(OGF_LINK_CONTROL, 0x2c), "B" 366 }; 367 368 /** 369 * @param bd_addr 370 */ 371 const hci_cmd_t hci_user_confirmation_request_negative_reply = { 372 OPCODE(OGF_LINK_CONTROL, 0x2d), "B" 373 }; 374 375 /** 376 * @param bd_addr 377 * @param numeric_value 378 */ 379 const hci_cmd_t hci_user_passkey_request_reply = { 380 OPCODE(OGF_LINK_CONTROL, 0x2e), "B4" 381 }; 382 383 /** 384 * @param bd_addr 385 */ 386 const hci_cmd_t hci_user_passkey_request_negative_reply = { 387 OPCODE(OGF_LINK_CONTROL, 0x2f), "B" 388 }; 389 390 /** 391 * @param bd_addr 392 * @param c Simple Pairing Hash C 393 * @param r Simple Pairing Randomizer R 394 */ 395 const hci_cmd_t hci_remote_oob_data_request_reply = { 396 OPCODE(OGF_LINK_CONTROL, 0x30), "BPP" 397 }; 398 399 /** 400 * @param bd_addr 401 */ 402 const hci_cmd_t hci_remote_oob_data_request_negative_reply = { 403 OPCODE(OGF_LINK_CONTROL, 0x33), "B" 404 }; 405 406 /** 407 * @param bd_addr 408 * @param reason (Part D, Error codes) 409 */ 410 const hci_cmd_t hci_io_capability_request_negative_reply = { 411 OPCODE(OGF_LINK_CONTROL, 0x34), "B1" 412 }; 413 414 /** 415 * @param handle 416 * @param transmit_bandwidth 417 * @param receive_bandwidth 418 * @param transmit_coding_format_type 419 * @param transmit_coding_format_company 420 * @param transmit_coding_format_codec 421 * @param receive_coding_format_type 422 * @param receive_coding_format_company 423 * @param receive_coding_format_codec 424 * @param transmit_coding_frame_size 425 * @param receive_coding_frame_size 426 * @param input_bandwidth 427 * @param output_bandwidth 428 * @param input_coding_format_type 429 * @param input_coding_format_company 430 * @param input_coding_format_codec 431 * @param output_coding_format_type 432 * @param output_coding_format_company 433 * @param output_coding_format_codec 434 * @param input_coded_data_size 435 * @param outupt_coded_data_size 436 * @param input_pcm_data_format 437 * @param output_pcm_data_format 438 * @param input_pcm_sample_payload_msb_position 439 * @param output_pcm_sample_payload_msb_position 440 * @param input_data_path 441 * @param output_data_path 442 * @param input_transport_unit_size 443 * @param output_transport_unit_size 444 * @param max_latency 445 * @param packet_type 446 * @param retransmission_effort 447 */ 448 const hci_cmd_t hci_enhanced_setup_synchronous_connection = { 449 OPCODE(OGF_LINK_CONTROL, 0x3d), "H4412212222441221222211111111221" 450 }; 451 452 /** 453 * @param bd_addr 454 * @param transmit_bandwidth 455 * @param receive_bandwidth 456 * @param transmit_coding_format_type 457 * @param transmit_coding_format_company 458 * @param transmit_coding_format_codec 459 * @param receive_coding_format_type 460 * @param receive_coding_format_company 461 * @param receive_coding_format_codec 462 * @param transmit_coding_frame_size 463 * @param receive_coding_frame_size 464 * @param input_bandwidth 465 * @param output_bandwidth 466 * @param input_coding_format_type 467 * @param input_coding_format_company 468 * @param input_coding_format_codec 469 * @param output_coding_format_type 470 * @param output_coding_format_company 471 * @param output_coding_format_codec 472 * @param input_coded_data_size 473 * @param outupt_coded_data_size 474 * @param input_pcm_data_format 475 * @param output_pcm_data_format 476 * @param input_pcm_sample_payload_msb_position 477 * @param output_pcm_sample_payload_msb_position 478 * @param input_data_path 479 * @param output_data_path 480 * @param input_transport_unit_size 481 * @param output_transport_unit_size 482 * @param max_latency 483 * @param packet_type 484 * @param retransmission_effort 485 */ 486 const hci_cmd_t hci_enhanced_accept_synchronous_connection = { 487 OPCODE(OGF_LINK_CONTROL, 0x3e), "B4412212222441221222211111111221" 488 }; 489 490 /** 491 * Link Policy Commands 492 */ 493 494 /** 495 * @param handle 496 * @param sniff_max_interval 497 * @param sniff_min_interval 498 * @param sniff_attempt 499 * @param sniff_timeout 500 */ 501 const hci_cmd_t hci_sniff_mode = { 502 OPCODE(OGF_LINK_POLICY, 0x03), "H2222" 503 }; 504 505 /** 506 * @param handle 507 * @param flags 508 * @param service_type 509 * @param token_rate (bytes/s) 510 * @param peak_bandwith (bytes/s) 511 * @param latency (us) 512 * @param delay_variation (us) 513 */ 514 const hci_cmd_t hci_qos_setup = { 515 OPCODE(OGF_LINK_POLICY, 0x07), "H114444" 516 }; 517 518 /** 519 * @param handle 520 */ 521 const hci_cmd_t hci_role_discovery = { 522 OPCODE(OGF_LINK_POLICY, 0x09), "H" 523 }; 524 525 /** 526 * @param bd_addr 527 * @param role (0=master,1=slave) 528 */ 529 const hci_cmd_t hci_switch_role_command= { 530 OPCODE(OGF_LINK_POLICY, 0x0b), "B1" 531 }; 532 533 /** 534 * @param handle 535 */ 536 const hci_cmd_t hci_read_link_policy_settings = { 537 OPCODE(OGF_LINK_POLICY, 0x0c), "H" 538 }; 539 540 /** 541 * @param handle 542 * @param settings 543 */ 544 const hci_cmd_t hci_write_link_policy_settings = { 545 OPCODE(OGF_LINK_POLICY, 0x0d), "H2" 546 }; 547 548 549 /** 550 * Controller & Baseband Commands 551 */ 552 553 /** 554 * @param event_mask_lover_octets 555 * @param event_mask_higher_octets 556 */ 557 const hci_cmd_t hci_set_event_mask = { 558 OPCODE(OGF_CONTROLLER_BASEBAND, 0x01), "44" 559 }; 560 561 /** 562 */ 563 const hci_cmd_t hci_reset = { 564 OPCODE(OGF_CONTROLLER_BASEBAND, 0x03), "" 565 }; 566 567 /** 568 * @param handle 569 */ 570 const hci_cmd_t hci_flush = { 571 OPCODE(OGF_CONTROLLER_BASEBAND, 0x09), "H" 572 }; 573 574 /** 575 * @param bd_addr 576 * @param delete_all_flags 577 */ 578 const hci_cmd_t hci_delete_stored_link_key = { 579 OPCODE(OGF_CONTROLLER_BASEBAND, 0x12), "B1" 580 }; 581 582 #ifdef ENABLE_CLASSIC 583 /** 584 * @param local_name (UTF-8, Null Terminated, max 248 octets) 585 */ 586 const hci_cmd_t hci_write_local_name = { 587 OPCODE(OGF_CONTROLLER_BASEBAND, 0x13), "N" 588 }; 589 #endif 590 591 /** 592 */ 593 const hci_cmd_t hci_read_local_name = { 594 OPCODE(OGF_CONTROLLER_BASEBAND, 0x14), "" 595 }; 596 597 /** 598 * @param page_timeout (* 0.625 ms) 599 */ 600 const hci_cmd_t hci_write_page_timeout = { 601 OPCODE(OGF_CONTROLLER_BASEBAND, 0x18), "2" 602 }; 603 604 /** 605 * @param scan_enable (no, inq, page, inq+page) 606 */ 607 const hci_cmd_t hci_write_scan_enable = { 608 OPCODE(OGF_CONTROLLER_BASEBAND, 0x1A), "1" 609 }; 610 611 /** 612 * @param authentication_enable 613 */ 614 const hci_cmd_t hci_write_authentication_enable = { 615 OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1" 616 }; 617 618 /** 619 * @param class_of_device 620 */ 621 const hci_cmd_t hci_write_class_of_device = { 622 OPCODE(OGF_CONTROLLER_BASEBAND, 0x24), "3" 623 }; 624 625 /** 626 */ 627 const hci_cmd_t hci_read_num_broadcast_retransmissions = { 628 OPCODE(OGF_CONTROLLER_BASEBAND, 0x29), "" 629 }; 630 631 /** 632 * @param num_broadcast_retransmissions (e.g. 0 for a single broadcast) 633 */ 634 const hci_cmd_t hci_write_num_broadcast_retransmissions = { 635 OPCODE(OGF_CONTROLLER_BASEBAND, 0x2a), "1" 636 }; 637 638 /** 639 * @param synchronous_flow_control_enable - if yes, num completed packet everts are sent for SCO packets 640 */ 641 const hci_cmd_t hci_write_synchronous_flow_control_enable = { 642 OPCODE(OGF_CONTROLLER_BASEBAND, 0x2f), "1" 643 }; 644 645 /** 646 * @param host_acl_data_packet_length 647 * @param host_synchronous_data_packet_length 648 * @param host_total_num_acl_data_packets 649 * @param host_total_num_synchronous_data_packets 650 */ 651 const hci_cmd_t hci_host_buffer_size = { 652 OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122" 653 }; 654 655 /** 656 * @param handle 657 */ 658 const hci_cmd_t hci_read_link_supervision_timeout = { 659 OPCODE(OGF_CONTROLLER_BASEBAND, 0x36), "H" 660 }; 661 662 /** 663 * @param handle 664 * @param timeout (0x0001 - 0xFFFF Time -> Range: 0.625ms - 40.9 sec) 665 */ 666 const hci_cmd_t hci_write_link_supervision_timeout = { 667 OPCODE(OGF_CONTROLLER_BASEBAND, 0x37), "H2" 668 }; 669 670 /** 671 * @param inquiry_mode (0x00 = standard, 0x01 = with RSSI, 0x02 = extended) 672 */ 673 const hci_cmd_t hci_write_inquiry_mode = { 674 OPCODE(OGF_CONTROLLER_BASEBAND, 0x45), "1" 675 }; 676 677 /** 678 * @param fec_required 679 * @param exstended_inquiry_response 680 */ 681 const hci_cmd_t hci_write_extended_inquiry_response = { 682 OPCODE(OGF_CONTROLLER_BASEBAND, 0x52), "1E" 683 }; 684 685 /** 686 * @param mode (0 = off, 1 = on) 687 */ 688 const hci_cmd_t hci_write_simple_pairing_mode = { 689 OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1" 690 }; 691 692 /** 693 */ 694 const hci_cmd_t hci_read_local_oob_data = { 695 OPCODE(OGF_CONTROLLER_BASEBAND, 0x57), "" 696 // return status, C, R 697 }; 698 699 /** 700 * @param mode (0 = off, 1 = on) 701 */ 702 const hci_cmd_t hci_write_default_erroneous_data_reporting = { 703 OPCODE(OGF_CONTROLLER_BASEBAND, 0x5B), "1" 704 }; 705 706 /** 707 */ 708 const hci_cmd_t hci_read_le_host_supported = { 709 OPCODE(OGF_CONTROLLER_BASEBAND, 0x6c), "" 710 // return: status, le supported host, simultaneous le host 711 }; 712 713 /** 714 * @param le_supported_host 715 * @param simultaneous_le_host 716 */ 717 const hci_cmd_t hci_write_le_host_supported = { 718 OPCODE(OGF_CONTROLLER_BASEBAND, 0x6d), "11" 719 // return: status 720 }; 721 722 /** 723 */ 724 const hci_cmd_t hci_read_local_extended_ob_data = { 725 OPCODE(OGF_CONTROLLER_BASEBAND, 0x7d), "" 726 // return status, C_192, R_192, R_256, C_256 727 }; 728 729 730 /** 731 * Testing Commands 732 */ 733 734 735 /** 736 */ 737 const hci_cmd_t hci_read_loopback_mode = { 738 OPCODE(OGF_TESTING, 0x01), "" 739 // return: status, loopback mode (0 = off, 1 = local loopback, 2 = remote loopback) 740 }; 741 742 /** 743 * @param loopback_mode 744 */ 745 const hci_cmd_t hci_write_loopback_mode = { 746 OPCODE(OGF_TESTING, 0x02), "1" 747 // return: status 748 }; 749 750 751 /** 752 * Informational Parameters 753 */ 754 755 const hci_cmd_t hci_read_local_version_information = { 756 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x01), "" 757 }; 758 const hci_cmd_t hci_read_local_supported_commands = { 759 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x02), "" 760 }; 761 const hci_cmd_t hci_read_local_supported_features = { 762 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x03), "" 763 }; 764 const hci_cmd_t hci_read_buffer_size = { 765 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x05), "" 766 }; 767 const hci_cmd_t hci_read_bd_addr = { 768 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), "" 769 }; 770 771 /** 772 * Status Paramters 773 */ 774 775 /** 776 * @param handle 777 */ 778 const hci_cmd_t hci_read_rssi = { 779 OPCODE(OGF_STATUS_PARAMETERS, 0x05), "H" 780 // no params 781 }; 782 783 784 785 #ifdef ENABLE_BLE 786 /** 787 * Low Energy Commands 788 */ 789 790 /** 791 * @param event_mask_lower_octets 792 * @param event_mask_higher_octets 793 */ 794 const hci_cmd_t hci_le_set_event_mask = { 795 OPCODE(OGF_LE_CONTROLLER, 0x01), "44" 796 // return: status 797 }; 798 799 const hci_cmd_t hci_le_read_buffer_size = { 800 OPCODE(OGF_LE_CONTROLLER, 0x02), "" 801 // return: status, le acl data packet len (16), total num le acl data packets(8) 802 }; 803 const hci_cmd_t hci_le_read_supported_features = { 804 OPCODE(OGF_LE_CONTROLLER, 0x03), "" 805 // return: LE_Features See [Vol 6] Part B, Section 4.6 806 }; 807 808 /** 809 * @param random_bd_addr 810 */ 811 const hci_cmd_t hci_le_set_random_address = { 812 OPCODE(OGF_LE_CONTROLLER, 0x05), "B" 813 // return: status 814 }; 815 816 /** 817 * @param advertising_interval_min ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec) 818 * @param advertising_interval_max ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec) 819 * @param advertising_type (enum from 0: ADV_IND, ADC_DIRECT_IND, ADV_SCAN_IND, ADV_NONCONN_IND) 820 * @param own_address_type (enum from 0: public device address, random device address) 821 * @param direct_address_type () 822 * @param direct_address (public or random address of device to be connecteed) 823 * @param advertising_channel_map (flags: chan_37(1), chan_38(2), chan_39(4)) 824 * @param advertising_filter_policy (enum from 0: scan any conn any, scan whitelist, con any, scan any conn whitelist, scan whitelist, con whitelist) 825 */ 826 const hci_cmd_t hci_le_set_advertising_parameters = { 827 OPCODE(OGF_LE_CONTROLLER, 0x06), "22111B11" 828 // return: status 829 }; 830 831 const hci_cmd_t hci_le_read_advertising_channel_tx_power = { 832 OPCODE(OGF_LE_CONTROLLER, 0x07), "" 833 // return: status, level [-20,10] signed int (8), units dBm 834 }; 835 836 /** 837 * @param advertising_data_length 838 * @param advertising_data (31 bytes) 839 */ 840 const hci_cmd_t hci_le_set_advertising_data= { 841 OPCODE(OGF_LE_CONTROLLER, 0x08), "1A" 842 // return: status 843 }; 844 845 /** 846 * @param scan_response_data_length 847 * @param scan_response_data (31 bytes) 848 */ 849 const hci_cmd_t hci_le_set_scan_response_data= { 850 OPCODE(OGF_LE_CONTROLLER, 0x09), "1A" 851 // return: status 852 }; 853 854 /** 855 * @param advertise_enable (off: 0, on: 1) 856 */ 857 const hci_cmd_t hci_le_set_advertise_enable = { 858 OPCODE(OGF_LE_CONTROLLER, 0x0a), "1" 859 // return: status 860 }; 861 862 /** 863 * @param le_scan_type (passive (0), active (1)) 864 * @param le_scan_interval ([0x0004,0x4000], unit: 0.625 msec) 865 * @param le_scan_window ([0x0004,0x4000], unit: 0.625 msec) 866 * @param own_address_type (public (0), random (1)) 867 * @param scanning_filter_policy (any (0), only whitelist (1)) 868 */ 869 const hci_cmd_t hci_le_set_scan_parameters = { 870 OPCODE(OGF_LE_CONTROLLER, 0x0b), "12211" 871 // return: status 872 }; 873 874 /** 875 * @param le_scan_enable (disabled (0), enabled (1)) 876 * @param filter_duplices (disabled (0), enabled (1)) 877 */ 878 const hci_cmd_t hci_le_set_scan_enable = { 879 OPCODE(OGF_LE_CONTROLLER, 0x0c), "11" 880 // return: status 881 }; 882 883 /** 884 * @param le_scan_interval ([0x0004, 0x4000], unit: 0.625 msec) 885 * @param le_scan_window ([0x0004, 0x4000], unit: 0.625 msec) 886 * @param initiator_filter_policy (peer address type + peer address (0), whitelist (1)) 887 * @param peer_address_type (public (0), random (1)) 888 * @param peer_address 889 * @param own_address_type (public (0), random (1)) 890 * @param conn_interval_min ([0x0006, 0x0c80], unit: 1.25 msec) 891 * @param conn_interval_max ([0x0006, 0x0c80], unit: 1.25 msec) 892 * @param conn_latency (number of connection events [0x0000, 0x01f4]) 893 * @param supervision_timeout ([0x000a, 0x0c80], unit: 10 msec) 894 * @param minimum_CE_length ([0x0000, 0xffff], unit: 0.625 msec) 895 * @param maximum_CE_length ([0x0000, 0xffff], unit: 0.625 msec) 896 */ 897 const hci_cmd_t hci_le_create_connection= { 898 OPCODE(OGF_LE_CONTROLLER, 0x0d), "2211B1222222" 899 // return: none -> le create connection complete event 900 }; 901 902 const hci_cmd_t hci_le_create_connection_cancel = { 903 OPCODE(OGF_LE_CONTROLLER, 0x0e), "" 904 // return: status 905 }; 906 907 const hci_cmd_t hci_le_read_white_list_size = { 908 OPCODE(OGF_LE_CONTROLLER, 0x0f), "" 909 // return: status, number of entries in controller whitelist 910 }; 911 912 const hci_cmd_t hci_le_clear_white_list = { 913 OPCODE(OGF_LE_CONTROLLER, 0x10), "" 914 // return: status 915 }; 916 917 /** 918 * @param address_type (public (0), random (1)) 919 * @param bd_addr 920 */ 921 const hci_cmd_t hci_le_add_device_to_white_list = { 922 OPCODE(OGF_LE_CONTROLLER, 0x11), "1B" 923 // return: status 924 }; 925 926 /** 927 * @param address_type (public (0), random (1)) 928 * @param bd_addr 929 */ 930 const hci_cmd_t hci_le_remove_device_from_white_list = { 931 OPCODE(OGF_LE_CONTROLLER, 0x12), "1B" 932 // return: status 933 }; 934 935 /** 936 * @param conn_handle 937 * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec) 938 * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec) 939 * @param conn_latency ([0x0000,0x03e8], number of connection events) 940 * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec) 941 * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec) 942 * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec) 943 */ 944 const hci_cmd_t hci_le_connection_update = { 945 OPCODE(OGF_LE_CONTROLLER, 0x13), "H222222" 946 // return: none -> le connection update complete event 947 }; 948 949 /** 950 * @param channel_map_lower_32bits 951 * @param channel_map_higher_5bits 952 */ 953 const hci_cmd_t hci_le_set_host_channel_classification = { 954 OPCODE(OGF_LE_CONTROLLER, 0x14), "41" 955 // return: status 956 }; 957 958 /** 959 * @param conn_handle 960 */ 961 const hci_cmd_t hci_le_read_channel_map = { 962 OPCODE(OGF_LE_CONTROLLER, 0x15), "H" 963 // return: status, connection handle, channel map (5 bytes, 37 used) 964 }; 965 966 /** 967 * @param conn_handle 968 */ 969 const hci_cmd_t hci_le_read_remote_used_features = { 970 OPCODE(OGF_LE_CONTROLLER, 0x16), "H" 971 // return: none -> le read remote used features complete event 972 }; 973 974 /** 975 * @param key ((128) for AES-128) 976 * @param plain_text (128) 977 */ 978 const hci_cmd_t hci_le_encrypt = { 979 OPCODE(OGF_LE_CONTROLLER, 0x17), "PP" 980 // return: status, encrypted data (128) 981 }; 982 983 const hci_cmd_t hci_le_rand = { 984 OPCODE(OGF_LE_CONTROLLER, 0x18), "" 985 // return: status, random number (64) 986 }; 987 988 /** 989 * @param conn_handle 990 * @param random_number_lower_32bits 991 * @param random_number_higher_32bits 992 * @param encryption_diversifier (16) 993 * @param long_term_key (128) 994 */ 995 const hci_cmd_t hci_le_start_encryption = { 996 OPCODE(OGF_LE_CONTROLLER, 0x19), "H442P" 997 // return: none -> encryption changed or encryption key refresh complete event 998 }; 999 1000 /** 1001 * @param connection_handle 1002 * @param long_term_key (128) 1003 */ 1004 const hci_cmd_t hci_le_long_term_key_request_reply = { 1005 OPCODE(OGF_LE_CONTROLLER, 0x1a), "HP" 1006 // return: status, connection handle 1007 }; 1008 1009 /** 1010 * @param conn_handle 1011 */ 1012 const hci_cmd_t hci_le_long_term_key_negative_reply = { 1013 OPCODE(OGF_LE_CONTROLLER, 0x1b), "H" 1014 // return: status, connection handle 1015 }; 1016 1017 /** 1018 * @param conn_handle 1019 */ 1020 const hci_cmd_t hci_le_read_supported_states = { 1021 OPCODE(OGF_LE_CONTROLLER, 0x1c), "H" 1022 // return: status, LE states (64) 1023 }; 1024 1025 /** 1026 * @param rx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2) 1027 */ 1028 const hci_cmd_t hci_le_receiver_test = { 1029 OPCODE(OGF_LE_CONTROLLER, 0x1d), "1" 1030 // return: status 1031 }; 1032 1033 /** 1034 * @param tx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2) 1035 * @param test_payload_lengh ([0x00,0x25]) 1036 * @param packet_payload ([0,7] different patterns) 1037 */ 1038 const hci_cmd_t hci_le_transmitter_test = { 1039 OPCODE(OGF_LE_CONTROLLER, 0x1e), "111" 1040 // return: status 1041 }; 1042 1043 /** 1044 * @param end_test_cmd 1045 */ 1046 const hci_cmd_t hci_le_test_end = { 1047 OPCODE(OGF_LE_CONTROLLER, 0x1f), "1" 1048 // return: status, number of packets (8) 1049 }; 1050 1051 /** 1052 */ 1053 const hci_cmd_t hci_le_read_local_p256_public_key = { 1054 OPCODE(OGF_LE_CONTROLLER, 0x25), "" 1055 // LE Read Local P-256 Public Key Complete is generated on completion 1056 }; 1057 1058 #ifdef HAVE_HCI_CONTROLLER_DHKEY_SUPPORT 1059 /** 1060 * @param end_test_cmd 1061 */ 1062 const hci_cmd_t hci_le_generate_dhkey = { 1063 OPCODE(OGF_LE_CONTROLLER, 0x26), "QQ" 1064 // LE Generate DHKey Complete is generated on completion 1065 }; 1066 #endif 1067 1068 #endif 1069 1070 // Broadcom / Cypress specific HCI commands 1071 1072 /** 1073 * @brief Configure SCO Routing (BCM) 1074 * @param sco_routing is 0 for PCM, 1 for Transport, 2 for Codec and 3 for I2S 1075 * @param pcm_interface_rate is 0 for 128KBps, 1 for 256 KBps, 2 for 512KBps, 3 for 1024KBps, and 4 for 2048Kbps 1076 * @param frame_type is 0 for short and 1 for long 1077 * @param sync_mode is 0 for slave and 1 for master 1078 * @param clock_mode is 0 for slabe and 1 for master 1079 */ 1080 const hci_cmd_t hci_bcm_write_sco_pcm_int = { 1081 OPCODE(0x3f, 0x1c), "11111" 1082 // return: status 1083 }; 1084