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