libusb10.h revision 338789
1194676Sthompsa/* $FreeBSD: stable/10/lib/libusb/libusb10.h 338789 2018-09-19 07:57:30Z hselasky $ */ 2194676Sthompsa/*- 3194676Sthompsa * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4194676Sthompsa * 5194676Sthompsa * Redistribution and use in source and binary forms, with or without 6194676Sthompsa * modification, are permitted provided that the following conditions 7194676Sthompsa * are met: 8194676Sthompsa * 1. Redistributions of source code must retain the above copyright 9194676Sthompsa * notice, this list of conditions and the following disclaimer. 10194676Sthompsa * 2. Redistributions in binary form must reproduce the above copyright 11194676Sthompsa * notice, this list of conditions and the following disclaimer in the 12194676Sthompsa * documentation and/or other materials provided with the distribution. 13194676Sthompsa * 14194676Sthompsa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15194676Sthompsa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16194676Sthompsa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17194676Sthompsa * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18194676Sthompsa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19194676Sthompsa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20194676Sthompsa * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21194676Sthompsa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22194676Sthompsa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23194676Sthompsa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24194676Sthompsa * SUCH DAMAGE. 25194676Sthompsa */ 26194676Sthompsa 27194676Sthompsa#ifndef __LIBUSB10_H__ 28195957Salfred#define __LIBUSB10_H__ 29194676Sthompsa 30248236Shselasky#ifndef LIBUSB_GLOBAL_INCLUDE_FILE 31195957Salfred#include <sys/queue.h> 32248236Shselasky#endif 33194676Sthompsa 34195957Salfred#define GET_CONTEXT(ctx) (((ctx) == NULL) ? usbi_default_context : (ctx)) 35195957Salfred#define UNEXPORTED __attribute__((__visibility__("hidden"))) 36195957Salfred#define CTX_LOCK(ctx) pthread_mutex_lock(&(ctx)->ctx_lock) 37195957Salfred#define CTX_TRYLOCK(ctx) pthread_mutex_trylock(&(ctx)->ctx_lock) 38195957Salfred#define CTX_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->ctx_lock) 39302275Shselasky#define HOTPLUG_LOCK(ctx) pthread_mutex_lock(&(ctx)->hotplug_lock) 40302275Shselasky#define HOTPLUG_UNLOCK(ctx) pthread_mutex_unlock(&(ctx)->hotplug_lock) 41194676Sthompsa 42195957Salfred#define DPRINTF(ctx, dbg, format, args...) do { \ 43195957Salfred if ((ctx)->debug == dbg) { \ 44195957Salfred switch (dbg) { \ 45195957Salfred case LIBUSB_DEBUG_FUNCTION: \ 46195957Salfred printf("LIBUSB_FUNCTION: " \ 47195957Salfred format "\n", ## args); \ 48195957Salfred break; \ 49195957Salfred case LIBUSB_DEBUG_TRANSFER: \ 50195957Salfred printf("LIBUSB_TRANSFER: " \ 51195957Salfred format "\n", ## args); \ 52195957Salfred break; \ 53195957Salfred default: \ 54195957Salfred break; \ 55195957Salfred } \ 56195957Salfred } \ 57195957Salfred} while(0) 58194676Sthompsa 59195957Salfred/* internal structures */ 60194676Sthompsa 61195957Salfredstruct libusb_super_pollfd { 62195957Salfred TAILQ_ENTRY(libusb_super_pollfd) entry; 63195957Salfred struct libusb20_device *pdev; 64195957Salfred struct libusb_pollfd pollfd; 65195957Salfred}; 66194676Sthompsa 67195957Salfredstruct libusb_super_transfer { 68195957Salfred TAILQ_ENTRY(libusb_super_transfer) entry; 69195957Salfred uint8_t *curr_data; 70195957Salfred uint32_t rem_len; 71195957Salfred uint32_t last_len; 72302275Shselasky uint32_t stream_id; 73199575Sthompsa uint8_t state; 74199575Sthompsa#define LIBUSB_SUPER_XFER_ST_NONE 0 75199575Sthompsa#define LIBUSB_SUPER_XFER_ST_PEND 1 76195957Salfred}; 77194676Sthompsa 78302275Shselaskystruct libusb_hotplug_callback_handle_struct { 79302275Shselasky TAILQ_ENTRY(libusb_hotplug_callback_handle_struct) entry; 80302275Shselasky int events; 81302275Shselasky int vendor; 82302275Shselasky int product; 83302275Shselasky int devclass; 84302275Shselasky libusb_hotplug_callback_fn fn; 85302275Shselasky void *user_data; 86302275Shselasky}; 87302275Shselasky 88195957Salfredstruct libusb_context { 89195957Salfred int debug; 90195957Salfred int debug_fixed; 91195957Salfred int ctrl_pipe[2]; 92195957Salfred int tr_done_ref; 93195957Salfred int tr_done_gen; 94194676Sthompsa 95195957Salfred pthread_mutex_t ctx_lock; 96302275Shselasky pthread_mutex_t hotplug_lock; 97195957Salfred pthread_cond_t ctx_cond; 98302275Shselasky pthread_t hotplug_handler; 99195957Salfred pthread_t ctx_handler; 100195957Salfred#define NO_THREAD ((pthread_t)-1) 101195957Salfred 102195957Salfred TAILQ_HEAD(, libusb_super_pollfd) pollfds; 103195957Salfred TAILQ_HEAD(, libusb_super_transfer) tr_done; 104302275Shselasky TAILQ_HEAD(, libusb_hotplug_callback_handle_struct) hotplug_cbh; 105302275Shselasky TAILQ_HEAD(, libusb_device) hotplug_devs; 106195957Salfred 107195957Salfred struct libusb_super_pollfd ctx_poll; 108195957Salfred 109195957Salfred libusb_pollfd_added_cb fd_added_cb; 110195957Salfred libusb_pollfd_removed_cb fd_removed_cb; 111195957Salfred void *fd_cb_user_data; 112195957Salfred}; 113195957Salfred 114195957Salfredstruct libusb_device { 115195957Salfred int refcnt; 116195957Salfred 117338789Shselasky int device_is_gone; 118338789Shselasky 119195957Salfred uint32_t claimed_interfaces; 120195957Salfred 121195957Salfred struct libusb_super_pollfd dev_poll; 122195957Salfred 123195957Salfred struct libusb_context *ctx; 124195957Salfred 125302275Shselasky TAILQ_ENTRY(libusb_device) hotplug_entry; 126302275Shselasky 127195957Salfred TAILQ_HEAD(, libusb_super_transfer) tr_head; 128195957Salfred 129195957Salfred struct libusb20_device *os_priv; 130195957Salfred}; 131195957Salfred 132195957Salfredextern struct libusb_context *usbi_default_context; 133195957Salfred 134195957Salfredvoid libusb10_add_pollfd(libusb_context *ctx, struct libusb_super_pollfd *pollfd, struct libusb20_device *pdev, int fd, short events); 135195957Salfredvoid libusb10_remove_pollfd(libusb_context *ctx, struct libusb_super_pollfd *pollfd); 136195957Salfredvoid libusb10_cancel_all_transfer(libusb_device *dev); 137338789Shselaskyvoid libusb10_cancel_all_transfer_locked(struct libusb20_device *pdev, struct libusb_device *dev); 138195957Salfred 139195957Salfred#endif /* __LIBUSB10_H__ */ 140