Skip to content

Commit 422d93c

Browse files
committed
Yet another workaround for HP LaserJet Enterprise M406 devices
Some HP LaserJet Enterprise M406 devices may return a current configuration value that does not match the bConfigurationValue of any existing configuration. This can happen if the device is not configured, or if the firmware returns an incorrect number for the current configuration. Unfortunately, I don't have more detailed information to investigate, though such investigation would have only academic value. As a workaround, we assume that if only one configuration exists, it is the current configuration, regardless of its bConfigurationValue.
1 parent 7500a47 commit 422d93c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

usbio_libusb.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,27 @@ func (devhandle *UsbDevHandle) currentInterfaces() ([]int, error) {
542542
return nil, UsbError{"libusb_get_configuration", UsbErrCode(rc)}
543543
}
544544

545+
// If bConfigurationValue matches the wanted configuration
546+
// value, we are done
545547
if conf.bConfigurationValue == C.uint8_t(config) {
546548
break
547549
}
548550

551+
// If we have only one configuration, we are done too.
552+
//
553+
// This may happen if the device is not configured, or if
554+
// the firmware returns an incorrect number for the current
555+
// configuration.
556+
//
557+
// This weird behavior has been seen in the wild for some
558+
// HP LaserJet Enterprise M406 devices. So, as a last resort,
559+
// assume that if only one configuration exists, it is the
560+
// current configuration, regardless of its bConfigurationValue.
561+
if cDesc.bNumConfigurations == 1 {
562+
break
563+
}
564+
565+
// Throw away mismatching configuration and continue
549566
C.libusb_free_config_descriptor(conf)
550567
conf = nil
551568
}

0 commit comments

Comments
 (0)