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