Permalink
Browse files

Replaced some extremely weird code that I came up with during the ini…

…tial

reverse engineering of the flashing protocol. Turns out all I needed to do
was send the sequence size in bytes rather than performing weird
calculations (which when packed) end up representing the same thing!
  • Loading branch information...
1 parent ee02a9c commit 713af23d0a8a65926e03ad2e50406aae2463e6e1 @Benjamin-Dobell committed Mar 28, 2012
@@ -961,14 +961,16 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
unsigned int sequenceCount = fileSize / (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize);
unsigned int lastSequenceSize = kMaxSequenceLength;
- unsigned int partialPacketLength = fileSize % SendFilePartPacket::kDefaultPacketSize;
+ unsigned int partialPacketByteCount = fileSize % SendFilePartPacket::kDefaultPacketSize;
+
if (fileSize % (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize) != 0)
{
sequenceCount++;
int lastSequenceBytes = fileSize % (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize);
lastSequenceSize = lastSequenceBytes / SendFilePartPacket::kDefaultPacketSize;
- if (partialPacketLength != 0)
+
+ if (partialPacketByteCount != 0)
lastSequenceSize++;
}
@@ -982,6 +984,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
// Min(lastSequenceSize, 131072)
bool isLastSequence = sequenceIndex == sequenceCount - 1;
unsigned int sequenceSize = (isLastSequence) ? lastSequenceSize : kMaxSequenceLength;
+ unsigned int sequenceByteCount = ((isLastSequence) ? lastSequenceSize : kMaxSequenceLength) * SendFilePartPacket::kDefaultPacketSize + partialPacketByteCount;
FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(0, 2 * sequenceSize);
success = SendPacket(beginFileTransferPacket);
@@ -1118,13 +1121,10 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
previousPercent = currentPercent;
}
- unsigned int lastFullPacketIndex = 2 * ((isLastSequence && partialPacketLength != 0) ? sequenceSize - 1 : sequenceSize);
-
if (destination == EndFileTransferPacket::kDestinationPhone)
{
- EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(
- (isLastSequence) ? partialPacketLength : 0, lastFullPacketIndex, 0, partitionType, fileIdentifier,
- isLastSequence);
+ EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket(sequenceByteCount, 0, partitionType,
+ fileIdentifier, isLastSequence);
success = SendPacket(endPhoneFileTransferPacket, 3000);
delete endPhoneFileTransferPacket;
@@ -1138,8 +1138,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
}
else // destination == EndFileTransferPacket::kDestinationModem
{
- EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(
- (isLastSequence) ? partialPacketLength : 0, lastFullPacketIndex, 0, partitionType, isLastSequence);
+ EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket(sequenceByteCount, 0, partitionType, isLastSequence);
success = SendPacket(endModemFileTransferPacket, 3000);
delete endModemFileTransferPacket;
@@ -46,30 +46,17 @@ namespace Heimdall
private:
unsigned int destination; // Chip identifier perhaps
- unsigned short partialPacketLength; // Length or (length - 65536) if lastFullPacket is odd.
- unsigned int lastFullPacketIndex;
- unsigned short unknown1;
+ unsigned int sequenceByteCount;
+ unsigned int unknown1;
unsigned int partitionType;
protected:
- EndFileTransferPacket(unsigned int destination, unsigned int partialPacketLength, unsigned int lastFullPacketIndex,
- unsigned short unknown1, unsigned int partitionType)
+ EndFileTransferPacket(unsigned int destination, unsigned int sequenceByteCount, unsigned int unknown1, unsigned int partitionType)
: FileTransferPacket(FileTransferPacket::kRequestEnd)
{
this->destination = destination;
-
- if (partialPacketLength > 65535)
- {
- this->partialPacketLength = (partialPacketLength - 65536);
- this->lastFullPacketIndex = lastFullPacketIndex + 1;
- }
- else
- {
- this->partialPacketLength = partialPacketLength;
- this->lastFullPacketIndex = lastFullPacketIndex;
- }
-
+ this->sequenceByteCount = sequenceByteCount;
this->unknown1 = unknown1;
this->partitionType = partitionType;
}
@@ -81,20 +68,12 @@ namespace Heimdall
return (destination);
}
- unsigned int GetPartialPacketLength(void) const
- {
- if (lastFullPacketIndex % 2 == 0)
- return (partialPacketLength);
- else
- return (partialPacketLength + 65536);
- }
-
- unsigned int GetLastFullPacketIndex(void) const
+ unsigned int GetSequenceByteCount(void) const
{
- return (lastFullPacketIndex - lastFullPacketIndex % 2);
+ return (sequenceByteCount);
}
- unsigned short GetUnknown1(void) const
+ unsigned int GetUnknown1(void) const
{
return (unknown1);
}
@@ -109,9 +88,8 @@ namespace Heimdall
FileTransferPacket::Pack();
PackInteger(FileTransferPacket::kDataSize, destination);
- PackShort(FileTransferPacket::kDataSize + 4, partialPacketLength);
- PackInteger(FileTransferPacket::kDataSize + 6, lastFullPacketIndex);
- PackShort(FileTransferPacket::kDataSize + 10, unknown1);
+ PackInteger(FileTransferPacket::kDataSize + 4, sequenceByteCount);
+ PackInteger(FileTransferPacket::kDataSize + 8, unknown1);
PackInteger(FileTransferPacket::kDataSize + 12, partitionType);
}
};
@@ -34,10 +34,8 @@ namespace Heimdall
public:
- EndModemFileTransferPacket(unsigned int partialPacketLength, unsigned int lastFullPacketIndex, unsigned short unknown1,
- unsigned int partitionType, bool endOfFile)
- : EndFileTransferPacket(EndFileTransferPacket::kDestinationModem, partialPacketLength,
- lastFullPacketIndex, unknown1, partitionType)
+ EndModemFileTransferPacket(unsigned int sequenceByteCount, unsigned int unknown1, unsigned int partitionType, bool endOfFile)
+ : EndFileTransferPacket(EndFileTransferPacket::kDestinationModem, sequenceByteCount, unknown1, partitionType)
{
this->endOfFile = (endOfFile) ? 1 : 0;
}
@@ -57,10 +57,9 @@ namespace Heimdall
public:
- EndPhoneFileTransferPacket(unsigned int partialPacketLength, unsigned int lastFullPacketIndex, unsigned short unknown1,
- unsigned int partitionType, unsigned int fileIdentifier, bool endOfFile)
- : EndFileTransferPacket(EndFileTransferPacket::kDestinationPhone, partialPacketLength,
- lastFullPacketIndex, unknown1, partitionType)
+ EndPhoneFileTransferPacket(unsigned int sequenceByteCount, unsigned int unknown1, unsigned int partitionType,
+ unsigned int fileIdentifier, bool endOfFile)
+ : EndFileTransferPacket(EndFileTransferPacket::kDestinationPhone, sequenceByteCount, unknown1, partitionType)
{
this->fileIdentifier = fileIdentifier;
this->endOfFile = (endOfFile) ? 1 : 0;

0 comments on commit 713af23

Please sign in to comment.