libusb20_int.h revision 356399
180709Sjake/* $FreeBSD: stable/10/lib/libusb/libusb20_int.h 356399 2020-01-06 09:22:33Z hselasky $ */ 280709Sjake/*- 3226054Smarius * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 480709Sjake * 580709Sjake * Redistribution and use in source and binary forms, with or without 680709Sjake * modification, are permitted provided that the following conditions 780709Sjake * are met: 880709Sjake * 1. Redistributions of source code must retain the above copyright 980709Sjake * notice, this list of conditions and the following disclaimer. 1080709Sjake * 2. Redistributions in binary form must reproduce the above copyright 1180709Sjake * notice, this list of conditions and the following disclaimer in the 1280709Sjake * documentation and/or other materials provided with the distribution. 1380709Sjake * 1480709Sjake * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1581334Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1680709Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1780709Sjake * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1881334Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1980709Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2080709Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2180709Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2280709Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2380709Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2480709Sjake * SUCH DAMAGE. 2580709Sjake */ 2680709Sjake 2780709Sjake/* 2880709Sjake * This file describes internal structures. 2980709Sjake */ 3080709Sjake 3180709Sjake#ifndef _LIBUSB20_INT_H_ 3280709Sjake#define _LIBUSB20_INT_H_ 3380709Sjake 3480709Sjake#ifdef COMPAT_32BIT 3588616Sjake#define libusb20_pass_ptr(ptr) ((uint64_t)(uintptr_t)(ptr)) 3689032Sjake#else 37216802Smarius#define libusb20_pass_ptr(ptr) (ptr) 3888616Sjake#endif 3989032Sjake 4088616Sjakestruct libusb20_device; 4181893Sjakestruct libusb20_backend; 4288616Sjakestruct libusb20_transfer; 4389032Sjakestruct libusb20_quirk; 4489032Sjake 4588616Sjakeunion libusb20_session_data { 4688616Sjake unsigned long session_data; 4788616Sjake struct timespec tv; 4889032Sjake uint32_t plugtime; 4989032Sjake}; 5088616Sjake 5189032Sjake/* USB backend specific */ 5288616Sjaketypedef const char *(libusb20_get_backend_name_t)(void); 53225886Smariustypedef int (libusb20_root_get_dev_quirk_t)(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq); 54225886Smariustypedef int (libusb20_root_get_quirk_name_t)(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq); 55225886Smariustypedef int (libusb20_root_add_dev_quirk_t)(struct libusb20_backend *pbe, struct libusb20_quirk *pq); 56225886Smariustypedef int (libusb20_root_remove_dev_quirk_t)(struct libusb20_backend *pbe, struct libusb20_quirk *pq); 57225886Smariustypedef int (libusb20_close_device_t)(struct libusb20_device *pdev); 58225886Smariustypedef int (libusb20_dev_get_info_t)(struct libusb20_device *pdev, struct usb_device_info *pinfo); 5989032Sjaketypedef int (libusb20_dev_get_iface_desc_t)(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len); 6088616Sjaketypedef int (libusb20_init_backend_t)(struct libusb20_backend *pbe); 6189032Sjaketypedef int (libusb20_open_device_t)(struct libusb20_device *pdev, uint16_t transfer_count_max); 6289032Sjaketypedef void (libusb20_exit_backend_t)(struct libusb20_backend *pbe); 6389032Sjaketypedef int (libusb20_root_set_template_t)(struct libusb20_backend *pbe, int temp); 64225886Smariustypedef int (libusb20_root_get_template_t)(struct libusb20_backend *pbe, int *ptemp); 65225886Smarius 66225886Smarius#define LIBUSB20_DEFINE(n,field) \ 67225886Smarius libusb20_##field##_t *field; 68225886Smarius 69225886Smarius#define LIBUSB20_DECLARE(n,field) \ 7089032Sjake /* .field = */ n##_##field, 7189032Sjake 7292198Sjake#define LIBUSB20_BACKEND(m,n) \ 73225886Smarius /* description of this backend */ \ 74117658Sjmg m(n, get_backend_name) \ 75225886Smarius /* optional backend methods */ \ 76225886Smarius m(n, init_backend) \ 77225886Smarius m(n, exit_backend) \ 78225886Smarius m(n, dev_get_info) \ 79225886Smarius m(n, dev_get_iface_desc) \ 80225887Smarius m(n, root_get_dev_quirk) \ 81117658Sjmg m(n, root_get_quirk_name) \ 82117658Sjmg m(n, root_add_dev_quirk) \ 83117658Sjmg m(n, root_remove_dev_quirk) \ 8492198Sjake m(n, root_set_template) \ 8592198Sjake m(n, root_get_template) \ 86225886Smarius /* mandatory device methods */ \ 87225886Smarius m(n, open_device) \ 88225886Smarius m(n, close_device) \ 89225886Smarius 90225886Smariusstruct libusb20_backend_methods { 91225886Smarius LIBUSB20_BACKEND(LIBUSB20_DEFINE,) 9292198Sjake}; 9392198Sjake 94221750Smarius/* USB dummy methods */ 95225886Smariustypedef int (libusb20_dummy_int_t)(void); 96221750Smariustypedef void (libusb20_dummy_void_t)(void); 97225886Smarius 98225886Smarius/* USB device specific */ 99225886Smariustypedef int (libusb20_detach_kernel_driver_t)(struct libusb20_device *pdev, uint8_t iface_index); 100225886Smariustypedef int (libusb20_do_request_sync_t)(struct libusb20_device *pdev, struct LIBUSB20_CONTROL_SETUP_DECODED *setup, void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags); 101225886Smariustypedef int (libusb20_get_config_desc_full_t)(struct libusb20_device *pdev, uint8_t **ppbuf, uint16_t *plen, uint8_t index); 102226054Smariustypedef int (libusb20_get_config_index_t)(struct libusb20_device *pdev, uint8_t *pindex); 103226054Smariustypedef int (libusb20_kernel_driver_active_t)(struct libusb20_device *pdev, uint8_t iface_index); 104226054Smariustypedef int (libusb20_process_t)(struct libusb20_device *pdev); 105226054Smariustypedef int (libusb20_reset_device_t)(struct libusb20_device *pdev); 106226054Smariustypedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode); 107226054Smariustypedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode); 108226054Smariustypedef int (libusb20_get_port_path_t)(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize); 109226054Smariustypedef int (libusb20_get_power_usage_t)(struct libusb20_device *pdev, uint16_t *power_usage); 110226054Smariustypedef int (libusb20_get_stats_t)(struct libusb20_device *pdev, struct libusb20_device_stats *pstats); 111226054Smariustypedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index); 112226054Smariustypedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index); 113226054Smariustypedef int (libusb20_check_connected_t)(struct libusb20_device *pdev); 114226054Smarius 115226054Smarius 116226054Smarius/* USB transfer specific */ 117226054Smariustypedef int (libusb20_tr_open_t)(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no, uint16_t stream_id, uint8_t pre_scale); 118226054Smariustypedef int (libusb20_tr_close_t)(struct libusb20_transfer *xfer); 119226054Smariustypedef int (libusb20_tr_clear_stall_sync_t)(struct libusb20_transfer *xfer); 120226054Smariustypedef void (libusb20_tr_submit_t)(struct libusb20_transfer *xfer); 121226054Smariustypedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer); 122226054Smarius 123226054Smarius#define LIBUSB20_DEVICE(m,n) \ 124226054Smarius m(n, detach_kernel_driver) \ 125226054Smarius m(n, do_request_sync) \ 126226054Smarius m(n, get_config_desc_full) \ 127225886Smarius m(n, get_config_index) \ 128221750Smarius m(n, kernel_driver_active) \ 129221750Smarius m(n, process) \ 130226054Smarius m(n, reset_device) \ 131226054Smarius m(n, check_connected) \ 132226054Smarius m(n, set_power_mode) \ 133226054Smarius m(n, get_power_mode) \ 134226054Smarius m(n, get_port_path) \ 135226054Smarius m(n, get_power_usage) \ 136226054Smarius m(n, get_stats) \ 137226054Smarius m(n, set_alt_index) \ 138226054Smarius m(n, set_config_index) \ 139226054Smarius m(n, tr_cancel_async) \ 140226054Smarius m(n, tr_clear_stall_sync) \ 141226054Smarius m(n, tr_close) \ 142226054Smarius m(n, tr_open) \ 143226054Smarius m(n, tr_submit) \ 144226054Smarius 145226054Smariusstruct libusb20_device_methods { 146226054Smarius LIBUSB20_DEVICE(LIBUSB20_DEFINE,) 147226054Smarius}; 148226054Smarius 149226054Smariusstruct libusb20_backend { 150226054Smarius TAILQ_HEAD(, libusb20_device) usb_devs; 151226054Smarius const struct libusb20_backend_methods *methods; 152226054Smarius}; 153226054Smarius 154226054Smariusstruct libusb20_transfer { 155226054Smarius struct libusb20_device *pdev; /* the USB device we belong to */ 156226054Smarius libusb20_tr_callback_t *callback; 157226054Smarius void *priv_sc0; /* private client data */ 158226054Smarius void *priv_sc1; /* private client data */ 159226054Smarius /* 160226054Smarius * Pointer to a list of buffer pointers: 161226054Smarius */ 162226054Smarius#ifdef COMPAT_32BIT 16397262Sjake uint64_t *ppBuffer; 164225886Smarius#else 16597262Sjake void **ppBuffer; 16684176Sjake#endif 167225886Smarius /* 16897262Sjake * Pointer to frame lengths, which are updated to actual length 16984176Sjake * after the USB transfer completes: 170225886Smarius */ 171225886Smarius uint32_t *pLength; 172225886Smarius uint32_t maxTotalLength; 173225886Smarius uint32_t maxFrames; /* total number of frames */ 174225886Smarius uint32_t nFrames; /* total number of frames */ 175225886Smarius uint32_t aFrames; /* actual number of frames */ 17680709Sjake uint32_t timeout; 17780709Sjake /* isochronous completion time in milliseconds */ 17889032Sjake uint16_t timeComplete; 179225886Smarius uint16_t trIndex; 180225886Smarius uint16_t maxPacketLen; 181225886Smarius uint8_t flags; /* see LIBUSB20_TRANSFER_XXX */ 182225886Smarius uint8_t status; /* see LIBUSB20_TRANSFER_XXX */ 18389032Sjake uint8_t is_opened; 18489032Sjake uint8_t is_pending; 18589032Sjake uint8_t is_cancel; 18689032Sjake uint8_t is_draining; 18789032Sjake uint8_t is_restart; 188225886Smarius}; 189225886Smarius 190225886Smariusstruct libusb20_device { 191225886Smarius 192225886Smarius /* device descriptor */ 193225886Smarius struct LIBUSB20_DEVICE_DESC_DECODED ddesc; 19488616Sjake 19588616Sjake /* device timestamp */ 196100840Sjake union libusb20_session_data session_data; 197100840Sjake 198225886Smarius /* our device entry */ 199225886Smarius TAILQ_ENTRY(libusb20_device) dev_entry; 200225886Smarius 201225886Smarius /* device methods */ 202225886Smarius const struct libusb20_device_methods *methods; 203114071Sobrien 20480709Sjake /* backend methods */ 20580709Sjake const struct libusb20_backend_methods *beMethods; 20680709Sjake 207216802Smarius /* list of USB transfers */ 208216802Smarius struct libusb20_transfer *pTransfer; 209216802Smarius 210216802Smarius /* private backend data */ 211216802Smarius void *privBeData; 212216802Smarius 213216802Smarius /* libUSB v0.1 and v1.0 compat data */ 214216802Smarius void *privLuData; 215216802Smarius 216216802Smarius /* claimed interface */ 217216802Smarius uint8_t claimed_interface; 218216802Smarius 219216802Smarius /* auto detach kernel driver */ 22092213Sjake uint8_t auto_detach; 22192213Sjake 22292213Sjake /* device file handle */ 22392213Sjake int file; 22480709Sjake 225 /* device file handle (control transfers only) */ 226 int file_ctrl; 227 228 /* debugging level */ 229 int debug; 230 231 /* number of USB transfers */ 232 uint16_t nTransfer; 233 234 uint8_t bus_number; 235 uint8_t device_address; 236 uint8_t usb_mode; 237 uint8_t usb_speed; 238 uint8_t is_opened; 239 uint8_t parent_address; 240 uint8_t parent_port; 241 242 char usb_desc[96]; 243}; 244 245extern const struct libusb20_backend_methods libusb20_ugen20_backend; 246extern const struct libusb20_backend_methods libusb20_linux_backend; 247 248#endif /* _LIBUSB20_INT_H_ */ 249