summaryrefslogtreecommitdiffstats
path: root/src/dfu.c
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-06-21 05:03:27 -0400
committerGravatar Joshua Hill2010-06-21 05:03:27 -0400
commitef2a1037524ad559658a31793d4a96e07773cebc (patch)
tree45416d3eadabe83df85c97a7ce326f27258376c3 /src/dfu.c
parent8708123ecfd708239137445c9f83c86a96ae63b7 (diff)
parentb39abb66ffa5e26f38cb2ba03562d091decafc84 (diff)
downloadidevicerestore-ef2a1037524ad559658a31793d4a96e07773cebc.tar.gz
idevicerestore-ef2a1037524ad559658a31793d4a96e07773cebc.tar.bz2
Merge branch 'rcg'
Diffstat (limited to 'src/dfu.c')
-rw-r--r--src/dfu.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/dfu.c b/src/dfu.c
index 5e13f38..1b0e8e7 100644
--- a/src/dfu.c
+++ b/src/dfu.c
@@ -19,10 +19,69 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <libirecovery.h>
#include "dfu.h"
+#include "recovery.h"
+#include "idevicerestore.h"
-int dfu_get_ecid(uint64_t* ecid) {
+int dfu_check_mode() {
+ irecv_client_t dfu = NULL;
+ irecv_error_t dfu_error = IRECV_E_SUCCESS;
+
+ dfu_error = irecv_open(&dfu);
+ if (dfu_error != IRECV_E_SUCCESS) {
+ return -1;
+ }
+
+ if (dfu->mode != kDfuMode) {
+ irecv_close(dfu);
+ return -1;
+ }
+
+ irecv_close(dfu);
+ dfu = NULL;
+ return 0;
+}
+
+int dfu_enter_recovery(const char* ipsw, plist_t tss) {
+ irecv_client_t dfu = NULL;
+ const char* component = "iBSS";
+ irecv_error_t dfu_error = IRECV_E_SUCCESS;
+ if (recovery_open_with_timeout(&dfu) < 0 || dfu->mode != kDfuMode) {
+ error("ERROR: Unable to connect to DFU device\n");
+ if (dfu)
+ irecv_close(dfu);
+ return -1;
+ }
+
+ if (recovery_send_signed_component(dfu, ipsw, tss, "iBSS") < 0) {
+ error("ERROR: Unable to send %s to device\n", component);
+ irecv_close(dfu);
+ return -1;
+ }
+
+ dfu_error = irecv_reset(dfu);
+ if (dfu_error != IRECV_E_SUCCESS) {
+ error("ERROR: Unable to reset device\n");
+ irecv_close(dfu);
+ return -1;
+ }
+ irecv_close(dfu);
+ dfu = NULL;
+
+ // Reconnect to device, but this time make sure we're not still in DFU mode
+ if (recovery_open_with_timeout(&dfu) < 0 || dfu->mode == kDfuMode) {
+ error("ERROR: Unable to connect to recovery device\n");
+ if (dfu)
+ irecv_close(dfu);
+ return -1;
+ }
+
+ idevicerestore_mode = MODE_RECOVERY;
+ irecv_close(dfu);
+ dfu = NULL;
return 0;
}