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