tr4mpass/include/exploit/dfu_proto.h
Moussa Ouallaf 9bd1a75b2d build(deps): fix pkg-config skew, libusb include, libplist/libirecovery drift
Sync PKGCONFIG_DEPS with Makefile (add libcurl); normalize
<libusb.h> include across 6 files; add compat shims for libplist
2.2/2.3 and libirecovery IRECV_SEND_OPT_DFU_NOTIFY_FINISH; add
pacman/zypper/apk installer branches; drop bogus info->pid read
in path_b_identity.c in favor of irecv_get_mode(). Extend the
mock libirecovery to expose irecv_get_mode() so the mock test
build keeps passing against the new call site. Add Makefile
compile canaries that emit -DTP_PLIST_HAS_MEM_FREE,
-DTP_PLIST_HAS_FMT_ARG, and -DTP_IRECV_HAS_NOTIFY_FINISH plus a
.build-flags diagnostic file consumed by tr4mpass doctor.

Files modified:
- Makefile
- start.sh
- start-helpers.sh
- include/compat/plist_compat.h (new)
- include/compat/libirecovery_compat.h (new)
- include/util/usb_helpers.h
- include/util/plist_helpers.h
- include/exploit/dfu_proto.h
- include/device/device.h
- include/device/usb_dfu.h
- include/activation/activation.h
- include/activation/record.h
- src/bypass/path_b_identity.c
- src/bypass/path_b.c
- src/bypass/path_a_ramdisk.c
- src/activation/session_online.c
- tests/mocks/mock_irecv_sym.c
- .gitignore

Closes: #70, #74, #67, #54, #51, #44, #21, #55, #31, #24, #19
2026-07-17 02:43:53 +02:00

116 lines
3.8 KiB
C

/* dfu_proto.h -- DFU protocol state machine for checkm8 exploit delivery */
#ifndef DFU_PROTO_H
#define DFU_PROTO_H
#include <stddef.h>
#include <stdint.h>
#include <libusb.h>
/* ------------------------------------------------------------------ */
/* DFU class-specific request codes (USB DFU 1.1 spec, Table 3.2) */
/* ------------------------------------------------------------------ */
#define DFU_REQ_DETACH 0x00
#define DFU_REQ_DNLOAD 0x01
#define DFU_REQ_UPLOAD 0x02
#define DFU_REQ_GETSTATUS 0x03
#define DFU_REQ_CLRSTATUS 0x04
#define DFU_REQ_GETSTATE 0x05
#define DFU_REQ_ABORT 0x06
/* ------------------------------------------------------------------ */
/* DFU state values (bState field in status response) */
/* ------------------------------------------------------------------ */
#define DFU_STATE_IDLE 0x02
#define DFU_STATE_DNLOAD_SYNC 0x03
#define DFU_STATE_DNBUSY 0x04
#define DFU_STATE_DNLOAD_IDLE 0x05
#define DFU_STATE_MANIFEST_SYNC 0x06
#define DFU_STATE_MANIFEST 0x07
#define DFU_STATE_MANIFEST_WAIT_RST 0x08
#define DFU_STATE_UPLOAD_IDLE 0x09
#define DFU_STATE_ERROR 0x0A
/* ------------------------------------------------------------------ */
/* DFU status values (bStatus field in status response) */
/* ------------------------------------------------------------------ */
#define DFU_STATUS_OK 0x00
#define DFU_STATUS_ERR_TARGET 0x01
#define DFU_STATUS_ERR_FILE 0x02
#define DFU_STATUS_ERR_WRITE 0x03
#define DFU_STATUS_ERR_UNKNOWN 0x07
#define DFU_STATUS_ERR_STALLED 0x0F
/* ------------------------------------------------------------------ */
/* DFU status structure */
/* ------------------------------------------------------------------ */
typedef struct {
uint8_t bStatus;
uint32_t bwPollTimeout; /* 3 bytes on wire, stored as uint32 */
uint8_t bState;
uint8_t iString;
} dfu_status_t;
/* ------------------------------------------------------------------ */
/* Protocol API */
/* ------------------------------------------------------------------ */
/*
* Query device status. Sends DFU_GETSTATUS and parses the 6-byte
* response into the dfu_status_t structure.
* Returns 0 on success, -1 on failure.
*/
int dfu_get_status(libusb_device_handle *dev, dfu_status_t *status);
/*
* Clear error status. Sends DFU_CLRSTATUS with no data stage.
* Returns 0 on success, -1 on failure.
*/
int dfu_clr_status(libusb_device_handle *dev);
/*
* Query current DFU state byte.
* Returns 0 on success, -1 on failure.
*/
int dfu_get_state(libusb_device_handle *dev, uint8_t *state);
/*
* Send a DFU_DNLOAD request with the given block number and data.
* A zero-length transfer (len=0) signals end of download.
* Returns 0 on success, -1 on failure.
*/
int dfu_dnload(libusb_device_handle *dev, uint16_t block_num,
const void *data, size_t len);
/*
* Send a DFU_UPLOAD request to read data from the device.
* On success, *actual is set to the number of bytes received.
* Returns 0 on success, -1 on failure.
*/
int dfu_upload(libusb_device_handle *dev, uint16_t block_num,
void *buf, size_t len, size_t *actual);
/*
* Abort the current DFU operation.
* Returns 0 on success, -1 on failure.
*/
int dfu_abort(libusb_device_handle *dev);
/*
* Send a data buffer via DFU_DNLOAD followed by a GETSTATUS poll.
* Returns 0 on success, -1 on failure.
*/
int dfu_send_data(libusb_device_handle *dev, const void *data, size_t len);
/*
* Reset the DFU state machine to dfuIDLE by clearing errors and
* aborting any in-progress operation.
* Returns 0 on success, -1 on failure.
*/
int dfu_reset_to_idle(libusb_device_handle *dev);
#endif /* DFU_PROTO_H */