xref: /btstack/src/hci.h (revision d2ec4031ba952131d1d02b296836f73dead6f8fb)
1 /*
2  * Copyright (C) 2009-2012 by Matthias Ringwald
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 MATTHIAS RINGWALD 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 [email protected]
34  *
35  */
36 
37 /*
38  *  hci.h
39  *
40  *  Created by Matthias Ringwald on 4/29/09.
41  *
42  */
43 
44 #ifndef __HCI_H
45 #define __HCI_H
46 
47 #include "btstack-config.h"
48 
49 #include <btstack/hci_cmds.h>
50 #include <btstack/utils.h>
51 #include "hci_transport.h"
52 #include "bt_control.h"
53 #include "remote_device_db.h"
54 
55 #include <stdint.h>
56 #include <stdlib.h>
57 #include <stdarg.h>
58 #include <btstack/linked_list.h>
59 
60 #if defined __cplusplus
61 extern "C" {
62 #endif
63 
64 // packet header sizes
65 #define HCI_CMD_HEADER_SIZE          3
66 #define HCI_ACL_HEADER_SIZE   	     4
67 #define HCI_SCO_HEADER_SIZE  	     3
68 #define HCI_EVENT_HEADER_SIZE        2
69 
70 // packet sizes (max payload)
71 #define HCI_ACL_DM1_SIZE            17
72 #define HCI_ACL_DH1_SIZE            27
73 #define HCI_ACL_2DH1_SIZE           54
74 #define HCI_ACL_3DH1_SIZE           83
75 #define HCI_ACL_DM3_SIZE           121
76 #define HCI_ACL_DH3_SIZE           183
77 #define HCI_ACL_DM5_SIZE           224
78 #define HCI_ACL_DH5_SIZE           339
79 #define HCI_ACL_2DH3_SIZE          367
80 #define HCI_ACL_3DH3_SIZE          552
81 #define HCI_ACL_2DH5_SIZE          679
82 #define HCI_ACL_3DH5_SIZE         1021
83 
84 #define HCI_EVENT_PAYLOAD_SIZE     255
85 #define HCI_CMD_PAYLOAD_SIZE       255
86 
87 // packet buffer sizes
88 // HCI_ACL_PAYLOAD_SIZE is configurable and defined in config.h
89 #define HCI_EVENT_BUFFER_SIZE      (HCI_EVENT_HEADER_SIZE + HCI_EVENT_PAYLOAD_SIZE)
90 #define HCI_CMD_BUFFER_SIZE        (HCI_CMD_HEADER_SIZE   + HCI_CMD_PAYLOAD_SIZE)
91 #define HCI_ACL_BUFFER_SIZE        (HCI_ACL_HEADER_SIZE   + HCI_ACL_PAYLOAD_SIZE)
92 
93 // size of hci buffers, big enough for command, event, or acl packet without H4 packet type
94 // @note cmd buffer is bigger than event buffer
95 #ifdef HCI_PACKET_BUFFER_SIZE
96     #if HCI_PACKET_BUFFER_SIZE < HCI_ACL_BUFFER_SIZE
97         #error HCI_PACKET_BUFFER_SIZE must be equal or larger than HCI_ACL_BUFFER_SIZE
98     #endif
99     #if HCI_PACKET_BUFFER_SIZE < HCI_CMD_BUFFER_SIZE
100         #error HCI_PACKET_BUFFER_SIZE must be equal or larger than HCI_CMD_BUFFER_SIZE
101     #endif
102 #else
103     #if HCI_ACL_BUFFER_SIZE > HCI_CMD_BUFFER_SIZE
104         #define HCI_PACKET_BUFFER_SIZE HCI_ACL_BUFFER_SIZE
105     #else
106         #define HCI_PACKET_BUFFER_SIZE HCI_CMD_BUFFER_SIZE
107     #endif
108 #endif
109 
110 // OGFs
111 #define OGF_LINK_CONTROL          0x01
112 #define OGF_LINK_POLICY           0x02
113 #define OGF_CONTROLLER_BASEBAND   0x03
114 #define OGF_INFORMATIONAL_PARAMETERS 0x04
115 #define OGF_STATUS_PARAMETERS     0x05
116 #define OGF_LE_CONTROLLER 0x08
117 #define OGF_BTSTACK 0x3d
118 #define OGF_VENDOR  0x3f
119 
120 // cmds for BTstack
121 // get state: @returns HCI_STATE
122 #define BTSTACK_GET_STATE                                  0x01
123 
124 // set power mode: @param HCI_POWER_MODE
125 #define BTSTACK_SET_POWER_MODE                             0x02
126 
127 // set capture mode: @param on
128 #define BTSTACK_SET_ACL_CAPTURE_MODE                       0x03
129 
130 // get BTstack version
131 #define BTSTACK_GET_VERSION                                0x04
132 
133 // get system Bluetooth state
134 #define BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED               0x05
135 
136 // set system Bluetooth state
137 #define BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED               0x06
138 
139 // enable inquiry scan for this client
140 #define BTSTACK_SET_DISCOVERABLE                           0x07
141 
142 // set global Bluetooth state
143 #define BTSTACK_SET_BLUETOOTH_ENABLED                      0x08
144 
145 // create l2cap channel: @param bd_addr(48), psm (16)
146 #define L2CAP_CREATE_CHANNEL                               0x20
147 
148 // disconnect l2cap disconnect, @param channel(16), reason(8)
149 #define L2CAP_DISCONNECT                                   0x21
150 
151 // register l2cap service: @param psm(16), mtu (16)
152 #define L2CAP_REGISTER_SERVICE                             0x22
153 
154 // unregister l2cap disconnect, @param psm(16)
155 #define L2CAP_UNREGISTER_SERVICE                           0x23
156 
157 // accept connection @param bd_addr(48), dest cid (16)
158 #define L2CAP_ACCEPT_CONNECTION                            0x24
159 
160 // decline l2cap disconnect,@param bd_addr(48), dest cid (16), reason(8)
161 #define L2CAP_DECLINE_CONNECTION                           0x25
162 
163 // create l2cap channel: @param bd_addr(48), psm (16), mtu (16)
164 #define L2CAP_CREATE_CHANNEL_MTU                           0x26
165 
166 // register SDP Service Record: service record (size)
167 #define SDP_REGISTER_SERVICE_RECORD                        0x30
168 
169 // unregister SDP Service Record
170 #define SDP_UNREGISTER_SERVICE_RECORD                      0x31
171 
172 // Get remote RFCOMM services
173 #define SDP_CLIENT_QUERY_RFCOMM_SERVICES                   0x32
174 
175 // Get remote SDP services
176 #define SDP_CLIENT_QUERY_SERVICES                          0x33
177 
178 // RFCOMM "HCI" Commands
179 #define RFCOMM_CREATE_CHANNEL       0x40
180 #define RFCOMM_DISCONNECT			0x41
181 #define RFCOMM_REGISTER_SERVICE     0x42
182 #define RFCOMM_UNREGISTER_SERVICE   0x43
183 #define RFCOMM_ACCEPT_CONNECTION    0x44
184 #define RFCOMM_DECLINE_CONNECTION   0x45
185 #define RFCOMM_PERSISTENT_CHANNEL   0x46
186 #define RFCOMM_CREATE_CHANNEL_WITH_CREDITS   0x47
187 #define RFCOMM_REGISTER_SERVICE_WITH_CREDITS 0x48
188 #define RFCOMM_GRANT_CREDITS                 0x49
189 
190 // GAP Classic 0x50
191 #define GAP_DISCONNECT              0x50
192 
193 // GAP LE      0x60
194 #define GAP_LE_SCAN_START           0x60
195 #define GAP_LE_SCAN_STOP            0x61
196 #define GAP_LE_CONNECT              0x62
197 #define GAP_LE_CONNECT_CANCEL       0x63
198 #define GAP_LE_SET_SCAN_PARAMETERS  0x64
199 
200 // GATT (Client) 0x70
201 #define GATT_DISCOVER_ALL_PRIMARY_SERVICES                       0x70
202 #define GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16                 0x71
203 #define GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128                0x72
204 #define GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE                  0x73
205 #define GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE                0x74
206 #define GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128     0x75
207 #define GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS                 0x76
208 #define GATT_READ_VALUE_OF_CHARACTERISTIC                        0x77
209 #define GATT_READ_LONG_VALUE_OF_CHARACTERISTIC                   0x78
210 #define GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE      0x79
211 #define GATT_WRITE_VALUE_OF_CHARACTERISTIC                       0x7A
212 #define GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC                  0x7B
213 #define GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC         0x7C
214 #define GATT_READ_CHARACTERISTIC_DESCRIPTOR                      0X7D
215 #define GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR                 0X7E
216 #define GATT_WRITE_CHARACTERISTIC_DESCRIPTOR                     0X7F
217 #define GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR                0X80
218 #define GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION           0X81
219 
220 //
221 #define IS_COMMAND(packet, command) (READ_BT_16(packet,0) == command.opcode)
222 
223 // data: event(8)
224 #define DAEMON_EVENT_CONNECTION_OPENED                     0x50
225 
226 // data: event(8)
227 #define DAEMON_EVENT_CONNECTION_CLOSED                     0x51
228 
229 // data: event(8), nr_connections(8)
230 #define DAEMON_NR_CONNECTIONS_CHANGED                      0x52
231 
232 // data: event(8)
233 #define DAEMON_EVENT_NEW_RFCOMM_CREDITS                    0x53
234 
235 // data: event(8)
236 #define DAEMON_EVENT_HCI_PACKET_SENT                       0x54
237 
238 /**
239  * LE connection parameter update state
240  */
241 
242 typedef enum {
243     CON_PARAMETER_UPDATE_NONE,
244     CON_PARAMETER_UPDATE_SEND_RESPONSE,
245     CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS,
246     CON_PARAMETER_UPDATE_DENY
247 } le_con_parameter_update_state_t;
248 
249 typedef struct le_connection_parameter_range{
250     uint16_t le_conn_interval_min;
251     uint16_t le_conn_interval_max;
252     uint16_t le_conn_latency_min;
253     uint16_t le_conn_latency_max;
254     uint16_t le_supervision_timeout_min;
255     uint16_t le_supervision_timeout_max;
256 } le_connection_parameter_range_t;
257 
258 // Authentication flags
259 typedef enum {
260     AUTH_FLAGS_NONE                = 0x0000,
261     RECV_LINK_KEY_REQUEST          = 0x0001,
262     HANDLE_LINK_KEY_REQUEST        = 0x0002,
263     SENT_LINK_KEY_REPLY            = 0x0004,
264     SENT_LINK_KEY_NEGATIVE_REQUEST = 0x0008,
265     RECV_LINK_KEY_NOTIFICATION     = 0x0010,
266     DENY_PIN_CODE_REQUEST          = 0x0040,
267     RECV_IO_CAPABILITIES_REQUEST   = 0x0080,
268     SEND_IO_CAPABILITIES_REPLY     = 0x0100,
269     SEND_USER_CONFIRM_REPLY        = 0x0200,
270     SEND_USER_PASSKEY_REPLY        = 0x0400,
271 
272     // pairing status
273     LEGACY_PAIRING_ACTIVE          = 0x2000,
274     SSP_PAIRING_ACTIVE             = 0x4000,
275 
276     // connection status
277     CONNECTION_ENCRYPTED           = 0x8000,
278 } hci_authentication_flags_t;
279 
280 /**
281  * Connection State
282  */
283 typedef enum {
284     SEND_CREATE_CONNECTION = 0,
285     SENT_CREATE_CONNECTION,
286     SEND_CANCEL_CONNECTION,
287     SENT_CANCEL_CONNECTION,
288     RECEIVED_CONNECTION_REQUEST,
289     ACCEPTED_CONNECTION_REQUEST,
290     REJECTED_CONNECTION_REQUEST,
291     OPEN,
292     SEND_DISCONNECT,
293     SENT_DISCONNECT
294 } CONNECTION_STATE;
295 
296 // bonding flags
297 enum {
298     BONDING_REQUEST_REMOTE_FEATURES   = 0x01,
299     BONDING_RECEIVED_REMOTE_FEATURES  = 0x02,
300     BONDING_REMOTE_SUPPORTS_SSP       = 0x04,
301     BONDING_DISCONNECT_SECURITY_BLOCK = 0x08,
302     BONDING_DISCONNECT_DEDICATED_DONE = 0x10,
303     BONDING_SEND_AUTHENTICATE_REQUEST = 0x20,
304     BONDING_SEND_ENCRYPTION_REQUEST   = 0x40,
305     BONDING_DEDICATED                 = 0x80,
306     BONDING_EMIT_COMPLETE_ON_DISCONNECT = 0x100
307 };
308 
309 typedef enum {
310     BLUETOOTH_OFF = 1,
311     BLUETOOTH_ON,
312     BLUETOOTH_ACTIVE
313 } BLUETOOTH_STATE;
314 
315 // le central scanning state
316 typedef enum {
317     LE_SCAN_IDLE,
318     LE_START_SCAN,
319     LE_SCANNING,
320     LE_STOP_SCAN,
321 } le_scanning_state_t;
322 
323 
324 typedef struct {
325     // linked list - assert: first field
326     linked_item_t    item;
327 
328     // remote side
329     bd_addr_t address;
330 
331     // module handle
332     hci_con_handle_t con_handle;
333 
334     // le public, le random, classic
335     bd_addr_type_t address_type;
336 
337     // connection state
338     CONNECTION_STATE state;
339 
340     // bonding
341     uint16_t bonding_flags;
342     uint8_t  bonding_status;
343     // requested security level
344     gap_security_level_t requested_security_level;
345 
346     //
347     link_key_type_t link_key_type;
348 
349     // errands
350     uint32_t authentication_flags;
351 
352     timer_source_t timeout;
353 
354 #ifdef HAVE_TIME
355     // timer
356     struct timeval timestamp;
357 #endif
358 #ifdef HAVE_TICK
359     uint32_t timestamp; // timeout in system ticks
360 #endif
361 
362     // ACL packet recombination - ACL Header + ACL payload
363     uint8_t  acl_recombination_buffer[4 + HCI_ACL_BUFFER_SIZE];
364     uint16_t acl_recombination_pos;
365     uint16_t acl_recombination_length;
366 
367     // number ACL packets sent to controller
368     uint8_t num_acl_packets_sent;
369 
370     // connection parameter update
371     le_con_parameter_update_state_t le_con_parameter_update_state;
372     uint16_t le_conn_interval_min;
373     uint16_t le_conn_interval_max;
374     uint16_t le_conn_latency;
375     uint16_t le_supervision_timeout;
376     uint16_t le_update_con_parameter_response;
377 } hci_connection_t;
378 
379 
380 /**
381  * main data structure
382  */
383 typedef struct {
384     // transport component with configuration
385     hci_transport_t  * hci_transport;
386     void             * config;
387 
388     // bsic configuration
389     const char         * local_name;
390     uint32_t           class_of_device;
391     bd_addr_t          local_bd_addr;
392     uint8_t            ssp_enable;
393     uint8_t            ssp_io_capability;
394     uint8_t            ssp_authentication_requirement;
395     uint8_t            ssp_auto_accept;
396 
397     // hardware power controller
398     bt_control_t     * control;
399 
400     // list of existing baseband connections
401     linked_list_t     connections;
402 
403     // single buffer for HCI packet assembly
404     uint8_t   hci_packet_buffer[HCI_PACKET_BUFFER_SIZE]; // opcode (16), len(8)
405     uint8_t   hci_packet_buffer_reserved;
406     uint16_t  acl_fragmentation_pos;
407     uint16_t  acl_fragmentation_total_size;
408 
409     /* host to controller flow control */
410     uint8_t  num_cmd_packets;
411     // uint8_t  total_num_cmd_packets;
412     uint8_t  acl_packets_total_num;
413     uint16_t acl_data_packet_length;
414     uint8_t  le_acl_packets_total_num;
415     uint16_t le_data_packets_length;
416 
417     /* local supported features */
418     uint8_t local_supported_features[8];
419 
420     // usable packet types given acl_data_packet_length and HCI_ACL_BUFFER_SIZE
421     uint16_t packet_types;
422 
423     /* callback to L2CAP layer */
424     void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
425 
426     /* remote device db */
427     remote_device_db_t const*remote_device_db;
428 
429     /* hci state machine */
430     HCI_STATE state;
431     uint8_t   substate;
432     uint8_t   cmds_ready;
433 
434     uint16_t  last_cmd_opcode;
435 
436     uint8_t   discoverable;
437     uint8_t   connectable;
438     uint8_t   bondable;
439 
440     /* buffer for scan enable cmd - 0xff no change */
441     uint8_t   new_scan_enable_value;
442 
443     // buffer for single connection decline
444     uint8_t   decline_reason;
445     bd_addr_t decline_addr;
446 
447     uint8_t   adv_addr_type;
448     bd_addr_t adv_address;
449 
450     le_scanning_state_t le_scanning_state;
451 
452     // buffer for le scan type command - 0xff not set
453     uint8_t  le_scan_type;
454     uint16_t le_scan_interval;
455     uint16_t le_scan_window;
456 
457     le_connection_parameter_range_t le_connection_parameter_range;
458 } hci_stack_t;
459 
460 /**
461  * set connection iterator
462  */
463 void hci_connections_get_iterator(linked_list_iterator_t *it);
464 
465 le_connection_parameter_range_t gap_le_get_connection_parameter_range();
466 void gap_le_set_connection_parameter_range(le_connection_parameter_range_t range);
467 
468 // *************** le client start
469 
470 le_command_status_t le_central_start_scan(void);
471 le_command_status_t le_central_stop_scan(void);
472 le_command_status_t le_central_connect(bd_addr_t * addr, bd_addr_type_t addr_type);
473 le_command_status_t le_central_connect_cancel(void);
474 le_command_status_t gap_disconnect(hci_con_handle_t handle);
475 void le_central_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window);
476 
477 // *************** le client end
478 
479 // create and send hci command packets based on a template and a list of parameters
480 uint16_t hci_create_cmd(uint8_t *hci_cmd_buffer, hci_cmd_t *cmd, ...);
481 uint16_t hci_create_cmd_internal(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr);
482 
483 void hci_connectable_control(uint8_t enable);
484 void hci_close(void);
485 
486 /**
487  * run the hci control loop once
488  */
489 void hci_run(void);
490 
491 // send complete CMD packet
492 int hci_send_cmd_packet(uint8_t *packet, int size);
493 
494 // send ACL packet prepared in hci packet buffer
495 int hci_send_acl_packet_buffer(int size);
496 
497 // new functions replacing hci_can_send_packet_now[_using_packet_buffer]
498 int hci_can_send_command_packet_now(void);
499 int hci_can_send_acl_packet_now(hci_con_handle_t con_handle);
500 int hci_can_send_prepared_acl_packet_now(hci_con_handle_t con_handle);
501 
502 // non-blocking UART driver needs
503 // @deprecated use hci_can_send_X_now instead
504 int hci_can_send_packet_now(uint8_t packet_type);
505 
506 // same as hci_can_send_packet_now, but also checks if packet buffer is free for use
507 // @deprecated use hci_can_send_X_now instead
508 int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type);
509 
510 // reserves outgoing packet buffer. @returns 1 if successful
511 int  hci_reserve_packet_buffer(void);
512 void hci_release_packet_buffer(void);
513 
514 // used for internal checks in l2cap[-le].c
515 int hci_is_packet_buffer_reserved(void);
516 
517 // get point to packet buffer
518 uint8_t* hci_get_outgoing_packet_buffer(void);
519 
520 bd_addr_t * hci_local_bd_addr(void);
521 hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle);
522 hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t *addr, bd_addr_type_t addr_type);
523 int hci_is_le_connection(hci_connection_t * connection);
524 uint8_t  hci_number_outgoing_packets(hci_con_handle_t handle);
525 uint8_t  hci_number_free_acl_slots_for_handle(hci_con_handle_t con_handle);
526 int      hci_authentication_active_for_handle(hci_con_handle_t handle);
527 uint16_t hci_max_acl_data_packet_length(void);
528 uint16_t hci_max_acl_le_data_packet_length(void);
529 uint16_t hci_usable_acl_packet_types(void);
530 int      hci_non_flushable_packet_boundary_flag_supported(void);
531 
532 void hci_disconnect_all(void);
533 
534 void hci_emit_state(void);
535 void hci_emit_connection_complete(hci_connection_t *conn, uint8_t status);
536 void hci_emit_l2cap_check_timeout(hci_connection_t *conn);
537 void hci_emit_disconnection_complete(uint16_t handle, uint8_t reason);
538 void hci_emit_nr_connections_changed(void);
539 void hci_emit_hci_open_failed(void);
540 void hci_emit_btstack_version(void);
541 void hci_emit_system_bluetooth_enabled(uint8_t enabled);
542 void hci_emit_remote_name_cached(bd_addr_t *addr, device_name_t *name);
543 void hci_emit_discoverable_enabled(uint8_t enabled);
544 void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level);
545 void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status);
546 
547 // query if remote side supports SSP
548 // query if the local side supports SSP
549 int hci_local_ssp_activated(void);
550 
551 // query if the remote side supports SSP
552 int hci_remote_ssp_supported(hci_con_handle_t con_handle);
553 
554 // query if both sides support SSP
555 int hci_ssp_supported_on_both_sides(hci_con_handle_t handle);
556 
557 // disable automatic l2cap disconnect for testing
558 void hci_disable_l2cap_timeout_check(void);
559 
560 // disconnect because of security block
561 void hci_disconnect_security_block(hci_con_handle_t con_handle);
562 
563 /** Embedded API **/
564 
565 // Set up HCI. Needs to be called before any other function
566 void hci_init(hci_transport_t *transport, void *config, bt_control_t *control, remote_device_db_t const* remote_device_db);
567 
568 // Set class of device that will be set during Bluetooth init
569 void hci_set_class_of_device(uint32_t class_of_device);
570 
571 // Registers a packet handler. Used if L2CAP is not used (rarely).
572 void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
573 
574 // Requests the change of BTstack power mode.
575 int  hci_power_control(HCI_POWER_MODE mode);
576 
577 // Allows to control if device is discoverable. OFF by default.
578 void hci_discoverable_control(uint8_t enable);
579 
580 // Creates and sends HCI command packets based on a template and
581 // a list of parameters. Will return error if outgoing data buffer
582 // is occupied.
583 int hci_send_cmd(const hci_cmd_t *cmd, ...);
584 
585 // Deletes link key for remote device with baseband address.
586 void hci_drop_link_key_for_bd_addr(bd_addr_t *addr);
587 
588 // Configure Secure Simple Pairing
589 
590 // enable will enable SSP during init
591 void hci_ssp_set_enable(int enable);
592 
593 // if set, BTstack will respond to io capability request using authentication requirement
594 void hci_ssp_set_io_capability(int ssp_io_capability);
595 void hci_ssp_set_authentication_requirement(int authentication_requirement);
596 
597 // if set, BTstack will confirm a numberic comparion and enter '000000' if requested
598 void hci_ssp_set_auto_accept(int auto_accept);
599 
600 // get addr type and address used in advertisement packets
601 void hci_le_advertisement_address(uint8_t * addr_type, bd_addr_t * addr);
602 
603 
604 #if defined __cplusplus
605 }
606 #endif
607 
608 #endif // __HCI_H
609