11f504dbdSmatthias.ringwald /* 21f504dbdSmatthias.ringwald * hci.h 31f504dbdSmatthias.ringwald * 41f504dbdSmatthias.ringwald * Created by Matthias Ringwald on 4/29/09. 51f504dbdSmatthias.ringwald * 61f504dbdSmatthias.ringwald */ 71f504dbdSmatthias.ringwald 81f504dbdSmatthias.ringwald #pragma once 91f504dbdSmatthias.ringwald 1093b8dc03Smatthias.ringwald #include <stdint.h> 1102ea9861Smatthias.ringwald #include <stdlib.h> 1293b8dc03Smatthias.ringwald 131f504dbdSmatthias.ringwald #include "hci_transport.h" 141f504dbdSmatthias.ringwald 15*ea6387dfSmatthias.ringwald 16*ea6387dfSmatthias.ringwald // helper for BT little endian format 17*ea6387dfSmatthias.ringwald #define READ_BT_16( buffer, pos) (buffer[pos] | (buffer[pos+1] << 8)) 18*ea6387dfSmatthias.ringwald #define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16)) 19*ea6387dfSmatthias.ringwald #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*ea6387dfSmatthias.ringwald 21*ea6387dfSmatthias.ringwald 22*ea6387dfSmatthias.ringwald // packet headers 23*ea6387dfSmatthias.ringwald #define HCI_CMD_DATA_PKT_HDR 0x03 24*ea6387dfSmatthias.ringwald #define HCI_ACL_DATA_PKT_HDR 0x04 25*ea6387dfSmatthias.ringwald #define HCI_SCO_DATA_PKT_HDR 0x03 26*ea6387dfSmatthias.ringwald #define HCI_EVENT_PKT_HDR 0x02 27*ea6387dfSmatthias.ringwald 28*ea6387dfSmatthias.ringwald /** 29*ea6387dfSmatthias.ringwald * @brief Length of a bluetooth device address. 30*ea6387dfSmatthias.ringwald */ 31*ea6387dfSmatthias.ringwald #define BD_ADDR_LEN 6 32*ea6387dfSmatthias.ringwald typedef uint8_t bd_addr_t[BD_ADDR_LEN]; 33*ea6387dfSmatthias.ringwald 34*ea6387dfSmatthias.ringwald 35*ea6387dfSmatthias.ringwald /** 36*ea6387dfSmatthias.ringwald * @brief The link key type 37*ea6387dfSmatthias.ringwald */ 38*ea6387dfSmatthias.ringwald #define LINK_KEY_LEN 16 39*ea6387dfSmatthias.ringwald typedef uint8_t link_key_t[LINK_KEY_LEN]; 40*ea6387dfSmatthias.ringwald 41*ea6387dfSmatthias.ringwald 42475c8125Smatthias.ringwald typedef enum { 43475c8125Smatthias.ringwald HCI_POWER_OFF = 0, 44475c8125Smatthias.ringwald HCI_POWER_ON 45475c8125Smatthias.ringwald } HCI_POWER_MODE; 46475c8125Smatthias.ringwald 4793b8dc03Smatthias.ringwald typedef struct { 480a974e0cSmatthias.ringwald uint16_t opcode; 4993b8dc03Smatthias.ringwald const char *format; 5093b8dc03Smatthias.ringwald } hci_cmd_t; 5193b8dc03Smatthias.ringwald 5202ea9861Smatthias.ringwald 53475c8125Smatthias.ringwald // set up HCI 54475c8125Smatthias.ringwald void hci_init(hci_transport_t *transport, void *config); 55475c8125Smatthias.ringwald 56475c8125Smatthias.ringwald // power control 57475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE mode); 58475c8125Smatthias.ringwald 591f504dbdSmatthias.ringwald // run the hci daemon loop 60475c8125Smatthias.ringwald void hci_run(); 611f504dbdSmatthias.ringwald 62554588a5Smatthias.ringwald // 63554588a5Smatthias.ringwald void hexdump(uint8_t *data, int size); 64554588a5Smatthias.ringwald 6502ea9861Smatthias.ringwald // create and send hci command packet based on a template and a list of parameters 6602ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...); 67554588a5Smatthias.ringwald 6893b8dc03Smatthias.ringwald extern hci_cmd_t hci_inquiry; 6993b8dc03Smatthias.ringwald extern hci_cmd_t hci_reset; 7002ea9861Smatthias.ringwald extern hci_cmd_t hci_create_connection; 7102ea9861Smatthias.ringwald extern hci_cmd_t hci_host_buffer_size; 7202ea9861Smatthias.ringwald extern hci_cmd_t hci_write_page_timeout; 7393b8dc03Smatthias.ringwald 7493b8dc03Smatthias.ringwald #define HCI_INQUIRY_LAP 0x9E8B33L // 0x9E8B33: General/Unlimited Inquiry Access Code (GIAC) 75