From a80d45b603e840c2903df1bd60a3f85db4ab9d20 Mon Sep 17 00:00:00 2001 From: Nicolas VIVIEN Date: Thu, 24 Nov 2011 20:48:21 -0500 Subject: [PATCH] Added IsAttachKernelDriver() API to USB wrappers --- src/usbwrap.h | 1 + src/usbwrap_libusb.cc | 17 +++++++++++++++++ src/usbwrap_libusb_1_0.cc | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/usbwrap.h b/src/usbwrap.h index 8e072a9e..c056ce72 100644 --- a/src/usbwrap.h +++ b/src/usbwrap.h @@ -273,6 +273,7 @@ public: bool SetConfiguration(unsigned char cfg); bool ClearHalt(int ep); bool Reset(); + bool IsAttachKernelDriver(int iface, std::string& name); bool DetachKernelDriver(int iface); ///////////////////////////// diff --git a/src/usbwrap_libusb.cc b/src/usbwrap_libusb.cc index db85cdb5..b00ebb8e 100644 --- a/src/usbwrap_libusb.cc +++ b/src/usbwrap_libusb.cc @@ -404,6 +404,23 @@ int Device::GetPowerLevel() return m_id.m_impl->m_dev->config[0].MaxPower; } +bool Device::IsAttachKernelDriver(int iface, std::string& name) +{ + int ret; + char buffer[64]; + + ret = usb_get_driver_np(m_handle->m_handle, iface, buffer, sizeof(buffer)); + if (ret == 0) { + dout("interface (" << m_handle->m_handle << ", 0x" << std::hex << iface + << ") already claimed by driver \"" << name << "\" " + << "attempting to detach it "); + name = buffer; + return true; + } + + return false; +} + // Requests that the kernel driver is detached, returning false on failure bool Device::DetachKernelDriver(int iface) { diff --git a/src/usbwrap_libusb_1_0.cc b/src/usbwrap_libusb_1_0.cc index a76ce140..c88ec3be 100644 --- a/src/usbwrap_libusb_1_0.cc +++ b/src/usbwrap_libusb_1_0.cc @@ -589,6 +589,23 @@ int Device::GetPowerLevel() return ret; } +bool Device::IsAttachKernelDriver(int iface, std::string& name) +{ + int ret; + char buffer[64]; + + ret = usb_get_driver_np(m_handle->m_handle, iface, buffer, sizeof(buffer)); + if (ret == 0) { + dout("interface (" << m_handle->m_handle << ", 0x" << std::hex << iface + << ") already claimed by driver \"" << name << "\" " + << "attempting to detach it "); + name = buffer; + return true; + } + + return false; +} + // Requests that the kernel driver is detached, returning false on failure bool Device::DetachKernelDriver(int iface) { -- 2.11.4.GIT