summaryrefslogtreecommitdiffstats
path: root/heimdall/source
diff options
context:
space:
mode:
authorBenjamin Dobell <benjamin.dobell@glassechidna.com.au>2011-07-20 18:43:49 +0200
committerBenjamin Dobell <benjamin.dobell@glassechidna.com.au>2011-07-20 18:43:49 +0200
commitbabef8e580c4b9d2daae1bd7b4092b59b5fa70be (patch)
tree87155afe8e797d1d0b6a24f12725c07c6d23995f /heimdall/source
parentDocumentation update. (diff)
downloadHeimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.tar
Heimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.tar.gz
Heimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.tar.bz2
Heimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.tar.lz
Heimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.tar.xz
Heimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.tar.zst
Heimdall-babef8e580c4b9d2daae1bd7b4092b59b5fa70be.zip
Diffstat (limited to 'heimdall/source')
-rw-r--r--heimdall/source/BridgeManager.cpp26
-rw-r--r--heimdall/source/BridgeManager.h9
-rw-r--r--heimdall/source/Interface.cpp5
-rw-r--r--heimdall/source/Interface.h2
-rw-r--r--heimdall/source/main.cpp20
5 files changed, 41 insertions, 21 deletions
diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp
index f58c4e2..00bdf29 100644
--- a/heimdall/source/BridgeManager.cpp
+++ b/heimdall/source/BridgeManager.cpp
@@ -143,11 +143,11 @@ bool BridgeManager::DetectDevice(void)
libusb_free_device_list(devices, deviceCount);
- Interface::Print("Failed to detect compatible device\n");
+ Interface::PrintDeviceDetectionFailed();
return (false);
}
-bool BridgeManager::Initialise(void)
+int BridgeManager::Initialise(void)
{
Interface::Print("Initialising connection...\n");
@@ -157,7 +157,7 @@ bool BridgeManager::Initialise(void)
{
Interface::PrintError("Failed to initialise libusb. libusb error: %d\n", result);
Interface::Print("Failed to connect to device!");
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
Interface::Print("Detecting device...\n");
@@ -189,15 +189,15 @@ bool BridgeManager::Initialise(void)
if (!heimdallDevice)
{
- Interface::PrintError("Failed to detect device!\n");
- return (false);
+ Interface::PrintDeviceDetectionFailed();
+ return (BridgeManager::kInitialiseDeviceNotDetected);
}
result = libusb_open(heimdallDevice, &deviceHandle);
if (result != LIBUSB_SUCCESS)
{
Interface::PrintError("Failed to access device. libusb error: %d\n", result);
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
libusb_device_descriptor deviceDescriptor;
@@ -205,12 +205,13 @@ bool BridgeManager::Initialise(void)
if (result != LIBUSB_SUCCESS)
{
Interface::PrintError("Failed to retrieve device description\n");
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
if (verbose)
{
unsigned char stringBuffer[128];
+
if (libusb_get_string_descriptor_ascii(deviceHandle, deviceDescriptor.iManufacturer,
stringBuffer, 128) >= 0)
{
@@ -241,10 +242,11 @@ bool BridgeManager::Initialise(void)
libusb_config_descriptor *configDescriptor;
result = libusb_get_config_descriptor(heimdallDevice, 0, &configDescriptor);
+
if (result != LIBUSB_SUCCESS || !configDescriptor)
{
Interface::PrintError("Failed to retrieve config descriptor\n");
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
int interfaceIndex = -1;
@@ -301,7 +303,7 @@ bool BridgeManager::Initialise(void)
if (result != LIBUSB_SUCCESS)
{
Interface::PrintError("Failed to find correct interface configuration\n");
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
Interface::Print("Claiming interface...\n");
@@ -323,7 +325,7 @@ bool BridgeManager::Initialise(void)
if (result != LIBUSB_SUCCESS)
{
Interface::PrintError("Claiming interface failed!\n");
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
Interface::Print("Setting up interface...\n");
@@ -332,12 +334,12 @@ bool BridgeManager::Initialise(void)
if (result != LIBUSB_SUCCESS)
{
Interface::PrintError("Setting up interface failed!\n");
- return (false);
+ return (BridgeManager::kInitialiseFailed);
}
Interface::Print("\n");
- return (true);
+ return (BridgeManager::kInitialiseSucceeded);
}
bool BridgeManager::BeginSession(void) const
diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h
index b488ea6..d87f67d 100644
--- a/heimdall/source/BridgeManager.h
+++ b/heimdall/source/BridgeManager.h
@@ -61,6 +61,13 @@ namespace Heimdall
enum
{
+ kInitialiseSucceeded = 0,
+ kInitialiseFailed,
+ kInitialiseDeviceNotDetected
+ };
+
+ enum
+ {
kVidSamsung = 0x04E8
};
@@ -98,7 +105,7 @@ namespace Heimdall
~BridgeManager();
bool DetectDevice(void);
- bool Initialise(void);
+ int Initialise(void);
bool BeginSession(void) const;
bool EndSession(bool reboot) const;
diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp
index bb0f30b..b2677cc 100644
--- a/heimdall/source/Interface.cpp
+++ b/heimdall/source/Interface.cpp
@@ -419,6 +419,11 @@ void Interface::PrintFullInfo(void)
Print(extraInfo);
}
+void Interface::PrintDeviceDetectionFailed(void)
+{
+ Print("Failed to detect compatible download-mode device.\n");
+}
+
void Interface::PrintPit(const PitData *pitData)
{
Interface::Print("Entry Count: %d\n", pitData->GetEntryCount());
diff --git a/heimdall/source/Interface.h b/heimdall/source/Interface.h
index 338445b..4474a2a 100644
--- a/heimdall/source/Interface.h
+++ b/heimdall/source/Interface.h
@@ -285,6 +285,8 @@ namespace Heimdall
static void PrintReleaseInfo(void);
static void PrintFullInfo(void);
+ static void PrintDeviceDetectionFailed(void);
+
static void PrintPit(const PitData *pitData);
static string& GetPitArgument(void)
diff --git a/heimdall/source/main.cpp b/heimdall/source/main.cpp
index f5bf173..a3ae962 100644
--- a/heimdall/source/main.cpp
+++ b/heimdall/source/main.cpp
@@ -244,7 +244,7 @@ void closeFiles(map<string, FILE *> argumentfileMap)
argumentfileMap.clear();
}
-bool getDeviceInfo(BridgeManager *bridgeManager)
+bool retrieveDeviceInfo(BridgeManager *bridgeManager)
{
// ---------- GET DEVICE INFORMATION ----------
@@ -271,6 +271,8 @@ bool getDeviceInfo(BridgeManager *bridgeManager)
Interface::PrintError("Unexpected device info response!\nExpected: 180, 0 or 3\nReceived:%d\n", deviceInfoResult);
return (false);
}
+
+ return (true);
}
int downloadPitFile(BridgeManager *bridgeManager, unsigned char **pitBuffer)
@@ -643,10 +645,12 @@ int main(int argc, char **argv)
Interface::PrintReleaseInfo();
Sleep(1000);
- if (!bridgeManager->Initialise())
+ int initialiseResult = bridgeManager->Initialise();
+
+ if (initialiseResult != 0)
{
delete bridgeManager;
- return (0);
+ return ((initialiseResult == BridgeManager::kInitialiseDeviceNotDetected) ? 1 : 0);
}
bool success;
@@ -666,7 +670,7 @@ int main(int argc, char **argv)
return (0);
}
- if (!bridgeManager->BeginSession() || !getDeviceInfo(bridgeManager))
+ if (!bridgeManager->BeginSession() || !retrieveDeviceInfo(bridgeManager))
{
closeFiles(argumentFileMap);
delete bridgeManager;
@@ -686,7 +690,7 @@ int main(int argc, char **argv)
case Interface::kActionClosePcScreen:
{
- if (!bridgeManager->BeginSession() || !getDeviceInfo(bridgeManager))
+ if (!bridgeManager->BeginSession() || !retrieveDeviceInfo(bridgeManager))
{
delete bridgeManager;
return (-1);
@@ -713,7 +717,7 @@ int main(int argc, char **argv)
return (0);
}
- if (!bridgeManager->BeginSession() || !getDeviceInfo(bridgeManager))
+ if (!bridgeManager->BeginSession() || !retrieveDeviceInfo(bridgeManager))
{
delete bridgeManager;
fclose(outputPitFile);
@@ -764,7 +768,7 @@ int main(int argc, char **argv)
int chipId = atoi(argumentMap.find(Interface::actions[Interface::kActionDump].valueArguments[Interface::kDumpValueArgChipId])->second.c_str());
- if (!bridgeManager->BeginSession() || !getDeviceInfo(bridgeManager))
+ if (!bridgeManager->BeginSession() || !retrieveDeviceInfo(bridgeManager))
{
fclose(dumpFile);
@@ -783,7 +787,7 @@ int main(int argc, char **argv)
case Interface::kActionPrintPit:
{
- if (!bridgeManager->BeginSession() || !getDeviceInfo(bridgeManager))
+ if (!bridgeManager->BeginSession() || !retrieveDeviceInfo(bridgeManager))
{
delete bridgeManager;
return (-1);