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