From c2341ea006981f39a8bc2030412958a4fbe63743 Mon Sep 17 00:00:00 2001 From: hselasky Date: Mon, 6 Jan 2020 09:40:18 +0000 Subject: [PATCH] MFC r351146: Implement detach_kernel_driver command in usbconfig(8). Submitted by: Kevin Zheng PR: 239916 git-svn-id: svn://svn.freebsd.org/base/stable/10@356407 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/usbconfig/usbconfig.8 | 9 +++++++-- usr.sbin/usbconfig/usbconfig.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8 index e6cefc38c..60b337a09 100644 --- a/usr.sbin/usbconfig/usbconfig.8 +++ b/usr.sbin/usbconfig/usbconfig.8 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd April 29, 2018 +.Dd August 16, 2019 .Dt USBCONFIG 8 .Os .Sh NAME @@ -52,6 +52,9 @@ Should only be used in conjunction with the unit argument. .It Fl d Ar [ugen]. Limit device range to USB devices connected to the given unit and address. The unit and address coordinates may be prefixed by the lowercased word "ugen". +.It Fl i Ar interface_index +Specify interface index as indicated by the command description. +If this argument is not specified a value of zero will be used for the interface index. .It Fl h Show help and available commands. .El @@ -71,7 +74,7 @@ the interface drivers and reducing the power consumption to minimum, but without going into power saving mode or detaching from the bus. In some cases, it prevents the device from charging. .It Cm set_alt Ar alt_index -Choose the alternate interface for the USB device. +Choose the alternate interface for the selected interface and USB device. Alternative settings for the current configuration are available as the .Ar bAlternateSetting in @@ -119,6 +122,8 @@ Display the list of interface drivers (such as or .Xr u3g 4 ) currently attached to the device. +.It Cm detach_kernel_driver +Detach kernel driver for the selected interface and USB device. .It Cm suspend Force the device to suspend. .It Cm resume diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c index 9b02c0d5d..3a1f6d62d 100644 --- a/usr.sbin/usbconfig/usbconfig.c +++ b/usr.sbin/usbconfig/usbconfig.c @@ -87,6 +87,7 @@ struct options { uint8_t got_add_quirk:1; uint8_t got_dump_string:1; uint8_t got_do_request:1; + uint8_t got_detach_kernel_driver:1; }; struct token { @@ -109,6 +110,7 @@ enum { T_ADD_QUIRK, T_REMOVE_QUIRK, T_SHOW_IFACE_DRIVER, + T_DETACH_KERNEL_DRIVER, T_DUMP_QUIRK_NAMES, T_DUMP_DEVICE_QUIRKS, T_DUMP_ALL_DESC, @@ -142,6 +144,7 @@ static const struct token token[] = { {"remove_dev_quirk_vplh", T_REMOVE_DEVICE_QUIRK, 5}, {"add_quirk", T_ADD_QUIRK, 1}, {"remove_quirk", T_REMOVE_QUIRK, 1}, + {"detach_kernel_driver", T_DETACH_KERNEL_DRIVER, 0}, {"dump_quirk_names", T_DUMP_QUIRK_NAMES, 0}, {"dump_device_quirks", T_DUMP_DEVICE_QUIRKS, 0}, {"dump_all_desc", T_DUMP_ALL_DESC, 0}, @@ -282,6 +285,7 @@ usage(void) " remove_dev_quirk_vplh " "\n" " add_quirk " "\n" " remove_quirk " "\n" + " detach_kernel_driver" "\n" " dump_quirk_names" "\n" " dump_device_quirks" "\n" " dump_all_desc" "\n" @@ -490,6 +494,11 @@ flush_command(struct libusb20_backend *pbe, struct options *opt) err(1, "could not set power ON"); } } + if (opt->got_detach_kernel_driver) { + if (libusb20_dev_detach_kernel_driver(pdev, opt->iface)) { + err(1, "could not detach kernel driver"); + } + } dump_any = (opt->got_dump_all_desc || opt->got_dump_device_desc || @@ -609,6 +618,13 @@ main(int argc, char **argv) opt->got_any++; break; + case T_DETACH_KERNEL_DRIVER: + if (opt->got_detach_kernel_driver) + duplicate_option(argv[n]); + opt->got_detach_kernel_driver = 1; + opt->got_any++; + break; + case T_DUMP_QUIRK_NAMES: if (opt->got_dump_quirk_names) duplicate_option(argv[n]); -- 2.42.0