From e89ca790593c45fb257b0df215c6721ebe038f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 24 Oct 2016 22:15:41 +0200 Subject: [PATCH] Disable Bluetooth descriptor check if adapter is forced Some adapters don't have the correct interface class, so they are not recognised as Bluetooth adapters. It seems that apart from hardcoding VIDs/PIDs (which is how it's done in the Linux kernel, and which I'm not very fond of), there is no other way to detect if a device is a Bluetooth adapter or not. This change makes Dolphin skip the descriptor check when trying to find a usable adapter for Bluetooth Passthrough if the use of a specific adapter was forced; it is assumed that the user knows what they are doing if they hand-edited their config file. This allows such adapters to be used. --- .../WII_IPC_HLE_Device_usb_bt_real.cpp | 19 ++++++++++++++----- .../IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h | 2 -- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.cpp index 9aa5785f4f..6239dae948 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.cpp @@ -36,7 +36,7 @@ static void EnqueueReply(const u32 command_address) WII_IPC_HLE_Interface::EnqueueReply(command_address, 0, CoreTiming::FromThread::ANY); } -static bool IsWantedDevice(libusb_device_descriptor& descriptor) +static bool IsWantedDevice(const libusb_device_descriptor& descriptor) { const int vid = SConfig::GetInstance().m_bt_passthrough_vid; const int pid = SConfig::GetInstance().m_bt_passthrough_pid; @@ -45,6 +45,18 @@ static bool IsWantedDevice(libusb_device_descriptor& descriptor) return descriptor.idVendor == vid && descriptor.idProduct == pid; } +static bool IsBluetoothDevice(const libusb_interface_descriptor& descriptor) +{ + constexpr u8 SUBCLASS = 0x01; + constexpr u8 PROTOCOL_BLUETOOTH = 0x01; + if (SConfig::GetInstance().m_bt_passthrough_vid != -1 && + SConfig::GetInstance().m_bt_passthrough_pid != -1) + return true; + return descriptor.bInterfaceClass == LIBUSB_CLASS_WIRELESS && + descriptor.bInterfaceSubClass == SUBCLASS && + descriptor.bInterfaceProtocol == PROTOCOL_BLUETOOTH; +} + CWII_IPC_HLE_Device_usb_oh1_57e_305_real::CWII_IPC_HLE_Device_usb_oh1_57e_305_real( u32 device_id, const std::string& device_name) : CWII_IPC_HLE_Device_usb_oh1_57e_305_base(device_id, device_name) @@ -94,10 +106,7 @@ IPCCommandResult CWII_IPC_HLE_Device_usb_oh1_57e_305_real::Open(u32 command_addr const libusb_interface& interface = config_descriptor->interface[INTERFACE]; const libusb_interface_descriptor& descriptor = interface.altsetting[0]; - if (descriptor.bInterfaceClass == LIBUSB_CLASS_WIRELESS && - descriptor.bInterfaceSubClass == SUBCLASS && - descriptor.bInterfaceProtocol == PROTOCOL_BLUETOOTH && IsWantedDevice(device_descriptor) && - OpenDevice(device)) + if (IsBluetoothDevice(descriptor) && IsWantedDevice(device_descriptor) && OpenDevice(device)) { unsigned char manufacturer[50] = {}, product[50] = {}, serial_number[50] = {}; libusb_get_string_descriptor_ascii(m_handle, device_descriptor.iManufacturer, manufacturer, diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h index 3bab9db86b..fd2e172e57 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_real.h @@ -50,8 +50,6 @@ public: private: static constexpr u8 INTERFACE = 0x00; - static constexpr u8 SUBCLASS = 0x01; - static constexpr u8 PROTOCOL_BLUETOOTH = 0x01; // Arbitrarily chosen value that allows emulated software to send commands often enough // so that the sync button event is triggered at least every 200ms. // Ideally this should be equal to 0, so we don't trigger unnecessary libusb transfers.