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 10*ba681a6cSmatthias.ringwald #include "hci_cmds.h" 11*ba681a6cSmatthias.ringwald #include "utils.h" 12*ba681a6cSmatthias.ringwald #include "hci_transport.h" 13*ba681a6cSmatthias.ringwald #include "bt_control.h" 14*ba681a6cSmatthias.ringwald 1593b8dc03Smatthias.ringwald #include <stdint.h> 1602ea9861Smatthias.ringwald #include <stdlib.h> 171cd208adSmatthias.ringwald #include <stdarg.h> 1893b8dc03Smatthias.ringwald 19ea6387dfSmatthias.ringwald 20475c8125Smatthias.ringwald typedef enum { 21475c8125Smatthias.ringwald HCI_POWER_OFF = 0, 22475c8125Smatthias.ringwald HCI_POWER_ON 23475c8125Smatthias.ringwald } HCI_POWER_MODE; 24475c8125Smatthias.ringwald 253429f56bSmatthias.ringwald typedef enum { 263429f56bSmatthias.ringwald HCI_STATE_OFF = 0, 273429f56bSmatthias.ringwald HCI_STATE_INITIALIZING, 283429f56bSmatthias.ringwald HCI_STATE_WORKING, 293429f56bSmatthias.ringwald HCI_STATE_HALTING 303429f56bSmatthias.ringwald } HCI_STATE; 313429f56bSmatthias.ringwald 32c01e9cbdSmatthias.ringwald typedef enum { 33c01e9cbdSmatthias.ringwald SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0, 34c01e9cbdSmatthias.ringwald SEND_PIN_CODE_RESPONSE = 1 << 1 35c01e9cbdSmatthias.ringwald } hci_connection_flags_t; 36c01e9cbdSmatthias.ringwald 3716833f0aSmatthias.ringwald typedef struct hci_connection { 38c01e9cbdSmatthias.ringwald // linked list 3916833f0aSmatthias.ringwald struct hci_connection * next; 40c01e9cbdSmatthias.ringwald 41c01e9cbdSmatthias.ringwald // remote side 4216833f0aSmatthias.ringwald bd_addr_t address; 4316833f0aSmatthias.ringwald hci_con_handle_t con_handle; 44c01e9cbdSmatthias.ringwald 45c01e9cbdSmatthias.ringwald // hci state machine 46c01e9cbdSmatthias.ringwald hci_connection_flags_t flags; 47c01e9cbdSmatthias.ringwald 4816833f0aSmatthias.ringwald } hci_connection_t; 4916833f0aSmatthias.ringwald 50c01e9cbdSmatthias.ringwald 5116833f0aSmatthias.ringwald typedef struct { 5216833f0aSmatthias.ringwald hci_transport_t * hci_transport; 5311e23e5fSmatthias.ringwald bt_control_t * control; 5411e23e5fSmatthias.ringwald void * config; 5511e23e5fSmatthias.ringwald 5616833f0aSmatthias.ringwald uint8_t * hci_cmd_buffer; 5716833f0aSmatthias.ringwald hci_connection_t * connections; 5816833f0aSmatthias.ringwald 5916833f0aSmatthias.ringwald /* host to controller flow control */ 6016833f0aSmatthias.ringwald uint8_t num_cmd_packets; 6116833f0aSmatthias.ringwald uint8_t num_acl_packets; 6216833f0aSmatthias.ringwald 6316833f0aSmatthias.ringwald /* callback to L2CAP layer */ 641cd208adSmatthias.ringwald void (*event_packet_handler)(uint8_t *packet, uint16_t size); 651cd208adSmatthias.ringwald void (*acl_packet_handler) (uint8_t *packet, uint16_t size); 6616833f0aSmatthias.ringwald 673429f56bSmatthias.ringwald /* hci state machine */ 683429f56bSmatthias.ringwald HCI_STATE state; 693429f56bSmatthias.ringwald uint8_t substate; 703429f56bSmatthias.ringwald uint8_t cmds_ready; 713429f56bSmatthias.ringwald 7216833f0aSmatthias.ringwald } hci_stack_t; 7316833f0aSmatthias.ringwald 7402ea9861Smatthias.ringwald 75475c8125Smatthias.ringwald // set up HCI 7611e23e5fSmatthias.ringwald void hci_init(hci_transport_t *transport, void *config, bt_control_t *control); 77475c8125Smatthias.ringwald 781cd208adSmatthias.ringwald void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size)); 7916833f0aSmatthias.ringwald 801cd208adSmatthias.ringwald void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, uint16_t size)); 8116833f0aSmatthias.ringwald 82475c8125Smatthias.ringwald // power control 83475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE mode); 84475c8125Smatthias.ringwald 853429f56bSmatthias.ringwald /** 863429f56bSmatthias.ringwald * run the hci daemon loop once 873429f56bSmatthias.ringwald * 883429f56bSmatthias.ringwald * @return 0 or next timeout 893429f56bSmatthias.ringwald */ 903429f56bSmatthias.ringwald uint32_t hci_run(); 911f504dbdSmatthias.ringwald 921cd208adSmatthias.ringwald // create and send hci command packets based on a template and a list of parameters 9302ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...); 94d8905019Smatthias.ringwald 95d8905019Smatthias.ringwald // send complete CMD packet 9649857181Smatthias.ringwald int hci_send_cmd_packet(uint8_t *packet, int size); 97554588a5Smatthias.ringwald 9843625864Smatthias.ringwald // send ACL packet 9943625864Smatthias.ringwald int hci_send_acl_packet(uint8_t *packet, int size); 100