xref: /btstack/src/hci_cmd.h (revision e90bae0148b168505f3c9b81279423e4ad8096b5)
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 
4456042629SMatthias Ringwald #ifndef __HCI_CMDS_H
4556042629SMatthias 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_enhanced_setup_synchronous_connection;
9756042629SMatthias Ringwald extern const hci_cmd_t hci_enhanced_accept_synchronous_connection;
9856042629SMatthias Ringwald extern const hci_cmd_t hci_disconnect;
99e49d496aSMatthias Ringwald extern const hci_cmd_t hci_flush;
10056042629SMatthias Ringwald extern const hci_cmd_t hci_host_buffer_size;
10156042629SMatthias Ringwald extern const hci_cmd_t hci_inquiry;
10256042629SMatthias Ringwald extern const hci_cmd_t hci_io_capability_request_reply;
10356042629SMatthias Ringwald extern const hci_cmd_t hci_io_capability_request_negative_reply;
10456042629SMatthias Ringwald extern const hci_cmd_t hci_inquiry_cancel;
10556042629SMatthias Ringwald extern const hci_cmd_t hci_link_key_request_negative_reply;
10656042629SMatthias Ringwald extern const hci_cmd_t hci_link_key_request_reply;
10756042629SMatthias Ringwald extern const hci_cmd_t hci_pin_code_request_reply;
10856042629SMatthias Ringwald extern const hci_cmd_t hci_pin_code_request_negative_reply;
10956042629SMatthias Ringwald extern const hci_cmd_t hci_qos_setup;
11056042629SMatthias Ringwald extern const hci_cmd_t hci_read_bd_addr;
11156042629SMatthias Ringwald extern const hci_cmd_t hci_read_buffer_size;
11256042629SMatthias Ringwald extern const hci_cmd_t hci_read_le_host_supported;
11356042629SMatthias Ringwald extern const hci_cmd_t hci_read_link_policy_settings;
11456042629SMatthias Ringwald extern const hci_cmd_t hci_read_link_supervision_timeout;
115*e90bae01SMatthias Ringwald extern const hci_cmd_t hci_read_local_name;
11656042629SMatthias Ringwald extern const hci_cmd_t hci_read_local_version_information;
11756042629SMatthias Ringwald extern const hci_cmd_t hci_read_local_supported_commands;
11856042629SMatthias Ringwald extern const hci_cmd_t hci_read_local_supported_features;
11956042629SMatthias Ringwald extern const hci_cmd_t hci_read_num_broadcast_retransmissions;
12056042629SMatthias Ringwald extern const hci_cmd_t hci_read_remote_supported_features_command;
12156042629SMatthias Ringwald extern const hci_cmd_t hci_read_rssi;
12256042629SMatthias Ringwald extern const hci_cmd_t hci_reject_connection_request;
12356042629SMatthias Ringwald extern const hci_cmd_t hci_remote_name_request;
12456042629SMatthias Ringwald extern const hci_cmd_t hci_remote_name_request_cancel;
12556042629SMatthias Ringwald extern const hci_cmd_t hci_remote_oob_data_request_negative_reply;
12656042629SMatthias Ringwald extern const hci_cmd_t hci_reset;
12756042629SMatthias Ringwald extern const hci_cmd_t hci_role_discovery;
12856042629SMatthias Ringwald extern const hci_cmd_t hci_set_event_mask;
12956042629SMatthias Ringwald extern const hci_cmd_t hci_set_connection_encryption;
13056042629SMatthias Ringwald extern const hci_cmd_t hci_setup_synchronous_connection;
13156042629SMatthias Ringwald extern const hci_cmd_t hci_sniff_mode;
13256042629SMatthias Ringwald extern const hci_cmd_t hci_switch_role_command;
13356042629SMatthias Ringwald extern const hci_cmd_t hci_user_confirmation_request_negative_reply;
13456042629SMatthias Ringwald extern const hci_cmd_t hci_user_confirmation_request_reply;
13556042629SMatthias Ringwald extern const hci_cmd_t hci_user_passkey_request_negative_reply;
13656042629SMatthias Ringwald extern const hci_cmd_t hci_user_passkey_request_reply;
13756042629SMatthias Ringwald extern const hci_cmd_t hci_write_authentication_enable;
13856042629SMatthias Ringwald extern const hci_cmd_t hci_write_class_of_device;
139483c5078SMatthias Ringwald extern const hci_cmd_t hci_write_default_erroneous_data_reporting;
14056042629SMatthias Ringwald extern const hci_cmd_t hci_write_extended_inquiry_response;
14156042629SMatthias Ringwald extern const hci_cmd_t hci_write_inquiry_mode;
14256042629SMatthias Ringwald extern const hci_cmd_t hci_write_le_host_supported;
14356042629SMatthias Ringwald extern const hci_cmd_t hci_write_link_policy_settings;
14456042629SMatthias Ringwald extern const hci_cmd_t hci_write_link_supervision_timeout;
14556042629SMatthias Ringwald extern const hci_cmd_t hci_write_local_name;
14656042629SMatthias Ringwald extern const hci_cmd_t hci_write_num_broadcast_retransmissions;
14756042629SMatthias Ringwald extern const hci_cmd_t hci_write_page_timeout;
14856042629SMatthias Ringwald extern const hci_cmd_t hci_write_scan_enable;
14956042629SMatthias Ringwald extern const hci_cmd_t hci_write_simple_pairing_mode;
15056042629SMatthias Ringwald extern const hci_cmd_t hci_write_synchronous_flow_control_enable;
15156042629SMatthias Ringwald extern const hci_cmd_t hci_read_loopback_mode;
15256042629SMatthias Ringwald extern const hci_cmd_t hci_write_loopback_mode;
15356042629SMatthias Ringwald 
15456042629SMatthias Ringwald extern const hci_cmd_t hci_le_add_device_to_white_list;
15556042629SMatthias Ringwald extern const hci_cmd_t hci_le_clear_white_list;
15656042629SMatthias Ringwald extern const hci_cmd_t hci_le_connection_update;
15756042629SMatthias Ringwald extern const hci_cmd_t hci_le_create_connection;
15856042629SMatthias Ringwald extern const hci_cmd_t hci_le_create_connection_cancel;
15956042629SMatthias Ringwald extern const hci_cmd_t hci_le_encrypt;
16082180fcaSMatthias Ringwald extern const hci_cmd_t hci_le_generate_dhkey;
16156042629SMatthias Ringwald extern const hci_cmd_t hci_le_long_term_key_negative_reply;
16256042629SMatthias Ringwald extern const hci_cmd_t hci_le_long_term_key_request_reply;
16356042629SMatthias Ringwald extern const hci_cmd_t hci_le_rand;
16456042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_advertising_channel_tx_power;
16556042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_buffer_size ;
16656042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_channel_map;
16782180fcaSMatthias Ringwald extern const hci_cmd_t hci_le_read_local_p256_public_key;
16856042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_remote_used_features;
16956042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_supported_features;
17056042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_supported_states;
17156042629SMatthias Ringwald extern const hci_cmd_t hci_le_read_white_list_size;
17256042629SMatthias Ringwald extern const hci_cmd_t hci_le_receiver_test;
17356042629SMatthias Ringwald extern const hci_cmd_t hci_le_remove_device_from_white_list;
17456042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_advertise_enable;
17556042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_advertising_data;
17656042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_advertising_parameters;
17756042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_event_mask;
17856042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_host_channel_classification;
17956042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_random_address;
18056042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_scan_enable;
18156042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_scan_parameters;
18256042629SMatthias Ringwald extern const hci_cmd_t hci_le_set_scan_response_data;
18356042629SMatthias Ringwald extern const hci_cmd_t hci_le_start_encryption;
18456042629SMatthias Ringwald extern const hci_cmd_t hci_le_test_end;
18556042629SMatthias Ringwald extern const hci_cmd_t hci_le_transmitter_test;
18656042629SMatthias Ringwald 
18756042629SMatthias Ringwald /**
18856042629SMatthias Ringwald  * construct HCI Command based on template
18956042629SMatthias Ringwald  *
19056042629SMatthias Ringwald  * Format:
19156042629SMatthias Ringwald  *   1,2,3,4: one to four byte value
19256042629SMatthias Ringwald  *   H: HCI connection handle
19356042629SMatthias Ringwald  *   B: Bluetooth Baseband Address (BD_ADDR)
19456042629SMatthias Ringwald  *   D: 8 byte data block
19556042629SMatthias Ringwald  *   E: Extended Inquiry Result
19656042629SMatthias Ringwald  *   N: Name up to 248 chars, \0 terminated
19756042629SMatthias Ringwald  *   P: 16 byte Pairing code
19856042629SMatthias Ringwald  *   A: 31 bytes advertising data
19956042629SMatthias Ringwald  *   S: Service Record (Data Element Sequence)
20056042629SMatthias Ringwald  */
20156042629SMatthias Ringwald  uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr);
20256042629SMatthias Ringwald 
20356042629SMatthias Ringwald 
20456042629SMatthias Ringwald #if defined __cplusplus
20556042629SMatthias Ringwald }
20656042629SMatthias Ringwald #endif
20756042629SMatthias Ringwald 
20856042629SMatthias Ringwald #endif // __HCI_CMDS_H
209