#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <signal.h>
#include "pi-debug.h"
#include "pi-source.h"
#include "pi-usb.h"
#include "pi-util.h"
#include <usb.h>
Include dependency graph for libusb.c:

Go to the source code of this file.
Defines | |
| #define | MAX_READ_SIZE 16384 |
| #define | AUTO_READ_SIZE 64 |
Functions | |
| static int | u_open (struct pi_socket *ps, struct pi_sockaddr *addr, size_t addrlen) |
| static int | u_close (struct pi_socket *ps) |
| static ssize_t | u_write (struct pi_socket *ps, const unsigned char *buf, size_t len, int flags) |
| static ssize_t | u_read (struct pi_socket *ps, pi_buffer_t *buf, size_t len, int flags) |
| static int | u_read_i (struct pi_socket *ps, pi_buffer_t *buf, size_t len, int flags, int timeout) |
| static int | u_poll (struct pi_socket *ps, int timeout) |
| static int | u_wait_for_device (struct pi_socket *ps, int *timeout) |
| static int | u_flush (pi_socket_t *ps, int flags) |
| static int | u_control_request (pi_usb_data_t *usb_data, int request_type, int request, int value, int control_index, void *data, int size, int timeout) |
| void | pi_usb_impl_init (struct pi_usb_impl *impl) |
| static int | USB_open (pi_usb_data_t *data) |
| static int | USB_poll (pi_usb_data_t *data) |
| static int | USB_close (void) |
| static void | RD_do_read (int timeout) |
| static void * | RD_main (void *foo) |
| static int | RD_start (void) |
| static int | RD_stop (void) |
Variables | |
| static usb_dev_handle * | USB_handle |
| static int | USB_interface |
| static int | USB_in_endpoint |
| static int | USB_out_endpoint |
| static char * | RD_buffer = NULL |
| static size_t | RD_buffer_size |
| static size_t | RD_buffer_used |
| static pthread_mutex_t | RD_buffer_mutex = PTHREAD_MUTEX_INITIALIZER |
| static pthread_cond_t | RD_buffer_available_cond = PTHREAD_COND_INITIALIZER |
| static int | RD_wanted |
| static int | RD_running = 0 |
| static char | RD_usb_buffer [16384] |
| static pthread_t | RD_thread = 0 |
| #define MAX_READ_SIZE 16384 |
| void pi_usb_impl_init | ( | struct pi_usb_impl * | impl | ) |
Definition at line 66 of file libusb.c.
References pi_usb_impl::changebaud, pi_usb_impl::close, pi_usb_impl::control_request, pi_usb_impl::flush, pi_usb_impl::open, pi_usb_impl::poll, pi_usb_impl::read, u_close(), u_control_request(), u_flush(), u_open(), u_poll(), u_read(), u_wait_for_device(), u_write(), pi_usb_impl::wait_for_device, and pi_usb_impl::write.
00067 { 00068 impl->open = u_open; 00069 impl->close = u_close; 00070 impl->write = u_write; 00071 impl->read = u_read; 00072 impl->flush = u_flush; 00073 impl->poll = u_poll; 00074 impl->wait_for_device = u_wait_for_device; 00075 impl->changebaud = NULL; /* we don't need this one for libusb (yet) */ 00076 impl->control_request = u_control_request; 00077 }
Here is the call graph for this function:

| static void RD_do_read | ( | int | timeout | ) | [static] |
Definition at line 268 of file libusb.c.
References AUTO_READ_SIZE, LOG, MAX_READ_SIZE, PI_DBG_DEV, PI_DBG_LVL_DEBUG, PI_DBG_LVL_ERR, PI_DBG_LVL_NONE, RD_buffer, RD_buffer_available_cond, RD_buffer_mutex, RD_buffer_size, RD_buffer_used, RD_running, RD_usb_buffer, RD_wanted, USB_handle, and USB_in_endpoint.
Referenced by RD_main().
00269 { 00270 int bytes_read, read_size; 00271 00272 read_size = RD_wanted - RD_buffer_used; 00273 if (read_size < AUTO_READ_SIZE) 00274 read_size = AUTO_READ_SIZE; 00275 else if (read_size > MAX_READ_SIZE) 00276 read_size = MAX_READ_SIZE; 00277 00278 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "Reading: len: %d, timeout: %d.\n", read_size, timeout)); 00279 bytes_read = usb_bulk_read (USB_handle, USB_in_endpoint, RD_usb_buffer, read_size, timeout); 00280 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d\n", 00281 __FILE__, __LINE__, __FUNCTION__, bytes_read)); 00282 if (bytes_read < 0) { 00283 if (bytes_read == -ENODEV) { 00284 LOG((PI_DBG_DEV, PI_DBG_LVL_NONE, "Device went byebye!\n")); 00285 RD_running = 0; 00286 return; 00287 #ifdef ELAST 00288 } else if (bytes_read == -(ELAST + 1)) { 00289 usb_clear_halt (USB_handle, USB_in_endpoint); 00290 return; 00291 #endif 00292 } else if (bytes_read == -ETIMEDOUT) 00293 return; 00294 00295 LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, "libusb: USB bulk read returned error code %d\n", bytes_read)); 00296 return; 00297 } 00298 if (!bytes_read) 00299 return; 00300 00301 00302 pthread_mutex_lock (&RD_buffer_mutex); 00303 if ((RD_buffer_used + bytes_read) > RD_buffer_size) { 00304 RD_buffer_size = ((RD_buffer_used + bytes_read + 0xfffe) & ~0xffff) - 1; /* 64k chunks. */ 00305 RD_buffer = realloc (RD_buffer, RD_buffer_size); 00306 } 00307 00308 memcpy (RD_buffer + RD_buffer_used, RD_usb_buffer, bytes_read); 00309 RD_buffer_used += bytes_read; 00310 pthread_cond_broadcast (&RD_buffer_available_cond); 00311 pthread_mutex_unlock (&RD_buffer_mutex); 00312 }
| static void* RD_main | ( | void * | foo | ) | [static] |
Definition at line 315 of file libusb.c.
References RD_buffer, RD_buffer_size, RD_buffer_used, RD_do_read(), and RD_running.
Referenced by RD_start().
00316 { 00317 RD_buffer_used = 0; 00318 RD_buffer = NULL; 00319 RD_buffer_size = 0; 00320 00321 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 00322 00323 while (RD_running == 1) { 00324 RD_do_read (0); 00325 } 00326 00327 RD_running = 0; 00328 00329 return NULL; 00330 }
Here is the call graph for this function:

| static int RD_start | ( | void | ) | [static] |
Definition at line 334 of file libusb.c.
References RD_main(), RD_running, and RD_thread.
Referenced by u_wait_for_device().
00335 { 00336 if (RD_thread || RD_running) 00337 return 0; 00338 00339 RD_running = 1; 00340 pthread_create (&RD_thread, NULL, RD_main, NULL); 00341 00342 return 1; 00343 }
Here is the call graph for this function:

| static int RD_stop | ( | void | ) | [static] |
Definition at line 346 of file libusb.c.
References RD_running, and RD_thread.
Referenced by u_close().
00347 { 00348 if (!RD_thread && !RD_running) 00349 return 0; 00350 00351 if (RD_running) 00352 RD_running = 0; 00353 00354 if (RD_thread) { 00355 pthread_cancel(RD_thread); 00356 RD_thread = 0; 00357 } 00358 00359 if (RD_thread || RD_running) 00360 return 0; 00361 00362 return 1; 00363 }
| static int u_close | ( | struct pi_socket * | ps | ) | [static] |
Definition at line 393 of file libusb.c.
References LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, RD_stop(), pi_socket::sd, and USB_close().
00394 { 00395 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00396 __FILE__, __LINE__, __FUNCTION__)); 00397 00398 RD_stop (); 00399 USB_close (); 00400 00401 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00402 __FILE__, __LINE__, __FUNCTION__)); 00403 00404 return close (ps->sd); 00405 }
Here is the call graph for this function:

| static int u_control_request | ( | pi_usb_data_t * | usb_data, | |
| int | request_type, | |||
| int | request, | |||
| int | value, | |||
| int | control_index, | |||
| void * | data, | |||
| int | size, | |||
| int | timeout | |||
| ) | [static] |
Definition at line 594 of file libusb.c.
References pi_usb_data::ref.
Referenced by pi_usb_impl_init().
00596 { 00597 return usb_control_msg (usb_data->ref, request_type, request, value, control_index, data, size, timeout); 00598 }
| static int u_flush | ( | pi_socket_t * | ps, | |
| int | flags | |||
| ) | [static] |
Definition at line 582 of file libusb.c.
References PI_FLUSH_INPUT, RD_buffer_mutex, and RD_buffer_used.
00583 { 00584 if (flags & PI_FLUSH_INPUT) { 00585 /* clear internal buffer */ 00586 pthread_mutex_lock (&RD_buffer_mutex); 00587 RD_buffer_used = 0; 00588 pthread_mutex_unlock (&RD_buffer_mutex); 00589 } 00590 return 0; 00591 }
| static int u_open | ( | struct pi_socket * | ps, | |
| struct pi_sockaddr * | addr, | |||
| size_t | addrlen | |||
| ) | [static] |
Definition at line 374 of file libusb.c.
References pi_device::data, pi_socket::device, LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, RD_running, and USB_open().
00375 { 00376 pi_usb_data_t *data = (pi_usb_data_t *)ps->device->data; 00377 00378 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00379 __FILE__, __LINE__, __FUNCTION__)); 00380 00381 if (RD_running) 00382 return -1; 00383 if (!USB_open (data)) 00384 return -1; 00385 00386 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00387 __FILE__, __LINE__, __FUNCTION__)); 00388 00389 return 1; 00390 }
Here is the call graph for this function:

| static int u_poll | ( | struct pi_socket * | ps, | |
| int | timeout | |||
| ) | [static] |
Definition at line 450 of file libusb.c.
References LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, PI_MSG_PEEK, and u_read_i().
00451 { 00452 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00453 __FILE__, __LINE__, __FUNCTION__)); 00454 00455 return u_read_i (ps, NULL, 1, PI_MSG_PEEK, timeout); 00456 }
Here is the call graph for this function:

| static ssize_t u_read | ( | struct pi_socket * | ps, | |
| pi_buffer_t * | buf, | |||
| size_t | len, | |||
| int | flags | |||
| ) | [static] |
Definition at line 480 of file libusb.c.
References buf, CHECK, pi_device::data, pi_socket::device, LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, pi_dumpdata(), and u_read_i().
00481 { 00482 int ret; 00483 00484 ret = u_read_i (ps, buf, len, flags, ((struct pi_usb_data *)ps->device->data)->timeout); 00485 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "Read: %d (%d).\n", ret, len)); 00486 if (ret > 0) 00487 CHECK (PI_DBG_DEV, PI_DBG_LVL_DEBUG, pi_dumpdata (buf->data, ret)); 00488 00489 return (ssize_t)ret; 00490 }
Here is the call graph for this function:

| static int u_read_i | ( | struct pi_socket * | ps, | |
| pi_buffer_t * | buf, | |||
| size_t | len, | |||
| int | flags, | |||
| int | timeout | |||
| ) | [static] |
Definition at line 493 of file libusb.c.
References buf, LOG, pi_buffer_append(), PI_DBG_DEV, PI_DBG_LVL_DEBUG, PI_ERR_SOCK_DISCONNECTED, PI_MSG_PEEK, RD_buffer, RD_buffer_available_cond, RD_buffer_mutex, RD_buffer_size, RD_buffer_used, RD_running, and RD_wanted.
Referenced by u_poll(), and u_read().
00494 { 00495 if (!RD_running) 00496 return PI_ERR_SOCK_DISCONNECTED; 00497 00498 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d %d\n", 00499 __FILE__, __LINE__, __FUNCTION__, len, flags, timeout)); 00500 00501 pthread_mutex_lock (&RD_buffer_mutex); 00502 if (flags & PI_MSG_PEEK && len > 256) 00503 len = 256; 00504 00505 if (RD_buffer_used < len) { 00506 struct timeval now; 00507 struct timespec when, nownow; 00508 int last_used; 00509 gettimeofday(&now, NULL); 00510 when.tv_sec = now.tv_sec + timeout / 1000; 00511 when.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000; 00512 if (when.tv_nsec >= 1000000000) { 00513 when.tv_nsec -= 1000000000; 00514 when.tv_sec++; 00515 } 00516 00517 RD_wanted = len; 00518 do { 00519 last_used = RD_buffer_used; 00520 00521 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d.\n", 00522 __FILE__, __LINE__, __FUNCTION__, len, RD_buffer_used)); 00523 00524 if (timeout) { 00525 gettimeofday(&now, NULL); 00526 nownow.tv_sec = now.tv_sec; 00527 nownow.tv_nsec = now.tv_usec * 1000; 00528 if ((nownow.tv_sec == when.tv_sec ? (nownow.tv_nsec > when.tv_nsec) : (nownow.tv_sec > when.tv_sec))) { 00529 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d.\n", 00530 __FILE__, __LINE__, __FUNCTION__, len, RD_buffer_used)); 00531 break; 00532 } 00533 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d.\n", 00534 __FILE__, __LINE__, __FUNCTION__, len, RD_buffer_used)); 00535 if (pthread_cond_timedwait (&RD_buffer_available_cond, &RD_buffer_mutex, &when) == ETIMEDOUT) { 00536 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d.\n", 00537 __FILE__, __LINE__, __FUNCTION__, len, RD_buffer_used)); 00538 break; 00539 } 00540 } else 00541 pthread_cond_wait (&RD_buffer_available_cond, &RD_buffer_mutex); 00542 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d.\n", 00543 __FILE__, __LINE__, __FUNCTION__, len, RD_buffer_used)); 00544 } while (RD_buffer_used < len); 00545 00546 RD_wanted = 0; 00547 } 00548 00549 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s): %d %d.\n", 00550 __FILE__, __LINE__, __FUNCTION__, len, RD_buffer_used)); 00551 00552 if (!RD_running) { 00553 pthread_mutex_unlock (&RD_buffer_mutex); 00554 return PI_ERR_SOCK_DISCONNECTED; 00555 } 00556 00557 if (RD_buffer_used < len) 00558 len = RD_buffer_used; 00559 00560 if (len && buf) { 00561 pi_buffer_append (buf, RD_buffer, len); 00562 if (!(flags & PI_MSG_PEEK)) { 00563 RD_buffer_used -= len; 00564 if (RD_buffer_used) 00565 memmove (RD_buffer, RD_buffer + len, RD_buffer_used); 00566 00567 if ((RD_buffer_size - RD_buffer_used) > (1024 * 1024)) { 00568 /* If we have more then 1M free in the buffer, shrink it. */ 00569 RD_buffer_size = ((RD_buffer_used + 0xfffe) & ~0xffff) - 1; 00570 RD_buffer = realloc (RD_buffer, RD_buffer_size); 00571 } 00572 } 00573 } 00574 00575 pthread_mutex_unlock (&RD_buffer_mutex); 00576 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00577 __FILE__, __LINE__, __FUNCTION__)); 00578 return len; 00579 }
Here is the call graph for this function:

| static int u_wait_for_device | ( | struct pi_socket * | ps, | |
| int * | timeout | |||
| ) | [static] |
Definition at line 408 of file libusb.c.
References pi_device::data, pi_socket::device, LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, pi_timeout_expired(), pi_timeout_to_timespec(), pi_timespec_to_timeout(), RD_start(), USB_close(), and USB_poll().
00409 { 00410 pi_usb_data_t *data = (pi_usb_data_t *)ps->device->data; 00411 struct timespec when; 00412 int ret = 0; 00413 00414 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s %d (%s).\n", 00415 __FILE__, __LINE__, __FUNCTION__)); 00416 00417 if (*timeout) 00418 pi_timeout_to_timespec (*timeout, &when); 00419 00420 while (1) { 00421 ret = USB_poll (data); 00422 if (ret > 0) { 00423 /* Evil, calculate how much longer the timeout is. */ 00424 if (*timeout) { 00425 *timeout = pi_timespec_to_timeout (&when); 00426 if (*timeout <= 0) 00427 *timeout = 1; 00428 } 00429 if (!RD_start ()) { 00430 USB_close (); 00431 return -1; 00432 } 00433 return ret; 00434 00435 } 00436 00437 if (*timeout) { 00438 if (pi_timeout_expired(&when)) { 00439 *timeout = 1; 00440 return 0; 00441 } 00442 } 00443 usleep (500000); 00444 } 00445 00446 return 0; 00447 }
Here is the call graph for this function:

| static ssize_t u_write | ( | struct pi_socket * | ps, | |
| const unsigned char * | buf, | |||
| size_t | len, | |||
| int | flags | |||
| ) | [static] |
Definition at line 459 of file libusb.c.
References CHECK, pi_device::data, pi_socket::device, LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, pi_dumpdata(), RD_running, USB_handle, and USB_out_endpoint.
00460 { 00461 int timeout = ((struct pi_usb_data *)ps->device->data)->timeout; 00462 int ret; 00463 00464 if (!RD_running) 00465 return -1; 00466 00467 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "Writing: len: %d, flags: %d, timeout: %d.\n", len, flags, timeout)); 00468 if (len <= 0) 00469 return 0; 00470 00471 ret = usb_bulk_write (USB_handle, USB_out_endpoint, buf, len, timeout); 00472 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "Wrote: %d.\n", ret)); 00473 if (ret > 0) 00474 CHECK (PI_DBG_DEV, PI_DBG_LVL_DEBUG, pi_dumpdata (buf, ret)); 00475 00476 return (ssize_t)ret; 00477 }
Here is the call graph for this function:

| static int USB_close | ( | void | ) | [static] |
Definition at line 236 of file libusb.c.
References USB_handle, and USB_interface.
Referenced by u_close(), and u_wait_for_device().
00237 { 00238 if (!USB_handle) 00239 return 0; 00240 00241 usb_release_interface (USB_handle, USB_interface); 00242 usb_close (USB_handle); 00243 USB_handle = NULL; 00244 return 1; 00245 }
| static int USB_open | ( | pi_usb_data_t * | data | ) | [static] |
| static int USB_poll | ( | pi_usb_data_t * | data | ) | [static] |
Definition at line 100 of file libusb.c.
References CHECK, LOG, PI_DBG_DEV, PI_DBG_LVL_DEBUG, PI_DBG_LVL_ERR, USB_check_device(), USB_configure_device(), USB_handle, USB_in_endpoint, USB_interface, and USB_out_endpoint.
Referenced by u_wait_for_device().
00101 { 00102 struct usb_bus *bus; 00103 struct usb_device *dev; 00104 int ret; 00105 u_int8_t input_endpoint = 0xFF, output_endpoint = 0xFF; 00106 #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 00107 int first; 00108 #endif 00109 00110 usb_find_busses (); 00111 usb_find_devices (); 00112 CHECK (PI_DBG_DEV, PI_DBG_LVL_DEBUG, usb_set_debug (2)); 00113 00114 for (bus = usb_busses; bus; bus = bus->next) { 00115 for (dev = bus->devices; dev; dev = dev->next) { 00116 int i; 00117 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: checking device %p\n", 00118 __FILE__, dev)); 00119 00120 if (dev->descriptor.bNumConfigurations < 1) 00121 continue; 00122 if (!dev->config) 00123 continue; 00124 if (dev->config[0].bNumInterfaces < 1) 00125 continue; 00126 if (dev->config[0].interface[0].num_altsetting < 1) 00127 continue; 00128 if (dev->config[0].interface[0].altsetting[0].bNumEndpoints < 2) 00129 continue; 00130 00131 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: %d, 0x%04x 0x%04x.\n", 00132 __FILE__, __LINE__, dev->descriptor.idVendor, dev->descriptor.idProduct)); 00133 00134 if (USB_check_device (data, dev->descriptor.idVendor, dev->descriptor.idProduct)) 00135 continue; 00136 00137 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: trying to open device %p\n", 00138 __FILE__, dev)); 00139 00140 USB_handle = usb_open(dev); 00141 00142 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: USB_handle=%p\n", 00143 __FILE__, USB_handle)); 00144 00145 data->ref = USB_handle; 00146 00147 input_endpoint = output_endpoint = 0xFF; 00148 USB_in_endpoint = USB_out_endpoint = 0xFF; 00149 00150 ret = USB_configure_device (data, &input_endpoint, &output_endpoint); 00151 if (ret < 0) { 00152 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, 00153 "%s: USB configure failed for familar device: 0x%04x 0x%04x. (LifeDrive issue?)\n", 00154 __FILE__, dev->descriptor.idVendor, dev->descriptor.idProduct)); 00155 00156 usb_close(USB_handle); 00157 continue; 00158 } 00159 00160 for (i = 0; i < dev->config[0].interface[0].altsetting[0].bNumEndpoints; i++) { 00161 struct usb_endpoint_descriptor *endpoint; 00162 u_int8_t address; 00163 00164 endpoint = &dev->config[0].interface[0].altsetting[0].endpoint[i]; 00165 00166 if (endpoint->wMaxPacketSize != 0x40) 00167 continue; 00168 if ((endpoint->bmAttributes & USB_ENDPOINT_TYPE_MASK) != USB_ENDPOINT_TYPE_BULK) 00169 continue; 00170 address = endpoint->bEndpointAddress; 00171 if ((address & USB_ENDPOINT_DIR_MASK)) { 00172 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "In: 0x%x 0x%x.\n", address, input_endpoint)); 00173 if (input_endpoint == 0xFF) 00174 USB_in_endpoint = address; 00175 else if ((address & USB_ENDPOINT_ADDRESS_MASK) == input_endpoint) 00176 USB_in_endpoint = address; 00177 } else { 00178 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "Out: 0x%x 0x%x.\n", address, output_endpoint)); 00179 if (output_endpoint == 0xFF) 00180 USB_out_endpoint = address; 00181 else if ((address & USB_ENDPOINT_ADDRESS_MASK) == output_endpoint) 00182 USB_out_endpoint = address; 00183 } 00184 } 00185 00186 if (USB_in_endpoint == 0xFF || USB_out_endpoint == 0xFF) { 00187 usb_close (USB_handle); 00188 continue; 00189 } 00190 00191 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, 00192 "Config: %d, 0x%x 0x%x | 0x%x 0x%x.\n", 00193 ret, input_endpoint, output_endpoint, USB_in_endpoint, USB_out_endpoint)); 00194 00195 USB_interface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber; 00196 #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 00197 first = 1; 00198 claim: 00199 #endif 00200 i = usb_claim_interface (USB_handle, USB_interface); 00201 if (i < 0) { 00202 if (i == -EBUSY) { 00203 LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, "Unable to claim device: Busy.\n")); 00204 #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 00205 if (first) { 00206 usb_detach_kernel_driver_np (USB_handle, USB_interface); 00207 first = 0; 00208 goto claim; 00209 } 00210 #endif 00211 } else if (i == -ENOMEM) 00212 LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, "Unable to claim device: No memory.\n")); 00213 else 00214 LOG((PI_DBG_DEV, PI_DBG_LVL_ERR, "Unable to claim device: %d.\n", i)); 00215 usb_close (USB_handle); 00216 00217 errno = -i; 00218 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: %d.\n", 00219 __FILE__, __LINE__)); 00220 00221 return 0; 00222 } 00223 00224 LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: %d.\n", 00225 __FILE__, __LINE__)); 00226 return 1; 00227 } 00228 } 00229 00230 errno = ENODEV; 00231 CHECK (PI_DBG_DEV, PI_DBG_LVL_DEBUG, usb_set_debug (0)); 00232 return 0; 00233 }
Here is the call graph for this function:

char* RD_buffer = NULL [static] |
pthread_cond_t RD_buffer_available_cond = PTHREAD_COND_INITIALIZER [static] |
pthread_mutex_t RD_buffer_mutex = PTHREAD_MUTEX_INITIALIZER [static] |
size_t RD_buffer_size [static] |
size_t RD_buffer_used [static] |
Definition at line 259 of file libusb.c.
Referenced by RD_do_read(), RD_main(), u_flush(), and u_read_i().
int RD_running = 0 [static] |
Definition at line 263 of file libusb.c.
Referenced by RD_do_read(), RD_main(), RD_start(), RD_stop(), u_open(), u_read_i(), and u_write().
pthread_t RD_thread = 0 [static] |
char RD_usb_buffer[16384] [static] |
int RD_wanted [static] |
usb_dev_handle* USB_handle [static] |
Definition at line 86 of file libusb.c.
Referenced by RD_do_read(), u_write(), USB_close(), and USB_poll().
int USB_in_endpoint [static] |
int USB_interface [static] |
int USB_out_endpoint [static] |