"facade/rootservice.proto",
"hal/facade.proto",
"hci/facade.proto",
- "l2cap/facade.proto",
+ "l2cap/classic/facade.proto",
],
}
"hal/facade.pb.h",
"hci/facade.grpc.pb.h",
"hci/facade.pb.h",
- "l2cap/facade.grpc.pb.h",
- "l2cap/facade.pb.h",
+ "l2cap/classic/facade.grpc.pb.h",
+ "l2cap/classic/facade.pb.h",
],
}
"hal/facade.pb.cc",
"hci/facade.grpc.pb.cc",
"hci/facade.pb.cc",
- "l2cap/facade.grpc.pb.cc",
- "l2cap/facade.pb.cc",
+ "l2cap/classic/facade.grpc.pb.cc",
+ "l2cap/classic/facade.pb.cc",
],
}
"touch $(genDir)/hal/cert/__init__.py; " +
"touch $(genDir)/hci/__init__.py; " +
"touch $(genDir)/hci/cert/__init__.py; " +
- "touch $(genDir)/l2cap/__init__.py; " +
- "touch $(genDir)/l2cap/cert/__init__.py; ",
+ "touch $(genDir)/l2cap/classic/__init__.py; " +
+ "touch $(genDir)/l2cap/classic/cert/__init__.py; ",
srcs: [
":BluetoothFacadeProto",
":BluetoothCertStackProto",
"hci/__init__.py",
"hci/facade_pb2_grpc.py",
"hci/facade_pb2.py",
- "l2cap/__init__.py",
- "l2cap/facade_pb2_grpc.py",
- "l2cap/facade_pb2.py",
+ "l2cap/classic/__init__.py",
+ "l2cap/classic/facade_pb2_grpc.py",
+ "l2cap/classic/facade_pb2.py",
"hal/cert/__init__.py",
"hal/cert/api_pb2_grpc.py",
"hal/cert/api_pb2.py",
"hci/cert/__init__.py",
"hci/cert/api_pb2_grpc.py",
"hci/cert/api_pb2.py",
- "l2cap/cert/__init__.py",
- "l2cap/cert/api_pb2_grpc.py",
- "l2cap/cert/api_pb2.py",
+ "l2cap/classic/cert/__init__.py",
+ "l2cap/classic/cert/api_pb2_grpc.py",
+ "l2cap/classic/cert/api_pb2.py",
],
}
"cert/rootservice.proto",
"hal/cert/api.proto",
"hci/cert/api.proto",
- "l2cap/cert/api.proto",
+ "l2cap/classic/cert/api.proto",
],
}
"hal/cert/api.pb.h",
"hci/cert/api.grpc.pb.h",
"hci/cert/api.pb.h",
- "l2cap/cert/api.grpc.pb.h",
- "l2cap/cert/api.pb.h",
+ "l2cap/classic/cert/api.grpc.pb.h",
+ "l2cap/classic/cert/api.pb.h",
],
}
"hal/cert/api.pb.cc",
"hci/cert/api.grpc.pb.cc",
"hci/cert/api.pb.cc",
- "l2cap/cert/api.grpc.pb.cc",
- "l2cap/cert/api.pb.cc",
+ "l2cap/classic/cert/api.grpc.pb.cc",
+ "l2cap/classic/cert/api.pb.cc",
],
}
from cert import rootservice_pb2_grpc as cert_rootservice_pb2_grpc
from hal.cert import api_pb2_grpc as hal_cert_pb2_grpc
from hci.cert import api_pb2_grpc as hci_cert_pb2_grpc
-from l2cap.cert import api_pb2_grpc as l2cap_cert_pb2_grpc
+from l2cap.classic.cert import api_pb2_grpc as l2cap_cert_pb2_grpc
ACTS_CONTROLLER_CONFIG_NAME = "GdCertDevice"
ACTS_CONTROLLER_REFERENCE_NAME = "gd_cert_devices"
from facade import rootservice_pb2_grpc as facade_rootservice_pb2_grpc
from hal import facade_pb2_grpc as hal_facade_pb2_grpc
from hci import facade_pb2_grpc as hci_facade_pb2_grpc
-from l2cap import facade_pb2_grpc as l2cap_facade_pb2_grpc
+from l2cap.classic import facade_pb2_grpc as l2cap_facade_pb2_grpc
ACTS_CONTROLLER_CONFIG_NAME = "GdDevice"
ACTS_CONTROLLER_REFERENCE_NAME = "gd_devices"
#include "grpc/grpc_module.h"
#include "hal/cert/cert.h"
#include "hci/cert/cert.h"
-#include "l2cap/cert/cert.h"
+#include "l2cap/classic/cert/cert.h"
#include "os/log.h"
#include "os/thread.h"
#include "stack_manager.h"
break;
case BluetoothModule::L2CAP:
modules.add<::bluetooth::cert::ReadOnlyPropertyServerModule>();
- modules.add<::bluetooth::l2cap::cert::L2capModuleCertModule>();
+ modules.add<::bluetooth::l2cap::classic::cert::L2capModuleCertModule>();
break;
default:
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "invalid module under test");
#include "grpc/grpc_module.h"
#include "hal/facade.h"
#include "hci/facade.h"
-#include "l2cap/facade.h"
+#include "l2cap/classic/facade.h"
#include "os/log.h"
#include "os/thread.h"
#include "stack_manager.h"
break;
case BluetoothModule::L2CAP:
modules.add<::bluetooth::facade::ReadOnlyPropertyServerModule>();
- modules.add<::bluetooth::l2cap::L2capModuleFacadeModule>();
+ modules.add<::bluetooth::l2cap::classic::L2capModuleFacadeModule>();
break;
default:
return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "invalid module under test");
name: "BluetoothL2capSources",
srcs: [
"fcs.cc",
- "l2cap_layer.cc",
- "classic_dynamic_channel.cc",
- "classic_dynamic_channel_manager.cc",
- "classic_dynamic_channel_service.cc",
- "classic_fixed_channel.cc",
- "classic_fixed_channel_manager.cc",
- "classic_fixed_channel_service.cc",
- "internal/classic_dynamic_channel_allocator.cc",
- "internal/classic_dynamic_channel_impl.cc",
- "internal/classic_dynamic_channel_service_manager_impl.cc",
- "internal/classic_fixed_channel_impl.cc",
- "internal/classic_fixed_channel_service_manager_impl.cc",
- "internal/classic_link.cc",
- "internal/classic_link_manager.cc",
- "internal/le_fixed_channel_impl.cc",
- "internal/le_fixed_channel_service_manager_impl.cc",
- "internal/le_link_manager.cc",
+ "classic/dynamic_channel.cc",
+ "classic/dynamic_channel_manager.cc",
+ "classic/dynamic_channel_service.cc",
+ "classic/fixed_channel.cc",
+ "classic/fixed_channel_manager.cc",
+ "classic/fixed_channel_service.cc",
+ "classic/internal/dynamic_channel_allocator.cc",
+ "classic/internal/dynamic_channel_impl.cc",
+ "classic/internal/dynamic_channel_service_manager_impl.cc",
+ "classic/internal/fixed_channel_impl.cc",
+ "classic/internal/fixed_channel_service_manager_impl.cc",
+ "classic/internal/link.cc",
+ "classic/internal/link_manager.cc",
+ "classic/l2cap_classic_module.cc",
"internal/scheduler_fifo.cc",
- "le_fixed_channel.cc",
- "le_fixed_channel_manager.cc",
- "le_fixed_channel_service.cc",
+ "le/internal/fixed_channel_impl.cc",
+ "le/internal/fixed_channel_service_manager_impl.cc",
+ "le/internal/link_manager.cc",
+ "le/fixed_channel.cc",
+ "le/fixed_channel_manager.cc",
+ "le/fixed_channel_service.cc",
+ "le/l2cap_le_module.cc",
],
}
filegroup {
name: "BluetoothL2capTestSources",
srcs: [
- "l2cap_packet_test.cc",
- "internal/classic_dynamic_channel_allocator_test.cc",
- "internal/classic_dynamic_channel_impl_test.cc",
- "internal/classic_dynamic_channel_service_manager_test.cc",
- "internal/classic_fixed_channel_impl_test.cc",
- "internal/classic_fixed_channel_service_manager_test.cc",
- "internal/classic_link_manager_test.cc",
+ "classic/internal/dynamic_channel_allocator_test.cc",
+ "classic/internal/dynamic_channel_impl_test.cc",
+ "classic/internal/dynamic_channel_service_manager_test.cc",
+ "classic/internal/fixed_channel_impl_test.cc",
+ "classic/internal/fixed_channel_service_manager_test.cc",
+ "classic/internal/link_manager_test.cc",
"internal/fixed_channel_allocator_test.cc",
- "internal/le_fixed_channel_impl_test.cc",
- "internal/le_fixed_channel_service_manager_test.cc",
- "internal/le_link_manager_test.cc",
"internal/scheduler_fifo_test.cc",
+ "l2cap_packet_test.cc",
+ "le/internal/fixed_channel_impl_test.cc",
+ "le/internal/fixed_channel_service_manager_test.cc",
+ "le/internal/link_manager_test.cc",
"signal_id_test.cc",
],
}
filegroup {
name: "BluetoothFacade_l2cap_layer",
srcs: [
- "facade.cc",
+ "classic/facade.cc",
],
}
filegroup {
name: "BluetoothCertSource_l2cap_layer",
srcs: [
- "cert/cert.cc",
+ "classic/cert/cert.cc",
],
}
syntax = "proto3";
-package bluetooth.l2cap.cert;
+package bluetooth.l2cap.classic.cert;
import "google/protobuf/empty.proto";
import "facade/common.proto";
* limitations under the License.
*/
-#include "l2cap/cert/cert.h"
+#include "l2cap/classic/cert/cert.h"
#include <cstdint>
#include <memory>
#include "grpc/grpc_event_stream.h"
#include "hci/acl_manager.h"
#include "hci/cert/cert.h"
-#include "l2cap/cert/api.grpc.pb.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/classic/cert/api.grpc.pb.h"
+#include "l2cap/classic/l2cap_classic_module.h"
#include "l2cap/l2cap_packets.h"
#include "os/log.h"
#include "packet/raw_builder.h"
using ::bluetooth::facade::EventStreamRequest;
using ::bluetooth::packet::RawBuilder;
+using ::bluetooth::l2cap::classic::cert::ConnectionCompleteEvent;
+using ::bluetooth::l2cap::classic::cert::L2capPacket;
+
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace cert {
using namespace facade;
::bluetooth::grpc::GrpcEventStream<ConnectionCompleteEvent, ConnectionCompleteEvent> connection_complete_stream_{
&connection_complete_callback_};
- ::grpc::Status FetchConnectionComplete(
- ::grpc::ServerContext* context, const ::bluetooth::facade::EventStreamRequest* request,
- ::grpc::ServerWriter<::bluetooth::l2cap::cert::ConnectionCompleteEvent>* writer) override {
+ ::grpc::Status FetchConnectionComplete(::grpc::ServerContext* context,
+ const ::bluetooth::facade::EventStreamRequest* request,
+ ::grpc::ServerWriter<ConnectionCompleteEvent>* writer) override {
return connection_complete_stream_.HandleRequest(context, request, writer);
}
- ::grpc::Status SendL2capPacket(::grpc::ServerContext* context, const ::bluetooth::l2cap::cert::L2capPacket* request,
+ ::grpc::Status SendL2capPacket(::grpc::ServerContext* context, const L2capPacket* request,
::google::protobuf::Empty* response) override {
std::unique_ptr<RawBuilder> packet = std::make_unique<RawBuilder>();
auto req_string = request->payload();
::bluetooth::ModuleFactory([]() { return new L2capModuleCertModule(); });
} // namespace cert
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <grpc++/grpc++.h>
#include "grpc/grpc_module.h"
-#include "l2cap/l2cap_layer.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace cert {
class L2capModuleCertService;
};
} // namespace cert
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
from facade import common_pb2
from facade import rootservice_pb2 as facade_rootservice_pb2
from google.protobuf import empty_pb2
-from l2cap import facade_pb2 as l2cap_facade_pb2
+from l2cap.classic import facade_pb2 as l2cap_facade_pb2
class SimpleL2capTest(GdBaseTestClass):
def setup_test(self):
* limitations under the License.
*/
-#include "l2cap/le_fixed_channel.h"
+#include "l2cap/classic/dynamic_channel.h"
#include "common/bind.h"
-#include "l2cap/internal/le_fixed_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-hci::Address LeFixedChannel::GetDevice() const {
+hci::Address DynamicChannel::GetDevice() const {
return impl_->GetDevice();
}
-void LeFixedChannel::RegisterOnCloseCallback(os::Handler* user_handler,
- LeFixedChannel::OnCloseCallback on_close_callback) {
- l2cap_handler_->Post(common::BindOnce(&internal::LeFixedChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
+void DynamicChannel::RegisterOnCloseCallback(os::Handler* user_handler,
+ DynamicChannel::OnCloseCallback on_close_callback) {
+ l2cap_handler_->Post(common::BindOnce(&internal::DynamicChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
std::move(on_close_callback)));
}
-void LeFixedChannel::Acquire() {
- l2cap_handler_->Post(common::BindOnce(&internal::LeFixedChannelImpl::Acquire, impl_));
-}
-
-void LeFixedChannel::Release() {
- l2cap_handler_->Post(common::BindOnce(&internal::LeFixedChannelImpl::Release, impl_));
+void DynamicChannel::Close() {
+ l2cap_handler_->Post(common::BindOnce(&internal::DynamicChannelImpl::Close, impl_));
}
common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
-LeFixedChannel::GetQueueUpEnd() const {
+DynamicChannel::GetQueueUpEnd() const {
return impl_->GetQueueUpEnd();
}
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicDynamicChannelImpl;
+class DynamicChannelImpl;
} // namespace internal
/**
* L2CAP Dynamic channel object. User needs to call Close() when user no longer wants to use it. Otherwise the link
* won't be disconnected.
*/
-class ClassicDynamicChannel {
+class DynamicChannel {
public:
- // Should only be constructed by modules that have access to ClassicLinkManager
- ClassicDynamicChannel(std::shared_ptr<internal::ClassicDynamicChannelImpl> impl, os::Handler* l2cap_handler)
+ // Should only be constructed by modules that have access to LinkManager
+ DynamicChannel(std::shared_ptr<internal::DynamicChannelImpl> impl, os::Handler* l2cap_handler)
: impl_(std::move(impl)), l2cap_handler_(l2cap_handler) {
ASSERT(impl_ != nullptr);
ASSERT(l2cap_handler_ != nullptr);
common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() const;
private:
- std::shared_ptr<internal::ClassicDynamicChannelImpl> impl_;
+ std::shared_ptr<internal::DynamicChannelImpl> impl_;
os::Handler* l2cap_handler_;
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/internal/classic_dynamic_channel_service_impl.h"
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/internal/dynamic_channel_service_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link_manager.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-bool ClassicDynamicChannelManager::ConnectChannel(hci::Address device, Psm psm,
- OnConnectionOpenCallback on_connection_open,
- OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
+bool DynamicChannelManager::ConnectChannel(hci::Address device, Psm psm, OnConnectionOpenCallback on_connection_open,
+ OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
// TODO impl me when there is no link, and when there is link
return false;
}
-bool ClassicDynamicChannelManager::RegisterService(Psm psm, const SecurityPolicy& security_policy,
- OnRegistrationCompleteCallback on_registration_complete,
- OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
- internal::ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration{
+bool DynamicChannelManager::RegisterService(Psm psm, const SecurityPolicy& security_policy,
+ OnRegistrationCompleteCallback on_registration_complete,
+ OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
+ internal::DynamicChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = handler,
.on_registration_complete_callback_ = std::move(on_registration_complete),
.on_connection_open_callback_ = std::move(on_connection_open)};
- l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelServiceManagerImpl::Register,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::DynamicChannelServiceManagerImpl::Register,
common::Unretained(service_manager_), psm,
std::move(pending_registration)));
return true;
}
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager.h"
#include "hci/address.h"
-#include "l2cap/classic_dynamic_channel.h"
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/classic/dynamic_channel.h"
+#include "l2cap/classic/dynamic_channel_service.h"
#include "l2cap/l2cap_packets.h"
#include "l2cap/psm.h"
#include "l2cap/security_policy.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-class L2capLayer;
+class L2capClassicModule;
namespace internal {
-class ClassicLinkManager;
-class ClassicDynamicChannelServiceManagerImpl;
+class LinkManager;
+class DynamicChannelServiceManagerImpl;
} // namespace internal
-class ClassicDynamicChannelManager {
+class DynamicChannelManager {
public:
enum class ConnectionResultCode {
SUCCESS = 0,
using OnConnectionFailureCallback = common::OnceCallback<void(ConnectionResult result)>;
/**
- * OnConnectionOpenCallback(ClassicDynamicChannel channel);
+ * OnConnectionOpenCallback(DynamicChannel channel);
*/
- using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<ClassicDynamicChannel>)>;
+ using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<DynamicChannel>)>;
enum class RegistrationResult {
SUCCESS = 0,
};
/**
- * OnRegistrationFailureCallback(RegistrationResult result, ClassicDynamicChannelService service);
+ * OnRegistrationFailureCallback(RegistrationResult result, DynamicChannelService service);
*/
using OnRegistrationCompleteCallback =
- common::OnceCallback<void(RegistrationResult, std::unique_ptr<ClassicDynamicChannelService>)>;
+ common::OnceCallback<void(RegistrationResult, std::unique_ptr<DynamicChannelService>)>;
/**
* Connect to a Dynamic channel on a remote device
* - This method is asynchronous.
* - When false is returned, the registration fails immediately.
* - When true is returned, method caller should wait for on_service_registered callback that contains a
- * ClassicDynamicChannelService object. The registered service can be managed from that object.
+ * DynamicChannelService object. The registered service can be managed from that object.
* - If a PSM is already registered or some other error happens, on_registration_complete will be triggered with a
* non-SUCCESS value
- * - After a service is registered, a ClassicDynamicChannel is delivered through on_open_callback when the remote
+ * - After a service is registered, a DynamicChannel is delivered through on_open_callback when the remote
* initiates a channel open and channel is opened successfully
* - on_open_callback, will only be triggered after on_service_registered callback
*
OnRegistrationCompleteCallback on_registration_complete,
OnConnectionOpenCallback on_connection_open, os::Handler* handler);
- friend class L2capLayer;
+ friend class L2capClassicModule;
private:
// The constructor is not to be used by user code
- ClassicDynamicChannelManager(internal::ClassicDynamicChannelServiceManagerImpl* service_manager,
- internal::ClassicLinkManager* link_manager, os::Handler* l2cap_layer_handler)
+ DynamicChannelManager(internal::DynamicChannelServiceManagerImpl* service_manager,
+ internal::LinkManager* link_manager, os::Handler* l2cap_layer_handler)
: service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {
ASSERT(service_manager_ != nullptr);
ASSERT(link_manager_ != nullptr);
ASSERT(l2cap_layer_handler_ != nullptr);
}
- internal::ClassicDynamicChannelServiceManagerImpl* service_manager_ = nullptr;
- internal::ClassicLinkManager* link_manager_ = nullptr;
+ internal::DynamicChannelServiceManagerImpl* service_manager_ = nullptr;
+ internal::LinkManager* link_manager_ = nullptr;
os::Handler* l2cap_layer_handler_ = nullptr;
- DISALLOW_COPY_AND_ASSIGN(ClassicDynamicChannelManager);
+ DISALLOW_COPY_AND_ASSIGN(DynamicChannelManager);
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/classic/dynamic_channel_service.h"
#include "common/bind.h"
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-void ClassicDynamicChannelService::Unregister(OnUnregisteredCallback on_unregistered,
- os::Handler* on_unregistered_handler) {
+void DynamicChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
ASSERT_LOG(manager_ != nullptr, "this service is invalid");
- l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelServiceManagerImpl::Unregister,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::DynamicChannelServiceManagerImpl::Unregister,
common::Unretained(manager_), psm_, std::move(on_unregistered),
on_unregistered_handler));
}
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicDynamicChannelServiceManagerImpl;
+class DynamicChannelServiceManagerImpl;
}
-class ClassicDynamicChannelService {
+class DynamicChannelService {
public:
- ClassicDynamicChannelService() = default;
+ DynamicChannelService() = default;
using OnUnregisteredCallback = common::OnceCallback<void()>;
*/
void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
- friend internal::ClassicDynamicChannelServiceManagerImpl;
+ friend internal::DynamicChannelServiceManagerImpl;
private:
- ClassicDynamicChannelService(Psm psm, internal::ClassicDynamicChannelServiceManagerImpl* manager,
- os::Handler* handler)
+ DynamicChannelService(Psm psm, internal::DynamicChannelServiceManagerImpl* manager, os::Handler* handler)
: psm_(psm), manager_(manager), l2cap_layer_handler_(handler) {
ASSERT(IsPsmValid(psm));
ASSERT(manager_ != nullptr);
ASSERT(l2cap_layer_handler_ != nullptr);
}
Psm psm_ = kDefaultPsm;
- internal::ClassicDynamicChannelServiceManagerImpl* manager_ = nullptr;
+ internal::DynamicChannelServiceManagerImpl* manager_ = nullptr;
os::Handler* l2cap_layer_handler_;
- DISALLOW_COPY_AND_ASSIGN(ClassicDynamicChannelService);
+ DISALLOW_COPY_AND_ASSIGN(DynamicChannelService);
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include "grpc/grpc_event_stream.h"
#include "hci/address.h"
#include "hci/facade.h"
-#include "l2cap/facade.grpc.pb.h"
-#include "l2cap/facade.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/classic/facade.grpc.pb.h"
+#include "l2cap/classic/facade.h"
+#include "l2cap/classic/l2cap_classic_module.h"
#include "l2cap/l2cap_packets.h"
#include "os/log.h"
#include "packet/raw_builder.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
class L2capModuleFacadeService : public L2capModuleFacade::Service {
public:
- L2capModuleFacadeService(L2capLayer* l2cap_layer, os::Handler* facade_handler)
+ L2capModuleFacadeService(L2capClassicModule* l2cap_layer, os::Handler* facade_handler)
: l2cap_layer_(l2cap_layer), facade_handler_(facade_handler) {
ASSERT(l2cap_layer_ != nullptr);
ASSERT(facade_handler_ != nullptr);
::grpc::Status FetchConnectionComplete(
::grpc::ServerContext* context, const ::bluetooth::facade::EventStreamRequest* request,
- ::grpc::ServerWriter<::bluetooth::l2cap::ConnectionCompleteEvent>* writer) override {
+ ::grpc::ServerWriter<::bluetooth::l2cap::classic::ConnectionCompleteEvent>* writer) override {
return connection_complete_stream_.HandleRequest(context, request, writer);
}
::grpc::Status Connect(::grpc::ServerContext* context, const facade::BluetoothAddress* request,
::google::protobuf::Empty* response) override {
- auto fixed_channel_manager = l2cap_layer_->GetClassicFixedChannelManager();
+ auto fixed_channel_manager = l2cap_layer_->GetFixedChannelManager();
hci::Address peer;
ASSERT(hci::Address::FromString(request->address(), peer));
- fixed_channel_manager->ConnectServices(peer, common::BindOnce([](ClassicFixedChannelManager::ConnectionResult) {}),
+ fixed_channel_manager->ConnectServices(peer, common::BindOnce([](FixedChannelManager::ConnectionResult) {}),
facade_handler_);
return ::grpc::Status::OK;
}
- ::grpc::Status SendL2capPacket(::grpc::ServerContext* context, const ::bluetooth::l2cap::L2capPacket* request,
- SendL2capPacketResult* response) override {
+ ::grpc::Status SendL2capPacket(::grpc::ServerContext* context,
+ const ::bluetooth::l2cap::classic::L2capPacket* request,
+ ::bluetooth::l2cap::classic::SendL2capPacketResult* response) override {
if (connection_less_channel_helper_map_.find(request->channel()) == connection_less_channel_helper_map_.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION, "Channel not registered");
}
std::vector<uint8_t> packet(request->payload().begin(), request->payload().end());
connection_less_channel_helper_map_[request->channel()]->SendPacket(packet);
- response->set_result_type(SendL2capPacketResultType::OK);
+ response->set_result_type(::bluetooth::l2cap::classic::SendL2capPacketResultType::OK);
return ::grpc::Status::OK;
}
::grpc::Status FetchL2capData(::grpc::ServerContext* context, const ::bluetooth::facade::EventStreamRequest* request,
- ::grpc::ServerWriter<::bluetooth::l2cap::L2capPacket>* writer) override {
+ ::grpc::ServerWriter<::bluetooth::l2cap::classic::L2capPacket>* writer) override {
return l2cap_stream_.HandleRequest(context, request, writer);
}
::grpc::Status RegisterChannel(::grpc::ServerContext* context,
- const ::bluetooth::l2cap::RegisterChannelRequest* request,
+ const ::bluetooth::l2cap::classic::RegisterChannelRequest* request,
::google::protobuf::Empty* response) override {
if (connection_less_channel_helper_map_.find(request->channel()) != connection_less_channel_helper_map_.end()) {
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION, "Already registered");
class L2capFixedChannelHelper {
public:
- L2capFixedChannelHelper(L2capModuleFacadeService* service, L2capLayer* l2cap_layer, os::Handler* handler, Cid cid)
+ L2capFixedChannelHelper(L2capModuleFacadeService* service, L2capClassicModule* l2cap_layer, os::Handler* handler,
+ Cid cid)
: facade_service_(service), l2cap_layer_(l2cap_layer), handler_(handler), cid_(cid) {
- fixed_channel_manager_ = l2cap_layer_->GetClassicFixedChannelManager();
+ fixed_channel_manager_ = l2cap_layer_->GetFixedChannelManager();
fixed_channel_manager_->RegisterService(
cid, {},
common::BindOnce(&L2capFixedChannelHelper::on_l2cap_service_registration_complete, common::Unretained(this)),
common::Bind(&L2capFixedChannelHelper::on_connection_open, common::Unretained(this)), handler_);
}
- void on_l2cap_service_registration_complete(ClassicFixedChannelManager::RegistrationResult registration_result,
- std::unique_ptr<ClassicFixedChannelService> service) {
+ void on_l2cap_service_registration_complete(FixedChannelManager::RegistrationResult registration_result,
+ std::unique_ptr<FixedChannelService> service) {
service_ = std::move(service);
}
- void on_connection_open(std::unique_ptr<ClassicFixedChannel> channel) {
+ void on_connection_open(std::unique_ptr<FixedChannel> channel) {
ConnectionCompleteEvent event;
event.mutable_remote()->set_address(channel->GetDevice().ToString());
facade_service_->connection_complete_stream_.OnIncomingEvent(event);
};
L2capModuleFacadeService* facade_service_;
- L2capLayer* l2cap_layer_;
+ L2capClassicModule* l2cap_layer_;
os::Handler* handler_;
- std::unique_ptr<ClassicFixedChannelManager> fixed_channel_manager_;
- std::unique_ptr<ClassicFixedChannelService> service_;
- std::unique_ptr<ClassicFixedChannel> channel_ = nullptr;
+ std::unique_ptr<FixedChannelManager> fixed_channel_manager_;
+ std::unique_ptr<FixedChannelService> service_;
+ std::unique_ptr<FixedChannel> channel_ = nullptr;
Cid cid_;
};
- l2cap::L2capLayer* l2cap_layer_;
+ l2cap::classic::L2capClassicModule* l2cap_layer_;
::bluetooth::os::Handler* facade_handler_;
std::map<Cid, std::unique_ptr<L2capFixedChannelHelper>> connection_less_channel_helper_map_;
void L2capModuleFacadeModule::ListDependencies(ModuleList* list) {
::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
- list->add<l2cap::L2capLayer>();
+ list->add<l2cap::classic::L2capClassicModule>();
list->add<hci::HciLayer>();
}
::bluetooth::grpc::GrpcFacadeModule::Start();
GetDependency<hci::HciLayer>()->EnqueueCommand(hci::WriteScanEnableBuilder::Create(hci::ScanEnable::PAGE_SCAN_ONLY),
common::BindOnce([](hci::CommandCompleteView) {}), GetHandler());
- service_ = new L2capModuleFacadeService(GetDependency<l2cap::L2capLayer>(), GetHandler());
+ service_ = new L2capModuleFacadeService(GetDependency<l2cap::classic::L2capClassicModule>(), GetHandler());
}
void L2capModuleFacadeModule::Stop() {
const ModuleFactory L2capModuleFacadeModule::Factory =
::bluetooth::ModuleFactory([]() { return new L2capModuleFacadeModule(); });
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
namespace bluetooth {
namespace l2cap {
+namespace classic {
class L2capModuleFacadeService;
L2capModuleFacadeService* service_;
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
syntax = "proto3";
-package bluetooth.l2cap;
+package bluetooth.l2cap.classic;
import "google/protobuf/empty.proto";
import "facade/common.proto";
* limitations under the License.
*/
-#include "l2cap/classic_fixed_channel.h"
+#include "l2cap/classic/fixed_channel.h"
#include "common/bind.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-hci::Address ClassicFixedChannel::GetDevice() const {
+hci::Address FixedChannel::GetDevice() const {
return impl_->GetDevice();
}
-void ClassicFixedChannel::RegisterOnCloseCallback(os::Handler* user_handler,
- ClassicFixedChannel::OnCloseCallback on_close_callback) {
- l2cap_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelImpl::RegisterOnCloseCallback, impl_,
- user_handler, std::move(on_close_callback)));
+void FixedChannel::RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback) {
+ l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
+ std::move(on_close_callback)));
}
-void ClassicFixedChannel::Acquire() {
- l2cap_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelImpl::Acquire, impl_));
+void FixedChannel::Acquire() {
+ l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Acquire, impl_));
}
-void ClassicFixedChannel::Release() {
- l2cap_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelImpl::Release, impl_));
+void FixedChannel::Release() {
+ l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Release, impl_));
}
common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
-ClassicFixedChannel::GetQueueUpEnd() const {
+FixedChannel::GetQueueUpEnd() const {
return impl_->GetQueueUpEnd();
}
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicFixedChannelImpl;
+class FixedChannelImpl;
} // namespace internal
/**
* Otherwise, {@link FixedChannel#Release()} will be called automatically.
*
*/
-class ClassicFixedChannel {
+class FixedChannel {
public:
- // Should only be constructed by modules that have access to ClassicLinkManager
- ClassicFixedChannel(std::shared_ptr<internal::ClassicFixedChannelImpl> impl, os::Handler* l2cap_handler)
+ // Should only be constructed by modules that have access to LinkManager
+ FixedChannel(std::shared_ptr<internal::FixedChannelImpl> impl, os::Handler* l2cap_handler)
: impl_(std::move(impl)), l2cap_handler_(l2cap_handler) {
ASSERT(impl_ != nullptr);
ASSERT(l2cap_handler_ != nullptr);
/**
* Indicate that this Fixed Channel is no longer being used. ACL connection will be disconnected after
- * kClassicLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is using this
+ * kLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is using this
* ACL connection. However a module can still receive data on this channel as long as it remains open.
*/
void Release();
common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() const;
private:
- std::shared_ptr<internal::ClassicFixedChannelImpl> impl_;
+ std::shared_ptr<internal::FixedChannelImpl> impl_;
os::Handler* l2cap_handler_;
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link_manager.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-bool ClassicFixedChannelManager::ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback,
- os::Handler* handler) {
- internal::ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+bool FixedChannelManager::ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback,
+ os::Handler* handler) {
+ internal::LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.on_fail_callback_ = std::move(on_fail_callback), .handler_ = handler};
- l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicLinkManager::ConnectFixedChannelServices,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::LinkManager::ConnectFixedChannelServices,
common::Unretained(link_manager_), device,
std::move(pending_fixed_channel_connection)));
return true;
}
-bool ClassicFixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
- OnRegistrationCompleteCallback on_registration_complete,
- OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
- internal::ClassicFixedChannelServiceImpl::PendingRegistration pending_registration{
+bool FixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
+ OnRegistrationCompleteCallback on_registration_complete,
+ OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
+ internal::FixedChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = handler,
.on_registration_complete_callback_ = std::move(on_registration_complete),
.on_connection_open_callback_ = std::move(on_connection_open)};
- l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelServiceManagerImpl::Register,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Register,
common::Unretained(service_manager_), cid,
std::move(pending_registration)));
return true;
}
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#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"
+#include "l2cap/classic/fixed_channel.h"
+#include "l2cap/classic/fixed_channel_service.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-class L2capLayer;
+class L2capClassicModule;
namespace internal {
-class ClassicLinkManager;
-class ClassicFixedChannelServiceManagerImpl;
+class LinkManager;
+class FixedChannelServiceManagerImpl;
} // namespace internal
-class ClassicFixedChannelManager {
+class FixedChannelManager {
public:
enum class ConnectionResultCode {
SUCCESS = 0,
using OnConnectionFailureCallback = common::OnceCallback<void(ConnectionResult result)>;
/**
- * OnConnectionOpenCallback(ClassicFixedChannel channel);
+ * OnConnectionOpenCallback(FixedChannel channel);
*/
- using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<ClassicFixedChannel>)>;
+ using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<FixedChannel>)>;
enum class RegistrationResult {
SUCCESS = 0,
};
/**
- * OnRegistrationFailureCallback(RegistrationResult result, ClassicFixedChannelService service);
+ * OnRegistrationFailureCallback(RegistrationResult result, FixedChannelService service);
*/
using OnRegistrationCompleteCallback =
- common::OnceCallback<void(RegistrationResult, std::unique_ptr<ClassicFixedChannelService>)>;
+ common::OnceCallback<void(RegistrationResult, std::unique_ptr<FixedChannelService>)>;
/**
* Connect to ALL fixed channels on a remote device
* - When true is returned, method caller should wait for on_fail_callback or on_open_callback registered through
* RegisterService() API.
* - If an ACL connection does not exist, this method will create an ACL connection. As a result, on_open_callback
- * supplied through RegisterService() will be triggered to provide the actual ClassicFixedChannel objects
+ * supplied through RegisterService() will be triggered to provide the actual FixedChannel objects
* - If HCI connection failed, on_fail_callback will be triggered with FAIL_HCI_ERROR
* - If fixed channel on a remote device is already reported as connected via on_open_callback and has been acquired
- * via ClassicFixedChannel#Acquire() API, it won't be reported again
+ * via FixedChannel#Acquire() API, it won't be reported again
* - If no service is registered, on_fail_callback will be triggered with FAIL_NO_SERVICE_REGISTERED
* - If there is an ACL connection and channels for each service is allocated, on_fail_callback will be triggered with
* FAIL_ALL_SERVICES_HAVE_CHANNEL
* This call will initiate an effort to connect all fixed channel services on a remote device.
* Due to the connectionless nature of fixed channels, all fixed channels will be connected together.
* If a fixed channel service does not need a particular fixed channel. It should release the received
- * channel immediately after receiving on_open_callback via ClassicFixedChannel#Release()
+ * channel immediately after receiving on_open_callback via FixedChannel#Release()
*
* A module calling ConnectServices() must have called RegisterService() before.
* The callback will come back from on_open_callback in the service that is registered
* - This method is asynchronous.
* - When false is returned, the registration fails immediately.
* - When true is returned, method caller should wait for on_service_registered callback that contains a
- * ClassicFixedChannelService object. The registered service can be managed from that object.
+ * FixedChannelService object. The registered service can be managed from that object.
* - If a CID is already registered or some other error happens, on_registration_complete will be triggered with a
* non-SUCCESS value
- * - After a service is registered, any classic ACL connection will create a ClassicFixedChannel object that is
+ * - After a service is registered, any classic ACL connection will create a FixedChannel object that is
* delivered through on_open_callback
* - on_open_callback, will only be triggered after on_service_registered callback
*
- * @param cid: Classic cid used to receive incoming connections
+ * @param cid: cid used to receive incoming connections
* @param security_policy: The security policy used for the connection.
* @param on_registration_complete: A callback to indicate the service setup has completed. If the return status is
* not SUCCESS, it means service is not registered due to reasons like CID already take
OnRegistrationCompleteCallback on_registration_complete,
OnConnectionOpenCallback on_connection_open, os::Handler* handler);
- friend class L2capLayer;
+ friend class L2capClassicModule;
private:
// The constructor is not to be used by user code
- ClassicFixedChannelManager(internal::ClassicFixedChannelServiceManagerImpl* service_manager,
- internal::ClassicLinkManager* link_manager, os::Handler* l2cap_layer_handler)
+ FixedChannelManager(internal::FixedChannelServiceManagerImpl* service_manager, internal::LinkManager* link_manager,
+ os::Handler* l2cap_layer_handler)
: service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {}
- internal::ClassicFixedChannelServiceManagerImpl* service_manager_ = nullptr;
- internal::ClassicLinkManager* link_manager_ = nullptr;
+ internal::FixedChannelServiceManagerImpl* service_manager_ = nullptr;
+ internal::LinkManager* link_manager_ = nullptr;
os::Handler* l2cap_layer_handler_ = nullptr;
- DISALLOW_COPY_AND_ASSIGN(ClassicFixedChannelManager);
+ DISALLOW_COPY_AND_ASSIGN(FixedChannelManager);
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel_service.h"
#include "common/bind.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-void ClassicFixedChannelService::Unregister(OnUnregisteredCallback on_unregistered,
- os::Handler* on_unregistered_handler) {
+void FixedChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
ASSERT_LOG(manager_ != nullptr, "this service is invalid");
- l2cap_layer_handler_->Post(common::BindOnce(&internal::ClassicFixedChannelServiceManagerImpl::Unregister,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Unregister,
common::Unretained(manager_), cid_, std::move(on_unregistered),
on_unregistered_handler));
}
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicFixedChannelServiceManagerImpl;
+class FixedChannelServiceManagerImpl;
} // namespace internal
-class ClassicFixedChannelService {
+class FixedChannelService {
public:
- ClassicFixedChannelService() = default;
+ FixedChannelService() = default;
using OnUnregisteredCallback = common::OnceCallback<void()>;
*/
void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
- friend internal::ClassicFixedChannelServiceManagerImpl;
+ friend internal::FixedChannelServiceManagerImpl;
private:
- ClassicFixedChannelService(Cid cid, internal::ClassicFixedChannelServiceManagerImpl* manager, os::Handler* handler)
+ FixedChannelService(Cid cid, internal::FixedChannelServiceManagerImpl* manager, os::Handler* handler)
: cid_(cid), manager_(manager), l2cap_layer_handler_(handler) {}
Cid cid_ = kInvalidCid;
- internal::ClassicFixedChannelServiceManagerImpl* manager_ = nullptr;
+ internal::FixedChannelServiceManagerImpl* manager_ = nullptr;
os::Handler* l2cap_layer_handler_;
- DISALLOW_COPY_AND_ASSIGN(ClassicFixedChannelService);
+ DISALLOW_COPY_AND_ASSIGN(FixedChannelService);
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <unordered_map>
-#include "classic_dynamic_channel_allocator.h"
#include "l2cap/cid.h"
-#include "l2cap/internal/classic_dynamic_channel_allocator.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/dynamic_channel_allocator.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-std::shared_ptr<ClassicDynamicChannelImpl> ClassicDynamicChannelAllocator::AllocateChannel(
- Psm psm, Cid remote_cid, SecurityPolicy security_policy) {
+std::shared_ptr<DynamicChannelImpl> DynamicChannelAllocator::AllocateChannel(Psm psm, Cid remote_cid,
+ SecurityPolicy security_policy) {
if (IsChannelAllocated((psm))) {
LOG_INFO("Psm 0x%x for device %s is already in use", psm, link_->GetDevice().ToString().c_str());
return nullptr;
LOG_WARN("All cid are used");
return nullptr;
}
- auto elem = channels_.try_emplace(
- psm, std::make_shared<ClassicDynamicChannelImpl>(psm, cid, remote_cid, link_, l2cap_handler_));
+ auto elem =
+ channels_.try_emplace(psm, std::make_shared<DynamicChannelImpl>(psm, cid, remote_cid, link_, l2cap_handler_));
ASSERT_LOG(elem.second, "Failed to create channel for psm 0x%x device %s", psm,
link_->GetDevice().ToString().c_str());
ASSERT(elem.first->second != nullptr);
return elem.first->second;
}
-void ClassicDynamicChannelAllocator::FreeChannel(Psm psm) {
+void DynamicChannelAllocator::FreeChannel(Psm psm) {
ASSERT_LOG(IsChannelAllocated(psm), "Channel is not in use: psm %d, device %s", psm,
link_->GetDevice().ToString().c_str());
channels_.erase(psm);
}
-bool ClassicDynamicChannelAllocator::IsChannelAllocated(Psm psm) const {
+bool DynamicChannelAllocator::IsChannelAllocated(Psm psm) const {
return channels_.find(psm) != channels_.end();
}
-std::shared_ptr<ClassicDynamicChannelImpl> ClassicDynamicChannelAllocator::FindChannel(Psm psm) {
+std::shared_ptr<DynamicChannelImpl> DynamicChannelAllocator::FindChannel(Psm psm) {
ASSERT_LOG(IsChannelAllocated(psm), "Channel is not in use: psm %d, device %s", psm,
link_->GetDevice().ToString().c_str());
return channels_.find(psm)->second;
}
-size_t ClassicDynamicChannelAllocator::NumberOfChannels() const {
+size_t DynamicChannelAllocator::NumberOfChannels() const {
return channels_.size();
}
-void ClassicDynamicChannelAllocator::OnAclDisconnected(hci::ErrorCode reason) {
+void DynamicChannelAllocator::OnAclDisconnected(hci::ErrorCode reason) {
for (auto& elem : channels_) {
elem.second->OnClosed(reason);
}
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <unordered_map>
#include "l2cap/cid.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
#include "l2cap/psm.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicLink;
+class Link;
// Helper class for keeping channels in a Link. It allocates and frees Channel object, and supports querying whether a
// channel is in use
-class ClassicDynamicChannelAllocator {
+class DynamicChannelAllocator {
public:
- ClassicDynamicChannelAllocator(ClassicLink* link, os::Handler* l2cap_handler)
- : link_(link), l2cap_handler_(l2cap_handler) {
+ DynamicChannelAllocator(Link* link, os::Handler* l2cap_handler) : link_(link), l2cap_handler_(l2cap_handler) {
ASSERT(link_ != nullptr);
ASSERT(l2cap_handler_ != nullptr);
}
// Allocates a channel. If psm is used, OR the remote cid already exists, return nullptr.
- // NOTE: The returned ClassicDynamicChannelImpl object is still owned by the channel allocator, NOT the client.
- std::shared_ptr<ClassicDynamicChannelImpl> AllocateChannel(Psm psm, Cid remote_cid, SecurityPolicy security_policy);
+ // NOTE: The returned DynamicChannelImpl object is still owned by the channel allocator, NOT the client.
+ std::shared_ptr<DynamicChannelImpl> AllocateChannel(Psm psm, Cid remote_cid, SecurityPolicy security_policy);
// Frees a channel. If psm doesn't exist, it will crash
void FreeChannel(Psm psm);
bool IsChannelAllocated(Psm psm) const;
- std::shared_ptr<ClassicDynamicChannelImpl> FindChannel(Psm psm);
+ std::shared_ptr<DynamicChannelImpl> FindChannel(Psm psm);
size_t NumberOfChannels() const;
void OnAclDisconnected(hci::ErrorCode hci_status);
private:
- ClassicLink* link_;
+ Link* link_;
os::Handler* l2cap_handler_;
- std::unordered_map<Psm, std::shared_ptr<ClassicDynamicChannelImpl>> channels_;
+ std::unordered_map<Psm, std::shared_ptr<DynamicChannelImpl>> channels_;
std::set<Cid> used_cid_;
std::set<Cid> used_remote_cid_;
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/internal/classic_dynamic_channel_allocator.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/dynamic_channel_allocator.h"
+#include "l2cap/classic/internal/link_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
#include <gmock/gmock.h>
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-using testing::MockClassicLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
using ::testing::Return;
const hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
handler_ = new os::Handler(thread_);
mock_parameter_provider_ = new MockParameterProvider();
- mock_classic_link_ = new MockClassicLink(handler_, mock_parameter_provider_);
+ mock_classic_link_ = new MockLink(handler_, mock_parameter_provider_);
EXPECT_CALL(*mock_classic_link_, GetDevice()).WillRepeatedly(Return(device));
- channel_allocator_ = std::make_unique<ClassicDynamicChannelAllocator>(mock_classic_link_, handler_);
+ channel_allocator_ = std::make_unique<DynamicChannelAllocator>(mock_classic_link_, handler_);
}
void TearDown() override {
os::Thread* thread_{nullptr};
os::Handler* handler_{nullptr};
MockParameterProvider* mock_parameter_provider_{nullptr};
- MockClassicLink* mock_classic_link_{nullptr};
- std::unique_ptr<ClassicDynamicChannelAllocator> channel_allocator_;
+ MockLink* mock_classic_link_{nullptr};
+ std::unique_ptr<DynamicChannelAllocator> channel_allocator_;
};
TEST_F(L2capClassicDynamicChannelAllocatorTest, precondition) {
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <unordered_map>
#include "l2cap/cid.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/psm.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-ClassicDynamicChannelImpl::ClassicDynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, ClassicLink* link,
- os::Handler* l2cap_handler)
+DynamicChannelImpl::DynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, Link* link, os::Handler* l2cap_handler)
: psm_(psm), cid_(cid), remote_cid_(remote_cid), link_(link), l2cap_handler_(l2cap_handler),
device_(link->GetDevice()) {
ASSERT(IsPsmValid(psm_));
ASSERT(l2cap_handler_ != nullptr);
}
-hci::Address ClassicDynamicChannelImpl::GetDevice() const {
+hci::Address DynamicChannelImpl::GetDevice() const {
return device_;
}
-void ClassicDynamicChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
- ClassicDynamicChannel::OnCloseCallback on_close_callback) {
+void DynamicChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
+ DynamicChannel::OnCloseCallback on_close_callback) {
ASSERT_LOG(user_handler_ == nullptr, "OnCloseCallback can only be registered once");
// If channel is already closed, call the callback immediately without saving it
if (closed_) {
on_close_callback_ = std::move(on_close_callback);
}
-void ClassicDynamicChannelImpl::Close() {
+void DynamicChannelImpl::Close() {
// TODO: Implement it by sending signalling packet
}
-void ClassicDynamicChannelImpl::OnClosed(hci::ErrorCode status) {
+void DynamicChannelImpl::OnClosed(hci::ErrorCode status) {
ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(),
cid_, static_cast<int>(close_reason_), static_cast<int>(status));
closed_ = true;
on_close_callback_.Reset();
}
-std::string ClassicDynamicChannelImpl::ToString() {
+std::string DynamicChannelImpl::ToString() {
std::ostringstream ss;
ss << "Device " << device_.ToString() << "Psm 0x" << std::hex << psm_ << " Cid 0x" << std::hex << cid_;
return ss.str();
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include "common/bidi_queue.h"
#include "hci/address.h"
#include "l2cap/cid.h"
-#include "l2cap/classic_dynamic_channel.h"
+#include "l2cap/classic/dynamic_channel.h"
#include "l2cap/psm.h"
#include "os/handler.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicLink;
+class Link;
-class ClassicDynamicChannelImpl {
+class DynamicChannelImpl {
public:
- ClassicDynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, ClassicLink* link, os::Handler* l2cap_handler);
+ DynamicChannelImpl(Psm psm, Cid cid, Cid remote_cid, Link* link, os::Handler* l2cap_handler);
- virtual ~ClassicDynamicChannelImpl() = default;
+ virtual ~DynamicChannelImpl() = default;
hci::Address GetDevice() const;
- virtual void RegisterOnCloseCallback(os::Handler* user_handler,
- ClassicDynamicChannel::OnCloseCallback on_close_callback);
+ virtual void RegisterOnCloseCallback(os::Handler* user_handler, DynamicChannel::OnCloseCallback on_close_callback);
virtual void Close();
virtual void OnClosed(hci::ErrorCode status);
const Psm psm_;
const Cid cid_;
const Cid remote_cid_;
- ClassicLink* link_;
+ Link* link_;
os::Handler* l2cap_handler_;
const hci::Address device_;
// User supported states
os::Handler* user_handler_ = nullptr;
- ClassicDynamicChannel::OnCloseCallback on_close_callback_{};
+ DynamicChannel::OnCloseCallback on_close_callback_{};
// Internal states
bool closed_ = false;
common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
kChannelQueueSize};
- DISALLOW_COPY_AND_ASSIGN(ClassicDynamicChannelImpl);
+ DISALLOW_COPY_AND_ASSIGN(DynamicChannelImpl);
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
#include "common/testing/bind_test_util.h"
#include "l2cap/cid.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/link_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-using testing::MockClassicLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
using ::testing::Return;
class L2capClassicDynamicChannelImplTest : public ::testing::Test {
TEST_F(L2capClassicDynamicChannelImplTest, get_device) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
- l2cap_handler_);
+ DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+ l2cap_handler_);
EXPECT_EQ(device, dynamic_channel_impl.GetDevice());
}
TEST_F(L2capClassicDynamicChannelImplTest, close_triggers_callback) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
- l2cap_handler_);
+ DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+ l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capClassicDynamicChannelImplTest, register_callback_after_close_should_call_immediately) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
- l2cap_handler_);
+ DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+ l2cap_handler_);
// Channel closure should do nothing
dynamic_channel_impl.OnClosed(hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
TEST_F(L2capClassicDynamicChannelImplTest, close_twice_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
- l2cap_handler_);
+ DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+ l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capClassicDynamicChannelImplTest, multiple_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicDynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
- l2cap_handler_);
+ DynamicChannelImpl dynamic_channel_impl(0x01, kFirstDynamicChannel, kFirstDynamicChannel, &mock_classic_link,
+ l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#pragma once
-#include "l2cap/le_fixed_channel.h"
-#include "l2cap/le_fixed_channel_manager.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "common/bind.h"
+
+#include "l2cap/classic/dynamic_channel.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/dynamic_channel_service.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-
-class LeFixedChannelServiceImpl {
+class DynamicChannelServiceImpl {
public:
- virtual ~LeFixedChannelServiceImpl() = default;
+ virtual ~DynamicChannelServiceImpl() = default;
struct PendingRegistration {
os::Handler* user_handler_ = nullptr;
- LeFixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
- LeFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+ DynamicChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
+ DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
};
- virtual void NotifyChannelCreation(std::unique_ptr<LeFixedChannel> channel) {
+ virtual void NotifyChannelCreation(std::unique_ptr<DynamicChannel> channel) {
user_handler_->Post(common::BindOnce(on_connection_open_callback_, std::move(channel)));
}
- friend class LeFixedChannelServiceManagerImpl;
+ friend class DynamicChannelServiceManagerImpl;
protected:
// protected access for mocking
- LeFixedChannelServiceImpl(os::Handler* user_handler,
- LeFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
+ DynamicChannelServiceImpl(os::Handler* user_handler,
+ DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback)
: user_handler_(user_handler), on_connection_open_callback_(std::move(on_connection_open_callback)) {}
private:
os::Handler* user_handler_ = nullptr;
- LeFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+ DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
#include "common/bind.h"
-#include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_service_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_service_impl.h"
+#include "l2cap/psm.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-void LeFixedChannelServiceManagerImpl::Register(Cid cid,
- LeFixedChannelServiceImpl::PendingRegistration pending_registration) {
- if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kLeSignallingCid) {
- std::unique_ptr<LeFixedChannelService> invalid_service(new LeFixedChannelService());
+void DynamicChannelServiceManagerImpl::Register(Psm psm,
+ DynamicChannelServiceImpl::PendingRegistration pending_registration) {
+ if (!IsPsmValid(psm)) {
+ std::unique_ptr<DynamicChannelService> invalid_service(new DynamicChannelService());
pending_registration.user_handler_->Post(
common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
- LeFixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
- } else if (IsServiceRegistered(cid)) {
- std::unique_ptr<LeFixedChannelService> invalid_service(new LeFixedChannelService());
+ DynamicChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
+ } else if (IsServiceRegistered(psm)) {
+ std::unique_ptr<DynamicChannelService> invalid_service(new DynamicChannelService());
pending_registration.user_handler_->Post(common::BindOnce(
std::move(pending_registration.on_registration_complete_callback_),
- LeFixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
+ DynamicChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
} else {
- service_map_.try_emplace(cid,
- LeFixedChannelServiceImpl(pending_registration.user_handler_,
+ service_map_.try_emplace(psm,
+ DynamicChannelServiceImpl(pending_registration.user_handler_,
std::move(pending_registration.on_connection_open_callback_)));
- std::unique_ptr<LeFixedChannelService> user_service(new LeFixedChannelService(cid, this, l2cap_layer_handler_));
+ std::unique_ptr<DynamicChannelService> user_service(new DynamicChannelService(psm, this, l2cap_layer_handler_));
pending_registration.user_handler_->Post(
common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
- LeFixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
+ DynamicChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
}
}
-void LeFixedChannelServiceManagerImpl::Unregister(Cid cid, LeFixedChannelService::OnUnregisteredCallback callback,
+void DynamicChannelServiceManagerImpl::Unregister(Psm psm, DynamicChannelService::OnUnregisteredCallback callback,
os::Handler* handler) {
- if (IsServiceRegistered(cid)) {
- service_map_.erase(cid);
+ if (IsServiceRegistered(psm)) {
+ service_map_.erase(psm);
handler->Post(std::move(callback));
} else {
- LOG_ERROR("service not registered cid:%d", cid);
+ LOG_ERROR("service not registered psm:%d", psm);
}
}
-bool LeFixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
- return service_map_.find(cid) != service_map_.end();
+bool DynamicChannelServiceManagerImpl::IsServiceRegistered(Psm psm) const {
+ return service_map_.find(psm) != service_map_.end();
}
-LeFixedChannelServiceImpl* LeFixedChannelServiceManagerImpl::GetService(Cid cid) {
- ASSERT(IsServiceRegistered(cid));
- return &service_map_.find(cid)->second;
+DynamicChannelServiceImpl* DynamicChannelServiceManagerImpl::GetService(Psm psm) {
+ ASSERT(IsServiceRegistered(psm));
+ return &service_map_.find(psm)->second;
}
-std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> LeFixedChannelServiceManagerImpl::GetRegisteredServices() {
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> DynamicChannelServiceManagerImpl::GetRegisteredServices() {
+ std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> results;
for (auto& elem : service_map_) {
results.emplace_back(elem.first, &elem.second);
}
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <unordered_map>
-#include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_service_impl.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "l2cap/classic/dynamic_channel_service.h"
+#include "l2cap/classic/internal/dynamic_channel_service_impl.h"
+#include "l2cap/psm.h"
#include "os/handler.h"
+#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class LeFixedChannelServiceManagerImpl {
+class DynamicChannelServiceManagerImpl {
public:
- explicit LeFixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
+ explicit DynamicChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
: l2cap_layer_handler_(l2cap_layer_handler) {}
- virtual ~LeFixedChannelServiceManagerImpl() = default;
+ virtual ~DynamicChannelServiceManagerImpl() = default;
+ //
// All APIs must be invoked in L2CAP layer handler
-
- virtual void Register(Cid cid, LeFixedChannelServiceImpl::PendingRegistration pending_registration);
- virtual void Unregister(Cid cid, LeFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
- virtual bool IsServiceRegistered(Cid cid) const;
- virtual LeFixedChannelServiceImpl* GetService(Cid cid);
- virtual std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> GetRegisteredServices();
-
+ //
+ virtual void Register(Psm psm, DynamicChannelServiceImpl::PendingRegistration pending_registration);
+ virtual void Unregister(Psm psm, DynamicChannelService::OnUnregisteredCallback callback, os::Handler* handler);
+ virtual bool IsServiceRegistered(Psm psm) const;
+ virtual DynamicChannelServiceImpl* GetService(Psm psm);
+
+ virtual std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> GetRegisteredServices();
+ //
private:
os::Handler* l2cap_layer_handler_ = nullptr;
- std::unordered_map<Cid, LeFixedChannelServiceImpl> service_map_;
+ std::unordered_map<Psm, DynamicChannelServiceImpl> service_map_;
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
-
#include <future>
+#include <gtest/gtest.h>
+
#include "common/bind.h"
#include "l2cap/cid.h"
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/dynamic_channel_service.h"
+#include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
#include "os/handler.h"
#include "os/thread.h"
-#include <gtest/gtest.h>
-
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
class L2capDynamicServiceManagerTest : public ::testing::Test {
public:
~L2capDynamicServiceManagerTest() override = default;
- void OnServiceRegistered(bool expect_success, ClassicDynamicChannelManager::RegistrationResult result,
- std::unique_ptr<ClassicDynamicChannelService> user_service) {
- EXPECT_EQ(result == ClassicDynamicChannelManager::RegistrationResult::SUCCESS, expect_success);
+ void OnServiceRegistered(bool expect_success, DynamicChannelManager::RegistrationResult result,
+ std::unique_ptr<DynamicChannelService> user_service) {
+ EXPECT_EQ(result == DynamicChannelManager::RegistrationResult::SUCCESS, expect_success);
service_registered_ = expect_success;
}
thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
user_handler_ = new os::Handler(thread_);
l2cap_handler_ = new os::Handler(thread_);
- manager_ = new ClassicDynamicChannelServiceManagerImpl{l2cap_handler_};
+ manager_ = new DynamicChannelServiceManagerImpl{l2cap_handler_};
}
void TearDown() override {
future.wait_for(std::chrono::milliseconds(3));
}
- ClassicDynamicChannelServiceManagerImpl* manager_ = nullptr;
+ DynamicChannelServiceManagerImpl* manager_ = nullptr;
os::Thread* thread_ = nullptr;
os::Handler* user_handler_ = nullptr;
os::Handler* l2cap_handler_ = nullptr;
};
TEST_F(L2capDynamicServiceManagerTest, register_and_unregister_classic_dynamic_channel) {
- ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration{
+ DynamicChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = user_handler_,
.on_registration_complete_callback_ =
common::BindOnce(&L2capDynamicServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
}
TEST_F(L2capDynamicServiceManagerTest, register_classic_dynamic_channel_bad_cid) {
- ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration{
+ DynamicChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = user_handler_,
.on_registration_complete_callback_ =
common::BindOnce(&L2capDynamicServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <unordered_map>
#include "l2cap/cid.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-ClassicFixedChannelImpl::ClassicFixedChannelImpl(Cid cid, ClassicLink* link, os::Handler* l2cap_handler)
+FixedChannelImpl::FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler)
: cid_(cid), device_(link->GetDevice()), link_(link), l2cap_handler_(l2cap_handler) {
ASSERT_LOG(cid_ >= kFirstFixedChannel && cid_ <= kLastFixedChannel, "Invalid cid: %d", cid_);
ASSERT(!device_.IsEmpty());
ASSERT(l2cap_handler_ != nullptr);
}
-void ClassicFixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
- ClassicFixedChannel::OnCloseCallback on_close_callback) {
+void FixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
+ FixedChannel::OnCloseCallback on_close_callback) {
ASSERT_LOG(user_handler_ == nullptr, "OnCloseCallback can only be registered once");
// If channel is already closed, call the callback immediately without saving it
if (closed_) {
on_close_callback_ = std::move(on_close_callback);
}
-void ClassicFixedChannelImpl::OnClosed(hci::ErrorCode status) {
+void FixedChannelImpl::OnClosed(hci::ErrorCode status) {
ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(),
cid_, static_cast<int>(close_reason_), static_cast<int>(status));
closed_ = true;
on_close_callback_.Reset();
}
-void ClassicFixedChannelImpl::Acquire() {
+void FixedChannelImpl::Acquire() {
ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
if (closed_) {
LOG_WARN("%s is already closed", ToString().c_str());
link_->RefreshRefCount();
}
-void ClassicFixedChannelImpl::Release() {
+void FixedChannelImpl::Release() {
ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
if (closed_) {
LOG_WARN("%s is already closed", ToString().c_str());
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include "common/bidi_queue.h"
#include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel.h"
+#include "l2cap/classic/fixed_channel.h"
#include "os/handler.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicLink;
+class Link;
-class ClassicFixedChannelImpl {
+class FixedChannelImpl {
public:
- ClassicFixedChannelImpl(Cid cid, ClassicLink* link, os::Handler* l2cap_handler);
+ FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler);
- virtual ~ClassicFixedChannelImpl() = default;
+ virtual ~FixedChannelImpl() = default;
hci::Address GetDevice() const {
return device_;
}
- virtual void RegisterOnCloseCallback(os::Handler* user_handler,
- ClassicFixedChannel::OnCloseCallback on_close_callback);
+ virtual void RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback);
virtual void Acquire();
// For logging purpose only
const hci::Address device_;
// Needed to handle Acquire() and Release()
- ClassicLink* link_;
+ Link* link_;
os::Handler* l2cap_handler_;
// User supported states
os::Handler* user_handler_ = nullptr;
- ClassicFixedChannel::OnCloseCallback on_close_callback_{};
+ FixedChannel::OnCloseCallback on_close_callback_{};
// Internal states
bool acquired_ = false;
common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
kChannelQueueSize};
- DISALLOW_COPY_AND_ASSIGN(ClassicFixedChannelImpl);
+ DISALLOW_COPY_AND_ASSIGN(FixedChannelImpl);
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
*/
#pragma once
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
namespace testing {
-class MockClassicFixedChannelImpl : public ClassicFixedChannelImpl {
+class MockFixedChannelImpl : public FixedChannelImpl {
public:
- MockClassicFixedChannelImpl(Cid cid, ClassicLink* link, os::Handler* l2cap_handler)
- : ClassicFixedChannelImpl(cid, link, l2cap_handler) {}
+ MockFixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler) : FixedChannelImpl(cid, link, l2cap_handler) {}
MOCK_METHOD(void, RegisterOnCloseCallback,
- (os::Handler * user_handler, ClassicFixedChannel::OnCloseCallback on_close_callback), (override));
+ (os::Handler * user_handler, FixedChannel::OnCloseCallback on_close_callback), (override));
MOCK_METHOD(void, Acquire, (), (override));
MOCK_METHOD(void, Release, (), (override));
MOCK_METHOD(bool, IsAcquired, (), (override, const));
} // namespace testing
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
#include "common/testing/bind_test_util.h"
#include "l2cap/cid.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/link_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-using testing::MockClassicLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
using ::testing::Return;
class L2capClassicFixedChannelImplTest : public ::testing::Test {
TEST_F(L2capClassicFixedChannelImplTest, get_device) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
EXPECT_EQ(device, fixed_channel_impl.GetDevice());
}
TEST_F(L2capClassicFixedChannelImplTest, close_triggers_callback) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capClassicFixedChannelImplTest, register_callback_after_close_should_call_immediately) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
// Channel closure should do nothing
fixed_channel_impl.OnClosed(hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
TEST_F(L2capClassicFixedChannelImplTest, close_twice_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capClassicFixedChannelImplTest, multiple_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capClassicFixedChannelImplTest, call_acquire_before_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
EXPECT_DEATH(fixed_channel_impl.Acquire(), ".*Acquire.*");
}
TEST_F(L2capClassicFixedChannelImplTest, call_release_before_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
EXPECT_DEATH(fixed_channel_impl.Release(), ".*Release.*");
}
TEST_F(L2capClassicFixedChannelImplTest, test_acquire_release_channel) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capClassicFixedChannelImplTest, test_acquire_after_close) {
MockParameterProvider mock_parameter_provider;
- MockClassicLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_classic_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_classic_link, GetDevice()).WillRepeatedly(Return(device));
- ClassicFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_classic_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#pragma once
-#include "l2cap/classic_fixed_channel.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/fixed_channel_service.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicFixedChannelServiceImpl {
+class FixedChannelServiceImpl {
public:
- virtual ~ClassicFixedChannelServiceImpl() = default;
+ virtual ~FixedChannelServiceImpl() = default;
struct PendingRegistration {
os::Handler* user_handler_ = nullptr;
- ClassicFixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
- ClassicFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+ FixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
+ FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
};
- virtual void NotifyChannelCreation(std::unique_ptr<ClassicFixedChannel> channel) {
+ virtual void NotifyChannelCreation(std::unique_ptr<FixedChannel> channel) {
user_handler_->Post(common::BindOnce(on_connection_open_callback_, std::move(channel)));
}
- friend class ClassicFixedChannelServiceManagerImpl;
+ friend class FixedChannelServiceManagerImpl;
protected:
// protected access for mocking
- ClassicFixedChannelServiceImpl(os::Handler* user_handler,
- ClassicFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
+ FixedChannelServiceImpl(os::Handler* user_handler,
+ FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
: user_handler_(user_handler), on_connection_open_callback_(std::move(on_connection_open_callback)) {}
private:
os::Handler* user_handler_ = nullptr;
- ClassicFixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+ FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
*/
#pragma once
-#include "l2cap/internal/classic_fixed_channel_impl.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
namespace testing {
-class MockClassicFixedChannelServiceImpl : public ClassicFixedChannelServiceImpl {
+class MockFixedChannelServiceImpl : public FixedChannelServiceImpl {
public:
- MockClassicFixedChannelServiceImpl()
- : ClassicFixedChannelServiceImpl(nullptr, ClassicFixedChannelManager::OnConnectionOpenCallback()) {}
- MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<ClassicFixedChannel> channel), (override));
+ MockFixedChannelServiceImpl() : FixedChannelServiceImpl(nullptr, FixedChannelManager::OnConnectionOpenCallback()) {}
+ MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<FixedChannel> channel), (override));
};
} // namespace testing
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2019 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.
+ */
+
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+
+#include "common/bind.h"
+#include "l2cap/cid.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl.h"
+#include "os/log.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace classic {
+namespace internal {
+
+void FixedChannelServiceManagerImpl::Register(Cid cid,
+ FixedChannelServiceImpl::PendingRegistration pending_registration) {
+ if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kClassicSignallingCid) {
+ std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+ pending_registration.user_handler_->Post(
+ common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+ FixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
+ } else if (IsServiceRegistered(cid)) {
+ std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+ pending_registration.user_handler_->Post(
+ common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+ FixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
+ } else {
+ service_map_.try_emplace(cid,
+ FixedChannelServiceImpl(pending_registration.user_handler_,
+ std::move(pending_registration.on_connection_open_callback_)));
+ std::unique_ptr<FixedChannelService> user_service(new FixedChannelService(cid, this, l2cap_layer_handler_));
+ pending_registration.user_handler_->Post(
+ common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+ FixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
+ }
+}
+
+void FixedChannelServiceManagerImpl::Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback,
+ os::Handler* handler) {
+ if (IsServiceRegistered(cid)) {
+ service_map_.erase(cid);
+ handler->Post(std::move(callback));
+ } else {
+ LOG_ERROR("service not registered cid:%d", cid);
+ }
+}
+
+bool FixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
+ return service_map_.find(cid) != service_map_.end();
+}
+
+FixedChannelServiceImpl* FixedChannelServiceManagerImpl::GetService(Cid cid) {
+ ASSERT(IsServiceRegistered(cid));
+ return &service_map_.find(cid)->second;
+}
+
+std::vector<std::pair<Cid, FixedChannelServiceImpl*>> FixedChannelServiceManagerImpl::GetRegisteredServices() {
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
+ for (auto& elem : service_map_) {
+ results.emplace_back(elem.first, &elem.second);
+ }
+ return results;
+}
+
+} // namespace internal
+} // namespace classic
+} // namespace l2cap
+} // namespace bluetooth
#include <unordered_map>
#include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel_service.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl.h"
+#include "l2cap/classic/fixed_channel_service.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicFixedChannelServiceManagerImpl {
+class FixedChannelServiceManagerImpl {
public:
- explicit ClassicFixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
+ explicit FixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
: l2cap_layer_handler_(l2cap_layer_handler) {}
- virtual ~ClassicFixedChannelServiceManagerImpl() = default;
+ virtual ~FixedChannelServiceManagerImpl() = default;
// All APIs must be invoked in L2CAP layer handler
- virtual void Register(Cid cid, ClassicFixedChannelServiceImpl::PendingRegistration pending_registration);
- virtual void Unregister(Cid cid, ClassicFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
+ virtual void Register(Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration);
+ virtual void Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
virtual bool IsServiceRegistered(Cid cid) const;
- virtual ClassicFixedChannelServiceImpl* GetService(Cid cid);
- virtual std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> GetRegisteredServices();
+ virtual FixedChannelServiceImpl* GetService(Cid cid);
+ virtual std::vector<std::pair<Cid, FixedChannelServiceImpl*>> GetRegisteredServices();
private:
os::Handler* l2cap_layer_handler_ = nullptr;
- std::unordered_map<Cid, ClassicFixedChannelServiceImpl> service_map_;
+ std::unordered_map<Cid, FixedChannelServiceImpl> service_map_;
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
*/
#pragma once
-#include "l2cap/internal/classic_fixed_channel_impl.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
namespace testing {
-class MockClassicFixedChannelServiceManagerImpl : public ClassicFixedChannelServiceManagerImpl {
+class MockFixedChannelServiceManagerImpl : public FixedChannelServiceManagerImpl {
public:
- MockClassicFixedChannelServiceManagerImpl() : ClassicFixedChannelServiceManagerImpl(nullptr) {}
- MOCK_METHOD(void, Register, (Cid cid, ClassicFixedChannelServiceImpl::PendingRegistration pending_registration),
+ MockFixedChannelServiceManagerImpl() : FixedChannelServiceManagerImpl(nullptr) {}
+ MOCK_METHOD(void, Register, (Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration), (override));
+ MOCK_METHOD(void, Unregister, (Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler),
(override));
- MOCK_METHOD(void, Unregister,
- (Cid cid, ClassicFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler), (override));
MOCK_METHOD(bool, IsServiceRegistered, (Cid cid), (const, override));
- MOCK_METHOD(ClassicFixedChannelServiceImpl*, GetService, (Cid cid), (override));
- MOCK_METHOD((std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
+ MOCK_METHOD(FixedChannelServiceImpl*, GetService, (Cid cid), (override));
+ MOCK_METHOD((std::vector<std::pair<Cid, FixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
};
} // namespace testing
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
* limitations under the License.
*/
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
#include <future>
#include "common/bind.h"
#include "l2cap/cid.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/classic_fixed_channel_service.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/fixed_channel_service.h"
#include "os/handler.h"
#include "os/thread.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class L2capFixedServiceManagerTest : public ::testing::Test {
+class L2capClassicFixedServiceManagerTest : public ::testing::Test {
public:
- ~L2capFixedServiceManagerTest() override = default;
+ ~L2capClassicFixedServiceManagerTest() override = default;
- void OnServiceRegistered(bool expect_success, ClassicFixedChannelManager::RegistrationResult result,
- std::unique_ptr<ClassicFixedChannelService> user_service) {
- EXPECT_EQ(result == ClassicFixedChannelManager::RegistrationResult::SUCCESS, expect_success);
+ void OnServiceRegistered(bool expect_success, FixedChannelManager::RegistrationResult result,
+ std::unique_ptr<FixedChannelService> user_service) {
+ EXPECT_EQ(result == FixedChannelManager::RegistrationResult::SUCCESS, expect_success);
service_registered_ = expect_success;
}
protected:
void SetUp() override {
- manager_ = new ClassicFixedChannelServiceManagerImpl{nullptr};
+ manager_ = new FixedChannelServiceManagerImpl{nullptr};
thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
user_handler_ = new os::Handler(thread_);
}
future.wait_for(std::chrono::milliseconds(3));
}
- ClassicFixedChannelServiceManagerImpl* manager_ = nullptr;
+ FixedChannelServiceManagerImpl* manager_ = nullptr;
os::Thread* thread_ = nullptr;
os::Handler* user_handler_ = nullptr;
bool service_registered_ = false;
};
-TEST_F(L2capFixedServiceManagerTest, register_and_unregister_classic_fixed_channel) {
- ClassicFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capClassicFixedServiceManagerTest, register_and_unregister_classic_fixed_channel) {
+ FixedChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = user_handler_,
.on_registration_complete_callback_ =
- common::BindOnce(&L2capFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
+ common::BindOnce(&L2capClassicFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
Cid cid = kSmpBrCid;
EXPECT_FALSE(manager_->IsServiceRegistered(cid));
manager_->Register(cid, std::move(pending_registration));
EXPECT_FALSE(manager_->IsServiceRegistered(cid));
}
-TEST_F(L2capFixedServiceManagerTest, register_classic_fixed_channel_bad_cid) {
- ClassicFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capClassicFixedServiceManagerTest, register_classic_fixed_channel_bad_cid) {
+ FixedChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = user_handler_,
.on_registration_complete_callback_ =
- common::BindOnce(&L2capFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
+ common::BindOnce(&L2capClassicFixedServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
Cid cid = 0x1000;
EXPECT_FALSE(manager_->IsServiceRegistered(cid));
manager_->Register(cid, std::move(pending_registration));
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/internal/classic_link.h"
-
#include <chrono>
#include <memory>
#include "hci/acl_manager.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/internal/parameter_provider.h"
#include "l2cap/internal/scheduler.h"
#include "os/alarm.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-ClassicLink::ClassicLink(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
- std::unique_ptr<Scheduler> scheduler, ParameterProvider* parameter_provider)
+Link::Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
+ std::unique_ptr<l2cap::internal::Scheduler> scheduler,
+ l2cap::internal::ParameterProvider* parameter_provider)
: l2cap_handler_(l2cap_handler), acl_connection_(std::move(acl_connection)), scheduler_(std::move(scheduler)),
parameter_provider_(parameter_provider) {
ASSERT(l2cap_handler_ != nullptr);
ASSERT(acl_connection_ != nullptr);
ASSERT(scheduler_ != nullptr);
ASSERT(parameter_provider_ != nullptr);
- acl_connection_->RegisterDisconnectCallback(
- common::BindOnce(&ClassicLink::OnAclDisconnected, common::Unretained(this)), l2cap_handler_);
- link_idle_disconnect_alarm_.Schedule(common::BindOnce(&ClassicLink::Disconnect, common::Unretained(this)),
+ acl_connection_->RegisterDisconnectCallback(common::BindOnce(&Link::OnAclDisconnected, common::Unretained(this)),
+ l2cap_handler_);
+ link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
}
-void ClassicLink::OnAclDisconnected(hci::ErrorCode status) {
+void Link::OnAclDisconnected(hci::ErrorCode status) {
fixed_channel_allocator_.OnAclDisconnected(status);
// TODO hsz: add dynamic channel part
}
-void ClassicLink::Disconnect() {
+void Link::Disconnect() {
acl_connection_->Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION);
}
-std::shared_ptr<ClassicFixedChannelImpl> ClassicLink::AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
+std::shared_ptr<FixedChannelImpl> Link::AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
auto channel = fixed_channel_allocator_.AllocateChannel(cid, security_policy);
scheduler_->AttachChannel(cid, channel->GetQueueDownEnd());
return channel;
}
-bool ClassicLink::IsFixedChannelAllocated(Cid cid) {
+bool Link::IsFixedChannelAllocated(Cid cid) {
return fixed_channel_allocator_.IsChannelAllocated(cid);
}
-std::shared_ptr<ClassicDynamicChannelImpl> ClassicLink::AllocateDynamicChannel(Psm psm, Cid remote_cid,
- SecurityPolicy security_policy) {
+std::shared_ptr<DynamicChannelImpl> Link::AllocateDynamicChannel(Psm psm, Cid remote_cid,
+ SecurityPolicy security_policy) {
auto channel = dynamic_channel_allocator_.AllocateChannel(psm, remote_cid, security_policy);
scheduler_->AttachChannel(channel->GetCid(), channel->GetQueueDownEnd());
return channel;
}
-void ClassicLink::FreeDynamicChannel(Cid cid) {}
+void Link::FreeDynamicChannel(Cid cid) {}
-void ClassicLink::RefreshRefCount() {
+void Link::RefreshRefCount() {
int ref_count = 0;
ref_count += fixed_channel_allocator_.GetRefCount();
ref_count += dynamic_channel_allocator_.NumberOfChannels();
if (ref_count > 0) {
link_idle_disconnect_alarm_.Cancel();
} else {
- link_idle_disconnect_alarm_.Schedule(common::BindOnce(&ClassicLink::Disconnect, common::Unretained(this)),
+ link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
}
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <memory>
#include "hci/acl_manager.h"
-#include "l2cap/internal/classic_dynamic_channel_allocator.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
-#include "l2cap/internal/classic_fixed_channel_impl.h"
+#include "l2cap/classic/internal/dynamic_channel_allocator.h"
+#include "l2cap/classic/internal/dynamic_channel_impl.h"
+#include "l2cap/classic/internal/fixed_channel_impl.h"
#include "l2cap/internal/fixed_channel_allocator.h"
#include "l2cap/internal/parameter_provider.h"
#include "l2cap/internal/scheduler.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicLink {
+class Link {
public:
- ClassicLink(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
- std::unique_ptr<Scheduler> scheduler, ParameterProvider* parameter_provider);
+ Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
+ std::unique_ptr<l2cap::internal::Scheduler> scheduler, l2cap::internal::ParameterProvider* parameter_provider);
- virtual ~ClassicLink() = default;
+ virtual ~Link() = default;
virtual hci::Address GetDevice() {
return acl_connection_->GetAddress();
virtual void Disconnect();
- // ClassicFixedChannel methods
+ // FixedChannel methods
- virtual std::shared_ptr<ClassicFixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy);
+ virtual std::shared_ptr<FixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy);
virtual bool IsFixedChannelAllocated(Cid cid);
// ClassicDynamicChannel methods
- virtual std::shared_ptr<ClassicDynamicChannelImpl> AllocateDynamicChannel(Psm psm, Cid remote_cid,
- SecurityPolicy security_policy);
+ virtual std::shared_ptr<DynamicChannelImpl> AllocateDynamicChannel(Psm psm, Cid remote_cid,
+ SecurityPolicy security_policy);
virtual void FreeDynamicChannel(Cid cid);
private:
os::Handler* l2cap_handler_;
- FixedChannelAllocator<ClassicFixedChannelImpl, ClassicLink> fixed_channel_allocator_{this, l2cap_handler_};
- ClassicDynamicChannelAllocator dynamic_channel_allocator_{this, l2cap_handler_};
+ l2cap::internal::FixedChannelAllocator<FixedChannelImpl, Link> fixed_channel_allocator_{this, l2cap_handler_};
+ DynamicChannelAllocator dynamic_channel_allocator_{this, l2cap_handler_};
std::unique_ptr<hci::AclConnection> acl_connection_;
- std::unique_ptr<Scheduler> scheduler_;
- ParameterProvider* parameter_provider_;
+ std::unique_ptr<l2cap::internal::Scheduler> scheduler_;
+ l2cap::internal::ParameterProvider* parameter_provider_;
os::Alarm link_idle_disconnect_alarm_{l2cap_handler_};
- DISALLOW_COPY_AND_ASSIGN(ClassicLink);
+ DISALLOW_COPY_AND_ASSIGN(Link);
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager.h"
#include "hci/address.h"
-#include "l2cap/internal/classic_link.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/internal/scheduler_fifo.h"
-#include "l2cap/l2cap_layer.h"
#include "os/handler.h"
#include "os/log.h"
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/internal/link_manager.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-void ClassicLinkManager::ConnectFixedChannelServices(hci::Address device,
- PendingFixedChannelConnection pending_fixed_channel_connection) {
+void LinkManager::ConnectFixedChannelServices(hci::Address device,
+ PendingFixedChannelConnection pending_fixed_channel_connection) {
// Check if there is any service registered
auto fixed_channel_services = service_manager_->GetRegisteredServices();
if (fixed_channel_services.empty()) {
// If so, return error
pending_fixed_channel_connection.handler_->Post(common::BindOnce(
std::move(pending_fixed_channel_connection.on_fail_callback_),
- ClassicFixedChannelManager::ConnectionResult{
- .connection_result_code = ClassicFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
+ FixedChannelManager::ConnectionResult{
+ .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
return;
}
// Otherwise, check if device has an ACL connection
// Allocate channel for newly registered fixed channels
auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
fixed_channel_service.second->NotifyChannelCreation(
- std::make_unique<ClassicFixedChannel>(fixed_channel_impl, l2cap_handler_));
+ std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
num_new_channels++;
}
// Declare connection failure if no new channels are created
if (num_new_channels == 0) {
- pending_fixed_channel_connection.handler_->Post(
- common::BindOnce(std::move(pending_fixed_channel_connection.on_fail_callback_),
- ClassicFixedChannelManager::ConnectionResult{
- .connection_result_code =
- ClassicFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
+ pending_fixed_channel_connection.handler_->Post(common::BindOnce(
+ std::move(pending_fixed_channel_connection.on_fail_callback_),
+ FixedChannelManager::ConnectionResult{
+ .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
}
// No need to create ACL connection, return without saving any pending connections
return;
acl_manager_->CreateConnection(device);
}
-ClassicLink* ClassicLinkManager::GetLink(const hci::Address device) {
+Link* LinkManager::GetLink(const hci::Address device) {
if (links_.find(device) == links_.end()) {
return nullptr;
}
return &links_.find(device)->second;
}
-void ClassicLinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
+void LinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
// Same link should not be connected twice
hci::Address device = acl_connection->GetAddress();
ASSERT_LOG(GetLink(device) == nullptr, "%s is connected twice without disconnection",
acl_connection->GetAddress().ToString().c_str());
auto* link_queue_up_end = acl_connection->GetAclQueueEnd();
links_.try_emplace(device, l2cap_handler_, std::move(acl_connection),
- std::make_unique<Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
+ std::make_unique<l2cap::internal::Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
auto* link = GetLink(device);
// Allocate and distribute channels for all registered fixed channel services
auto fixed_channel_services = service_manager_->GetRegisteredServices();
for (auto& fixed_channel_service : fixed_channel_services) {
auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
fixed_channel_service.second->NotifyChannelCreation(
- std::make_unique<ClassicFixedChannel>(fixed_channel_impl, l2cap_handler_));
+ std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
}
// Remove device from pending links list, if any
auto pending_link = pending_links_.find(device);
pending_links_.erase(pending_link);
}
-void ClassicLinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reason) {
+void LinkManager::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()) {
return;
}
for (auto& pending_fixed_channel_connection : pending_link->second.pending_fixed_channel_connections_) {
- pending_fixed_channel_connection.handler_->Post(
- common::BindOnce(std::move(pending_fixed_channel_connection.on_fail_callback_),
- ClassicFixedChannelManager::ConnectionResult{
- .connection_result_code = ClassicFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR,
- .hci_error = reason}));
+ pending_fixed_channel_connection.handler_->Post(common::BindOnce(
+ std::move(pending_fixed_channel_connection.on_fail_callback_),
+ FixedChannelManager::ConnectionResult{
+ .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR, .hci_error = reason}));
}
// Remove entry in pending link list
pending_links_.erase(pending_link);
}
-void ClassicLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
+void LinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
auto* link = GetLink(device);
ASSERT_LOG(link != nullptr, "Device %s is disconnected with reason 0x%x, but not in local database",
device.ToString().c_str(), static_cast<uint8_t>(status));
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include <memory>
#include <unordered_map>
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link.h"
+#include "hci/acl_manager.h"
+#include "hci/address.h"
+#include "l2cap/classic/dynamic_channel_manager.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/internal/parameter_provider.h"
#include "l2cap/internal/scheduler.h"
#include "os/handler.h"
-#include "hci/acl_manager.h"
-#include "hci/address.h"
-
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
-class ClassicLinkManager : public hci::ConnectionCallbacks {
+class LinkManager : public hci::ConnectionCallbacks {
public:
- ClassicLinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager,
- ClassicFixedChannelServiceManagerImpl* service_manager, ParameterProvider* parameter_provider)
+ LinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager, FixedChannelServiceManagerImpl* service_manager,
+ l2cap::internal::ParameterProvider* parameter_provider)
: l2cap_handler_(l2cap_handler), acl_manager_(acl_manager), service_manager_(service_manager),
parameter_provider_(parameter_provider) {
acl_manager_->RegisterCallbacks(this, l2cap_handler_);
struct PendingFixedChannelConnection {
os::Handler* handler_;
- ClassicFixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
+ FixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
};
struct PendingDynamicChannelConnection {
os::Handler* handler_;
- ClassicDynamicChannelManager::OnConnectionOpenCallback on_open_callback_;
- ClassicDynamicChannelManager::OnConnectionFailureCallback on_fail_callback_;
+ DynamicChannelManager::OnConnectionOpenCallback on_open_callback_;
+ DynamicChannelManager::OnConnectionFailureCallback on_fail_callback_;
};
struct PendingLink {
// ACL methods
- ClassicLink* GetLink(hci::Address device);
+ Link* GetLink(hci::Address device);
void OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) override;
void OnConnectFail(hci::Address device, hci::ErrorCode reason) override;
void OnDisconnect(hci::Address device, hci::ErrorCode status);
- // ClassicFixedChannelManager methods
+ // FixedChannelManager methods
void ConnectFixedChannelServices(hci::Address device, PendingFixedChannelConnection pending_fixed_channel_connection);
// Dependencies
os::Handler* l2cap_handler_;
hci::AclManager* acl_manager_;
- ClassicFixedChannelServiceManagerImpl* service_manager_;
- ParameterProvider* parameter_provider_;
+ FixedChannelServiceManagerImpl* service_manager_;
+ l2cap::internal::ParameterProvider* parameter_provider_;
// Internal states
std::unordered_map<hci::Address, PendingLink> pending_links_;
- std::unordered_map<hci::Address, ClassicLink> links_;
- DISALLOW_COPY_AND_ASSIGN(ClassicLinkManager);
+ std::unordered_map<hci::Address, Link> links_;
+ DISALLOW_COPY_AND_ASSIGN(LinkManager);
};
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/internal/classic_link_manager.h"
+#include "l2cap/classic/internal/link_manager.h"
#include <future>
#include <thread>
#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"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl_mock.h"
+#include "l2cap/classic/fixed_channel_manager.h"
+#include "l2cap/classic/internal/fixed_channel_service_impl_mock.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
#include "os/handler.h"
#include "os/thread.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
using hci::testing::MockAclConnection;
using hci::testing::MockAclManager;
+using l2cap::internal::testing::MockParameterProvider;
using ::testing::_; // Matcher to any value
using ::testing::ByMove;
using ::testing::DoAll;
-using testing::MockClassicFixedChannelServiceImpl;
-using testing::MockClassicFixedChannelServiceManagerImpl;
-using testing::MockParameterProvider;
+using testing::MockFixedChannelServiceImpl;
+using testing::MockFixedChannelServiceManagerImpl;
using ::testing::Return;
using ::testing::SaveArg;
};
TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl) {
- MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
auto user_handler = std::make_unique<os::Handler>(thread_);
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
- &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+ LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
- .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
- .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+ channel_1 = std::move(channel);
+ });
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+ channel_2 = std::move(channel);
+ });
hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
SyncHandler(hci_callback_handler);
EXPECT_NE(channel_2, nullptr);
// Step 4: Calling ConnectServices() to the same device will no trigger another connection attempt
- ClassicFixedChannelManager::ConnectionResult my_result;
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
+ FixedChannelManager::ConnectionResult my_result;
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
.handler_ = user_handler.get(),
.on_fail_callback_ = common::testing::BindLambdaForTesting(
- [&my_result](ClassicFixedChannelManager::ConnectionResult result) { my_result = result; })};
+ [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection_2));
SyncHandler(user_handler.get());
EXPECT_EQ(my_result.connection_result_code,
- ClassicFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
+ FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
// Step 5: Register new service will cause new channels to be created during ConnectServices()
- MockClassicFixedChannelServiceImpl mock_service_3;
+ MockFixedChannelServiceImpl mock_service_3;
results.emplace_back(kSmpBrCid + 1, &mock_service_3);
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
- std::unique_ptr<ClassicFixedChannel> channel_3;
- EXPECT_CALL(mock_service_3, NotifyChannelCreation(_))
- .WillOnce([&channel_3](std::unique_ptr<ClassicFixedChannel> channel) { channel_3 = std::move(channel); });
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
+ std::unique_ptr<FixedChannel> channel_3;
+ EXPECT_CALL(mock_service_3, NotifyChannelCreation(_)).WillOnce([&channel_3](std::unique_ptr<FixedChannel> channel) {
+ channel_3 = std::move(channel);
+ });
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection_3));
EXPECT_NE(channel_3, nullptr);
}
TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_with_no_service) {
- MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
auto user_handler = std::make_unique<os::Handler>(thread_);
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
- &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+ LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Make sure no service is registered
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without any service registered will result in failure
EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(0);
- ClassicFixedChannelManager::ConnectionResult my_result;
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ FixedChannelManager::ConnectionResult my_result;
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
.on_fail_callback_ = common::testing::BindLambdaForTesting(
- [&my_result](ClassicFixedChannelManager::ConnectionResult result) { my_result = result; })};
+ [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
SyncHandler(user_handler.get());
- EXPECT_EQ(my_result.connection_result_code,
- ClassicFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
+ EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
user_handler->Clear();
}
TEST_F(L2capClassicLinkManagerTest, connect_fixed_channel_service_without_acl_with_hci_failure) {
- MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
auto user_handler = std::make_unique<os::Handler>(thread_);
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
- &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+ LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockClassicFixedChannelServiceImpl mock_service_1;
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
- ClassicFixedChannelManager::ConnectionResult my_result;
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ FixedChannelManager::ConnectionResult my_result;
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
.on_fail_callback_ = common::testing::BindLambdaForTesting(
- [&my_result](ClassicFixedChannelManager::ConnectionResult result) { my_result = result; })};
+ [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection failure event should trigger connection failure callback
hci::ErrorCode::PAGE_TIMEOUT));
SyncHandler(hci_callback_handler);
SyncHandler(user_handler.get());
- EXPECT_EQ(my_result.connection_result_code, ClassicFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
+ EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
EXPECT_EQ(my_result.hci_error, hci::ErrorCode::PAGE_TIMEOUT);
user_handler->Clear();
TEST_F(L2capClassicLinkManagerTest, not_acquiring_channels_should_disconnect_acl_after_timeout) {
EXPECT_CALL(*mock_parameter_provider_, GetClassicLinkIdleDisconnectTimeout)
.WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
- MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
auto user_handler = std::make_unique<os::Handler>(thread_);
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
- &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+ LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
- .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
- .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+ channel_1 = std::move(channel);
+ });
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+ channel_2 = std::move(channel);
+ });
hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
SyncHandler(hci_callback_handler);
TEST_F(L2capClassicLinkManagerTest, acquiring_channels_should_not_disconnect_acl_after_timeout) {
EXPECT_CALL(*mock_parameter_provider_, GetClassicLinkIdleDisconnectTimeout)
.WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
- MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
auto user_handler = std::make_unique<os::Handler>(thread_);
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
- &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+ LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
- .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
- .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+ channel_1 = std::move(channel);
+ });
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+ channel_2 = std::move(channel);
+ });
hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
SyncHandler(hci_callback_handler);
TEST_F(L2capClassicLinkManagerTest, acquiring_and_releasing_channels_should_eventually_disconnect_acl) {
EXPECT_CALL(*mock_parameter_provider_, GetClassicLinkIdleDisconnectTimeout)
.WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
- MockClassicFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_classic_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
auto user_handler = std::make_unique<os::Handler>(thread_);
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- ClassicLinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager,
- &mock_classic_fixed_channel_service_manager, mock_parameter_provider_);
+ LinkManager classic_link_manager(l2cap_handler_, &mock_acl_manager, &mock_classic_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_connection_callbacks, &classic_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockClassicFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_classic_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateConnection(device)).Times(1);
- ClassicLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](ClassicFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
classic_link_manager.ConnectFixedChannelServices(device, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<ClassicFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_))
- .WillOnce([&channel_1](std::unique_ptr<ClassicFixedChannel> channel) { channel_1 = std::move(channel); });
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_))
- .WillOnce([&channel_2](std::unique_ptr<ClassicFixedChannel> channel) { channel_2 = std::move(channel); });
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
+ channel_1 = std::move(channel);
+ });
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
+ channel_2 = std::move(channel);
+ });
hci_callback_handler->Post(common::BindOnce(&hci::ConnectionCallbacks::OnConnectSuccess,
common::Unretained(hci_connection_callbacks), std::move(acl_connection)));
SyncHandler(hci_callback_handler);
}
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager_mock.h"
#include "hci/address.h"
-#include "l2cap/internal/le_link.h"
+#include "l2cap/classic/internal/link.h"
#include "l2cap/internal/scheduler_mock.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace classic {
namespace internal {
namespace testing {
using hci::testing::MockAclConnection;
-class MockLeLink : public LeLink {
+class MockLink : public Link {
public:
- explicit MockLeLink(os::Handler* handler, ParameterProvider* parameter_provider)
- : LeLink(handler, std::make_unique<MockAclConnection>(), std::make_unique<MockScheduler>(), parameter_provider){};
+ explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider)
+ : Link(handler, std::make_unique<MockAclConnection>(),
+ std::make_unique<l2cap::internal::testing::MockScheduler>(), parameter_provider){};
MOCK_METHOD(hci::Address, GetDevice, (), (override));
MOCK_METHOD(void, OnAclDisconnected, (hci::ErrorCode status), (override));
MOCK_METHOD(void, Disconnect, (), (override));
- MOCK_METHOD(std::shared_ptr<LeFixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
+ MOCK_METHOD(std::shared_ptr<FixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
(override));
MOCK_METHOD(bool, IsFixedChannelAllocated, (Cid cid), (override));
MOCK_METHOD(void, RefreshRefCount, (), (override));
} // namespace testing
} // namespace internal
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2019 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.
+ */
+#define LOG_TAG "l2cap2"
+
+#include <memory>
+
+#include "common/bidi_queue.h"
+#include "hci/acl_manager.h"
+#include "hci/address.h"
+#include "hci/hci_layer.h"
+#include "hci/hci_packets.h"
+#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/classic/internal/link_manager.h"
+#include "l2cap/internal/parameter_provider.h"
+#include "module.h"
+#include "os/handler.h"
+#include "os/log.h"
+
+#include "l2cap/classic/l2cap_classic_module.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace classic {
+
+const ModuleFactory L2capClassicModule::Factory = ModuleFactory([]() { return new L2capClassicModule(); });
+
+struct L2capClassicModule::impl {
+ impl(os::Handler* l2cap_handler, hci::AclManager* acl_manager)
+ : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager) {}
+ os::Handler* l2cap_handler_;
+ hci::AclManager* acl_manager_;
+ l2cap::internal::ParameterProvider parameter_provider_;
+ internal::FixedChannelServiceManagerImpl fixed_channel_service_manager_impl_{l2cap_handler_};
+ internal::LinkManager link_manager_{l2cap_handler_, acl_manager_, &fixed_channel_service_manager_impl_,
+ ¶meter_provider_};
+};
+
+void L2capClassicModule::ListDependencies(ModuleList* list) {
+ list->add<hci::AclManager>();
+}
+
+void L2capClassicModule::Start() {
+ pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<hci::AclManager>());
+}
+
+void L2capClassicModule::Stop() {
+ pimpl_.reset();
+}
+
+std::unique_ptr<FixedChannelManager> L2capClassicModule::GetFixedChannelManager() {
+ return std::unique_ptr<FixedChannelManager>(new FixedChannelManager(&pimpl_->fixed_channel_service_manager_impl_,
+ &pimpl_->link_manager_, pimpl_->l2cap_handler_));
+}
+
+} // namespace classic
+} // namespace l2cap
+} // namespace bluetooth
\ No newline at end of file
#include <memory>
-#include "l2cap/classic_fixed_channel_manager.h"
-#include "l2cap/le_fixed_channel_manager.h"
+#include "l2cap/classic/fixed_channel_manager.h"
#include "module.h"
namespace bluetooth {
namespace l2cap {
+namespace classic {
-class L2capLayer : public bluetooth::Module {
+class L2capClassicModule : public bluetooth::Module {
public:
- L2capLayer() = default;
- ~L2capLayer() = default;
+ L2capClassicModule() = default;
+ ~L2capClassicModule() = default;
/**
* Get the api to the classic fixed channel l2cap module
*/
- std::unique_ptr<ClassicFixedChannelManager> GetClassicFixedChannelManager();
-
- /**
- * Get the api to the LE fixed channel l2cap module
- */
- std::unique_ptr<LeFixedChannelManager> GetLeFixedChannelManager();
+ std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
static const ModuleFactory Factory;
private:
struct impl;
std::unique_ptr<impl> pimpl_;
- DISALLOW_COPY_AND_ASSIGN(L2capLayer);
+ DISALLOW_COPY_AND_ASSIGN(L2capClassicModule);
};
+} // namespace classic
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2019 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.
- */
-
-#include "l2cap/internal/classic_dynamic_channel_service_manager_impl.h"
-
-#include "common/bind.h"
-#include "l2cap/internal/classic_dynamic_channel_service_impl.h"
-#include "l2cap/psm.h"
-#include "os/log.h"
-
-namespace bluetooth {
-namespace l2cap {
-namespace internal {
-
-void ClassicDynamicChannelServiceManagerImpl::Register(
- Psm psm, ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration) {
- if (!IsPsmValid(psm)) {
- std::unique_ptr<ClassicDynamicChannelService> invalid_service(new ClassicDynamicChannelService());
- pending_registration.user_handler_->Post(common::BindOnce(
- std::move(pending_registration.on_registration_complete_callback_),
- ClassicDynamicChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
- } else if (IsServiceRegistered(psm)) {
- std::unique_ptr<ClassicDynamicChannelService> invalid_service(new ClassicDynamicChannelService());
- pending_registration.user_handler_->Post(common::BindOnce(
- std::move(pending_registration.on_registration_complete_callback_),
- ClassicDynamicChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
- } else {
- service_map_.try_emplace(
- psm, ClassicDynamicChannelServiceImpl(pending_registration.user_handler_,
- std::move(pending_registration.on_connection_open_callback_)));
- std::unique_ptr<ClassicDynamicChannelService> user_service(
- new ClassicDynamicChannelService(psm, this, l2cap_layer_handler_));
- pending_registration.user_handler_->Post(
- common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
- ClassicDynamicChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
- }
-}
-
-void ClassicDynamicChannelServiceManagerImpl::Unregister(Psm psm,
- ClassicDynamicChannelService::OnUnregisteredCallback callback,
- os::Handler* handler) {
- if (IsServiceRegistered(psm)) {
- service_map_.erase(psm);
- handler->Post(std::move(callback));
- } else {
- LOG_ERROR("service not registered psm:%d", psm);
- }
-}
-
-bool ClassicDynamicChannelServiceManagerImpl::IsServiceRegistered(Psm psm) const {
- return service_map_.find(psm) != service_map_.end();
-}
-
-ClassicDynamicChannelServiceImpl* ClassicDynamicChannelServiceManagerImpl::GetService(Psm psm) {
- ASSERT(IsServiceRegistered(psm));
- return &service_map_.find(psm)->second;
-}
-
-std::vector<std::pair<Psm, ClassicDynamicChannelServiceImpl*>>
-ClassicDynamicChannelServiceManagerImpl::GetRegisteredServices() {
- std::vector<std::pair<Psm, ClassicDynamicChannelServiceImpl*>> results;
- for (auto& elem : service_map_) {
- results.emplace_back(elem.first, &elem.second);
- }
- return results;
-}
-
-} // namespace internal
-} // namespace l2cap
-} // namespace bluetooth
+++ /dev/null
-/*
- * Copyright 2019 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.
- */
-
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-
-#include "common/bind.h"
-#include "l2cap/cid.h"
-#include "l2cap/internal/classic_fixed_channel_service_impl.h"
-#include "os/log.h"
-
-namespace bluetooth {
-namespace l2cap {
-namespace internal {
-
-void ClassicFixedChannelServiceManagerImpl::Register(
- Cid cid, ClassicFixedChannelServiceImpl::PendingRegistration pending_registration) {
- if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kClassicSignallingCid) {
- std::unique_ptr<ClassicFixedChannelService> invalid_service(new ClassicFixedChannelService());
- pending_registration.user_handler_->Post(common::BindOnce(
- std::move(pending_registration.on_registration_complete_callback_),
- ClassicFixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
- } else if (IsServiceRegistered(cid)) {
- std::unique_ptr<ClassicFixedChannelService> invalid_service(new ClassicFixedChannelService());
- pending_registration.user_handler_->Post(common::BindOnce(
- std::move(pending_registration.on_registration_complete_callback_),
- ClassicFixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
- } else {
- service_map_.try_emplace(
- cid, ClassicFixedChannelServiceImpl(pending_registration.user_handler_,
- std::move(pending_registration.on_connection_open_callback_)));
- std::unique_ptr<ClassicFixedChannelService> user_service(
- new ClassicFixedChannelService(cid, this, l2cap_layer_handler_));
- pending_registration.user_handler_->Post(
- common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
- ClassicFixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
- }
-}
-
-void ClassicFixedChannelServiceManagerImpl::Unregister(Cid cid,
- ClassicFixedChannelService::OnUnregisteredCallback callback,
- os::Handler* handler) {
- if (IsServiceRegistered(cid)) {
- service_map_.erase(cid);
- handler->Post(std::move(callback));
- } else {
- LOG_ERROR("service not registered cid:%d", cid);
- }
-}
-
-bool ClassicFixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
- return service_map_.find(cid) != service_map_.end();
-}
-
-ClassicFixedChannelServiceImpl* ClassicFixedChannelServiceManagerImpl::GetService(Cid cid) {
- ASSERT(IsServiceRegistered(cid));
- return &service_map_.find(cid)->second;
-}
-
-std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>>
-ClassicFixedChannelServiceManagerImpl::GetRegisteredServices() {
- std::vector<std::pair<Cid, ClassicFixedChannelServiceImpl*>> results;
- for (auto& elem : service_map_) {
- results.emplace_back(elem.first, &elem.second);
- }
- return results;
-}
-
-} // namespace internal
-} // namespace l2cap
-} // namespace bluetooth
*/
#include "l2cap/internal/fixed_channel_allocator.h"
-#include "l2cap/internal/classic_fixed_channel_impl_mock.h"
-#include "l2cap/internal/classic_link_mock.h"
+#include "l2cap/classic/internal/fixed_channel_impl_mock.h"
+#include "l2cap/classic/internal/link_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
#include <gmock/gmock.h>
namespace l2cap {
namespace internal {
-using testing::MockClassicFixedChannelImpl;
-using testing::MockClassicLink;
+using l2cap::classic::internal::testing::MockFixedChannelImpl;
+using l2cap::classic::internal::testing::MockLink;
using testing::MockParameterProvider;
using ::testing::Return;
thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
handler_ = new os::Handler(thread_);
mock_parameter_provider_ = new MockParameterProvider();
- mock_classic_link_ = new MockClassicLink(handler_, mock_parameter_provider_);
+ mock_classic_link_ = new MockLink(handler_, mock_parameter_provider_);
EXPECT_CALL(*mock_classic_link_, GetDevice()).WillRepeatedly(Return(device));
// Use classic as a place holder
- channel_allocator_ = std::make_unique<FixedChannelAllocator<MockClassicFixedChannelImpl, MockClassicLink>>(
- mock_classic_link_, handler_);
+ channel_allocator_ =
+ std::make_unique<FixedChannelAllocator<MockFixedChannelImpl, MockLink>>(mock_classic_link_, handler_);
}
void TearDown() override {
os::Thread* thread_{nullptr};
os::Handler* handler_{nullptr};
MockParameterProvider* mock_parameter_provider_{nullptr};
- MockClassicLink* mock_classic_link_{nullptr};
- std::unique_ptr<FixedChannelAllocator<MockClassicFixedChannelImpl, MockClassicLink>> channel_allocator_;
+ MockLink* mock_classic_link_{nullptr};
+ std::unique_ptr<FixedChannelAllocator<MockFixedChannelImpl, MockLink>> channel_allocator_;
};
TEST_F(L2capFixedChannelAllocatorTest, precondition) {
+++ /dev/null
-/*
- * Copyright 2019 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.
- */
-#define LOG_TAG "l2cap2"
-
-#include <memory>
-
-#include "common/bidi_queue.h"
-#include "hci/acl_manager.h"
-#include "hci/address.h"
-#include "hci/hci_layer.h"
-#include "hci/hci_packets.h"
-#include "l2cap/internal/classic_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/classic_link_manager.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/le_link_manager.h"
-#include "l2cap/internal/parameter_provider.h"
-#include "module.h"
-#include "os/handler.h"
-#include "os/log.h"
-
-#include "l2cap/l2cap_layer.h"
-
-namespace bluetooth {
-namespace l2cap {
-
-const ModuleFactory L2capLayer::Factory = ModuleFactory([]() { return new L2capLayer(); });
-
-struct L2capLayer::impl {
- impl(os::Handler* l2cap_handler, hci::AclManager* acl_manager)
- : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager) {}
- os::Handler* l2cap_handler_;
- hci::AclManager* acl_manager_;
- internal::ParameterProvider parameter_provider_;
- internal::ClassicFixedChannelServiceManagerImpl classic_fixed_channel_service_manager_impl_{l2cap_handler_};
- internal::ClassicLinkManager classic_link_manager_{
- l2cap_handler_, acl_manager_, &classic_fixed_channel_service_manager_impl_, ¶meter_provider_};
- internal::LeFixedChannelServiceManagerImpl le_fixed_channel_service_manager_impl_{l2cap_handler_};
- internal::LeLinkManager le_link_manager_{l2cap_handler_, acl_manager_, &le_fixed_channel_service_manager_impl_,
- ¶meter_provider_};
-};
-
-void L2capLayer::ListDependencies(ModuleList* list) {
- list->add<hci::AclManager>();
-}
-
-void L2capLayer::Start() {
- pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<hci::AclManager>());
-}
-
-void L2capLayer::Stop() {
- pimpl_.reset();
-}
-
-std::unique_ptr<ClassicFixedChannelManager> L2capLayer::GetClassicFixedChannelManager() {
- return std::unique_ptr<ClassicFixedChannelManager>(new ClassicFixedChannelManager(
- &pimpl_->classic_fixed_channel_service_manager_impl_, &pimpl_->classic_link_manager_, pimpl_->l2cap_handler_));
-}
-
-std::unique_ptr<LeFixedChannelManager> L2capLayer::GetLeFixedChannelManager() {
- return std::unique_ptr<LeFixedChannelManager>(new LeFixedChannelManager(
- &pimpl_->le_fixed_channel_service_manager_impl_, &pimpl_->le_link_manager_, pimpl_->l2cap_handler_));
-}
-
-} // namespace l2cap
-} // namespace bluetooth
\ No newline at end of file
* limitations under the License.
*/
-#include "l2cap/classic_dynamic_channel.h"
+#include "l2cap/le/fixed_channel.h"
#include "common/bind.h"
-#include "l2cap/internal/classic_dynamic_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
-hci::Address ClassicDynamicChannel::GetDevice() const {
+hci::Address FixedChannel::GetDevice() const {
return impl_->GetDevice();
}
-void ClassicDynamicChannel::RegisterOnCloseCallback(os::Handler* user_handler,
- ClassicDynamicChannel::OnCloseCallback on_close_callback) {
- l2cap_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelImpl::RegisterOnCloseCallback, impl_,
- user_handler, std::move(on_close_callback)));
+void FixedChannel::RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback) {
+ l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::RegisterOnCloseCallback, impl_, user_handler,
+ std::move(on_close_callback)));
}
-void ClassicDynamicChannel::Close() {
- l2cap_handler_->Post(common::BindOnce(&internal::ClassicDynamicChannelImpl::Close, impl_));
+void FixedChannel::Acquire() {
+ l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Acquire, impl_));
+}
+
+void FixedChannel::Release() {
+ l2cap_handler_->Post(common::BindOnce(&internal::FixedChannelImpl::Release, impl_));
}
common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>*
-ClassicDynamicChannel::GetQueueUpEnd() const {
+FixedChannel::GetQueueUpEnd() const {
return impl_->GetQueueUpEnd();
}
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class LeFixedChannelImpl;
+class FixedChannelImpl;
} // namespace internal
/**
* Otherwise, {@link FixedChannel#Release()} will be called automatically.
*
*/
-class LeFixedChannel {
+class FixedChannel {
public:
- // Should only be constructed by modules that have access to LeLinkManager
- LeFixedChannel(std::shared_ptr<internal::LeFixedChannelImpl> impl, os::Handler* l2cap_handler)
+ // Should only be constructed by modules that have access to LinkManager
+ FixedChannel(std::shared_ptr<internal::FixedChannelImpl> impl, os::Handler* l2cap_handler)
: impl_(std::move(impl)), l2cap_handler_(l2cap_handler) {
ASSERT(impl_ != nullptr);
ASSERT(l2cap_handler_ != nullptr);
/**
* Indicate that this Fixed Channel is no longer being used. ACL connection will be disconnected after
- * kLeLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is using this
+ * kLinkIdleDisconnectTimeout if no other DynamicChannel is connected or no other Fixed Channel is using this
* ACL connection. However a module can still receive data on this channel as long as it remains open.
*/
void Release();
common::BidiQueueEnd<packet::BasePacketBuilder, packet::PacketView<packet::kLittleEndian>>* GetQueueUpEnd() const;
private:
- std::shared_ptr<internal::LeFixedChannelImpl> impl_;
+ std::shared_ptr<internal::FixedChannelImpl> impl_;
os::Handler* l2cap_handler_;
};
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/le_fixed_channel_manager.h"
-#include "l2cap/internal/le_fixed_channel_service_impl.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/le_link_manager.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/internal/fixed_channel_service_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/link_manager.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
-bool LeFixedChannelManager::ConnectServices(hci::Address device, hci::AddressType address_type,
- OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
- internal::LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+bool FixedChannelManager::ConnectServices(hci::Address device, hci::AddressType address_type,
+ OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
+ internal::LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.on_fail_callback_ = std::move(on_fail_callback), .handler_ = handler};
- l2cap_layer_handler_->Post(common::BindOnce(&internal::LeLinkManager::ConnectFixedChannelServices,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::LinkManager::ConnectFixedChannelServices,
common::Unretained(link_manager_), device, address_type,
std::move(pending_fixed_channel_connection)));
return true;
}
-bool LeFixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
- OnRegistrationCompleteCallback on_registration_complete,
- OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
- internal::LeFixedChannelServiceImpl::PendingRegistration pending_registration{
+bool FixedChannelManager::RegisterService(Cid cid, const SecurityPolicy& security_policy,
+ OnRegistrationCompleteCallback on_registration_complete,
+ OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
+ internal::FixedChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = handler,
.on_registration_complete_callback_ = std::move(on_registration_complete),
.on_connection_open_callback_ = std::move(on_connection_open)};
- l2cap_layer_handler_->Post(common::BindOnce(&internal::LeFixedChannelServiceManagerImpl::Register,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Register,
common::Unretained(service_manager_), cid,
std::move(pending_registration)));
return true;
}
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager.h"
#include "hci/address.h"
#include "l2cap/cid.h"
-#include "l2cap/le_fixed_channel.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "l2cap/le/fixed_channel.h"
+#include "l2cap/le/fixed_channel_service.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
-class L2capLayer;
+class L2capLeModule;
namespace internal {
-class LeLinkManager;
-class LeFixedChannelServiceManagerImpl;
+class LinkManager;
+class FixedChannelServiceManagerImpl;
} // namespace internal
-class LeFixedChannelManager {
+class FixedChannelManager {
public:
enum class ConnectionResultCode {
SUCCESS = 0,
using OnConnectionFailureCallback = common::OnceCallback<void(ConnectionResult result)>;
/**
- * OnConnectionOpenCallback(LeFixedChannel channel);
+ * OnConnectionOpenCallback(FixedChannel channel);
*/
- using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<LeFixedChannel>)>;
+ using OnConnectionOpenCallback = common::Callback<void(std::unique_ptr<FixedChannel>)>;
enum class RegistrationResult {
SUCCESS = 0,
};
/**
- * OnRegistrationFailureCallback(RegistrationResult result, LeFixedChannelService service);
+ * OnRegistrationFailureCallback(RegistrationResult result, FixedChannelService service);
*/
using OnRegistrationCompleteCallback =
- common::OnceCallback<void(RegistrationResult, std::unique_ptr<LeFixedChannelService>)>;
+ common::OnceCallback<void(RegistrationResult, std::unique_ptr<FixedChannelService>)>;
/**
* Connect to ALL fixed channels on a remote device
* - When true is returned, method caller should wait for on_fail_callback or on_open_callback registered through
* RegisterService() API.
* - If an ACL connection does not exist, this method will create an ACL connection. As a result, on_open_callback
- * supplied through RegisterService() will be triggered to provide the actual LeFixedChannel objects
+ * supplied through RegisterService() will be triggered to provide the actual FixedChannel objects
* - If HCI connection failed, on_fail_callback will be triggered with FAIL_HCI_ERROR
* - If fixed channel on a remote device is already reported as connected via on_open_callback and has been acquired
- * via LeFixedChannel#Acquire() API, it won't be reported again
+ * via FixedChannel#Acquire() API, it won't be reported again
* - If no service is registered, on_fail_callback will be triggered with FAIL_NO_SERVICE_REGISTERED
* - If there is an ACL connection and channels for each service is allocated, on_fail_callback will be triggered with
* FAIL_ALL_SERVICES_HAVE_CHANNEL
* This call will initiate an effort to connect all fixed channel services on a remote device.
* Due to the connectionless nature of fixed channels, all fixed channels will be connected together.
* If a fixed channel service does not need a particular fixed channel. It should release the received
- * channel immediately after receiving on_open_callback via LeFixedChannel#Release()
+ * channel immediately after receiving on_open_callback via FixedChannel#Release()
*
* A module calling ConnectServices() must have called RegisterService() before.
* The callback will come back from on_open_callback in the service that is registered
* - This method is asynchronous.
* - When false is returned, the registration fails immediately.
* - When true is returned, method caller should wait for on_service_registered callback that contains a
- * LeFixedChannelService object. The registered service can be managed from that object.
+ * FixedChannelService object. The registered service can be managed from that object.
* - If a CID is already registered or some other error happens, on_registration_complete will be triggered with a
* non-SUCCESS value
- * - After a service is registered, any classic ACL connection will create a LeFixedChannel object that is
+ * - After a service is registered, any classic ACL connection will create a FixedChannel object that is
* delivered through on_open_callback
* - on_open_callback, will only be triggered after on_service_registered callback
*
- * @param cid: Le cid used to receive incoming connections
+ * @param cid: cid used to receive incoming connections
* @param security_policy: The security policy used for the connection.
* @param on_registration_complete: A callback to indicate the service setup has completed. If the return status is
* not SUCCESS, it means service is not registered due to reasons like CID already take
OnRegistrationCompleteCallback on_registration_complete,
OnConnectionOpenCallback on_connection_open, os::Handler* handler);
- friend class L2capLayer;
+ friend class L2capLeModule;
private:
// The constructor is not to be used by user code
- LeFixedChannelManager(internal::LeFixedChannelServiceManagerImpl* service_manager,
- internal::LeLinkManager* link_manager, os::Handler* l2cap_layer_handler)
+ FixedChannelManager(internal::FixedChannelServiceManagerImpl* service_manager, internal::LinkManager* link_manager,
+ os::Handler* l2cap_layer_handler)
: service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {}
- internal::LeFixedChannelServiceManagerImpl* service_manager_ = nullptr;
- internal::LeLinkManager* link_manager_ = nullptr;
+ internal::FixedChannelServiceManagerImpl* service_manager_ = nullptr;
+ internal::LinkManager* link_manager_ = nullptr;
os::Handler* l2cap_layer_handler_ = nullptr;
- DISALLOW_COPY_AND_ASSIGN(LeFixedChannelManager);
+ DISALLOW_COPY_AND_ASSIGN(FixedChannelManager);
};
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/le_fixed_channel_service.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/fixed_channel_service.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
-void LeFixedChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
+void FixedChannelService::Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler) {
ASSERT_LOG(manager_ != nullptr, "this service is invalid");
- l2cap_layer_handler_->Post(common::BindOnce(&internal::LeFixedChannelServiceManagerImpl::Unregister,
+ l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Unregister,
common::Unretained(manager_), cid_, std::move(on_unregistered),
on_unregistered_handler));
}
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class LeFixedChannelServiceManagerImpl;
+class FixedChannelServiceManagerImpl;
}
-class LeFixedChannelService {
+class FixedChannelService {
public:
- LeFixedChannelService() = default;
+ FixedChannelService() = default;
using OnUnregisteredCallback = common::OnceCallback<void()>;
*/
void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
- friend internal::LeFixedChannelServiceManagerImpl;
+ friend internal::FixedChannelServiceManagerImpl;
private:
- LeFixedChannelService(Cid cid, internal::LeFixedChannelServiceManagerImpl* manager, os::Handler* handler)
+ FixedChannelService(Cid cid, internal::FixedChannelServiceManagerImpl* manager, os::Handler* handler)
: cid_(cid), manager_(manager), l2cap_layer_handler_(handler) {}
Cid cid_ = kInvalidCid;
- internal::LeFixedChannelServiceManagerImpl* manager_ = nullptr;
+ internal::FixedChannelServiceManagerImpl* manager_ = nullptr;
os::Handler* l2cap_layer_handler_;
- DISALLOW_COPY_AND_ASSIGN(LeFixedChannelService);
+ DISALLOW_COPY_AND_ASSIGN(FixedChannelService);
};
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include <unordered_map>
#include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_impl.h"
-#include "l2cap/internal/le_link.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
+#include "l2cap/le/internal/link.h"
#include "l2cap/security_policy.h"
#include "os/handler.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-LeFixedChannelImpl::LeFixedChannelImpl(Cid cid, LeLink* link, os::Handler* l2cap_handler)
+FixedChannelImpl::FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler)
: cid_(cid), device_(link->GetDevice()), link_(link), l2cap_handler_(l2cap_handler) {
ASSERT_LOG(cid_ >= kFirstFixedChannel && cid_ <= kLastFixedChannel, "Invalid cid: %d", cid_);
ASSERT(!device_.IsEmpty());
ASSERT(l2cap_handler_ != nullptr);
}
-void LeFixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
- LeFixedChannel::OnCloseCallback on_close_callback) {
+void FixedChannelImpl::RegisterOnCloseCallback(os::Handler* user_handler,
+ FixedChannel::OnCloseCallback on_close_callback) {
ASSERT_LOG(user_handler_ == nullptr, "OnCloseCallback can only be registered once");
// If channel is already closed, call the callback immediately without saving it
if (closed_) {
on_close_callback_ = std::move(on_close_callback);
}
-void LeFixedChannelImpl::OnClosed(hci::ErrorCode status) {
+void FixedChannelImpl::OnClosed(hci::ErrorCode status) {
ASSERT_LOG(!closed_, "Device %s Cid 0x%x closed twice, old status 0x%x, new status 0x%x", device_.ToString().c_str(),
cid_, static_cast<int>(close_reason_), static_cast<int>(status));
closed_ = true;
on_close_callback_.Reset();
}
-void LeFixedChannelImpl::Acquire() {
+void FixedChannelImpl::Acquire() {
ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
if (closed_) {
LOG_WARN("%s is already closed", ToString().c_str());
link_->RefreshRefCount();
}
-void LeFixedChannelImpl::Release() {
+void FixedChannelImpl::Release() {
ASSERT_LOG(user_handler_ != nullptr, "Must register OnCloseCallback before calling any methods");
if (closed_) {
LOG_WARN("%s is already closed", ToString().c_str());
}
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include "common/bidi_queue.h"
#include "l2cap/cid.h"
-#include "l2cap/le_fixed_channel.h"
+#include "l2cap/le/fixed_channel.h"
#include "os/handler.h"
#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class LeLink;
+class Link;
-class LeFixedChannelImpl {
+class FixedChannelImpl {
public:
- LeFixedChannelImpl(Cid cid, LeLink* link, os::Handler* l2cap_handler);
+ FixedChannelImpl(Cid cid, Link* link, os::Handler* l2cap_handler);
- virtual ~LeFixedChannelImpl() = default;
+ virtual ~FixedChannelImpl() = default;
hci::Address GetDevice() const {
return device_;
}
- virtual void RegisterOnCloseCallback(os::Handler* user_handler, LeFixedChannel::OnCloseCallback on_close_callback);
+ virtual void RegisterOnCloseCallback(os::Handler* user_handler, FixedChannel::OnCloseCallback on_close_callback);
virtual void Acquire();
// For logging purpose only
const hci::Address device_;
// Needed to handle Acquire() and Release()
- LeLink* link_;
+ Link* link_;
os::Handler* l2cap_handler_;
// User supported states
os::Handler* user_handler_ = nullptr;
- LeFixedChannel::OnCloseCallback on_close_callback_{};
+ FixedChannel::OnCloseCallback on_close_callback_{};
// Internal states
bool acquired_ = false;
common::BidiQueue<packet::PacketView<packet::kLittleEndian>, packet::BasePacketBuilder> channel_queue_{
kChannelQueueSize};
- DISALLOW_COPY_AND_ASSIGN(LeFixedChannelImpl);
+ DISALLOW_COPY_AND_ASSIGN(FixedChannelImpl);
};
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
*/
#pragma once
-#include "l2cap/internal/le_fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
namespace testing {
-class MockLeFixedChannelImpl : public LeFixedChannelImpl {
+class MockFixedChannelImpl : public FixedChannelImpl {
public:
MOCK_METHOD(void, RegisterOnCloseCallback,
- (os::Handler * user_handler, LeFixedChannel::OnCloseCallback on_close_callback), (override));
+ (os::Handler * user_handler, FixedChannel::OnCloseCallback on_close_callback), (override));
MOCK_METHOD(void, Acquire, (), (override));
MOCK_METHOD(void, Release, (), (override));
MOCK_METHOD(bool, IsAcquired, (), (override, const));
} // namespace testing
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "l2cap/internal/le_fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
#include "common/testing/bind_test_util.h"
#include "l2cap/cid.h"
-#include "l2cap/internal/le_link_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
+#include "l2cap/le/internal/link_mock.h"
#include "os/handler.h"
#include <gmock/gmock.h>
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-using testing::MockLeLink;
-using testing::MockParameterProvider;
+using l2cap::internal::testing::MockParameterProvider;
+using testing::MockLink;
using ::testing::Return;
class L2capLeFixedChannelImplTest : public ::testing::Test {
TEST_F(L2capLeFixedChannelImplTest, get_device) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
EXPECT_EQ(device, fixed_channel_impl.GetDevice());
}
TEST_F(L2capLeFixedChannelImplTest, close_triggers_callback) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capLeFixedChannelImplTest, register_callback_after_close_should_call_immediately) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
// Channel closure should do nothing
fixed_channel_impl.OnClosed(hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION);
TEST_F(L2capLeFixedChannelImplTest, close_twice_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capLeFixedChannelImplTest, multiple_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capLeFixedChannelImplTest, call_acquire_before_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
EXPECT_DEATH(fixed_channel_impl.Acquire(), ".*Acquire.*");
}
TEST_F(L2capLeFixedChannelImplTest, call_release_before_registeration_should_fail) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
EXPECT_DEATH(fixed_channel_impl.Release(), ".*Release.*");
}
TEST_F(L2capLeFixedChannelImplTest, test_acquire_release_channel) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
TEST_F(L2capLeFixedChannelImplTest, test_acquire_after_close) {
MockParameterProvider mock_parameter_provider;
- MockLeLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
+ MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider);
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device));
- LeFixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
+ FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_);
// Register on close callback
auto user_handler = std::make_unique<os::Handler>(thread_);
}
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#pragma once
-#include "common/bind.h"
-
-#include "l2cap/classic_dynamic_channel.h"
-#include "l2cap/classic_dynamic_channel_manager.h"
-#include "l2cap/classic_dynamic_channel_service.h"
+#include "l2cap/le/fixed_channel.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_service.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class ClassicDynamicChannelServiceImpl {
+
+class FixedChannelServiceImpl {
public:
- virtual ~ClassicDynamicChannelServiceImpl() = default;
+ virtual ~FixedChannelServiceImpl() = default;
struct PendingRegistration {
os::Handler* user_handler_ = nullptr;
- ClassicDynamicChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
- ClassicDynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+ FixedChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_;
+ FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
};
- virtual void NotifyChannelCreation(std::unique_ptr<ClassicDynamicChannel> channel) {
+ virtual void NotifyChannelCreation(std::unique_ptr<FixedChannel> channel) {
user_handler_->Post(common::BindOnce(on_connection_open_callback_, std::move(channel)));
}
- friend class ClassicDynamicChannelServiceManagerImpl;
+ friend class FixedChannelServiceManagerImpl;
protected:
// protected access for mocking
- ClassicDynamicChannelServiceImpl(os::Handler* user_handler,
- ClassicDynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback)
+ FixedChannelServiceImpl(os::Handler* user_handler,
+ FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback)
: user_handler_(user_handler), on_connection_open_callback_(std::move(on_connection_open_callback)) {}
private:
os::Handler* user_handler_ = nullptr;
- ClassicDynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
+ FixedChannelManager::OnConnectionOpenCallback on_connection_open_callback_;
};
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
*/
#pragma once
-#include "l2cap/internal/le_fixed_channel_impl.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
namespace testing {
-class MockLeFixedChannelServiceImpl : public LeFixedChannelServiceImpl {
+class MockFixedChannelServiceImpl : public FixedChannelServiceImpl {
public:
- MockLeFixedChannelServiceImpl()
- : LeFixedChannelServiceImpl(nullptr, LeFixedChannelManager::OnConnectionOpenCallback()) {}
- MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<LeFixedChannel> channel), (override));
+ MockFixedChannelServiceImpl() : FixedChannelServiceImpl(nullptr, FixedChannelManager::OnConnectionOpenCallback()) {}
+ MOCK_METHOD(void, NotifyChannelCreation, (std::unique_ptr<FixedChannel> channel), (override));
};
} // namespace testing
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2019 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.
+ */
+
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+
+#include "common/bind.h"
+#include "l2cap/cid.h"
+#include "l2cap/le/internal/fixed_channel_service_impl.h"
+#include "os/log.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace le {
+namespace internal {
+
+void FixedChannelServiceManagerImpl::Register(Cid cid,
+ FixedChannelServiceImpl::PendingRegistration pending_registration) {
+ if (cid < kFirstFixedChannel || cid > kLastFixedChannel || cid == kLeSignallingCid) {
+ std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+ pending_registration.user_handler_->Post(
+ common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+ FixedChannelManager::RegistrationResult::FAIL_INVALID_SERVICE, std::move(invalid_service)));
+ } else if (IsServiceRegistered(cid)) {
+ std::unique_ptr<FixedChannelService> invalid_service(new FixedChannelService());
+ pending_registration.user_handler_->Post(
+ common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+ FixedChannelManager::RegistrationResult::FAIL_DUPLICATE_SERVICE, std::move(invalid_service)));
+ } else {
+ service_map_.try_emplace(cid,
+ FixedChannelServiceImpl(pending_registration.user_handler_,
+ std::move(pending_registration.on_connection_open_callback_)));
+ std::unique_ptr<FixedChannelService> user_service(new FixedChannelService(cid, this, l2cap_layer_handler_));
+ pending_registration.user_handler_->Post(
+ common::BindOnce(std::move(pending_registration.on_registration_complete_callback_),
+ FixedChannelManager::RegistrationResult::SUCCESS, std::move(user_service)));
+ }
+}
+
+void FixedChannelServiceManagerImpl::Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback,
+ os::Handler* handler) {
+ if (IsServiceRegistered(cid)) {
+ service_map_.erase(cid);
+ handler->Post(std::move(callback));
+ } else {
+ LOG_ERROR("service not registered cid:%d", cid);
+ }
+}
+
+bool FixedChannelServiceManagerImpl::IsServiceRegistered(Cid cid) const {
+ return service_map_.find(cid) != service_map_.end();
+}
+
+FixedChannelServiceImpl* FixedChannelServiceManagerImpl::GetService(Cid cid) {
+ ASSERT(IsServiceRegistered(cid));
+ return &service_map_.find(cid)->second;
+}
+
+std::vector<std::pair<Cid, FixedChannelServiceImpl*>> FixedChannelServiceManagerImpl::GetRegisteredServices() {
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
+ for (auto& elem : service_map_) {
+ results.emplace_back(elem.first, &elem.second);
+ }
+ return results;
+}
+
+} // namespace internal
+} // namespace le
+} // namespace l2cap
+} // namespace bluetooth
#include <unordered_map>
-#include "l2cap/classic_dynamic_channel_service.h"
-#include "l2cap/internal/classic_dynamic_channel_service_impl.h"
-#include "l2cap/psm.h"
+#include "l2cap/cid.h"
+#include "l2cap/le/fixed_channel_service.h"
+#include "l2cap/le/internal/fixed_channel_service_impl.h"
#include "os/handler.h"
-#include "os/log.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class ClassicDynamicChannelServiceManagerImpl {
+class FixedChannelServiceManagerImpl {
public:
- explicit ClassicDynamicChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
+ explicit FixedChannelServiceManagerImpl(os::Handler* l2cap_layer_handler)
: l2cap_layer_handler_(l2cap_layer_handler) {}
+ virtual ~FixedChannelServiceManagerImpl() = default;
- virtual ~ClassicDynamicChannelServiceManagerImpl() = default;
- //
// All APIs must be invoked in L2CAP layer handler
- //
- virtual void Register(Psm psm, ClassicDynamicChannelServiceImpl::PendingRegistration pending_registration);
- virtual void Unregister(Psm psm, ClassicDynamicChannelService::OnUnregisteredCallback callback, os::Handler* handler);
- virtual bool IsServiceRegistered(Psm psm) const;
- virtual ClassicDynamicChannelServiceImpl* GetService(Psm psm);
-
- virtual std::vector<std::pair<Psm, ClassicDynamicChannelServiceImpl*>> GetRegisteredServices();
- //
+
+ virtual void Register(Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration);
+ virtual void Unregister(Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler);
+ virtual bool IsServiceRegistered(Cid cid) const;
+ virtual FixedChannelServiceImpl* GetService(Cid cid);
+ virtual std::vector<std::pair<Cid, FixedChannelServiceImpl*>> GetRegisteredServices();
+
private:
os::Handler* l2cap_layer_handler_ = nullptr;
- std::unordered_map<Psm, ClassicDynamicChannelServiceImpl> service_map_;
+ std::unordered_map<Cid, FixedChannelServiceImpl> service_map_;
};
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
*/
#pragma once
-#include "l2cap/internal/le_fixed_channel_impl.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
namespace testing {
-class MockLeFixedChannelServiceManagerImpl : public LeFixedChannelServiceManagerImpl {
+class MockFixedChannelServiceManagerImpl : public FixedChannelServiceManagerImpl {
public:
- MockLeFixedChannelServiceManagerImpl() : LeFixedChannelServiceManagerImpl(nullptr) {}
- MOCK_METHOD(void, Register, (Cid cid, LeFixedChannelServiceImpl::PendingRegistration pending_registration),
- (override));
- MOCK_METHOD(void, Unregister, (Cid cid, LeFixedChannelService::OnUnregisteredCallback callback, os::Handler* handler),
+ MockFixedChannelServiceManagerImpl() : FixedChannelServiceManagerImpl(nullptr) {}
+ MOCK_METHOD(void, Register, (Cid cid, FixedChannelServiceImpl::PendingRegistration pending_registration), (override));
+ MOCK_METHOD(void, Unregister, (Cid cid, FixedChannelService::OnUnregisteredCallback callback, os::Handler* handler),
(override));
MOCK_METHOD(bool, IsServiceRegistered, (Cid cid), (const, override));
- MOCK_METHOD(LeFixedChannelServiceImpl*, GetService, (Cid cid), (override));
- MOCK_METHOD((std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
+ MOCK_METHOD(FixedChannelServiceImpl*, GetService, (Cid cid), (override));
+ MOCK_METHOD((std::vector<std::pair<Cid, FixedChannelServiceImpl*>>), GetRegisteredServices, (), (override));
};
} // namespace testing
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
* limitations under the License.
*/
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
#include <future>
#include "common/bind.h"
#include "l2cap/cid.h"
-#include "l2cap/le_fixed_channel_manager.h"
-#include "l2cap/le_fixed_channel_service.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_service.h"
#include "os/handler.h"
#include "os/thread.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class L2capServiceManagerTest : public ::testing::Test {
+class L2capLeServiceManagerTest : public ::testing::Test {
public:
- ~L2capServiceManagerTest() override = default;
+ ~L2capLeServiceManagerTest() override = default;
- void OnServiceRegistered(bool expect_success, LeFixedChannelManager::RegistrationResult result,
- std::unique_ptr<LeFixedChannelService> user_service) {
- EXPECT_EQ(result == LeFixedChannelManager::RegistrationResult::SUCCESS, expect_success);
+ void OnServiceRegistered(bool expect_success, FixedChannelManager::RegistrationResult result,
+ std::unique_ptr<FixedChannelService> user_service) {
+ EXPECT_EQ(result == FixedChannelManager::RegistrationResult::SUCCESS, expect_success);
service_registered_ = expect_success;
}
protected:
void SetUp() override {
- manager_ = new LeFixedChannelServiceManagerImpl{nullptr};
+ manager_ = new FixedChannelServiceManagerImpl{nullptr};
thread_ = new os::Thread("test_thread", os::Thread::Priority::NORMAL);
user_handler_ = new os::Handler(thread_);
}
future.wait_for(std::chrono::milliseconds(3));
}
- LeFixedChannelServiceManagerImpl* manager_ = nullptr;
+ FixedChannelServiceManagerImpl* manager_ = nullptr;
os::Thread* thread_ = nullptr;
os::Handler* user_handler_ = nullptr;
bool service_registered_ = false;
};
-TEST_F(L2capServiceManagerTest, register_and_unregister_le_fixed_channel) {
- LeFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capLeServiceManagerTest, register_and_unregister_le_fixed_channel) {
+ FixedChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = user_handler_,
.on_registration_complete_callback_ =
- common::BindOnce(&L2capServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
+ common::BindOnce(&L2capLeServiceManagerTest::OnServiceRegistered, common::Unretained(this), true)};
Cid cid = kSmpBrCid;
EXPECT_FALSE(manager_->IsServiceRegistered(cid));
manager_->Register(cid, std::move(pending_registration));
EXPECT_FALSE(manager_->IsServiceRegistered(cid));
}
-TEST_F(L2capServiceManagerTest, register_le_fixed_channel_bad_cid) {
- LeFixedChannelServiceImpl::PendingRegistration pending_registration{
+TEST_F(L2capLeServiceManagerTest, register_le_fixed_channel_bad_cid) {
+ FixedChannelServiceImpl::PendingRegistration pending_registration{
.user_handler_ = user_handler_,
.on_registration_complete_callback_ =
- common::BindOnce(&L2capServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
+ common::BindOnce(&L2capLeServiceManagerTest::OnServiceRegistered, common::Unretained(this), false)};
Cid cid = 0x1000;
EXPECT_FALSE(manager_->IsServiceRegistered(cid));
manager_->Register(cid, std::move(pending_registration));
}
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager.h"
#include "l2cap/internal/fixed_channel_allocator.h"
-#include "l2cap/internal/le_fixed_channel_impl.h"
#include "l2cap/internal/parameter_provider.h"
#include "l2cap/internal/scheduler.h"
+#include "l2cap/le/internal/fixed_channel_impl.h"
#include "os/alarm.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class LeLink {
+class Link {
public:
- LeLink(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
- std::unique_ptr<Scheduler> scheduler, ParameterProvider* parameter_provider)
+ Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
+ std::unique_ptr<l2cap::internal::Scheduler> scheduler, l2cap::internal::ParameterProvider* parameter_provider)
: l2cap_handler_(l2cap_handler), acl_connection_(std::move(acl_connection)), scheduler_(std::move(scheduler)),
parameter_provider_(parameter_provider) {
ASSERT(l2cap_handler_ != nullptr);
ASSERT(acl_connection_ != nullptr);
ASSERT(scheduler_ != nullptr);
ASSERT(parameter_provider_ != nullptr);
- acl_connection_->RegisterDisconnectCallback(common::BindOnce(&LeLink::OnAclDisconnected, common::Unretained(this)),
+ acl_connection_->RegisterDisconnectCallback(common::BindOnce(&Link::OnAclDisconnected, common::Unretained(this)),
l2cap_handler_);
- link_idle_disconnect_alarm_.Schedule(common::BindOnce(&LeLink::Disconnect, common::Unretained(this)),
+ link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
parameter_provider_->GetLeLinkIdleDisconnectTimeout());
}
- virtual ~LeLink() = default;
+ virtual ~Link() = default;
inline virtual hci::Address GetDevice() {
return acl_connection_->GetAddress();
acl_connection_->Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION);
}
- // LeFixedChannel methods
+ // FixedChannel methods
- virtual std::shared_ptr<LeFixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
+ virtual std::shared_ptr<FixedChannelImpl> AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
auto channel = fixed_channel_allocator_.AllocateChannel(cid, security_policy);
scheduler_->AttachChannel(cid, channel->GetQueueDownEnd());
return channel;
if (ref_count > 0) {
link_idle_disconnect_alarm_.Cancel();
} else {
- link_idle_disconnect_alarm_.Schedule(common::BindOnce(&LeLink::Disconnect, common::Unretained(this)),
+ link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
parameter_provider_->GetLeLinkIdleDisconnectTimeout());
}
}
private:
os::Handler* l2cap_handler_;
- FixedChannelAllocator<LeFixedChannelImpl, LeLink> fixed_channel_allocator_{this, l2cap_handler_};
+ l2cap::internal::FixedChannelAllocator<FixedChannelImpl, Link> fixed_channel_allocator_{this, l2cap_handler_};
std::unique_ptr<hci::AclConnection> acl_connection_;
- std::unique_ptr<Scheduler> scheduler_;
- ParameterProvider* parameter_provider_;
+ std::unique_ptr<l2cap::internal::Scheduler> scheduler_;
+ l2cap::internal::ParameterProvider* parameter_provider_;
os::Alarm link_idle_disconnect_alarm_{l2cap_handler_};
- DISALLOW_COPY_AND_ASSIGN(LeLink);
+ DISALLOW_COPY_AND_ASSIGN(Link);
};
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager.h"
#include "hci/address.h"
-#include "l2cap/internal/le_link.h"
#include "l2cap/internal/scheduler_fifo.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/le/internal/link.h"
#include "os/handler.h"
#include "os/log.h"
-#include "l2cap/internal/le_link_manager.h"
+#include "l2cap/le/internal/link_manager.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-void LeLinkManager::ConnectFixedChannelServices(hci::Address device, hci::AddressType address_type,
- PendingFixedChannelConnection pending_fixed_channel_connection) {
+void LinkManager::ConnectFixedChannelServices(hci::Address device, hci::AddressType address_type,
+ PendingFixedChannelConnection pending_fixed_channel_connection) {
// Check if there is any service registered
auto fixed_channel_services = service_manager_->GetRegisteredServices();
if (fixed_channel_services.empty()) {
// If so, return error
pending_fixed_channel_connection.handler_->Post(common::BindOnce(
std::move(pending_fixed_channel_connection.on_fail_callback_),
- LeFixedChannelManager::ConnectionResult{
- .connection_result_code = LeFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
+ FixedChannelManager::ConnectionResult{
+ .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED}));
return;
}
// Otherwise, check if device has an ACL connection
// Allocate channel for newly registered fixed channels
auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
fixed_channel_service.second->NotifyChannelCreation(
- std::make_unique<LeFixedChannel>(fixed_channel_impl, l2cap_handler_));
+ std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
num_new_channels++;
}
// Declare connection failure if no new channels are created
if (num_new_channels == 0) {
pending_fixed_channel_connection.handler_->Post(common::BindOnce(
std::move(pending_fixed_channel_connection.on_fail_callback_),
- LeFixedChannelManager::ConnectionResult{
- .connection_result_code = LeFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
+ FixedChannelManager::ConnectionResult{
+ .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL}));
}
// No need to create ACL connection, return without saving any pending connections
return;
acl_manager_->CreateLeConnection(device, address_type);
}
-LeLink* LeLinkManager::GetLink(const hci::Address device) {
+Link* LinkManager::GetLink(const hci::Address device) {
if (links_.find(device) == links_.end()) {
return nullptr;
}
return &links_.find(device)->second;
}
-void LeLinkManager::OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
+void LinkManager::OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) {
// Same link should not be connected twice
hci::Address device = acl_connection->GetAddress();
ASSERT_LOG(GetLink(device) == nullptr, "%s is connected twice without disconnection",
acl_connection->GetAddress().ToString().c_str());
auto* link_queue_up_end = acl_connection->GetAclQueueEnd();
links_.try_emplace(device, l2cap_handler_, std::move(acl_connection),
- std::make_unique<Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
+ std::make_unique<l2cap::internal::Fifo>(link_queue_up_end, l2cap_handler_), parameter_provider_);
auto* link = GetLink(device);
// Allocate and distribute channels for all registered fixed channel services
auto fixed_channel_services = service_manager_->GetRegisteredServices();
for (auto& fixed_channel_service : fixed_channel_services) {
auto fixed_channel_impl = link->AllocateFixedChannel(fixed_channel_service.first, SecurityPolicy());
fixed_channel_service.second->NotifyChannelCreation(
- std::make_unique<LeFixedChannel>(fixed_channel_impl, l2cap_handler_));
+ std::make_unique<FixedChannel>(fixed_channel_impl, l2cap_handler_));
}
// Remove device from pending links list, if any
auto pending_link = pending_links_.find(device);
pending_links_.erase(pending_link);
}
-void LeLinkManager::OnLeConnectFail(hci::Address device, hci::AddressType address_type, hci::ErrorCode reason) {
+void LinkManager::OnLeConnectFail(hci::Address device, hci::AddressType address_type, hci::ErrorCode reason) {
// Notify all pending links for this device
auto pending_link = pending_links_.find(device);
if (pending_link == pending_links_.end()) {
return;
}
for (auto& pending_fixed_channel_connection : pending_link->second.pending_fixed_channel_connections_) {
- pending_fixed_channel_connection.handler_->Post(
- common::BindOnce(std::move(pending_fixed_channel_connection.on_fail_callback_),
- LeFixedChannelManager::ConnectionResult{
- .connection_result_code = LeFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR,
- .hci_error = reason}));
+ pending_fixed_channel_connection.handler_->Post(common::BindOnce(
+ std::move(pending_fixed_channel_connection.on_fail_callback_),
+ FixedChannelManager::ConnectionResult{
+ .connection_result_code = FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR, .hci_error = reason}));
}
// Remove entry in pending link list
pending_links_.erase(pending_link);
}
-void LeLinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
+void LinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
auto* link = GetLink(device);
ASSERT_LOG(link != nullptr, "Device %s is disconnected with reason 0x%x, but not in local database",
device.ToString().c_str(), static_cast<uint8_t>(status));
}
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include "os/handler.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl.h"
-#include "l2cap/internal/le_link.h"
#include "l2cap/internal/parameter_provider.h"
#include "l2cap/internal/scheduler.h"
-#include "l2cap/le_fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/link.h"
#include "hci/acl_manager.h"
#include "hci/address.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
-class LeLinkManager : public hci::LeConnectionCallbacks {
+class LinkManager : public hci::LeConnectionCallbacks {
public:
- LeLinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager,
- LeFixedChannelServiceManagerImpl* service_manager, ParameterProvider* parameter_provider)
+ LinkManager(os::Handler* l2cap_handler, hci::AclManager* acl_manager, FixedChannelServiceManagerImpl* service_manager,
+ l2cap::internal::ParameterProvider* parameter_provider)
: l2cap_handler_(l2cap_handler), acl_manager_(acl_manager), service_manager_(service_manager),
parameter_provider_(parameter_provider) {
acl_manager_->RegisterLeCallbacks(this, l2cap_handler_);
struct PendingFixedChannelConnection {
os::Handler* handler_;
- LeFixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
+ FixedChannelManager::OnConnectionFailureCallback on_fail_callback_;
};
struct PendingLink {
// ACL methods
- LeLink* GetLink(hci::Address device);
+ Link* GetLink(hci::Address device);
void OnLeConnectSuccess(std::unique_ptr<hci::AclConnection> acl_connection) override;
void OnLeConnectFail(hci::Address device, hci::AddressType address_type, hci::ErrorCode reason) override;
void OnDisconnect(hci::Address device, hci::ErrorCode status);
- // LeFixedChannelManager methods
+ // FixedChannelManager methods
void ConnectFixedChannelServices(hci::Address device, hci::AddressType address_type,
PendingFixedChannelConnection pending_fixed_channel_connection);
// Dependencies
os::Handler* l2cap_handler_;
hci::AclManager* acl_manager_;
- LeFixedChannelServiceManagerImpl* service_manager_;
- ParameterProvider* parameter_provider_;
+ FixedChannelServiceManagerImpl* service_manager_;
+ l2cap::internal::ParameterProvider* parameter_provider_;
// Internal states
std::unordered_map<hci::Address, PendingLink> pending_links_;
- std::unordered_map<hci::Address, LeLink> links_;
- DISALLOW_COPY_AND_ASSIGN(LeLinkManager);
+ std::unordered_map<hci::Address, Link> links_;
+ DISALLOW_COPY_AND_ASSIGN(LinkManager);
};
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
* limitations under the License.
*/
-#include "l2cap/internal/le_link_manager.h"
+#include "l2cap/le/internal/link_manager.h"
#include <future>
#include <thread>
#include "hci/acl_manager_mock.h"
#include "hci/address.h"
#include "l2cap/cid.h"
-#include "l2cap/internal/le_fixed_channel_service_impl_mock.h"
-#include "l2cap/internal/le_fixed_channel_service_manager_impl_mock.h"
#include "l2cap/internal/parameter_provider_mock.h"
-#include "l2cap/le_fixed_channel_manager.h"
+#include "l2cap/le/fixed_channel_manager.h"
+#include "l2cap/le/internal/fixed_channel_service_impl_mock.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl_mock.h"
#include "os/handler.h"
#include "os/thread.h"
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
using hci::testing::MockAclConnection;
using hci::testing::MockAclManager;
+using l2cap::internal::testing::MockParameterProvider;
using ::testing::_; // Matcher to any value
using ::testing::ByMove;
using ::testing::DoAll;
-using testing::MockLeFixedChannelServiceImpl;
-using testing::MockLeFixedChannelServiceManagerImpl;
-using testing::MockParameterProvider;
+using testing::MockFixedChannelServiceImpl;
+using testing::MockFixedChannelServiceManagerImpl;
using ::testing::Return;
using ::testing::SaveArg;
};
TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl) {
- MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
- mock_parameter_provider_);
+ LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<LeFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
channel_1 = std::move(channel);
});
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
channel_2 = std::move(channel);
});
hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
EXPECT_NE(channel_2, nullptr);
// Step 4: Calling ConnectServices() to the same device will no trigger another connection attempt
- LeFixedChannelManager::ConnectionResult my_result;
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
+ FixedChannelManager::ConnectionResult my_result;
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_2{
.handler_ = user_handler.get(),
.on_fail_callback_ = common::testing::BindLambdaForTesting(
- [&my_result](LeFixedChannelManager::ConnectionResult result) { my_result = result; })};
+ [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection_2));
SyncHandler(user_handler.get());
EXPECT_EQ(my_result.connection_result_code,
- LeFixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
+ FixedChannelManager::ConnectionResultCode::FAIL_ALL_SERVICES_HAVE_CHANNEL);
// Step 5: Register new service will cause new channels to be created during ConnectServices()
- MockLeFixedChannelServiceImpl mock_service_3;
+ MockFixedChannelServiceImpl mock_service_3;
results.emplace_back(kSmpBrCid + 1, &mock_service_3);
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection_3{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
- std::unique_ptr<LeFixedChannel> channel_3;
- EXPECT_CALL(mock_service_3, NotifyChannelCreation(_)).WillOnce([&channel_3](std::unique_ptr<LeFixedChannel> channel) {
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
+ std::unique_ptr<FixedChannel> channel_3;
+ EXPECT_CALL(mock_service_3, NotifyChannelCreation(_)).WillOnce([&channel_3](std::unique_ptr<FixedChannel> channel) {
channel_3 = std::move(channel);
});
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection_3));
}
TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_no_service) {
- MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
hci::AddressType address_type = hci::AddressType::PUBLIC_DEVICE_ADDRESS;
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
- mock_parameter_provider_);
+ LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Make sure no service is registered
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without any service registered will result in failure
EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(0);
- LeFixedChannelManager::ConnectionResult my_result;
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ FixedChannelManager::ConnectionResult my_result;
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
.on_fail_callback_ = common::testing::BindLambdaForTesting(
- [&my_result](LeFixedChannelManager::ConnectionResult result) { my_result = result; })};
+ [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
SyncHandler(user_handler.get());
- EXPECT_EQ(my_result.connection_result_code, LeFixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
+ EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_NO_SERVICE_REGISTERED);
user_handler->Clear();
}
TEST_F(L2capLeLinkManagerTest, connect_fixed_channel_service_without_acl_with_hci_failure) {
- MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
- mock_parameter_provider_);
+ LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockLeFixedChannelServiceImpl mock_service_1;
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
- LeFixedChannelManager::ConnectionResult my_result;
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ FixedChannelManager::ConnectionResult my_result;
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
.on_fail_callback_ = common::testing::BindLambdaForTesting(
- [&my_result](LeFixedChannelManager::ConnectionResult result) { my_result = result; })};
+ [&my_result](FixedChannelManager::ConnectionResult result) { my_result = result; })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection failure event should trigger connection failure callback
hci::ErrorCode::PAGE_TIMEOUT));
SyncHandler(hci_callback_handler);
SyncHandler(user_handler.get());
- EXPECT_EQ(my_result.connection_result_code, LeFixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
+ EXPECT_EQ(my_result.connection_result_code, FixedChannelManager::ConnectionResultCode::FAIL_HCI_ERROR);
EXPECT_EQ(my_result.hci_error, hci::ErrorCode::PAGE_TIMEOUT);
user_handler->Clear();
TEST_F(L2capLeLinkManagerTest, not_acquiring_channels_should_disconnect_acl_after_timeout) {
EXPECT_CALL(*mock_parameter_provider_, GetLeLinkIdleDisconnectTimeout)
.WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
- MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
- mock_parameter_provider_);
+ LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<LeFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
channel_1 = std::move(channel);
});
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
channel_2 = std::move(channel);
});
hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
channel_2->RegisterOnCloseCallback(
user_handler.get(), common::testing::BindLambdaForTesting([&](hci::ErrorCode status) { status_2 = status; }));
- // Step 4: Leave channel IDLE long enough, they will disconnect
+ // Step 4: ave channel IDLE long enough, they will disconnect
EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(1);
std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 1.2);
TEST_F(L2capLeLinkManagerTest, acquiring_channels_should_not_disconnect_acl_after_timeout) {
EXPECT_CALL(*mock_parameter_provider_, GetLeLinkIdleDisconnectTimeout)
.WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
- MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
hci::AddressType address_type = hci::AddressType::RANDOM_DEVICE_ADDRESS;
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
- mock_parameter_provider_);
+ LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<LeFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
channel_1 = std::move(channel);
});
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
channel_2 = std::move(channel);
});
hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
channel_1->Acquire();
- // Step 4: Leave channel IDLE, it won't disconnect to due acquired channel 1
+ // Step 4: ave channel IDLE, it won't disconnect to due acquired channel 1
EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(0);
std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 2);
TEST_F(L2capLeLinkManagerTest, acquiring_and_releasing_channels_should_eventually_disconnect_acl) {
EXPECT_CALL(*mock_parameter_provider_, GetLeLinkIdleDisconnectTimeout)
.WillRepeatedly(Return(kTestIdleDisconnectTimeoutShort));
- MockLeFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
+ MockFixedChannelServiceManagerImpl mock_le_fixed_channel_service_manager;
MockAclManager mock_acl_manager;
hci::Address device{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
hci::AddressType address_type = hci::AddressType::PUBLIC_IDENTITY_ADDRESS;
os::Handler* hci_callback_handler = nullptr;
EXPECT_CALL(mock_acl_manager, RegisterLeCallbacks(_, _))
.WillOnce(DoAll(SaveArg<0>(&hci_le_connection_callbacks), SaveArg<1>(&hci_callback_handler)));
- LeLinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
- mock_parameter_provider_);
+ LinkManager le_link_manager(l2cap_handler_, &mock_acl_manager, &mock_le_fixed_channel_service_manager,
+ mock_parameter_provider_);
EXPECT_EQ(hci_le_connection_callbacks, &le_link_manager);
EXPECT_EQ(hci_callback_handler, l2cap_handler_);
// Register fake services
- MockLeFixedChannelServiceImpl mock_service_1, mock_service_2;
- std::vector<std::pair<Cid, LeFixedChannelServiceImpl*>> results;
+ MockFixedChannelServiceImpl mock_service_1, mock_service_2;
+ std::vector<std::pair<Cid, FixedChannelServiceImpl*>> results;
results.emplace_back(kSmpBrCid, &mock_service_1);
results.emplace_back(kConnectionlessCid, &mock_service_2);
EXPECT_CALL(mock_le_fixed_channel_service_manager, GetRegisteredServices()).WillRepeatedly(Return(results));
// Step 2: Connect to fixed channel without ACL connection should trigger ACL connection process
EXPECT_CALL(mock_acl_manager, CreateLeConnection(device, address_type)).Times(1);
- LeLinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
+ LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
.handler_ = user_handler.get(),
- .on_fail_callback_ = common::BindOnce([](LeFixedChannelManager::ConnectionResult result) { FAIL(); })};
+ .on_fail_callback_ = common::BindOnce([](FixedChannelManager::ConnectionResult result) { FAIL(); })};
le_link_manager.ConnectFixedChannelServices(device, address_type, std::move(pending_fixed_channel_connection));
// Step 3: ACL connection success event should trigger channel creation for all registered services
hci::AclConnection::Queue link_queue{10};
EXPECT_CALL(*acl_connection, GetAclQueueEnd()).WillRepeatedly((Return(link_queue.GetUpEnd())));
EXPECT_CALL(*acl_connection, GetAddress()).WillRepeatedly(Return(device));
- std::unique_ptr<LeFixedChannel> channel_1, channel_2;
- EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<LeFixedChannel> channel) {
+ std::unique_ptr<FixedChannel> channel_1, channel_2;
+ EXPECT_CALL(mock_service_1, NotifyChannelCreation(_)).WillOnce([&channel_1](std::unique_ptr<FixedChannel> channel) {
channel_1 = std::move(channel);
});
- EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<LeFixedChannel> channel) {
+ EXPECT_CALL(mock_service_2, NotifyChannelCreation(_)).WillOnce([&channel_2](std::unique_ptr<FixedChannel> channel) {
channel_2 = std::move(channel);
});
hci_callback_handler->Post(common::BindOnce(&hci::LeConnectionCallbacks::OnLeConnectSuccess,
channel_1->Acquire();
- // Step 4: Leave channel IDLE, it won't disconnect to due acquired channel 1
+ // Step 4: ave channel IDLE, it won't disconnect to due acquired channel 1
EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(0);
std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 2);
- // Step 5: Leave channel IDLE long enough, they will disconnect
+ // Step 5: ave channel IDLE long enough, they will disconnect
channel_1->Release();
EXPECT_CALL(*raw_acl_connection, Disconnect(hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION)).Times(1);
std::this_thread::sleep_for(kTestIdleDisconnectTimeoutShort * 1.2);
}
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
#include "hci/acl_manager_mock.h"
#include "hci/address.h"
-#include "l2cap/internal/classic_link.h"
#include "l2cap/internal/scheduler_mock.h"
+#include "l2cap/le/internal/link.h"
#include <gmock/gmock.h>
// Unit test interfaces
namespace bluetooth {
namespace l2cap {
+namespace le {
namespace internal {
namespace testing {
using hci::testing::MockAclConnection;
-class MockClassicLink : public ClassicLink {
+class MockLink : public Link {
public:
- explicit MockClassicLink(os::Handler* handler, ParameterProvider* parameter_provider)
- : ClassicLink(handler, std::make_unique<MockAclConnection>(), std::make_unique<MockScheduler>(),
- parameter_provider){};
+ explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider)
+ : Link(handler, std::make_unique<MockAclConnection>(),
+ std::make_unique<l2cap::internal::testing::MockScheduler>(), parameter_provider){};
MOCK_METHOD(hci::Address, GetDevice, (), (override));
MOCK_METHOD(void, OnAclDisconnected, (hci::ErrorCode status), (override));
MOCK_METHOD(void, Disconnect, (), (override));
- MOCK_METHOD(std::shared_ptr<ClassicFixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
+ MOCK_METHOD(std::shared_ptr<FixedChannelImpl>, AllocateFixedChannel, (Cid cid, SecurityPolicy security_policy),
(override));
MOCK_METHOD(bool, IsFixedChannelAllocated, (Cid cid), (override));
MOCK_METHOD(void, RefreshRefCount, (), (override));
} // namespace testing
} // namespace internal
+} // namespace le
} // namespace l2cap
} // namespace bluetooth
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2019 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.
+ */
+#define LOG_TAG "l2cap2"
+
+#include <memory>
+
+#include "common/bidi_queue.h"
+#include "hci/acl_manager.h"
+#include "hci/address.h"
+#include "hci/hci_layer.h"
+#include "hci/hci_packets.h"
+#include "l2cap/internal/parameter_provider.h"
+#include "l2cap/le/internal/fixed_channel_service_manager_impl.h"
+#include "l2cap/le/internal/link_manager.h"
+#include "module.h"
+#include "os/handler.h"
+#include "os/log.h"
+
+#include "l2cap/le/l2cap_le_module.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace le {
+
+const ModuleFactory L2capLeModule::Factory = ModuleFactory([]() { return new L2capLeModule(); });
+
+struct L2capLeModule::impl {
+ impl(os::Handler* l2cap_handler, hci::AclManager* acl_manager)
+ : l2cap_handler_(l2cap_handler), acl_manager_(acl_manager) {}
+ os::Handler* l2cap_handler_;
+ hci::AclManager* acl_manager_;
+ l2cap::internal::ParameterProvider parameter_provider_;
+ internal::FixedChannelServiceManagerImpl fixed_channel_service_manager_impl_{l2cap_handler_};
+ internal::LinkManager link_manager_{l2cap_handler_, acl_manager_, &fixed_channel_service_manager_impl_,
+ ¶meter_provider_};
+};
+
+void L2capLeModule::ListDependencies(ModuleList* list) {
+ list->add<hci::AclManager>();
+}
+
+void L2capLeModule::Start() {
+ pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<hci::AclManager>());
+}
+
+void L2capLeModule::Stop() {
+ pimpl_.reset();
+}
+
+std::unique_ptr<FixedChannelManager> L2capLeModule::GetFixedChannelManager() {
+ return std::unique_ptr<FixedChannelManager>(new FixedChannelManager(&pimpl_->fixed_channel_service_manager_impl_,
+ &pimpl_->link_manager_, pimpl_->l2cap_handler_));
+}
+
+} // namespace le
+} // namespace l2cap
+} // namespace bluetooth
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2019 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 <memory>
+
+#include "l2cap/le/fixed_channel_manager.h"
+#include "module.h"
+
+namespace bluetooth {
+namespace l2cap {
+namespace le {
+
+class L2capLeModule : public bluetooth::Module {
+ public:
+ L2capLeModule() = default;
+ ~L2capLeModule() = default;
+
+ /**
+ * Get the api to the LE fixed channel l2cap module
+ */
+ std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
+
+ static const ModuleFactory Factory;
+
+ protected:
+ void ListDependencies(ModuleList* list) override;
+
+ void Start() override;
+
+ void Stop() override;
+
+ private:
+ struct impl;
+ std::unique_ptr<impl> pimpl_;
+ DISALLOW_COPY_AND_ASSIGN(L2capLeModule);
+};
+
+} // namespace le
+} // namespace l2cap
+} // namespace bluetooth
\ No newline at end of file
#include "hal/hci_hal.h"
#include "hci/acl_manager.h"
#include "hci/classic_security_manager.h"
-#include "l2cap/l2cap_layer.h"
+#include "l2cap/classic/l2cap_classic_module.h"
+#include "l2cap/le/l2cap_le_module.h"
#include "os/log.h"
#include "os/thread.h"
#include "shim/controller.h"
modules.add<::bluetooth::hal::HciHal>();
modules.add<::bluetooth::hci::AclManager>();
modules.add<::bluetooth::hci::ClassicSecurityManager>();
- modules.add<::bluetooth::l2cap::L2capLayer>();
+ modules.add<::bluetooth::l2cap::classic::L2capClassicModule>();
+ modules.add<::bluetooth::l2cap::le::L2capLeModule>();
modules.add<::bluetooth::shim::Controller>();
modules.add<::bluetooth::shim::HciLayer>();