summaryrefslogtreecommitdiffstats
path: root/src/irecovery.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-05-20 13:10:26 +0200
committerGravatar Martin Szulecki2010-05-20 13:10:26 +0200
commitfdbdb9f9e964528d08038e51cd57f9545cef294a (patch)
tree9f8b43a2d95121973d48c2c23c26d732168069cb /src/irecovery.c
parentcf12a431935f814b6f0b98fe43915c48fde2fcf0 (diff)
downloadlibirecovery-fdbdb9f9e964528d08038e51cd57f9545cef294a.tar.gz
libirecovery-fdbdb9f9e964528d08038e51cd57f9545cef294a.tar.bz2
Improve irecv_open()'s device selection logic and allow opening by uuid
Previous code did attempt to open anything with an Apple vendor id. Now it also verifies if the USB device is within a mode we know and also allows targeting a specific device by it's UUID.
Diffstat (limited to 'src/irecovery.c')
-rw-r--r--src/irecovery.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/irecovery.c b/src/irecovery.c
index 1c4957e..56b0453 100644
--- a/src/irecovery.c
+++ b/src/irecovery.c
@@ -52,8 +52,10 @@ void parse_command(irecv_device_t* device, unsigned char* command, unsigned int
52 } else 52 } else
53 53
54 if(!strcmp(cmd, "/reconnect")) { 54 if(!strcmp(cmd, "/reconnect")) {
55 char* uuid = strdup(device->uuid);
55 irecv_close(device); 56 irecv_close(device);
56 irecv_open(device); 57 irecv_open(device, uuid);
58 free(uuid);
57 } else 59 } else
58 60
59 if(!strcmp(cmd, "/upload")) { 61 if(!strcmp(cmd, "/upload")) {
@@ -151,6 +153,7 @@ void print_usage() {
151 printf("iRecovery - iDevice Recovery Utility\n"); 153 printf("iRecovery - iDevice Recovery Utility\n");
152 printf("Usage: ./irecovery [args]\n"); 154 printf("Usage: ./irecovery [args]\n");
153 printf("\t-v\t\tStart irecovery in verbose mode.\n"); 155 printf("\t-v\t\tStart irecovery in verbose mode.\n");
156 printf("\t-u <uuid>\ttarget specific device by its 40-digit device UUID\n");
154 printf("\t-c <cmd>\tSend command to device.\n"); 157 printf("\t-c <cmd>\tSend command to device.\n");
155 printf("\t-f <file>\tSend file to device.\n"); 158 printf("\t-f <file>\tSend file to device.\n");
156 printf("\t-h\t\tShow this help.\n"); 159 printf("\t-h\t\tShow this help.\n");
@@ -163,9 +166,10 @@ int main(int argc, char** argv) {
163 int opt = 0; 166 int opt = 0;
164 int action = 0; 167 int action = 0;
165 char* argument = NULL; 168 char* argument = NULL;
169 char *uuid = NULL;
166 irecv_error_t error = 0; 170 irecv_error_t error = 0;
167 if(argc == 1) print_usage(); 171 if(argc == 1) print_usage();
168 while ((opt = getopt(argc, argv, "vhrsc:f:")) > 0) { 172 while ((opt = getopt(argc, argv, "vhru:sc:f:")) > 0) {
169 switch (opt) { 173 switch (opt) {
170 case 'v': 174 case 'v':
171 verbose += 1; 175 verbose += 1;
@@ -179,6 +183,10 @@ int main(int argc, char** argv) {
179 action = kResetDevice; 183 action = kResetDevice;
180 break; 184 break;
181 185
186 case 'u':
187 uuid = optarg;
188 break;
189
182 case 's': 190 case 's':
183 action = kStartShell; 191 action = kStartShell;
184 break; 192 break;
@@ -195,7 +203,7 @@ int main(int argc, char** argv) {
195 203
196 default: 204 default:
197 fprintf(stderr, "Unknown argument\n"); 205 fprintf(stderr, "Unknown argument\n");
198 break; 206 return -1;
199 } 207 }
200 } 208 }
201 209
@@ -209,14 +217,16 @@ int main(int argc, char** argv) {
209 int i = 0; 217 int i = 0;
210 for(i = 0; i <= 5; i++) { 218 for(i = 0; i <= 5; i++) {
211 debug("Attempting to connect... "); 219 debug("Attempting to connect... ");
220
221 if(irecv_open(device, uuid) < 0) sleep(1);
222 else break;
223
224 debug("failed. No recovery device found.\n");
225
212 if(i == 5) { 226 if(i == 5) {
213 irecv_exit(device); 227 irecv_exit(device);
214 return -1; 228 return -1;
215 } 229 }
216
217 if(irecv_open(device) < 0) sleep(1);
218 else break;
219 debug("failed\n");
220 } 230 }
221 231
222 switch(action) { 232 switch(action) {