aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb/libusb10.h
diff options
context:
space:
mode:
authorAndrew Thompson <thompsa@FreeBSD.org>2009-07-10 14:15:53 +0000
committerAndrew Thompson <thompsa@FreeBSD.org>2009-07-10 14:15:53 +0000
commitc500e4dd03b53b2f9d020fee096d971e231f3c77 (patch)
tree57a73b4c88e143f696376dd2fa566249ccfe438c /lib/libusb/libusb10.h
parentd77e2734a1bec37609fafbb3ecedd69e35ad894c (diff)
downloadsrc-c500e4dd03b53b2f9d020fee096d971e231f3c77.tar.gz
src-c500e4dd03b53b2f9d020fee096d971e231f3c77.zip
Sync the libusb 1.0 exported api to the latest GSoC code.
- Fix possible uninitialised variables and null derefs - Support big transfers - Various bug fixes and style changes Submitted by: Sylvestre Gallon Sponsored by: Google Summer of Code 2009 Approved by: re (kib)
Notes
Notes: svn path=/head/; revision=195560
Diffstat (limited to 'lib/libusb/libusb10.h')
-rw-r--r--lib/libusb/libusb10.h213
1 files changed, 19 insertions, 194 deletions
diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h
index 60a13da5be41..3557ec088dca 100644
--- a/lib/libusb/libusb10.h
+++ b/lib/libusb/libusb10.h
@@ -31,44 +31,6 @@
* The two following macros were taken from the original LibUSB v1.0
* for sake of compatibility:
*/
-#define USB_LIST_INIT(entry) \
- (entry)->prev = (entry)->next = entry;
-#define USB_LIST_EMPTY(entry) \
- ((entry)->next = (entry))
-
-#define LIST_ADD(entry, head) \
- (entry)->next = (head)->next; \
- (entry)->prev = (head); \
- (head)->next->prev = (entry); \
- (head)->next = (entry);
-#define LIST_ADD_TAIL(entry, head) \
- (entry)->next = (head); \
- (entry)->prev = (head)->prev; \
- (head)->prev->next = (entry); \
- (head)->prev = (entry);
-#define LIST_DEL(entry) \
- (entry)->next->prev = (entry)->prev; \
- (entry)->prev->next = (entry)->next;
-
-#define LIST_ENT(ptr, type, member) \
- ((type *)((char *)(ptr) - (unsigned long) (&((type*)0L)->member)))
-#define LIST_FOREACH_ENTRY(pos, head, member) \
- for (pos = LIST_ENT((head)->next, typeof(*pos), member) ; \
- &pos->member != head ; \
- pos = LIST_ENT(pos->member.next, typeof(*pos), member))
-#define LIST_FOREACH_ENTRY_SAFE(pos, n, head, member) \
- for (pos = LIST_ENT((head)->next, typeof(*pos), member), \
- n = LIST_ENT(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = LIST_ENT(n->member.next, typeof(*n), member))
-
-/* fetch libusb20_transfer from libusb20_device */
-#define GET_XFER(xfer, endpoint, pdev)\
- xfer = libusb20_tr_get_pointer(pdev, \
- (2 *endpoint)|(endpoint/0x80)); \
- if (xfer == NULL) \
- return (LIBUSB_ERROR_OTHER);
-
static int get_next_timeout(libusb_context *ctx, struct timeval *tv, struct timeval *out);
static int handle_timeouts(struct libusb_context *ctx);
@@ -83,163 +45,26 @@ extern pthread_mutex_t libusb20_lock;
#define MAX(a,b) (((a)>(b))?(a):(b))
#define USB_TIMED_OUT (1<<0)
-
-static inline void
-dprintf(libusb_context *ctx, int debug, char *str)
-{
- if (ctx->debug != debug)
- return ;
-
- switch (ctx->debug) {
- case LIBUSB_DEBUG_NO:
- break ;
- case LIBUSB_DEBUG_FUNCTION:
- printf("LIBUSB FUNCTION : %s\n", str);
- break ;
- case LIBUSB_DEBUG_TRANSFER:
- printf("LIBUSB TRANSFER : %s\n", str);
- break ;
- default:
- printf("LIBUSB UNKNOW DEBUG\n");
- break ;
- }
- return ;
+#define UNEXPORTED __attribute__((__visibility__("hidden")))
+
+#define DPRINTF(ctx, dbg, format, args...) \
+if (ctx->debug == dbg) { \
+ printf("LIBUSB_%s : ", (ctx->debug == LIBUSB_DEBUG_FUNCTION) ? "FUNCTION" : "TRANSFER"); \
+ switch(ctx->debug) { \
+ case LIBUSB_DEBUG_FUNCTION: \
+ printf(format, ## args);\
+ break ; \
+ case LIBUSB_DEBUG_TRANSFER: \
+ printf(format, ## args);\
+ break ; \
+ } \
+ printf("\n"); \
}
-struct usb_pollfd {
- struct libusb_pollfd pollfd;
- struct list_head list;
-};
-
-struct usb_transfer {
- int num_iso_packets;
- struct list_head list;
- struct timeval timeout;
- int transferred;
- uint8_t flags;
-};
-
-static inline int
-usb_add_pollfd(libusb_context *ctx, int fd, short events)
-{
- struct usb_pollfd *pollfd;
-
- if (ctx == NULL)
- return (LIBUSB_ERROR_INVALID_PARAM);
-
- pollfd = malloc(sizeof(*pollfd));
- if (pollfd == NULL)
- return (LIBUSB_ERROR_NO_MEM);
-
- pollfd->pollfd.fd = fd;
- pollfd->pollfd.events = events;
-
- pthread_mutex_lock(&ctx->pollfds_lock);
- LIST_ADD_TAIL(&pollfd->list, &ctx->pollfds);
- pthread_mutex_unlock(&ctx->pollfds_lock);
-
- if (ctx->fd_added_cb)
- ctx->fd_added_cb(fd, events, ctx->fd_cb_user_data);
- return (0);
-}
-
-static inline void
-usb_remove_pollfd(libusb_context *ctx, int fd)
-{
- struct usb_pollfd *pollfd;
- int found;
-
- found = 0;
- pthread_mutex_lock(&ctx->pollfds_lock);
-
- LIST_FOREACH_ENTRY(pollfd, &ctx->pollfds, list) {
- if (pollfd->pollfd.fd == fd) {
- found = 1;
- break ;
- }
- }
-
- if (found == 0) {
- pthread_mutex_unlock(&ctx->pollfds_lock);
- return ;
- }
-
- LIST_DEL(&pollfd->list);
- pthread_mutex_unlock(&ctx->pollfds_lock);
- free(pollfd);
-
- if (ctx->fd_removed_cb)
- ctx->fd_removed_cb(fd, ctx->fd_cb_user_data);
-}
-
-static inline void
-usb_handle_transfer_completion(struct usb_transfer *uxfer,
- enum libusb_transfer_status status)
-{
- libusb_transfer *xfer;
- libusb_context *ctx;
- int len;
-
- xfer = (struct libusb_transfer *) ((uint8_t *)uxfer +
- sizeof(struct usb_transfer));
- ctx = xfer->dev_handle->dev->ctx;
-
- pthread_mutex_lock(&ctx->flying_transfers_lock);
- LIST_DEL(&uxfer->list);
- pthread_mutex_unlock(&ctx->flying_transfers_lock);
-
- if (status == LIBUSB_TRANSFER_COMPLETED && xfer->flags &
- LIBUSB_TRANSFER_SHORT_NOT_OK) {
- len = xfer->length;
- if (xfer->type == LIBUSB_TRANSFER_TYPE_CONTROL)
- len -= sizeof(libusb_control_setup);
- if (len != uxfer->transferred) {
- status = LIBUSB_TRANSFER_ERROR;
- }
- }
-
- xfer->status = status;
- xfer->actual_length = uxfer->transferred;
-
- if (xfer->callback)
- xfer->callback(xfer);
- if (xfer->flags & LIBUSB_TRANSFER_FREE_TRANSFER)
- libusb_free_transfer(xfer);
-
- pthread_mutex_lock(&ctx->event_waiters_lock);
- pthread_cond_broadcast(&ctx->event_waiters_cond);
- pthread_mutex_unlock(&ctx->event_waiters_lock);
-}
-
-static inline void
-usb_handle_disconnect(struct libusb_device_handle *devh)
-{
- struct libusb_context *ctx;
- struct libusb_transfer *xfer;
- struct usb_transfer *cur;
- struct usb_transfer *to_cancel;
-
- ctx = devh->dev->ctx;
-
- while (1) {
- pthread_mutex_lock(&ctx->flying_transfers_lock);
- to_cancel = NULL;
- LIST_FOREACH_ENTRY(cur, &ctx->flying_transfers, list) {
- xfer = (struct libusb_transfer *) ((uint8_t *)cur +
- sizeof(struct usb_transfer));
- if (xfer->dev_handle == devh) {
- to_cancel = cur;
- break ;
- }
- }
- pthread_mutex_unlock(&ctx->flying_transfers_lock);
-
- if (to_cancel == NULL)
- break ;
-
- usb_handle_transfer_completion(to_cancel, LIBUSB_TRANSFER_NO_DEVICE);
- }
- return ;
-}
+UNEXPORTED int usb_add_pollfd(libusb_context *ctx, int fd, short events);
+UNEXPORTED void usb_remove_pollfd(libusb_context *ctx, int fd);
+UNEXPORTED void usb_handle_transfer_completion(struct usb_transfer *uxfer,
+ enum libusb_transfer_status status);
+UNEXPORTED void usb_handle_disconnect(struct libusb_device_handle *devh);
#endif /*__LIBUSB10_H__*/