Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 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 <cstdint> |
| 20 | #include <set> |
| 21 | #include <unordered_map> |
| 22 | |
| 23 | #include "acl_connection.h" |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 24 | #include "hci/address.h" |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 25 | #include "include/acl.h" |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 26 | |
| 27 | namespace test_vendor_lib { |
| 28 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 29 | using ::bluetooth::hci::Address; |
| 30 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 31 | class AclConnectionHandler { |
| 32 | public: |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 33 | AclConnectionHandler() = default; |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 34 | |
| 35 | virtual ~AclConnectionHandler() = default; |
| 36 | |
Myles Watson | e066df4 | 2019-11-13 14:39:18 -0800 | [diff] [blame^] | 37 | bool CreatePendingConnection(Address addr, bool authenticate_on_connect); |
| 38 | bool HasPendingConnection(Address addr) const; |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 39 | bool CancelPendingConnection(Address addr); |
Myles Watson | e066df4 | 2019-11-13 14:39:18 -0800 | [diff] [blame^] | 40 | bool AuthenticatePendingConnection() const; |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 41 | |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 42 | bool CreatePendingLeConnection(Address addr, uint8_t addr_type); |
Myles Watson | e066df4 | 2019-11-13 14:39:18 -0800 | [diff] [blame^] | 43 | bool HasPendingLeConnection(Address addr, uint8_t addr_type) const; |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 44 | bool CancelPendingLeConnection(Address addr, uint8_t addr_type); |
| 45 | |
| 46 | uint16_t CreateConnection(Address addr); |
| 47 | uint16_t CreateLeConnection(Address addr, uint8_t address_type, uint8_t own_address_type); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 48 | bool Disconnect(uint16_t handle); |
| 49 | bool HasHandle(uint16_t handle) const; |
| 50 | |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 51 | uint16_t GetHandle(Address addr) const; |
| 52 | Address GetAddress(uint16_t handle) const; |
| 53 | uint8_t GetAddressType(uint16_t handle) const; |
| 54 | uint8_t GetOwnAddressType(uint16_t handle) const; |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 55 | |
| 56 | void SetConnected(uint16_t handle, bool connected); |
| 57 | bool IsConnected(uint16_t handle) const; |
| 58 | |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 59 | bool IsDeviceConnected(Address addr, uint8_t address_type = 0) const; |
| 60 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 61 | void Encrypt(uint16_t handle); |
| 62 | bool IsEncrypted(uint16_t handle) const; |
| 63 | |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 64 | void SetAddress(uint16_t handle, Address address, uint8_t address_type = 0); // default to public |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 65 | |
| 66 | private: |
| 67 | std::unordered_map<uint16_t, AclConnection> acl_connections_; |
Myles Watson | 52da8b8 | 2019-09-06 11:34:10 -0700 | [diff] [blame] | 68 | bool classic_connection_pending_{false}; |
Myles Watson | e066df4 | 2019-11-13 14:39:18 -0800 | [diff] [blame^] | 69 | Address pending_connection_address_{Address::kEmpty}; |
| 70 | bool authenticate_pending_classic_connection_{false}; |
Myles Watson | 52da8b8 | 2019-09-06 11:34:10 -0700 | [diff] [blame] | 71 | bool le_connection_pending_{false}; |
Myles Watson | e066df4 | 2019-11-13 14:39:18 -0800 | [diff] [blame^] | 72 | Address pending_le_connection_address_{Address::kEmpty}; |
| 73 | uint8_t pending_le_connection_address_type_{false}; |
| 74 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 75 | uint16_t GetUnusedHandle(); |
Myles Watson | 9672353 | 2019-09-02 14:52:46 -0700 | [diff] [blame] | 76 | uint16_t last_handle_{acl::kReservedHandle - 2}; |
| 77 | void set_own_address_type(uint16_t handle, uint8_t own_address_type); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace test_vendor_lib |