• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 #pragma once
20 
21 #include <base/callback.h>
22 #include <base/location.h>
23 #include <stdbool.h>
24 
25 #include "bt_types.h"
26 #include "osi/include/allocator.h"
27 #include "osi/include/fixed_queue.h"
28 #include "osi/include/future.h"
29 #include "osi/include/osi.h"
30 
31 static const char HCI_MODULE[] = "hci_module";
32 
33 ///// LEGACY DEFINITIONS /////
34 
35 /* Message event mask across Host/Controller lib and stack */
36 #define MSG_EVT_MASK 0xFF00     /* eq. BT_EVT_MASK */
37 #define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */
38 
39 /* Message event ID passed from Host/Controller lib to stack */
40 #define MSG_HC_TO_STACK_HCI_ERR 0x1300      /* eq. BT_EVT_TO_BTU_HCIT_ERR */
41 #define MSG_HC_TO_STACK_HCI_ACL 0x1100      /* eq. BT_EVT_TO_BTU_HCI_ACL */
42 #define MSG_HC_TO_STACK_HCI_SCO 0x1200      /* eq. BT_EVT_TO_BTU_HCI_SCO */
43 #define MSG_HC_TO_STACK_HCI_EVT 0x1000      /* eq. BT_EVT_TO_BTU_HCI_EVT */
44 #define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* BT_EVT_TO_BTU_L2C_SEG_XMIT */
45 
46 /* Message event ID passed from stack to vendor lib */
47 #define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
48 #define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
49 #define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
50 
51 /* Local Bluetooth Controller ID for BR/EDR */
52 #define LOCAL_BR_EDR_CONTROLLER_ID 0
53 
54 ///// END LEGACY DEFINITIONS /////
55 
56 typedef struct hci_hal_t hci_hal_t;
57 typedef struct btsnoop_t btsnoop_t;
58 typedef struct controller_t controller_t;
59 typedef struct hci_inject_t hci_inject_t;
60 typedef struct packet_fragmenter_t packet_fragmenter_t;
61 typedef struct vendor_t vendor_t;
62 
63 typedef unsigned char* bdaddr_t;
64 typedef uint16_t command_opcode_t;
65 
66 typedef void (*command_complete_cb)(BT_HDR* response, void* context);
67 typedef void (*command_status_cb)(uint8_t status, BT_HDR* command,
68                                   void* context);
69 
70 typedef struct hci_t {
71   // Set the callback that the HCI layer uses to send data upwards
72   void (*set_data_cb)(
73       base::Callback<void(const base::Location&, BT_HDR*)> send_data_cb);
74 
75   // Send a command through the HCI layer
76   void (*transmit_command)(BT_HDR* command,
77                            command_complete_cb complete_callback,
78                            command_status_cb status_cb, void* context);
79 
80   future_t* (*transmit_command_futured)(BT_HDR* command);
81 
82   // Send some data downward through the HCI layer
83   void (*transmit_downward)(uint16_t type, void* data);
84 } hci_t;
85 
86 const hci_t* hci_layer_get_interface();
87 
88 const hci_t* hci_layer_get_test_interface(
89     const allocator_t* buffer_allocator_interface,
90     const btsnoop_t* btsnoop_interface,
91     const packet_fragmenter_t* packet_fragmenter_interface);
92 
93 void post_to_main_message_loop(const base::Location& from_here, BT_HDR* p_msg);
94 
95 void hci_layer_cleanup_interface();
96