Loading system/gd/hci/acl_manager.cc +23 −3 Original line number Diff line number Diff line Loading @@ -212,6 +212,9 @@ struct AclManager::impl : public security::ISecurityManagerListener { hci_layer_->RegisterEventHandler(EventCode::LINK_SUPERVISION_TIMEOUT_CHANGED, Bind(&impl::on_link_supervision_timeout_changed, common::Unretained(this)), handler_); le_initiator_address_ = AddressWithType(Address{{0x00, 0x11, 0xFF, 0xFF, 0x33, 0x22}}, AddressType::RANDOM_DEVICE_ADDRESS); } void Stop() { Loading Loading @@ -994,7 +997,7 @@ struct AclManager::impl : public security::ISecurityManagerListener { uint16_t le_scan_interval = 0x0060; uint16_t le_scan_window = 0x0030; InitiatorFilterPolicy initiator_filter_policy = InitiatorFilterPolicy::USE_PEER_ADDRESS; OwnAddressType own_address_type = OwnAddressType::RANDOM_DEVICE_ADDRESS; OwnAddressType own_address_type = static_cast<OwnAddressType>(le_initiator_address_.GetAddressType()); uint16_t conn_interval_min = 0x0018; uint16_t conn_interval_max = 0x0028; uint16_t conn_latency = 0x0000; Loading @@ -1018,8 +1021,10 @@ struct AclManager::impl : public security::ISecurityManagerListener { // With real controllers, we must set random address before using it to establish connection // TODO: have separate state machine generate new address when needed, consider using auto-generation in // controller hci_layer_->EnqueueCommand(hci::LeSetRandomAddressBuilder::Create(Address{{0x00, 0x11, 0xFF, 0xFF, 0x33, 0x22}}), if (own_address_type == OwnAddressType::RANDOM_DEVICE_ADDRESS) { hci_layer_->EnqueueCommand(hci::LeSetRandomAddressBuilder::Create(le_initiator_address_.GetAddress()), common::BindOnce([](CommandCompleteView status) {}), handler_); } hci_layer_->EnqueueCommand(LeExtendedCreateConnectionBuilder::Create( initiator_filter_policy, own_address_type, address_with_type.GetAddressType(), Loading @@ -1043,6 +1048,15 @@ struct AclManager::impl : public security::ISecurityManagerListener { } } void set_le_initiator_address(AddressWithType le_initiator_address) { le_initiator_address_ = le_initiator_address; if (le_initiator_address_.GetAddressType() != AddressType::RANDOM_DEVICE_ADDRESS) { // Usually controllers provide vendor-specific way to override public address. Implement it if it's ever needed. LOG_ALWAYS_FATAL("Don't know how to use this type of address"); } } void cancel_connect(Address address) { auto connecting_addr = connecting_.find(address); if (connecting_addr == connecting_.end()) { Loading Loading @@ -1817,6 +1831,7 @@ struct AclManager::impl : public security::ISecurityManagerListener { common::Callback<bool(Address, ClassOfDevice)> should_accept_connection_; std::queue<std::pair<Address, std::unique_ptr<CreateConnectionBuilder>>> pending_outgoing_connections_; uint16_t default_link_policy_settings_ = 0; AddressWithType le_initiator_address_; }; AclConnection::QueueUpEnd* AclConnection::GetAclQueueEnd() const { Loading Loading @@ -2009,6 +2024,11 @@ void AclManager::CreateLeConnection(AddressWithType address_with_type) { common::BindOnce(&impl::create_le_connection, common::Unretained(pimpl_.get()), address_with_type)); } void AclManager::SetLeInitiatorAddress(AddressWithType initiator_address) { GetHandler()->Post( common::BindOnce(&impl::set_le_initiator_address, common::Unretained(pimpl_.get()), initiator_address)); } void AclManager::CancelConnect(Address address) { GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address)); } Loading system/gd/hci/acl_manager.h +2 −0 Original line number Diff line number Diff line Loading @@ -260,6 +260,8 @@ class AclManager : public Module { // Generates OnLeConnectSuccess if connected, or OnLeConnectFail otherwise virtual void CreateLeConnection(AddressWithType address_with_type); virtual void SetLeInitiatorAddress(AddressWithType initiator_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(Address address); Loading system/gd/hci/facade/le_acl_manager_facade.cc +9 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,15 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, return ::grpc::Status::OK; } ::grpc::Status SetInitiatorAddress(::grpc::ServerContext* context, const ::bluetooth::facade::BluetoothAddressWithType* request, ::google::protobuf::Empty* writer) override { Address address; ASSERT(Address::FromString(request->address().address(), address)); acl_manager_->SetLeInitiatorAddress(AddressWithType(address, static_cast<AddressType>(request->type()))); return ::grpc::Status::OK; } std::unique_ptr<BasePacketBuilder> enqueue_packet(const LeAclData* request, std::promise<void> promise) { acl_connections_[request->handle()]->GetAclQueueEnd()->UnregisterEnqueue(); std::unique_ptr<RawBuilder> packet = Loading system/gd/hci/facade/le_acl_manager_facade.proto +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ syntax = "proto3"; package bluetooth.hci; import "google/protobuf/empty.proto"; import "facade/common.proto"; service LeAclManagerFacade { rpc CreateConnection(LeConnectionMsg) returns (stream LeConnectionEvent) {} Loading @@ -11,6 +12,7 @@ service LeAclManagerFacade { rpc SendAclData(LeAclData) returns (google.protobuf.Empty) {} rpc FetchAclData(google.protobuf.Empty) returns (stream LeAclData) {} rpc FetchIncomingConnection(google.protobuf.Empty) returns (stream LeConnectionEvent) {} rpc SetInitiatorAddress(bluetooth.facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {} } message LeHandleMsg { Loading system/gd/l2cap/le/cert/dual_l2cap_test.py +9 −8 Original line number Diff line number Diff line Loading @@ -48,6 +48,13 @@ class DualL2capTest(GdBaseTestClass): self.cert_l2cap = CertL2cap(self.cert) self.dut_le_l2cap = PyLeL2cap(self.dut) self.cert_le_l2cap = CertLeL2cap(self.cert) self.dut_le_address = common.BluetoothAddressWithType( address = common.BluetoothAddress(address=bytes(b'0D:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_address = common.BluetoothAddressWithType( address = common.BluetoothAddress(address=bytes(b'55:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_le_l2cap._device.hci_le_acl_manager.SetInitiatorAddress(self.cert_address) def teardown_test(self): self.cert_le_l2cap.close() Loading @@ -68,15 +75,9 @@ class DualL2capTest(GdBaseTestClass): gap_name.data = list(bytes(b'Im_The_DUT')) gap_data = le_advertising_facade.GapDataMsg( data=bytes(gap_name.Serialize())) self.dut_address = common.BluetoothAddressWithType( address = common.BluetoothAddress(address=bytes(b'0D:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_address = common.BluetoothAddressWithType( address=common.BluetoothAddress(address=b"22:33:ff:ff:11:00"), type=common.RANDOM_DEVICE_ADDRESS) config = le_advertising_facade.AdvertisingConfig( advertisement=[gap_data], random_address=self.dut_address.address, random_address=self.dut_le_address.address, interval_min=512, interval_max=768, event_type=le_advertising_facade.AdvertisingEventType.ADV_IND, Loading @@ -90,7 +91,7 @@ class DualL2capTest(GdBaseTestClass): request = le_advertising_facade.CreateAdvertiserRequest(config=config) create_response = self.dut.hci_le_advertising_manager.CreateAdvertiser( request) self.cert_le_l2cap.connect_le_acl(self.dut_address) self.cert_le_l2cap.connect_le_acl(self.dut_le_address) def _open_le_coc_from_dut(self, psm=0x33, our_scid=None): response_future = self.dut_le_l2cap.connect_coc_to_cert(self.cert_address, psm) Loading Loading
system/gd/hci/acl_manager.cc +23 −3 Original line number Diff line number Diff line Loading @@ -212,6 +212,9 @@ struct AclManager::impl : public security::ISecurityManagerListener { hci_layer_->RegisterEventHandler(EventCode::LINK_SUPERVISION_TIMEOUT_CHANGED, Bind(&impl::on_link_supervision_timeout_changed, common::Unretained(this)), handler_); le_initiator_address_ = AddressWithType(Address{{0x00, 0x11, 0xFF, 0xFF, 0x33, 0x22}}, AddressType::RANDOM_DEVICE_ADDRESS); } void Stop() { Loading Loading @@ -994,7 +997,7 @@ struct AclManager::impl : public security::ISecurityManagerListener { uint16_t le_scan_interval = 0x0060; uint16_t le_scan_window = 0x0030; InitiatorFilterPolicy initiator_filter_policy = InitiatorFilterPolicy::USE_PEER_ADDRESS; OwnAddressType own_address_type = OwnAddressType::RANDOM_DEVICE_ADDRESS; OwnAddressType own_address_type = static_cast<OwnAddressType>(le_initiator_address_.GetAddressType()); uint16_t conn_interval_min = 0x0018; uint16_t conn_interval_max = 0x0028; uint16_t conn_latency = 0x0000; Loading @@ -1018,8 +1021,10 @@ struct AclManager::impl : public security::ISecurityManagerListener { // With real controllers, we must set random address before using it to establish connection // TODO: have separate state machine generate new address when needed, consider using auto-generation in // controller hci_layer_->EnqueueCommand(hci::LeSetRandomAddressBuilder::Create(Address{{0x00, 0x11, 0xFF, 0xFF, 0x33, 0x22}}), if (own_address_type == OwnAddressType::RANDOM_DEVICE_ADDRESS) { hci_layer_->EnqueueCommand(hci::LeSetRandomAddressBuilder::Create(le_initiator_address_.GetAddress()), common::BindOnce([](CommandCompleteView status) {}), handler_); } hci_layer_->EnqueueCommand(LeExtendedCreateConnectionBuilder::Create( initiator_filter_policy, own_address_type, address_with_type.GetAddressType(), Loading @@ -1043,6 +1048,15 @@ struct AclManager::impl : public security::ISecurityManagerListener { } } void set_le_initiator_address(AddressWithType le_initiator_address) { le_initiator_address_ = le_initiator_address; if (le_initiator_address_.GetAddressType() != AddressType::RANDOM_DEVICE_ADDRESS) { // Usually controllers provide vendor-specific way to override public address. Implement it if it's ever needed. LOG_ALWAYS_FATAL("Don't know how to use this type of address"); } } void cancel_connect(Address address) { auto connecting_addr = connecting_.find(address); if (connecting_addr == connecting_.end()) { Loading Loading @@ -1817,6 +1831,7 @@ struct AclManager::impl : public security::ISecurityManagerListener { common::Callback<bool(Address, ClassOfDevice)> should_accept_connection_; std::queue<std::pair<Address, std::unique_ptr<CreateConnectionBuilder>>> pending_outgoing_connections_; uint16_t default_link_policy_settings_ = 0; AddressWithType le_initiator_address_; }; AclConnection::QueueUpEnd* AclConnection::GetAclQueueEnd() const { Loading Loading @@ -2009,6 +2024,11 @@ void AclManager::CreateLeConnection(AddressWithType address_with_type) { common::BindOnce(&impl::create_le_connection, common::Unretained(pimpl_.get()), address_with_type)); } void AclManager::SetLeInitiatorAddress(AddressWithType initiator_address) { GetHandler()->Post( common::BindOnce(&impl::set_le_initiator_address, common::Unretained(pimpl_.get()), initiator_address)); } void AclManager::CancelConnect(Address address) { GetHandler()->Post(BindOnce(&impl::cancel_connect, common::Unretained(pimpl_.get()), address)); } Loading
system/gd/hci/acl_manager.h +2 −0 Original line number Diff line number Diff line Loading @@ -260,6 +260,8 @@ class AclManager : public Module { // Generates OnLeConnectSuccess if connected, or OnLeConnectFail otherwise virtual void CreateLeConnection(AddressWithType address_with_type); virtual void SetLeInitiatorAddress(AddressWithType initiator_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(Address address); Loading
system/gd/hci/facade/le_acl_manager_facade.cc +9 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,15 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, return ::grpc::Status::OK; } ::grpc::Status SetInitiatorAddress(::grpc::ServerContext* context, const ::bluetooth::facade::BluetoothAddressWithType* request, ::google::protobuf::Empty* writer) override { Address address; ASSERT(Address::FromString(request->address().address(), address)); acl_manager_->SetLeInitiatorAddress(AddressWithType(address, static_cast<AddressType>(request->type()))); return ::grpc::Status::OK; } std::unique_ptr<BasePacketBuilder> enqueue_packet(const LeAclData* request, std::promise<void> promise) { acl_connections_[request->handle()]->GetAclQueueEnd()->UnregisterEnqueue(); std::unique_ptr<RawBuilder> packet = Loading
system/gd/hci/facade/le_acl_manager_facade.proto +2 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ syntax = "proto3"; package bluetooth.hci; import "google/protobuf/empty.proto"; import "facade/common.proto"; service LeAclManagerFacade { rpc CreateConnection(LeConnectionMsg) returns (stream LeConnectionEvent) {} Loading @@ -11,6 +12,7 @@ service LeAclManagerFacade { rpc SendAclData(LeAclData) returns (google.protobuf.Empty) {} rpc FetchAclData(google.protobuf.Empty) returns (stream LeAclData) {} rpc FetchIncomingConnection(google.protobuf.Empty) returns (stream LeConnectionEvent) {} rpc SetInitiatorAddress(bluetooth.facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {} } message LeHandleMsg { Loading
system/gd/l2cap/le/cert/dual_l2cap_test.py +9 −8 Original line number Diff line number Diff line Loading @@ -48,6 +48,13 @@ class DualL2capTest(GdBaseTestClass): self.cert_l2cap = CertL2cap(self.cert) self.dut_le_l2cap = PyLeL2cap(self.dut) self.cert_le_l2cap = CertLeL2cap(self.cert) self.dut_le_address = common.BluetoothAddressWithType( address = common.BluetoothAddress(address=bytes(b'0D:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_address = common.BluetoothAddressWithType( address = common.BluetoothAddress(address=bytes(b'55:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_le_l2cap._device.hci_le_acl_manager.SetInitiatorAddress(self.cert_address) def teardown_test(self): self.cert_le_l2cap.close() Loading @@ -68,15 +75,9 @@ class DualL2capTest(GdBaseTestClass): gap_name.data = list(bytes(b'Im_The_DUT')) gap_data = le_advertising_facade.GapDataMsg( data=bytes(gap_name.Serialize())) self.dut_address = common.BluetoothAddressWithType( address = common.BluetoothAddress(address=bytes(b'0D:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_address = common.BluetoothAddressWithType( address=common.BluetoothAddress(address=b"22:33:ff:ff:11:00"), type=common.RANDOM_DEVICE_ADDRESS) config = le_advertising_facade.AdvertisingConfig( advertisement=[gap_data], random_address=self.dut_address.address, random_address=self.dut_le_address.address, interval_min=512, interval_max=768, event_type=le_advertising_facade.AdvertisingEventType.ADV_IND, Loading @@ -90,7 +91,7 @@ class DualL2capTest(GdBaseTestClass): request = le_advertising_facade.CreateAdvertiserRequest(config=config) create_response = self.dut.hci_le_advertising_manager.CreateAdvertiser( request) self.cert_le_l2cap.connect_le_acl(self.dut_address) self.cert_le_l2cap.connect_le_acl(self.dut_le_address) def _open_le_coc_from_dut(self, psm=0x33, our_scid=None): response_future = self.dut_le_l2cap.connect_coc_to_cert(self.cert_address, psm) Loading