• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 
21 #include "stack/include/bt_hdr.h"
22 #include "stack/include/bt_types.h"
23 #include "stack/include/gatt_api.h"
24 #include "stack/include/hci_error_code.h"
25 #include "stack/include/hci_mode.h"
26 #include "stack/include/hcidefs.h"
27 #include "types/ble_address_with_type.h"
28 #include "types/class_of_device.h"
29 #include "types/hci_role.h"
30 #include "types/raw_address.h"
31 
32 namespace bluetooth {
33 namespace shim {
34 namespace legacy {
35 
36 typedef struct {
37   void (*on_connected)(const RawAddress& bda, uint16_t handle, uint8_t enc_mode,
38                        bool locally_initiated);
39   void (*on_connect_request)(const RawAddress& bda,
40                              const types::ClassOfDevice&);
41   void (*on_failed)(const RawAddress& bda, tHCI_STATUS status,
42                     bool locally_initiated);
43   void (*on_disconnected)(tHCI_STATUS status, uint16_t handle,
44                           tHCI_STATUS reason);
45 } acl_classic_connection_interface_t;
46 
47 typedef struct {
48   void (*on_connected)(const tBLE_BD_ADDR& address_with_type, uint16_t handle,
49                        tHCI_ROLE role, uint16_t conn_interval,
50                        uint16_t conn_latency, uint16_t conn_timeout,
51                        const RawAddress& local_rpa, const RawAddress& peer_rpa,
52                        tBLE_ADDR_TYPE peer_addr_type,
53                        bool can_read_discoverable_characteristics);
54   void (*on_failed)(const tBLE_BD_ADDR& address_with_type, uint16_t handle,
55                     bool enhanced, tHCI_STATUS status);
56   void (*on_disconnected)(tHCI_STATUS status, uint16_t handle,
57                           tHCI_STATUS reason);
58   void (*on_iso_disconnected)(uint16_t handle, tHCI_STATUS reason);
59 } acl_le_connection_interface_t;
60 
61 typedef struct {
62   void (*on_esco_connect_request)(const RawAddress&,
63                                   const types::ClassOfDevice&);
64   void (*on_sco_connect_request)(const RawAddress&,
65                                  const types::ClassOfDevice&);
66   void (*on_disconnected)(uint16_t handle, tHCI_REASON reason);
67 } acl_sco_connection_interface_t;
68 
69 typedef struct {
70   void (*on_authentication_complete)(uint16_t handle, tHCI_STATUS status);
71   void (*on_change_connection_link_key_complete)();
72   void (*on_encryption_change)(bool enabled);
73   void (*on_flow_specification_complete)(uint16_t flow_direction,
74                                          uint16_t service_type,
75                                          uint32_t token_rate,
76                                          uint32_t token_bucket_size,
77                                          uint32_t peak_bandwidth,
78                                          uint32_t access_latency);
79   void (*on_flush_occurred)();
80   void (*on_central_link_key_complete)(uint8_t key_flag);
81   void (*on_mode_change)(tHCI_STATUS status, uint16_t handle,
82                          tHCI_MODE current_mode, uint16_t interval);
83   void (*on_sniff_subrating)(tHCI_STATUS status, uint16_t handle,
84                              uint16_t maximum_transmit_latency,
85                              uint16_t maximum_receive_latency,
86                              uint16_t minimum_remote_timeout,
87                              uint16_t minimum_local_timeout);
88   void (*on_packet_type_changed)(uint16_t packet_type);
89   void (*on_qos_setup_complete)(uint16_t service_type, uint32_t token_rate,
90                                 uint32_t peak_bandwidth, uint32_t latency,
91                                 uint32_t delay_variation);
92   void (*on_read_afh_channel_map_complete)(uint8_t afh_mode,
93                                            uint8_t afh_channel_map[]);
94   void (*on_read_automatic_flush_timeout_complete)(uint16_t flush_timeout);
95   void (*on_read_clock_complete)(uint32_t clock, uint16_t accuracy);
96   void (*on_read_clock_offset_complete)(uint16_t clock_offset);
97   void (*on_read_failed_contact_counter_complete)(
98       uint16_t failed_contact_counter);
99   void (*on_read_link_policy_settings_complete)(uint16_t link_policy_settings);
100   void (*on_read_link_quality_complete)(uint8_t link_quality);
101   void (*on_read_link_supervision_timeout_complete)(
102       uint16_t link_supervision_timeout);
103   void (*on_read_remote_supported_features_complete)(uint16_t handle,
104                                                      uint64_t features);
105   void (*on_read_remote_extended_features_complete)(uint16_t handle,
106                                                     uint8_t current_page_number,
107                                                     uint8_t max_page_number,
108                                                     uint64_t features);
109   void (*on_read_remote_version_information_complete)(
110       tHCI_STATUS status, uint16_t handle, uint8_t lmp_version,
111       uint16_t manufacturer_name, uint16_t sub_version);
112   void (*on_read_rssi_complete)(uint8_t rssi);
113   void (*on_read_transmit_power_level_complete)(uint8_t transmit_power_level);
114   void (*on_role_change)(tHCI_STATUS status, const RawAddress& bd_addr,
115                          tHCI_ROLE new_role);
116   void (*on_role_discovery_complete)(tHCI_ROLE current_role);
117 } acl_classic_link_interface_t;
118 
119 typedef struct {
120   void (*on_connection_update)(tHCI_STATUS status, uint16_t handle,
121                                uint16_t connection_interval,
122                                uint16_t connection_latency,
123                                uint16_t supervision_timeout);
124   void (*on_data_length_change)(uint16_t handle, uint16_t max_tx_octets,
125                                 uint16_t max_tx_time, uint16_t max_rx_octets,
126                                 uint16_t max_rx_time);
127   void (*on_read_remote_version_information_complete)(
128       tHCI_STATUS status, uint16_t handle, uint8_t lmp_version,
129       uint16_t manufacturer_name, uint16_t sub_version);
130   void (*on_phy_update)(tGATT_STATUS status, uint16_t handle, uint8_t tx_phy,
131                         uint8_t rx_phy);
132 
133   void (*on_le_subrate_change)(uint16_t handle, uint16_t subrate_factor,
134                                uint16_t latency, uint16_t cont_num,
135                                uint16_t timeout, uint8_t status);
136 } acl_le_link_interface_t;
137 
138 typedef struct {
139   acl_classic_connection_interface_t classic;
140   acl_le_connection_interface_t le;
141   acl_sco_connection_interface_t sco;
142 } acl_connection_interface_t;
143 
144 typedef struct {
145   acl_classic_link_interface_t classic;
146   acl_le_link_interface_t le;
147 } acl_link_interface_t;
148 
149 typedef struct {
150   void (*on_send_data_upwards)(BT_HDR*);
151   void (*on_packets_completed)(uint16_t handle, uint16_t num_packets);
152   acl_connection_interface_t connection;
153   acl_link_interface_t link;
154 } acl_interface_t;
155 
156 const acl_interface_t& GetAclInterface();
157 
158 }  // namespace legacy
159 }  // namespace shim
160 }  // namespace bluetooth
161