summaryrefslogtreecommitdiff
path: root/system/gd/hci/acl_manager/le_acl_connection.h
blob: a805d19d6858912bdc8006475a7ced2716edc674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <atomic>
#include <memory>

#include "hci/acl_manager/acl_connection.h"
#include "hci/acl_manager/le_connection_management_callbacks.h"
#include "hci/address_with_type.h"
#include "hci/hci_packets.h"
#include "hci/le_acl_connection_interface.h"

namespace bluetooth {
namespace hci {
namespace acl_manager {

class LeAclConnection : public AclConnection {
 public:
  LeAclConnection();
  LeAclConnection(
      std::shared_ptr<Queue> queue,
      LeAclConnectionInterface* le_acl_connection_interface,
      uint16_t handle,
      AddressWithType local_address,
      AddressWithType remote_address,
      Role role);
  LeAclConnection(const LeAclConnection&) = delete;
  LeAclConnection& operator=(const LeAclConnection&) = delete;

  ~LeAclConnection();

  virtual AddressWithType GetLocalAddress() const {
    return local_address_;
  }

  virtual void UpdateLocalAddress(AddressWithType address) {
    local_address_ = address;
  }

  virtual AddressWithType GetRemoteAddress() const {
    return remote_address_;
  }

  virtual Role GetRole() const {
    return role_;
  }

  // The peer address and type returned from the Connection Complete Event
  AddressWithType peer_address_with_type_;
  Address remote_initiator_address_;
  Address local_initiator_address_;
  // 5.2::7.7.65.10 Connection interval used on this connection.
  // Range: 0x0006 to 0x0C80
  // Time = N * 1.25 ms
  // Time Range: 7.5 ms to 4000 ms.
  uint16_t interval_;
  // 5.2::7.7.65.10 Peripheral latency for the connection in number of connection events.
  // Range: 0x0000 to 0x01F3
  uint16_t latency_;
  // 5.2::7.7.65.10 Connection supervision timeout.
  // Range: 0x000A to 0x0C80
  // Time = N * 10 ms
  // Time Range: 100 ms to 32 s
  uint16_t supervision_timeout_;

  // True if connection address was in the filter accept list, false otherwise
  bool in_filter_accept_list_;
  bool IsInFilterAcceptList() const {
    return in_filter_accept_list_;
  }

  Address local_resolvable_private_address_ = Address::kEmpty;
  Address peer_resolvable_private_address_ = Address::kEmpty;

  virtual void RegisterCallbacks(LeConnectionManagementCallbacks* callbacks, os::Handler* handler);
  virtual void Disconnect(DisconnectReason reason);

  virtual bool LeConnectionUpdate(uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency,
                                  uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length);

  virtual bool ReadRemoteVersionInformation() override;
  virtual bool LeReadRemoteFeatures();

  // TODO implement LeRemoteConnectionParameterRequestReply, LeRemoteConnectionParameterRequestNegativeReply

  // Called once before passing the connection to the client
  virtual LeConnectionManagementCallbacks* GetEventCallbacks(std::function<void(uint16_t)> invalidate_callbacks);

 protected:
  AddressWithType local_address_;
  AddressWithType remote_address_;
  Role role_;

 private:
  virtual bool check_connection_parameters(
      uint16_t conn_interval_min,
      uint16_t conn_interval_max,
      uint16_t expected_conn_latency,
      uint16_t expected_supervision_timeout);
  struct impl;
  struct impl* pimpl_ = nullptr;
};

}  // namespace acl_manager
}  // namespace hci
}  // namespace bluetooth