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 1906b35ec0Smatthias.ringwald /** 2006b35ec0Smatthias.ringwald * Connection State 2106b35ec0Smatthias.ringwald */ 22c01e9cbdSmatthias.ringwald typedef enum { 23c01e9cbdSmatthias.ringwald SEND_NEGATIVE_LINK_KEY_REQUEST = 1 << 0, 24c01e9cbdSmatthias.ringwald SEND_PIN_CODE_RESPONSE = 1 << 1 25c01e9cbdSmatthias.ringwald } hci_connection_flags_t; 26c01e9cbdSmatthias.ringwald 27*c8e4258aSmatthias.ringwald typedef enum { 28*c8e4258aSmatthias.ringwald SENT_CREATE_CONNECTION = 1, 29*c8e4258aSmatthias.ringwald RECEIVED_CONNECTION_REQUEST, 30*c8e4258aSmatthias.ringwald ACCEPTED_CONNECTION_REQUEST, 31*c8e4258aSmatthias.ringwald REJECTED_CONNECTION_REQUEST, 32*c8e4258aSmatthias.ringwald OPEN, 33*c8e4258aSmatthias.ringwald SENT_DISCONNECT 34*c8e4258aSmatthias.ringwald } CONNECTION_STATE; 35*c8e4258aSmatthias.ringwald 36*c8e4258aSmatthias.ringwald typedef struct { 3706b35ec0Smatthias.ringwald // linked list - assert: first field 3806b35ec0Smatthias.ringwald linked_item_t item; 39c01e9cbdSmatthias.ringwald 40c01e9cbdSmatthias.ringwald // remote side 4116833f0aSmatthias.ringwald bd_addr_t address; 4206b35ec0Smatthias.ringwald 4306b35ec0Smatthias.ringwald // module handle 4416833f0aSmatthias.ringwald hci_con_handle_t con_handle; 45c01e9cbdSmatthias.ringwald 46*c8e4258aSmatthias.ringwald // state 47*c8e4258aSmatthias.ringwald CONNECTION_STATE state; 48*c8e4258aSmatthias.ringwald 4906b35ec0Smatthias.ringwald // errands 50c01e9cbdSmatthias.ringwald hci_connection_flags_t flags; 51*c8e4258aSmatthias.ringwald 5216833f0aSmatthias.ringwald } hci_connection_t; 5316833f0aSmatthias.ringwald 5406b35ec0Smatthias.ringwald /** 5506b35ec0Smatthias.ringwald * main data structure 5606b35ec0Smatthias.ringwald */ 5716833f0aSmatthias.ringwald typedef struct { 5806b35ec0Smatthias.ringwald // transport component with configuration 5916833f0aSmatthias.ringwald hci_transport_t * hci_transport; 6011e23e5fSmatthias.ringwald void * config; 6111e23e5fSmatthias.ringwald 6206b35ec0Smatthias.ringwald // hardware power controller 6306b35ec0Smatthias.ringwald bt_control_t * control; 6406b35ec0Smatthias.ringwald 6506b35ec0Smatthias.ringwald // list of existing baseband connections 66fe1ed1b8Smatthias.ringwald linked_list_t connections; 6716833f0aSmatthias.ringwald 6806b35ec0Smatthias.ringwald // single buffer for HCI Command assembly 6906b35ec0Smatthias.ringwald uint8_t * hci_cmd_buffer; 7006b35ec0Smatthias.ringwald 7116833f0aSmatthias.ringwald /* host to controller flow control */ 7216833f0aSmatthias.ringwald uint8_t num_cmd_packets; 7316833f0aSmatthias.ringwald uint8_t num_acl_packets; 7416833f0aSmatthias.ringwald 7516833f0aSmatthias.ringwald /* callback to L2CAP layer */ 761cd208adSmatthias.ringwald void (*event_packet_handler)(uint8_t *packet, uint16_t size); 771cd208adSmatthias.ringwald void (*acl_packet_handler) (uint8_t *packet, uint16_t size); 7816833f0aSmatthias.ringwald 793429f56bSmatthias.ringwald /* hci state machine */ 803429f56bSmatthias.ringwald HCI_STATE state; 813429f56bSmatthias.ringwald uint8_t substate; 823429f56bSmatthias.ringwald uint8_t cmds_ready; 833429f56bSmatthias.ringwald 8416833f0aSmatthias.ringwald } hci_stack_t; 8516833f0aSmatthias.ringwald 86475c8125Smatthias.ringwald // set up HCI 8711e23e5fSmatthias.ringwald void hci_init(hci_transport_t *transport, void *config, bt_control_t *control); 88475c8125Smatthias.ringwald 891cd208adSmatthias.ringwald void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size)); 9016833f0aSmatthias.ringwald 911cd208adSmatthias.ringwald void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, uint16_t size)); 9216833f0aSmatthias.ringwald 93475c8125Smatthias.ringwald // power control 94475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE mode); 95475c8125Smatthias.ringwald 963429f56bSmatthias.ringwald /** 97*c8e4258aSmatthias.ringwald * run the hci control loop once 983429f56bSmatthias.ringwald */ 9906b35ec0Smatthias.ringwald void hci_run(); 1001f504dbdSmatthias.ringwald 1011cd208adSmatthias.ringwald // create and send hci command packets based on a template and a list of parameters 10202ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...); 103d8905019Smatthias.ringwald 104d8905019Smatthias.ringwald // send complete CMD packet 10549857181Smatthias.ringwald int hci_send_cmd_packet(uint8_t *packet, int size); 106554588a5Smatthias.ringwald 10743625864Smatthias.ringwald // send ACL packet 10843625864Smatthias.ringwald int hci_send_acl_packet(uint8_t *packet, int size); 10906b35ec0Smatthias.ringwald 11006b35ec0Smatthias.ringwald // 1111e6aba47Smatthias.ringwald void hci_emit_state(); 112*c8e4258aSmatthias.ringwald void hci_emit_connection_complete(hci_connection_t *conn); 113