summaryrefslogtreecommitdiffstats
path: root/include/libirecovery.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libirecovery.h')
-rw-r--r--include/libirecovery.h150
1 files changed, 128 insertions, 22 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h
index 2ef1ae3..3220669 100644
--- a/include/libirecovery.h
+++ b/include/libirecovery.h
@@ -1,19 +1,20 @@
1/** 1/**
2 * iRecovery - Utility for DFU 2.0, WTF and Recovery Mode 2 * GreenPois0n iRecovery - libirecovery.h
3 * Copyright (C) 2008 - 2009 westbaer 3 * Copyright (C) 2010 Chronic-Dev Team
4 * 4 * Copyright (C) 2010 Joshua Hill
5 * This program is free software: you can redistribute it and/or modify 5 *
6 * it under the terms of the GNU General Public License as published by 6 * This program is free software: you can redistribute it and/or modify
7 * the Free Software Foundation, either version 3 of the License, or 7 * it under the terms of the GNU General Public License as published by
8 * (at your option) any later version. 8 * the Free Software Foundation, either version 3 of the License, or
9 * 9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, 10 *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * This program is distributed in the hope that it will be useful,
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * GNU General Public License for more details. 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * 14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License 15 *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/ 18 **/
18 19
19#ifndef LIBIRECOVERY_H 20#ifndef LIBIRECOVERY_H
@@ -23,10 +24,52 @@
23extern "C" { 24extern "C" {
24#endif 25#endif
25 26
27#ifndef WIN32
26#include <libusb-1.0/libusb.h> 28#include <libusb-1.0/libusb.h>
29#else
30#define WIN32_LEAN_AND_MEAN
31#include <windows.h>
32#define sleep(n) Sleep(1000 * n)
33#endif
27 34
28#define APPLE_VENDOR_ID 0x05AC 35#define APPLE_VENDOR_ID 0x05AC
29 36
37#define CPID_UNKNOWN -1
38#define CPID_IPHONE2G 8900
39#define CPID_IPOD1G 8900
40#define CPID_IPHONE3G 8900
41#define CPID_IPOD2G 8720
42#define CPID_IPHONE3GS 8920
43#define CPID_IPOD3G 8922
44#define CPID_IPAD1G 8930
45#define CPID_IPHONE4 8930
46#define CPID_IPOD4G 8930
47#define CPID_APPLETV2 8930
48
49#define BDID_UNKNOWN -1
50#define BDID_IPHONE2G 0
51#define BDID_IPOD1G 2
52#define BDID_IPHONE3G 4
53#define BDID_IPOD2G 0
54#define BDID_IPHONE3GS 0
55#define BDID_IPOD3G 2
56#define BDID_IPAD1G 2
57#define BDID_IPHONE4 0
58#define BDID_IPOD4G 8
59#define BDID_APPLETV2 10
60
61#define DEVICE_UNKNOWN -1
62#define DEVICE_IPHONE2G 0
63#define DEVICE_IPOD1G 1
64#define DEVICE_IPHONE3G 2
65#define DEVICE_IPOD2G 3
66#define DEVICE_IPHONE3GS 4
67#define DEVICE_IPOD3G 5
68#define DEVICE_IPAD1G 6
69#define DEVICE_IPHONE4 7
70#define DEVICE_IPOD4G 8
71#define DEVICE_APPLETV2 9
72
30enum { 73enum {
31 kRecoveryMode1 = 0x1280, 74 kRecoveryMode1 = 0x1280,
32 kRecoveryMode2 = 0x1281, 75 kRecoveryMode2 = 0x1281,
@@ -46,6 +89,8 @@ typedef enum {
46 IRECV_E_USB_STATUS = -7, 89 IRECV_E_USB_STATUS = -7,
47 IRECV_E_USB_INTERFACE = -8, 90 IRECV_E_USB_INTERFACE = -8,
48 IRECV_E_USB_CONFIGURATION = -9, 91 IRECV_E_USB_CONFIGURATION = -9,
92 IRECV_E_PIPE = -10,
93 IRECV_E_TIMEOUT = -11,
49 IRECV_E_UNKNOWN_ERROR = -255 94 IRECV_E_UNKNOWN_ERROR = -255
50} irecv_error_t; 95} irecv_error_t;
51 96
@@ -67,6 +112,7 @@ typedef struct {
67 112
68struct irecv_client; 113struct irecv_client;
69typedef struct irecv_client* irecv_client_t; 114typedef struct irecv_client* irecv_client_t;
115typedef struct irecv_device* irecv_device_t;
70typedef int(*irecv_event_cb_t)(irecv_client_t client, const irecv_event_t* event); 116typedef int(*irecv_event_cb_t)(irecv_client_t client, const irecv_event_t* event);
71 117
72struct irecv_client { 118struct irecv_client {
@@ -75,7 +121,18 @@ struct irecv_client {
75 int interface; 121 int interface;
76 int alt_interface; 122 int alt_interface;
77 unsigned short mode; 123 unsigned short mode;
124 char serial[256];
125
126#ifndef WIN32
78 libusb_device_handle* handle; 127 libusb_device_handle* handle;
128#else
129 HANDLE handle;
130 HANDLE hDFU;
131 HANDLE hIB;
132 LPSTR iBootPath;
133 LPSTR DfuPath;
134#endif
135
79 irecv_event_cb_t progress_callback; 136 irecv_event_cb_t progress_callback;
80 irecv_event_cb_t received_callback; 137 irecv_event_cb_t received_callback;
81 irecv_event_cb_t connected_callback; 138 irecv_event_cb_t connected_callback;
@@ -84,26 +141,75 @@ struct irecv_client {
84 irecv_event_cb_t disconnected_callback; 141 irecv_event_cb_t disconnected_callback;
85}; 142};
86 143
144struct irecv_device {
145 int index;
146 const char* product;
147 const char* model;
148 unsigned int board_id;
149 unsigned int chip_id;
150 const char* url;
151};
152
153static struct irecv_device irecv_devices[] = {
154 { 0, "iPhone1,1", "m68ap", 0, 8900,
155 "http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-7481.20100202.4orot/iPhone1,1_3.1.3_7E18_Restore.ipsw" },
156 { 1, "iPod1,1", "n45ap", 2, 8900,
157 NULL },
158 { 2, "iPhone1,2", "n82ap", 4, 8900,
159 "http://appldnld.apple.com/iPhone4/061-7932.20100908.3fgt5/iPhone1,2_4.1_8B117_Restore.ipsw" },
160 { 3, "iPod2,1", "n72ap", 0, 8720,
161 "http://appldnld.apple.com/iPhone4/061-7937.20100908.ghj4f/iPod2,1_4.1_8B117_Restore.ipsw" },
162 { 4, "iPhone2,1", "n88ap", 0, 8920,
163 "http://appldnld.apple.com/iPhone4/061-7938.20100908.F3rCk/iPhone2,1_4.1_8B117_Restore.ipsw" },
164 { 5, "iPod3,1", "n18ap", 2, 8922,
165 "http://appldnld.apple.com/iPhone4/061-7941.20100908.sV9KE/iPod3,1_4.1_8B117_Restore.ipsw" },
166 { 6, "iPad1,1", "k48ap", 2, 8930,
167 "http://appldnld.apple.com/iPad/061-8801.20100811.CvfR5/iPad1,1_3.2.2_7B500_Restore.ipsw" },
168 { 7, "iPhone3,1", "n90ap", 0, 8930,
169 "http://appldnld.apple.com/iPhone4/061-7939.20100908.Lcyg3/iPhone3,1_4.1_8B117_Restore.ipsw" },
170 { 8, "iPod4,1", "n81ap", 8, 8930,
171 "http://appldnld.apple.com/iPhone4/061-8490.20100901.hyjtR/iPod4,1_4.1_8B117_Restore.ipsw" },
172 { 9, "AppleTV2,1", "k66ap", 10, 8930,
173 "http://appldnld.apple.com/AppleTV/061-8940.20100926.Tvtnz/AppleTV2,1_4.1_8M89_Restore.ipsw" },
174 { -1, NULL, NULL, -1, -1,
175 NULL }
176};
177
87void irecv_set_debug_level(int level); 178void irecv_set_debug_level(int level);
88const char* irecv_strerror(irecv_error_t error); 179const char* irecv_strerror(irecv_error_t error);
180irecv_error_t irecv_open_attempts(irecv_client_t* pclient, int attempts);
89irecv_error_t irecv_open(irecv_client_t* client); 181irecv_error_t irecv_open(irecv_client_t* client);
90irecv_error_t irecv_reset(irecv_client_t client); 182irecv_error_t irecv_reset(irecv_client_t client);
91irecv_error_t irecv_close(irecv_client_t client); 183irecv_error_t irecv_close(irecv_client_t client);
92irecv_error_t irecv_receive(irecv_client_t client); 184irecv_error_t irecv_receive(irecv_client_t client);
93irecv_error_t irecv_send_exploit(irecv_client_t client); 185irecv_error_t irecv_send_exploit(irecv_client_t client);
94irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid);
95irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid);
96irecv_error_t irecv_send_file(irecv_client_t client, const char* filename);
97irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid);
98irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename); 186irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename);
99irecv_error_t irecv_send_command(irecv_client_t client, unsigned char* command);
100irecv_error_t irecv_set_configuration(irecv_client_t client, int configuration); 187irecv_error_t irecv_set_configuration(irecv_client_t client, int configuration);
188
189irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void *user_data);
101irecv_error_t irecv_event_unsubscribe(irecv_client_t client, irecv_event_type type); 190irecv_error_t irecv_event_unsubscribe(irecv_client_t client, irecv_event_type type);
191
192irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, int dfuNotifyFinished);
193irecv_error_t irecv_send_command(irecv_client_t client, char* command);
194irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, unsigned long length, int dfuNotifyFinished);
195
196irecv_error_t irecv_saveenv(irecv_client_t client);
197irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value);
102irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value); 198irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value);
103irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value); 199irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value);
104irecv_error_t irecv_set_interface(irecv_client_t client, int interface, int alt_interface); 200irecv_error_t irecv_set_interface(irecv_client_t client, int interface, int alt_interface);
105irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, unsigned int length); 201irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid);
106irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void *user_data); 202irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid);
203irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid);
204void irecv_hexdump(unsigned char* buf, unsigned int len, unsigned int addr);
205
206void irecv_init();
207void irecv_exit();
208irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause);
209irecv_error_t irecv_reset_counters(irecv_client_t client);
210irecv_error_t irecv_finish_transfer(irecv_client_t client);
211irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned long length);
212irecv_error_t irecv_get_device(irecv_client_t client, irecv_device_t* device);
107 213
108#ifdef __cplusplus 214#ifdef __cplusplus
109} 215}