Loading system/vendor_libs/test_vendor_lib/desktop/test_environment.cc +1 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ void TestEnvironment::SetUpTestChannel() { int socket_fd = test_channel_transport_.SetUp(test_port_); test_channel_.AddPhy({"BR_EDR"}); test_channel_.AddPhy({"LOW_ENERGY"}); test_channel_.SetTimerPeriod({"100"}); test_channel_.SetTimerPeriod({"10"}); test_channel_.StartTimer({}); test_channel_.RegisterSendResponse( Loading system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc +5 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,11 @@ void DualModeController::Initialize(const std::vector<std::string>& args) { if (args.size() < 2) return; Address addr; if (Address::FromString(args[1], addr)) properties_.SetAddress(addr); if (Address::FromString(args[1], addr)) { properties_.SetAddress(addr); } else { LOG_FATAL(LOG_TAG, "Invalid address: %s", args[1].c_str()); } }; std::string DualModeController::GetTypeString() const { Loading system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.cc +23 −14 Original line number Diff line number Diff line Loading @@ -52,9 +52,16 @@ size_t H4Packetizer::HciGetPacketLengthForType(hci::PacketType type, const uint8 return (((preamble[offset + 1]) << 8) | preamble[offset]); } H4Packetizer::H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb) : uart_fd_(fd), command_cb_(command_cb), event_cb_(event_cb), acl_cb_(acl_cb), sco_cb_(sco_cb) {} H4Packetizer::H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb, ClientDisconnectCallback disconnect_cb) : uart_fd_(fd), command_cb_(command_cb), event_cb_(event_cb), acl_cb_(acl_cb), sco_cb_(sco_cb), disconnect_cb_(disconnect_cb) {} size_t H4Packetizer::Send(uint8_t type, const uint8_t* data, size_t length) { struct iovec iov[] = {{&type, sizeof(type)}, {const_cast<uint8_t*>(data), length}}; Loading Loading @@ -98,20 +105,22 @@ void H4Packetizer::OnDataReady(int fd) { if (hci_packet_type_ == hci::PacketType::UNKNOWN) { uint8_t buffer[1] = {0}; ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, 1)); if (bytes_read != 1) { if (bytes_read == 0) { ALOGI("%s: Nothing ready, will retry!", __func__); ALOGI("%s: remote disconnected!", __func__); disconnect_cb_(); return; } else if (bytes_read < 0) { if (errno == EAGAIN) { // No data, try again later. ALOGV("%s: Nothing ready, will retry!", __func__); return; } else { LOG_ALWAYS_FATAL("%s: Read packet type error: %s", __func__, strerror(errno)); } } else { LOG_ALWAYS_FATAL("%s: More bytes read than expected (%u)!", __func__, static_cast<unsigned int>(bytes_read)); LOG_ALWAYS_FATAL("%s: Read packet type error: %s", __func__, strerror(errno)); } } else if (bytes_read > 1) { LOG_ALWAYS_FATAL("%s: More bytes read than expected (%u)!", __func__, static_cast<unsigned int>(bytes_read)); } hci_packet_type_ = static_cast<hci::PacketType>(buffer[0]); if (hci_packet_type_ != hci::PacketType::ACL && hci_packet_type_ != hci::PacketType::SCO && Loading system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.h +7 −2 Original line number Diff line number Diff line Loading @@ -26,11 +26,14 @@ namespace test_vendor_lib { namespace hci { using HciPacketReadyCallback = std::function<void(void)>; using ClientDisconnectCallback = std::function<void()>; class H4Packetizer : public HciProtocol { public: H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb); H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb, ClientDisconnectCallback disconnect_cb); size_t Send(uint8_t type, const uint8_t* data, size_t length); Loading @@ -46,6 +49,8 @@ class H4Packetizer : public HciProtocol { PacketReadCallback acl_cb_; PacketReadCallback sco_cb_; ClientDisconnectCallback disconnect_cb_; hci::PacketType hci_packet_type_{hci::PacketType::UNKNOWN}; // 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1) Loading system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.cc +12 −1 Original line number Diff line number Diff line Loading @@ -81,7 +81,9 @@ HciSocketDevice::HciSocketDevice(int file_descriptor) : socket_file_descriptor_( std::shared_ptr<std::vector<uint8_t>> packet_copy = std::make_shared<std::vector<uint8_t>>(raw_command); HandleCommand(packet_copy); }, [](const std::vector<uint8_t>&) { CHECK(false) << "Unexpected Event in HciSocketDevice!"; }, [](const std::vector<uint8_t>&) { CHECK(false) << "Unexpected Event in HciSocketDevice!"; }, [this](const std::vector<uint8_t>& raw_acl) { LOG_INFO(LOG_TAG, "Rx ACL"); std::shared_ptr<std::vector<uint8_t>> packet_copy = std::make_shared<std::vector<uint8_t>>(raw_acl); Loading @@ -91,6 +93,10 @@ HciSocketDevice::HciSocketDevice(int file_descriptor) : socket_file_descriptor_( LOG_INFO(LOG_TAG, "Rx SCO"); std::shared_ptr<std::vector<uint8_t>> packet_copy = std::make_shared<std::vector<uint8_t>>(raw_sco); HandleSco(packet_copy); }, [this]() { LOG_INFO(LOG_TAG, "HCI socket device disconnected"); close_callback_(); }); RegisterEventChannel([this](std::shared_ptr<std::vector<uint8_t>> packet) { Loading Loading @@ -130,4 +136,9 @@ void HciSocketDevice::SendHci(hci::PacketType packet_type, const std::shared_ptr } } void HciSocketDevice::RegisterCloseCallback( std::function<void()> close_callback) { close_callback_ = close_callback; } } // namespace test_vendor_lib Loading
system/vendor_libs/test_vendor_lib/desktop/test_environment.cc +1 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ void TestEnvironment::SetUpTestChannel() { int socket_fd = test_channel_transport_.SetUp(test_port_); test_channel_.AddPhy({"BR_EDR"}); test_channel_.AddPhy({"LOW_ENERGY"}); test_channel_.SetTimerPeriod({"100"}); test_channel_.SetTimerPeriod({"10"}); test_channel_.StartTimer({}); test_channel_.RegisterSendResponse( Loading
system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc +5 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,11 @@ void DualModeController::Initialize(const std::vector<std::string>& args) { if (args.size() < 2) return; Address addr; if (Address::FromString(args[1], addr)) properties_.SetAddress(addr); if (Address::FromString(args[1], addr)) { properties_.SetAddress(addr); } else { LOG_FATAL(LOG_TAG, "Invalid address: %s", args[1].c_str()); } }; std::string DualModeController::GetTypeString() const { Loading
system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.cc +23 −14 Original line number Diff line number Diff line Loading @@ -52,9 +52,16 @@ size_t H4Packetizer::HciGetPacketLengthForType(hci::PacketType type, const uint8 return (((preamble[offset + 1]) << 8) | preamble[offset]); } H4Packetizer::H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb) : uart_fd_(fd), command_cb_(command_cb), event_cb_(event_cb), acl_cb_(acl_cb), sco_cb_(sco_cb) {} H4Packetizer::H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb, ClientDisconnectCallback disconnect_cb) : uart_fd_(fd), command_cb_(command_cb), event_cb_(event_cb), acl_cb_(acl_cb), sco_cb_(sco_cb), disconnect_cb_(disconnect_cb) {} size_t H4Packetizer::Send(uint8_t type, const uint8_t* data, size_t length) { struct iovec iov[] = {{&type, sizeof(type)}, {const_cast<uint8_t*>(data), length}}; Loading Loading @@ -98,20 +105,22 @@ void H4Packetizer::OnDataReady(int fd) { if (hci_packet_type_ == hci::PacketType::UNKNOWN) { uint8_t buffer[1] = {0}; ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, 1)); if (bytes_read != 1) { if (bytes_read == 0) { ALOGI("%s: Nothing ready, will retry!", __func__); ALOGI("%s: remote disconnected!", __func__); disconnect_cb_(); return; } else if (bytes_read < 0) { if (errno == EAGAIN) { // No data, try again later. ALOGV("%s: Nothing ready, will retry!", __func__); return; } else { LOG_ALWAYS_FATAL("%s: Read packet type error: %s", __func__, strerror(errno)); } } else { LOG_ALWAYS_FATAL("%s: More bytes read than expected (%u)!", __func__, static_cast<unsigned int>(bytes_read)); LOG_ALWAYS_FATAL("%s: Read packet type error: %s", __func__, strerror(errno)); } } else if (bytes_read > 1) { LOG_ALWAYS_FATAL("%s: More bytes read than expected (%u)!", __func__, static_cast<unsigned int>(bytes_read)); } hci_packet_type_ = static_cast<hci::PacketType>(buffer[0]); if (hci_packet_type_ != hci::PacketType::ACL && hci_packet_type_ != hci::PacketType::SCO && Loading
system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.h +7 −2 Original line number Diff line number Diff line Loading @@ -26,11 +26,14 @@ namespace test_vendor_lib { namespace hci { using HciPacketReadyCallback = std::function<void(void)>; using ClientDisconnectCallback = std::function<void()>; class H4Packetizer : public HciProtocol { public: H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb); H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb, ClientDisconnectCallback disconnect_cb); size_t Send(uint8_t type, const uint8_t* data, size_t length); Loading @@ -46,6 +49,8 @@ class H4Packetizer : public HciProtocol { PacketReadCallback acl_cb_; PacketReadCallback sco_cb_; ClientDisconnectCallback disconnect_cb_; hci::PacketType hci_packet_type_{hci::PacketType::UNKNOWN}; // 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1) Loading
system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.cc +12 −1 Original line number Diff line number Diff line Loading @@ -81,7 +81,9 @@ HciSocketDevice::HciSocketDevice(int file_descriptor) : socket_file_descriptor_( std::shared_ptr<std::vector<uint8_t>> packet_copy = std::make_shared<std::vector<uint8_t>>(raw_command); HandleCommand(packet_copy); }, [](const std::vector<uint8_t>&) { CHECK(false) << "Unexpected Event in HciSocketDevice!"; }, [](const std::vector<uint8_t>&) { CHECK(false) << "Unexpected Event in HciSocketDevice!"; }, [this](const std::vector<uint8_t>& raw_acl) { LOG_INFO(LOG_TAG, "Rx ACL"); std::shared_ptr<std::vector<uint8_t>> packet_copy = std::make_shared<std::vector<uint8_t>>(raw_acl); Loading @@ -91,6 +93,10 @@ HciSocketDevice::HciSocketDevice(int file_descriptor) : socket_file_descriptor_( LOG_INFO(LOG_TAG, "Rx SCO"); std::shared_ptr<std::vector<uint8_t>> packet_copy = std::make_shared<std::vector<uint8_t>>(raw_sco); HandleSco(packet_copy); }, [this]() { LOG_INFO(LOG_TAG, "HCI socket device disconnected"); close_callback_(); }); RegisterEventChannel([this](std::shared_ptr<std::vector<uint8_t>> packet) { Loading Loading @@ -130,4 +136,9 @@ void HciSocketDevice::SendHci(hci::PacketType packet_type, const std::shared_ptr } } void HciSocketDevice::RegisterCloseCallback( std::function<void()> close_callback) { close_callback_ = close_callback; } } // namespace test_vendor_lib