From 5cd4141c980bfd516ba2843afa2c2a8348d5613a Mon Sep 17 00:00:00 2001 From: Robert Craig Date: Wed, 30 Oct 2013 10:30:26 -0400 Subject: Fix error condition check on finding correct usb interface. --- heimdall/source/BridgeManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index ed12b87..d21ea60 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -232,7 +232,7 @@ int BridgeManager::FindDeviceInterface(void) libusb_free_config_descriptor(configDescriptor); - if (result != LIBUSB_SUCCESS) + if (interfaceIndex < 0) { Interface::PrintError("Failed to find correct interface configuration\n"); return (BridgeManager::kInitialiseFailed); -- cgit v1.1 From 3af0c3ad63437ac53f5e2832a22e21a8790686f5 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Wed, 30 Apr 2014 01:40:10 +1000 Subject: Minor code clean up. --- heimdall/source/BridgeManager.cpp | 155 +++++++++++++++++--------------- heimdall/source/BridgeManager.h | 11 +++ heimdall/source/EndFileTransferPacket.h | 16 ++-- heimdall/source/FlashAction.cpp | 2 +- heimdall/source/Interface.cpp | 3 + 5 files changed, 104 insertions(+), 83 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index ed12b87..49dde7f 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -307,51 +307,99 @@ void BridgeManager::ReleaseDeviceInterface(void) Interface::Print("\n"); } -bool BridgeManager::InitialiseProtocol(void) +enum { - Interface::Print("Initialising protocol...\n"); + kControlRequestSetLineCoding = 0x20, + kControlRequestSetControlLineState = 0x22 +}; - unsigned char dataBuffer[7]; - int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000); +enum +{ + kLineCodingCharFormatZeroToOneStopBit = 0, + kLineCodingCharFormatOneToOneAndAHalfStopBits = 1, + kLineCodingCharFormatTwoToTwoAndAHalfStopBits = 2 +}; - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #1 failed. Result: %d\n", result); +enum +{ + kParityTypeNone = 0, + kParityTypeOdd = 1, + kParityTypeEven = 2, + kParityTypeMark = 3, + kParityTypeSpace = 4 +}; - memset(dataBuffer, 0, 7); - dataBuffer[1] = 0xC2; - dataBuffer[2] = 0x01; - dataBuffer[6] = 0x07; +bool BridgeManager::SetControlLineState(unsigned short controlSignalFlags) +{ + int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, kControlRequestSetControlLineState, controlSignalFlags, 0, nullptr, 0, 1000); - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000); + if (result != LIBUSB_SUCCESS) + { + if (verbose) + Interface::PrintWarning("Control line state (signal flags: 0x%x) transfer failed. Result: %d\n", controlSignalFlags, result); - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #2 failed. Result: %d\n", result); + return (false); + } + else + { + return (true); + } +} + +bool BridgeManager::SetControlLineCoding(LineCoding lineCoding) +{ + unsigned char dataBuffer[7]; + + dataBuffer[0] = lineCoding.dteRate & 0xFF; + dataBuffer[1] = (lineCoding.dteRate >> 8) & 0xFF; + dataBuffer[2] = (lineCoding.dteRate >> 16) & 0xFF; + dataBuffer[3] = (lineCoding.dteRate >> 24) & 0xFF; + dataBuffer[4] = lineCoding.charFormat; + dataBuffer[5] = lineCoding.parityType; + dataBuffer[6] = lineCoding.dataBits; - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000); + int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, kControlRequestSetLineCoding, 0x0, 0, dataBuffer, 7, 1000); - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #3 failed. Result: %d\n", result); + if (result != LIBUSB_SUCCESS) + { + if (verbose) + Interface::PrintWarning("Setting control line coding failed. Result: %d\n", result); - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000); + return (false); + } + else + { + return (true); + } +} - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #4 failed. Result: %d\n", result); +enum +{ + kLineStateControlSignalDtePresent = 1, + kLineStateControlSignalCarrierControl = 1 << 1 +}; - memset(dataBuffer, 0, 7); - dataBuffer[1] = 0xC2; - dataBuffer[2] = 0x01; - dataBuffer[6] = 0x08; +bool BridgeManager::InitialiseProtocol(void) +{ + Interface::Print("Initialising protocol...\n"); - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000); + LineCoding lineCoding; - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #5 failed. Result: %d\n", result); + lineCoding.dteRate = 115200; + lineCoding.charFormat = kLineCodingCharFormatZeroToOneStopBit; + lineCoding.parityType = kParityTypeNone; + lineCoding.dataBits = 7; - result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000); + SetControlLineState(kLineStateControlSignalDtePresent | kLineStateControlSignalCarrierControl); + SetControlLineCoding(lineCoding); + SetControlLineState(kLineStateControlSignalDtePresent | kLineStateControlSignalCarrierControl); + SetControlLineState(kLineStateControlSignalCarrierControl); + + lineCoding.dataBits = 8; + SetControlLineCoding(lineCoding); - if (result < 0 && verbose) - Interface::PrintWarning("Control transfer #6 failed. Result: %d\n", result); + SetControlLineState(kLineStateControlSignalCarrierControl); unsigned int attempt = 0; @@ -371,12 +419,13 @@ bool BridgeManager::InitialiseProtocol(void) int dataTransferred = 0; + unsigned char dataBuffer[7]; + // Send "ODIN" memcpy(dataBuffer, "ODIN", 4); memset(dataBuffer + 4, 0, 1); - result = libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000); - if (result < 0) + if (libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000) != LIBUSB_SUCCESS) { if (verbose) Interface::PrintError("Failed to send data: \"%s\"\n", dataBuffer); @@ -402,9 +451,7 @@ bool BridgeManager::InitialiseProtocol(void) int retry = 0; dataTransferred = 0; - result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); - - if (result < 0) + if (libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000) != LIBUSB_SUCCESS) { if (verbose) Interface::PrintError("Failed to receive handshake response."); @@ -652,46 +699,6 @@ bool BridgeManager::BeginSession(void) } } - // -------------------- KIES DOESN'T DO THIS -------------------- - - /*DeviceTypePacket deviceTypePacket; - - if (!SendPacket(&deviceTypePacket)) - { - Interface::PrintError("Failed to request device type!\n"); - return (false); - } - - SessionSetupResponse deviceTypeResponse; - - if (!ReceivePacket(&deviceTypeResponse)) - return (false); - - unsigned int deviceType = deviceTypeResponse.GetResult(); - - switch (deviceType) - { - // NOTE: If you add a new device type don't forget to update the error message below! - - case 0: // Galaxy S etc. - case 3: // Galaxy Tab - case 30: // Galaxy S 2 Skyrocket - case 180: // Galaxy S etc. - case 190: // M110S Galaxy S - - if (verbose) - Interface::Print("Session begun with device of type: %d.\n\n", deviceType); - else - Interface::Print("Session begun.\n\n"); - - return (true); - - default: - - Interface::PrintError("Unexpected device info response!\nExpected: 0, 3, 30, 180 or 190\nReceived:%d\n", deviceType); - return (false); - }*/ - Interface::Print("Session begun.\n\n"); return (true); } diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index e67c679..1f88cdc 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -94,6 +94,14 @@ namespace Heimdall Default = Error }; + typedef struct + { + unsigned int dteRate; + unsigned char charFormat; + unsigned char parityType; + unsigned char dataBits; + } LineCoding; + private: static const DeviceIdentifier supportedDevices[kSupportedDeviceCount]; @@ -131,6 +139,9 @@ namespace Heimdall bool InitialiseProtocol(void); + bool SetControlLineState(unsigned short controlSignalFlags); + bool SetControlLineCoding(LineCoding lineCoding); + public: BridgeManager(bool verbose, int communicationDelay = BridgeManager::kCommunicationDelayDefault); diff --git a/heimdall/source/EndFileTransferPacket.h b/heimdall/source/EndFileTransferPacket.h index 7e78899..9ae4a44 100644 --- a/heimdall/source/EndFileTransferPacket.h +++ b/heimdall/source/EndFileTransferPacket.h @@ -34,7 +34,7 @@ namespace Heimdall { kDestinationPhone = 0x00, kDestinationModem = 0x01 - }; + }; protected: @@ -47,18 +47,18 @@ namespace Heimdall unsigned int destination; // PDA / Modem unsigned int sequenceByteCount; - unsigned int unknown1; - unsigned int chipIdentifier; + unsigned int unknown1; // EFS? + unsigned int deviceType; protected: - EndFileTransferPacket(unsigned int destination, unsigned int sequenceByteCount, unsigned int unknown1, unsigned int chipIdentifier) + EndFileTransferPacket(unsigned int destination, unsigned int sequenceByteCount, unsigned int unknown1, unsigned int deviceType) : FileTransferPacket(FileTransferPacket::kRequestEnd) { this->destination = destination; this->sequenceByteCount = sequenceByteCount; this->unknown1 = unknown1; - this->chipIdentifier = chipIdentifier; + this->deviceType = deviceType; } public: @@ -78,9 +78,9 @@ namespace Heimdall return (unknown1); } - unsigned int GetChipIdentifier(void) const + unsigned int GetDeviceType(void) const { - return (chipIdentifier); + return (deviceType); } virtual void Pack(void) @@ -90,7 +90,7 @@ namespace Heimdall PackInteger(FileTransferPacket::kDataSize, destination); PackInteger(FileTransferPacket::kDataSize + 4, sequenceByteCount); PackInteger(FileTransferPacket::kDataSize + 8, unknown1); - PackInteger(FileTransferPacket::kDataSize + 12, chipIdentifier); + PackInteger(FileTransferPacket::kDataSize + 12, deviceType); } }; } diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index 6f2d49b..e951d4e 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -251,7 +251,7 @@ static bool flashFile(BridgeManager *bridgeManager, const PartitionFlashInfo& pa Interface::Print("Uploading %s\n", partitionFlashInfo.pitEntry->GetPartitionName()); if (bridgeManager->SendFile(partitionFlashInfo.file, EndModemFileTransferPacket::kDestinationModem, - partitionFlashInfo.pitEntry->GetDeviceType())) // <-- Odin method + partitionFlashInfo.pitEntry->GetDeviceType())) { Interface::Print("%s upload successful\n\n", partitionFlashInfo.pitEntry->GetPartitionName()); return (true); diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp index dbf8431..910f346 100644 --- a/heimdall/source/Interface.cpp +++ b/heimdall/source/Interface.cpp @@ -264,6 +264,9 @@ void Interface::PrintPit(const PitData *pitData) if (entry->GetAttributes() & PitEntry::kAttributeSTL) Interface::Print("STL "); + /*if (entry->GetAttributes() & PitEntry::kAttributeBML) + Interface::Print("BML ");*/ + if (entry->GetAttributes() & PitEntry::kAttributeWrite) Interface::Print("Read/Write"); else -- cgit v1.1 From 1e345bcd7c6a82bbf0800781416d5df15b555da0 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Wed, 30 Apr 2014 03:49:19 +1000 Subject: Fix support for SGS4 (with empty bulk transfers) After each bulk transfer sent containing an Odin/Loke protocol packet, we now send through a zero length bulk transfer. This is required for newer devices to function correctly. --- heimdall/source/BridgeManager.cpp | 140 +++++++++++++++----------------------- heimdall/source/BridgeManager.h | 2 + 2 files changed, 55 insertions(+), 87 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 49dde7f..3e85a09 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -80,7 +80,6 @@ enum enum { - kHandshakeMaxAttempts = 5, kReceivePacketMaxAttempts = 5 }; @@ -384,7 +383,7 @@ bool BridgeManager::InitialiseProtocol(void) { Interface::Print("Initialising protocol...\n"); - LineCoding lineCoding; + /*LineCoding lineCoding; lineCoding.dteRate = 115200; lineCoding.charFormat = kLineCodingCharFormatZeroToOneStopBit; @@ -399,93 +398,53 @@ bool BridgeManager::InitialiseProtocol(void) lineCoding.dataBits = 8; SetControlLineCoding(lineCoding); - SetControlLineState(kLineStateControlSignalCarrierControl); + SetControlLineState(kLineStateControlSignalCarrierControl);*/ - unsigned int attempt = 0; + int dataTransferred = 0; - // max(250, communicationDelay) - int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; + unsigned char dataBuffer[7]; - for (; attempt < kHandshakeMaxAttempts; attempt++) - { - if (attempt > 0) - { - if (verbose) - Interface::PrintErrorSameLine(" Retrying...\n"); - - // Wait longer each retry - Sleep(retryDelay * (attempt + 1)); - } + // Send "ODIN" + memcpy(dataBuffer, "ODIN", 4); + memset(dataBuffer + 4, 0, 1); - int dataTransferred = 0; + if (!SendBulkTransfer(dataBuffer, 4, 1000)) + { + Interface::PrintError("Failed to send handshake!"); + } - unsigned char dataBuffer[7]; + // Expect "LOKE" + memset(dataBuffer, 0, 7); - // Send "ODIN" - memcpy(dataBuffer, "ODIN", 4); - memset(dataBuffer + 4, 0, 1); + int retry = 0; + dataTransferred = 0; - if (libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000) != LIBUSB_SUCCESS) - { - if (verbose) - Interface::PrintError("Failed to send data: \"%s\"\n", dataBuffer); - else - Interface::PrintError("Failed to send data!"); + int result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); - return (false); - } - - if (dataTransferred != 4) + if (result != LIBUSB_SUCCESS) + { + if (verbose) + Interface::PrintError("Failed to receive handshake response. Result: %d\n", result); + } + else + { + if (dataTransferred == 4 && memcmp(dataBuffer, "LOKE", 4) == 0) { - if (verbose) - Interface::PrintError("Failed to complete sending of data: \"%s\"\n", dataBuffer); - else - Interface::PrintError("Failed to complete sending of data!"); - - return (false); - } - - // Expect "LOKE" - memset(dataBuffer, 0, 7); - - int retry = 0; - dataTransferred = 0; - - if (libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000) != LIBUSB_SUCCESS) - { - if (verbose) - Interface::PrintError("Failed to receive handshake response."); + // Successfully received "LOKE" + Interface::Print("Protocol initialisation successful.\n\n"); + return (true); } else { - if (dataTransferred == 4 && memcmp(dataBuffer, "LOKE", 4) == 0) - { - // Successfully received "LOKE" - break; - } - else - { - if (verbose) - Interface::PrintError("Expected: \"%s\"\nReceived: \"%s\"\n", "LOKE", dataBuffer); + if (verbose) + Interface::PrintError("Expected: \"LOKE\"\nReceived: \"%s\"\n", dataBuffer); - Interface::PrintError("Unexpected handshake response!"); - } + Interface::PrintError("Unexpected handshake response!\n"); } } - if (attempt == kHandshakeMaxAttempts) - { - if (verbose) - Interface::PrintErrorSameLine("\n"); - - Interface::PrintError("Protocol initialisation failed!\n\n"); - return (false); - } - else - { - Interface::Print("Protocol initialisation successful.\n\n"); - return (true); - } + Interface::PrintError("Protocol initialisation failed!\n\n"); + return (false); } BridgeManager::BridgeManager(bool verbose, int communicationDelay) @@ -759,21 +718,18 @@ bool BridgeManager::EndSession(bool reboot) const return (true); } -bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) const +bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const { - packet->Pack(); - int dataTransferred; - int result = libusb_bulk_transfer(deviceHandle, outEndpoint, packet->GetData(), packet->GetSize(), - &dataTransferred, timeout); + int result = libusb_bulk_transfer(deviceHandle, outEndpoint, data, length, &dataTransferred, timeout); - if (result < 0 && retry) + if (result != LIBUSB_SUCCESS && retry) { // max(250, communicationDelay) int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; if (verbose) - Interface::PrintError("libusb error %d whilst sending packet.", result); + Interface::PrintError("libusb error %d whilst sending bulk transfer.", result); // Retry for (int i = 0; i < 5; i++) @@ -784,26 +740,36 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) // Wait longer each retry Sleep(retryDelay * (i + 1)); - result = libusb_bulk_transfer(deviceHandle, outEndpoint, packet->GetData(), packet->GetSize(), - &dataTransferred, timeout); + result = libusb_bulk_transfer(deviceHandle, outEndpoint, data, length, &dataTransferred, timeout); - if (result >= 0) + if (result == LIBUSB_SUCCESS) break; if (verbose) - Interface::PrintError("libusb error %d whilst sending packet.", result); + Interface::PrintError("libusb error %d whilst sending bulk transfer.", result); } if (verbose) Interface::PrintErrorSameLine("\n"); } - if (communicationDelay != 0) - Sleep(communicationDelay); + return (result == LIBUSB_SUCCESS && dataTransferred == length); +} - if (result < 0 || dataTransferred != packet->GetSize()) +bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) const +{ + packet->Pack(); + + if (!SendBulkTransfer(packet->GetData(), packet->GetSize(), timeout, retry)) + 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, retry)) return (false); + if (communicationDelay != 0) + Sleep(communicationDelay); + return (true); } diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 1f88cdc..6481de6 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -142,6 +142,8 @@ namespace Heimdall bool SetControlLineState(unsigned short controlSignalFlags); bool SetControlLineCoding(LineCoding lineCoding); + bool SendBulkTransfer(unsigned char *data, int length, int timeout = 3000, bool retry = true) const; + public: BridgeManager(bool verbose, int communicationDelay = BridgeManager::kCommunicationDelayDefault); -- cgit v1.1 From 3dae56a59626cbf235afa847efbfbcc422d52055 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 4 May 2014 02:53:57 +1000 Subject: Bumped version number to 1.4.1 --- heimdall/source/Interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'heimdall/source') diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp index 910f346..b070dad 100644 --- a/heimdall/source/Interface.cpp +++ b/heimdall/source/Interface.cpp @@ -42,7 +42,7 @@ using namespace Heimdall; map actionMap; bool stdoutErrors = false; -const char *version = "v1.4.0"; +const char *version = "v1.4.1"; const char *actionUsage = "Usage: heimdall \n"; const char *releaseInfo = "Heimdall %s\n\n\ -- cgit v1.1 From a5452e884a1f1119d87e12e42d6ca9745617d054 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Mon, 5 May 2014 03:33:12 +1000 Subject: Cleaned up command line interface - Removed the "--delay " argument. - Improved Action usage info. --- heimdall/source/BridgeManager.cpp | 15 +++------------ heimdall/source/BridgeManager.h | 8 +------- heimdall/source/ClosePcScreenAction.cpp | 17 ++++++----------- heimdall/source/DownloadPitAction.cpp | 17 ++++++----------- heimdall/source/FlashAction.cpp | 28 +++++++++++----------------- heimdall/source/PrintPitAction.cpp | 16 ++++++---------- 6 files changed, 33 insertions(+), 68 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 3e85a09..e954f3b 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -447,10 +447,9 @@ bool BridgeManager::InitialiseProtocol(void) return (false); } -BridgeManager::BridgeManager(bool verbose, int communicationDelay) +BridgeManager::BridgeManager(bool verbose) { this->verbose = verbose; - this->communicationDelay = communicationDelay; libusbContext = nullptr; deviceHandle = nullptr; @@ -725,8 +724,7 @@ bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeou if (result != LIBUSB_SUCCESS && retry) { - // max(250, communicationDelay) - int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; + static const int retryDelay = 250; if (verbose) Interface::PrintError("libusb error %d whilst sending bulk transfer.", result); @@ -767,9 +765,6 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) if (!SendBulkTransfer(nullptr, 0, timeout, retry)) return (false); - if (communicationDelay != 0) - Sleep(communicationDelay); - return (true); } @@ -789,8 +784,7 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, bool retry unsigned int attempt = 0; unsigned int maxAttempts = (retry) ? kReceivePacketMaxAttempts : 1; - // max(250, communicationDelay) - int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; + static const int retryDelay = 250; for (; attempt < maxAttempts; attempt++) { @@ -818,9 +812,6 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, bool retry if (attempt == maxAttempts) return (false); - if (communicationDelay != 0) - Sleep(communicationDelay); - if (dataTransferred != packet->GetSize() && !packet->IsSizeVariable()) { if (verbose) diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 6481de6..6635724 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -61,11 +61,6 @@ namespace Heimdall enum { - kCommunicationDelayDefault = 0 - }; - - enum - { kInitialiseSucceeded = 0, kInitialiseFailed, kInitialiseDeviceNotDetected @@ -107,7 +102,6 @@ namespace Heimdall static const DeviceIdentifier supportedDevices[kSupportedDeviceCount]; bool verbose; - int communicationDelay; libusb_context *libusbContext; libusb_device_handle *deviceHandle; @@ -146,7 +140,7 @@ namespace Heimdall public: - BridgeManager(bool verbose, int communicationDelay = BridgeManager::kCommunicationDelayDefault); + BridgeManager(bool verbose); ~BridgeManager(); bool DetectDevice(void); diff --git a/heimdall/source/ClosePcScreenAction.cpp b/heimdall/source/ClosePcScreenAction.cpp index 2bc1b61..a72eab6 100644 --- a/heimdall/source/ClosePcScreenAction.cpp +++ b/heimdall/source/ClosePcScreenAction.cpp @@ -29,9 +29,12 @@ using namespace std; using namespace Heimdall; const char *ClosePcScreenAction::usage = "Action: close-pc-screen\n\ -Arguments: [--verbose] [--no-reboot] [--stdout-errors] [--delay ]\n\ +Arguments: [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ [--usb-log-level ]\n\ -Description: Attempts to get rid off the \"connect phone to PC\" screen.\n"; +Description: Attempts to get rid off the \"connect phone to PC\" screen.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag."; int ClosePcScreenAction::Execute(int argc, char **argv) { @@ -40,7 +43,6 @@ int ClosePcScreenAction::Execute(int argc, char **argv) map argumentTypes; argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -53,9 +55,7 @@ int ClosePcScreenAction::Execute(int argc, char **argv) return (0); } - const UnsignedIntegerArgument *communicationDelayArgument = static_cast(arguments.GetArgument("delay")); const StringArgument *usbLogLevelArgument = static_cast(arguments.GetArgument("usb-log-level")); - BridgeManager::UsbLogLevel usbLogLevel = BridgeManager::UsbLogLevel::Default; if (usbLogLevelArgument) @@ -104,12 +104,7 @@ int ClosePcScreenAction::Execute(int argc, char **argv) // Download PIT file from device. - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp index abebfae..43325eb 100644 --- a/heimdall/source/DownloadPitAction.cpp +++ b/heimdall/source/DownloadPitAction.cpp @@ -33,9 +33,12 @@ using namespace Heimdall; const char *DownloadPitAction::usage = "Action: download-pit\n\ Arguments: --output [--verbose] [--no-reboot] [--stdout-errors]\n\ - [--delay ] [--usb-log-level ]\n\ + [--usb-log-level ]\n\ Description: Downloads the connected device's PIT file to the specified\n\ - output file.\n"; + output file.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag."; int DownloadPitAction::Execute(int argc, char **argv) { @@ -45,7 +48,6 @@ int DownloadPitAction::Execute(int argc, char **argv) argumentTypes["output"] = kArgumentTypeString; argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -67,8 +69,6 @@ int DownloadPitAction::Execute(int argc, char **argv) return (0); } - const UnsignedIntegerArgument *communicationDelayArgument = static_cast(arguments.GetArgument("delay")); - bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; bool verbose = arguments.GetArgument("verbose") != nullptr; @@ -130,12 +130,7 @@ int DownloadPitAction::Execute(int argc, char **argv) // Download PIT file from device. - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index e951d4e..b528597 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -39,17 +39,19 @@ using namespace Heimdall; const char *FlashAction::usage = "Action: flash\n\ Arguments:\n\ - --repartition --pit \n\ - --|-- [...]\n\ - [--verbose] [--no-reboot] [--stdout-errors] [--delay ]\n\ - [--usb-log-level ]\n\ + [-- ...]\n\ + [-- ...]\n\ + [--pit ] [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ + [--usb-log-level ]\n\ or:\n\ - --|-- [...]\n\ - [--pit ]\n\ - [--verbose] [--no-reboot] [--stdout-errors] [--delay ]\n\ - [--usb-log-level ]\n\ + --repartition --pit [-- ...]\n\ + [-- ...] [--verbose] [--no-reboot]\n\ + [--resume] [--stdout-errors] [--usb-log-level ]\n\ Description: Flashes one or more firmware files to your phone. Partition names\n\ (or identifiers) can be obtained by executing the print-pit action.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag.\n\ WARNING: If you're repartitioning it's strongly recommended you specify\n\ all files at your disposal.\n"; @@ -389,7 +391,6 @@ int FlashAction::Execute(int argc, char **argv) argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -417,8 +418,6 @@ int FlashAction::Execute(int argc, char **argv) return (0); } - const UnsignedIntegerArgument *communicationDelayArgument = static_cast(arguments.GetArgument("delay")); - bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; bool verbose = arguments.GetArgument("verbose") != nullptr; @@ -497,12 +496,7 @@ int FlashAction::Execute(int argc, char **argv) // Perform flash - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 1c8c98a..4ed6e6c 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -34,10 +34,13 @@ using namespace Heimdall; const char *PrintPitAction::usage = "Action: print-pit\n\ Arguments: [--file ] [--verbose] [--no-reboot] [--stdout-errors]\n\ - [--delay ] [--usb-log-level ]\n\ + [--usb-log-level ]\n\ Description: Prints the contents of a PIT file in a human readable format. If\n\ a filename is not provided then Heimdall retrieves the PIT file from the \n\ - connected device.\n"; + connected device.\n\ +Note: --no-reboot causes the device to remain in download mode after the action\n\ + is completed. If you wish to perform another action whilst remaining in\n\ + download mode, then the following action must specify the --resume flag."; int PrintPitAction::Execute(int argc, char **argv) { @@ -47,7 +50,6 @@ int PrintPitAction::Execute(int argc, char **argv) argumentTypes["file"] = kArgumentTypeString; argumentTypes["no-reboot"] = kArgumentTypeFlag; argumentTypes["resume"] = kArgumentTypeFlag; - argumentTypes["delay"] = kArgumentTypeUnsignedInteger; argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; @@ -61,7 +63,6 @@ int PrintPitAction::Execute(int argc, char **argv) } const StringArgument *fileArgument = static_cast(arguments.GetArgument("file")); - const UnsignedIntegerArgument *communicationDelayArgument = static_cast(arguments.GetArgument("delay")); bool reboot = arguments.GetArgument("no-reboot") == nullptr; bool resume = arguments.GetArgument("resume") != nullptr; @@ -155,12 +156,7 @@ int PrintPitAction::Execute(int argc, char **argv) { // Print PIT from a device. - int communicationDelay = BridgeManager::kCommunicationDelayDefault; - - if (communicationDelayArgument) - communicationDelay = communicationDelayArgument->GetValue(); - - BridgeManager *bridgeManager = new BridgeManager(verbose, communicationDelay); + BridgeManager *bridgeManager = new BridgeManager(verbose); bridgeManager->SetUsbLogLevel(usbLogLevel); if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) -- cgit v1.1 From 9f957a193701788cac66292daea2c89ed94a033f Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Tue, 6 May 2014 22:52:10 +1000 Subject: Updated copyright notices to 2014 --- heimdall/source/Arguments.cpp | 2 +- heimdall/source/Arguments.h | 2 +- heimdall/source/BeginDumpPacket.h | 2 +- heimdall/source/BeginSessionPacket.h | 2 +- heimdall/source/BridgeManager.cpp | 2 +- heimdall/source/BridgeManager.h | 2 +- heimdall/source/ClosePcScreenAction.cpp | 2 +- heimdall/source/ClosePcScreenAction.h | 2 +- heimdall/source/ControlPacket.h | 2 +- heimdall/source/DetectAction.cpp | 2 +- heimdall/source/DetectAction.h | 2 +- heimdall/source/DeviceTypePacket.h | 2 +- heimdall/source/DownloadPitAction.cpp | 2 +- heimdall/source/DownloadPitAction.h | 2 +- heimdall/source/DumpPartFileTransferPacket.h | 2 +- heimdall/source/DumpPartPitFilePacket.h | 2 +- heimdall/source/DumpResponse.h | 2 +- heimdall/source/EndFileTransferPacket.h | 2 +- heimdall/source/EndModemFileTransferPacket.h | 2 +- heimdall/source/EndPhoneFileTransferPacket.h | 2 +- heimdall/source/EndPitFileTransferPacket.h | 2 +- heimdall/source/EndSessionPacket.h | 2 +- heimdall/source/FilePartSizePacket.h | 2 +- heimdall/source/FileTransferPacket.h | 2 +- heimdall/source/FlashAction.cpp | 2 +- heimdall/source/FlashAction.h | 2 +- heimdall/source/FlashPartFileTransferPacket.h | 2 +- heimdall/source/FlashPartPitFilePacket.h | 2 +- heimdall/source/Heimdall.h | 2 +- heimdall/source/HelpAction.cpp | 2 +- heimdall/source/HelpAction.h | 2 +- heimdall/source/InboundPacket.h | 2 +- heimdall/source/InfoAction.cpp | 2 +- heimdall/source/InfoAction.h | 2 +- heimdall/source/Interface.cpp | 4 ++-- heimdall/source/Interface.h | 2 +- heimdall/source/OutboundPacket.h | 2 +- heimdall/source/Packet.h | 2 +- heimdall/source/PitFilePacket.h | 2 +- heimdall/source/PitFileResponse.h | 2 +- heimdall/source/PrintPitAction.cpp | 2 +- heimdall/source/PrintPitAction.h | 2 +- heimdall/source/ReceiveFilePartPacket.h | 2 +- heimdall/source/ResponsePacket.h | 2 +- heimdall/source/SendFilePartPacket.h | 2 +- heimdall/source/SendFilePartResponse.h | 2 +- heimdall/source/SessionSetupPacket.h | 2 +- heimdall/source/SessionSetupResponse.h | 2 +- heimdall/source/TotalBytesPacket.h | 2 +- heimdall/source/Utility.cpp | 2 +- heimdall/source/Utility.h | 2 +- heimdall/source/VersionAction.cpp | 2 +- heimdall/source/VersionAction.h | 2 +- heimdall/source/main.cpp | 2 +- 54 files changed, 55 insertions(+), 55 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/Arguments.cpp b/heimdall/source/Arguments.cpp index a37572d..feae2e1 100644 --- a/heimdall/source/Arguments.cpp +++ b/heimdall/source/Arguments.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Arguments.h b/heimdall/source/Arguments.h index 72aa036..83cf128 100644 --- a/heimdall/source/Arguments.h +++ b/heimdall/source/Arguments.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/BeginDumpPacket.h b/heimdall/source/BeginDumpPacket.h index 9561aa3..d664674 100644 --- a/heimdall/source/BeginDumpPacket.h +++ b/heimdall/source/BeginDumpPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/BeginSessionPacket.h b/heimdall/source/BeginSessionPacket.h index c688504..27d982e 100644 --- a/heimdall/source/BeginSessionPacket.h +++ b/heimdall/source/BeginSessionPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 6546541..1559a70 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 6635724..04b03c3 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/ClosePcScreenAction.cpp b/heimdall/source/ClosePcScreenAction.cpp index a72eab6..1a3387c 100644 --- a/heimdall/source/ClosePcScreenAction.cpp +++ b/heimdall/source/ClosePcScreenAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/ClosePcScreenAction.h b/heimdall/source/ClosePcScreenAction.h index 6f167ca..a3def99 100644 --- a/heimdall/source/ClosePcScreenAction.h +++ b/heimdall/source/ClosePcScreenAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/ControlPacket.h b/heimdall/source/ControlPacket.h index 99169b7..78785f8 100644 --- a/heimdall/source/ControlPacket.h +++ b/heimdall/source/ControlPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DetectAction.cpp b/heimdall/source/DetectAction.cpp index 13d8ea1..2139b27 100644 --- a/heimdall/source/DetectAction.cpp +++ b/heimdall/source/DetectAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DetectAction.h b/heimdall/source/DetectAction.h index d71d396..b706db6 100644 --- a/heimdall/source/DetectAction.h +++ b/heimdall/source/DetectAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DeviceTypePacket.h b/heimdall/source/DeviceTypePacket.h index 6721bc6..4c2dc2a 100644 --- a/heimdall/source/DeviceTypePacket.h +++ b/heimdall/source/DeviceTypePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp index 43325eb..845283c 100644 --- a/heimdall/source/DownloadPitAction.cpp +++ b/heimdall/source/DownloadPitAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DownloadPitAction.h b/heimdall/source/DownloadPitAction.h index b9bfd2d..6c5f6c3 100644 --- a/heimdall/source/DownloadPitAction.h +++ b/heimdall/source/DownloadPitAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DumpPartFileTransferPacket.h b/heimdall/source/DumpPartFileTransferPacket.h index 229927d..3c0a922 100644 --- a/heimdall/source/DumpPartFileTransferPacket.h +++ b/heimdall/source/DumpPartFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DumpPartPitFilePacket.h b/heimdall/source/DumpPartPitFilePacket.h index 343c339..1190a06 100644 --- a/heimdall/source/DumpPartPitFilePacket.h +++ b/heimdall/source/DumpPartPitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/DumpResponse.h b/heimdall/source/DumpResponse.h index 060dfc3..6777ce1 100644 --- a/heimdall/source/DumpResponse.h +++ b/heimdall/source/DumpResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/EndFileTransferPacket.h b/heimdall/source/EndFileTransferPacket.h index 9ae4a44..bb312da 100644 --- a/heimdall/source/EndFileTransferPacket.h +++ b/heimdall/source/EndFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/EndModemFileTransferPacket.h b/heimdall/source/EndModemFileTransferPacket.h index 2a42880..f0489a5 100644 --- a/heimdall/source/EndModemFileTransferPacket.h +++ b/heimdall/source/EndModemFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/EndPhoneFileTransferPacket.h b/heimdall/source/EndPhoneFileTransferPacket.h index 803ce73..5ab21b4 100644 --- a/heimdall/source/EndPhoneFileTransferPacket.h +++ b/heimdall/source/EndPhoneFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/EndPitFileTransferPacket.h b/heimdall/source/EndPitFileTransferPacket.h index 9dddcb0..378ab00 100644 --- a/heimdall/source/EndPitFileTransferPacket.h +++ b/heimdall/source/EndPitFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/EndSessionPacket.h b/heimdall/source/EndSessionPacket.h index 5ac2c5a..52cea50 100644 --- a/heimdall/source/EndSessionPacket.h +++ b/heimdall/source/EndSessionPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FilePartSizePacket.h b/heimdall/source/FilePartSizePacket.h index 42b9525..c346fad 100644 --- a/heimdall/source/FilePartSizePacket.h +++ b/heimdall/source/FilePartSizePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FileTransferPacket.h b/heimdall/source/FileTransferPacket.h index c7a2f6b..3dd18a2 100644 --- a/heimdall/source/FileTransferPacket.h +++ b/heimdall/source/FileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index b528597..e528680 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FlashAction.h b/heimdall/source/FlashAction.h index 7c41136..d837374 100644 --- a/heimdall/source/FlashAction.h +++ b/heimdall/source/FlashAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FlashPartFileTransferPacket.h b/heimdall/source/FlashPartFileTransferPacket.h index 1824467..861a2f9 100644 --- a/heimdall/source/FlashPartFileTransferPacket.h +++ b/heimdall/source/FlashPartFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/FlashPartPitFilePacket.h b/heimdall/source/FlashPartPitFilePacket.h index c6ea41a..b893c92 100644 --- a/heimdall/source/FlashPartPitFilePacket.h +++ b/heimdall/source/FlashPartPitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index 5a5b4c6..ce7aaea 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/HelpAction.cpp b/heimdall/source/HelpAction.cpp index e2f9bdb..a95dd18 100644 --- a/heimdall/source/HelpAction.cpp +++ b/heimdall/source/HelpAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/HelpAction.h b/heimdall/source/HelpAction.h index 83e1d37..bb27790 100644 --- a/heimdall/source/HelpAction.h +++ b/heimdall/source/HelpAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/InboundPacket.h b/heimdall/source/InboundPacket.h index f929297..d42a6bc 100644 --- a/heimdall/source/InboundPacket.h +++ b/heimdall/source/InboundPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/InfoAction.cpp b/heimdall/source/InfoAction.cpp index e60758a..dc1a1af 100644 --- a/heimdall/source/InfoAction.cpp +++ b/heimdall/source/InfoAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/InfoAction.h b/heimdall/source/InfoAction.h index ae5d445..6727502 100644 --- a/heimdall/source/InfoAction.h +++ b/heimdall/source/InfoAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp index b070dad..4a300ca 100644 --- a/heimdall/source/Interface.cpp +++ b/heimdall/source/Interface.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -46,7 +46,7 @@ const char *version = "v1.4.1"; const char *actionUsage = "Usage: heimdall \n"; const char *releaseInfo = "Heimdall %s\n\n\ -Copyright (c) 2010-2013, Benjamin Dobell, Glass Echidna\n\ +Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna\n\ http://www.glassechidna.com.au/\n\n\ This software is provided free of charge. Copying and redistribution is\nencouraged.\n\n\ If you appreciate this software and you would like to support future\ndevelopment please consider donating:\n\ diff --git a/heimdall/source/Interface.h b/heimdall/source/Interface.h index 27d08c8..e4c89d7 100644 --- a/heimdall/source/Interface.h +++ b/heimdall/source/Interface.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/OutboundPacket.h b/heimdall/source/OutboundPacket.h index 50fb9d3..77f562e 100644 --- a/heimdall/source/OutboundPacket.h +++ b/heimdall/source/OutboundPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Packet.h b/heimdall/source/Packet.h index b571ae4..43007d9 100644 --- a/heimdall/source/Packet.h +++ b/heimdall/source/Packet.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/PitFilePacket.h b/heimdall/source/PitFilePacket.h index 7bc32fb..f2f27db 100644 --- a/heimdall/source/PitFilePacket.h +++ b/heimdall/source/PitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/PitFileResponse.h b/heimdall/source/PitFileResponse.h index 68fd7ed..b993b2f 100644 --- a/heimdall/source/PitFileResponse.h +++ b/heimdall/source/PitFileResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 4ed6e6c..05f6de7 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/PrintPitAction.h b/heimdall/source/PrintPitAction.h index f672375..948f0bd 100644 --- a/heimdall/source/PrintPitAction.h +++ b/heimdall/source/PrintPitAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/ReceiveFilePartPacket.h b/heimdall/source/ReceiveFilePartPacket.h index a07549b..8dc8321 100644 --- a/heimdall/source/ReceiveFilePartPacket.h +++ b/heimdall/source/ReceiveFilePartPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/ResponsePacket.h b/heimdall/source/ResponsePacket.h index 9883852..9463333 100644 --- a/heimdall/source/ResponsePacket.h +++ b/heimdall/source/ResponsePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h index a553a65..6bbc086 100644 --- a/heimdall/source/SendFilePartPacket.h +++ b/heimdall/source/SendFilePartPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/SendFilePartResponse.h b/heimdall/source/SendFilePartResponse.h index 3cfc91c..763d2d2 100644 --- a/heimdall/source/SendFilePartResponse.h +++ b/heimdall/source/SendFilePartResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/SessionSetupPacket.h b/heimdall/source/SessionSetupPacket.h index b8353bd..055e701 100644 --- a/heimdall/source/SessionSetupPacket.h +++ b/heimdall/source/SessionSetupPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/SessionSetupResponse.h b/heimdall/source/SessionSetupResponse.h index 9647219..0fb2de5 100644 --- a/heimdall/source/SessionSetupResponse.h +++ b/heimdall/source/SessionSetupResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/TotalBytesPacket.h b/heimdall/source/TotalBytesPacket.h index 79a02b5..35e9f29 100644 --- a/heimdall/source/TotalBytesPacket.h +++ b/heimdall/source/TotalBytesPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Utility.cpp b/heimdall/source/Utility.cpp index d8947d2..2256cf5 100644 --- a/heimdall/source/Utility.cpp +++ b/heimdall/source/Utility.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/Utility.h b/heimdall/source/Utility.h index 195ecf0..0008319 100644 --- a/heimdall/source/Utility.h +++ b/heimdall/source/Utility.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/VersionAction.cpp b/heimdall/source/VersionAction.cpp index 6121cad..36edd4e 100644 --- a/heimdall/source/VersionAction.cpp +++ b/heimdall/source/VersionAction.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/VersionAction.h b/heimdall/source/VersionAction.h index 20457b5..9a1e6ce 100644 --- a/heimdall/source/VersionAction.h +++ b/heimdall/source/VersionAction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/heimdall/source/main.cpp b/heimdall/source/main.cpp index b7ae47b..b5d44d0 100644 --- a/heimdall/source/main.cpp +++ b/heimdall/source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2013 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal -- cgit v1.1 From 9b56396ba19617b70ebde5f5072ad8b401697e50 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Wed, 7 May 2014 00:23:19 +1000 Subject: It would seem that messing around with line coding etc. is not necessary. --- heimdall/source/BridgeManager.cpp | 94 +-------------------------------------- heimdall/source/BridgeManager.h | 11 ----- 2 files changed, 1 insertion(+), 104 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 1559a70..44e3c0c 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -306,102 +306,10 @@ void BridgeManager::ReleaseDeviceInterface(void) Interface::Print("\n"); } -enum -{ - kControlRequestSetLineCoding = 0x20, - kControlRequestSetControlLineState = 0x22 -}; - - -enum -{ - kLineCodingCharFormatZeroToOneStopBit = 0, - kLineCodingCharFormatOneToOneAndAHalfStopBits = 1, - kLineCodingCharFormatTwoToTwoAndAHalfStopBits = 2 -}; - -enum -{ - kParityTypeNone = 0, - kParityTypeOdd = 1, - kParityTypeEven = 2, - kParityTypeMark = 3, - kParityTypeSpace = 4 -}; - -bool BridgeManager::SetControlLineState(unsigned short controlSignalFlags) -{ - int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, kControlRequestSetControlLineState, controlSignalFlags, 0, nullptr, 0, 1000); - - if (result != LIBUSB_SUCCESS) - { - if (verbose) - Interface::PrintWarning("Control line state (signal flags: 0x%x) transfer failed. Result: %d\n", controlSignalFlags, result); - - return (false); - } - else - { - return (true); - } -} - -bool BridgeManager::SetControlLineCoding(LineCoding lineCoding) -{ - unsigned char dataBuffer[7]; - - dataBuffer[0] = lineCoding.dteRate & 0xFF; - dataBuffer[1] = (lineCoding.dteRate >> 8) & 0xFF; - dataBuffer[2] = (lineCoding.dteRate >> 16) & 0xFF; - dataBuffer[3] = (lineCoding.dteRate >> 24) & 0xFF; - dataBuffer[4] = lineCoding.charFormat; - dataBuffer[5] = lineCoding.parityType; - dataBuffer[6] = lineCoding.dataBits; - - int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, kControlRequestSetLineCoding, 0x0, 0, dataBuffer, 7, 1000); - - if (result != LIBUSB_SUCCESS) - { - if (verbose) - Interface::PrintWarning("Setting control line coding failed. Result: %d\n", result); - - return (false); - } - else - { - return (true); - } -} - -enum -{ - kLineStateControlSignalDtePresent = 1, - kLineStateControlSignalCarrierControl = 1 << 1 -}; - bool BridgeManager::InitialiseProtocol(void) { Interface::Print("Initialising protocol...\n"); - /*LineCoding lineCoding; - - lineCoding.dteRate = 115200; - lineCoding.charFormat = kLineCodingCharFormatZeroToOneStopBit; - lineCoding.parityType = kParityTypeNone; - lineCoding.dataBits = 7; - - SetControlLineState(kLineStateControlSignalDtePresent | kLineStateControlSignalCarrierControl); - SetControlLineCoding(lineCoding); - SetControlLineState(kLineStateControlSignalDtePresent | kLineStateControlSignalCarrierControl); - SetControlLineState(kLineStateControlSignalCarrierControl); - - lineCoding.dataBits = 8; - SetControlLineCoding(lineCoding); - - SetControlLineState(kLineStateControlSignalCarrierControl);*/ - - int dataTransferred = 0; - unsigned char dataBuffer[7]; // Send "ODIN" @@ -417,7 +325,7 @@ bool BridgeManager::InitialiseProtocol(void) memset(dataBuffer, 0, 7); int retry = 0; - dataTransferred = 0; + int dataTransferred = 0; int result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 04b03c3..9ebbdae 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -89,14 +89,6 @@ namespace Heimdall Default = Error }; - typedef struct - { - unsigned int dteRate; - unsigned char charFormat; - unsigned char parityType; - unsigned char dataBits; - } LineCoding; - private: static const DeviceIdentifier supportedDevices[kSupportedDeviceCount]; @@ -133,9 +125,6 @@ namespace Heimdall bool InitialiseProtocol(void); - bool SetControlLineState(unsigned short controlSignalFlags); - bool SetControlLineCoding(LineCoding lineCoding); - bool SendBulkTransfer(unsigned char *data, int length, int timeout = 3000, bool retry = true) const; public: -- cgit v1.1 From ce486f7ecbf4259e5cf401c16a175e63046d73c8 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Wed, 7 May 2014 06:48:00 +1000 Subject: Removed a few unused variables. --- heimdall/source/BridgeManager.cpp | 1 - heimdall/source/FlashAction.cpp | 1 - heimdall/source/ResponsePacket.h | 2 -- 3 files changed, 4 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 44e3c0c..7db00d5 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -324,7 +324,6 @@ bool BridgeManager::InitialiseProtocol(void) // Expect "LOKE" memset(dataBuffer, 0, 7); - int retry = 0; int dataTransferred = 0; int result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index e528680..2ceaa3e 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -100,7 +100,6 @@ static bool openFiles(Arguments& arguments, vector& partitionFile for (vector::const_iterator it = arguments.GetArguments().begin(); it != arguments.GetArguments().end(); it++) { - bool isPartitionArgument = false; const string& argumentName = (*it)->GetName(); // The only way an argument could exist without being in the argument types map is if it's a wild-card. diff --git a/heimdall/source/ResponsePacket.h b/heimdall/source/ResponsePacket.h index 9463333..d0769af 100644 --- a/heimdall/source/ResponsePacket.h +++ b/heimdall/source/ResponsePacket.h @@ -64,8 +64,6 @@ namespace Heimdall virtual bool Unpack(void) { - const unsigned char *data = GetData(); - unsigned int receivedResponseType = UnpackInteger(0); if (receivedResponseType != responseType) { -- cgit v1.1 From d5cd49b73c3dfaf5b1188030a6bc9fc597edae8a Mon Sep 17 00:00:00 2001 From: Martin Willers Date: Thu, 8 May 2014 12:32:56 +0200 Subject: fix --stdout-errors handling When using --stdout-errors, the messages written to stdout contained garbage. Inside vfprintf(), each va_arg() consumes one entry from the va_args. Trying to use the same va_args variable again results in undefined behavior as subsequent va_arg() invocations continue to read from memory past the actual variable space. Instead, a copy has to be made with va_copy() and this be used for outputting to stdout. --- heimdall/source/Interface.cpp | 72 +++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 30 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp index 4a300ca..fd989fa 100644 --- a/heimdall/source/Interface.cpp +++ b/heimdall/source/Interface.cpp @@ -92,74 +92,86 @@ void Interface::Print(const char *format, ...) void Interface::PrintWarning(const char *format, ...) { - va_list args; - va_start(args, format); - - fprintf(stderr, "WARNING: "); - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); fprintf(stdout, "WARNING: "); - vfprintf(stdout, format, args); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + fprintf(stderr, "WARNING: "); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintWarningSameLine(const char *format, ...) { - va_list args; - va_start(args, format); - - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { - vfprintf(stdout, format, args); + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintError(const char *format, ...) { - va_list args; - va_start(args, format); - - fprintf(stderr, "ERROR: "); - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); fprintf(stdout, "ERROR: "); - vfprintf(stdout, format, args); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + fprintf(stderr, "ERROR: "); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintErrorSameLine(const char *format, ...) { - va_list args; - va_start(args, format); - - vfprintf(stderr, format, args); - fflush(stderr); + va_list stderrArgs; + va_start(stderrArgs, format); if (stdoutErrors) { - vfprintf(stdout, format, args); + va_list stdoutArgs; + va_copy(stdoutArgs, stderrArgs); + vfprintf(stdout, format, stdoutArgs); fflush(stdout); + va_end(stdoutArgs); } - va_end(args); + vfprintf(stderr, format, stderrArgs); + fflush(stderr); + + va_end(stderrArgs); } void Interface::PrintVersion(void) -- cgit v1.1 From 150e3344de8a6e63d968db1011b73407c3fa9d0e Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 11 May 2014 19:18:59 +1000 Subject: Fixed header guard typo. --- heimdall/source/TotalBytesPacket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'heimdall/source') diff --git a/heimdall/source/TotalBytesPacket.h b/heimdall/source/TotalBytesPacket.h index 35e9f29..a3b0d27 100644 --- a/heimdall/source/TotalBytesPacket.h +++ b/heimdall/source/TotalBytesPacket.h @@ -18,7 +18,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ -#ifndef TOTALBYTESSPACKET_H +#ifndef TOTALBYTESPACKET_H #define TOTALBYTESPACKET_H // Heimdall -- cgit v1.1 From e6fdafd4829842d96eefa3163b6149265819fe95 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 11 May 2014 19:26:26 +1000 Subject: Fixed help output alignment. --- heimdall/source/ClosePcScreenAction.cpp | 2 +- heimdall/source/DownloadPitAction.cpp | 2 +- heimdall/source/FlashAction.cpp | 14 +++++++------- heimdall/source/PrintPitAction.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/ClosePcScreenAction.cpp b/heimdall/source/ClosePcScreenAction.cpp index 1a3387c..edc7157 100644 --- a/heimdall/source/ClosePcScreenAction.cpp +++ b/heimdall/source/ClosePcScreenAction.cpp @@ -34,7 +34,7 @@ Arguments: [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ Description: Attempts to get rid off the \"connect phone to PC\" screen.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag."; + download mode, then the following action must specify the --resume flag."; int ClosePcScreenAction::Execute(int argc, char **argv) { diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp index 845283c..0bde9d8 100644 --- a/heimdall/source/DownloadPitAction.cpp +++ b/heimdall/source/DownloadPitAction.cpp @@ -38,7 +38,7 @@ Description: Downloads the connected device's PIT file to the specified\n\ output file.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag."; + download mode, then the following action must specify the --resume flag."; int DownloadPitAction::Execute(int argc, char **argv) { diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index 2ceaa3e..aa08ed8 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -39,19 +39,19 @@ using namespace Heimdall; const char *FlashAction::usage = "Action: flash\n\ Arguments:\n\ - [-- ...]\n\ - [-- ...]\n\ - [--pit ] [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ - [--usb-log-level ]\n\ + [-- ...]\n\ + [-- ...]\n\ + [--pit ] [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ + [--usb-log-level ]\n\ or:\n\ --repartition --pit [-- ...]\n\ - [-- ...] [--verbose] [--no-reboot]\n\ - [--resume] [--stdout-errors] [--usb-log-level ]\n\ + [-- ...] [--verbose] [--no-reboot]\n\ + [--resume] [--stdout-errors] [--usb-log-level ]\n\ Description: Flashes one or more firmware files to your phone. Partition names\n\ (or identifiers) can be obtained by executing the print-pit action.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag.\n\ + download mode, then the following action must specify the --resume flag.\n\ WARNING: If you're repartitioning it's strongly recommended you specify\n\ all files at your disposal.\n"; diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 05f6de7..01f57aa 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -40,7 +40,7 @@ Description: Prints the contents of a PIT file in a human readable format. If\n\ connected device.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag."; + download mode, then the following action must specify the --resume flag."; int PrintPitAction::Execute(int argc, char **argv) { -- cgit v1.1 From abea6dbbe0456c374b7889d61902023178beb09b Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Thu, 15 May 2014 00:59:13 +1000 Subject: Added missing new lines to CLI help output. --- heimdall/source/ClosePcScreenAction.cpp | 2 +- heimdall/source/DownloadPitAction.cpp | 2 +- heimdall/source/PrintPitAction.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/ClosePcScreenAction.cpp b/heimdall/source/ClosePcScreenAction.cpp index edc7157..16e30aa 100644 --- a/heimdall/source/ClosePcScreenAction.cpp +++ b/heimdall/source/ClosePcScreenAction.cpp @@ -34,7 +34,7 @@ Arguments: [--verbose] [--no-reboot] [--resume] [--stdout-errors]\n\ Description: Attempts to get rid off the \"connect phone to PC\" screen.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag."; + download mode, then the following action must specify the --resume flag.\n"; int ClosePcScreenAction::Execute(int argc, char **argv) { diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp index 0bde9d8..000844e 100644 --- a/heimdall/source/DownloadPitAction.cpp +++ b/heimdall/source/DownloadPitAction.cpp @@ -38,7 +38,7 @@ Description: Downloads the connected device's PIT file to the specified\n\ output file.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag."; + download mode, then the following action must specify the --resume flag.\n"; int DownloadPitAction::Execute(int argc, char **argv) { diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 01f57aa..781973d 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -40,7 +40,7 @@ Description: Prints the contents of a PIT file in a human readable format. If\n\ connected device.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ - download mode, then the following action must specify the --resume flag."; + download mode, then the following action must specify the --resume flag.\n"; int PrintPitAction::Execute(int argc, char **argv) { -- cgit v1.1 From b62d66b297ab0401818a4d723d5206d03e5f9bca Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sat, 17 May 2014 04:36:51 +1000 Subject: Windows does not provide (or require) va_copy. --- heimdall/source/Heimdall.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'heimdall/source') diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index ce7aaea..5e348c4 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -26,6 +26,10 @@ #include #undef GetBinaryType +#ifndef va_copy +#define va_copy(d, s) ((d) = (s)) +#endif + #else #include "../config.h" -- cgit v1.1 From fd23c07ef525f836d4974189ae5c7f3ecb0bb640 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 18 May 2014 04:18:36 +1000 Subject: Removed unused optional parameters in BridgeManager. --- heimdall/source/BridgeManager.cpp | 35 +++++++++++++---------------------- heimdall/source/BridgeManager.h | 6 +++--- 2 files changed, 16 insertions(+), 25 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 7db00d5..719d041 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -624,12 +624,12 @@ bool BridgeManager::EndSession(bool reboot) const return (true); } -bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const +bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeout) const { int dataTransferred; int result = libusb_bulk_transfer(deviceHandle, outEndpoint, data, length, &dataTransferred, timeout); - if (result != LIBUSB_SUCCESS && retry) + if (result != LIBUSB_SUCCESS) { static const int retryDelay = 250; @@ -661,39 +661,33 @@ bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeou return (result == LIBUSB_SUCCESS && dataTransferred == length); } -bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, bool retry) const +bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout) const { packet->Pack(); - if (!SendBulkTransfer(packet->GetData(), packet->GetSize(), timeout, retry)) + 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, retry)) + if (!SendBulkTransfer(nullptr, 0, timeout)) return (false); return (true); } -bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, bool retry, unsigned char *buffer, unsigned int bufferSize) const +bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout) const { - bool bufferProvided = buffer != nullptr && bufferSize >= packet->GetSize(); - - if (!bufferProvided) - { - buffer = packet->GetData(); - bufferSize = packet->GetSize(); - } + unsigned char *buffer = packet->GetData(); + unsigned int bufferSize = packet->GetSize(); int dataTransferred; int result; unsigned int attempt = 0; - unsigned int maxAttempts = (retry) ? kReceivePacketMaxAttempts : 1; - + static const int retryDelay = 250; - for (; attempt < maxAttempts; attempt++) + for (; attempt < kReceivePacketMaxAttempts; attempt++) { if (attempt > 0) { @@ -716,7 +710,7 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, bool retry if (verbose && attempt > 0) Interface::PrintErrorSameLine("\n"); - if (attempt == maxAttempts) + if (attempt == kReceivePacketMaxAttempts) return (false); if (dataTransferred != packet->GetSize() && !packet->IsSizeVariable()) @@ -727,9 +721,6 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, bool retry return (false); } - if (bufferProvided) - memcpy(packet->GetData(), buffer, dataTransferred); - packet->SetReceivedSize(dataTransferred); bool unpacked = packet->Unpack(); @@ -1170,7 +1161,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceByteCount, 0, deviceType, fileIdentifier, isLastSequence); - success = SendPacket(endPhoneFileTransferPacket, 3000); + success = SendPacket(endPhoneFileTransferPacket); delete endPhoneFileTransferPacket; if (!success) @@ -1184,7 +1175,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceByteCount, 0, deviceType, isLastSequence); - success = SendPacket(endModemFileTransferPacket, 3000); + success = SendPacket(endModemFileTransferPacket); delete endModemFileTransferPacket; if (!success) diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 9ebbdae..6b967fa 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -125,7 +125,7 @@ namespace Heimdall bool InitialiseProtocol(void); - bool SendBulkTransfer(unsigned char *data, int length, int timeout = 3000, bool retry = true) const; + bool SendBulkTransfer(unsigned char *data, int length, int timeout = 3000) const; public: @@ -138,8 +138,8 @@ namespace Heimdall bool BeginSession(void); bool EndSession(bool reboot) const; - bool SendPacket(OutboundPacket *packet, int timeout = 3000, bool retry = true) const; - bool ReceivePacket(InboundPacket *packet, int timeout = 3000, bool retry = true, unsigned char *buffer = nullptr, unsigned int bufferSize = -1) const; + bool SendPacket(OutboundPacket *packet, int timeout = 3000) const; + bool ReceivePacket(InboundPacket *packet, int timeout = 3000) const; bool RequestDeviceType(unsigned int request, int *result) const; -- cgit v1.1 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(-) (limited to 'heimdall/source') 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 From 7d6ddcd5d54e30e7437f0ba1aa4676224e68bf6a Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sat, 31 May 2014 12:05:02 +1000 Subject: Give devices some leeway to handle empty bulk transfers. --- heimdall/source/BridgeManager.cpp | 16 ++++++++++------ heimdall/source/BridgeManager.h | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index a2cba80..96c22fb 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -624,12 +624,12 @@ bool BridgeManager::EndSession(bool reboot) const return (true); } -bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeout) const +bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const { int dataTransferred; int result = libusb_bulk_transfer(deviceHandle, outEndpoint, data, length, &dataTransferred, timeout); - if (result != LIBUSB_SUCCESS) + if (result != LIBUSB_SUCCESS && retry) { static const int retryDelay = 250; @@ -667,8 +667,10 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int sendEmpt if (sendEmptyTransferFlags & kSendEmptyTransferBefore) { - if (!SendBulkTransfer(nullptr, 0, timeout)) - return (false); + if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutSendEmptyTransfer, false) && verbose) + { + Interface::PrintWarning("Empty bulk transfer before sending packet failed. Continuing anyway...\n"); + } } if (!SendBulkTransfer(packet->GetData(), packet->GetSize(), timeout)) @@ -676,8 +678,10 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int sendEmpt if (sendEmptyTransferFlags & kSendEmptyTransferAfter) { - if (!SendBulkTransfer(nullptr, 0, timeout)) - return (false); + if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutSendEmptyTransfer, false) && verbose) + { + Interface::PrintWarning("Empty bulk transfer after sending packet failed. Continuing anyway...\n"); + } } return (true); diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index 7028003..e85dc87 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -81,7 +81,8 @@ namespace Heimdall enum { kDefaultTimeoutSend = 3000, - kDefaultTimeoutReceive = 3000 + kDefaultTimeoutReceive = 3000, + kDefaultTimeoutSendEmptyTransfer = 100 }; enum class UsbLogLevel @@ -139,7 +140,7 @@ namespace Heimdall bool InitialiseProtocol(void); - bool SendBulkTransfer(unsigned char *data, int length, int timeout) const; + bool SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry = true) const; public: -- cgit v1.1 From 46d9a51e18d260e416479432fec50c6e601eb3ce Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 1 Jun 2014 13:12:07 +1000 Subject: Fixed file transfer sequence bug --- heimdall/source/BridgeManager.cpp | 16 +++++++--------- heimdall/source/SendFilePartPacket.h | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 96c22fb..32807ca 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -1040,14 +1040,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { bool isLastSequence = (sequenceIndex == sequenceCount - 1); unsigned int sequenceSize = (isLastSequence) ? lastSequenceSize : fileTransferSequenceMaxLength; - unsigned int sequenceByteCount; + unsigned int sequenceTotalByteCount = sequenceSize * fileTransferPacketSize; - if (isLastSequence) - sequenceByteCount = ((partialPacketByteCount) ? lastSequenceSize - 1 : lastSequenceSize) * fileTransferPacketSize + partialPacketByteCount; - else - sequenceByteCount = fileTransferSequenceMaxLength * fileTransferPacketSize; - - FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(sequenceByteCount); + FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(sequenceTotalByteCount); success = SendPacket(beginFileTransferPacket); delete beginFileTransferPacket; @@ -1169,9 +1164,12 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int previousPercent = currentPercent; } + unsigned int sequenceEffectiveByteCount = (isLastSequence && partialPacketByteCount != 0) ? + fileTransferPacketSize * (lastSequenceSize - 1) + partialPacketByteCount : sequenceTotalByteCount; + if (destination == EndFileTransferPacket::kDestinationPhone) { - EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceByteCount, 0, deviceType, fileIdentifier, isLastSequence); + EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceEffectiveByteCount, 0, deviceType, fileIdentifier, isLastSequence); success = SendPacket(endPhoneFileTransferPacket, kDefaultTimeoutSend, kSendEmptyTransferBeforeAndAfter); delete endPhoneFileTransferPacket; @@ -1185,7 +1183,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int } else // destination == EndFileTransferPacket::kDestinationModem { - EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceByteCount, 0, deviceType, isLastSequence); + EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceEffectiveByteCount, 0, deviceType, isLastSequence); success = SendPacket(endModemFileTransferPacket, kDefaultTimeoutSend, kSendEmptyTransferBeforeAndAfter); delete endModemFileTransferPacket; diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h index 6bbc086..3ecaa89 100644 --- a/heimdall/source/SendFilePartPacket.h +++ b/heimdall/source/SendFilePartPacket.h @@ -34,7 +34,7 @@ namespace Heimdall { public: - SendFilePartPacket(FILE *file, int size) : OutboundPacket(size) + SendFilePartPacket(FILE *file, unsigned int size) : OutboundPacket(size) { memset(data, 0, size); @@ -45,13 +45,13 @@ namespace Heimdall fseek(file, position, SEEK_SET); // min(fileSize, size) - int bytesToRead = (fileSize < size) ? fileSize - position : size; + unsigned int bytesToRead = (fileSize < size) ? fileSize - position : size; // bytesRead is discarded (it's just there to stop GCC warnings) - int bytesRead = fread(data, 1, bytesToRead, file); + unsigned int bytesRead = fread(data, 1, bytesToRead, file); } - SendFilePartPacket(unsigned char *buffer, int size) : OutboundPacket(size) + SendFilePartPacket(unsigned char *buffer, unsigned int size) : OutboundPacket(size) { memcpy(data, buffer, size); } -- cgit v1.1 From 082fb091f1a0cab9d00e82de54fee32b6a1c0c7b Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 1 Jun 2014 14:09:56 +1000 Subject: Fixed support for large files (up to 2^32 - 1 bytes) The Loke protocol supports 32-bit unsigned for the size of files being flashed. However, POSIX file commands only support 32-bit (signed). As such we now have platform specific support for larger files. --- heimdall/source/BridgeManager.cpp | 10 +++++----- heimdall/source/DownloadPitAction.cpp | 6 +++--- heimdall/source/FlashAction.cpp | 36 +++++++++++++++++------------------ heimdall/source/Heimdall.h | 13 +++++++++++++ heimdall/source/PrintPitAction.cpp | 10 +++++----- heimdall/source/SendFilePartPacket.h | 8 ++++---- 6 files changed, 48 insertions(+), 35 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 32807ca..dc2926a 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -1002,9 +1002,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int return (false); } - fseek(file, 0, SEEK_END); - long fileSize = ftell(file); - rewind(file); + FileSeek(file, 0, SEEK_END); + unsigned int fileSize = (unsigned int)FileTell(file); + FileRewind(file); ResponsePacket *fileTransferResponse = new ResponsePacket(ResponsePacket::kResponseTypeFileTransfer); success = ReceivePacket(fileTransferResponse); @@ -1031,7 +1031,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int lastSequenceSize++; } - long bytesTransferred = 0; + unsigned int bytesTransferred = 0; unsigned int currentPercent; unsigned int previousPercent = 0; Interface::Print("0%%"); @@ -1144,7 +1144,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int if (bytesTransferred > fileSize) bytesTransferred = fileSize; - currentPercent = (int)(100.0f * ((float)bytesTransferred / (float)fileSize)); + currentPercent = (unsigned int)(100.0 * ((double)bytesTransferred / (double)fileSize)); if (currentPercent != previousPercent) { diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp index 000844e..841afd2 100644 --- a/heimdall/source/DownloadPitAction.cpp +++ b/heimdall/source/DownloadPitAction.cpp @@ -120,7 +120,7 @@ int DownloadPitAction::Execute(int argc, char **argv) // Open output file const char *outputFilename = outputArgument->GetValue().c_str(); - FILE *outputPitFile = fopen(outputFilename, "wb"); + FILE *outputPitFile = FileOpen(outputFilename, "wb"); if (!outputPitFile) { @@ -135,7 +135,7 @@ int DownloadPitAction::Execute(int argc, char **argv) if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession()) { - fclose(outputPitFile); + FileClose(outputPitFile); delete bridgeManager; return (1); @@ -164,7 +164,7 @@ int DownloadPitAction::Execute(int argc, char **argv) delete bridgeManager; - fclose(outputPitFile); + FileClose(outputPitFile); delete [] pitBuffer; return (success ? 0 : 1); diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index aa08ed8..590e0b5 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -87,7 +87,7 @@ static bool openFiles(Arguments& arguments, vector& partitionFile if (pitArgument) { - pitFile = fopen(pitArgument->GetValue().c_str(), "rb"); + pitFile = FileOpen(pitArgument->GetValue().c_str(), "rb"); if (!pitFile) { @@ -109,7 +109,7 @@ static bool openFiles(Arguments& arguments, vector& partitionFile if (arguments.GetArgumentTypes().find(argumentName) == arguments.GetArgumentTypes().end()) { const StringArgument *stringArgument = static_cast(*it); - FILE *file = fopen(stringArgument->GetValue().c_str(), "rb"); + FILE *file = FileOpen(stringArgument->GetValue().c_str(), "rb"); if (!file) { @@ -130,34 +130,34 @@ static void closeFiles(vector& partitionFiles, FILE *& pitFile) if (pitFile) { - fclose(pitFile); + FileClose(pitFile); pitFile = nullptr; } // Close partition files for (vector::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++) - fclose(it->file); + FileClose(it->file); partitionFiles.clear(); } static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector& partitionFiles, FILE *pitFile, bool repartition) { - int totalBytes = 0; + unsigned int totalBytes = 0; for (vector::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++) { - fseek(it->file, 0, SEEK_END); - totalBytes += ftell(it->file); - rewind(it->file); + FileSeek(it->file, 0, SEEK_END); + totalBytes += (unsigned int)FileTell(it->file); + FileRewind(it->file); } if (repartition) { - fseek(pitFile, 0, SEEK_END); - totalBytes += ftell(pitFile); - rewind(pitFile); + FileSeek(pitFile, 0, SEEK_END); + totalBytes += (unsigned int)FileTell(pitFile); + FileRewind(pitFile); } bool success; @@ -168,7 +168,7 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector 0) { - rewind(pitFile); + FileRewind(pitFile); localPitData = new PitData(); localPitData->Unpack(pitFileBuffer); diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index 5e348c4..3982dd4 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -30,6 +30,12 @@ #define va_copy(d, s) ((d) = (s)) #endif +#define FileOpen(FILE, MODE) fopen(FILE, MODE) +#define FileClose(FILE) fclose(FILE) +#define FileSeek(FILE, OFFSET, ORIGIN) _fseeki64(FILE, OFFSET, ORIGIN) +#define FileTell(FILE) _ftelli64(FILE) +#define FileRewind(FILE) rewind(FILE) + #else #include "../config.h" @@ -37,6 +43,13 @@ #if defined(OS_DARWIN) || defined(OS_LINUX) #include #define Sleep(t) usleep(1000*t) + +#define FileOpen(FILE, MODE) fopen(FILE, MODE) +#define FileClose(FILE) fclose(FILE) +#define FileSeek(FILE, OFFSET, ORIGIN) fseeko(FILE, OFFSET, ORIGIN) +#define FileTell(FILE) ftello(FILE) +#define FileRewind(FILE) rewind(FILE) + #else #error operating system not supported #endif diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 781973d..12c28d1 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -115,7 +115,7 @@ int PrintPitAction::Execute(int argc, char **argv) { const char *filename = fileArgument->GetValue().c_str(); - localPitFile = fopen(filename, "rb"); + localPitFile = FileOpen(filename, "rb"); if (!localPitFile) { @@ -133,14 +133,14 @@ int PrintPitAction::Execute(int argc, char **argv) { // Print PIT from file; there's no need for a BridgeManager. - fseek(localPitFile, 0, SEEK_END); - long localPitFileSize = ftell(localPitFile); - rewind(localPitFile); + FileSeek(localPitFile, 0, SEEK_END); + unsigned int localPitFileSize = (unsigned int)FileTell(localPitFile); + FileRewind(localPitFile); // Load the local pit file into memory. unsigned char *pitFileBuffer = new unsigned char[localPitFileSize]; size_t dataRead = fread(pitFileBuffer, 1, localPitFileSize, localPitFile); // dataRead is discarded, it's here to remove warnings. - fclose(localPitFile); + FileClose(localPitFile); PitData *pitData = new PitData(); pitData->Unpack(pitFileBuffer); diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h index 3ecaa89..38e9dbe 100644 --- a/heimdall/source/SendFilePartPacket.h +++ b/heimdall/source/SendFilePartPacket.h @@ -38,11 +38,11 @@ namespace Heimdall { memset(data, 0, size); - long position = ftell(file); + unsigned int position = (unsigned int)FileTell(file); - fseek(file, 0, SEEK_END); - long fileSize = ftell(file); - fseek(file, position, SEEK_SET); + FileSeek(file, 0, SEEK_END); + unsigned int fileSize = (unsigned int)FileTell(file); + FileSeek(file, position, SEEK_SET); // min(fileSize, size) unsigned int bytesToRead = (fileSize < size) ? fileSize - position : size; -- cgit v1.1 From d613a87cdb6b27bf5f36200295f926a91f8d27be Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sun, 6 Jul 2014 03:50:48 +1000 Subject: More empty transfer craziness, this time when receving packets It seems newer devices need more weird empty transfers in order to function. --- heimdall/source/BridgeManager.cpp | 125 +++++++++++++++++++++----------------- heimdall/source/BridgeManager.h | 15 ++--- 2 files changed, 76 insertions(+), 64 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index dc2926a..9b8fdfa 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -68,26 +68,11 @@ const DeviceIdentifier BridgeManager::supportedDevices[BridgeManager::kSupported enum { - kDumpBufferSize = 4096, -}; - -enum -{ kFileTransferSequenceMaxLengthDefault = 800, kFileTransferPacketSizeDefault = 131072, kFileTransferSequenceTimeoutDefault = 30000 // 30 seconds }; -enum -{ - kReceivePacketMaxAttempts = 5 -}; - -enum -{ - kPitSizeMultiplicand = 4096 -}; - int BridgeManager::FindDeviceInterface(void) { Interface::Print("Detecting device...\n"); @@ -661,13 +646,53 @@ bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeou return (result == LIBUSB_SUCCESS && dataTransferred == length); } -bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int sendEmptyTransferFlags) const +int BridgeManager::ReceiveBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const +{ + int dataTransferred; + int result = libusb_bulk_transfer(deviceHandle, inEndpoint, data, length, &dataTransferred, timeout); + + if (result != LIBUSB_SUCCESS && retry) + { + static const int retryDelay = 250; + + if (verbose) + Interface::PrintError("libusb error %d whilst receiving bulk transfer.", result); + + // Retry + for (int i = 0; i < 5; i++) + { + if (verbose) + Interface::PrintErrorSameLine(" Retrying...\n"); + + // Wait longer each retry + Sleep(retryDelay * (i + 1)); + + result = libusb_bulk_transfer(deviceHandle, inEndpoint, data, length, &dataTransferred, timeout); + + if (result == LIBUSB_SUCCESS) + break; + + if (verbose) + Interface::PrintError("libusb error %d whilst receiving bulk transfer.", result); + } + + if (verbose) + Interface::PrintErrorSameLine("\n"); + } + + if (result != LIBUSB_SUCCESS) + return (result); + + return (dataTransferred); +} + +bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int emptyTransferFlags) const { packet->Pack(); - if (sendEmptyTransferFlags & kSendEmptyTransferBefore) + if (emptyTransferFlags & kEmptyTransferBefore) { - if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutSendEmptyTransfer, false) && verbose) + if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) && verbose) { Interface::PrintWarning("Empty bulk transfer before sending packet failed. Continuing anyway...\n"); } @@ -676,9 +701,9 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int sendEmpt if (!SendBulkTransfer(packet->GetData(), packet->GetSize(), timeout)) return (false); - if (sendEmptyTransferFlags & kSendEmptyTransferAfter) + if (emptyTransferFlags & kEmptyTransferAfter) { - if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutSendEmptyTransfer, false) && verbose) + if (!SendBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) && verbose) { Interface::PrintWarning("Empty bulk transfer after sending packet failed. Continuing anyway...\n"); } @@ -687,59 +712,44 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout, int sendEmpt return (true); } -bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout) const +bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, int emptyTransferFlags) const { - unsigned char *buffer = packet->GetData(); - unsigned int bufferSize = packet->GetSize(); - - int dataTransferred; - int result; - - unsigned int attempt = 0; - - static const int retryDelay = 250; - - for (; attempt < kReceivePacketMaxAttempts; attempt++) + if (emptyTransferFlags & kEmptyTransferBefore) { - if (attempt > 0) + if (ReceiveBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) < 0 && verbose) { - if (verbose) - Interface::PrintErrorSameLine(" Retrying...\n"); - - // Wait longer each retry - Sleep(retryDelay * (attempt + 1)); + Interface::PrintWarning("Empty bulk transfer before receiving packet failed. Continuing anyway...\n"); } - - result = libusb_bulk_transfer(deviceHandle, inEndpoint, buffer, bufferSize, &dataTransferred, timeout); - - if (result >= 0) - break; - - if (verbose) - Interface::PrintError("libusb error %d whilst receiving packet.", result); } - if (verbose && attempt > 0) - Interface::PrintErrorSameLine("\n"); + int receivedSize = ReceiveBulkTransfer(packet->GetData(), packet->GetSize(), timeout); - if (attempt == kReceivePacketMaxAttempts) + if (receivedSize < 0) return (false); - if (dataTransferred != packet->GetSize() && !packet->IsSizeVariable()) + if (receivedSize != packet->GetSize() && !packet->IsSizeVariable()) { if (verbose) - Interface::PrintError("Incorrect packet size received - expected size = %d, received size = %d.\n", packet->GetSize(), dataTransferred); + Interface::PrintError("Incorrect packet size received - expected size = %d, received size = %d.\n", packet->GetSize(), receivedSize); return (false); } - packet->SetReceivedSize(dataTransferred); + packet->SetReceivedSize(receivedSize); bool unpacked = packet->Unpack(); if (!unpacked && verbose) Interface::PrintError("Failed to unpack received packet.\n"); + if (emptyTransferFlags & kEmptyTransferAfter) + { + if (ReceiveBulkTransfer(nullptr, 0, kDefaultTimeoutEmptyTransfer, false) < 0 && verbose) + { + Interface::PrintWarning("Empty bulk transfer after receiving packet failed. Continuing anyway...\n"); + } + } + return (unpacked); } @@ -903,7 +913,6 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const unsigned char *buffer = new unsigned char[fileSize]; int offset = 0; - // NOTE: The PIT file appears to always be padded out to exactly 4 kilobytes. for (unsigned int i = 0; i < transferCount; i++) { DumpPartPitFilePacket *requestPacket = new DumpPartPitFilePacket(i); @@ -916,9 +925,11 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const delete [] buffer; return (0); } + + int receiveEmptyTransferFlags = (i == transferCount - 1) ? kEmptyTransferAfter : kEmptyTransferNone; ReceiveFilePartPacket *receiveFilePartPacket = new ReceiveFilePartPacket(); - success = ReceivePacket(receiveFilePartPacket); + success = ReceivePacket(receiveFilePartPacket, receiveEmptyTransferFlags); if (!success) { @@ -1067,7 +1078,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int 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; + int sendEmptyTransferFlags = (filePartIndex == 0) ? kEmptyTransferNone : kEmptyTransferBefore; // Send SendFilePartPacket *sendFilePartPacket = new SendFilePartPacket(file, fileTransferPacketSize); @@ -1171,7 +1182,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceEffectiveByteCount, 0, deviceType, fileIdentifier, isLastSequence); - success = SendPacket(endPhoneFileTransferPacket, kDefaultTimeoutSend, kSendEmptyTransferBeforeAndAfter); + success = SendPacket(endPhoneFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferBeforeAndAfter); delete endPhoneFileTransferPacket; if (!success) @@ -1185,7 +1196,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceEffectiveByteCount, 0, deviceType, isLastSequence); - success = SendPacket(endModemFileTransferPacket, kDefaultTimeoutSend, kSendEmptyTransferBeforeAndAfter); + success = SendPacket(endModemFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferBeforeAndAfter); delete endModemFileTransferPacket; if (!success) diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index e85dc87..840fb5e 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -82,7 +82,7 @@ namespace Heimdall { kDefaultTimeoutSend = 3000, kDefaultTimeoutReceive = 3000, - kDefaultTimeoutSendEmptyTransfer = 100 + kDefaultTimeoutEmptyTransfer = 100 }; enum class UsbLogLevel @@ -98,10 +98,10 @@ namespace Heimdall enum { - kSendEmptyTransferNone = 0, - kSendEmptyTransferBefore = 1, - kSendEmptyTransferAfter = 1 << 1, - kSendEmptyTransferBeforeAndAfter = kSendEmptyTransferBefore | kSendEmptyTransferAfter + kEmptyTransferNone = 0, + kEmptyTransferBefore = 1, + kEmptyTransferAfter = 1 << 1, + kEmptyTransferBeforeAndAfter = kEmptyTransferBefore | kEmptyTransferAfter }; private: @@ -141,6 +141,7 @@ namespace Heimdall bool InitialiseProtocol(void); bool SendBulkTransfer(unsigned char *data, int length, int timeout, bool retry = true) const; + int ReceiveBulkTransfer(unsigned char *data, int length, int timeout, bool retry = true) const; public: @@ -153,8 +154,8 @@ namespace Heimdall bool BeginSession(void); bool EndSession(bool reboot) const; - bool SendPacket(OutboundPacket *packet, int timeout = kDefaultTimeoutSend, int sendEmptyTransferFlags = kSendEmptyTransferAfter) const; - bool ReceivePacket(InboundPacket *packet, int timeout = kDefaultTimeoutReceive) const; + bool SendPacket(OutboundPacket *packet, int timeout = kDefaultTimeoutSend, int emptyTransferFlags = kEmptyTransferAfter) const; + bool ReceivePacket(InboundPacket *packet, int timeout = kDefaultTimeoutReceive, int emptyTransferFlags = kEmptyTransferNone) const; bool RequestDeviceType(unsigned int request, int *result) const; -- cgit v1.1 From 1ddfdc1a880279ce07b2c43f60b7aa138d4ad315 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Mon, 17 Nov 2014 07:02:07 +1100 Subject: CMake files for Heimdall CLI and mingw support --- heimdall/source/BridgeManager.cpp | 6 ++++-- heimdall/source/Heimdall.h | 16 +++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 9b8fdfa..8fb678c 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -19,7 +19,7 @@ THE SOFTWARE.*/ // C Standard Library -#include +#include // libusb #include @@ -53,7 +53,9 @@ #include "SessionSetupResponse.h" // Future versions of libusb will use usb_interface instead of interface. +#ifndef usb_interface #define usb_interface interface +#endif #define USB_CLASS_CDC_DATA 0x0A @@ -1035,7 +1037,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { sequenceCount++; - int lastSequenceBytes = fileSize % (fileTransferSequenceMaxLength * fileTransferPacketSize); + unsigned int lastSequenceBytes = fileSize % (fileTransferSequenceMaxLength * fileTransferPacketSize); lastSequenceSize = lastSequenceBytes / fileTransferPacketSize; if (partialPacketByteCount != 0) diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index 3982dd4..c5c11ef 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -21,7 +21,7 @@ #ifndef HEIMDALL_H #define HEIMDALL_H -#ifdef OS_WINDOWS +#ifdef _MSC_VER // Microsoft Visual C Standard Library #include #undef GetBinaryType @@ -36,24 +36,18 @@ #define FileTell(FILE) _ftelli64(FILE) #define FileRewind(FILE) rewind(FILE) -#else +#else // POSIX Standard Library -#include "../config.h" - -#if defined(OS_DARWIN) || defined(OS_LINUX) #include + #define Sleep(t) usleep(1000*t) #define FileOpen(FILE, MODE) fopen(FILE, MODE) #define FileClose(FILE) fclose(FILE) -#define FileSeek(FILE, OFFSET, ORIGIN) fseeko(FILE, OFFSET, ORIGIN) -#define FileTell(FILE) ftello(FILE) +#define FileSeek(FILE, OFFSET, ORIGIN) fseeko64(FILE, OFFSET, ORIGIN) +#define FileTell(FILE) ftello64(FILE) #define FileRewind(FILE) rewind(FILE) -#else -#error operating system not supported -#endif - #endif #if (!(defined _MSC_VER) || (_MSC_VER < 1700)) -- cgit v1.1 From ee53613ec16af1334516402a9ba99a92934fe01c Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Mon, 17 Nov 2014 16:05:25 +1100 Subject: Continue to support autotools... for now --- heimdall/source/Heimdall.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'heimdall/source') diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index c5c11ef..45d0cbd 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -38,6 +38,10 @@ #else // POSIX Standard Library +#ifdef AUTOCONF +#include "../config.h" +#endif + #include #define Sleep(t) usleep(1000*t) -- cgit v1.1 From 69c3aafd81e2804216361ac13eea4b157594ce24 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Wed, 10 Dec 2014 00:50:30 +1100 Subject: Fix UNIX CMake (and OS X autotools) builds for Heimdall CLI --- heimdall/source/Heimdall.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index 45d0cbd..205f01d 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -48,8 +48,8 @@ #define FileOpen(FILE, MODE) fopen(FILE, MODE) #define FileClose(FILE) fclose(FILE) -#define FileSeek(FILE, OFFSET, ORIGIN) fseeko64(FILE, OFFSET, ORIGIN) -#define FileTell(FILE) ftello64(FILE) +#define FileSeek(FILE, OFFSET, ORIGIN) fseeko(FILE, OFFSET, ORIGIN) +#define FileTell(FILE) ftello(FILE) #define FileRewind(FILE) rewind(FILE) #endif -- cgit v1.1 From e98281afb7d9cf7429339c2aaa45f80fc0ce1584 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sat, 21 Feb 2015 03:37:32 +1100 Subject: Fixed incorrect method arguments causing PIT transfers to fail --- heimdall/source/BridgeManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 8fb678c..1065795 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -931,8 +931,8 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const int receiveEmptyTransferFlags = (i == transferCount - 1) ? kEmptyTransferAfter : kEmptyTransferNone; ReceiveFilePartPacket *receiveFilePartPacket = new ReceiveFilePartPacket(); - success = ReceivePacket(receiveFilePartPacket, receiveEmptyTransferFlags); - + success = ReceivePacket(receiveFilePartPacket, kDefaultTimeoutReceive, receiveEmptyTransferFlags); + if (!success) { Interface::PrintError("Failed to receive PIT file part #%d!\n", i); -- cgit v1.1 From fae5f627a092ca3b3c79d0da050e6ff41c67f53f Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Sat, 21 Feb 2015 03:38:07 +1100 Subject: Implemented hack to make WinUSB play nice with empty receive transfers --- heimdall/source/BridgeManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'heimdall/source') diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 1065795..b7bff3d 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -650,6 +650,14 @@ bool BridgeManager::SendBulkTransfer(unsigned char *data, int length, int timeou int BridgeManager::ReceiveBulkTransfer(unsigned char *data, int length, int timeout, bool retry) const { + if (data == nullptr) + { + // HACK: It seems WinUSB ignores us when we try to read with length zero. + static unsigned char dummyData; + data = &dummyData; + length = 1; + } + int dataTransferred; int result = libusb_bulk_transfer(deviceHandle, inEndpoint, data, length, &dataTransferred, timeout); -- cgit v1.1 From 46c4f8be14aff1794f88f675ab372a8a07261c1a Mon Sep 17 00:00:00 2001 From: Steffen Pankratz Date: Mon, 29 Feb 2016 18:42:55 +0100 Subject: - fixed logical error, wrong variable was used in error message --- heimdall/source/FlashAction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'heimdall/source') diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index 590e0b5..d9203b0 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -185,7 +185,7 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector Date: Sun, 6 Mar 2016 13:45:37 +0100 Subject: - fixed compiler warning: dead initialization (the values are never read) In order to not get compiler warnings about 'unused return values' a void cast is used, which also makes it clear the the returned values are ignored on purpose --- heimdall/source/PrintPitAction.cpp | 2 +- heimdall/source/SendFilePartPacket.h | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp index 12c28d1..7ae8e6b 100644 --- a/heimdall/source/PrintPitAction.cpp +++ b/heimdall/source/PrintPitAction.cpp @@ -139,7 +139,7 @@ int PrintPitAction::Execute(int argc, char **argv) // Load the local pit file into memory. unsigned char *pitFileBuffer = new unsigned char[localPitFileSize]; - size_t dataRead = fread(pitFileBuffer, 1, localPitFileSize, localPitFile); // dataRead is discarded, it's here to remove warnings. + (void)fread(pitFileBuffer, 1, localPitFileSize, localPitFile); FileClose(localPitFile); PitData *pitData = new PitData(); diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h index 38e9dbe..561bf58 100644 --- a/heimdall/source/SendFilePartPacket.h +++ b/heimdall/source/SendFilePartPacket.h @@ -46,9 +46,7 @@ namespace Heimdall // min(fileSize, size) unsigned int bytesToRead = (fileSize < size) ? fileSize - position : size; - - // bytesRead is discarded (it's just there to stop GCC warnings) - unsigned int bytesRead = fread(data, 1, bytesToRead, file); + (void)fread(data, 1, bytesToRead, file); } SendFilePartPacket(unsigned char *buffer, unsigned int size) : OutboundPacket(size) -- cgit v1.1 From e8a77e66862daac5a3bab825a375fbb43b8b5b8b Mon Sep 17 00:00:00 2001 From: Steffen Pankratz Date: Sun, 6 Mar 2016 16:31:00 +0100 Subject: - removed superfluous semicolons from namespace definitions --- heimdall/source/ClosePcScreenAction.h | 2 +- heimdall/source/DetectAction.h | 2 +- heimdall/source/DownloadPitAction.h | 2 +- heimdall/source/FlashAction.h | 2 +- heimdall/source/HelpAction.h | 2 +- heimdall/source/InfoAction.h | 2 +- heimdall/source/Interface.h | 2 +- heimdall/source/PrintPitAction.h | 2 +- heimdall/source/VersionAction.h | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'heimdall/source') diff --git a/heimdall/source/ClosePcScreenAction.h b/heimdall/source/ClosePcScreenAction.h index a3def99..58cbdee 100644 --- a/heimdall/source/ClosePcScreenAction.h +++ b/heimdall/source/ClosePcScreenAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/DetectAction.h b/heimdall/source/DetectAction.h index b706db6..b4bcd59 100644 --- a/heimdall/source/DetectAction.h +++ b/heimdall/source/DetectAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/DownloadPitAction.h b/heimdall/source/DownloadPitAction.h index 6c5f6c3..e93dcb5 100644 --- a/heimdall/source/DownloadPitAction.h +++ b/heimdall/source/DownloadPitAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/FlashAction.h b/heimdall/source/FlashAction.h index d837374..dcc969e 100644 --- a/heimdall/source/FlashAction.h +++ b/heimdall/source/FlashAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/HelpAction.h b/heimdall/source/HelpAction.h index bb27790..ce06ac4 100644 --- a/heimdall/source/HelpAction.h +++ b/heimdall/source/HelpAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/InfoAction.h b/heimdall/source/InfoAction.h index 6727502..89fec36 100644 --- a/heimdall/source/InfoAction.h +++ b/heimdall/source/InfoAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/Interface.h b/heimdall/source/Interface.h index e4c89d7..a3fb1d7 100644 --- a/heimdall/source/Interface.h +++ b/heimdall/source/Interface.h @@ -74,7 +74,7 @@ namespace Heimdall void PrintPit(const libpit::PitData *pitData); void SetStdoutErrors(bool enabled); - }; + } } #endif diff --git a/heimdall/source/PrintPitAction.h b/heimdall/source/PrintPitAction.h index 948f0bd..ff2831b 100644 --- a/heimdall/source/PrintPitAction.h +++ b/heimdall/source/PrintPitAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif diff --git a/heimdall/source/VersionAction.h b/heimdall/source/VersionAction.h index 9a1e6ce..9dee26f 100644 --- a/heimdall/source/VersionAction.h +++ b/heimdall/source/VersionAction.h @@ -28,7 +28,7 @@ namespace Heimdall extern const char *usage; int Execute(int argc, char **argv); - }; + } } #endif -- cgit v1.1