summaryrefslogtreecommitdiffstats
path: root/heimdall/source/BridgeManager.cpp
diff options
context:
space:
mode:
authorBenjamin Dobell <benjamin.dobell+git@glassechidna.com.au>2014-04-29 17:40:10 +0200
committerBenjamin Dobell <benjamin.dobell+git@glassechidna.com.au>2014-05-06 13:39:04 +0200
commit3af0c3ad63437ac53f5e2832a22e21a8790686f5 (patch)
tree38d653a3a80a9889e8fc3a17cadfa5fd62fa5ce1 /heimdall/source/BridgeManager.cpp
parentMerge pull request #180 from marclaporte/master (diff)
downloadHeimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.tar
Heimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.tar.gz
Heimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.tar.bz2
Heimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.tar.lz
Heimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.tar.xz
Heimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.tar.zst
Heimdall-3af0c3ad63437ac53f5e2832a22e21a8790686f5.zip
Diffstat (limited to 'heimdall/source/BridgeManager.cpp')
-rw-r--r--heimdall/source/BridgeManager.cpp155
1 files changed, 81 insertions, 74 deletions
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);
}