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 10ba681a6cSmatthias.ringwald #include "hci_cmds.h" 11ba681a6cSmatthias.ringwald #include "utils.h" 12ba681a6cSmatthias.ringwald #include "hci_transport.h" 13ba681a6cSmatthias.ringwald #include "bt_control.h" 14ba681a6cSmatthias.ringwald 1593b8dc03Smatthias.ringwald #include <stdint.h> 1602ea9861Smatthias.ringwald #include <stdlib.h> 171cd208adSmatthias.ringwald #include <stdarg.h> 1893b8dc03Smatthias.ringwald 19*06b35ec0Smatthias.ringwald /** 20*06b35ec0Smatthias.ringwald * Hardware state of Bluetooth controller 21*06b35ec0Smatthias.ringwald */ 22475c8125Smatthias.ringwald typedef enum { 23475c8125Smatthias.ringwald HCI_POWER_OFF = 0, 24475c8125Smatthias.ringwald HCI_POWER_ON 25475c8125Smatthias.ringwald } HCI_POWER_MODE; 26475c8125Smatthias.ringwald 27*06b35ec0Smatthias.ringwald /** 28*06b35ec0Smatthias.ringwald * State of BTstack 29*06b35ec0Smatthias.ringwald */ 303429f56bSmatthias.ringwald typedef enum { 313429f56bSmatthias.ringwald HCI_STATE_OFF = 0, 323429f56bSmatthias.ringwald HCI_STATE_INITIALIZING, 333429f56bSmatthias.ringwald HCI_STATE_WORKING, 343429f56bSmatthias.ringwald HCI_STATE_HALTING 353429f56bSmatthias.ringwald } HCI_STATE; 363429f56bSmatthias.ringwald 37*06b35ec0Smatthias.ringwald /** 38*06b35ec0Smatthias.ringwald * Connection State 39*06b35ec0Smatthias.ringwald */ 40c01e9cbdSmatthias.ringwald typedef enum { 41c01e9cbdSmatthias.ringwald SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0, 42c01e9cbdSmatthias.ringwald SEND_PIN_CODE_RESPONSE = 1 << 1 43c01e9cbdSmatthias.ringwald } hci_connection_flags_t; 44c01e9cbdSmatthias.ringwald 4516833f0aSmatthias.ringwald typedef struct hci_connection { 46*06b35ec0Smatthias.ringwald // linked list - assert: first field 47*06b35ec0Smatthias.ringwald linked_item_t item; 48c01e9cbdSmatthias.ringwald 49c01e9cbdSmatthias.ringwald // remote side 5016833f0aSmatthias.ringwald bd_addr_t address; 51*06b35ec0Smatthias.ringwald 52*06b35ec0Smatthias.ringwald // module handle 5316833f0aSmatthias.ringwald hci_con_handle_t con_handle; 54c01e9cbdSmatthias.ringwald 55*06b35ec0Smatthias.ringwald // errands 56c01e9cbdSmatthias.ringwald hci_connection_flags_t flags; 5716833f0aSmatthias.ringwald } hci_connection_t; 5816833f0aSmatthias.ringwald 59*06b35ec0Smatthias.ringwald /** 60*06b35ec0Smatthias.ringwald * main data structure 61*06b35ec0Smatthias.ringwald */ 6216833f0aSmatthias.ringwald typedef struct { 63*06b35ec0Smatthias.ringwald // transport component with configuration 6416833f0aSmatthias.ringwald hci_transport_t * hci_transport; 6511e23e5fSmatthias.ringwald void * config; 6611e23e5fSmatthias.ringwald 67*06b35ec0Smatthias.ringwald // hardware power controller 68*06b35ec0Smatthias.ringwald bt_control_t * control; 69*06b35ec0Smatthias.ringwald 70*06b35ec0Smatthias.ringwald // list of existing baseband connections 7116833f0aSmatthias.ringwald hci_connection_t * connections; 7216833f0aSmatthias.ringwald 73*06b35ec0Smatthias.ringwald // single buffer for HCI Command assembly 74*06b35ec0Smatthias.ringwald uint8_t * hci_cmd_buffer; 75*06b35ec0Smatthias.ringwald 7616833f0aSmatthias.ringwald /* host to controller flow control */ 7716833f0aSmatthias.ringwald uint8_t num_cmd_packets; 7816833f0aSmatthias.ringwald uint8_t num_acl_packets; 7916833f0aSmatthias.ringwald 8016833f0aSmatthias.ringwald /* callback to L2CAP layer */ 811cd208adSmatthias.ringwald void (*event_packet_handler)(uint8_t *packet, uint16_t size); 821cd208adSmatthias.ringwald void (*acl_packet_handler) (uint8_t *packet, uint16_t size); 8316833f0aSmatthias.ringwald 843429f56bSmatthias.ringwald /* hci state machine */ 853429f56bSmatthias.ringwald HCI_STATE state; 863429f56bSmatthias.ringwald uint8_t substate; 873429f56bSmatthias.ringwald uint8_t cmds_ready; 883429f56bSmatthias.ringwald 8916833f0aSmatthias.ringwald } hci_stack_t; 9016833f0aSmatthias.ringwald 91475c8125Smatthias.ringwald // set up HCI 9211e23e5fSmatthias.ringwald void hci_init(hci_transport_t *transport, void *config, bt_control_t *control); 93475c8125Smatthias.ringwald 941cd208adSmatthias.ringwald void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size)); 9516833f0aSmatthias.ringwald 961cd208adSmatthias.ringwald void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, uint16_t size)); 9716833f0aSmatthias.ringwald 98475c8125Smatthias.ringwald // power control 99475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE mode); 100475c8125Smatthias.ringwald 1013429f56bSmatthias.ringwald /** 1023429f56bSmatthias.ringwald * run the hci daemon loop once 1033429f56bSmatthias.ringwald */ 104*06b35ec0Smatthias.ringwald void hci_run(); 1051f504dbdSmatthias.ringwald 1061cd208adSmatthias.ringwald // create and send hci command packets based on a template and a list of parameters 10702ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...); 108d8905019Smatthias.ringwald 109d8905019Smatthias.ringwald // send complete CMD packet 11049857181Smatthias.ringwald int hci_send_cmd_packet(uint8_t *packet, int size); 111554588a5Smatthias.ringwald 11243625864Smatthias.ringwald // send ACL packet 11343625864Smatthias.ringwald int hci_send_acl_packet(uint8_t *packet, int size); 114*06b35ec0Smatthias.ringwald 115*06b35ec0Smatthias.ringwald //