diff options
Diffstat (limited to 'include/libirecovery.h')
-rw-r--r-- | include/libirecovery.h | 240 |
1 files changed, 160 insertions, 80 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h index c459984..ec9255b 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h | |||
@@ -1,20 +1,22 @@ | |||
1 | /** | 1 | /* |
2 | * iRecovery - Utility for DFU 2.0, WTF and Recovery Mode | 2 | * libirecovery.h |
3 | * Copyright (C) 2008 - 2009 westbaer | 3 | * Communication to iBoot/iBSS on Apple iOS devices via USB |
4 | * | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | 5 | * Copyright (c) 2012-2023 Nikias Bassen <nikias@gmx.li> |
6 | * it under the terms of the GNU General Public License as published by | 6 | * Copyright (c) 2012-2013 Martin Szulecki <m.szulecki@libimobiledevice.org> |
7 | * the Free Software Foundation, either version 3 of the License, or | 7 | * Copyright (c) 2010 Chronic-Dev Team |
8 | * (at your option) any later version. | 8 | * Copyright (c) 2010 Joshua Hill |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, | 10 | * All rights reserved. This program and the accompanying materials |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * are made available under the terms of the GNU Lesser General Public License |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * (LGPL) version 2.1 which accompanies this distribution, and is available at |
13 | * GNU General Public License for more details. | 13 | * http://www.gnu.org/licenses/lgpl-2.1.html |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License | 15 | * This library is distributed in the hope that it will be useful, |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | **/ | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 | * Lesser General Public License for more details. | ||
19 | */ | ||
18 | 20 | ||
19 | #ifndef LIBIRECOVERY_H | 21 | #ifndef LIBIRECOVERY_H |
20 | #define LIBIRECOVERY_H | 22 | #define LIBIRECOVERY_H |
@@ -23,93 +25,171 @@ | |||
23 | extern "C" { | 25 | extern "C" { |
24 | #endif | 26 | #endif |
25 | 27 | ||
26 | #include <libusb-1.0/libusb.h> | 28 | #include <stdint.h> |
27 | 29 | ||
28 | #define APPLE_VENDOR_ID 0x05AC | 30 | #ifndef IRECV_API |
31 | #ifdef IRECV_STATIC | ||
32 | #define IRECV_API | ||
33 | #elif defined(_WIN32) | ||
34 | #define IRECV_API __declspec(dllimport) | ||
35 | #else | ||
36 | #define IRECV_API | ||
37 | #endif | ||
38 | #endif | ||
29 | 39 | ||
30 | enum { | 40 | enum irecv_mode { |
31 | kRecoveryMode1 = 0x1280, | 41 | IRECV_K_RECOVERY_MODE_1 = 0x1280, |
32 | kRecoveryMode2 = 0x1281, | 42 | IRECV_K_RECOVERY_MODE_2 = 0x1281, |
33 | kRecoveryMode3 = 0x1282, | 43 | IRECV_K_RECOVERY_MODE_3 = 0x1282, |
34 | kRecoveryMode4 = 0x1283, | 44 | IRECV_K_RECOVERY_MODE_4 = 0x1283, |
35 | kDfuMode = 0x1227 | 45 | IRECV_K_WTF_MODE = 0x1222, |
46 | IRECV_K_DFU_MODE = 0x1227, | ||
47 | IRECV_K_PORT_DFU_MODE = 0xf014 | ||
36 | }; | 48 | }; |
37 | 49 | ||
38 | typedef enum { | 50 | typedef enum { |
39 | IRECV_E_SUCCESS = 0, | 51 | IRECV_E_SUCCESS = 0, |
40 | IRECV_E_NO_DEVICE = -1, | 52 | IRECV_E_NO_DEVICE = -1, |
41 | IRECV_E_OUT_OF_MEMORY = -2, | 53 | IRECV_E_OUT_OF_MEMORY = -2, |
42 | IRECV_E_UNABLE_TO_CONNECT = -3, | 54 | IRECV_E_UNABLE_TO_CONNECT = -3, |
43 | IRECV_E_INVALID_INPUT = -4, | 55 | IRECV_E_INVALID_INPUT = -4, |
44 | IRECV_E_FILE_NOT_FOUND = -5, | 56 | IRECV_E_FILE_NOT_FOUND = -5, |
45 | IRECV_E_USB_UPLOAD = -6, | 57 | IRECV_E_USB_UPLOAD = -6, |
46 | IRECV_E_USB_STATUS = -7, | 58 | IRECV_E_USB_STATUS = -7, |
47 | IRECV_E_USB_INTERFACE = -8, | 59 | IRECV_E_USB_INTERFACE = -8, |
48 | IRECV_E_USB_CONFIGURATION = -9, | 60 | IRECV_E_USB_CONFIGURATION = -9, |
49 | IRECV_E_PIPE = -10, | 61 | IRECV_E_PIPE = -10, |
50 | IRECV_E_TIMEOUT = -11, | 62 | IRECV_E_TIMEOUT = -11, |
51 | IRECV_E_UNKNOWN_ERROR = -255 | 63 | IRECV_E_UNSUPPORTED = -254, |
64 | IRECV_E_UNKNOWN_ERROR = -255 | ||
52 | } irecv_error_t; | 65 | } irecv_error_t; |
53 | 66 | ||
54 | typedef enum { | 67 | typedef enum { |
55 | IRECV_RECEIVED = 1, | 68 | IRECV_RECEIVED = 1, |
56 | IRECV_PRECOMMAND = 2, | 69 | IRECV_PRECOMMAND = 2, |
57 | IRECV_POSTCOMMAND = 3, | 70 | IRECV_POSTCOMMAND = 3, |
58 | IRECV_CONNECTED = 4, | 71 | IRECV_CONNECTED = 4, |
59 | IRECV_DISCONNECTED = 5, | 72 | IRECV_DISCONNECTED = 5, |
60 | IRECV_PROGRESS = 6 | 73 | IRECV_PROGRESS = 6 |
61 | } irecv_event_type; | 74 | } irecv_event_type; |
62 | 75 | ||
63 | typedef struct { | 76 | typedef struct { |
64 | int size; | 77 | int size; |
65 | char* data; | 78 | const char* data; |
66 | double progress; | 79 | double progress; |
67 | irecv_event_type type; | 80 | irecv_event_type type; |
68 | } irecv_event_t; | 81 | } irecv_event_t; |
69 | 82 | ||
70 | struct irecv_client; | 83 | struct irecv_device { |
71 | typedef struct irecv_client* irecv_client_t; | 84 | const char* product_type; |
72 | typedef int(*irecv_event_cb_t)(irecv_client_t client, const irecv_event_t* event); | 85 | const char* hardware_model; |
86 | unsigned int board_id; | ||
87 | unsigned int chip_id; | ||
88 | const char* display_name; | ||
89 | }; | ||
90 | typedef struct irecv_device* irecv_device_t; | ||
91 | |||
92 | struct irecv_device_info { | ||
93 | unsigned int cpid; | ||
94 | unsigned int cprv; | ||
95 | unsigned int cpfm; | ||
96 | unsigned int scep; | ||
97 | unsigned int bdid; | ||
98 | uint64_t ecid; | ||
99 | unsigned int ibfl; | ||
100 | char* srnm; | ||
101 | char* imei; | ||
102 | char* srtg; | ||
103 | char* serial_string; | ||
104 | unsigned char* ap_nonce; | ||
105 | unsigned int ap_nonce_size; | ||
106 | unsigned char* sep_nonce; | ||
107 | unsigned int sep_nonce_size; | ||
108 | uint16_t pid; | ||
109 | }; | ||
73 | 110 | ||
74 | struct irecv_client { | 111 | typedef enum { |
75 | int debug; | 112 | IRECV_DEVICE_ADD = 1, |
76 | int config; | 113 | IRECV_DEVICE_REMOVE = 2 |
77 | int interface; | 114 | } irecv_device_event_type; |
78 | int alt_interface; | 115 | |
79 | unsigned short mode; | 116 | typedef struct { |
80 | char serial[256]; | 117 | irecv_device_event_type type; |
81 | libusb_device_handle* handle; | 118 | enum irecv_mode mode; |
82 | irecv_event_cb_t progress_callback; | 119 | struct irecv_device_info *device_info; |
83 | irecv_event_cb_t received_callback; | 120 | } irecv_device_event_t; |
84 | irecv_event_cb_t connected_callback; | 121 | |
85 | irecv_event_cb_t precommand_callback; | 122 | typedef struct irecv_client_private irecv_client_private; |
86 | irecv_event_cb_t postcommand_callback; | 123 | typedef irecv_client_private* irecv_client_t; |
87 | irecv_event_cb_t disconnected_callback; | 124 | |
125 | enum { | ||
126 | IRECV_SEND_OPT_NONE = 0, | ||
127 | IRECV_SEND_OPT_DFU_NOTIFY_FINISH = (1 << 0), | ||
128 | IRECV_SEND_OPT_DFU_FORCE_ZLP = (1 << 1), | ||
129 | IRECV_SEND_OPT_DFU_SMALL_PKT = (1 << 2) | ||
88 | }; | 130 | }; |
89 | 131 | ||
90 | void irecv_set_debug_level(int level); | 132 | /* library */ |
91 | const char* irecv_strerror(irecv_error_t error); | 133 | IRECV_API void irecv_set_debug_level(int level); |
92 | irecv_error_t irecv_open(irecv_client_t* client); | 134 | IRECV_API const char* irecv_strerror(irecv_error_t error); |
93 | irecv_error_t irecv_reset(irecv_client_t client); | 135 | IRECV_API void irecv_init(void); /* deprecated: libirecovery has constructor now */ |
94 | irecv_error_t irecv_close(irecv_client_t client); | 136 | IRECV_API void irecv_exit(void); /* deprecated: libirecovery has destructor now */ |
95 | irecv_error_t irecv_receive(irecv_client_t client); | 137 | |
96 | irecv_error_t irecv_send_exploit(irecv_client_t client); | 138 | IRECV_API const char* irecv_version(); |
97 | irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename); | 139 | |
98 | irecv_error_t irecv_set_configuration(irecv_client_t client, int configuration); | 140 | /* device connectivity */ |
99 | 141 | IRECV_API irecv_error_t irecv_open_with_ecid(irecv_client_t* client, uint64_t ecid); | |
100 | irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void *user_data); | 142 | IRECV_API irecv_error_t irecv_open_with_ecid_and_attempts(irecv_client_t* pclient, uint64_t ecid, int attempts); |
101 | irecv_error_t irecv_event_unsubscribe(irecv_client_t client, irecv_event_type type); | 143 | IRECV_API irecv_error_t irecv_reset(irecv_client_t client); |
102 | 144 | IRECV_API irecv_error_t irecv_close(irecv_client_t client); | |
103 | irecv_error_t irecv_send_file(irecv_client_t client, const char* filename); | 145 | IRECV_API irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause); |
104 | irecv_error_t irecv_send_command(irecv_client_t client, unsigned char* command); | 146 | |
105 | irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, unsigned long length); | 147 | /* misc */ |
106 | 148 | IRECV_API irecv_error_t irecv_receive(irecv_client_t client); | |
107 | irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value); | 149 | IRECV_API irecv_error_t irecv_execute_script(irecv_client_t client, const char* script); |
108 | irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value); | 150 | IRECV_API irecv_error_t irecv_reset_counters(irecv_client_t client); |
109 | irecv_error_t irecv_set_interface(irecv_client_t client, int interface, int alt_interface); | 151 | IRECV_API irecv_error_t irecv_finish_transfer(irecv_client_t client); |
110 | irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid); | 152 | IRECV_API irecv_error_t irecv_trigger_limera1n_exploit(irecv_client_t client); |
111 | irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid); | 153 | |
112 | irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid); | 154 | /* usb helpers */ |
155 | IRECV_API irecv_error_t irecv_usb_set_configuration(irecv_client_t client, int configuration); | ||
156 | IRECV_API irecv_error_t irecv_usb_set_interface(irecv_client_t client, int usb_interface, int usb_alt_interface); | ||
157 | IRECV_API int irecv_usb_control_transfer(irecv_client_t client, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, unsigned char *data, uint16_t w_length, unsigned int timeout); | ||
158 | IRECV_API int irecv_usb_bulk_transfer(irecv_client_t client, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout); | ||
159 | |||
160 | /* events */ | ||
161 | typedef void(*irecv_device_event_cb_t)(const irecv_device_event_t* event, void *user_data); | ||
162 | typedef struct irecv_device_event_context* irecv_device_event_context_t; | ||
163 | IRECV_API irecv_error_t irecv_device_event_subscribe(irecv_device_event_context_t *context, irecv_device_event_cb_t callback, void *user_data); | ||
164 | IRECV_API irecv_error_t irecv_device_event_unsubscribe(irecv_device_event_context_t context); | ||
165 | typedef int(*irecv_event_cb_t)(irecv_client_t client, const irecv_event_t* event); | ||
166 | IRECV_API irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void *user_data); | ||
167 | IRECV_API irecv_error_t irecv_event_unsubscribe(irecv_client_t client, irecv_event_type type); | ||
168 | |||
169 | /* I/O */ | ||
170 | IRECV_API irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, unsigned int options); | ||
171 | IRECV_API irecv_error_t irecv_send_command(irecv_client_t client, const char* command); | ||
172 | IRECV_API irecv_error_t irecv_send_command_breq(irecv_client_t client, const char* command, uint8_t b_request); | ||
173 | IRECV_API irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, unsigned long length, unsigned int options); | ||
174 | IRECV_API irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned long length); | ||
175 | |||
176 | /* commands */ | ||
177 | IRECV_API irecv_error_t irecv_saveenv(irecv_client_t client); | ||
178 | IRECV_API irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value); | ||
179 | IRECV_API irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value); | ||
180 | IRECV_API irecv_error_t irecv_setenv_np(irecv_client_t client, const char* variable, const char* value); | ||
181 | IRECV_API irecv_error_t irecv_reboot(irecv_client_t client); | ||
182 | IRECV_API irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value); | ||
183 | |||
184 | /* device information */ | ||
185 | IRECV_API irecv_error_t irecv_get_mode(irecv_client_t client, int* mode); | ||
186 | IRECV_API const struct irecv_device_info* irecv_get_device_info(irecv_client_t client); | ||
187 | |||
188 | /* device database queries */ | ||
189 | IRECV_API irecv_device_t irecv_devices_get_all(void); | ||
190 | IRECV_API irecv_error_t irecv_devices_get_device_by_client(irecv_client_t client, irecv_device_t* device); | ||
191 | IRECV_API irecv_error_t irecv_devices_get_device_by_product_type(const char* product_type, irecv_device_t* device); | ||
192 | IRECV_API irecv_error_t irecv_devices_get_device_by_hardware_model(const char* hardware_model, irecv_device_t* device); | ||
113 | 193 | ||
114 | #ifdef __cplusplus | 194 | #ifdef __cplusplus |
115 | } | 195 | } |