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/BridgeManager.cpp') 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 ++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 74 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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); } -- 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 +++++++++++++++----------------------- 1 file changed, 53 insertions(+), 87 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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); } -- 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 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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) -- 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/BridgeManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'heimdall/source/BridgeManager.cpp') 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 -- 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 +-------------------------------------- 1 file changed, 1 insertion(+), 93 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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); -- 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 - 1 file changed, 1 deletion(-) (limited to 'heimdall/source/BridgeManager.cpp') 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); -- 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 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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) -- 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 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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) -- 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 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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); -- 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 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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; -- 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 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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) { -- 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 +++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 57 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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) -- 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 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'heimdall/source/BridgeManager.cpp') 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) -- 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/BridgeManager.cpp') 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/BridgeManager.cpp') 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