1 /* 2 * hci.h 3 * 4 * Created by Matthias Ringwald on 4/29/09. 5 * 6 */ 7 8 #pragma once 9 10 #include "hci_cmds.h" 11 #include "utils.h" 12 #include "hci_transport.h" 13 #include "bt_control.h" 14 15 #include <stdint.h> 16 #include <stdlib.h> 17 #include <stdarg.h> 18 19 20 typedef enum { 21 HCI_POWER_OFF = 0, 22 HCI_POWER_ON 23 } HCI_POWER_MODE; 24 25 typedef enum { 26 HCI_STATE_OFF = 0, 27 HCI_STATE_INITIALIZING, 28 HCI_STATE_WORKING, 29 HCI_STATE_HALTING 30 } HCI_STATE; 31 32 typedef enum { 33 SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0, 34 SEND_PIN_CODE_RESPONSE = 1 << 1 35 } hci_connection_flags_t; 36 37 typedef struct hci_connection { 38 // linked list 39 struct hci_connection * next; 40 41 // remote side 42 bd_addr_t address; 43 hci_con_handle_t con_handle; 44 45 // hci state machine 46 hci_connection_flags_t flags; 47 48 } hci_connection_t; 49 50 51 typedef struct { 52 hci_transport_t * hci_transport; 53 bt_control_t * control; 54 void * config; 55 56 uint8_t * hci_cmd_buffer; 57 hci_connection_t * connections; 58 59 /* host to controller flow control */ 60 uint8_t num_cmd_packets; 61 uint8_t num_acl_packets; 62 63 /* callback to L2CAP layer */ 64 void (*event_packet_handler)(uint8_t *packet, uint16_t size); 65 void (*acl_packet_handler) (uint8_t *packet, uint16_t size); 66 67 /* hci state machine */ 68 HCI_STATE state; 69 uint8_t substate; 70 uint8_t cmds_ready; 71 72 } hci_stack_t; 73 74 75 // set up HCI 76 void hci_init(hci_transport_t *transport, void *config, bt_control_t *control); 77 78 void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size)); 79 80 void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, uint16_t size)); 81 82 // power control 83 int hci_power_control(HCI_POWER_MODE mode); 84 85 /** 86 * run the hci daemon loop once 87 * 88 * @return 0 or next timeout 89 */ 90 uint32_t hci_run(); 91 92 // create and send hci command packets based on a template and a list of parameters 93 int hci_send_cmd(hci_cmd_t *cmd, ...); 94 95 // send complete CMD packet 96 int hci_send_cmd_packet(uint8_t *packet, int size); 97 98 // send ACL packet 99 int hci_send_acl_packet(uint8_t *packet, int size); 100