xref: /btstack/src/hci.h (revision ea6387df266da0720d97951c099ef33e618dbf23)
1 /*
2  *  hci.h
3  *
4  *  Created by Matthias Ringwald on 4/29/09.
5  *
6  */
7 
8 #pragma once
9 
10 #include <stdint.h>
11 #include <stdlib.h>
12 
13 #include "hci_transport.h"
14 
15 
16 // helper for BT little endian format
17 #define READ_BT_16( buffer, pos) (buffer[pos] | (buffer[pos+1] << 8))
18 #define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16))
19 #define READ_BT_32( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16) | (((uint32_t) buffer[pos+3])) << 24)
20 
21 
22 // packet headers
23 #define HCI_CMD_DATA_PKT_HDR	  0x03
24 #define HCI_ACL_DATA_PKT_HDR	  0x04
25 #define HCI_SCO_DATA_PKT_HDR	  0x03
26 #define HCI_EVENT_PKT_HDR         0x02
27 
28 /**
29  * @brief Length of a bluetooth device address.
30  */
31 #define BD_ADDR_LEN 6
32 typedef uint8_t bd_addr_t[BD_ADDR_LEN];
33 
34 
35 /**
36  * @brief The link key type
37  */
38 #define LINK_KEY_LEN 16
39 typedef uint8_t link_key_t[LINK_KEY_LEN];
40 
41 
42 typedef enum {
43     HCI_POWER_OFF = 0,
44     HCI_POWER_ON
45 } HCI_POWER_MODE;
46 
47 typedef struct {
48     uint16_t    opcode;
49     const char *format;
50 } hci_cmd_t;
51 
52 
53 // set up HCI
54 void hci_init(hci_transport_t *transport, void *config);
55 
56 // power control
57 int hci_power_control(HCI_POWER_MODE mode);
58 
59 // run the hci daemon loop
60 void hci_run();
61 
62 //
63 void hexdump(uint8_t *data, int size);
64 
65 // create and send hci command packet based on a template and a list of parameters
66 int hci_send_cmd(hci_cmd_t *cmd, ...);
67 
68 extern hci_cmd_t hci_inquiry;
69 extern hci_cmd_t hci_reset;
70 extern hci_cmd_t hci_create_connection;
71 extern hci_cmd_t hci_host_buffer_size;
72 extern hci_cmd_t hci_write_page_timeout;
73 
74 #define HCI_INQUIRY_LAP 0x9E8B33L  // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC)
75