1 /* 2 * Copyright 2018 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 <chrono> 20 #include <cstdint> 21 22 #include "hci/address_with_type.h" 23 #include "phy.h" 24 25 namespace rootcanal { 26 27 using ::bluetooth::hci::AddressWithType; 28 29 // Model the connection of a device to the controller. 30 class AclConnection { 31 public: 32 AclConnection(AddressWithType address, AddressWithType own_address, 33 AddressWithType resolved_address, Phy::Type phy_type, 34 bluetooth::hci::Role role); 35 36 virtual ~AclConnection() = default; 37 38 void Encrypt(); 39 40 bool IsEncrypted() const; 41 42 AddressWithType GetAddress() const; 43 44 void SetAddress(AddressWithType address); 45 46 AddressWithType GetOwnAddress() const; 47 48 void SetOwnAddress(AddressWithType address); 49 50 AddressWithType GetResolvedAddress() const; 51 52 Phy::Type GetPhyType() const; 53 54 uint16_t GetLinkPolicySettings() const; 55 56 void SetLinkPolicySettings(uint16_t settings); 57 58 bluetooth::hci::Role GetRole() const; 59 60 void SetRole(bluetooth::hci::Role role); 61 62 void ResetLinkTimer(); 63 64 std::chrono::steady_clock::duration TimeUntilNearExpiring() const; 65 66 bool IsNearExpiring() const; 67 68 std::chrono::steady_clock::duration TimeUntilExpired() const; 69 70 bool HasExpired() const; 71 72 private: 73 AddressWithType address_; 74 AddressWithType own_address_; 75 AddressWithType resolved_address_; 76 Phy::Type type_{Phy::Type::BR_EDR}; 77 78 // State variables 79 bool encrypted_{false}; 80 uint16_t link_policy_settings_{0}; 81 bluetooth::hci::Role role_{bluetooth::hci::Role::CENTRAL}; 82 std::chrono::steady_clock::time_point last_packet_timestamp_; 83 std::chrono::steady_clock::duration timeout_; 84 }; 85 86 } // namespace rootcanal 87