From a6da38d75dce7941262a64b0097a9e2502bff22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 2 May 2019 18:56:10 +0200 Subject: [PATCH] IOS/USB: Fix TransferCommand length type The total buffer size for isochronous transfers should be a u32, not a u16. It is easy to hit the bug with devices such as cameras, which require larger buffers. This fixes Your Shape. This also fixes the length type for bulk and interrupt transfers, which should be u32 as that's what IOS supports. I'm not sure why I made them u16... probably because OH0 uses u16 for most lengths... --- Source/Core/Core/IOS/USB/Common.h | 6 +++--- Source/Core/Core/IOS/USB/USBV4.cpp | 2 +- Source/Core/Core/IOS/USB/USBV5.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Common.h b/Source/Core/Core/IOS/USB/Common.h index 58a164adc1..8a6c4edf06 100644 --- a/Source/Core/Core/IOS/USB/Common.h +++ b/Source/Core/Core/IOS/USB/Common.h @@ -127,14 +127,14 @@ struct CtrlMessage : TransferCommand struct BulkMessage : TransferCommand { - u16 length = 0; + u32 length = 0; u8 endpoint = 0; using TransferCommand::TransferCommand; }; struct IntrMessage : TransferCommand { - u16 length = 0; + u32 length = 0; u8 endpoint = 0; using TransferCommand::TransferCommand; }; @@ -143,7 +143,7 @@ struct IsoMessage : TransferCommand { u32 packet_sizes_addr = 0; std::vector packet_sizes; - u16 length = 0; + u32 length = 0; u8 num_packets = 0; u8 endpoint = 0; using TransferCommand::TransferCommand; diff --git a/Source/Core/Core/IOS/USB/USBV4.cpp b/Source/Core/Core/IOS/USB/USBV4.cpp index c31848fe1c..1aae6c6a7b 100644 --- a/Source/Core/Core/IOS/USB/USBV4.cpp +++ b/Source/Core/Core/IOS/USB/USBV4.cpp @@ -87,7 +87,7 @@ V4IntrMessage::V4IntrMessage(Kernel& ios, const IOCtlRequest& ioctl) : IntrMessa { HIDRequest hid_request; Memory::CopyFromEmu(&hid_request, ioctl.buffer_in, sizeof(hid_request)); - length = static_cast(Common::swap32(hid_request.interrupt.length)); + length = Common::swap32(hid_request.interrupt.length); endpoint = static_cast(Common::swap32(hid_request.interrupt.endpoint)); data_address = Common::swap32(hid_request.data_addr); } diff --git a/Source/Core/Core/IOS/USB/USBV5.cpp b/Source/Core/Core/IOS/USB/USBV5.cpp index 09eb3d6718..0da9448a65 100644 --- a/Source/Core/Core/IOS/USB/USBV5.cpp +++ b/Source/Core/Core/IOS/USB/USBV5.cpp @@ -31,14 +31,14 @@ V5CtrlMessage::V5CtrlMessage(Kernel& ios, const IOCtlVRequest& ioctlv) V5BulkMessage::V5BulkMessage(Kernel& ios, const IOCtlVRequest& ioctlv) : BulkMessage(ios, ioctlv, ioctlv.GetVector(1)->address) { - length = static_cast(ioctlv.GetVector(1)->size); + length = ioctlv.GetVector(1)->size; endpoint = Memory::Read_U8(ioctlv.in_vectors[0].address + 18); } V5IntrMessage::V5IntrMessage(Kernel& ios, const IOCtlVRequest& ioctlv) : IntrMessage(ios, ioctlv, ioctlv.GetVector(1)->address) { - length = static_cast(ioctlv.GetVector(1)->size); + length = ioctlv.GetVector(1)->size; endpoint = Memory::Read_U8(ioctlv.in_vectors[0].address + 14); } @@ -50,7 +50,7 @@ V5IsoMessage::V5IsoMessage(Kernel& ios, const IOCtlVRequest& ioctlv) packet_sizes_addr = ioctlv.GetVector(1)->address; for (size_t i = 0; i < num_packets; ++i) packet_sizes.push_back(Memory::Read_U16(static_cast(packet_sizes_addr + i * sizeof(u16)))); - length = static_cast(ioctlv.GetVector(2)->size); + length = ioctlv.GetVector(2)->size; } } // namespace USB