summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libirecovery.h114
-rw-r--r--src/libirecovery.c73
2 files changed, 72 insertions, 115 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h
index 8c17167..a405005 100644
--- a/include/libirecovery.h
+++ b/include/libirecovery.h
@@ -26,11 +26,6 @@ extern "C" {
26 26
27#include <stdint.h> 27#include <stdint.h>
28 28
29
30#define APPLE_VENDOR_ID 0x05AC
31#define CPID_UNKNOWN -1
32#define BDID_UNKNOWN -1
33
34enum { 29enum {
35 IRECV_K_RECOVERY_MODE_1 = 0x1280, 30 IRECV_K_RECOVERY_MODE_1 = 0x1280,
36 IRECV_K_RECOVERY_MODE_2 = 0x1281, 31 IRECV_K_RECOVERY_MODE_2 = 0x1281,
@@ -72,119 +67,16 @@ typedef struct {
72 irecv_event_type type; 67 irecv_event_type type;
73} irecv_event_t; 68} irecv_event_t;
74 69
75struct irecv_client;
76typedef struct irecv_client* irecv_client_t;
77typedef struct irecv_device* irecv_device_t;
78
79struct irecv_client {
80 int debug;
81 int config;
82 int interface;
83 int alt_interface;
84 unsigned short mode;
85 char serial[256];
86
87#ifndef WIN32
88 libusb_device_handle* handle;
89#else
90 HANDLE handle;
91 HANDLE hDFU;
92 HANDLE hIB;
93 LPSTR iBootPath;
94 LPSTR DfuPath;
95#endif
96
97 irecv_event_cb_t progress_callback;
98 irecv_event_cb_t received_callback;
99 irecv_event_cb_t connected_callback;
100 irecv_event_cb_t precommand_callback;
101 irecv_event_cb_t postcommand_callback;
102 irecv_event_cb_t disconnected_callback;
103};
104
105#define DEVICE_UNKNOWN -1
106#define DEVICE_IPHONE2G 0
107#define DEVICE_IPHONE3G 1
108#define DEVICE_IPHONE3GS 2
109#define DEVICE_IPHONE4 3
110#define DEVICE_IPHONE4REVA 4
111#define DEVICE_IPHONE4CDMA 5
112#define DEVICE_IPHONE4S 6
113#define DEVICE_IPHONE51 7
114#define DEVICE_IPHONE52 8
115#define DEVICE_IPHONE53 9
116#define DEVICE_IPHONE54 10
117#define DEVICE_IPHONE61 11
118#define DEVICE_IPHONE62 12
119#define DEVICE_IPOD1G 13
120#define DEVICE_IPOD2G 14
121#define DEVICE_IPOD3G 15
122#define DEVICE_IPOD4G 16
123#define DEVICE_IPOD5G 17
124#define DEVICE_IPAD1G 18
125#define DEVICE_IPAD21 19
126#define DEVICE_IPAD22 20
127#define DEVICE_IPAD23 21
128#define DEVICE_IPAD24 22
129#define DEVICE_IPAD25 23
130#define DEVICE_IPAD26 24
131#define DEVICE_IPAD27 25
132#define DEVICE_IPAD31 26
133#define DEVICE_IPAD32 27
134#define DEVICE_IPAD33 28
135#define DEVICE_IPAD34 29
136#define DEVICE_IPAD35 30
137#define DEVICE_IPAD36 31
138#define DEVICE_APPLETV2 32
139#define DEVICE_APPLETV31 33
140#define DEVICE_APPLETV32 34
141
142struct irecv_device { 70struct irecv_device {
143 int index;
144 const char* product; 71 const char* product;
145 const char* model; 72 const char* model;
146 unsigned int board_id; 73 unsigned int board_id;
147 unsigned int chip_id; 74 unsigned int chip_id;
148}; 75};
76typedef struct irecv_device* irecv_device_t;
149 77
150static struct irecv_device irecv_devices[] = { 78typedef struct irecv_client_private irecv_client_private;
151 { 0, "iPhone1,1", "m68ap", 0x00, 0x8900 }, 79typedef irecv_client_private* irecv_client_t;
152 { 1, "iPhone1,2", "n82ap", 0x04, 0x8900 },
153 { 2, "iPhone2,1", "n88ap", 0x00, 0x8920 },
154 { 3, "iPhone3,1", "n90ap", 0x00, 0x8930 },
155 { 4, "iPhone3,2", "n90bap", 0x04, 0x8930 },
156 { 5, "iPhone3,3", "n92ap", 0x06, 0x8930 },
157 { 6, "iPhone4,1", "n94ap", 0x08, 0x8940 },
158 { 7, "iPhone5,1", "n41ap", 0x00, 0x8950 },
159 { 8, "iPhone5,2", "n42ap", 0x02, 0x8950 },
160 { 9, "iPhone5,3", "n48ap", 0x0a, 0x8950 },
161 { 10, "iPhone5,4", "n49ap", 0x0e, 0x8950 },
162 { 11, "iPhone6,1", "n51ap", 0x00, 0x8960 },
163 { 12, "iPhone6,2", "n53ap", 0x02, 0x8960 },
164 { 13, "iPod1,1", "n45ap", 0x02, 0x8900 },
165 { 14, "iPod2,1", "n72ap", 0x00, 0x8720 },
166 { 15, "iPod3,1", "n18ap", 0x02, 0x8922 },
167 { 16, "iPod4,1", "n81ap", 0x08, 0x8930 },
168 { 17, "iPod5,1", "n78ap", 0x00, 0x8942 },
169 { 18, "iPad1,1", "k48ap", 0x02, 0x8930 },
170 { 19, "iPad2,1", "k93ap", 0x04, 0x8940 },
171 { 20, "iPad2,2", "k94ap", 0x06, 0x8940 },
172 { 21, "iPad2,3", "k95ap", 0x02, 0x8940 },
173 { 22, "iPad2,4", "k93aap", 0x06, 0x8942 },
174 { 23, "iPad2,5", "p105ap", 0x0a, 0x8942 },
175 { 24, "iPad2,6", "p106ap", 0x0c, 0x8942 },
176 { 25, "iPad2,7", "p107ap", 0x0e, 0x8942 },
177 { 26, "iPad3,1", "j1ap", 0x00, 0x8945 },
178 { 27, "iPad3,2", "j2ap", 0x02, 0x8945 },
179 { 28, "iPad3,3", "j2aap", 0x04, 0x8945 },
180 { 29, "iPad3,4", "p101ap", 0x00, 0x8955 },
181 { 30, "iPad3,5", "p102ap", 0x02, 0x8955 },
182 { 31, "iPad3,6", "p103ap", 0x04, 0x8955 },
183 { 32, "AppleTV2,1", "k66ap", 0x10, 0x8930 },
184 { 33, "AppleTV3,1", "j33ap", 0x08, 0x8942 },
185 { 34, "AppleTV3,2","j33iap", 0x00, 0x8947 },
186 { -1, NULL, NULL, -1, -1 }
187};
188 80
189/* library */ 81/* library */
190void irecv_set_debug_level(int level); 82void irecv_set_debug_level(int level);
diff --git a/src/libirecovery.c b/src/libirecovery.c
index a9369dc..1429237 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -42,7 +42,32 @@
42 42
43#include "libirecovery.h" 43#include "libirecovery.h"
44 44
45struct irecv_client_private {
46 int debug;
47 int config;
48 int interface;
49 int alt_interface;
50 unsigned short mode;
51 char serial[256];
52#ifndef WIN32
53 libusb_device_handle* handle;
54#else
55 HANDLE handle;
56 HANDLE hDFU;
57 HANDLE hIB;
58 LPSTR iBootPath;
59 LPSTR DfuPath;
60#endif
61 irecv_event_cb_t progress_callback;
62 irecv_event_cb_t received_callback;
63 irecv_event_cb_t connected_callback;
64 irecv_event_cb_t precommand_callback;
65 irecv_event_cb_t postcommand_callback;
66 irecv_event_cb_t disconnected_callback;
67};
68
45#define USB_TIMEOUT 10000 69#define USB_TIMEOUT 10000
70#define APPLE_VENDOR_ID 0x05AC
46 71
47#define BUFFER_SIZE 0x1000 72#define BUFFER_SIZE 0x1000
48#define debug(...) if(libirecovery_debug) fprintf(stderr, __VA_ARGS__) 73#define debug(...) if(libirecovery_debug) fprintf(stderr, __VA_ARGS__)
@@ -52,6 +77,44 @@ static int libirecovery_debug = 0;
52static libusb_context* libirecovery_context = NULL; 77static libusb_context* libirecovery_context = NULL;
53#endif 78#endif
54 79
80static struct irecv_device irecv_devices[] = {
81 {"iPhone1,1", "m68ap", 0x00, 0x8900 },
82 {"iPhone1,2", "n82ap", 0x04, 0x8900 },
83 {"iPhone2,1", "n88ap", 0x00, 0x8920 },
84 {"iPhone3,1", "n90ap", 0x00, 0x8930 },
85 {"iPhone3,2", "n90bap", 0x04, 0x8930 },
86 {"iPhone3,3", "n92ap", 0x06, 0x8930 },
87 {"iPhone4,1", "n94ap", 0x08, 0x8940 },
88 {"iPhone5,1", "n41ap", 0x00, 0x8950 },
89 {"iPhone5,2", "n42ap", 0x02, 0x8950 },
90 {"iPhone5,3", "n48ap", 0x0a, 0x8950 },
91 {"iPhone5,4", "n49ap", 0x0e, 0x8950 },
92 {"iPhone6,1", "n51ap", 0x00, 0x8960 },
93 {"iPhone6,2", "n53ap", 0x02, 0x8960 },
94 {"iPod1,1", "n45ap", 0x02, 0x8900 },
95 {"iPod2,1", "n72ap", 0x00, 0x8720 },
96 {"iPod3,1", "n18ap", 0x02, 0x8922 },
97 {"iPod4,1", "n81ap", 0x08, 0x8930 },
98 {"iPod5,1", "n78ap", 0x00, 0x8942 },
99 {"iPad1,1", "k48ap", 0x02, 0x8930 },
100 {"iPad2,1", "k93ap", 0x04, 0x8940 },
101 {"iPad2,2", "k94ap", 0x06, 0x8940 },
102 {"iPad2,3", "k95ap", 0x02, 0x8940 },
103 {"iPad2,4", "k93aap", 0x06, 0x8942 },
104 {"iPad2,5", "p105ap", 0x0a, 0x8942 },
105 {"iPad2,6", "p106ap", 0x0c, 0x8942 },
106 {"iPad2,7", "p107ap", 0x0e, 0x8942 },
107 {"iPad3,1", "j1ap", 0x00, 0x8945 },
108 {"iPad3,2", "j2ap", 0x02, 0x8945 },
109 {"iPad3,3", "j2aap", 0x04, 0x8945 },
110 {"iPad3,4", "p101ap", 0x00, 0x8955 },
111 {"iPad3,5", "p102ap", 0x02, 0x8955 },
112 {"iPad3,6", "p103ap", 0x04, 0x8955 },
113 {"AppleTV2,1", "k66ap", 0x10, 0x8930 },
114 {"AppleTV3,1", "j33ap", 0x08, 0x8942 },
115 {"AppleTV3,2","j33iap", 0x00, 0x8947 },
116 { NULL, NULL, -1, -1 }
117};
55 118
56static unsigned int dfu_hash_t1[256] = { 119static unsigned int dfu_hash_t1[256] = {
57 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 120 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
@@ -148,8 +211,8 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, unsigned long long ec
148 SP_DEVICE_INTERFACE_DATA currentInterface; 211 SP_DEVICE_INTERFACE_DATA currentInterface;
149 HDEVINFO usbDevices; 212 HDEVINFO usbDevices;
150 DWORD i; 213 DWORD i;
151 irecv_client_t _client = (irecv_client_t) malloc(sizeof(struct irecv_client)); 214 irecv_client_t _client = (irecv_client_t) malloc(sizeof(struct irecv_client_private));
152 memset(_client, 0, sizeof(struct irecv_client)); 215 memset(_client, 0, sizeof(struct irecv_client_private));
153 216
154 // Get DFU paths 217 // Get DFU paths
155 usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DFU, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); 218 usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DFU, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
@@ -561,7 +624,7 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, unsigned long long e
561 return IRECV_E_UNABLE_TO_CONNECT; 624 return IRECV_E_UNABLE_TO_CONNECT;
562 } 625 }
563 626
564 irecv_client_t client = (irecv_client_t) malloc(sizeof(struct irecv_client)); 627 irecv_client_t client = (irecv_client_t) malloc(sizeof(struct irecv_client_private));
565 if (client == NULL) { 628 if (client == NULL) {
566 libusb_free_device_list(usb_device_list, 1); 629 libusb_free_device_list(usb_device_list, 1);
567 libusb_close(usb_handle); 630 libusb_close(usb_handle);
@@ -569,7 +632,7 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, unsigned long long e
569 return IRECV_E_OUT_OF_MEMORY; 632 return IRECV_E_OUT_OF_MEMORY;
570 } 633 }
571 634
572 memset(client, '\0', sizeof(struct irecv_client)); 635 memset(client, '\0', sizeof(struct irecv_client_private));
573 client->interface = 0; 636 client->interface = 0;
574 client->handle = usb_handle; 637 client->handle = usb_handle;
575 client->mode = usb_descriptor.idProduct; 638 client->mode = usb_descriptor.idProduct;
@@ -1446,6 +1509,8 @@ irecv_error_t irecv_devices_get_device_by_client(irecv_client_t client, irecv_de
1446 uint32_t cpid = 0; 1509 uint32_t cpid = 0;
1447 int i = 0; 1510 int i = 0;
1448 1511
1512 *device = NULL;
1513
1449 if (irecv_get_cpid(client, &cpid) < 0) { 1514 if (irecv_get_cpid(client, &cpid) < 0) {
1450 return IRECV_E_UNKNOWN_ERROR; 1515 return IRECV_E_UNKNOWN_ERROR;
1451 } 1516 }