diff options
author | Martin Brabham <optedoblivion@google.com> | 2019-08-22 11:59:37 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-08-22 11:59:37 -0700 |
commit | cf95615e90613cd51d58b6c81c28e1f385806ea1 (patch) | |
tree | fcc7173f7bc6820648c88552e1b5ec54eeb78fdc | |
parent | 409fe960036f4b5b2dd94fd56b1a1927bb7ee069 (diff) | |
parent | 94db40c6c98c426e5645b2e9811018d7af2311c7 (diff) | |
download | bt-cf95615e90613cd51d58b6c81c28e1f385806ea1.tar.gz |
GD: Move Address and ClassOfDevice to hci
am: 94db40c6c9
Change-Id: I882104c8192e0aa28b0f4532dad606265a222723
35 files changed, 201 insertions, 202 deletions
diff --git a/gd/common/Android.bp b/gd/common/Android.bp index d8410f584..c9234278c 100644 --- a/gd/common/Android.bp +++ b/gd/common/Android.bp @@ -1,8 +1,6 @@ filegroup { name: "BluetoothCommonSources", srcs: [ - "address.cc", - "class_of_device.cc", "link_key.cc", ], } @@ -10,9 +8,7 @@ filegroup { filegroup { name: "BluetoothCommonTestSources", srcs: [ - "address_unittest.cc", "blocking_queue_unittest.cc", - "class_of_device_unittest.cc", "bidi_queue_unittest.cc", "observer_registry_test.cc", "link_key_unittest.cc", diff --git a/gd/hci/Android.bp b/gd/hci/Android.bp index 91c87ffde..b7ddec3cc 100644 --- a/gd/hci/Android.bp +++ b/gd/hci/Android.bp @@ -4,6 +4,8 @@ filegroup { "acl_manager.cc", "classic_security_manager.cc", "controller.cc", + "address.cc", + "class_of_device.cc", "hci_layer.cc", ], } @@ -15,6 +17,8 @@ filegroup { "acl_manager_test.cc", "classic_security_manager_test.cc", "controller_test.cc", + "address_unittest.cc", + "class_of_device_unittest.cc", "hci_layer_test.cc", ], } diff --git a/gd/hci/acl_manager.cc b/gd/hci/acl_manager.cc index ac4e21357..5978f3cf5 100644 --- a/gd/hci/acl_manager.cc +++ b/gd/hci/acl_manager.cc @@ -61,7 +61,7 @@ struct AclManager::impl { common::Bind(&impl::incoming_acl_credits, common::Unretained(this)), handler_); // TODO: determine when we should reject connection - should_accept_connection_ = common::Bind([](common::Address, common::ClassOfDevice) { return true; }); + should_accept_connection_ = common::Bind([](Address, ClassOfDevice) { return true; }); hci_queue_end_ = hci_layer_->GetAclQueueEnd(); hci_queue_end_->RegisterDequeue( handler_, common::Bind(&impl::dequeue_and_route_acl_packet_to_connection, common::Unretained(this))); @@ -204,7 +204,7 @@ struct AclManager::impl { void on_incoming_connection(EventPacketView packet) { ConnectionRequestView request = ConnectionRequestView::Create(packet); ASSERT(request.IsValid()); - common::Address address = request.GetBdAddr(); + Address address = request.GetBdAddr(); if (client_callbacks_ == nullptr) { LOG_ERROR("No callbacks to call"); auto reason = RejectConnectionReason::LIMITED_RESOURCES; @@ -267,7 +267,7 @@ struct AclManager::impl { } } - void create_connection(common::Address address) { + void create_connection(Address address) { // TODO: Configure default connection parameters? uint16_t packet_type = 0x4408 /* DM 1,3,5 */ | 0x8810 /*DH 1,3,5 */; PageScanRepetitionMode page_scan_repetition_mode = PageScanRepetitionMode::R1; @@ -287,7 +287,7 @@ struct AclManager::impl { handler_); } - void cancel_connect(common::Address address) { + void cancel_connect(Address address) { auto connecting_addr = connecting_.find(address); if (connecting_addr == connecting_.end()) { LOG_INFO("Cannot cancel non-existent connection to %s", address.ToString().c_str()); @@ -299,7 +299,7 @@ struct AclManager::impl { handler_); } - void accept_connection(common::Address address) { + void accept_connection(Address address) { auto role = AcceptConnectionRequestRole::BECOME_MASTER; // We prefer to be master hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role), common::BindOnce(&impl::on_accept_connection_status, common::Unretained(this), address), @@ -323,7 +323,7 @@ struct AclManager::impl { acl_connections_.erase(handle); } - void on_accept_connection_status(common::Address address, CommandStatusView status) { + void on_accept_connection_status(Address address, CommandStatusView status) { auto accept_status = AcceptConnectionRequestStatusView::Create(status); ASSERT(accept_status.IsValid()); if (status.GetStatus() != ErrorCode::SUCCESS) { @@ -398,8 +398,8 @@ struct AclManager::impl { os::Handler* client_handler_ = nullptr; common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* hci_queue_end_ = nullptr; std::map<uint16_t, AclManager::acl_connection> acl_connections_; - std::set<common::Address> connecting_; - common::Callback<bool(common::Address, common::ClassOfDevice)> should_accept_connection_; + std::set<Address> connecting_; + common::Callback<bool(Address, ClassOfDevice)> should_accept_connection_; }; AclConnection::QueueUpEnd* AclConnection::GetAclQueueEnd() const { @@ -428,11 +428,11 @@ bool AclManager::RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler* return true; } -void AclManager::CreateConnection(common::Address address) { +void AclManager::CreateConnection(Address address) { GetHandler()->Post(common::BindOnce(&impl::create_connection, common::Unretained(pimpl_.get()), address)); } -void AclManager::CancelConnect(common::Address address) { +void AclManager::CancelConnect(Address address) { GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address)); } diff --git a/gd/hci/acl_manager.h b/gd/hci/acl_manager.h index 585cef726..b379c3dcf 100644 --- a/gd/hci/acl_manager.h +++ b/gd/hci/acl_manager.h @@ -18,9 +18,9 @@ #include <memory> -#include "common/address.h" #include "common/bidi_queue.h" #include "common/callback.h" +#include "hci/address.h" #include "hci/hci_layer.h" #include "hci/hci_packets.h" #include "module.h" @@ -33,10 +33,10 @@ class AclManager; class AclConnection { public: - AclConnection() : manager_(nullptr), handle_(0), address_(common::Address::kEmpty){}; + AclConnection() : manager_(nullptr), handle_(0), address_(Address::kEmpty){}; virtual ~AclConnection() = default; - virtual common::Address GetAddress() const { + virtual Address GetAddress() const { return address_; } @@ -57,11 +57,11 @@ class AclConnection { private: friend AclManager; - AclConnection(AclManager* manager, uint16_t handle, common::Address address) + AclConnection(AclManager* manager, uint16_t handle, Address address) : manager_(manager), handle_(handle), address_(address) {} AclManager* manager_; uint16_t handle_; - common::Address address_; + Address address_; DISALLOW_COPY_AND_ASSIGN(AclConnection); }; @@ -71,7 +71,7 @@ class ConnectionCallbacks { // Invoked when controller sends Connection Complete event with Success error code virtual void OnConnectSuccess(std::unique_ptr<AclConnection> /* , initiated_by_local ? */) = 0; // Invoked when controller sends Connection Complete event with non-Success error code - virtual void OnConnectFail(common::Address, ErrorCode reason) = 0; + virtual void OnConnectFail(Address, ErrorCode reason) = 0; }; class AclManager : public Module { @@ -88,11 +88,11 @@ class AclManager : public Module { virtual bool RegisterCallbacks(ConnectionCallbacks* callbacks, os::Handler* handler); // Generates OnConnectSuccess if connected, or OnConnectFail otherwise - virtual void CreateConnection(common::Address address); + virtual void CreateConnection(Address address); // Generates OnConnectFail with error code "terminated by local host 0x16" if cancelled, or OnConnectSuccess if not // successfully cancelled and already connected - virtual void CancelConnect(common::Address address); + virtual void CancelConnect(Address address); static const ModuleFactory Factory; diff --git a/gd/hci/acl_manager_mock.h b/gd/hci/acl_manager_mock.h index 78bc64d62..a607a5cfa 100644 --- a/gd/hci/acl_manager_mock.h +++ b/gd/hci/acl_manager_mock.h @@ -26,7 +26,7 @@ namespace testing { class MockAclConnection : public AclConnection { public: - MOCK_METHOD(common::Address, GetAddress, (), (const, override)); + MOCK_METHOD(Address, GetAddress, (), (const, override)); MOCK_METHOD(void, RegisterDisconnectCallback, (common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler), (override)); MOCK_METHOD(bool, Disconnect, (DisconnectReason reason), (override)); @@ -37,8 +37,8 @@ class MockAclConnection : public AclConnection { class MockAclManager : public AclManager { public: MOCK_METHOD(bool, RegisterCallbacks, (ConnectionCallbacks * callbacks, os::Handler* handler), (override)); - MOCK_METHOD(void, CreateConnection, (common::Address address), (override)); - MOCK_METHOD(void, CancelConnect, (common::Address address), (override)); + MOCK_METHOD(void, CreateConnection, (Address address), (override)); + MOCK_METHOD(void, CancelConnect, (Address address), (override)); }; } // namespace testing diff --git a/gd/hci/acl_manager_test.cc b/gd/hci/acl_manager_test.cc index a9f4f50ed..b8d76fd18 100644 --- a/gd/hci/acl_manager_test.cc +++ b/gd/hci/acl_manager_test.cc @@ -24,8 +24,8 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "common/address.h" #include "common/bind.h" +#include "hci/address.h" #include "hci/controller.h" #include "hci/hci_layer.h" #include "os/thread.h" @@ -35,7 +35,6 @@ namespace bluetooth { namespace hci { namespace { -using common::Address; using common::BidiQueue; using common::BidiQueueEnd; using packet::kLittleEndian; @@ -266,7 +265,7 @@ class AclManagerTest : public AclManagerNoCallbacksTest { TEST_F(AclManagerTest, startup_teardown) {} TEST_F(AclManagerNoCallbacksTest, acl_connection_before_registered_callbacks) { - common::ClassOfDevice class_of_device; + ClassOfDevice class_of_device; test_hci_layer_->IncomingEvent( ConnectionRequestBuilder::Create(remote, class_of_device, ConnectionRequestLinkType::ACL)); diff --git a/gd/common/address.cc b/gd/hci/address.cc index cd8101a6a..db0695dd3 100644 --- a/gd/common/address.cc +++ b/gd/hci/address.cc @@ -16,7 +16,7 @@ * ******************************************************************************/ -#include "address.h" +#include "hci/address.h" #include <stdint.h> #include <algorithm> @@ -24,7 +24,7 @@ #include <vector> namespace bluetooth { -namespace common { +namespace hci { static_assert(sizeof(Address) == 6, "Address must be 6 bytes long!"); @@ -37,8 +37,8 @@ Address::Address(const uint8_t (&addr)[6]) { std::string Address::ToString() const { char buffer[] = "00:00:00:00:00:00"; - std::snprintf(&buffer[0], sizeof(buffer), - "%02x:%02x:%02x:%02x:%02x:%02x", address[5], address[4], address[3], address[2], address[1], address[0]); + std::snprintf(&buffer[0], sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x", address[5], address[4], address[3], + address[2], address[1], address[0]); std::string str(buffer); return str; } @@ -88,5 +88,5 @@ bool Address::IsValidAddress(const std::string& address) { return Address::FromString(address, tmp); } -} // namespace common +} // namespace hci } // namespace bluetooth diff --git a/gd/common/address.h b/gd/hci/address.h index f62464c3c..a8f515c22 100644 --- a/gd/common/address.h +++ b/gd/hci/address.h @@ -21,7 +21,7 @@ #include <string> namespace bluetooth { -namespace common { +namespace hci { class Address final { public: @@ -77,16 +77,16 @@ inline std::ostream& operator<<(std::ostream& os, const Address& a) { return os; } -} // namespace common +} // namespace hci } // namespace bluetooth namespace std { template <> -struct hash<bluetooth::common::Address> { - std::size_t operator()(const bluetooth::common::Address& val) const { - static_assert(sizeof(uint64_t) >= bluetooth::common::Address::kLength); +struct hash<bluetooth::hci::Address> { + std::size_t operator()(const bluetooth::hci::Address& val) const { + static_assert(sizeof(uint64_t) >= bluetooth::hci::Address::kLength); uint64_t int_addr = 0; - memcpy(reinterpret_cast<uint8_t*>(&int_addr), val.address, bluetooth::common::Address::kLength); + memcpy(reinterpret_cast<uint8_t*>(&int_addr), val.address, bluetooth::hci::Address::kLength); return std::hash<uint64_t>{}(int_addr); } }; diff --git a/gd/common/address_unittest.cc b/gd/hci/address_unittest.cc index a16f70d8b..17ecd3a70 100644 --- a/gd/common/address_unittest.cc +++ b/gd/hci/address_unittest.cc @@ -20,9 +20,9 @@ #include <gtest/gtest.h> -#include "common/address.h" +#include "hci/address.h" -using bluetooth::common::Address; +using bluetooth::hci::Address; static const char* test_addr = "bc:9a:78:56:34:12"; static const char* test_addr2 = "21:43:65:87:a9:cb"; @@ -204,7 +204,7 @@ TEST(AddressTest, BdAddrSameValueSameOrder) { Address addr1{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; Address addr2{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; // Test if two addresses with same byte value have the same hash - struct std::hash<bluetooth::common::Address> hasher; + struct std::hash<bluetooth::hci::Address> hasher; EXPECT_EQ(hasher(addr1), hasher(addr2)); // Test if two addresses with the same hash and the same value, they will // still map to the same value diff --git a/gd/hci/cert/cert.cc b/gd/hci/cert/cert.cc index dbd4a5dd6..0dd36f3c7 100644 --- a/gd/hci/cert/cert.cc +++ b/gd/hci/cert/cert.cc @@ -126,7 +126,7 @@ class AclManagerCertService : public AclManagerCert::Service { void on_incoming_connection(EventPacketView packet) { ConnectionRequestView request = ConnectionRequestView::Create(packet); ASSERT(request.IsValid()); - common::Address address = request.GetBdAddr(); + Address address = request.GetBdAddr(); if (accepted_devices_.find(address) != accepted_devices_.end()) { auto role = AcceptConnectionRequestRole::BECOME_MASTER; // We prefer to be master hci_layer_->EnqueueCommand(AcceptConnectionRequestBuilder::Create(address, role), @@ -166,8 +166,8 @@ class AclManagerCertService : public AclManagerCert::Service { const ::bluetooth::hci::cert::IncomingConnectionPolicy* request, ::google::protobuf::Empty* response) override { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); if (request->accepted()) { accepted_devices_.insert(peer); } else { @@ -186,8 +186,8 @@ class AclManagerCertService : public AclManagerCert::Service { ClockOffsetValid clock_offset_valid = ClockOffsetValid::INVALID; CreateConnectionRoleSwitch allow_role_switch = CreateConnectionRoleSwitch::ALLOW_ROLE_SWITCH; - common::Address peer; - ASSERT(common::Address::FromString(remote->address(), peer)); + Address peer; + ASSERT(Address::FromString(remote->address(), peer)); std::unique_ptr<CreateConnectionBuilder> packet = CreateConnectionBuilder::Create( peer, packet_type, page_scan_repetition_mode, clock_offset, clock_offset_valid, allow_role_switch); @@ -203,8 +203,8 @@ class AclManagerCertService : public AclManagerCert::Service { ::grpc::Status Disconnect(::grpc::ServerContext* context, const facade::BluetoothAddress* request, ::google::protobuf::Empty* response) override { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - common::Address::FromString(request->address(), peer); + Address peer; + Address::FromString(request->address(), peer); uint16_t handle = find_connected_device_handle_by_address(peer); if (handle == kInvalidHandle) { return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid address"); @@ -219,8 +219,8 @@ class AclManagerCertService : public AclManagerCert::Service { ::grpc::Status SendAclData(::grpc::ServerContext* context, const AclData* request, ::google::protobuf::Empty* response) override { - common::Address peer; - common::Address::FromString(request->remote().address(), peer); + Address peer; + Address::FromString(request->remote().address(), peer); auto handle = find_connected_device_handle_by_address(peer); if (handle == kInvalidHandle) { return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid address"); @@ -264,12 +264,12 @@ class AclManagerCertService : public AclManagerCert::Service { common::BidiQueueEnd<AclPacketBuilder, AclPacketView>* acl_queue_end_; os::EnqueueBuffer<AclPacketBuilder> acl_enqueue_buffer_{acl_queue_end_}; mutable std::mutex mutex_; - std::set<common::Address> accepted_devices_; - std::map<uint16_t /* handle */, common::Address> connected_devices_; + std::set<Address> accepted_devices_; + std::map<uint16_t /* handle */, Address> connected_devices_; constexpr static uint16_t kInvalidHandle = 0xffff; - uint16_t find_connected_device_handle_by_address(common::Address address) { + uint16_t find_connected_device_handle_by_address(Address address) { for (auto device : connected_devices_) { if (device.second == address) { return device.first; diff --git a/gd/common/class_of_device.cc b/gd/hci/class_of_device.cc index 8d7ff68c0..36dd2923f 100644 --- a/gd/common/class_of_device.cc +++ b/gd/hci/class_of_device.cc @@ -26,7 +26,7 @@ #include "os/log.h" namespace bluetooth { -namespace common { +namespace hci { static_assert(sizeof(ClassOfDevice) == ClassOfDevice::kLength, "ClassOfDevice must be 3 bytes long!"); @@ -36,11 +36,10 @@ ClassOfDevice::ClassOfDevice(const uint8_t (&class_of_device)[kLength]) { std::string ClassOfDevice::ToString() const { char buffer[] = "000-0-00"; - std::snprintf(&buffer[0], sizeof(buffer), - "%03x-%01x-%02x", (static_cast<uint16_t>(cod[2]) << 4) | cod[1] >> 4, cod[1] & 0x0f, cod[0]); + std::snprintf(&buffer[0], sizeof(buffer), "%03x-%01x-%02x", (static_cast<uint16_t>(cod[2]) << 4) | cod[1] >> 4, + cod[1] & 0x0f, cod[0]); std::string str(buffer); return str; - } bool ClassOfDevice::FromString(const std::string& from, ClassOfDevice& to) { @@ -94,5 +93,5 @@ bool ClassOfDevice::IsValid(const std::string& cod) { ClassOfDevice tmp; return ClassOfDevice::FromString(cod, tmp); } -} // namespace common +} // namespace hci } // namespace bluetooth diff --git a/gd/common/class_of_device.h b/gd/hci/class_of_device.h index 983f128eb..b44a45e03 100644 --- a/gd/common/class_of_device.h +++ b/gd/hci/class_of_device.h @@ -21,7 +21,7 @@ #include <string> namespace bluetooth { -namespace common { +namespace hci { class ClassOfDevice final { public: @@ -36,6 +36,10 @@ class ClassOfDevice final { return (std::memcmp(cod, rhs.cod, sizeof(cod)) == 0); } + bool operator!=(const ClassOfDevice& rhs) const { + return std::memcmp(cod, rhs.cod, sizeof(cod)) != 0; + } + std::string ToString() const; // Converts |string| to ClassOfDevice and places it in |to|. If |from| does @@ -55,5 +59,5 @@ inline std::ostream& operator<<(std::ostream& os, const ClassOfDevice& c) { return os; } -} // namespace common +} // namespace hci } // namespace bluetooth diff --git a/gd/common/class_of_device_unittest.cc b/gd/hci/class_of_device_unittest.cc index abd4a598a..85472dd31 100644 --- a/gd/common/class_of_device_unittest.cc +++ b/gd/hci/class_of_device_unittest.cc @@ -18,9 +18,9 @@ #include <gtest/gtest.h> -#include "common/class_of_device.h" +#include "hci/class_of_device.h" -using bluetooth::common::ClassOfDevice; +using bluetooth::hci::ClassOfDevice; static const char* test_class = "efc-d-ab"; static const uint8_t test_bytes[]{0xab, 0xcd, 0xef}; diff --git a/gd/hci/classic_security_manager.cc b/gd/hci/classic_security_manager.cc index 8c263d688..9f779f6f0 100644 --- a/gd/hci/classic_security_manager.cc +++ b/gd/hci/classic_security_manager.cc @@ -64,7 +64,7 @@ struct ClassicSecurityManager::impl { client_handler_ = handler; } - void link_key_request_reply(common::Address address, common::LinkKey link_key) { + void link_key_request_reply(Address address, common::LinkKey link_key) { std::array<uint8_t, 16> link_key_array; std::copy(std::begin(link_key.link_key), std::end(link_key.link_key), std::begin(link_key_array)); @@ -73,14 +73,14 @@ struct ClassicSecurityManager::impl { common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void link_key_request_negative_reply(common::Address address) { + void link_key_request_negative_reply(Address address) { std::unique_ptr<LinkKeyRequestNegativeReplyBuilder> packet = LinkKeyRequestNegativeReplyBuilder::Create(address); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void pin_code_request_reply(common::Address address, uint8_t len, std::string pin_code) { + void pin_code_request_reply(Address address, uint8_t len, std::string pin_code) { ASSERT(len > 0 && len <= 16 && pin_code.length() == len); // fill remaining char with 0 pin_code.append(std::string(16 - len, '0')); @@ -93,13 +93,13 @@ struct ClassicSecurityManager::impl { common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void pin_code_request_negative_reply(common::Address address) { + void pin_code_request_negative_reply(Address address) { std::unique_ptr<PinCodeRequestNegativeReplyBuilder> packet = PinCodeRequestNegativeReplyBuilder::Create(address); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void io_capability_request_reply(common::Address address, IoCapability io_capability, OobDataPresent oob_present, + void io_capability_request_reply(Address address, IoCapability io_capability, OobDataPresent oob_present, AuthenticationRequirements authentication_requirements) { std::unique_ptr<IoCapabilityRequestReplyBuilder> packet = IoCapabilityRequestReplyBuilder::Create(address, io_capability, oob_present, authentication_requirements); @@ -107,60 +107,60 @@ struct ClassicSecurityManager::impl { common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void io_capability_request_negative_reply(common::Address address, ErrorCode reason) { + void io_capability_request_negative_reply(Address address, ErrorCode reason) { std::unique_ptr<IoCapabilityRequestNegativeReplyBuilder> packet = IoCapabilityRequestNegativeReplyBuilder::Create(address, reason); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void user_confirmation_request_reply(common::Address address) { + void user_confirmation_request_reply(Address address) { std::unique_ptr<UserConfirmationRequestReplyBuilder> packet = UserConfirmationRequestReplyBuilder::Create(address); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void user_confirmation_request_negative_reply(common::Address address) { + void user_confirmation_request_negative_reply(Address address) { std::unique_ptr<UserConfirmationRequestNegativeReplyBuilder> packet = UserConfirmationRequestNegativeReplyBuilder::Create(address); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void user_passkey_request_reply(common::Address address, uint32_t passkey) { + void user_passkey_request_reply(Address address, uint32_t passkey) { ASSERT(passkey <= 999999); std::unique_ptr<UserPasskeyRequestReplyBuilder> packet = UserPasskeyRequestReplyBuilder::Create(address, passkey); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void user_passkey_request_negative_reply(common::Address address) { + void user_passkey_request_negative_reply(Address address) { std::unique_ptr<UserPasskeyRequestNegativeReplyBuilder> packet = UserPasskeyRequestNegativeReplyBuilder::Create(address); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void remote_oob_data_request_reply(common::Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r) { + void remote_oob_data_request_reply(Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r) { std::unique_ptr<RemoteOobDataRequestReplyBuilder> packet = RemoteOobDataRequestReplyBuilder::Create(address, c, r); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void remote_oob_data_request_negative_reply(common::Address address) { + void remote_oob_data_request_negative_reply(Address address) { std::unique_ptr<RemoteOobDataRequestNegativeReplyBuilder> packet = RemoteOobDataRequestNegativeReplyBuilder::Create(address); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void read_stored_link_key(common::Address address, ReadStoredLinkKeyReadAllFlag read_all_flag) { + void read_stored_link_key(Address address, ReadStoredLinkKeyReadAllFlag read_all_flag) { std::unique_ptr<ReadStoredLinkKeyBuilder> packet = ReadStoredLinkKeyBuilder::Create(address, read_all_flag); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void write_stored_link_key(uint8_t num_keys_to_write, common::Address address, common::LinkKey link_key) { + void write_stored_link_key(uint8_t num_keys_to_write, Address address, common::LinkKey link_key) { // TODO send multi link key std::array<uint8_t, 16> link_key_array; std::copy(std::begin(link_key.link_key), std::end(link_key.link_key), std::begin(link_key_array)); @@ -171,7 +171,7 @@ struct ClassicSecurityManager::impl { common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void delete_stored_link_key(common::Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag) { + void delete_stored_link_key(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag) { std::unique_ptr<DeleteStoredLinkKeyBuilder> packet = DeleteStoredLinkKeyBuilder::Create(address, delete_all_flag); hci_layer_->EnqueueCommand(std::move(packet), common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); @@ -201,7 +201,7 @@ struct ClassicSecurityManager::impl { common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_); } - void send_keypress_notification(common::Address address, KeypressNotificationType notification_type) { + void send_keypress_notification(Address address, KeypressNotificationType notification_type) { std::unique_ptr<SendKeypressNotificationBuilder> packet = SendKeypressNotificationBuilder::Create(address, notification_type); hci_layer_->EnqueueCommand(std::move(packet), @@ -271,73 +271,71 @@ bool ClassicSecurityManager::RegisterCallbacks(ClassicSecurityCommandCallbacks* return true; } -void ClassicSecurityManager::LinkKeyRequestReply(common::Address address, common::LinkKey link_key) { +void ClassicSecurityManager::LinkKeyRequestReply(Address address, common::LinkKey link_key) { GetHandler()->Post(BindOnce(&impl::link_key_request_reply, common::Unretained(pimpl_.get()), address, link_key)); } -void ClassicSecurityManager::LinkKeyRequestNegativeReply(common::Address address) { +void ClassicSecurityManager::LinkKeyRequestNegativeReply(Address address) { GetHandler()->Post(BindOnce(&impl::link_key_request_negative_reply, common::Unretained(pimpl_.get()), address)); } -void ClassicSecurityManager::PinCodeRequestReply(common::Address address, uint8_t len, std::string pin_code) { +void ClassicSecurityManager::PinCodeRequestReply(Address address, uint8_t len, std::string pin_code) { GetHandler()->Post(BindOnce(&impl::pin_code_request_reply, common::Unretained(pimpl_.get()), address, len, pin_code)); } -void ClassicSecurityManager::PinCodeRequestNegativeReply(common::Address address) { +void ClassicSecurityManager::PinCodeRequestNegativeReply(Address address) { GetHandler()->Post(BindOnce(&impl::pin_code_request_negative_reply, common::Unretained(pimpl_.get()), address)); } -void ClassicSecurityManager::IoCapabilityRequestReply(common::Address address, IoCapability io_capability, +void ClassicSecurityManager::IoCapabilityRequestReply(Address address, IoCapability io_capability, OobDataPresent oob_present, AuthenticationRequirements authentication_requirements) { GetHandler()->Post(BindOnce(&impl::io_capability_request_reply, common::Unretained(pimpl_.get()), address, io_capability, oob_present, authentication_requirements)); } -void ClassicSecurityManager::IoCapabilityRequestNegativeReply(common::Address address, ErrorCode reason) { +void ClassicSecurityManager::IoCapabilityRequestNegativeReply(Address address, ErrorCode reason) { GetHandler()->Post( BindOnce(&impl::io_capability_request_negative_reply, common::Unretained(pimpl_.get()), address, reason)); } -void ClassicSecurityManager::UserConfirmationRequestReply(common::Address address) { +void ClassicSecurityManager::UserConfirmationRequestReply(Address address) { GetHandler()->Post(BindOnce(&impl::user_confirmation_request_reply, common::Unretained(pimpl_.get()), address)); } -void ClassicSecurityManager::UserConfirmationRequestNegativeReply(common::Address address) { +void ClassicSecurityManager::UserConfirmationRequestNegativeReply(Address address) { GetHandler()->Post( BindOnce(&impl::user_confirmation_request_negative_reply, common::Unretained(pimpl_.get()), address)); } -void ClassicSecurityManager::UserPasskeyRequestReply(bluetooth::common::Address address, uint32_t passkey) { +void ClassicSecurityManager::UserPasskeyRequestReply(bluetooth::hci::Address address, uint32_t passkey) { GetHandler()->Post(BindOnce(&impl::user_passkey_request_reply, common::Unretained(pimpl_.get()), address, passkey)); } -void ClassicSecurityManager::UserPasskeyRequestNegativeReply(common::Address address) { +void ClassicSecurityManager::UserPasskeyRequestNegativeReply(Address address) { GetHandler()->Post(BindOnce(&impl::user_passkey_request_negative_reply, common::Unretained(pimpl_.get()), address)); } -void ClassicSecurityManager::RemoteOobDataRequestReply(common::Address address, std::array<uint8_t, 16> c, +void ClassicSecurityManager::RemoteOobDataRequestReply(Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r) { GetHandler()->Post(BindOnce(&impl::remote_oob_data_request_reply, common::Unretained(pimpl_.get()), address, c, r)); } -void ClassicSecurityManager::RemoteOobDataRequestNegativeReply(common::Address address) { +void ClassicSecurityManager::RemoteOobDataRequestNegativeReply(Address address) { GetHandler()->Post( BindOnce(&impl::remote_oob_data_request_negative_reply, common::Unretained(pimpl_.get()), address)); } -void ClassicSecurityManager::ReadStoredLinkKey(common::Address address, ReadStoredLinkKeyReadAllFlag read_all_flag) { +void ClassicSecurityManager::ReadStoredLinkKey(Address address, ReadStoredLinkKeyReadAllFlag read_all_flag) { GetHandler()->Post(BindOnce(&impl::read_stored_link_key, common::Unretained(pimpl_.get()), address, read_all_flag)); } -void ClassicSecurityManager::WriteStoredLinkKey(uint8_t num_keys_to_write, common::Address address, - common::LinkKey link_key) { +void ClassicSecurityManager::WriteStoredLinkKey(uint8_t num_keys_to_write, Address address, common::LinkKey link_key) { GetHandler()->Post( BindOnce(&impl::write_stored_link_key, common::Unretained(pimpl_.get()), num_keys_to_write, address, link_key)); } -void ClassicSecurityManager::DeleteStoredLinkKey(common::Address address, - DeleteStoredLinkKeyDeleteAllFlag delete_all_flag) { +void ClassicSecurityManager::DeleteStoredLinkKey(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag) { GetHandler()->Post( BindOnce(&impl::delete_stored_link_key, common::Unretained(pimpl_.get()), address, delete_all_flag)); } @@ -357,8 +355,7 @@ void ClassicSecurityManager::ReadLocalOobData() { GetHandler()->Post(BindOnce(&impl::read_local_oob_data, common::Unretained(pimpl_.get()))); } -void ClassicSecurityManager::SendKeypressNotification(common::Address address, - KeypressNotificationType notification_type) { +void ClassicSecurityManager::SendKeypressNotification(Address address, KeypressNotificationType notification_type) { GetHandler()->Post( BindOnce(&impl::send_keypress_notification, common::Unretained(pimpl_.get()), address, notification_type)); } diff --git a/gd/hci/classic_security_manager.h b/gd/hci/classic_security_manager.h index 20e2d157d..90289682d 100644 --- a/gd/hci/classic_security_manager.h +++ b/gd/hci/classic_security_manager.h @@ -16,8 +16,8 @@ #pragma once -#include "common/address.h" #include "common/link_key.h" +#include "hci/address.h" #include "hci/hci_packets.h" #include "module.h" @@ -37,27 +37,27 @@ class ClassicSecurityManager : public Module { bool RegisterCallbacks(ClassicSecurityCommandCallbacks* callbacks, os::Handler* handler); - void LinkKeyRequestReply(common::Address address, common::LinkKey link_key); - void LinkKeyRequestNegativeReply(common::Address address); - void PinCodeRequestReply(common::Address address, uint8_t len, std::string pin_code); - void PinCodeRequestNegativeReply(common::Address address); - void IoCapabilityRequestReply(common::Address address, IoCapability io_capability, OobDataPresent oob_present, + void LinkKeyRequestReply(Address address, common::LinkKey link_key); + void LinkKeyRequestNegativeReply(Address address); + void PinCodeRequestReply(Address address, uint8_t len, std::string pin_code); + void PinCodeRequestNegativeReply(Address address); + void IoCapabilityRequestReply(Address address, IoCapability io_capability, OobDataPresent oob_present, AuthenticationRequirements authentication_requirements); - void IoCapabilityRequestNegativeReply(common::Address address, ErrorCode reason); - void UserConfirmationRequestReply(common::Address address); - void UserConfirmationRequestNegativeReply(common::Address address); - void UserPasskeyRequestReply(common::Address address, uint32_t passkey); - void UserPasskeyRequestNegativeReply(common::Address address); - void RemoteOobDataRequestReply(common::Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r); - void RemoteOobDataRequestNegativeReply(common::Address address); - void ReadStoredLinkKey(common::Address address, ReadStoredLinkKeyReadAllFlag read_all_flag); - void WriteStoredLinkKey(uint8_t num_keys_to_write, common::Address address, common::LinkKey link_key); - void DeleteStoredLinkKey(common::Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag); + void IoCapabilityRequestNegativeReply(Address address, ErrorCode reason); + void UserConfirmationRequestReply(Address address); + void UserConfirmationRequestNegativeReply(Address address); + void UserPasskeyRequestReply(Address address, uint32_t passkey); + void UserPasskeyRequestNegativeReply(Address address); + void RemoteOobDataRequestReply(Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r); + void RemoteOobDataRequestNegativeReply(Address address); + void ReadStoredLinkKey(Address address, ReadStoredLinkKeyReadAllFlag read_all_flag); + void WriteStoredLinkKey(uint8_t num_keys_to_write, Address address, common::LinkKey link_key); + void DeleteStoredLinkKey(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag); void RefreshEncryptionKey(uint16_t connection_handle); void ReadSimplePairingMode(); void WriteSimplePairingMode(Enable simple_pairing_mode); void ReadLocalOobData(); - void SendKeypressNotification(common::Address address, KeypressNotificationType notification_type); + void SendKeypressNotification(Address address, KeypressNotificationType notification_type); void ReadLocalOobExtendedData(); void ReadEncryptionKeySize(uint16_t connection_handle); diff --git a/gd/hci/controller.cc b/gd/hci/controller.cc index 2637a99d2..3dbe0a5ee 100644 --- a/gd/hci/controller.cc +++ b/gd/hci/controller.cc @@ -112,7 +112,7 @@ struct Controller::impl { uint16_t acl_buffers_ = 0; uint8_t sco_buffer_length_ = 0; uint16_t sco_buffers_ = 0; - common::Address mac_address_; + Address mac_address_; }; // namespace hci Controller::Controller() : impl_(std::make_unique<impl>(*this)) {} @@ -140,7 +140,7 @@ uint16_t Controller::GetControllerNumScoPacketBuffers() { return impl_->sco_buffers_; } -common::Address Controller::GetControllerMacAddress() { +Address Controller::GetControllerMacAddress() { return impl_->mac_address_; } diff --git a/gd/hci/controller.h b/gd/hci/controller.h index b3e70f2d6..f7e9397e6 100644 --- a/gd/hci/controller.h +++ b/gd/hci/controller.h @@ -16,8 +16,8 @@ #pragma once -#include "common/address.h" #include "common/callback.h" +#include "hci/address.h" #include "hci/hci_packets.h" #include "module.h" #include "os/handler.h" @@ -42,7 +42,7 @@ class Controller : public Module { virtual uint16_t GetControllerNumScoPacketBuffers(); - virtual common::Address GetControllerMacAddress(); + virtual Address GetControllerMacAddress(); static const ModuleFactory Factory; diff --git a/gd/hci/controller_test.cc b/gd/hci/controller_test.cc index 377a011db..8612a1dd9 100644 --- a/gd/hci/controller_test.cc +++ b/gd/hci/controller_test.cc @@ -23,9 +23,9 @@ #include <gtest/gtest.h> -#include "common/address.h" #include "common/bind.h" #include "common/callback.h" +#include "hci/address.h" #include "hci/hci_layer.h" #include "os/thread.h" #include "packet/raw_builder.h" @@ -34,7 +34,6 @@ namespace bluetooth { namespace hci { namespace { -using common::Address; using common::BidiQueue; using common::BidiQueueEnd; using packet::kLittleEndian; @@ -82,7 +81,7 @@ class TestHciLayer : public HciLayer { total_num_acl_data_packets, total_num_synchronous_data_packets); } break; case (OpCode::READ_BD_ADDR): { - event_builder = ReadBdAddrCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, common::Address::kAny); + event_builder = ReadBdAddrCompleteBuilder::Create(num_packets, ErrorCode::SUCCESS, Address::kAny); } break; default: LOG_INFO("Dropping unhandled packet"); @@ -163,7 +162,7 @@ TEST_F(ControllerTest, read_controller_info) { ASSERT_EQ(controller_->GetControllerNumAclPacketBuffers(), test_hci_layer_->total_num_acl_data_packets); ASSERT_EQ(controller_->GetControllerScoPacketLength(), test_hci_layer_->synchronous_data_packet_length); ASSERT_EQ(controller_->GetControllerNumScoPacketBuffers(), test_hci_layer_->total_num_synchronous_data_packets); - ASSERT_EQ(controller_->GetControllerMacAddress(), common::Address::kAny); + ASSERT_EQ(controller_->GetControllerMacAddress(), Address::kAny); } std::promise<void> credits1_set; diff --git a/gd/hci/facade.cc b/gd/hci/facade.cc index a35297d44..f8cc7ccf4 100644 --- a/gd/hci/facade.cc +++ b/gd/hci/facade.cc @@ -75,8 +75,8 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public ::bluet ::grpc::Status Connect(::grpc::ServerContext* context, const facade::BluetoothAddress* remote, ::google::protobuf::Empty* response) override { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(remote->address(), peer)); + Address peer; + ASSERT(Address::FromString(remote->address(), peer)); acl_manager_->CreateConnection(peer); return ::grpc::Status::OK; } @@ -84,8 +84,8 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public ::bluet ::grpc::Status Disconnect(::grpc::ServerContext* context, const facade::BluetoothAddress* request, ::google::protobuf::Empty* response) override { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - common::Address::FromString(request->address(), peer); + Address peer; + Address::FromString(request->address(), peer); auto connection = acl_connections_.find(request->address()); if (connection == acl_connections_.end()) { LOG_ERROR("Invalid address"); @@ -163,7 +163,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public ::bluet return connection_complete_stream_.HandleRequest(context, request, writer); }; - void OnConnectFail(::bluetooth::common::Address address, ::bluetooth::hci::ErrorCode reason) override { + void OnConnectFail(Address address, ::bluetooth::hci::ErrorCode reason) override { std::unique_lock<std::mutex> lock(mutex_); ConnectionFailedEvent event; event.mutable_remote()->set_address(address.ToString()); @@ -309,9 +309,9 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::LinkKeyRequestReplyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; + Address peer; common::LinkKey link_key; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + ASSERT(Address::FromString(request->remote().address(), peer)); ASSERT(common::LinkKey::FromString(request->link_key(), link_key)); classic_security_manager_->LinkKeyRequestReply(peer, link_key); return ::grpc::Status::OK; @@ -321,8 +321,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::facade::BluetoothAddress* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->address(), peer)); + Address peer; + ASSERT(Address::FromString(request->address(), peer)); classic_security_manager_->LinkKeyRequestNegativeReply(peer); return ::grpc::Status::OK; } @@ -331,8 +331,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::PinCodeRequestReplyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); uint8_t len = request->len(); std::string pin_code = request->pin_code(); classic_security_manager_->PinCodeRequestReply(peer, len, pin_code); @@ -343,8 +343,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::facade::BluetoothAddress* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->address(), peer)); + Address peer; + ASSERT(Address::FromString(request->address(), peer)); classic_security_manager_->PinCodeRequestNegativeReply(peer); return ::grpc::Status::OK; } @@ -353,8 +353,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::IoCapabilityRequestReplyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); IoCapability io_capability = (IoCapability)request->io_capability(); OobDataPresent oob_present = (OobDataPresent)request->oob_present(); AuthenticationRequirements authentication_requirements = @@ -367,8 +367,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: ::grpc::ServerContext* context, const ::bluetooth::hci::IoCapabilityRequestNegativeReplyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); ErrorCode reason = (ErrorCode)request->reason(); classic_security_manager_->IoCapabilityRequestNegativeReply(peer, reason); return ::grpc::Status::OK; @@ -378,8 +378,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::facade::BluetoothAddress* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->address(), peer)); + Address peer; + ASSERT(Address::FromString(request->address(), peer)); classic_security_manager_->UserConfirmationRequestReply(peer); return ::grpc::Status::OK; } @@ -388,8 +388,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::facade::BluetoothAddress* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->address(), peer)); + Address peer; + ASSERT(Address::FromString(request->address(), peer)); classic_security_manager_->UserConfirmationRequestNegativeReply(peer); return ::grpc::Status::OK; } @@ -398,8 +398,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::UserPasskeyRequestReplyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); uint32_t passkey = request->passkey(); classic_security_manager_->UserPasskeyRequestReply(peer, passkey); return ::grpc::Status::OK; @@ -409,8 +409,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::facade::BluetoothAddress* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->address(), peer)); + Address peer; + ASSERT(Address::FromString(request->address(), peer)); classic_security_manager_->UserPasskeyRequestNegativeReply(peer); return ::grpc::Status::OK; } @@ -419,8 +419,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::RemoteOobDataRequestReplyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); std::string c_string = request->c(); std::string r_string = request->r(); std::array<uint8_t, 16> c; @@ -435,8 +435,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::facade::BluetoothAddress* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->address(), peer)); + Address peer; + ASSERT(Address::FromString(request->address(), peer)); classic_security_manager_->RemoteOobDataRequestNegativeReply(peer); return ::grpc::Status::OK; } @@ -445,8 +445,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::ReadStoredLinkKeyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); ReadStoredLinkKeyReadAllFlag read_all_flag = (ReadStoredLinkKeyReadAllFlag)request->read_all_flag(); classic_security_manager_->ReadStoredLinkKey(peer, read_all_flag); return ::grpc::Status::OK; @@ -457,9 +457,9 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); uint8_t num_keys_to_write = request->num_keys_to_write(); - common::Address peer; + Address peer; common::LinkKey link_key; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + ASSERT(Address::FromString(request->remote().address(), peer)); ASSERT(common::LinkKey::FromString(request->link_keys(), link_key)); classic_security_manager_->WriteStoredLinkKey(num_keys_to_write, peer, link_key); @@ -470,8 +470,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::DeleteStoredLinkKeyMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); DeleteStoredLinkKeyDeleteAllFlag delete_all_flag = (DeleteStoredLinkKeyDeleteAllFlag)request->delete_all_flag(); classic_security_manager_->DeleteStoredLinkKey(peer, delete_all_flag); return ::grpc::Status::OK; @@ -512,8 +512,8 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade: const ::bluetooth::hci::SendKeypressNotificationMessage* request, ::google::protobuf::Empty* response) { std::unique_lock<std::mutex> lock(mutex_); - common::Address peer; - ASSERT(common::Address::FromString(request->remote().address(), peer)); + Address peer; + ASSERT(Address::FromString(request->remote().address(), peer)); KeypressNotificationType notification_type = (KeypressNotificationType)request->notification_type(); classic_security_manager_->SendKeypressNotification(peer, notification_type); return ::grpc::Status::OK; diff --git a/gd/hci/hci_layer.cc b/gd/hci/hci_layer.cc index 7f8678598..9ba0d7532 100644 --- a/gd/hci/hci_layer.cc +++ b/gd/hci/hci_layer.cc @@ -77,7 +77,6 @@ class CommandQueueEntry { namespace bluetooth { namespace hci { -using common::Address; using common::BidiQueue; using common::BidiQueueEnd; using os::Alarm; diff --git a/gd/hci/hci_layer.h b/gd/hci/hci_layer.h index e0c55ddaa..8900ff7fb 100644 --- a/gd/hci/hci_layer.h +++ b/gd/hci/hci_layer.h @@ -19,10 +19,10 @@ #include <chrono> #include <map> -#include "common/address.h" +#include "address.h" +#include "class_of_device.h" #include "common/bidi_queue.h" #include "common/callback.h" -#include "common/class_of_device.h" #include "hal/hci_hal.h" #include "hci/hci_packets.h" #include "module.h" diff --git a/gd/hci/hci_layer_test.cc b/gd/hci/hci_layer_test.cc index 7d3fd77de..ce8df2d7f 100644 --- a/gd/hci/hci_layer_test.cc +++ b/gd/hci/hci_layer_test.cc @@ -481,8 +481,8 @@ TEST_F(HciTest, creditsTest) { TEST_F(HciTest, createConnectionTest) { // Send CreateConnection to the controller auto command_future = hal->GetSentCommandFuture(); - common::Address bd_addr; - ASSERT_TRUE(common::Address::FromString("A1:A2:A3:A4:A5:A6", bd_addr)); + Address bd_addr; + ASSERT_TRUE(Address::FromString("A1:A2:A3:A4:A5:A6", bd_addr)); uint16_t packet_type = 0x1234; PageScanRepetitionMode page_scan_repetition_mode = PageScanRepetitionMode::R0; uint16_t clock_offset = 0x3456; @@ -583,8 +583,8 @@ TEST_F(HciTest, createConnectionTest) { } TEST_F(HciTest, receiveMultipleAclPackets) { - common::Address bd_addr; - ASSERT_TRUE(common::Address::FromString("A1:A2:A3:A4:A5:A6", bd_addr)); + Address bd_addr; + ASSERT_TRUE(Address::FromString("A1:A2:A3:A4:A5:A6", bd_addr)); uint16_t handle = 0x0001; uint16_t num_packets = 100; PacketBoundaryFlag packet_boundary_flag = PacketBoundaryFlag::COMPLETE_PDU; diff --git a/gd/hci/hci_packets.pdl b/gd/hci/hci_packets.pdl index 036bcec1b..2d33815ea 100644 --- a/gd/hci/hci_packets.pdl +++ b/gd/hci/hci_packets.pdl @@ -1,7 +1,7 @@ little_endian_packets -custom_field Address : 48 "common/" -custom_field ClassOfDevice : 24 "common/" +custom_field Address : 48 "hci/" +custom_field ClassOfDevice : 24 "hci/" enum Enable : 8 { DISABLED = 0x00, diff --git a/gd/l2cap/classic_fixed_channel_manager.cc b/gd/l2cap/classic_fixed_channel_manager.cc index 3cd66175c..af4443597 100644 --- a/gd/l2cap/classic_fixed_channel_manager.cc +++ b/gd/l2cap/classic_fixed_channel_manager.cc @@ -22,7 +22,7 @@ namespace bluetooth { namespace l2cap { -bool ClassicFixedChannelManager::ConnectServices(common::Address device, OnConnectionFailureCallback on_fail_callback, +bool ClassicFixedChannelManager::ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback, os::Handler* handler) { internal::ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{ .on_fail_callback_ = std::move(on_fail_callback), .handler_ = handler}; @@ -46,4 +46,4 @@ bool ClassicFixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& } } // namespace l2cap -} // namespace bluetooth
\ No newline at end of file +} // namespace bluetooth diff --git a/gd/l2cap/classic_fixed_channel_manager.h b/gd/l2cap/classic_fixed_channel_manager.h index 4d4b9ae42..88691f8ed 100644 --- a/gd/l2cap/classic_fixed_channel_manager.h +++ b/gd/l2cap/classic_fixed_channel_manager.h @@ -17,8 +17,8 @@ #include <string> -#include "common/address.h" #include "hci/acl_manager.h" +#include "hci/address.h" #include "l2cap/cid.h" #include "l2cap/classic_fixed_channel.h" #include "l2cap/classic_fixed_channel_service.h" @@ -101,7 +101,7 @@ class ClassicFixedChannelManager { * * Returns: true if connection was able to be initiated, false otherwise. */ - bool ConnectServices(common::Address device, OnConnectionFailureCallback on_fail_callback, os::Handler* handler); + bool ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback, os::Handler* handler); /** * Register a service to receive incoming connections bound to a specific channel. @@ -141,4 +141,4 @@ class ClassicFixedChannelManager { }; } // namespace l2cap -} // namespace bluetooth
\ No newline at end of file +} // namespace bluetooth diff --git a/gd/l2cap/classic_fixed_channel_service.h b/gd/l2cap/classic_fixed_channel_service.h index 036a048b9..1e0a763ca 100644 --- a/gd/l2cap/classic_fixed_channel_service.h +++ b/gd/l2cap/classic_fixed_channel_service.h @@ -16,8 +16,8 @@ */ #pragma once -#include "common/address.h" #include "common/callback.h" +#include "hci/address.h" #include "l2cap/cid.h" #include "os/handler.h" @@ -54,4 +54,4 @@ class ClassicFixedChannelService { }; } // namespace l2cap -} // namespace bluetooth
\ No newline at end of file +} // namespace bluetooth diff --git a/gd/l2cap/facade.cc b/gd/l2cap/facade.cc index 50b2d6031..f1a6012d6 100644 --- a/gd/l2cap/facade.cc +++ b/gd/l2cap/facade.cc @@ -16,9 +16,9 @@ #include <cstdint> #include <unordered_map> -#include "common/address.h" #include "common/bind.h" #include "grpc/grpc_event_stream.h" +#include "hci/address.h" #include "l2cap/facade.grpc.pb.h" #include "l2cap/facade.h" #include "l2cap/l2cap_layer.h" diff --git a/gd/l2cap/internal/classic_link_manager.cc b/gd/l2cap/internal/classic_link_manager.cc index b174ed681..bda953bb2 100644 --- a/gd/l2cap/internal/classic_link_manager.cc +++ b/gd/l2cap/internal/classic_link_manager.cc @@ -17,6 +17,7 @@ #include <unordered_map> #include "hci/acl_manager.h" +#include "hci/address.h" #include "l2cap/internal/classic_link.h" #include "l2cap/internal/scheduler_fifo.h" #include "l2cap/l2cap_layer.h" @@ -29,7 +30,7 @@ namespace bluetooth { namespace l2cap { namespace internal { -void ClassicLinkManager::ConnectFixedChannelServices(common::Address device, +void ClassicLinkManager::ConnectFixedChannelServices(hci::Address device, PendingFixedChannelConnection pending_fixed_channel_connection) { // Check if there is any service registered auto fixed_channel_services = service_manager_->GetRegisteredServices(); @@ -82,7 +83,7 @@ void ClassicLinkManager::ConnectFixedChannelServices(common::Address device, acl_manager_->CreateConnection(device); } -ClassicLink* ClassicLinkManager::GetLink(const common::Address device) { +ClassicLink* ClassicLinkManager::GetLink(const hci::Address device) { if (links_.find(device) == links_.end()) { return nullptr; } @@ -91,7 +92,7 @@ ClassicLink* ClassicLinkManager::GetLink(const common::Address device) { void ClassicLinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) { // Same link should not be connected twice - common::Address address = acl_connection->GetAddress(); + hci::Address address = acl_connection->GetAddress(); ASSERT_LOG(GetLink(address) == nullptr, "%s is connected twice without disconnection", acl_connection->GetAddress().ToString().c_str()); auto* link_queue_up_end = acl_connection->GetAclQueueEnd(); @@ -114,7 +115,7 @@ void ClassicLinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> ac pending_links_.erase(pending_link); } -void ClassicLinkManager::OnConnectFail(common::Address device, hci::ErrorCode reason) { +void ClassicLinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reason) { // Notify all pending links for this device auto pending_link = pending_links_.find(device); if (pending_link == pending_links_.end()) { @@ -132,10 +133,10 @@ void ClassicLinkManager::OnConnectFail(common::Address device, hci::ErrorCode re pending_links_.erase(pending_link); } -void ClassicLinkManager::OnDisconnect(common::Address device, hci::ErrorCode status) { +void ClassicLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) { links_.erase(device); } } // namespace internal } // namespace l2cap -} // namespace bluetooth
\ No newline at end of file +} // namespace bluetooth diff --git a/gd/l2cap/internal/classic_link_manager.h b/gd/l2cap/internal/classic_link_manager.h index e578d02d6..c07c85259 100644 --- a/gd/l2cap/internal/classic_link_manager.h +++ b/gd/l2cap/internal/classic_link_manager.h @@ -28,6 +28,7 @@ #include "l2cap/internal/scheduler.h" #include "hci/acl_manager.h" +#include "hci/address.h" namespace bluetooth { namespace l2cap { @@ -50,13 +51,12 @@ class ClassicLinkManager : public hci::ConnectionCallbacks { std::vector<PendingFixedChannelConnection> pending_fixed_channel_connections_; }; - void ConnectFixedChannelServices(common::Address device, - PendingFixedChannelConnection pending_fixed_channel_connection); + void ConnectFixedChannelServices(hci::Address device, PendingFixedChannelConnection pending_fixed_channel_connection); - ClassicLink* GetLink(common::Address device); + ClassicLink* GetLink(hci::Address device); void OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) override; - void OnConnectFail(common::Address device, hci::ErrorCode reason) override; - void OnDisconnect(common::Address device, hci::ErrorCode status); + void OnConnectFail(hci::Address device, hci::ErrorCode reason) override; + void OnDisconnect(hci::Address device, hci::ErrorCode status); private: // Dependencies @@ -65,11 +65,11 @@ class ClassicLinkManager : public hci::ConnectionCallbacks { ClassicFixedChannelServiceManagerImpl* service_manager_; // Internal states - std::unordered_map<common::Address, PendingLink> pending_links_; - std::unordered_map<common::Address, ClassicLink> links_; + std::unordered_map<hci::Address, PendingLink> pending_links_; + std::unordered_map<hci::Address, ClassicLink> links_; DISALLOW_COPY_AND_ASSIGN(ClassicLinkManager); }; } // namespace internal } // namespace l2cap -} // namespace bluetooth
\ No newline at end of file +} // namespace bluetooth diff --git a/gd/l2cap/internal/classic_link_manager_test.cc b/gd/l2cap/internal/classic_link_manager_test.cc index 04295513e..5992b2e00 100644 --- a/gd/l2cap/internal/classic_link_manager_test.cc +++ b/gd/l2cap/internal/classic_link_manager_test.cc @@ -21,6 +21,7 @@ #include "common/bind.h" #include "common/testing/bind_test_util.h" #include "hci/acl_manager_mock.h" +#include "hci/address.h" #include "l2cap/cid.h" #include "l2cap/classic_fixed_channel_manager.h" #include "l2cap/internal/classic_fixed_channel_service_impl_mock.h" @@ -75,7 +76,7 @@ class L2capClassicLinkManagerTest : public ::testing::Test { TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) { MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager; MockAclManager mock_acl_manager; - common::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; + hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; auto user_handler = std::make_unique<os::Handler>(thread_); // Step 1: Verify callback registration with HCI @@ -151,7 +152,7 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) { TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_with_no_service) { MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager; MockAclManager mock_acl_manager; - common::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; + hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; auto user_handler = std::make_unique<os::Handler>(thread_); // Step 1: Verify callback registration with HCI @@ -186,7 +187,7 @@ TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_wi TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_with_hci_failure) { MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager; MockAclManager mock_acl_manager; - common::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; + hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}; auto user_handler = std::make_unique<os::Handler>(thread_); // Step 1: Verify callback registration with HCI diff --git a/gd/l2cap/l2cap_layer.cc b/gd/l2cap/l2cap_layer.cc index 315101ed6..087e58c30 100644 --- a/gd/l2cap/l2cap_layer.cc +++ b/gd/l2cap/l2cap_layer.cc @@ -17,9 +17,9 @@ #include <memory> -#include "common/address.h" #include "common/bidi_queue.h" #include "hci/acl_manager.h" +#include "hci/address.h" #include "hci/hci_packets.h" #include "l2cap/internal/classic_fixed_channel_service_manager_impl.h" #include "l2cap/internal/classic_link_manager.h" diff --git a/gd/packet/packet_view_unittest.cc b/gd/packet/packet_view_unittest.cc index fd96fd7f2..5927ac14c 100644 --- a/gd/packet/packet_view_unittest.cc +++ b/gd/packet/packet_view_unittest.cc @@ -20,9 +20,9 @@ #include <forward_list> #include <memory> -#include "common/address.h" +#include "hci/address.h" -using bluetooth::common::Address; +using bluetooth::hci::Address; using bluetooth::packet::PacketView; using bluetooth::packet::View; using std::vector; diff --git a/gd/packet/raw_builder.cc b/gd/packet/raw_builder.cc index fd6141773..78edd6202 100644 --- a/gd/packet/raw_builder.cc +++ b/gd/packet/raw_builder.cc @@ -20,8 +20,8 @@ #include "os/log.h" +using bluetooth::hci::Address; using std::vector; -using bluetooth::common::Address; namespace bluetooth { namespace packet { diff --git a/gd/packet/raw_builder.h b/gd/packet/raw_builder.h index 8f9edf504..1a7485aae 100644 --- a/gd/packet/raw_builder.h +++ b/gd/packet/raw_builder.h @@ -19,7 +19,7 @@ #include <cstdint> #include <vector> -#include "common/address.h" +#include "hci/address.h" #include "packet/bit_inserter.h" #include "packet/packet_builder.h" @@ -38,7 +38,7 @@ class RawBuilder : public PacketBuilder<true> { // Add |address| to the payload. Return true if: // - the new size of the payload is still <= |max_bytes_| - bool AddAddress(const common::Address& address); + bool AddAddress(const hci::Address& address); // Return true if |num_bytes| can be added to the payload. bool CanAddOctets(size_t num_bytes) const; diff --git a/gd/packet/raw_builder_unittest.cc b/gd/packet/raw_builder_unittest.cc index 27cecd602..5210fb641 100644 --- a/gd/packet/raw_builder_unittest.cc +++ b/gd/packet/raw_builder_unittest.cc @@ -20,9 +20,9 @@ #include <forward_list> #include <memory> -#include "common/address.h" +#include "hci/address.h" -using bluetooth::common::Address; +using bluetooth::hci::Address; using bluetooth::packet::BitInserter; using std::vector; |