Retire the three hardcoded DFU_SERIAL_INDEX = 3 constants in usb_dfu.c, path_b_identity.c, and checkm8_internal.h. usb_dfu_find() now captures bDeviceDescriptor.iSerialNumber into device_info_t and usb_dfu_read_info() iterates hint -> 3 -> 4 with the sentinel check deferred until every probe has returned only the product string. The checkm8 spray helpers accept the resolved index as a parameter, and the CLI override log fires whenever --cpid/--ecid populated a field the descriptor read could not, so A14/A15/A16 devices no longer strand users on the false NOT-in-SecureROM-DFU diagnostic. Files modified: - include/device/device.h - include/device/usb_dfu.h - include/exploit/checkm8_internal.h - src/bypass/path_b_identity.c - src/device/usb_dfu.c - src/exploit/checkm8.c - src/exploit/checkm8_spray.c - src/main.c - tests/mocks/mock_hw_stubs.c Closes: #45, #65, #59, #27, #17, #52, #30, #22, #25, #10, #8, #6, #7
88 lines
2.8 KiB
C
88 lines
2.8 KiB
C
#ifndef USB_DFU_H
|
|
#define USB_DFU_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <libusb.h>
|
|
|
|
/* Apple USB identifiers */
|
|
#define APPLE_VID 0x05AC
|
|
#define DFU_PID 0x1227
|
|
#define RECOVERY_PID 0x1281
|
|
|
|
/* DFU class-specific requests */
|
|
#define DFU_DNLOAD 1
|
|
#define DFU_UPLOAD 2
|
|
#define DFU_GETSTATUS 3
|
|
#define DFU_CLRSTATUS 4
|
|
#define DFU_ABORT 6
|
|
|
|
/* Default USB timeout in milliseconds */
|
|
#define DFU_USB_TIMEOUT 5000
|
|
|
|
/* Maximum serial string length from DFU descriptor */
|
|
#define DFU_SERIAL_MAX 256
|
|
|
|
/*
|
|
* Initialize the libusb context. Call once at startup.
|
|
* Returns 0 on success, -1 on failure.
|
|
*/
|
|
int usb_dfu_init(void);
|
|
|
|
/*
|
|
* Clean up the libusb context. Call once at shutdown.
|
|
*/
|
|
void usb_dfu_cleanup(void);
|
|
|
|
/*
|
|
* Find an Apple device in DFU mode (VID=0x05AC, PID=0x1227).
|
|
* On success, *handle is set to an opened device handle and 0 is
|
|
* returned. On failure, *handle is set to NULL and -1 is returned.
|
|
*
|
|
* If iserial_out is non-NULL, the device's bDeviceDescriptor.iSerialNumber
|
|
* (the actual USB string index that carries CPID/ECID) is written to it.
|
|
* A value of 0 means the descriptor did not advertise a serial index --
|
|
* usb_dfu_read_info() will fall back through the legacy probe order.
|
|
*/
|
|
int usb_dfu_find(libusb_device_handle **handle, uint8_t *iserial_out);
|
|
|
|
/*
|
|
* Read device info from the DFU serial string descriptor.
|
|
* Parses CPID and ECID as hex values from the key:value pairs.
|
|
* Copies the full serial string to serial (up to serial_len bytes).
|
|
* Missing fields are set to 0 / empty string.
|
|
*
|
|
* iserial_hint is the index reported by bDeviceDescriptor.iSerialNumber
|
|
* (usually populated by usb_dfu_find). Pass 0 when the caller has no
|
|
* hint; the function will still try the legacy indices 3 and 4.
|
|
* The read attempts, in order: (a) iserial_hint if non-zero,
|
|
* (b) 3 (pre-A9 default), (c) 4 (A14+ default). Duplicate indices are
|
|
* skipped. The "device is not in SecureROM DFU" sentinel is only
|
|
* raised when every probe returned the product string.
|
|
*
|
|
* Returns 0 on success, -1 on failure.
|
|
*/
|
|
int usb_dfu_read_info(libusb_device_handle *handle, uint8_t iserial_hint,
|
|
uint32_t *cpid, uint64_t *ecid,
|
|
char *serial, size_t serial_len);
|
|
|
|
/*
|
|
* Send data to the DFU device via control transfer (DFU_DNLOAD).
|
|
* Returns 0 on success, -1 on failure.
|
|
*/
|
|
int usb_dfu_send(libusb_device_handle *handle, const void *data, size_t len);
|
|
|
|
/*
|
|
* Receive data from the DFU device via control transfer (DFU_UPLOAD).
|
|
* On success, *actual is set to the number of bytes received and 0 is returned.
|
|
* On failure, *actual is set to 0 and -1 is returned.
|
|
*/
|
|
int usb_dfu_recv(libusb_device_handle *handle, void *buf, size_t len,
|
|
size_t *actual);
|
|
|
|
/*
|
|
* Close and release the DFU device handle.
|
|
*/
|
|
void usb_dfu_close(libusb_device_handle *handle);
|
|
|
|
#endif /* USB_DFU_H */
|