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 #include "stack/include/bt_types.h"
21 #include "stack/include/hci_error_code.h"
22 #include "stack/include/hcidefs.h"
23 #include "types/ble_address_with_type.h"
24 #include "types/class_of_device.h"
25 #include "types/hci_role.h"
26 #include "types/raw_address.h"
27 
28 namespace bluetooth {
29 namespace shim {
30 namespace legacy {
31 
32 typedef struct {
33   void (*on_connected)(const RawAddress& bda, uint16_t handle,
34                        uint8_t enc_mode);
35   void (*on_failed)(const RawAddress& bda, tHCI_STATUS status);
36   void (*on_disconnected)(tHCI_STATUS status, uint16_t handle,
37                           tHCI_STATUS reason);
38 } acl_classic_connection_interface_t;
39 
40 typedef struct {
41   void (*on_connected)(const tBLE_BD_ADDR& address_with_type, uint16_t handle,
42                        tHCI_ROLE role, uint16_t conn_interval,
43                        uint16_t conn_latency, uint16_t conn_timeout,
44                        const RawAddress& local_rpa, const RawAddress& peer_rpa,
45                        uint8_t peer_addr_type);
46   void (*on_failed)(const tBLE_BD_ADDR& address_with_type, uint16_t handle,
47                     bool enhanced, tHCI_STATUS status);
48   void (*on_disconnected)(tHCI_STATUS status, uint16_t handle,
49                           tHCI_STATUS reason);
50 } acl_le_connection_interface_t;
51 
52 typedef struct {
53   void (*on_esco_connect_request)(const RawAddress&,
54                                   const types::ClassOfDevice&);
55   void (*on_sco_connect_request)(const RawAddress&,
56                                  const types::ClassOfDevice&);
57   void (*on_disconnected)(uint16_t handle, tHCI_REASON reason);
58 } acl_sco_connection_interface_t;
59 
60 typedef struct {
61   void (*on_authentication_complete)(uint16_t handle, tHCI_STATUS status);
62   void (*on_change_connection_link_key_complete)();
63   void (*on_encryption_change)(bool enabled);
64   void (*on_flow_specification_complete)(uint16_t flow_direction,
65                                          uint16_t service_type,
66                                          uint32_t token_rate,
67                                          uint32_t token_bucket_size,
68                                          uint32_t peak_bandwidth,
69                                          uint32_t access_latency);
70   void (*on_flush_occurred)();
71   void (*on_central_link_key_complete)(uint8_t key_flag);
72   void (*on_mode_change)(tHCI_STATUS status, uint16_t handle,
73                          tHCI_MODE current_mode, uint16_t interval);
74   void (*on_sniff_subrating)(tHCI_STATUS status, uint16_t handle,
75                              uint16_t maximum_transmit_latency,
76                              uint16_t maximum_receive_latency,
77                              uint16_t minimum_remote_timeout,
78                              uint16_t minimum_local_timeout);
79   void (*on_packet_type_changed)(uint16_t packet_type);
80   void (*on_qos_setup_complete)(uint16_t service_type, uint32_t token_rate,
81                                 uint32_t peak_bandwidth, uint32_t latency,
82                                 uint32_t delay_variation);
83   void (*on_read_afh_channel_map_complete)(uint8_t afh_mode,
84                                            uint8_t afh_channel_map[]);
85   void (*on_read_automatic_flush_timeout_complete)(uint16_t flush_timeout);
86   void (*on_read_clock_complete)(uint32_t clock, uint16_t accuracy);
87   void (*on_read_clock_offset_complete)(uint16_t clock_offset);
88   void (*on_read_failed_contact_counter_complete)(
89       uint16_t failed_contact_counter);
90   void (*on_read_link_policy_settings_complete)(uint16_t link_policy_settings);
91   void (*on_read_link_quality_complete)(uint8_t link_quality);
92   void (*on_read_link_supervision_timeout_complete)(
93       uint16_t link_supervision_timeout);
94   void (*on_read_remote_supported_features_complete)(uint16_t handle,
95                                                      uint64_t features);
96   void (*on_read_remote_extended_features_complete)(uint16_t handle,
97                                                     uint8_t current_page_number,
98                                                     uint8_t max_page_number,
99                                                     uint64_t features);
100   void (*on_read_remote_version_information_complete)(
101       tHCI_STATUS status, uint16_t handle, uint8_t lmp_version,
102       uint16_t manufacturer_name, uint16_t sub_version);
103   void (*on_read_rssi_complete)(uint8_t rssi);
104   void (*on_read_transmit_power_level_complete)(uint8_t transmit_power_level);
105   void (*on_role_change)(tHCI_STATUS status, const RawAddress& bd_addr,
106                          tHCI_ROLE new_role);
107   void (*on_role_discovery_complete)(tHCI_ROLE current_role);
108 } acl_classic_link_interface_t;
109 
110 typedef struct {
111   void (*on_connection_update)(tHCI_STATUS status, uint16_t handle,
112                                uint16_t connection_interval,
113                                uint16_t connection_latency,
114                                uint16_t supervision_timeout);
115   void (*on_data_length_change)(uint16_t tx_octets, uint16_t tx_time,
116                                 uint16_t rx_octets, uint16_t rx_time);
117   void (*on_read_remote_version_information_complete)(
118       tHCI_STATUS status, uint16_t handle, uint8_t lmp_version,
119       uint16_t manufacturer_name, uint16_t sub_version);
120   void (*on_phy_update)(tHCI_STATUS status, uint16_t handle, uint8_t tx_phy,
121                         uint8_t rx_phy);
122 } acl_le_link_interface_t;
123 
124 typedef struct {
125   acl_classic_connection_interface_t classic;
126   acl_le_connection_interface_t le;
127   acl_sco_connection_interface_t sco;
128 } acl_connection_interface_t;
129 
130 typedef struct {
131   acl_classic_link_interface_t classic;
132   acl_le_link_interface_t le;
133 } acl_link_interface_t;
134 
135 typedef struct {
136   void (*on_send_data_upwards)(BT_HDR*);
137   void (*on_packets_completed)(uint16_t handle, uint16_t num_packets);
138   acl_connection_interface_t connection;
139   acl_link_interface_t link;
140 } acl_interface_t;
141 
142 const acl_interface_t GetAclInterface();
143 
144 }  // namespace legacy
145 }  // namespace shim
146 }  // namespace bluetooth
147