xref: /btstack/src/hci.h (revision 1e6aba4769cc9f1f9e6a695a7254eb66be5d4943)
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 
2716833f0aSmatthias.ringwald typedef struct hci_connection {
2806b35ec0Smatthias.ringwald     // linked list - assert: first field
2906b35ec0Smatthias.ringwald     linked_item_t    item;
30c01e9cbdSmatthias.ringwald 
31c01e9cbdSmatthias.ringwald     // remote side
3216833f0aSmatthias.ringwald     bd_addr_t address;
3306b35ec0Smatthias.ringwald 
3406b35ec0Smatthias.ringwald     // module handle
3516833f0aSmatthias.ringwald     hci_con_handle_t con_handle;
36c01e9cbdSmatthias.ringwald 
3706b35ec0Smatthias.ringwald     // errands
38c01e9cbdSmatthias.ringwald     hci_connection_flags_t flags;
3916833f0aSmatthias.ringwald } hci_connection_t;
4016833f0aSmatthias.ringwald 
4106b35ec0Smatthias.ringwald /**
4206b35ec0Smatthias.ringwald  * main data structure
4306b35ec0Smatthias.ringwald  */
4416833f0aSmatthias.ringwald typedef struct {
4506b35ec0Smatthias.ringwald     // transport component with configuration
4616833f0aSmatthias.ringwald     hci_transport_t  * hci_transport;
4711e23e5fSmatthias.ringwald     void             * config;
4811e23e5fSmatthias.ringwald 
4906b35ec0Smatthias.ringwald     // hardware power controller
5006b35ec0Smatthias.ringwald     bt_control_t     * control;
5106b35ec0Smatthias.ringwald 
5206b35ec0Smatthias.ringwald     // list of existing baseband connections
53fe1ed1b8Smatthias.ringwald     linked_list_t     connections;
5416833f0aSmatthias.ringwald 
5506b35ec0Smatthias.ringwald     // single buffer for HCI Command assembly
5606b35ec0Smatthias.ringwald     uint8_t          * hci_cmd_buffer;
5706b35ec0Smatthias.ringwald 
5816833f0aSmatthias.ringwald     /* host to controller flow control */
5916833f0aSmatthias.ringwald     uint8_t  num_cmd_packets;
6016833f0aSmatthias.ringwald     uint8_t  num_acl_packets;
6116833f0aSmatthias.ringwald 
6216833f0aSmatthias.ringwald     /* callback to L2CAP layer */
631cd208adSmatthias.ringwald     void (*event_packet_handler)(uint8_t *packet, uint16_t size);
641cd208adSmatthias.ringwald     void (*acl_packet_handler)  (uint8_t *packet, uint16_t size);
6516833f0aSmatthias.ringwald 
663429f56bSmatthias.ringwald     /* hci state machine */
673429f56bSmatthias.ringwald     HCI_STATE state;
683429f56bSmatthias.ringwald     uint8_t   substate;
693429f56bSmatthias.ringwald     uint8_t   cmds_ready;
703429f56bSmatthias.ringwald 
7116833f0aSmatthias.ringwald } hci_stack_t;
7216833f0aSmatthias.ringwald 
73475c8125Smatthias.ringwald // set up HCI
7411e23e5fSmatthias.ringwald void hci_init(hci_transport_t *transport, void *config, bt_control_t *control);
75475c8125Smatthias.ringwald 
761cd208adSmatthias.ringwald void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, uint16_t size));
7716833f0aSmatthias.ringwald 
781cd208adSmatthias.ringwald void hci_register_acl_packet_handler  (void (*handler)(uint8_t *packet, uint16_t size));
7916833f0aSmatthias.ringwald 
80475c8125Smatthias.ringwald // power control
81475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE mode);
82475c8125Smatthias.ringwald 
833429f56bSmatthias.ringwald /**
843429f56bSmatthias.ringwald  * run the hci daemon loop once
853429f56bSmatthias.ringwald  */
8606b35ec0Smatthias.ringwald void hci_run();
871f504dbdSmatthias.ringwald 
881cd208adSmatthias.ringwald // create and send hci command packets based on a template and a list of parameters
8902ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...);
90d8905019Smatthias.ringwald 
91d8905019Smatthias.ringwald // send complete CMD packet
9249857181Smatthias.ringwald int hci_send_cmd_packet(uint8_t *packet, int size);
93554588a5Smatthias.ringwald 
9443625864Smatthias.ringwald // send ACL packet
9543625864Smatthias.ringwald int hci_send_acl_packet(uint8_t *packet, int size);
9606b35ec0Smatthias.ringwald 
9706b35ec0Smatthias.ringwald //
98*1e6aba47Smatthias.ringwald void hci_emit_state();
99