Skip to content

fix: skip DFU runtime interfaces when scanning for devices - #15

Merged
raphaelcoeffic merged 2 commits into
mainfrom
fix/skip-runtime-dfu-interfaces
Nov 21, 2026
Merged

raphaelcoeffic merged 2 commits into
mainfrom
fix/skip-runtime-dfu-interfaces

Conversation

@raphaelcoeffic

@raphaelcoeffic raphaelcoeffic commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Alternative to #14, which reports the same bug: while scanning, rdfu fails entirely because it can't open a device unrelated to the one being flashed.

Problem

is_dfu_device matches on class and subclass only, so any device with a DFU runtime interface (protocol 1) gets opened during the scan. These are often ordinary peripherals in normal operation. If the user has no permission to open one, the whole search fails with errno 13.

Changes

  • Skip runtime interfaces, both when selecting devices to open and when collecting a device's interfaces. There is no DFU_DETACH code path here, so a runtime interface couldn't be used anyway. Protocol 0 is still accepted, for DFU 1.0 devices.
  • Name the device when an open fails. A new DfuError::Open variant carries the VID:PID, so the CLI and C++ callers both see it, for example Unable to open 30C9:00F3: failed to open device (errno 13). This adds a variant to the public DfuError enum, which affects any external Rust code matching on it exhaustively.

Why not skip devices that fail to open?

#14 logs the failure and carries on. Open errors stay fatal here because a failure on a device in DFU mode matters:

  • Wrong board: with two boards attached and one failing to open, get_dfu_device would see a single device, pass the ManyDFUDevices check and flash the other board. The reconnect paths could pick the wrong board the same way.
  • Misleading result: a permission problem would be reported as "No DFU device", and rdfu list would exit 0.

Behaviour changes

  • rdfu list and the C++ device list no longer show devices that only have a runtime interface.
  • If a device in DFU mode can't be opened, the scan still fails, but the error now names it. --vendor/--product can exclude it, because that filter is applied before any device is opened.

Testing

  • cargo fmt --check, cargo clippy --workspace --all-targets and cargo test pass on macOS.
  • Added a unit test for the interface predicate.
  • Not tested on hardware. No DFU device was attached, and rdfu list only reported "No DFU device found".

Still to confirm

The device in #14 (30C9:00F3) is assumed to expose a runtime interface, because it passes the current filter but is described as unrelated. Its lsusb -v output would confirm that. If it reports protocol 0 or 2 instead, the scan will still fail on it, with an error naming the device.

Devices exposing a DFU runtime interface were opened during the scan,
so one the user has no permission to access failed the whole search.
Runtime interfaces cannot be used without a detach, which is not
supported, so ignore them.

Keep open failures fatal for devices in DFU mode, as skipping them
could bypass the multiple device check and flash the wrong board, but
log which device failed.
Logging is not visible to C++ callers, as the library installs no
logger. Report the device in the error itself instead, so that every
front end shows which one failed.
@raphaelcoeffic
raphaelcoeffic force-pushed the fix/skip-runtime-dfu-interfaces branch from 78347f9 to 5f31f75 Compare November 21, 2026 07:38
@raphaelcoeffic
raphaelcoeffic merged commit 2001f5e into main Nov 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant