Automatically detach/reattach bluetooth driver in passthrough

When the bluetooth adapter device is opened/closed by dolphin, the
kernel driver is automatically detached/reattached.

This enables transparent sharing of the same bluetooth wiimotes and
bluetooth adapters between the hosts system and the emulated one using
the same.
This commit is contained in:
Gabriel Corona 2019-06-18 00:27:33 +02:00
parent b3525ad774
commit 70bca53ed6
1 changed files with 9 additions and 4 deletions

View File

@ -555,12 +555,17 @@ bool BluetoothReal::OpenDevice(libusb_device* device)
// Detaching always fails as a regular user on FreeBSD // Detaching always fails as a regular user on FreeBSD
// https://lists.freebsd.org/pipermail/freebsd-usb/2016-March/014161.html // https://lists.freebsd.org/pipermail/freebsd-usb/2016-March/014161.html
#ifndef __FreeBSD__ #ifndef __FreeBSD__
const int result = libusb_detach_kernel_driver(m_handle, INTERFACE); int result = libusb_set_auto_detach_kernel_driver(m_handle, 1);
if (result != 0)
{
result = libusb_detach_kernel_driver(m_handle, INTERFACE);
if (result < 0 && result != LIBUSB_ERROR_NOT_FOUND && result != LIBUSB_ERROR_NOT_SUPPORTED) if (result < 0 && result != LIBUSB_ERROR_NOT_FOUND && result != LIBUSB_ERROR_NOT_SUPPORTED)
{ {
PanicAlertT("Failed to detach kernel driver for BT passthrough: %s", libusb_error_name(result)); PanicAlertT("Failed to detach kernel driver for BT passthrough: %s",
libusb_error_name(result));
return false; return false;
} }
}
#endif #endif
if (libusb_claim_interface(m_handle, INTERFACE) < 0) if (libusb_claim_interface(m_handle, INTERFACE) < 0)
{ {