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