xref: /btstack/src/hci_cmd.h (revision b002ae8c9bbe62b83655e09434d7d0d258f08f16)
156042629SMatthias Ringwald /*
256042629SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
356042629SMatthias Ringwald  *
456042629SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
556042629SMatthias Ringwald  * modification, are permitted provided that the following conditions
656042629SMatthias Ringwald  * are met:
756042629SMatthias Ringwald  *
856042629SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
956042629SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
1056042629SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
1156042629SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
1256042629SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
1356042629SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
1456042629SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
1556042629SMatthias Ringwald  *    from this software without specific prior written permission.
1656042629SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
1756042629SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
1856042629SMatthias Ringwald  *    monetary gain.
1956042629SMatthias Ringwald  *
2056042629SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
2156042629SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2256042629SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2356042629SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
2456042629SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2556042629SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2656042629SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2756042629SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2856042629SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2956042629SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
3056042629SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3156042629SMatthias Ringwald  * SUCH DAMAGE.
3256042629SMatthias Ringwald  *
3356042629SMatthias Ringwald  * Please inquire about commercial licensing options at
3456042629SMatthias Ringwald  * [email protected]
3556042629SMatthias Ringwald  *
3656042629SMatthias Ringwald  */
3756042629SMatthias Ringwald 
3856042629SMatthias Ringwald /*
3956042629SMatthias Ringwald  *  hci_cmd.h
4056042629SMatthias Ringwald  *
4156042629SMatthias Ringwald  *  Created by Matthias Ringwald on 7/23/09.
4256042629SMatthias Ringwald  */
4356042629SMatthias Ringwald 
4480e33422SMatthias Ringwald #ifndef HCI_CMDS_H
4580e33422SMatthias Ringwald #define HCI_CMDS_H
4656042629SMatthias Ringwald 
4756042629SMatthias Ringwald #include "bluetooth.h"
4856042629SMatthias Ringwald #include "btstack_defines.h"
4956042629SMatthias Ringwald 
5056042629SMatthias Ringwald #include <stdint.h>
5156042629SMatthias Ringwald #include <stdarg.h>
5256042629SMatthias Ringwald 
5356042629SMatthias Ringwald #if defined __cplusplus
5456042629SMatthias Ringwald extern "C" {
5556042629SMatthias Ringwald #endif
5656042629SMatthias Ringwald 
5756042629SMatthias Ringwald /**
5856042629SMatthias Ringwald  *  Hardware state of Bluetooth controller
5956042629SMatthias Ringwald  */
6056042629SMatthias Ringwald typedef enum {
6156042629SMatthias Ringwald     HCI_POWER_OFF = 0,
6256042629SMatthias Ringwald     HCI_POWER_ON,
6356042629SMatthias Ringwald     HCI_POWER_SLEEP
6456042629SMatthias Ringwald } HCI_POWER_MODE;
6556042629SMatthias Ringwald 
6656042629SMatthias Ringwald /**
6756042629SMatthias Ringwald  * State of BTstack
6856042629SMatthias Ringwald  */
6956042629SMatthias Ringwald typedef enum {
7056042629SMatthias Ringwald     HCI_STATE_OFF = 0,
7156042629SMatthias Ringwald     HCI_STATE_INITIALIZING,
7256042629SMatthias Ringwald     HCI_STATE_WORKING,
7356042629SMatthias Ringwald     HCI_STATE_HALTING,
7456042629SMatthias Ringwald     HCI_STATE_SLEEPING,
7556042629SMatthias Ringwald     HCI_STATE_FALLING_ASLEEP
7656042629SMatthias Ringwald } HCI_STATE;
7756042629SMatthias Ringwald 
7856042629SMatthias Ringwald /**
7956042629SMatthias Ringwald  * compact HCI Command packet description
8056042629SMatthias Ringwald  */
8156042629SMatthias Ringwald  typedef struct {
8256042629SMatthias Ringwald     uint16_t    opcode;
8356042629SMatthias Ringwald     const char *format;
8456042629SMatthias Ringwald } hci_cmd_t;
8556042629SMatthias Ringwald 
8656042629SMatthias Ringwald 
8756042629SMatthias Ringwald // HCI Commands - see hci_cmd.c for info on parameters
8856042629SMatthias Ringwald extern const hci_cmd_t hci_accept_connection_request;
8956042629SMatthias Ringwald extern const hci_cmd_t hci_accept_synchronous_connection;
9056042629SMatthias Ringwald extern const hci_cmd_t hci_authentication_requested;
9156042629SMatthias Ringwald extern const hci_cmd_t hci_change_connection_link_key;
9256042629SMatthias Ringwald extern const hci_cmd_t hci_change_connection_packet_type;
9356042629SMatthias Ringwald extern const hci_cmd_t hci_create_connection;
9456042629SMatthias Ringwald extern const hci_cmd_t hci_create_connection_cancel;
9556042629SMatthias Ringwald extern const hci_cmd_t hci_delete_stored_link_key;
9656042629SMatthias Ringwald extern const hci_cmd_t hci_disconnect;
9784ca9bd8SMatthias Ringwald extern const hci_cmd_t hci_enable_device_under_test_mode;
98bed80775SMatthias Ringwald extern const hci_cmd_t hci_enhanced_accept_synchronous_connection;
99bed80775SMatthias Ringwald extern const hci_cmd_t hci_enhanced_setup_synchronous_connection;
1007cd21895SMatthias Ringwald extern const hci_cmd_t hci_exit_sniff_mode;
101e49d496aSMatthias Ringwald extern const hci_cmd_t hci_flush;
10256042629SMatthias Ringwald extern const hci_cmd_t hci_host_buffer_size;
10356042629SMatthias Ringwald extern const hci_cmd_t hci_inquiry;
10456042629SMatthias Ringwald extern const hci_cmd_t hci_inquiry_cancel;
105bed80775SMatthias Ringwald extern const hci_cmd_t hci_io_capability_request_negative_reply;
106bed80775SMatthias Ringwald extern const hci_cmd_t hci_io_capability_request_reply;
10756042629SMatthias Ringwald extern const hci_cmd_t hci_link_key_request_negative_reply;
10856042629SMatthias Ringwald extern const hci_cmd_t hci_link_key_request_reply;
10956042629SMatthias Ringwald extern const hci_cmd_t hci_pin_code_request_negative_reply;
110bed80775SMatthias Ringwald extern const hci_cmd_t hci_pin_code_request_reply;
11156042629SMatthias Ringwald extern const hci_cmd_t hci_qos_setup;
11256042629SMatthias Ringwald extern const hci_cmd_t hci_read_bd_addr;
11356042629SMatthias Ringwald extern const hci_cmd_t hci_read_buffer_size;
11497abfa24SMatthias Ringwald extern const hci_cmd_t hci_read_encryption_key_size;
1154eac2391SMatthias Ringwald extern const hci_cmd_t hci_read_inquiry_scan_activity;
11656042629SMatthias Ringwald extern const hci_cmd_t hci_read_le_host_supported;
11756042629SMatthias Ringwald extern const hci_cmd_t hci_read_link_policy_settings;
11856042629SMatthias Ringwald extern const hci_cmd_t hci_read_link_supervision_timeout;
119bed80775SMatthias Ringwald extern const hci_cmd_t hci_read_local_extended_ob_data;
120237daac5SMatthias Ringwald extern const hci_cmd_t hci_read_local_extended_oob_data;
121e90bae01SMatthias Ringwald extern const hci_cmd_t hci_read_local_name;
122195e82f3Sskoperst extern const hci_cmd_t hci_read_page_timeout;
123195e82f3Sskoperst extern const hci_cmd_t hci_read_page_scan_activity;
1249af39d9fSMatthias Ringwald extern const hci_cmd_t hci_read_pin_type;
125237daac5SMatthias Ringwald extern const hci_cmd_t hci_read_local_oob_data;
12656042629SMatthias Ringwald extern const hci_cmd_t hci_read_local_supported_commands;
12756042629SMatthias Ringwald extern const hci_cmd_t hci_read_local_supported_features;
128237daac5SMatthias Ringwald extern const hci_cmd_t hci_read_local_version_information;
129bed80775SMatthias Ringwald extern const hci_cmd_t hci_read_loopback_mode;
13056042629SMatthias Ringwald extern const hci_cmd_t hci_read_num_broadcast_retransmissions;
13156042629SMatthias Ringwald extern const hci_cmd_t hci_read_remote_supported_features_command;
132d5057706SMatthias Ringwald extern const hci_cmd_t hci_read_remote_extended_features_command;
1338b22c04dSMatthias Ringwald extern const hci_cmd_t hci_read_remote_version_information;
13444751e25SMatthias Ringwald extern const hci_cmd_t hci_read_transmit_power_level;
13556042629SMatthias Ringwald extern const hci_cmd_t hci_read_rssi;
13656042629SMatthias Ringwald extern const hci_cmd_t hci_reject_connection_request;
13756042629SMatthias Ringwald extern const hci_cmd_t hci_remote_name_request;
13856042629SMatthias Ringwald extern const hci_cmd_t hci_remote_name_request_cancel;
13956042629SMatthias Ringwald extern const hci_cmd_t hci_remote_oob_data_request_negative_reply;
140bed80775SMatthias Ringwald extern const hci_cmd_t hci_remote_oob_data_request_reply;
14156042629SMatthias Ringwald extern const hci_cmd_t hci_reset;
14256042629SMatthias Ringwald extern const hci_cmd_t hci_role_discovery;
14356042629SMatthias Ringwald extern const hci_cmd_t hci_set_connection_encryption;
1442b838201SMatthias Ringwald extern const hci_cmd_t hci_set_controller_to_host_flow_control;
14584ca9bd8SMatthias Ringwald extern const hci_cmd_t hci_set_event_mask;
14656042629SMatthias Ringwald extern const hci_cmd_t hci_setup_synchronous_connection;
14756042629SMatthias Ringwald extern const hci_cmd_t hci_sniff_mode;
14856042629SMatthias Ringwald extern const hci_cmd_t hci_switch_role_command;
14956042629SMatthias Ringwald extern const hci_cmd_t hci_user_confirmation_request_negative_reply;
15056042629SMatthias Ringwald extern const hci_cmd_t hci_user_confirmation_request_reply;
15156042629SMatthias Ringwald extern const hci_cmd_t hci_user_passkey_request_negative_reply;
15256042629SMatthias Ringwald extern const hci_cmd_t hci_user_passkey_request_reply;
15356042629SMatthias Ringwald extern const hci_cmd_t hci_write_authentication_enable;
15456042629SMatthias Ringwald extern const hci_cmd_t hci_write_class_of_device;
1559119d792SMilanka Ringwald extern const hci_cmd_t hci_write_current_iac_lap_two_iacs;
156483c5078SMatthias Ringwald extern const hci_cmd_t hci_write_default_erroneous_data_reporting;
15753138e7aSMatthias Ringwald extern const hci_cmd_t hci_write_default_link_policy_setting;
15856042629SMatthias Ringwald extern const hci_cmd_t hci_write_extended_inquiry_response;
15956042629SMatthias Ringwald extern const hci_cmd_t hci_write_inquiry_mode;
1604eac2391SMatthias Ringwald extern const hci_cmd_t hci_write_inquiry_scan_activity;
16156042629SMatthias Ringwald extern const hci_cmd_t hci_write_le_host_supported;
16256042629SMatthias Ringwald extern const hci_cmd_t hci_write_link_policy_settings;
16356042629SMatthias Ringwald extern const hci_cmd_t hci_write_link_supervision_timeout;
16456042629SMatthias Ringwald extern const hci_cmd_t hci_write_local_name;
165bed80775SMatthias Ringwald extern const hci_cmd_t hci_write_loopback_mode;
16656042629SMatthias Ringwald extern const hci_cmd_t hci_write_num_broadcast_retransmissions;
16756042629SMatthias Ringwald extern const hci_cmd_t hci_write_page_timeout;
1689af39d9fSMatthias Ringwald extern const hci_cmd_t hci_write_pin_type;
169195e82f3Sskoperst extern const hci_cmd_t hci_write_page_scan_activity;
17056042629SMatthias Ringwald extern const hci_cmd_t hci_write_scan_enable;
171*b002ae8cSMatthias Ringwald extern const hci_cmd_t hci_write_secure_connections_host_support;
17284ca9bd8SMatthias Ringwald extern const hci_cmd_t hci_write_secure_connections_test_mode;
17384ca9bd8SMatthias Ringwald extern const hci_cmd_t hci_write_simple_pairing_debug_mode;
17456042629SMatthias Ringwald extern const hci_cmd_t hci_write_simple_pairing_mode;
17556042629SMatthias Ringwald extern const hci_cmd_t hci_write_synchronous_flow_control_enable;
17656042629SMatthias Ringwald 
17756042629SMatthias Ringwald extern const hci_cmd_t hci_le_add_device_to_white_list;
17856042629SMatthias Ringwald extern const hci_cmd_t hci_le_clear_white_list;
17956042629SMatthias Ringwald extern const hci_cmd_t hci_le_connection_update;
18056042629SMatthias Ringwald extern const hci_cmd_t hci_le_create_connection;
18156042629SMatthias Ringwald extern const hci_cmd_t hci_le_create_connection_cancel;
18256042629SMatthias Ringwald extern const hci_cmd_t hci_le_encrypt;
18382180fcaSMatthias Ringwald extern const hci_cmd_t hci_le_generate_dhkey;
18456042629SMatthias Ringwald extern const hci_cmd_t hci_le_long_term_key_negative_reply;
18556042629SMatthias Ringwald extern const hci_cmd_t hci_le_long_term_key_request_reply;
18656042629SMatthias Ringwald extern const hci_cmd_t hci_le_rand;
18756042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_advertising_channel_tx_power;
18856042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_buffer_size ;
18956042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_channel_map;
19082180fcaSMatthias Ringwald extern const hci_cmd_t hci_le_read_local_p256_public_key;
1910ea2847fSMatthias Ringwald extern const hci_cmd_t hci_le_read_maximum_data_length;
192ca13daefSMatthias Ringwald extern const hci_cmd_t hci_le_read_phy;
19356042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_remote_used_features;
1940ea2847fSMatthias Ringwald extern const hci_cmd_t hci_le_read_suggested_default_data_length;
19556042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_supported_features;
19656042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_supported_states;
19756042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_white_list_size;
19856042629SMatthias Ringwald extern const hci_cmd_t hci_le_receiver_test;
199fe704c95SMatthias Ringwald extern const hci_cmd_t hci_le_remote_connection_parameter_request_negative_reply;
200ca13daefSMatthias Ringwald extern const hci_cmd_t hci_le_remote_connection_parameter_request_reply;
20156042629SMatthias Ringwald extern const hci_cmd_t hci_le_remove_device_from_white_list;
20256042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_advertise_enable;
20356042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_advertising_data;
20456042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_advertising_parameters;
2050ea2847fSMatthias Ringwald extern const hci_cmd_t hci_le_set_data_length;
206ca13daefSMatthias Ringwald extern const hci_cmd_t hci_le_set_default_phy;
20756042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_event_mask;
20856042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_host_channel_classification;
209ca13daefSMatthias Ringwald extern const hci_cmd_t hci_le_set_phy;
21056042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_random_address;
21156042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_scan_enable;
21256042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_scan_parameters;
21356042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_scan_response_data;
21456042629SMatthias Ringwald extern const hci_cmd_t hci_le_start_encryption;
21556042629SMatthias Ringwald extern const hci_cmd_t hci_le_test_end;
21656042629SMatthias Ringwald extern const hci_cmd_t hci_le_transmitter_test;
2170ea2847fSMatthias Ringwald extern const hci_cmd_t hci_le_write_suggested_default_data_length;
218a42798c3SMatthias Ringwald 
219a42798c3SMatthias Ringwald // Broadcom / Cypress specific HCI commands
220eab6959fSMatthias Ringwald extern const hci_cmd_t hci_bcm_set_sleep_mode;
2215cdaddfaSMatthias Ringwald extern const hci_cmd_t hci_bcm_write_sco_pcm_int;
2225cdaddfaSMatthias Ringwald extern const hci_cmd_t hci_bcm_write_tx_power_table;
2234545e386SMatthias Ringwald extern const hci_cmd_t hci_bcm_set_tx_pwr;
224a42798c3SMatthias Ringwald 
225ba39ed56SMatthias Ringwald // TI specific HCI commands
226ba39ed56SMatthias Ringwald extern const hci_cmd_t hci_ti_drpb_tester_con_tx;
227ba39ed56SMatthias Ringwald extern const hci_cmd_t hci_ti_drpb_tester_packet_tx_rx;
228ba39ed56SMatthias Ringwald 
22956042629SMatthias Ringwald /**
23056042629SMatthias Ringwald  * construct HCI Command based on template
23156042629SMatthias Ringwald  *
23256042629SMatthias Ringwald  * Format:
23356042629SMatthias Ringwald  *   1,2,3,4: one to four byte value
23456042629SMatthias Ringwald  *   H: HCI connection handle
23556042629SMatthias Ringwald  *   B: Bluetooth Baseband Address (BD_ADDR)
23656042629SMatthias Ringwald  *   D: 8 byte data block
23756042629SMatthias Ringwald  *   E: Extended Inquiry Result
23856042629SMatthias Ringwald  *   N: Name up to 248 chars, \0 terminated
23956042629SMatthias Ringwald  *   P: 16 byte Pairing code
24056042629SMatthias Ringwald  *   A: 31 bytes advertising data
24156042629SMatthias Ringwald  *   S: Service Record (Data Element Sequence)
24256042629SMatthias Ringwald  */
24356042629SMatthias Ringwald  uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr);
24456042629SMatthias Ringwald 
24556042629SMatthias Ringwald 
24656042629SMatthias Ringwald #if defined __cplusplus
24756042629SMatthias Ringwald }
24856042629SMatthias Ringwald #endif
24956042629SMatthias Ringwald 
25080e33422SMatthias Ringwald #endif // HCI_CMDS_H
251