xref: /btstack/src/hci_cmd.h (revision c37cd8f3d1350b92a2f66c31b2a5fcd75f8c91a4)
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.h
40  *
41  *  Created by Matthias Ringwald on 7/23/09.
42  */
43 
44 #ifndef __HCI_CMDS_H
45 #define __HCI_CMDS_H
46 
47 #include "bluetooth.h"
48 #include "btstack_defines.h"
49 
50 #include <stdint.h>
51 #include <stdarg.h>
52 
53 #if defined __cplusplus
54 extern "C" {
55 #endif
56 
57 /**
58  *  Hardware state of Bluetooth controller
59  */
60 typedef enum {
61     HCI_POWER_OFF = 0,
62     HCI_POWER_ON,
63     HCI_POWER_SLEEP
64 } HCI_POWER_MODE;
65 
66 /**
67  * State of BTstack
68  */
69 typedef enum {
70     HCI_STATE_OFF = 0,
71     HCI_STATE_INITIALIZING,
72     HCI_STATE_WORKING,
73     HCI_STATE_HALTING,
74     HCI_STATE_SLEEPING,
75     HCI_STATE_FALLING_ASLEEP
76 } HCI_STATE;
77 
78 /**
79  * compact HCI Command packet description
80  */
81  typedef struct {
82     uint16_t    opcode;
83     const char *format;
84 } hci_cmd_t;
85 
86 
87 // HCI Commands - see hci_cmd.c for info on parameters
88 extern const hci_cmd_t hci_accept_connection_request;
89 extern const hci_cmd_t hci_accept_synchronous_connection;
90 extern const hci_cmd_t hci_authentication_requested;
91 extern const hci_cmd_t hci_change_connection_link_key;
92 extern const hci_cmd_t hci_change_connection_packet_type;
93 extern const hci_cmd_t hci_create_connection;
94 extern const hci_cmd_t hci_create_connection_cancel;
95 extern const hci_cmd_t hci_delete_stored_link_key;
96 extern const hci_cmd_t hci_disconnect;
97 extern const hci_cmd_t hci_enable_device_under_test_mode;
98 extern const hci_cmd_t hci_enhanced_accept_synchronous_connection;
99 extern const hci_cmd_t hci_enhanced_setup_synchronous_connection;
100 extern const hci_cmd_t hci_flush;
101 extern const hci_cmd_t hci_host_buffer_size;
102 extern const hci_cmd_t hci_inquiry;
103 extern const hci_cmd_t hci_inquiry_cancel;
104 extern const hci_cmd_t hci_io_capability_request_negative_reply;
105 extern const hci_cmd_t hci_io_capability_request_reply;
106 extern const hci_cmd_t hci_link_key_request_negative_reply;
107 extern const hci_cmd_t hci_link_key_request_reply;
108 extern const hci_cmd_t hci_pin_code_request_negative_reply;
109 extern const hci_cmd_t hci_pin_code_request_reply;
110 extern const hci_cmd_t hci_qos_setup;
111 extern const hci_cmd_t hci_read_bd_addr;
112 extern const hci_cmd_t hci_read_buffer_size;
113 extern const hci_cmd_t hci_read_le_host_supported;
114 extern const hci_cmd_t hci_read_link_policy_settings;
115 extern const hci_cmd_t hci_read_link_supervision_timeout;
116 extern const hci_cmd_t hci_read_local_extended_ob_data;
117 extern const hci_cmd_t hci_read_local_extended_oob_data;
118 extern const hci_cmd_t hci_read_local_name;
119 extern const hci_cmd_t hci_read_local_oob_data;
120 extern const hci_cmd_t hci_read_local_supported_commands;
121 extern const hci_cmd_t hci_read_local_supported_features;
122 extern const hci_cmd_t hci_read_local_version_information;
123 extern const hci_cmd_t hci_read_loopback_mode;
124 extern const hci_cmd_t hci_read_num_broadcast_retransmissions;
125 extern const hci_cmd_t hci_read_remote_supported_features_command;
126 extern const hci_cmd_t hci_read_rssi;
127 extern const hci_cmd_t hci_reject_connection_request;
128 extern const hci_cmd_t hci_remote_name_request;
129 extern const hci_cmd_t hci_remote_name_request_cancel;
130 extern const hci_cmd_t hci_remote_oob_data_request_negative_reply;
131 extern const hci_cmd_t hci_remote_oob_data_request_reply;
132 extern const hci_cmd_t hci_reset;
133 extern const hci_cmd_t hci_role_discovery;
134 extern const hci_cmd_t hci_set_connection_encryption;
135 extern const hci_cmd_t hci_set_controller_to_host_flow_control;
136 extern const hci_cmd_t hci_set_event_mask;
137 extern const hci_cmd_t hci_setup_synchronous_connection;
138 extern const hci_cmd_t hci_sniff_mode;
139 extern const hci_cmd_t hci_switch_role_command;
140 extern const hci_cmd_t hci_user_confirmation_request_negative_reply;
141 extern const hci_cmd_t hci_user_confirmation_request_reply;
142 extern const hci_cmd_t hci_user_passkey_request_negative_reply;
143 extern const hci_cmd_t hci_user_passkey_request_reply;
144 extern const hci_cmd_t hci_write_authentication_enable;
145 extern const hci_cmd_t hci_write_class_of_device;
146 extern const hci_cmd_t hci_write_default_erroneous_data_reporting;
147 extern const hci_cmd_t hci_write_extended_inquiry_response;
148 extern const hci_cmd_t hci_write_inquiry_mode;
149 extern const hci_cmd_t hci_write_le_host_supported;
150 extern const hci_cmd_t hci_write_link_policy_settings;
151 extern const hci_cmd_t hci_write_link_supervision_timeout;
152 extern const hci_cmd_t hci_write_local_name;
153 extern const hci_cmd_t hci_write_loopback_mode;
154 extern const hci_cmd_t hci_write_num_broadcast_retransmissions;
155 extern const hci_cmd_t hci_write_page_timeout;
156 extern const hci_cmd_t hci_write_scan_enable;
157 extern const hci_cmd_t hci_write_secure_connections_test_mode;
158 extern const hci_cmd_t hci_write_simple_pairing_debug_mode;
159 extern const hci_cmd_t hci_write_simple_pairing_mode;
160 extern const hci_cmd_t hci_write_synchronous_flow_control_enable;
161 
162 extern const hci_cmd_t hci_le_add_device_to_white_list;
163 extern const hci_cmd_t hci_le_clear_white_list;
164 extern const hci_cmd_t hci_le_connection_update;
165 extern const hci_cmd_t hci_le_create_connection;
166 extern const hci_cmd_t hci_le_create_connection_cancel;
167 extern const hci_cmd_t hci_le_encrypt;
168 extern const hci_cmd_t hci_le_generate_dhkey;
169 extern const hci_cmd_t hci_le_long_term_key_negative_reply;
170 extern const hci_cmd_t hci_le_long_term_key_request_reply;
171 extern const hci_cmd_t hci_le_rand;
172 extern const hci_cmd_t hci_le_read_advertising_channel_tx_power;
173 extern const hci_cmd_t hci_le_read_buffer_size ;
174 extern const hci_cmd_t hci_le_read_channel_map;
175 extern const hci_cmd_t hci_le_read_local_p256_public_key;
176 extern const hci_cmd_t hci_le_read_maximum_data_length;
177 extern const hci_cmd_t hci_le_read_remote_used_features;
178 extern const hci_cmd_t hci_le_read_suggested_default_data_length;
179 extern const hci_cmd_t hci_le_read_supported_features;
180 extern const hci_cmd_t hci_le_read_supported_states;
181 extern const hci_cmd_t hci_le_read_white_list_size;
182 extern const hci_cmd_t hci_le_receiver_test;
183 extern const hci_cmd_t hci_le_remove_device_from_white_list;
184 extern const hci_cmd_t hci_le_set_advertise_enable;
185 extern const hci_cmd_t hci_le_set_advertising_data;
186 extern const hci_cmd_t hci_le_set_advertising_parameters;
187 extern const hci_cmd_t hci_le_set_data_length;
188 extern const hci_cmd_t hci_le_set_event_mask;
189 extern const hci_cmd_t hci_le_set_host_channel_classification;
190 extern const hci_cmd_t hci_le_set_random_address;
191 extern const hci_cmd_t hci_le_set_scan_enable;
192 extern const hci_cmd_t hci_le_set_scan_parameters;
193 extern const hci_cmd_t hci_le_set_scan_response_data;
194 extern const hci_cmd_t hci_le_start_encryption;
195 extern const hci_cmd_t hci_le_test_end;
196 extern const hci_cmd_t hci_le_transmitter_test;
197 extern const hci_cmd_t hci_le_write_suggested_default_data_length;
198 
199 // Broadcom / Cypress specific HCI commands
200 extern const hci_cmd_t hci_bcm_write_sco_pcm_int;
201 
202 /**
203  * construct HCI Command based on template
204  *
205  * Format:
206  *   1,2,3,4: one to four byte value
207  *   H: HCI connection handle
208  *   B: Bluetooth Baseband Address (BD_ADDR)
209  *   D: 8 byte data block
210  *   E: Extended Inquiry Result
211  *   N: Name up to 248 chars, \0 terminated
212  *   P: 16 byte Pairing code
213  *   A: 31 bytes advertising data
214  *   S: Service Record (Data Element Sequence)
215  */
216  uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr);
217 
218 
219 #if defined __cplusplus
220 }
221 #endif
222 
223 #endif // __HCI_CMDS_H
224