1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
/* $FreeBSD$ */
/*-
* Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* This file describes internal structures.
*/
#ifndef _LIBUSB20_INT_H_
#define _LIBUSB20_INT_H_
#ifdef COMPAT_32BIT
#define libusb20_pass_ptr(ptr) ((uint64_t)(uintptr_t)(ptr))
#else
#define libusb20_pass_ptr(ptr) (ptr)
#endif
struct libusb20_device;
struct libusb20_backend;
struct libusb20_transfer;
struct libusb20_quirk;
union libusb20_session_data {
unsigned long session_data;
struct timespec tv;
uint32_t plugtime;
};
/* USB backend specific */
typedef const char *(libusb20_get_backend_name_t)(void);
typedef int (libusb20_root_get_dev_quirk_t)(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq);
typedef int (libusb20_root_get_quirk_name_t)(struct libusb20_backend *pbe, uint16_t index, struct libusb20_quirk *pq);
typedef int (libusb20_root_add_dev_quirk_t)(struct libusb20_backend *pbe, struct libusb20_quirk *pq);
typedef int (libusb20_root_remove_dev_quirk_t)(struct libusb20_backend *pbe, struct libusb20_quirk *pq);
typedef int (libusb20_close_device_t)(struct libusb20_device *pdev);
typedef int (libusb20_dev_get_info_t)(struct libusb20_device *pdev, struct usb_device_info *pinfo);
typedef int (libusb20_dev_get_iface_desc_t)(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len);
typedef int (libusb20_init_backend_t)(struct libusb20_backend *pbe);
typedef int (libusb20_open_device_t)(struct libusb20_device *pdev, uint16_t transfer_count_max);
typedef void (libusb20_exit_backend_t)(struct libusb20_backend *pbe);
typedef int (libusb20_root_set_template_t)(struct libusb20_backend *pbe, int temp);
typedef int (libusb20_root_get_template_t)(struct libusb20_backend *pbe, int *ptemp);
#define LIBUSB20_DEFINE(n,field) \
libusb20_##field##_t *field;
#define LIBUSB20_DECLARE(n,field) \
/* .field = */ n##_##field,
#define LIBUSB20_BACKEND(m,n) \
/* description of this backend */ \
m(n, get_backend_name) \
/* optional backend methods */ \
m(n, init_backend) \
m(n, exit_backend) \
m(n, dev_get_info) \
m(n, dev_get_iface_desc) \
m(n, root_get_dev_quirk) \
m(n, root_get_quirk_name) \
m(n, root_add_dev_quirk) \
m(n, root_remove_dev_quirk) \
m(n, root_set_template) \
m(n, root_get_template) \
/* mandatory device methods */ \
m(n, open_device) \
m(n, close_device) \
struct libusb20_backend_methods {
LIBUSB20_BACKEND(LIBUSB20_DEFINE,)
};
/* USB dummy methods */
typedef int (libusb20_dummy_int_t)(void);
typedef void (libusb20_dummy_void_t)(void);
/* USB device specific */
typedef int (libusb20_detach_kernel_driver_t)(struct libusb20_device *pdev, uint8_t iface_index);
typedef 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);
typedef int (libusb20_get_config_desc_full_t)(struct libusb20_device *pdev, uint8_t **ppbuf, uint16_t *plen, uint8_t index);
typedef int (libusb20_get_config_index_t)(struct libusb20_device *pdev, uint8_t *pindex);
typedef int (libusb20_kernel_driver_active_t)(struct libusb20_device *pdev, uint8_t iface_index);
typedef int (libusb20_process_t)(struct libusb20_device *pdev);
typedef int (libusb20_reset_device_t)(struct libusb20_device *pdev);
typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode);
typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode);
typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index);
typedef int (libusb20_check_connected_t)(struct libusb20_device *pdev);
/* USB transfer specific */
typedef int (libusb20_tr_open_t)(struct libusb20_transfer *xfer, uint32_t MaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no, uint8_t pre_scale);
typedef int (libusb20_tr_close_t)(struct libusb20_transfer *xfer);
typedef int (libusb20_tr_clear_stall_sync_t)(struct libusb20_transfer *xfer);
typedef void (libusb20_tr_submit_t)(struct libusb20_transfer *xfer);
typedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer);
#define LIBUSB20_DEVICE(m,n) \
m(n, detach_kernel_driver) \
m(n, do_request_sync) \
m(n, get_config_desc_full) \
m(n, get_config_index) \
m(n, kernel_driver_active) \
m(n, process) \
m(n, reset_device) \
m(n, check_connected) \
m(n, set_power_mode) \
m(n, get_power_mode) \
m(n, set_alt_index) \
m(n, set_config_index) \
m(n, tr_cancel_async) \
m(n, tr_clear_stall_sync) \
m(n, tr_close) \
m(n, tr_open) \
m(n, tr_submit) \
struct libusb20_device_methods {
LIBUSB20_DEVICE(LIBUSB20_DEFINE,)
};
struct libusb20_backend {
TAILQ_HEAD(, libusb20_device) usb_devs;
const struct libusb20_backend_methods *methods;
};
struct libusb20_transfer {
struct libusb20_device *pdev; /* the USB device we belong to */
libusb20_tr_callback_t *callback;
void *priv_sc0; /* private client data */
void *priv_sc1; /* private client data */
/*
* Pointer to a list of buffer pointers:
*/
#ifdef COMPAT_32BIT
uint64_t *ppBuffer;
#else
void **ppBuffer;
#endif
/*
* Pointer to frame lengths, which are updated to actual length
* after the USB transfer completes:
*/
uint32_t *pLength;
uint32_t maxTotalLength;
uint32_t maxFrames; /* total number of frames */
uint32_t nFrames; /* total number of frames */
uint32_t aFrames; /* actual number of frames */
uint32_t timeout;
/* isochronous completion time in milliseconds */
uint16_t timeComplete;
uint16_t trIndex;
uint16_t maxPacketLen;
uint8_t flags; /* see LIBUSB20_TRANSFER_XXX */
uint8_t status; /* see LIBUSB20_TRANSFER_XXX */
uint8_t is_opened;
uint8_t is_pending;
uint8_t is_cancel;
uint8_t is_draining;
uint8_t is_restart;
};
struct libusb20_device {
/* device descriptor */
struct LIBUSB20_DEVICE_DESC_DECODED ddesc;
/* device timestamp */
union libusb20_session_data session_data;
/* our device entry */
TAILQ_ENTRY(libusb20_device) dev_entry;
/* device methods */
const struct libusb20_device_methods *methods;
/* backend methods */
const struct libusb20_backend_methods *beMethods;
/* list of USB transfers */
struct libusb20_transfer *pTransfer;
/* private backend data */
void *privBeData;
/* libUSB v0.1 and v1.0 compat data */
void *privLuData;
/* claimed interface */
uint8_t claimed_interface;
/* device file handle */
int file;
/* device file handle (control transfers only) */
int file_ctrl;
/* debugging level */
int debug;
/* number of USB transfers */
uint16_t nTransfer;
uint8_t bus_number;
uint8_t device_address;
uint8_t usb_mode;
uint8_t usb_speed;
uint8_t is_opened;
uint8_t parent_address;
uint8_t parent_port;
char usb_desc[96];
};
extern const struct libusb20_backend_methods libusb20_ugen20_backend;
extern const struct libusb20_backend_methods libusb20_linux_backend;
#endif /* _LIBUSB20_INT_H_ */
|