From 900161750ee5c21a56868bc0d56c755083afbe32 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 18 May 2014 05:45:39 +1000 Subject: Fixed regression that broke support for GT-I9100 etc. --- heimdall/source/BridgeManager.cpp | 34 +++++++++++++++++++++------------- heimdall/source/BridgeManager.h | 26 ++++++++++++++++++++------ 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 719d041..a2cba80 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -661,16 +661,24 @@ bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeou return (result == LIBUSB_SUCCESS && dataTransferred == length); } -bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout) const +bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int sendEmptyTransferFlags) const { packet->Pack(); + if (sendEmptyTransferFlags & kSendEmptyTransferBefore) + { + if (!SendBulkTransfer(nullptr, 0, timeout)) + return (false); + } + if (!SendBulkTransfer(packet->GetData(), packet->GetSize(), timeout)) return (false); - // After each packet we send an empty bulk transfer... Hey! I'm just implementing the protocol, I didn't define it! - if (!SendBulkTransfer(nullptr, 0, timeout)) - return (false); + if (sendEmptyTransferFlags & kSendEmptyTransferAfter) + { + if (!SendBulkTransfer(nullptr, 0, timeout)) + return (false); + } return (true); } @@ -1057,14 +1065,14 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int return (false); } - SendFilePartPacket *sendFilePartPacket; - SendFilePartResponse *sendFilePartResponse; - for (unsigned int filePartIndex = 0; filePartIndex < sequenceSize; filePartIndex++) { + // NOTE: This empty transfer thing is entirely ridiculous, but sadly it seems to be required. + int sendEmptyTransferFlags = (filePartIndex == 0) ? kSendEmptyTransferNone : kSendEmptyTransferBefore; + // Send - sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); - success = SendPacket(sendFilePartPacket); + SendFilePartPacket *sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); + success = SendPacket(sendFilePartPacket, kDefaultTimeoutSend, sendEmptyTransferFlags); delete sendFilePartPacket; if (!success) @@ -1075,7 +1083,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int } // Response - sendFilePartResponse = new SendFilePartResponse(); + SendFilePartResponse *sendFilePartResponse = new SendFilePartResponse(); success = ReceivePacket(sendFilePartResponse); int receivedPartIndex = sendFilePartResponse->GetPartIndex(); @@ -1093,7 +1101,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int // Send sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); - success = SendPacket(sendFilePartPacket); + success = SendPacket(sendFilePartPacket, kDefaultTimeoutSend, sendEmptyTransferFlags); delete sendFilePartPacket; if (!success) @@ -1161,7 +1169,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceByteCount, 0, deviceType, fileIdentifier, isLastSequence); - success = SendPacket(endPhoneFileTransferPacket); + success = SendPacket(endPhoneFileTransferPacket, kDefaultTimeoutSend, kSendEmptyTransferBeforeAndAfter); delete endPhoneFileTransferPacket; if (!success) @@ -1175,7 +1183,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceByteCount, 0, deviceType, isLastSequence); - success = SendPacket(endModemFileTransferPacket); + success = SendPacket(endModemFileTransferPacket, kDefaultTimeoutSend, kSendEmptyTransferBeforeAndAfter); delete endModemFileTransferPacket; if (!success) diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 6b967fa..7028003 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -73,9 +73,15 @@ namespace Heimdall enum { - kPidGalaxyS = 0x6601, - kPidGalaxyS2 = 0x685D, - kPidDroidCharge = 0x68C3 + kPidGalaxyS = 0x6601, + kPidGalaxyS2 = 0x685D, + kPidDroidCharge = 0x68C3 + }; + + enum + { + kDefaultTimeoutSend = 3000, + kDefaultTimeoutReceive = 3000 }; enum class UsbLogLevel @@ -89,6 +95,14 @@ namespace Heimdall Default = Error }; + enum + { + kSendEmptyTransferNone = 0, + kSendEmptyTransferBefore = 1, + kSendEmptyTransferAfter = 1 << 1, + kSendEmptyTransferBeforeAndAfter = kSendEmptyTransferBefore | kSendEmptyTransferAfter + }; + private: static const DeviceIdentifier supportedDevices[kSupportedDeviceCount]; @@ -125,7 +139,7 @@ namespace Heimdall bool InitialiseProtocol(void); - bool SendBulkTransfer(unsigned char *data, int length, int timeout = 3000) const; + bool SendBulkTransfer(unsigned char *data, int length, int timeout) const; public: @@ -138,8 +152,8 @@ namespace Heimdall bool BeginSession(void); bool EndSession(bool reboot) const; - bool SendPacket(OutboundPacket *packet, int timeout = 3000) const; - bool ReceivePacket(InboundPacket *packet, int timeout = 3000) const; + bool SendPacket(OutboundPacket *packet, int timeout = kDefaultTimeoutSend, int sendEmptyTransferFlags = kSendEmptyTransferAfter) const; + bool ReceivePacket(InboundPacket *packet, int timeout = kDefaultTimeoutReceive) const; bool RequestDeviceType(unsigned int request, int *result) const; -- cgit v1.1