diff options
| author | 2010-05-13 08:58:46 -0400 | |
|---|---|---|
| committer | 2010-05-13 08:58:46 -0400 | |
| commit | 520c99d33e18009660f30bd38b31a2f1cd432fe6 (patch) | |
| tree | 554dcde9de73f69a1cc34de0e4c7819fd148a5e8 /src/libirecovery.c | |
| parent | 5bbd277ce71521a3898697e4c8cb25ed65990f9c (diff) | |
| download | libirecovery-520c99d33e18009660f30bd38b31a2f1cd432fe6.tar.gz libirecovery-520c99d33e18009660f30bd38b31a2f1cd432fe6.tar.bz2 | |
Implemented command line argument parsing and irecv_command() function.
Diffstat (limited to 'src/libirecovery.c')
| -rw-r--r-- | src/libirecovery.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index a5b5c84..85967ec 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
| @@ -23,14 +23,13 @@ | |||
| 23 | 23 | ||
| 24 | #include "libirecovery.h" | 24 | #include "libirecovery.h" |
| 25 | 25 | ||
| 26 | static unsigned int debug = 1; | 26 | static unsigned int irecv_debug = 0; |
| 27 | 27 | ||
| 28 | int irecv_init(irecv_device** p_device) { | 28 | int irecv_init(irecv_device** p_device) { |
| 29 | struct libusb_context* usb_context = NULL; | 29 | struct libusb_context* usb_context = NULL; |
| 30 | 30 | ||
| 31 | libusb_init(&usb_context); | 31 | libusb_init(&usb_context); |
| 32 | if (debug) | 32 | if (irecv_debug) libusb_set_debug(usb_context, 3); |
| 33 | libusb_set_debug(usb_context, 3); | ||
| 34 | 33 | ||
| 35 | irecv_device* device = (irecv_device*) malloc(sizeof(irecv_device)); | 34 | irecv_device* device = (irecv_device*) malloc(sizeof(irecv_device)); |
| 36 | if (device == NULL) { | 35 | if (device == NULL) { |
| @@ -60,7 +59,7 @@ int irecv_open(irecv_device* device) { | |||
| 60 | for (i = 0; i < usb_device_count; i++) { | 59 | for (i = 0; i < usb_device_count; i++) { |
| 61 | usb_device = usb_device_list[i]; | 60 | usb_device = usb_device_list[i]; |
| 62 | libusb_get_device_descriptor(usb_device, &usb_descriptor); | 61 | libusb_get_device_descriptor(usb_device, &usb_descriptor); |
| 63 | if (usb_descriptor.idVendor == kAppleVendorId) { | 62 | if (usb_descriptor.idVendor == kAppleId) { |
| 64 | 63 | ||
| 65 | libusb_open(usb_device, &usb_handle); | 64 | libusb_open(usb_device, &usb_handle); |
| 66 | if (usb_handle == NULL) { | 65 | if (usb_handle == NULL) { |
| @@ -115,3 +114,30 @@ int irecv_exit(irecv_device* device) { | |||
| 115 | 114 | ||
| 116 | return IRECV_SUCCESS; | 115 | return IRECV_SUCCESS; |
| 117 | } | 116 | } |
| 117 | |||
| 118 | void irecv_set_debug(int level) { | ||
| 119 | printf("Debug has been set to %d\n", level); | ||
| 120 | irecv_debug = level; | ||
| 121 | } | ||
| 122 | |||
| 123 | int irecv_command(irecv_device* device, const char* command) { | ||
| 124 | if(device == NULL || device->handle == NULL) { | ||
| 125 | return IRECV_ERROR_NO_DEVICE; | ||
| 126 | } | ||
| 127 | |||
| 128 | ssize_t length = strlen(command); | ||
| 129 | if(length >= 0x100) { | ||
| 130 | return IRECV_ERROR_INVALID_INPUT; | ||
| 131 | } | ||
| 132 | |||
| 133 | int ret = libusb_control_transfer(device->handle, 0x40, 0, 0, 0, (unsigned char*) command, length+1, 100); | ||
| 134 | if(ret < 0) { | ||
| 135 | return IRECV_ERROR_UNKNOWN; | ||
| 136 | } | ||
| 137 | |||
| 138 | return IRECV_SUCCESS; | ||
| 139 | } | ||
| 140 | |||
| 141 | int irecv_upload(irecv_device* device, const char* filename) { | ||
| 142 | return IRECV_SUCCESS; | ||
| 143 | } | ||
