1/* $FreeBSD: head/lib/libusb/libusb.h 195560 2009-07-10 14:15:53Z thompsa $ */ |
2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 12 unchanged lines hidden (view full) --- 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#ifndef __LIBUSB_H__ 28#define __LIBUSB_H__ 29 |
30#include <sys/time.h> 31#include <sys/types.h> 32#include <sys/endian.h> 33#include <sys/queue.h> 34 |
35#include <stdint.h> 36#include <time.h> 37#include <string.h> 38#include <pthread.h> 39 |
40 41#ifdef __cplusplus 42extern "C" { 43#endif 44#if 0 45} /* indent fix */ 46 47#endif 48 |
49/* libusb enums */ 50 51enum libusb_class_code { 52 LIBUSB_CLASS_PER_INTERFACE = 0, 53 LIBUSB_CLASS_AUDIO = 1, 54 LIBUSB_CLASS_COMM = 2, 55 LIBUSB_CLASS_HID = 3, 56 LIBUSB_CLASS_PTP = 6, --- 119 unchanged lines hidden (view full) --- 176}; 177 178enum libusb_debug_level { 179 LIBUSB_DEBUG_NO=0, 180 LIBUSB_DEBUG_FUNCTION=1, 181 LIBUSB_DEBUG_TRANSFER=2, 182}; 183 |
184/* internal structures */ 185 186typedef struct libusb_pollfd { 187 int fd; 188 short events; 189} libusb_pollfd; 190 191struct usb_pollfd { 192 TAILQ_ENTRY(usb_pollfd) list; 193 struct libusb_pollfd pollfd; 194}; 195 196struct usb_transfer { 197 TAILQ_ENTRY(usb_transfer) list; 198 int num_iso_packets; 199 struct timeval timeout; 200 int transferred; 201 uint8_t flags; 202}; 203 204struct usb_ep_tr { 205 TAILQ_ENTRY(usb_ep_tr) list; 206 uint8_t addr; 207 uint8_t idx; 208 uint8_t flags; 209 void *os_priv; 210}; |
211/* libusb structures */ 212 213typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data); 214typedef void (*libusb_pollfd_removed_cb) (int fd, void *user_data); 215 216typedef struct libusb_context { 217 int debug; 218 int debug_fixed; 219 220 int ctrl_pipe[2]; 221 |
222 TAILQ_HEAD(usb_devs_list, libusb_device) usb_devs; |
223 pthread_mutex_t usb_devs_lock; 224 |
225 TAILQ_HEAD(open_devs_list, libusb_device_handle) open_devs; |
226 pthread_mutex_t open_devs_lock; 227 |
228 TAILQ_HEAD(flying_transfers_list, usb_transfer) flying_transfers; |
229 pthread_mutex_t flying_transfers_lock; 230 |
231 TAILQ_HEAD(pollfds_list, usb_pollfd) pollfds; |
232 pthread_mutex_t pollfds_lock; 233 234 unsigned int pollfd_modify; 235 pthread_mutex_t pollfd_modify_lock; 236 237 libusb_pollfd_added_cb fd_added_cb; 238 libusb_pollfd_removed_cb fd_removed_cb; 239 void *fd_cb_user_data; --- 10 unchanged lines hidden (view full) --- 250 int refcnt; 251 252 struct libusb_context *ctx; 253 254 uint8_t bus_number; 255 uint8_t device_address; 256 uint8_t num_configurations; 257 |
258 TAILQ_ENTRY(libusb_device) list; |
259 unsigned long session_data; 260 void *os_priv; 261} libusb_device; 262 263typedef struct libusb_device_handle { 264 pthread_mutex_t lock; 265 unsigned long claimed_interfaces; 266 |
267 TAILQ_ENTRY(libusb_device_handle) list; |
268 struct libusb_device *dev; 269 void *os_priv; |
270 TAILQ_HEAD(ep_list, usb_ep_tr) ep_list; |
271} libusb_device_handle; 272 273typedef struct libusb_device_descriptor { 274 uint8_t bLength; 275 uint8_t bDescriptorType; 276 uint16_t bcdUSB; 277 uint8_t bDeviceClass; 278 uint8_t bDeviceSubClass; --- 85 unchanged lines hidden (view full) --- 364 libusb_transfer_cb_fn callback; 365 void *user_data; 366 unsigned char *buffer; 367 void *os_priv; 368 int num_iso_packets; 369 struct libusb_iso_packet_descriptor iso_packet_desc[0]; 370} libusb_transfer __aligned(sizeof(void *)); 371 |
372/* Library initialisation */ 373 374void libusb_set_debug(libusb_context * ctx, int level); 375int libusb_init(libusb_context ** context); 376void libusb_exit(struct libusb_context *ctx); 377 378/* Device handling and enumeration */ 379 380ssize_t libusb_get_device_list(libusb_context * ctx, libusb_device *** list); 381void libusb_free_device_list(libusb_device ** list, int unref_devices); 382uint8_t libusb_get_bus_number(libusb_device * dev); 383uint8_t libusb_get_device_address(libusb_device * dev); |
384int libusb_clear_halt(libusb_device_handle *devh, unsigned char endpoint); |
385int libusb_get_max_packet_size(libusb_device * dev, unsigned char endpoint); 386libusb_device *libusb_ref_device(libusb_device * dev); 387void libusb_unref_device(libusb_device * dev); 388int libusb_open(libusb_device * dev, libusb_device_handle ** devh); 389libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context * ctx, uint16_t vendor_id, uint16_t product_id); 390void libusb_close(libusb_device_handle * devh); 391libusb_device *libusb_get_device(libusb_device_handle * devh); 392int libusb_get_configuration(libusb_device_handle * devh, int *config); --- 57 unchanged lines hidden --- |