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 "hci/acl_manager/acl_connection.h"
20 #include "hci/acl_manager/le_connection_management_callbacks.h"
21 #include "hci/address_with_type.h"
22 #include "hci/hci_packets.h"
23 #include "hci/le_acl_connection_interface.h"
24 
25 namespace bluetooth {
26 namespace hci {
27 namespace acl_manager {
28 
29 class LeAclConnection : public AclConnection {
30  public:
31   LeAclConnection();
32   LeAclConnection(std::shared_ptr<Queue> queue, LeAclConnectionInterface* le_acl_connection_interface,
33                   common::OnceCallback<void(DisconnectReason)> disconnect, uint16_t handle,
34                   AddressWithType local_address, AddressWithType remote_address, Role role);
35   ~LeAclConnection() override;
36 
GetLocalAddress()37   virtual AddressWithType GetLocalAddress() const {
38     return local_address_;
39   }
40 
GetRemoteAddress()41   virtual AddressWithType GetRemoteAddress() const {
42     return remote_address_;
43   }
44 
GetRole()45   virtual Role GetRole() const {
46     return role_;
47   }
48 
49   virtual void RegisterCallbacks(LeConnectionManagementCallbacks* callbacks, os::Handler* handler);
50   virtual void Disconnect(DisconnectReason reason);
51 
52   virtual bool LeConnectionUpdate(uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency,
53                                   uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length);
54   // TODO implement LeRemoteConnectionParameterRequestReply, LeRemoteConnectionParameterRequestNegativeReply
55 
56   // Called once before passing the connection to the client
57   virtual LeConnectionManagementCallbacks* GetEventCallbacks();
58 
59  private:
60   virtual bool check_connection_parameters(
61       uint16_t conn_interval_min,
62       uint16_t conn_interval_max,
63       uint16_t expected_conn_latency,
64       uint16_t expected_supervision_timeout);
65   struct impl;
66   struct impl* pimpl_ = nullptr;
67   AddressWithType local_address_;
68   AddressWithType remote_address_;
69   Role role_;
70   DISALLOW_COPY_AND_ASSIGN(LeAclConnection);
71 };
72 
73 }  // namespace acl_manager
74 }  // namespace hci
75 }  // namespace bluetooth
76