summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-07-26 01:44:03 +0200
committerGravatar Martin Szulecki2010-07-26 01:44:03 +0200
commit49765561ae922dcfe55294534c493f32cb81b67b (patch)
tree24c948ac3c8c436aeb239cc9814742a3843efeec
parent18c0756c78b49f197437d4aba924ab2e92cdad5d (diff)
downloadlibirecovery-49765561ae922dcfe55294534c493f32cb81b67b.tar.gz
libirecovery-49765561ae922dcfe55294534c493f32cb81b67b.tar.bz2
Cache the USB serial on irecv_open() to avoid descriptor calls later
-rw-r--r--include/libirecovery.h1
-rw-r--r--src/libirecovery.c24
2 files changed, 7 insertions, 18 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h
index 3e03626..c459984 100644
--- a/include/libirecovery.h
+++ b/include/libirecovery.h
@@ -77,6 +77,7 @@ struct irecv_client {
int interface;
int alt_interface;
unsigned short mode;
+ char serial[256];
libusb_device_handle* handle;
irecv_event_cb_t progress_callback;
irecv_event_cb_t received_callback;
diff --git a/src/libirecovery.c b/src/libirecovery.c
index 18683f1..38e0fc3 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -93,6 +93,9 @@ irecv_error_t irecv_open(irecv_client_t* pclient) {
return error;
}
+ /* cache usb serial */
+ libusb_get_string_descriptor_ascii(client->handle, usb_descriptor.iSerialNumber, client->serial, 255);
+
*pclient = client;
return IRECV_E_SUCCESS;
}
@@ -501,16 +504,11 @@ irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** v
}
irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid) {
- char info[256];
- memset(info, '\0', 256);
-
if (client == NULL || client->handle == NULL) {
return IRECV_E_NO_DEVICE;
}
- libusb_get_string_descriptor_ascii(client->handle, 3, info, 255);
-
- unsigned char* cpid_string = strstr(info, "CPID:");
+ unsigned char* cpid_string = strstr(client->serial, "CPID:");
if (cpid_string == NULL) {
*cpid = 0;
return IRECV_E_UNKNOWN_ERROR;
@@ -521,16 +519,11 @@ irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid) {
}
irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid) {
- char info[256];
- memset(info, '\0', 256);
-
if (client == NULL || client->handle == NULL) {
return IRECV_E_NO_DEVICE;
}
- libusb_get_string_descriptor_ascii(client->handle, 3, info, 255);
-
- unsigned char* bdid_string = strstr(info, "BDID:");
+ unsigned char* bdid_string = strstr(client->serial, "BDID:");
if (bdid_string == NULL) {
*bdid = 0;
return IRECV_E_UNKNOWN_ERROR;
@@ -541,16 +534,11 @@ irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid) {
}
irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid) {
- char info[256];
- memset(info, '\0', 256);
-
if (client == NULL || client->handle == NULL) {
return IRECV_E_NO_DEVICE;
}
- libusb_get_string_descriptor_ascii(client->handle, 3, info, 255);
-
- unsigned char* ecid_string = strstr(info, "ECID:");
+ unsigned char* ecid_string = strstr(client->serial, "ECID:");
if (ecid_string == NULL) {
*ecid = 0;
return IRECV_E_UNKNOWN_ERROR;