filegroup {
name: "BluetoothHalSources",
srcs: [
- "bluetooth_snoop_logger.cc",
+ "snoop_logger.cc",
],
}
class HciTransportationService
: public HciTransportation::Service,
- public ::bluetooth::hal::BluetoothHciHalCallbacks {
+ public ::bluetooth::hal::HciHalCallbacks {
public:
- HciTransportationService(BluetoothHciHal* hal) : hal_(hal) {
+ HciTransportationService(HciHal* hal) : hal_(hal) {
}
::grpc::Status SetLoopbackMode(::grpc::ServerContext* context,
// TODO
}
private:
- BluetoothHciHal* hal_;
+ HciHal* hal_;
};
void HalFacadeModule::ListDependencies(ModuleList* list) {
::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
- list->add<BluetoothHciHal>();
+ list->add<HciHal>();
}
void HalFacadeModule::Start(const ModuleRegistry* registry) {
::bluetooth::grpc::GrpcFacadeModule::Start(registry);
- auto hal = registry->GetInstance<BluetoothHciHal>();
+ auto hal = registry->GetInstance<HciHal>();
service_ = new HciTransportationService(hal);
hal->registerIncomingPacketCallback(service_);
// callback to BluetoothInitializationCompleteCallback
// The interface from the Bluetooth Controller to the stack
-class BluetoothHciHalCallbacks {
+class HciHalCallbacks {
public:
- virtual ~BluetoothHciHalCallbacks() = default;
+ virtual ~HciHalCallbacks() = default;
// This function is invoked when an HCI event is received from the
// Bluetooth controller to be forwarded to the Bluetooth stack
// Abstraction Layer (HAL). Dealing only in HCI packets and events simplifies
// the stack and abstracts away power management, initialization, and other
// implementation-specific details related to the hardware.
-class BluetoothHciHal : public ::bluetooth::Module {
+class HciHal : public ::bluetooth::Module {
public:
static const ModuleFactory Factory;
- virtual ~BluetoothHciHal() = default;
+ virtual ~HciHal() = default;
// Register the callback for incoming packets. All incoming packets are dropped before
// this callback is registered. Callback can only be registered once, but will be reset
// @param callback implements BluetoothHciHalCallbacks which will
// receive callbacks when incoming HCI packets are received
// from the controller to be sent to the host.
- virtual void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) = 0;
+ virtual void registerIncomingPacketCallback(HciHalCallbacks* callback) = 0;
// Send an HCI command (as specified in the Bluetooth Specification
// V4.2, Vol 2, Part 5, Section 5.4.1) to the Bluetooth controller.
#include <android/hardware/bluetooth/1.0/IBluetoothHciCallbacks.h>
#include <android/hardware/bluetooth/1.0/types.h>
-#include "hal/bluetooth_snoop_logger.h"
+#include "hal/snoop_logger.h"
#include "os/log.h"
using ::android::hardware::hidl_vec;
namespace {
constexpr char kDefaultBtsnoopPath[] = "/data/misc/bluetooth/logs/btsnoop_hci.log";
-class BluetoothHciDeathRecipient : public ::android::hardware::hidl_death_recipient {
+class HciDeathRecipient : public ::android::hardware::hidl_death_recipient {
public:
virtual void serviceDied(uint64_t /*cookie*/, const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
LOG_ERROR("Bluetooth HAL service died!");
}
};
-android::sp<BluetoothHciDeathRecipient> bluetooth_hci_death_recipient_ = new BluetoothHciDeathRecipient();
+android::sp<HciDeathRecipient> hci_death_recipient_ = new HciDeathRecipient();
-class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
+class InternalHciCallbacks : public IBluetoothHciCallbacks {
public:
- HciHalBluetoothHciCallbacks(BluetoothSnoopLogger* btsnoop_logger)
+ InternalHciCallbacks(SnoopLogger* btsnoop_logger)
: btsnoop_logger_(btsnoop_logger) {
init_promise_ = new std::promise<void>();
}
- void SetCallback(BluetoothHciHalCallbacks* callback) {
+ void SetCallback(HciHalCallbacks* callback) {
ASSERT(callback_ == nullptr && callback != nullptr);
callback_ = callback;
}
Return<void> hciEventReceived(const hidl_vec<uint8_t>& event) {
std::vector<uint8_t> received_hci_packet(event.begin(), event.end());
- btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
- BluetoothSnoopLogger::PacketType::EVT);
+ btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
+ SnoopLogger::PacketType::EVT);
if (callback_ != nullptr) {
callback_->hciEventReceived(std::move(received_hci_packet));
}
Return<void> aclDataReceived(const hidl_vec<uint8_t>& data) {
std::vector<uint8_t> received_hci_packet(data.begin(), data.end());
- btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
- BluetoothSnoopLogger::PacketType::ACL);
+ btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
+ SnoopLogger::PacketType::ACL);
if (callback_ != nullptr) {
callback_->aclDataReceived(std::move(received_hci_packet));
}
Return<void> scoDataReceived(const hidl_vec<uint8_t>& data) {
std::vector<uint8_t> received_hci_packet(data.begin(), data.end());
- btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
- BluetoothSnoopLogger::PacketType::SCO);
+ btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
+ SnoopLogger::PacketType::SCO);
if (callback_ != nullptr) {
callback_->scoDataReceived(std::move(received_hci_packet));
}
private:
std::promise<void>* init_promise_ = nullptr;
- BluetoothHciHalCallbacks* callback_ = nullptr;
- BluetoothSnoopLogger* btsnoop_logger_ = nullptr;
+ HciHalCallbacks* callback_ = nullptr;
+ SnoopLogger* btsnoop_logger_ = nullptr;
};
} // namespace
-class BluetoothHciHalHidl : public BluetoothHciHal {
+class HciHalHidl : public HciHal {
public:
- void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) override {
+ void registerIncomingPacketCallback(HciHalCallbacks* callback) override {
callbacks_->SetCallback(callback);
}
void sendHciCommand(HciPacket command) override {
- btsnoop_logger_->capture(command, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::CMD);
+ btsnoop_logger_->capture(command, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
bt_hci_->sendHciCommand(command);
}
void sendAclData(HciPacket packet) override {
- btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::ACL);
+ btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
bt_hci_->sendAclData(packet);
}
void sendScoData(HciPacket packet) override {
- btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::SCO);
+ btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::SCO);
bt_hci_->sendScoData(packet);
}
}
void Start(const ModuleRegistry* registry) override {
- btsnoop_logger_ = new BluetoothSnoopLogger(kDefaultBtsnoopPath);
+ btsnoop_logger_ = new SnoopLogger(kDefaultBtsnoopPath);
bt_hci_ = IBluetoothHci::getService();
ASSERT(bt_hci_ != nullptr);
- auto death_link = bt_hci_->linkToDeath(bluetooth_hci_death_recipient_, 0);
+ auto death_link = bt_hci_->linkToDeath(hci_death_recipient_, 0);
ASSERT_LOG(death_link.isOk(), "Unable to set the death recipient for the Bluetooth HAL");
// Block allows allocation of a variable that might be bypassed by goto.
{
- callbacks_ = new HciHalBluetoothHciCallbacks(btsnoop_logger_);
+ callbacks_ = new InternalHciCallbacks(btsnoop_logger_);
bt_hci_->initialize(callbacks_);
// Don't timeout here, time out at a higher layer
callbacks_->GetInitPromise()->get_future().wait();
void Stop(const ModuleRegistry* registry) override {
ASSERT(bt_hci_ != nullptr);
- auto death_unlink = bt_hci_->unlinkToDeath(bluetooth_hci_death_recipient_);
+ auto death_unlink = bt_hci_->unlinkToDeath(hci_death_recipient_);
if (!death_unlink.isOk()) {
LOG_ERROR("Error unlinking death recipient from the Bluetooth HAL");
}
}
private:
- android::sp<HciHalBluetoothHciCallbacks> callbacks_;
+ android::sp<InternalHciCallbacks> callbacks_;
android::sp<IBluetoothHci> bt_hci_;
- BluetoothSnoopLogger* btsnoop_logger_;
+ SnoopLogger* btsnoop_logger_;
};
-const ModuleFactory BluetoothHciHal::Factory = ModuleFactory([]() {
- return new BluetoothHciHalHidl();
+const ModuleFactory HciHal::Factory = ModuleFactory([]() {
+ return new HciHalHidl();
});
} // namespace hal
};
TEST_F(HciHalHidlTest, init_and_close) {
- fake_registry_.Start<BluetoothHciHal>();
+ fake_registry_.Start<HciHal>();
fake_registry_.StopAll();
}
} // namespace
#include <mutex>
#include <queue>
-#include "hal/bluetooth_snoop_logger.h"
+#include "hal/snoop_logger.h"
#include "os/log.h"
#include "os/reactor.h"
#include "os/thread.h"
namespace bluetooth {
namespace hal {
-class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
+class HciHalHostRootcanal : public HciHal {
public:
- void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) override {
+ void registerIncomingPacketCallback(HciHalCallbacks* callback) override {
std::lock_guard<std::mutex> lock(mutex_);
ASSERT(incoming_packet_callback_ == nullptr && callback != nullptr);
incoming_packet_callback_ = callback;
std::lock_guard<std::mutex> lock(mutex_);
ASSERT(sock_fd_ != INVALID_FD);
std::vector<uint8_t> packet = std::move(command);
- btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::CMD);
+ btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
packet.insert(packet.cbegin(), kH4Command);
write_to_rootcanal_fd(packet);
}
std::lock_guard<std::mutex> lock(mutex_);
ASSERT(sock_fd_ != INVALID_FD);
std::vector<uint8_t> packet = std::move(data);
- btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::ACL);
+ btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
packet.insert(packet.cbegin(), kH4Acl);
write_to_rootcanal_fd(packet);
}
std::lock_guard<std::mutex> lock(mutex_);
ASSERT(sock_fd_ != INVALID_FD);
std::vector<uint8_t> packet = std::move(data);
- btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::SCO);
+ btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::SCO);
packet.insert(packet.cbegin(), kH4Sco);
write_to_rootcanal_fd(packet);
}
ASSERT(sock_fd_ != INVALID_FD);
reactable_ =
hci_incoming_thread_.GetReactor()->Register(sock_fd_, [this]() { this->incoming_packet_received(); }, nullptr);
- btsnoop_logger_ = new BluetoothSnoopLogger(kDefaultBtsnoopPath);
+ btsnoop_logger_ = new SnoopLogger(kDefaultBtsnoopPath);
LOG_INFO("Rootcanal HAL opened successfully");
}
private:
std::mutex mutex_;
HciHalHostRootcanalConfig* config_ = HciHalHostRootcanalConfig::Get();
- BluetoothHciHalCallbacks* incoming_packet_callback_ = nullptr;
+ HciHalCallbacks* incoming_packet_callback_ = nullptr;
int sock_fd_ = INVALID_FD;
bluetooth::os::Thread hci_incoming_thread_ =
bluetooth::os::Thread("hci_incoming_thread", bluetooth::os::Thread::Priority::NORMAL);
bluetooth::os::Reactor::Reactable* reactable_ = nullptr;
std::queue<std::vector<uint8_t>> hci_outgoing_queue_;
- BluetoothSnoopLogger* btsnoop_logger_;
+ SnoopLogger* btsnoop_logger_;
void write_to_rootcanal_fd(HciPacket packet) {
// TODO: replace this with new queue when it's ready
HciPacket receivedHciPacket;
receivedHciPacket.assign(buf + kH4HeaderSize, buf + kH4HeaderSize + kHciEvtHeaderSize + payload_size);
- btsnoop_logger_->capture(receivedHciPacket, BluetoothSnoopLogger::Direction::INCOMING,
- BluetoothSnoopLogger::PacketType::EVT);
+ btsnoop_logger_->capture(receivedHciPacket, SnoopLogger::Direction::INCOMING,
+ SnoopLogger::PacketType::EVT);
incoming_packet_callback_->hciEventReceived(receivedHciPacket);
}
HciPacket receivedHciPacket;
receivedHciPacket.assign(buf + kH4HeaderSize, buf + kH4HeaderSize + kHciAclHeaderSize + payload_size);
- btsnoop_logger_->capture(receivedHciPacket, BluetoothSnoopLogger::Direction::INCOMING,
- BluetoothSnoopLogger::PacketType::ACL);
+ btsnoop_logger_->capture(receivedHciPacket, SnoopLogger::Direction::INCOMING,
+ SnoopLogger::PacketType::ACL);
incoming_packet_callback_->aclDataReceived(receivedHciPacket);
}
HciPacket receivedHciPacket;
receivedHciPacket.assign(buf + kH4HeaderSize, buf + kH4HeaderSize + kHciScoHeaderSize + payload_size);
- btsnoop_logger_->capture(receivedHciPacket, BluetoothSnoopLogger::Direction::INCOMING,
- BluetoothSnoopLogger::PacketType::SCO);
+ btsnoop_logger_->capture(receivedHciPacket, SnoopLogger::Direction::INCOMING,
+ SnoopLogger::PacketType::SCO);
incoming_packet_callback_->scoDataReceived(receivedHciPacket);
}
memset(buf, 0, kBufSize);
}
};
-const ModuleFactory BluetoothHciHal::Factory = ModuleFactory([]() {
- return new BluetoothHciHalHostRootcanal();
+const ModuleFactory HciHal::Factory = ModuleFactory([]() {
+ return new HciHalHostRootcanal();
});
} // namespace hal
std::queue<std::pair<uint8_t, HciPacket>> incoming_packets_queue_;
-class TestBluetoothHciHalCallbacks : public BluetoothHciHalCallbacks {
+class TestHciHalCallbacks : public HciHalCallbacks {
public:
void hciEventReceived(HciPacket packet) override {
incoming_packets_queue_.emplace(kH4Event, packet);
void SetUp() override {
HciHalHostRootcanalConfig::Get()->SetPort(kTestPort);
fake_server_ = new FakeRootcanalDesktopHciServer;
- fake_registry_.Start<BluetoothHciHal>();
- hal_ = fake_registry_.GetInstance<BluetoothHciHal>();
+ fake_registry_.Start<HciHal>();
+ hal_ = fake_registry_.GetInstance<HciHal>();
hal_->registerIncomingPacketCallback(&callbacks_);
fake_server_socket_ = fake_server_->Accept(); // accept() after client is connected to avoid blocking
std::queue<std::pair<uint8_t, HciPacket>> empty;
}
FakeRootcanalDesktopHciServer* fake_server_ = nullptr;
- BluetoothHciHal* hal_ = nullptr;
+ HciHal* hal_ = nullptr;
ModuleRegistry fake_registry_;
- TestBluetoothHciHalCallbacks callbacks_;
+ TestHciHalCallbacks callbacks_;
int fake_server_socket_ = -1;
};
* limitations under the License.
*/
-#include "hal/bluetooth_snoop_logger.h"
+#include "hal/snoop_logger.h"
#include <arpa/inet.h>
#include <netinet/in.h>
.datalink_type = BTSNOOP_DATALINK_TYPE};
} // namespace
-BluetoothSnoopLogger::BluetoothSnoopLogger(const std::string& filename) {
+SnoopLogger::SnoopLogger(const std::string& filename) {
{
std::ifstream btsnoop_istream(filename);
file_exists_ = btsnoop_istream.is_open();
}
}
-void BluetoothSnoopLogger::capture(const HciPacket& packet, Direction direction, PacketType type) {
+void SnoopLogger::capture(const HciPacket& packet, Direction direction, PacketType type) {
uint64_t timestamp_us =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch())
.count();
namespace bluetooth {
namespace hal {
-class BluetoothSnoopLogger {
+class SnoopLogger {
public:
- explicit BluetoothSnoopLogger(const std::string& filename);
+ explicit SnoopLogger(const std::string& filename);
enum class PacketType {
CMD = 1,