blob: c08f5297e34ccd662a0ae9ae72add5b023b8821c [file] [log] [blame]
Myles Watsone22dde22019-01-18 11:42:33 -08001/*
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"
Chienyuan3d8a8032019-11-01 18:04:07 +080024#include "hci/address.h"
Myles Watsone22dde22019-01-18 11:42:33 -080025#include "include/acl.h"
Myles Watsone22dde22019-01-18 11:42:33 -080026
27namespace test_vendor_lib {
28
Chienyuan3d8a8032019-11-01 18:04:07 +080029using ::bluetooth::hci::Address;
30
Myles Watsone22dde22019-01-18 11:42:33 -080031class AclConnectionHandler {
32 public:
Myles Watson96723532019-09-02 14:52:46 -070033 AclConnectionHandler() = default;
Myles Watsone22dde22019-01-18 11:42:33 -080034
35 virtual ~AclConnectionHandler() = default;
36
Myles Watsone066df42019-11-13 14:39:18 -080037 bool CreatePendingConnection(Address addr, bool authenticate_on_connect);
38 bool HasPendingConnection(Address addr) const;
Myles Watson96723532019-09-02 14:52:46 -070039 bool CancelPendingConnection(Address addr);
Myles Watsone066df42019-11-13 14:39:18 -080040 bool AuthenticatePendingConnection() const;
Myles Watsone22dde22019-01-18 11:42:33 -080041
Myles Watson96723532019-09-02 14:52:46 -070042 bool CreatePendingLeConnection(Address addr, uint8_t addr_type);
Myles Watsone066df42019-11-13 14:39:18 -080043 bool HasPendingLeConnection(Address addr, uint8_t addr_type) const;
Myles Watson96723532019-09-02 14:52:46 -070044 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 Watsone22dde22019-01-18 11:42:33 -080048 bool Disconnect(uint16_t handle);
49 bool HasHandle(uint16_t handle) const;
50
Myles Watson96723532019-09-02 14:52:46 -070051 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 Watsone22dde22019-01-18 11:42:33 -080055
56 void SetConnected(uint16_t handle, bool connected);
57 bool IsConnected(uint16_t handle) const;
58
Myles Watson96723532019-09-02 14:52:46 -070059 bool IsDeviceConnected(Address addr, uint8_t address_type = 0) const;
60
Myles Watsone22dde22019-01-18 11:42:33 -080061 void Encrypt(uint16_t handle);
62 bool IsEncrypted(uint16_t handle) const;
63
Myles Watson96723532019-09-02 14:52:46 -070064 void SetAddress(uint16_t handle, Address address, uint8_t address_type = 0); // default to public
Myles Watsone22dde22019-01-18 11:42:33 -080065
66 private:
67 std::unordered_map<uint16_t, AclConnection> acl_connections_;
Myles Watson52da8b82019-09-06 11:34:10 -070068 bool classic_connection_pending_{false};
Myles Watsone066df42019-11-13 14:39:18 -080069 Address pending_connection_address_{Address::kEmpty};
70 bool authenticate_pending_classic_connection_{false};
Myles Watson52da8b82019-09-06 11:34:10 -070071 bool le_connection_pending_{false};
Myles Watsone066df42019-11-13 14:39:18 -080072 Address pending_le_connection_address_{Address::kEmpty};
73 uint8_t pending_le_connection_address_type_{false};
74
Myles Watsone22dde22019-01-18 11:42:33 -080075 uint16_t GetUnusedHandle();
Myles Watson96723532019-09-02 14:52:46 -070076 uint16_t last_handle_{acl::kReservedHandle - 2};
77 void set_own_address_type(uint16_t handle, uint8_t own_address_type);
Myles Watsone22dde22019-01-18 11:42:33 -080078};
79
80} // namespace test_vendor_lib