summaryrefslogtreecommitdiffstats
path: root/src/libirecovery.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-09-26 23:53:23 +0200
committerGravatar Martin Szulecki2013-09-26 23:53:23 +0200
commit4afbb1aec79b3f80c55b3156475bdf546461464d (patch)
tree22b858cee5e5c64fd4f1336c87baa1f281d64797 /src/libirecovery.c
parent218635e3710ef6df647752294d52c8200b643b6f (diff)
downloadlibirecovery-4afbb1aec79b3f80c55b3156475bdf546461464d.tar.gz
libirecovery-4afbb1aec79b3f80c55b3156475bdf546461464d.tar.bz2
Move device database, client and device structs into private implementation
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r--src/libirecovery.c73
1 files changed, 69 insertions, 4 deletions
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 }