From 98ed7d1c29616174a11fb7791042cb3eb3e40642 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sat, 11 Nov 2023 12:16:29 +0100 Subject: [PATCH] poc: cancel USB xfer on NSP dump error. --- code_templates/nxdt_rw_poc.c | 10 ++++------ source/core/pfs.c | 2 +- source/core/usb.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/code_templates/nxdt_rw_poc.c b/code_templates/nxdt_rw_poc.c index 2959f85..3198560 100644 --- a/code_templates/nxdt_rw_poc.c +++ b/code_templates/nxdt_rw_poc.c @@ -5279,11 +5279,7 @@ static void nspThreadFunc(void *arg) bool cancelled = nsp_thread_data->transfer_cancelled; mutexUnlock(&g_fileMutex); - if (cancelled) - { - if (dev_idx == 1) usbCancelFileTransfer(); - goto end; - } + if (cancelled) goto end; if ((cur_nca_ctx->content_size - offset) < blksize) blksize = (cur_nca_ctx->content_size - offset); @@ -5563,7 +5559,7 @@ end: { fclose(fd); - if (!success && dev_idx != 1) + if (!success) { if (dev_idx == 0) { @@ -5575,6 +5571,8 @@ end: } } + if (!success && dev_idx == 1) usbCancelFileTransfer(); + pfsFreeImageContext(&pfs_img_ctx); if (raw_cert_chain) free(raw_cert_chain); diff --git a/source/core/pfs.c b/source/core/pfs.c index 68f09a6..2f85a7c 100644 --- a/source/core/pfs.c +++ b/source/core/pfs.c @@ -346,7 +346,7 @@ bool pfsWriteImageContextHeaderToMemoryBuffer(PartitionFileSystemImageContext *c header_size = (sizeof(PartitionFileSystemHeader) + (header->entry_count * sizeof(PartitionFileSystemEntry)) + header->name_table_size); /* Calculate padded header size and padding size. */ - padded_header_size = (IS_ALIGNED(header_size, PFS_HEADER_PADDING_ALIGNMENT) ? ALIGN_UP(header_size + 1, PFS_HEADER_PADDING_ALIGNMENT) : ALIGN_UP(header_size, PFS_HEADER_PADDING_ALIGNMENT)); + padded_header_size = (IS_ALIGNED(header_size, PFS_HEADER_PADDING_ALIGNMENT) ? (header_size + PFS_HEADER_PADDING_ALIGNMENT) : ALIGN_UP(header_size, PFS_HEADER_PADDING_ALIGNMENT)); padding_size = (u32)(padded_header_size - header_size); /* Check buffer size. */ diff --git a/source/core/usb.c b/source/core/usb.c index 5ff9821..29fc67d 100644 --- a/source/core/usb.c +++ b/source/core/usb.c @@ -32,7 +32,7 @@ #define USB_CMD_HEADER_MAGIC 0x4E584454 /* "NXDT". */ #define USB_TRANSFER_ALIGNMENT 0x1000 /* 4 KiB. */ -#define USB_TRANSFER_TIMEOUT 5 /* 5 seconds. */ +#define USB_TRANSFER_TIMEOUT 10 /* 10 seconds. */ #define USB_DEV_VID 0x057E /* VID officially used by Nintendo in usb:ds. */ #define USB_DEV_PID 0x3000 /* PID officially used by Nintendo in usb:ds. */