Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix USB handling and timeouts for newer devices #329

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions heimdall/source/BridgeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ bool BridgeManager::BeginSession(void)

BeginSessionPacket beginSessionPacket;

if (!SendPacket(&beginSessionPacket))
if (!SendPacket(&beginSessionPacket, kDefaultTimeoutSend, kEmptyTransferNone))
{
Interface::PrintError("Failed to begin session!\n");
return (false);
Expand All @@ -533,7 +533,7 @@ bool BridgeManager::BeginSession(void)

FilePartSizePacket filePartSizePacket(fileTransferPacketSize);

if (!SendPacket(&filePartSizePacket))
if (!SendPacket(&filePartSizePacket, kDefaultTimeoutSend, kEmptyTransferNone))
{
Interface::PrintError("Failed to send file part size packet!\n");
return (false);
Expand All @@ -560,7 +560,7 @@ bool BridgeManager::EndSession(bool reboot) const
Interface::Print("Ending session...\n");

EndSessionPacket *endSessionPacket = new EndSessionPacket(EndSessionPacket::kRequestEndSession);
bool success = SendPacket(endSessionPacket);
bool success = SendPacket(endSessionPacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete endSessionPacket;

if (!success)
Expand All @@ -586,7 +586,7 @@ bool BridgeManager::EndSession(bool reboot) const
Interface::Print("Rebooting device...\n");

EndSessionPacket *rebootDevicePacket = new EndSessionPacket(EndSessionPacket::kRequestRebootDevice);
bool success = SendPacket(rebootDevicePacket);
bool success = SendPacket(rebootDevicePacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete rebootDevicePacket;

if (!success)
Expand All @@ -607,6 +607,16 @@ bool BridgeManager::EndSession(bool reboot) const
return (false);
}
}
else
{
Interface::Print("Resetting USB device...\n");

int result = libusb_reset_device(deviceHandle);
if (result != LIBUSB_SUCCESS)
{
Interface::PrintError("libusb error %d while resetting device.", result);
}
}

return (true);
}
Expand Down Expand Up @@ -766,7 +776,7 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout, int emptyT
bool BridgeManager::RequestDeviceType(unsigned int request, int *result) const
{
DeviceTypePacket deviceTypePacket;
bool success = SendPacket(&deviceTypePacket);
bool success = SendPacket(&deviceTypePacket, kDefaultTimeoutSend, kEmptyTransferNone);

if (!success)
{
Expand Down Expand Up @@ -794,7 +804,7 @@ bool BridgeManager::SendPitData(const PitData *pitData) const

// Start file transfer
PitFilePacket *pitFilePacket = new PitFilePacket(PitFilePacket::kRequestFlash);
bool success = SendPacket(pitFilePacket);
bool success = SendPacket(pitFilePacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete pitFilePacket;

if (!success)
Expand All @@ -815,7 +825,7 @@ bool BridgeManager::SendPitData(const PitData *pitData) const

// Transfer file size
FlashPartPitFilePacket *flashPartPitFilePacket = new FlashPartPitFilePacket(pitBufferSize);
success = SendPacket(flashPartPitFilePacket);
success = SendPacket(flashPartPitFilePacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete flashPartPitFilePacket;

if (!success)
Expand Down Expand Up @@ -843,7 +853,7 @@ bool BridgeManager::SendPitData(const PitData *pitData) const

// Flash pit file
SendFilePartPacket *sendFilePartPacket = new SendFilePartPacket(pitBuffer, pitBufferSize);
success = SendPacket(sendFilePartPacket);
success = SendPacket(sendFilePartPacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete sendFilePartPacket;

delete [] pitBuffer;
Expand All @@ -866,7 +876,7 @@ bool BridgeManager::SendPitData(const PitData *pitData) const

// End pit file transfer
EndPitFileTransferPacket *endPitFileTransferPacket = new EndPitFileTransferPacket(pitBufferSize);
success = SendPacket(endPitFileTransferPacket);
success = SendPacket(endPitFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete endPitFileTransferPacket;

if (!success)
Expand Down Expand Up @@ -896,7 +906,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const

// Start file transfer
PitFilePacket *pitFilePacket = new PitFilePacket(PitFilePacket::kRequestDump);
success = SendPacket(pitFilePacket);
success = SendPacket(pitFilePacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete pitFilePacket;

if (!success)
Expand Down Expand Up @@ -926,7 +936,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const
for (unsigned int i = 0; i < transferCount; i++)
{
DumpPartPitFilePacket *requestPacket = new DumpPartPitFilePacket(i);
success = SendPacket(requestPacket);
success = SendPacket(requestPacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete requestPacket;

if (!success)
Expand Down Expand Up @@ -958,7 +968,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const

// End file transfer
pitFilePacket = new PitFilePacket(PitFilePacket::kRequestEndTransfer);
success = SendPacket(pitFilePacket);
success = SendPacket(pitFilePacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete pitFilePacket;

if (!success)
Expand Down Expand Up @@ -1014,7 +1024,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
}

FileTransferPacket *flashFileTransferPacket = new FileTransferPacket(FileTransferPacket::kRequestFlash);
bool success = SendPacket(flashFileTransferPacket);
bool success = SendPacket(flashFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete flashFileTransferPacket;

if (!success)
Expand Down Expand Up @@ -1064,7 +1074,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
unsigned int sequenceTotalByteCount = sequenceSize * fileTransferPacketSize;

FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(sequenceTotalByteCount);
success = SendPacket(beginFileTransferPacket);
success = SendPacket(beginFileTransferPacket, kDefaultTimeoutSend, kEmptyTransferNone);
delete beginFileTransferPacket;

if (!success)
Expand Down
4 changes: 2 additions & 2 deletions heimdall/source/BridgeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ namespace Heimdall

enum
{
kDefaultTimeoutSend = 3000,
kDefaultTimeoutReceive = 3000,
kDefaultTimeoutSend = 6000,
kDefaultTimeoutReceive = 6000,
kDefaultTimeoutEmptyTransfer = 100
};

Expand Down