fix(#5): add USB retry logic for LIBUSB_ERROR_PIPE

Resolves #5: LIBUSB_ERROR_PIPE

Root cause: USB control transfers had zero retry logic. LIBUSB_ERROR_PIPE
(-9) is a transient STALL that commonly occurs on A12+ devices during DFU
operations and typically clears on retry. Additionally, path_b_identity.c
called libusb_control_transfer directly, bypassing the usb_helpers wrapper
entirely.

Changes:
- usb_ctrl_transfer/usb_ctrl_transfer_no_data now retry up to 3 times on
  PIPE and TIMEOUT errors with 50ms delay between attempts
- usb_print_error provides actionable troubleshooting steps for PIPE errors
- path_b_identity.c now uses usb_ctrl_transfer (retry-aware) instead of
  calling libusb_control_transfer directly
- usb_dfu_read_info adds retry logic for serial descriptor reads
- start.sh: handle_dfu_requirement now guides A12+ Path B devices into DFU
  (previously only guided checkm8 Path A devices)
- start.sh: DFU-mode detection now queries CPID to correctly identify
  Path A vs Path B (previously assumed all DFU devices were Path A)

Files modified:
- src/util/usb_helpers.c
- src/bypass/path_b_identity.c
- src/device/usb_dfu.c
- start.sh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-12 20:02:14 +02:00
parent 92e9f99f25
commit 58f04f2be0
4 changed files with 110 additions and 51 deletions

View file

@ -13,6 +13,7 @@
#include "bypass/path_b.h"
#include "device/usb_dfu.h"
#include "util/usb_helpers.h"
#include "util/log.h"
/* USB descriptor request types */
@ -44,7 +45,7 @@ static int usb_get_string_descriptor(libusb_device_handle *usb,
return -1;
}
rc = libusb_control_transfer(
rc = usb_ctrl_transfer(
usb,
0x80, /* bmRequestType */
USB_REQ_GET_DESCRIPTOR, /* bRequest */
@ -58,6 +59,7 @@ static int usb_get_string_descriptor(libusb_device_handle *usb,
if (rc < 0) {
log_error("[path_b_id] GET_DESCRIPTOR failed: %s",
libusb_error_name(rc));
usb_print_error(rc);
return -1;
}
@ -194,7 +196,7 @@ int path_b_write_serial(device_info_t *dev, const char *new_serial)
}
/* SET_DESCRIPTOR: host-to-device, standard, device recipient */
rc = libusb_control_transfer(
rc = usb_ctrl_transfer(
dev->usb,
0x00, /* bmRequestType */
USB_REQ_SET_DESCRIPTOR, /* bRequest */
@ -208,7 +210,7 @@ int path_b_write_serial(device_info_t *dev, const char *new_serial)
if (rc < 0) {
log_warn("[path_b_id] SET_DESCRIPTOR returned: %s",
libusb_error_name(rc));
/* TODO: fallback vendor-specific transfer for A12+ DFU firmware */
usb_print_error(rc);
return -1;
}