summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2013-12-19 10:24:11 +0100
committerBjørn Mork <bjorn@mork.no>2013-12-19 10:24:11 +0100
commit6e112265ec140927166bcfa8f5a34313a1746a27 (patch)
tree37c1bb7984a536e88796c2fb66f1bcc46612e104
parente1eaca38824a7550106e2e7f26ff013c445eabea (diff)
setconfig: unbind drivers
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rwxr-xr-xscripts/setconfig.pl23
1 files changed, 21 insertions, 2 deletions
diff --git a/scripts/setconfig.pl b/scripts/setconfig.pl
index eaf9125..0421f9c 100755
--- a/scripts/setconfig.pl
+++ b/scripts/setconfig.pl
@@ -34,7 +34,26 @@ die "Cannot find any such device: $opt{'device'} - $!\n" unless $dev;
warn "Device: ", sprintf("%04x:%04x", $dev->idVendor(), $dev->idProduct()), "\n";
$dev->open();
-my ($ret, $descr) = &set_config($dev, $opt{cfg});
+
+# unbind all drivers
+foreach my $cfg (@{$dev->config()}) {
+foreach (@{$cfg->interfaces()}) {
+ my $ifnum = $_->[0]->bInterfaceNumber;
+
+ my $driver = $dev->get_driver_np($ifnum);
+ if ($driver) {
+ warn "unbinding interface $ifnum from kernel driver \"$driver\"\n";
+ if ($dev->detach_kernel_driver_np($ifnum) < 0) {
+ warn "unbinding FAILED\n";
+ return undef;
+ }
+ }
+}
+}
+my $ret = $dev->set_configuration($opt{cfg});
+
+#my ($ret, $descr) = &set_config($dev, $opt{cfg});
+warn "ret=$ret\n";
sub set_config {
my ($dev, $cfg) = @_;
@@ -42,7 +61,7 @@ sub set_config {
my $req = 0x09; # USB_REQ_SET_CONFIGURATION
my $wValue = 0x0;
- return (-1, undef) unless $cfg;
+ return (-1, undef) unless defined($cfg);
my $buf = 0 x 512; # pre-allocate buffer - libusb is not perl!
my $ret = $dev->control_msg($reqtype,