Minor code clean up.

alt_setting-error
Benjamin Dobell 2014-04-30 01:40:10 +10:00
parent 4435da4a8a
commit 3af0c3ad63
6 changed files with 115 additions and 93 deletions

View File

@ -307,51 +307,99 @@ void BridgeManager::ReleaseDeviceInterface(void)
Interface::Print("\n"); 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) bool BridgeManager::InitialiseProtocol(void)
{ {
Interface::Print("Initialising protocol...\n"); Interface::Print("Initialising protocol...\n");
unsigned char dataBuffer[7]; LineCoding lineCoding;
int result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000); lineCoding.dteRate = 115200;
lineCoding.charFormat = kLineCodingCharFormatZeroToOneStopBit;
lineCoding.parityType = kParityTypeNone;
lineCoding.dataBits = 7;
if (result < 0 && verbose) SetControlLineState(kLineStateControlSignalDtePresent | kLineStateControlSignalCarrierControl);
Interface::PrintWarning("Control transfer #1 failed. Result: %d\n", result); SetControlLineCoding(lineCoding);
SetControlLineState(kLineStateControlSignalDtePresent | kLineStateControlSignalCarrierControl);
SetControlLineState(kLineStateControlSignalCarrierControl);
lineCoding.dataBits = 8;
SetControlLineCoding(lineCoding);
memset(dataBuffer, 0, 7); SetControlLineState(kLineStateControlSignalCarrierControl);
dataBuffer[1] = 0xC2;
dataBuffer[2] = 0x01;
dataBuffer[6] = 0x07;
result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000);
if (result < 0 && verbose)
Interface::PrintWarning("Control transfer #2 failed. Result: %d\n", result);
result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000);
if (result < 0 && verbose)
Interface::PrintWarning("Control transfer #3 failed. Result: %d\n", result);
result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000);
if (result < 0 && verbose)
Interface::PrintWarning("Control transfer #4 failed. Result: %d\n", result);
memset(dataBuffer, 0, 7);
dataBuffer[1] = 0xC2;
dataBuffer[2] = 0x01;
dataBuffer[6] = 0x08;
result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000);
if (result < 0 && verbose)
Interface::PrintWarning("Control transfer #5 failed. Result: %d\n", result);
result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000);
if (result < 0 && verbose)
Interface::PrintWarning("Control transfer #6 failed. Result: %d\n", result);
unsigned int attempt = 0; unsigned int attempt = 0;
@ -371,12 +419,13 @@ bool BridgeManager::InitialiseProtocol(void)
int dataTransferred = 0; int dataTransferred = 0;
unsigned char dataBuffer[7];
// Send "ODIN" // Send "ODIN"
memcpy(dataBuffer, "ODIN", 4); memcpy(dataBuffer, "ODIN", 4);
memset(dataBuffer + 4, 0, 1); memset(dataBuffer + 4, 0, 1);
result = libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000); if (libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000) != LIBUSB_SUCCESS)
if (result < 0)
{ {
if (verbose) if (verbose)
Interface::PrintError("Failed to send data: \"%s\"\n", dataBuffer); Interface::PrintError("Failed to send data: \"%s\"\n", dataBuffer);
@ -402,9 +451,7 @@ bool BridgeManager::InitialiseProtocol(void)
int retry = 0; int retry = 0;
dataTransferred = 0; dataTransferred = 0;
result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); if (libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000) != LIBUSB_SUCCESS)
if (result < 0)
{ {
if (verbose) if (verbose)
Interface::PrintError("Failed to receive handshake response."); 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"); Interface::Print("Session begun.\n\n");
return (true); return (true);
} }

View File

@ -94,6 +94,14 @@ namespace Heimdall
Default = Error Default = Error
}; };
typedef struct
{
unsigned int dteRate;
unsigned char charFormat;
unsigned char parityType;
unsigned char dataBits;
} LineCoding;
private: private:
static const DeviceIdentifier supportedDevices[kSupportedDeviceCount]; static const DeviceIdentifier supportedDevices[kSupportedDeviceCount];
@ -131,6 +139,9 @@ namespace Heimdall
bool InitialiseProtocol(void); bool InitialiseProtocol(void);
bool SetControlLineState(unsigned short controlSignalFlags);
bool SetControlLineCoding(LineCoding lineCoding);
public: public:
BridgeManager(bool verbose, int communicationDelay = BridgeManager::kCommunicationDelayDefault); BridgeManager(bool verbose, int communicationDelay = BridgeManager::kCommunicationDelayDefault);

View File

@ -34,7 +34,7 @@ namespace Heimdall
{ {
kDestinationPhone = 0x00, kDestinationPhone = 0x00,
kDestinationModem = 0x01 kDestinationModem = 0x01
}; };
protected: protected:
@ -47,18 +47,18 @@ namespace Heimdall
unsigned int destination; // PDA / Modem unsigned int destination; // PDA / Modem
unsigned int sequenceByteCount; unsigned int sequenceByteCount;
unsigned int unknown1; unsigned int unknown1; // EFS?
unsigned int chipIdentifier; unsigned int deviceType;
protected: 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) : FileTransferPacket(FileTransferPacket::kRequestEnd)
{ {
this->destination = destination; this->destination = destination;
this->sequenceByteCount = sequenceByteCount; this->sequenceByteCount = sequenceByteCount;
this->unknown1 = unknown1; this->unknown1 = unknown1;
this->chipIdentifier = chipIdentifier; this->deviceType = deviceType;
} }
public: public:
@ -78,9 +78,9 @@ namespace Heimdall
return (unknown1); return (unknown1);
} }
unsigned int GetChipIdentifier(void) const unsigned int GetDeviceType(void) const
{ {
return (chipIdentifier); return (deviceType);
} }
virtual void Pack(void) virtual void Pack(void)
@ -90,7 +90,7 @@ namespace Heimdall
PackInteger(FileTransferPacket::kDataSize, destination); PackInteger(FileTransferPacket::kDataSize, destination);
PackInteger(FileTransferPacket::kDataSize + 4, sequenceByteCount); PackInteger(FileTransferPacket::kDataSize + 4, sequenceByteCount);
PackInteger(FileTransferPacket::kDataSize + 8, unknown1); PackInteger(FileTransferPacket::kDataSize + 8, unknown1);
PackInteger(FileTransferPacket::kDataSize + 12, chipIdentifier); PackInteger(FileTransferPacket::kDataSize + 12, deviceType);
} }
}; };
} }

View File

@ -251,7 +251,7 @@ static bool flashFile(BridgeManager *bridgeManager, const PartitionFlashInfo& pa
Interface::Print("Uploading %s\n", partitionFlashInfo.pitEntry->GetPartitionName()); Interface::Print("Uploading %s\n", partitionFlashInfo.pitEntry->GetPartitionName());
if (bridgeManager->SendFile(partitionFlashInfo.file, EndModemFileTransferPacket::kDestinationModem, 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()); Interface::Print("%s upload successful\n\n", partitionFlashInfo.pitEntry->GetPartitionName());
return (true); return (true);

View File

@ -264,6 +264,9 @@ void Interface::PrintPit(const PitData *pitData)
if (entry->GetAttributes() & PitEntry::kAttributeSTL) if (entry->GetAttributes() & PitEntry::kAttributeSTL)
Interface::Print("STL "); Interface::Print("STL ");
/*if (entry->GetAttributes() & PitEntry::kAttributeBML)
Interface::Print("BML ");*/
if (entry->GetAttributes() & PitEntry::kAttributeWrite) if (entry->GetAttributes() & PitEntry::kAttributeWrite)
Interface::Print("Read/Write"); Interface::Print("Read/Write");
else else

View File

@ -69,7 +69,8 @@ namespace libpit
enum enum
{ {
kAttributeWrite = 1, kAttributeWrite = 1,
kAttributeSTL = 1 << 1 kAttributeSTL = 1 << 1/*,
kAttributeBML = 1 << 2*/ // ???
}; };
enum enum