summaryrefslogtreecommitdiffstats
path: root/src/irecovery.c
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-05-13 08:58:46 -0400
committerGravatar Joshua Hill2010-05-13 08:58:46 -0400
commit520c99d33e18009660f30bd38b31a2f1cd432fe6 (patch)
tree554dcde9de73f69a1cc34de0e4c7819fd148a5e8 /src/irecovery.c
parent5bbd277ce71521a3898697e4c8cb25ed65990f9c (diff)
downloadlibirecovery-520c99d33e18009660f30bd38b31a2f1cd432fe6.tar.gz
libirecovery-520c99d33e18009660f30bd38b31a2f1cd432fe6.tar.bz2
Implemented command line argument parsing and irecv_command() function.
Diffstat (limited to 'src/irecovery.c')
-rw-r--r--src/irecovery.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/irecovery.c b/src/irecovery.c
index 90f975b..51320a5 100644
--- a/src/irecovery.c
+++ b/src/irecovery.c
@@ -17,9 +17,50 @@
**/
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <libirecovery.h>
+enum {
+ kResetDevice, kSendCommand
+};
+
+void print_usage() {
+ printf("iRecovery - iDevice Recovery Utility\n");
+ printf("Usage: ./irecovery [args]\n");
+ exit(1);
+}
+
int main(int argc, char** argv) {
+ int opt = 0;
+ int action = 0;
+ char* argument = NULL;
+ if(argc == 1) print_usage();
+ while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) {
+ switch (opt) {
+ case 'd':
+ irecv_set_debug(1);
+ break;
+
+ case 'h':
+ print_usage();
+ break;
+
+ case 'r':
+ action = kResetDevice;
+ break;
+
+ case 'c':
+ argument = optarg;
+ action = kSendCommand;
+ break;
+
+ default:
+ fprintf(stderr, "Unknown argument\n");
+ break;
+ }
+ }
+
irecv_device* device = NULL;
if(irecv_init(&device) < 0) {
fprintf(stderr, "Unable to initialize libirecovery\n");
@@ -31,27 +72,20 @@ int main(int argc, char** argv) {
return -1;
}
- switch (device->mode) {
- case kRecoveryMode:
- printf("Found device in recovery mode\n");
+ switch(action) {
+ case kResetDevice:
+ irecv_reset(device);
break;
- case kDfuMode:
- printf("Found device in DFU mode\n");
- break;
-
- case kKernelMode:
- printf("Found device in kernel mode\n");
+ case kSendCommand:
+ irecv_command(device, argument);
break;
default:
- printf("No device found\n");
+ fprintf(stderr, "Unknown action\n");
break;
}
- printf("Sending USB reset...\n");
- irecv_reset(device);
-
irecv_exit(device);
return 0;
}