From: yoonki.park Date: Thu, 24 Oct 2013 18:41:43 +0000 (+0900) Subject: fixed to register multiple same device & remove device from list when unplugging usb X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dbc850c5f3701e10be50a795bb3c55acfa136adc;p=sdk%2Ftools%2Fsdb.git fixed to register multiple same device & remove device from list when unplugging usb Change-Id: Ic57837abcfca627d40621e74660c19e385df5bd5 Signed-off-by: yoonki.park --- diff --git a/src/sdb_usb.h b/src/sdb_usb.h index 9d55a09..533bcec 100755 --- a/src/sdb_usb.h +++ b/src/sdb_usb.h @@ -37,4 +37,5 @@ void kick_disconnected_devices(); */ #define MAX_READ_WRITE (16 * 1024) +#define MAX_SERIAL_NAME 128 #endif // __USB_H diff --git a/src/usb_darwin.c b/src/usb_darwin.c index 7e9024d..03c16e0 100755 --- a/src/usb_darwin.c +++ b/src/usb_darwin.c @@ -40,7 +40,6 @@ #include "linkedlist.h" #include "transport.h" -#define MAX_C_STRLEN 128 #define kUSBLanguageEnglish 0x409 static IONotificationPortRef gNotifyPort; @@ -125,7 +124,7 @@ kern_return_t getUSBSerial(IOUSBDeviceInterface182 **dev, UInt8 string_id, char ((result_length - 2) >> 1)); /* Copy the character contents to a local C string */ - CFStringGetCString(result, spotSerial, MAX_C_STRLEN, kCFStringEncodingASCII); + CFStringGetCString(result, spotSerial, MAX_SERIAL_NAME, kCFStringEncodingASCII); } } } diff --git a/src/usb_linux.c b/src/usb_linux.c index 4f72d8a..545a535 100644 --- a/src/usb_linux.c +++ b/src/usb_linux.c @@ -33,7 +33,7 @@ #include "transport.h" #define TRACE_TAG TRACE_USB - +#define URB_TRANSFER_TIMEOUT 3000 SDB_MUTEX_DEFINE( usb_lock); LIST_NODE* usb_list = NULL; @@ -168,7 +168,7 @@ int register_device(const char* node, const char* serial) { usb->end_point[0] = endpoint_in; usb->end_point[1] = endpoint_out; - char usb_serial[256] = { 0, }; + char usb_serial[MAX_SERIAL_NAME] = { 0, }; if (serial != NULL) { s_strncpy(usb_serial, serial, sizeof(usb_serial)); @@ -387,9 +387,14 @@ static int usb_urb_transfer(usb_handle *h, int ep, char *bytes, int size, restart: waiting = 1; context = NULL; - while (!urb.usercontext - && ((ret = ioctl(h->node_fd, USBDEVFS_REAPURBNDELAY, &context)) - == -1) && waiting) { + for (;;) { + ret = ioctl(h->node_fd, USBDEVFS_REAPURBNDELAY, &context); + if (!urb.usercontext && (ret == -1) && waiting) { + continue; + } else { + break; + } + tv.tv_sec = 0; tv.tv_usec = 1000; // 1 msec @@ -401,8 +406,9 @@ static int usb_urb_transfer(usb_handle *h, int ep, char *bytes, int size, if ((tv_now.tv_sec > tv_cur.tv_sec) || ((tv_now.tv_sec == tv_cur.tv_sec) - && (tv_now.tv_usec >= tv_ref.tv_usec))) + && (tv_now.tv_usec >= tv_ref.tv_usec))) { waiting = 0; + } } } @@ -458,7 +464,7 @@ int sdb_usb_write(usb_handle *h, const void *_data, int len) { while (len > 0) { int xfer = (len > MAX_READ_WRITE) ? MAX_READ_WRITE : len; - n = usb_urb_transfer(h, h->end_point[1], data, xfer, 0); + n = usb_urb_transfer(h, h->end_point[1], data, xfer, URB_TRANSFER_TIMEOUT); if (n != xfer) { D("fail to usb write: n = %d, errno = %d (%s)\n", n, errno, strerror(errno)); return -1; @@ -482,7 +488,7 @@ int sdb_usb_read(usb_handle *h, void *_data, int len) { while (len > 0) { int xfer = (len > MAX_READ_WRITE) ? MAX_READ_WRITE : len; - n = usb_urb_transfer(h, h->end_point[0], data, xfer, 0); + n = usb_urb_transfer(h, h->end_point[0], data, xfer, URB_TRANSFER_TIMEOUT); if (n != xfer) { if ((errno == ETIMEDOUT)) { D("usb bulk read timeout\n"); diff --git a/src/usb_windows.c b/src/usb_windows.c index aed769e..87f0913 100644 --- a/src/usb_windows.c +++ b/src/usb_windows.c @@ -375,7 +375,7 @@ int usb_find_devices(GUID deviceClassID) { if (!is_device_registered(devicePath)) { struct usb_handle *hnd = usb_open(devicePath); if (hnd != NULL) { - char serial[256]; + char serial[MAX_SERIAL_NAME]={0,}; if (get_serial_number(hnd, serial, sizeof(serial)) > 0) { LOG_DEBUG("register usb for: %s\n", serial); if (register_device(hnd)) {