feat: libusb backend

This commit is contained in:
CLARATION committed 2026-06-22 18:19:25 -07:00
1 parent 2914030e65
commit d8154c3aeb
16 files changed
+1701 -402

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
#include "dfu.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#ifndef __APPLE__
# include "usb-libusb.h"
#endif
#include "payload.h"
bool dfu_check_status(const usb_handle_t *handle, uint8_t status, uint8_t state) {
struct {
uint8_t status, poll_timeout[3], state, str_idx;
} dfu_status;
transfer_ret_t transfer_ret;
return send_usb_control_request(handle, 0xA1, DFU_GETSTATUS, 0, 0, &dfu_status, sizeof(dfu_status), &transfer_ret)
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == sizeof(dfu_status)
&& dfu_status.status == status && dfu_status.state == state;
}
bool dfu_device_set_await_reset(const usb_handle_t *handle) {
transfer_ret_t transfer_ret;
return send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, 0, &transfer_ret)
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == 0
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST_SYNC)
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST)
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST_WAIT_RESET);
}
int dfu_serial_number_get_cpid(char *serial) {
char *cpid = strstr(serial, "CPID:");
if (cpid == NULL) { return -1; }
return strtol(cpid + 5, NULL, 16);
}
int dfu_serial_number_get_bdid(char *serial) {
char *bdid = strstr(serial, "BDID:");
if (bdid == NULL) { return -1; }
return strtol(bdid + 5, NULL, 16);
}
bool dfu_serial_number_is_in_dfu_mode(char *serial) {
char *DFU = strstr(serial, "SRTG");
return DFU != NULL;
}
bool dfu_serial_number_is_pwned(char *serial) {
char *pwnd = strstr(serial, "PWND:");
return pwnd != NULL;
}
bool dfu_serial_number_is_in_yolo_dfu(char *serial) {
char *yolo = strstr(serial, "YOLO");
return yolo != NULL;
}
bool device_serial_number_is_in_pongo_os(char *serial) {
char *pongo = strstr(serial, "SRTG:[PongoOS");
return pongo != NULL;
}