Loading system/test/rootcanal/Android.bp +38 −0 Original line number Diff line number Diff line Loading @@ -55,3 +55,41 @@ cc_binary { ], init_rc: ["android.hardware.bluetooth@1.0-service.sim.rc"], } cc_library_shared { name: "android.hardware.bluetooth@1.0-impl-sim", proprietary: true, relative_install_path: "hw", srcs: [ "bluetooth_hci.cc", ], shared_libs: [ "android.hardware.bluetooth@1.0", "libbase", "libchrome", "libcutils", "libhardware", "libhidlbase", "libhidltransport", "liblog", "libutils", ], cflags: [ "-Wall", "-Wextra", "-Werror", "-DHAS_NO_BDROID_BUILDCFG", ], static_libs: [ "android.hardware.bluetooth-async", "android.hardware.bluetooth-hci", "libbt-rootcanal", ], include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/hci/include", "packages/modules/Bluetooth/system/include", "packages/modules/Bluetooth/system/stack/include", ], } system/test/rootcanal/bluetooth_hci.cc +55 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ #include <string.h> #include <utils/Log.h> #include "acl_packet.h" #include "event_packet.h" #include "hci_internals.h" #include "sco_packet.h" namespace android { namespace hardware { Loading @@ -31,11 +34,13 @@ namespace V1_0 { namespace sim { using android::hardware::hidl_vec; using test_vendor_lib::AclPacket; using test_vendor_lib::AsyncManager; using test_vendor_lib::AsyncTaskId; using test_vendor_lib::CommandPacket; using test_vendor_lib::DualModeController; using test_vendor_lib::EventPacket; using test_vendor_lib::ScoPacket; using test_vendor_lib::TaskCallback; using test_vendor_lib::TestChannelTransport; Loading Loading @@ -92,10 +97,24 @@ Return<void> BluetoothHci::initialize(const sp<IBluetoothHciCallbacks>& cb) { cb->hciEventReceived(hci_event); }); /* RegisterAcl and RegisterSco cb->aclDataReceived(hci_packet); cb->scoDataReceived(hci_packet); */ controller_.RegisterAclChannel([cb](std::unique_ptr<AclPacket> packet) { std::vector<uint8_t> acl_vector = packet->GetPacket(); hidl_vec<uint8_t> acl_packet = acl_vector; cb->aclDataReceived(acl_packet); }); controller_.RegisterScoChannel([cb](std::unique_ptr<ScoPacket> packet) { size_t header_bytes = packet->GetHeaderSize(); size_t payload_bytes = packet->GetPayloadSize(); hidl_vec<uint8_t> sco_packet; sco_packet.resize(header_bytes + payload_bytes); memcpy(sco_packet.data(), packet->GetHeader().data(), header_bytes); memcpy(sco_packet.data() + header_bytes, packet->GetPayload().data(), payload_bytes); cb->scoDataReceived(sco_packet); }); controller_.RegisterTaskScheduler( [this](std::chrono::milliseconds delay, const TaskCallback& task) { Loading Loading @@ -142,13 +161,36 @@ Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& packet) { return Void(); } Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& /* packet */) { CHECK(false) << __func__ << " not yet implemented"; Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& packet) { async_manager_.ExecAsync(std::chrono::milliseconds(0), [this, packet]() { uint16_t channel = (packet[0] | (packet[1] << 8)) & 0xfff; AclPacket::PacketBoundaryFlags boundary_flags = static_cast<AclPacket::PacketBoundaryFlags>((packet[1] & 0x30) >> 4); AclPacket::BroadcastFlags broadcast_flags = static_cast<AclPacket::BroadcastFlags>((packet[1] & 0xC0) >> 6); std::unique_ptr<AclPacket> acl = std::unique_ptr<AclPacket>( new AclPacket(channel, boundary_flags, broadcast_flags)); for (size_t i = 4; i < packet.size(); i++) acl->AddPayloadOctets1(packet[i]); controller_.HandleAcl(std::move(acl)); }); return Void(); } Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& /* packet */) { CHECK(false) << __func__ << " not yet implemented"; Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& packet) { async_manager_.ExecAsync(std::chrono::milliseconds(0), [this, packet]() { uint16_t channel = (packet[0] | (packet[1] << 8)) & 0xfff; ScoPacket::PacketStatusFlags packet_status = static_cast<ScoPacket::PacketStatusFlags>((packet[1] & 0x30) >> 4); std::unique_ptr<ScoPacket> sco = std::unique_ptr<ScoPacket>(new ScoPacket(channel, packet_status)); for (size_t i = 3; i < packet.size(); i++) sco->AddPayloadOctets1(packet[i]); controller_.HandleSco(std::move(sco)); }); return Void(); } Loading Loading @@ -176,6 +218,11 @@ void BluetoothHci::SetUpTestChannel(int port) { }); } /* Fallback to shared library if there is no service. */ IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) { return new BluetoothHci(); } } // namespace gce } // namespace V1_0 } // namespace bluetooth Loading system/test/rootcanal/bluetooth_hci.h +2 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class BluetoothHci : public IBluetoothHci { test_vendor_lib::TestChannelTransport test_channel_transport_; }; extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name); } // namespace sim } // namespace V1_0 } // namespace bluetooth Loading system/vendor_libs/test_vendor_lib/Android.bp +10 −0 Original line number Diff line number Diff line Loading @@ -4,13 +4,23 @@ cc_library_static { name: "libbt-rootcanal", proprietary: true, srcs: [ "src/acl_packet.cc", "src/async_manager.cc", "src/beacon.cc", "src/beacon_swarm.cc", "src/broken_adv.cc", "src/bt_address.cc", "src/classic.cc", "src/command_packet.cc", "src/connection.cc", "src/device.cc", "src/device_factory.cc", "src/dual_mode_controller.cc", "src/event_packet.cc", "src/keyboard.cc", "src/packet.cc", "src/packet_stream.cc", "src/sco_packet.cc", "src/test_channel_transport.cc", ], cflags: [ Loading system/vendor_libs/test_vendor_lib/include/acl_packet.h 0 → 100644 +85 −0 Original line number Diff line number Diff line // // Copyright 2017 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 <cstdint> #include <string> #include <vector> namespace test_vendor_lib { // ACL data packets are specified in the Bluetooth Core Specification Version // 4.2, Volume 2, Part E, Section 5.4.2 class AclPacket { public: typedef enum { FirstNonAutomaticallyFlushable, Continuing, FirstAutomaticallyFlushable, Complete } PacketBoundaryFlags; typedef enum { PointToPoint, ActiveSlaveBroadcast, ParkedSlaveBroadcast, Reserved } BroadcastFlags; virtual ~AclPacket() = default; uint16_t GetChannel() const { return (raw_packet_[0] | (raw_packet_[1] << 8)) & 0xfff; } PacketBoundaryFlags GetPacketBoundaryFlags() const { return static_cast<PacketBoundaryFlags>((raw_packet_[1] & 0x30) >> 4); } BroadcastFlags GetBroadcastFlags() const { return static_cast<BroadcastFlags>((raw_packet_[1] & 0xC0) >> 6); } explicit AclPacket(uint16_t channel, AclPacket::PacketBoundaryFlags boundary_flags, AclPacket::BroadcastFlags broadcast); size_t GetPacketSize() const; const std::vector<uint8_t>& GetPacket() const; void AddPayloadOctets(size_t octets, const std::vector<uint8_t>& bytes); private: // Add |octets| bytes to the payload. void AddPayloadOctets(size_t octets, uint64_t value); static const size_t kHeaderSize = 4; public: // Add type-checking versions void AddPayloadOctets1(uint8_t value) { AddPayloadOctets(1, value); } void AddPayloadOctets2(uint16_t value) { AddPayloadOctets(2, value); } void AddPayloadOctets3(uint32_t value) { AddPayloadOctets(3, value); } void AddPayloadOctets4(uint32_t value) { AddPayloadOctets(4, value); } void AddPayloadOctets6(uint64_t value) { AddPayloadOctets(6, value); } void AddPayloadOctets8(uint64_t value) { AddPayloadOctets(8, value); } private: std::vector<uint8_t> raw_packet_; }; } // namespace test_vendor_lib Loading
system/test/rootcanal/Android.bp +38 −0 Original line number Diff line number Diff line Loading @@ -55,3 +55,41 @@ cc_binary { ], init_rc: ["android.hardware.bluetooth@1.0-service.sim.rc"], } cc_library_shared { name: "android.hardware.bluetooth@1.0-impl-sim", proprietary: true, relative_install_path: "hw", srcs: [ "bluetooth_hci.cc", ], shared_libs: [ "android.hardware.bluetooth@1.0", "libbase", "libchrome", "libcutils", "libhardware", "libhidlbase", "libhidltransport", "liblog", "libutils", ], cflags: [ "-Wall", "-Wextra", "-Werror", "-DHAS_NO_BDROID_BUILDCFG", ], static_libs: [ "android.hardware.bluetooth-async", "android.hardware.bluetooth-hci", "libbt-rootcanal", ], include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/hci/include", "packages/modules/Bluetooth/system/include", "packages/modules/Bluetooth/system/stack/include", ], }
system/test/rootcanal/bluetooth_hci.cc +55 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,10 @@ #include <string.h> #include <utils/Log.h> #include "acl_packet.h" #include "event_packet.h" #include "hci_internals.h" #include "sco_packet.h" namespace android { namespace hardware { Loading @@ -31,11 +34,13 @@ namespace V1_0 { namespace sim { using android::hardware::hidl_vec; using test_vendor_lib::AclPacket; using test_vendor_lib::AsyncManager; using test_vendor_lib::AsyncTaskId; using test_vendor_lib::CommandPacket; using test_vendor_lib::DualModeController; using test_vendor_lib::EventPacket; using test_vendor_lib::ScoPacket; using test_vendor_lib::TaskCallback; using test_vendor_lib::TestChannelTransport; Loading Loading @@ -92,10 +97,24 @@ Return<void> BluetoothHci::initialize(const sp<IBluetoothHciCallbacks>& cb) { cb->hciEventReceived(hci_event); }); /* RegisterAcl and RegisterSco cb->aclDataReceived(hci_packet); cb->scoDataReceived(hci_packet); */ controller_.RegisterAclChannel([cb](std::unique_ptr<AclPacket> packet) { std::vector<uint8_t> acl_vector = packet->GetPacket(); hidl_vec<uint8_t> acl_packet = acl_vector; cb->aclDataReceived(acl_packet); }); controller_.RegisterScoChannel([cb](std::unique_ptr<ScoPacket> packet) { size_t header_bytes = packet->GetHeaderSize(); size_t payload_bytes = packet->GetPayloadSize(); hidl_vec<uint8_t> sco_packet; sco_packet.resize(header_bytes + payload_bytes); memcpy(sco_packet.data(), packet->GetHeader().data(), header_bytes); memcpy(sco_packet.data() + header_bytes, packet->GetPayload().data(), payload_bytes); cb->scoDataReceived(sco_packet); }); controller_.RegisterTaskScheduler( [this](std::chrono::milliseconds delay, const TaskCallback& task) { Loading Loading @@ -142,13 +161,36 @@ Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& packet) { return Void(); } Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& /* packet */) { CHECK(false) << __func__ << " not yet implemented"; Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& packet) { async_manager_.ExecAsync(std::chrono::milliseconds(0), [this, packet]() { uint16_t channel = (packet[0] | (packet[1] << 8)) & 0xfff; AclPacket::PacketBoundaryFlags boundary_flags = static_cast<AclPacket::PacketBoundaryFlags>((packet[1] & 0x30) >> 4); AclPacket::BroadcastFlags broadcast_flags = static_cast<AclPacket::BroadcastFlags>((packet[1] & 0xC0) >> 6); std::unique_ptr<AclPacket> acl = std::unique_ptr<AclPacket>( new AclPacket(channel, boundary_flags, broadcast_flags)); for (size_t i = 4; i < packet.size(); i++) acl->AddPayloadOctets1(packet[i]); controller_.HandleAcl(std::move(acl)); }); return Void(); } Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& /* packet */) { CHECK(false) << __func__ << " not yet implemented"; Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& packet) { async_manager_.ExecAsync(std::chrono::milliseconds(0), [this, packet]() { uint16_t channel = (packet[0] | (packet[1] << 8)) & 0xfff; ScoPacket::PacketStatusFlags packet_status = static_cast<ScoPacket::PacketStatusFlags>((packet[1] & 0x30) >> 4); std::unique_ptr<ScoPacket> sco = std::unique_ptr<ScoPacket>(new ScoPacket(channel, packet_status)); for (size_t i = 3; i < packet.size(); i++) sco->AddPayloadOctets1(packet[i]); controller_.HandleSco(std::move(sco)); }); return Void(); } Loading Loading @@ -176,6 +218,11 @@ void BluetoothHci::SetUpTestChannel(int port) { }); } /* Fallback to shared library if there is no service. */ IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) { return new BluetoothHci(); } } // namespace gce } // namespace V1_0 } // namespace bluetooth Loading
system/test/rootcanal/bluetooth_hci.h +2 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ class BluetoothHci : public IBluetoothHci { test_vendor_lib::TestChannelTransport test_channel_transport_; }; extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name); } // namespace sim } // namespace V1_0 } // namespace bluetooth Loading
system/vendor_libs/test_vendor_lib/Android.bp +10 −0 Original line number Diff line number Diff line Loading @@ -4,13 +4,23 @@ cc_library_static { name: "libbt-rootcanal", proprietary: true, srcs: [ "src/acl_packet.cc", "src/async_manager.cc", "src/beacon.cc", "src/beacon_swarm.cc", "src/broken_adv.cc", "src/bt_address.cc", "src/classic.cc", "src/command_packet.cc", "src/connection.cc", "src/device.cc", "src/device_factory.cc", "src/dual_mode_controller.cc", "src/event_packet.cc", "src/keyboard.cc", "src/packet.cc", "src/packet_stream.cc", "src/sco_packet.cc", "src/test_channel_transport.cc", ], cflags: [ Loading
system/vendor_libs/test_vendor_lib/include/acl_packet.h 0 → 100644 +85 −0 Original line number Diff line number Diff line // // Copyright 2017 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 <cstdint> #include <string> #include <vector> namespace test_vendor_lib { // ACL data packets are specified in the Bluetooth Core Specification Version // 4.2, Volume 2, Part E, Section 5.4.2 class AclPacket { public: typedef enum { FirstNonAutomaticallyFlushable, Continuing, FirstAutomaticallyFlushable, Complete } PacketBoundaryFlags; typedef enum { PointToPoint, ActiveSlaveBroadcast, ParkedSlaveBroadcast, Reserved } BroadcastFlags; virtual ~AclPacket() = default; uint16_t GetChannel() const { return (raw_packet_[0] | (raw_packet_[1] << 8)) & 0xfff; } PacketBoundaryFlags GetPacketBoundaryFlags() const { return static_cast<PacketBoundaryFlags>((raw_packet_[1] & 0x30) >> 4); } BroadcastFlags GetBroadcastFlags() const { return static_cast<BroadcastFlags>((raw_packet_[1] & 0xC0) >> 6); } explicit AclPacket(uint16_t channel, AclPacket::PacketBoundaryFlags boundary_flags, AclPacket::BroadcastFlags broadcast); size_t GetPacketSize() const; const std::vector<uint8_t>& GetPacket() const; void AddPayloadOctets(size_t octets, const std::vector<uint8_t>& bytes); private: // Add |octets| bytes to the payload. void AddPayloadOctets(size_t octets, uint64_t value); static const size_t kHeaderSize = 4; public: // Add type-checking versions void AddPayloadOctets1(uint8_t value) { AddPayloadOctets(1, value); } void AddPayloadOctets2(uint16_t value) { AddPayloadOctets(2, value); } void AddPayloadOctets3(uint32_t value) { AddPayloadOctets(3, value); } void AddPayloadOctets4(uint32_t value) { AddPayloadOctets(4, value); } void AddPayloadOctets6(uint64_t value) { AddPayloadOctets(6, value); } void AddPayloadOctets8(uint64_t value) { AddPayloadOctets(8, value); } private: std::vector<uint8_t> raw_packet_; }; } // namespace test_vendor_lib