Be more careful about USB memory errors
This commit is contained in:
Vendored
+3
@@ -19,6 +19,9 @@ ddrhook1.standard_def=false
|
|||||||
# Use 15 kHz monitor mode
|
# Use 15 kHz monitor mode
|
||||||
ddrhook1.use_15khz=false
|
ddrhook1.use_15khz=false
|
||||||
|
|
||||||
|
# Enable USB memory data emulation
|
||||||
|
ddrhook1.usbmem_enabled=false
|
||||||
|
|
||||||
# Specify path for USB memory data
|
# Specify path for USB memory data
|
||||||
ddrhook1.usbmem_path=usbmem
|
ddrhook1.usbmem_path=usbmem
|
||||||
|
|
||||||
|
|||||||
Vendored
+3
@@ -19,6 +19,9 @@ ddrhook1.standard_def=false
|
|||||||
# Use 15 kHz monitor mode
|
# Use 15 kHz monitor mode
|
||||||
ddrhook1.use_15khz=false
|
ddrhook1.use_15khz=false
|
||||||
|
|
||||||
|
# Enable USB memory data emulation
|
||||||
|
ddrhook1.usbmem_enabled=false
|
||||||
|
|
||||||
# Specify path for USB memory data
|
# Specify path for USB memory data
|
||||||
ddrhook1.usbmem_path=usbmem
|
ddrhook1.usbmem_path=usbmem
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ static HANDLE usbmem_fd;
|
|||||||
static char usbmem_response[USBMEM_DATA_BUF_SIZE];
|
static char usbmem_response[USBMEM_DATA_BUF_SIZE];
|
||||||
static bool usbmem_pending;
|
static bool usbmem_pending;
|
||||||
static size_t usbmem_response_length;
|
static size_t usbmem_response_length;
|
||||||
|
static bool usbmem_enabled;
|
||||||
|
|
||||||
static HRESULT usbmem_open(struct irp *irp);
|
static HRESULT usbmem_open(struct irp *irp);
|
||||||
static HRESULT usbmem_close(struct irp *irp);
|
static HRESULT usbmem_close(struct irp *irp);
|
||||||
@@ -44,6 +45,7 @@ typedef enum {
|
|||||||
struct USBMEM_STATE {
|
struct USBMEM_STATE {
|
||||||
bool connected;
|
bool connected;
|
||||||
bool opened;
|
bool opened;
|
||||||
|
bool errored;
|
||||||
USBMEM_FILE_TYPE file_type;
|
USBMEM_FILE_TYPE file_type;
|
||||||
|
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
@@ -73,7 +75,7 @@ static void usbmem_reset_file_state(int port)
|
|||||||
usbmem_state[port].file_type = USBMEM_FILE_TYPE_NONE;
|
usbmem_state[port].file_type = USBMEM_FILE_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbmem_init(const char *path)
|
void usbmem_init(const char *path, const bool enabled)
|
||||||
{
|
{
|
||||||
log_assert(usbmem_fd == NULL);
|
log_assert(usbmem_fd == NULL);
|
||||||
|
|
||||||
@@ -85,20 +87,24 @@ void usbmem_init(const char *path)
|
|||||||
log_fatal("Opening nul fd failed: %08lx", hr);
|
log_fatal("Opening nul fd failed: %08lx", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usbmem_enabled = enabled;
|
||||||
|
|
||||||
GetFullPathNameA(path, sizeof(usb_data_path), usb_data_path, NULL);
|
GetFullPathNameA(path, sizeof(usb_data_path), usb_data_path, NULL);
|
||||||
log_misc("USB memory data path: %s", usb_data_path);
|
log_misc("USB memory data path: %s", usb_data_path);
|
||||||
|
|
||||||
|
if (!path_exists(usb_data_path)) {
|
||||||
|
log_warning("USB memory data path does not exist, disabling");
|
||||||
|
usbmem_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
target_device_id = -1;
|
target_device_id = -1;
|
||||||
for (int i = 0; i < USBMEM_DEVICE_COUNT; i++) {
|
for (int i = 0; i < USBMEM_DEVICE_COUNT; i++) {
|
||||||
char subpath[MAX_PATH];
|
char subpath[MAX_PATH];
|
||||||
snprintf(subpath, sizeof(subpath), "%s\\p%d", usb_data_path, i + 1);
|
snprintf(subpath, sizeof(subpath), "%s\\p%d", usb_data_path, i + 1);
|
||||||
|
|
||||||
if (!path_exists(subpath)) {
|
|
||||||
path_mkdir(subpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
usbmem_state[i].connected = false;
|
usbmem_state[i].connected = false;
|
||||||
usbmem_state[i].opened = false;
|
usbmem_state[i].opened = false;
|
||||||
|
usbmem_state[i].errored = false;
|
||||||
memset(usbmem_state[i].path, 0, sizeof(usbmem_state[i].path));
|
memset(usbmem_state[i].path, 0, sizeof(usbmem_state[i].path));
|
||||||
memset(usbmem_state[i].filename, 0, sizeof(usbmem_state[i].filename));
|
memset(usbmem_state[i].filename, 0, sizeof(usbmem_state[i].filename));
|
||||||
usbmem_reset_file_state(i);
|
usbmem_reset_file_state(i);
|
||||||
@@ -231,6 +237,13 @@ static HRESULT usbmem_write(struct irp *irp)
|
|||||||
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
|
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
|
||||||
} else if (target_device_id < 0 || target_device_id >= USBMEM_DEVICE_COUNT) {
|
} else if (target_device_id < 0 || target_device_id >= USBMEM_DEVICE_COUNT) {
|
||||||
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
|
str_cpy(usbmem_response, sizeof(usbmem_response), "fail");
|
||||||
|
} else if ((target_device_val == 'a' || target_device_val == 'b') && usbmem_state[target_device_id].errored) {
|
||||||
|
// If the device went through the entire process once and the file didn't exist
|
||||||
|
// then just force it to be disabled because otherwise it'll get stuck in a loop.
|
||||||
|
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
|
||||||
|
} else if (!usbmem_enabled) {
|
||||||
|
// Ignore all other USB device specific commands and pretend a device isn't plugged in.
|
||||||
|
str_cpy(usbmem_response, sizeof(usbmem_response), "not connected");
|
||||||
} else if (str_eq(request, "on_a") || str_eq(request, "on_b")) {
|
} else if (str_eq(request, "on_a") || str_eq(request, "on_b")) {
|
||||||
usbmem_state[target_device_id].connected = true;
|
usbmem_state[target_device_id].connected = true;
|
||||||
usbmem_reset_file_state(target_device_id);
|
usbmem_reset_file_state(target_device_id);
|
||||||
@@ -282,7 +295,7 @@ static HRESULT usbmem_write(struct irp *irp)
|
|||||||
|
|
||||||
if (!path_exists(temp)) {
|
if (!path_exists(temp)) {
|
||||||
log_warning("Couldn't find path %s\n", temp);
|
log_warning("Couldn't find path %s\n", temp);
|
||||||
str_cpy(usbmem_response, sizeof(usbmem_response), "not exist");
|
str_cpy(usbmem_response, sizeof(usbmem_response), "done");
|
||||||
} else {
|
} else {
|
||||||
log_misc("Changing path to %s\n", temp);
|
log_misc("Changing path to %s\n", temp);
|
||||||
str_cpy(usbmem_state[target_device_id].path, sizeof(usbmem_state[target_device_id].path), temp);
|
str_cpy(usbmem_state[target_device_id].path, sizeof(usbmem_state[target_device_id].path), temp);
|
||||||
@@ -316,6 +329,9 @@ static HRESULT usbmem_write(struct irp *irp)
|
|||||||
if (!path_exists(temp)) {
|
if (!path_exists(temp)) {
|
||||||
log_warning("Couldn't find file %s\n", temp);
|
log_warning("Couldn't find file %s\n", temp);
|
||||||
str_cpy(usbmem_response, sizeof(usbmem_response), "not exist");
|
str_cpy(usbmem_response, sizeof(usbmem_response), "not exist");
|
||||||
|
usbmem_state[target_device_id].connected = false;
|
||||||
|
usbmem_state[target_device_id].opened = false;
|
||||||
|
usbmem_state[target_device_id].errored = true;
|
||||||
} else {
|
} else {
|
||||||
bool loaded = file_load(temp, (void**)&usbmem_state[target_device_id].buffer,
|
bool loaded = file_load(temp, (void**)&usbmem_state[target_device_id].buffer,
|
||||||
&usbmem_state[target_device_id].buffer_len, false);
|
&usbmem_state[target_device_id].buffer_len, false);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef DDRHOOK_UTIL_USBMEM_H
|
#ifndef DDRHOOK_UTIL_USBMEM_H
|
||||||
#define DDRHOOK_UTIL_USBMEM_H
|
#define DDRHOOK_UTIL_USBMEM_H
|
||||||
|
|
||||||
void usbmem_init(const char *path);
|
void usbmem_init(const char *path, const bool enabled);
|
||||||
void usbmem_fini(void);
|
void usbmem_fini(void);
|
||||||
HRESULT usbmem_dispatch_irp(struct irp *irp);
|
HRESULT usbmem_dispatch_irp(struct irp *irp);
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,12 @@
|
|||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def"
|
#define DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY "ddrhook1.standard_def"
|
||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY "ddrhook1.use_15khz"
|
#define DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY "ddrhook1.use_15khz"
|
||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH "ddrhook1.usbmem_path"
|
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH "ddrhook1.usbmem_path"
|
||||||
|
#define DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED "ddrhook1.usbmem_enabled"
|
||||||
|
|
||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE true
|
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE true
|
||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE false
|
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_STANDARD_DEF_VALUE false
|
||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE false
|
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE false
|
||||||
|
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED false
|
||||||
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH "usbmem"
|
#define DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_PATH "usbmem"
|
||||||
|
|
||||||
void ddrhook1_config_ddrhook1_init(struct cconfig *config)
|
void ddrhook1_config_ddrhook1_init(struct cconfig *config)
|
||||||
@@ -33,6 +35,11 @@ void ddrhook1_config_ddrhook1_init(struct cconfig *config)
|
|||||||
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
|
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
|
||||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE,
|
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE,
|
||||||
"Use 15 kHz monitor mode");
|
"Use 15 kHz monitor mode");
|
||||||
|
cconfig_util_set_bool(
|
||||||
|
config,
|
||||||
|
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
|
||||||
|
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED,
|
||||||
|
"Enable USB memory data emulation");
|
||||||
cconfig_util_set_str(
|
cconfig_util_set_str(
|
||||||
config,
|
config,
|
||||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH,
|
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH,
|
||||||
@@ -76,6 +83,17 @@ void ddrhook1_config_ddrhook1_get(
|
|||||||
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
|
DDRHOOK1_CONFIG_DDRHOOK1_USE_15KHZ_KEY,
|
||||||
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE);
|
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_15KHZ_VALUE);
|
||||||
}
|
}
|
||||||
|
if (!cconfig_util_get_bool(
|
||||||
|
config,
|
||||||
|
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
|
||||||
|
&config_ddrhook1->usbmem_enabled,
|
||||||
|
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED)) {
|
||||||
|
log_warning(
|
||||||
|
"Invalid value for key '%s' specified, fallback "
|
||||||
|
"to default '%d'",
|
||||||
|
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_ENABLED,
|
||||||
|
DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USBMEM_ENABLED);
|
||||||
|
}
|
||||||
if (!cconfig_util_get_str(
|
if (!cconfig_util_get_str(
|
||||||
config,
|
config,
|
||||||
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH,
|
DDRHOOK1_CONFIG_DDRHOOK1_USBMEM_PATH,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ struct ddrhook1_config_ddrhook1 {
|
|||||||
bool use_com4_emu;
|
bool use_com4_emu;
|
||||||
bool standard_def;
|
bool standard_def;
|
||||||
bool use_15khz;
|
bool use_15khz;
|
||||||
|
bool usbmem_enabled;
|
||||||
char usbmem_path[MAX_PATH];
|
char usbmem_path[MAX_PATH];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ static DWORD STDCALL my_main()
|
|||||||
&security_rp_sign_key_black_ddrx,
|
&security_rp_sign_key_black_ddrx,
|
||||||
&security_rp_sign_key_white_eamuse);
|
&security_rp_sign_key_white_eamuse);
|
||||||
extio_init();
|
extio_init();
|
||||||
usbmem_init(config_ddrhook1.usbmem_path);
|
usbmem_init(config_ddrhook1.usbmem_path, config_ddrhook1.usbmem_enabled);
|
||||||
spike_init();
|
spike_init();
|
||||||
com4_init();
|
com4_init();
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
|
|||||||
bool com4;
|
bool com4;
|
||||||
bool ok;
|
bool ok;
|
||||||
int i;
|
int i;
|
||||||
char usbmem_data_path[MAX_PATH] = "usbmem";
|
char usbmem_data_path[MAX_PATH] = "";
|
||||||
|
bool usbmem_enabled = false;
|
||||||
|
|
||||||
log_info("--- Begin ddrhook dll_entry_init ---");
|
log_info("--- Begin ddrhook dll_entry_init ---");
|
||||||
|
|
||||||
@@ -74,6 +75,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
|
|||||||
/* Specify a USB memory path */
|
/* Specify a USB memory path */
|
||||||
if (i + 1 < argc) {
|
if (i + 1 < argc) {
|
||||||
strcpy(usbmem_data_path, argv[i+1]);
|
strcpy(usbmem_data_path, argv[i+1]);
|
||||||
|
usbmem_enabled = true;
|
||||||
i++; // Move forward one to skip the path parameter
|
i++; // Move forward one to skip the path parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
|
|||||||
ddrhook2_master_insert_hooks(NULL);
|
ddrhook2_master_insert_hooks(NULL);
|
||||||
p3io_ddr_init();
|
p3io_ddr_init();
|
||||||
extio_init();
|
extio_init();
|
||||||
usbmem_init(usbmem_data_path);
|
usbmem_init(usbmem_data_path, usbmem_enabled);
|
||||||
spike_init();
|
spike_init();
|
||||||
com4_init();
|
com4_init();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user