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 <atomic> 20 #include <memory> 21 22 #include "hci/acl_manager/acl_connection.h" 23 #include "hci/acl_manager/le_connection_management_callbacks.h" 24 #include "hci/address_with_type.h" 25 #include "hci/hci_packets.h" 26 #include "hci/le_acl_connection_interface.h" 27 28 namespace bluetooth { 29 namespace hci { 30 namespace acl_manager { 31 32 class LeAclConnection : public AclConnection { 33 public: 34 LeAclConnection(); 35 LeAclConnection( 36 std::shared_ptr<Queue> queue, 37 LeAclConnectionInterface* le_acl_connection_interface, 38 uint16_t handle, 39 AddressWithType local_address, 40 AddressWithType remote_address, 41 Role role); 42 LeAclConnection(const LeAclConnection&) = delete; 43 LeAclConnection& operator=(const LeAclConnection&) = delete; 44 45 ~LeAclConnection(); 46 GetLocalAddress()47 virtual AddressWithType GetLocalAddress() const { 48 return local_address_; 49 } 50 UpdateLocalAddress(AddressWithType address)51 virtual void UpdateLocalAddress(AddressWithType address) { 52 local_address_ = address; 53 } 54 GetRemoteAddress()55 virtual AddressWithType GetRemoteAddress() const { 56 return remote_address_; 57 } 58 GetRole()59 virtual Role GetRole() const { 60 return role_; 61 } 62 63 // The peer address and type returned from the Connection Complete Event 64 AddressWithType peer_address_with_type_; 65 Address remote_initiator_address_; 66 Address local_initiator_address_; 67 // 5.2::7.7.65.10 Connection interval used on this connection. 68 // Range: 0x0006 to 0x0C80 69 // Time = N * 1.25 ms 70 // Time Range: 7.5 ms to 4000 ms. 71 uint16_t interval_; 72 // 5.2::7.7.65.10 Peripheral latency for the connection in number of connection events. 73 // Range: 0x0000 to 0x01F3 74 uint16_t latency_; 75 // 5.2::7.7.65.10 Connection supervision timeout. 76 // Range: 0x000A to 0x0C80 77 // Time = N * 10 ms 78 // Time Range: 100 ms to 32 s 79 uint16_t supervision_timeout_; 80 81 // True if connection address was in the filter accept list, false otherwise 82 bool in_filter_accept_list_; IsInFilterAcceptList()83 bool IsInFilterAcceptList() const { 84 return in_filter_accept_list_; 85 } 86 87 Address local_resolvable_private_address_ = Address::kEmpty; 88 Address peer_resolvable_private_address_ = Address::kEmpty; 89 90 virtual void RegisterCallbacks(LeConnectionManagementCallbacks* callbacks, os::Handler* handler); 91 virtual void Disconnect(DisconnectReason reason); 92 93 virtual bool LeConnectionUpdate(uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency, 94 uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); 95 96 virtual bool ReadRemoteVersionInformation() override; 97 virtual bool LeReadRemoteFeatures(); 98 99 // TODO implement LeRemoteConnectionParameterRequestReply, LeRemoteConnectionParameterRequestNegativeReply 100 101 // Called once before passing the connection to the client 102 virtual LeConnectionManagementCallbacks* GetEventCallbacks(std::function<void(uint16_t)> invalidate_callbacks); 103 104 protected: 105 AddressWithType local_address_; 106 AddressWithType remote_address_; 107 Role role_; 108 109 private: 110 virtual bool check_connection_parameters( 111 uint16_t conn_interval_min, 112 uint16_t conn_interval_max, 113 uint16_t expected_conn_latency, 114 uint16_t expected_supervision_timeout); 115 struct impl; 116 struct impl* pimpl_ = nullptr; 117 }; 118 119 } // namespace acl_manager 120 } // namespace hci 121 } // namespace bluetooth 122