summaryrefslogtreecommitdiffstats
path: root/src/libirecovery.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r--src/libirecovery.c83
1 files changed, 3 insertions, 80 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index e3d6eb6..630a9b7 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -175,13 +175,11 @@ unsigned int irecv_get_status(irecv_device* device) {
175} 175}
176 176
177int irecv_send_buffer(irecv_device* device, unsigned char* buffer, int length) { 177int irecv_send_buffer(irecv_device* device, unsigned char* buffer, int length) {
178 int last = length % 0x800;
178 int packets = length / 0x800; 179 int packets = length / 0x800;
179 if (length % 0x800) { 180 if (last != 0) {
180 packets++; 181 packets++;
181 } 182 } else {
182
183 int last = length % 0x800;
184 if (!last) {
185 last = 0x800; 183 last = 0x800;
186 } 184 }
187 185
@@ -212,78 +210,3 @@ int irecv_send_buffer(irecv_device* device, unsigned char* buffer, int length) {
212 free(buffer); 210 free(buffer);
213 return IRECV_SUCCESS; 211 return IRECV_SUCCESS;
214} 212}
215
216/*
217int send_file(struct libusb_device_handle *handle, const char* filename, int loadOffset) {
218 FILE* file = fopen(filename, "rb");
219 if (file == NULL) {
220 printf("send_file: File %s not found.\n", filename);
221 return -1;
222 }
223
224 fseek(file, 0, SEEK_END);
225 int len = ftell(file);
226 fseek(file, 0, SEEK_SET);
227
228 char* buffer = malloc(len + loadOffset);
229 if (buffer == NULL) {
230 printf("send_file: Error allocating memory!\n");
231 fclose(file);
232 return -1;
233 }
234
235 fread(&buffer[loadOffset], 1, len, file);
236 fclose(file);
237
238 len += loadOffset;
239
240 int packets = len / 0x800;
241 if (len % 0x800) {
242 packets++;
243 }
244
245 int last = len % 0x800;
246 if (!last) {
247 last = 0x800;
248 }
249
250 int i = 0;
251 char response[6];
252 for (i = 0; i < packets; i++) {
253 int size = i + 1 < packets ? 0x800 : last;
254
255 if (!libusb_control_transfer(handle, 0x21, 1, i, 0, &buffer[i * 0x800], size, 1000)) {
256 printf("send_file: Error sending packet!\n");
257 return -1;
258 }
259
260 if (libusb_control_transfer(handle, 0xA1, 3, 0, 0, response, 6, 1000) != 6) {
261 printf("send_file: Error receiving status!\n");
262 return -1;
263
264 } else {
265 if (response[4] != 5) {
266 printf("send_file: Status error!\n");
267 return -1;
268 }
269 }
270 }
271
272 libusb_control_transfer(handle, 0x21, 1, i, 0, buffer, 0, 1000);
273 for (i = 6; i <= 8; i++) {
274 if (libusb_control_transfer(handle, 0xA1, 3, 0, 0, response, 6, 1000) != 6) {
275 printf("send_file: Error receiving status!\n");
276 return -1;
277
278 } else {
279 if (response[4] != i) {
280 printf("send_file: Status error!\n");
281 return -1;
282 }
283 }
284 }
285
286 free(buffer);
287 return 0;
288}
289*/