1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef _HCI_LAYER_H_
20 #define _HCI_LAYER_H_
21 
22 #include "stack/bt_types.h"
23 #include "osi/allocator.h"
24 #include "osi/osi.h"
25 #include "osi/future.h"
26 #include "osi/thread.h"
27 
28 ///// LEGACY DEFINITIONS /////
29 
30 /* Message event mask across Host/Controller lib and stack */
31 #define MSG_EVT_MASK                    0xFF00 /* eq. BT_EVT_MASK */
32 #define MSG_SUB_EVT_MASK                0x00FF /* eq. BT_SUB_EVT_MASK */
33 
34 /* Message event ID passed from Host/Controller lib to stack */
35 #define MSG_HC_TO_STACK_HCI_ERR        0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */
36 #define MSG_HC_TO_STACK_HCI_ACL        0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */
37 #define MSG_HC_TO_STACK_HCI_SCO        0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */
38 #define MSG_HC_TO_STACK_HCI_EVT        0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */
39 #define MSG_HC_TO_STACK_L2C_SEG_XMIT   0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */
40 
41 /* Message event ID passed from stack to vendor lib */
42 #define MSG_STACK_TO_HC_HCI_ACL        0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
43 #define MSG_STACK_TO_HC_HCI_SCO        0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
44 #define MSG_STACK_TO_HC_HCI_CMD        0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
45 
46 /* Local Bluetooth Controller ID for BR/EDR */
47 #define LOCAL_BR_EDR_CONTROLLER_ID      0
48 
49 ///// END LEGACY DEFINITIONS /////
50 
51 typedef struct hci_hal_t hci_hal_t;
52 //typedef struct btsnoop_t btsnoop_t;
53 typedef struct controller_t controller_t;
54 //typedef struct hci_inject_t hci_inject_t;
55 typedef struct packet_fragmenter_t packet_fragmenter_t;
56 //typedef struct vendor_t vendor_t;
57 //typedef struct low_power_manager_t low_power_manager_t;
58 
59 //typedef unsigned char * bdaddr_t;
60 typedef uint16_t command_opcode_t;
61 
62 /*
63 typedef enum {
64   LPM_DISABLE,
65   LPM_ENABLE,
66   LPM_WAKE_ASSERT,
67   LPM_WAKE_DEASSERT
68 } low_power_command_t;
69 */
70 
71 typedef void (*command_complete_cb)(BT_HDR *response, void *context);
72 typedef void (*command_status_cb)(uint8_t status, BT_HDR *command, void *context);
73 
74 typedef struct hci_t {
75     // Send a low power command, if supported and the low power manager is enabled.
76     //void (*send_low_power_command)(low_power_command_t command);
77 
78     // Do the postload sequence (call after the rest of the BT stack initializes).
79     void (*do_postload)(void);
80 
81     // Send a command through the HCI layer
82     void (*transmit_command)(
83         BT_HDR *command,
84         command_complete_cb complete_callback,
85         command_status_cb status_cb,
86         void *context
87     );
88 
89     future_t *(*transmit_command_futured)(BT_HDR *command);
90 
91     // Send some data downward through the HCI layer
92     void (*transmit_downward)(uint16_t type, void *data);
93 } hci_t;
94 
95 const hci_t *hci_layer_get_interface(void);
96 
97 int hci_start_up(void);
98 void hci_shut_down(void);
99 
100 bool hci_host_task_post(uint32_t timeout);
101 
102 #endif /* _HCI_LAYER_H_ */
103