1 [CCode (cprefix = "libusb_", cheader_filename = "libusb.h")]
3 [CCode (cname = "enum libusb_class_code", cprefix = "LIBUSB_CLASS_")]
4 public enum ClassCode {
17 [CCode (cname = "enum libusb_descriptor_type", cprefix = "LIBUSB_DT_")]
18 public enum DescriptorType {
30 [CCode (cprefix = "LIBUSB_DT_")]
31 namespace DescriptorTypeSize {
32 public const int DEVICE_SIZE;
33 public const int CONFIG_SIZE;
34 public const int INTERFACE_SIZE;
35 public const int ENDPOINT_SIZE;
36 public const int ENDPOINT_AUDIO_SIZE;
37 public const int HUB_NONVAR_SIZE;
40 namespace EndpointMask {
41 [CCode (cname = "LIBUSB_ENDPOINT_ADDRESS_MASK")]
42 public const int ADDRESS;
43 [CCode (cname = "LIBUSB_ENDPOINT_DIR_MASK")]
45 [CCode (cname = "LIBUSB_ENDPOINT_DIR_MASK")]
46 public const int DIRECTION;
49 [CCode (cname = "enum libusb_endpoint_direction", cprefix = "LIBUSB_ENDPOINT_")]
50 public enum EndpointDirection {
53 [CCode (cname = "LIBUSB_ENDPOINT_DIR_MASK")]
57 [CCode (cname = "enum libusb_transfer_type", cprefix = "LIBUSB_TRANSFER_TYPE_")]
58 public enum TransferType {
65 [CCode (cname = "enum libusb_standard_request", cprefix = "LIBUSB_REQUEST_")]
66 public enum StandardRequest {
79 [CCode (cname = "enum libusb_request_type", cprefix = "LIBUSB_REQUEST_TYPE_")]
80 public enum RequestType {
87 [CCode (cname = "enum libusb_request_recipient", cprefix = "LIBUSB_RECIPIENT_")]
88 public enum RequestRecipient {
95 [CCode (cname = "enum libusb_iso_sync_type", cprefix = "LIBUSB_ISO_SYNC_TYPE_")]
96 public enum IsoSyncType {
104 [CCode (cname = "enum libusb_iso_usage_type", cprefix = "LIBUSB_ISO_USAGE_TYPE_")]
105 public enum IsoUsageType {
112 [CCode (cname = "enum libusb_error", cprefix = "LIBUSB_ERROR_")]
114 [CCode (cname = "LIBUSB_SUCCESS")]
131 [CCode (cname = "enum libusb_transfer_flags", cprefix = "LIBUSB_TRANSFER_")]
132 public enum TransferFlags {
138 [CCode (cname = "struct libusb_device_descriptor")]
139 public struct DeviceDescriptor {
140 public uint8 bLength;
141 public uint8 bDescriptorType;
142 public uint16 bcdUSB;
143 public uint8 bDeviceClass;
144 public uint8 bDeviceSubClass;
145 public uint8 bDeviceProtocol;
146 public uint8 bMaxPacketSize0;
147 public uint16 idVendor;
148 public uint16 idProduct;
149 public uint16 bcdDevice;
150 public uint8 iManufacturer;
151 public uint8 iProduct;
152 public uint8 iSerialNumber;
153 public uint8 bNumConfigurations;
155 [CCode (cname = "libusb_get_device_descriptor", instance_pos = -1)]
156 public DeviceDescriptor (Device device);
159 [CCode (cname = "struct libusb_endpoint_descriptor", cprefix = "libusb_")]
160 public struct EndpointDescriptor {
161 public uint8 bLength;
162 public uint8 bDescriptorType;
163 public uint8 bEndpointAddress;
164 public uint8 bmAttributes;
165 public uint16 wMaxPacketSize;
166 public uint8 bInterval;
167 public uint8 bRefresh;
168 public uint8 bSynchAddress;
169 [CCode (array_length_cname = "extra_length")]
170 public uint8[] extra;
173 [CCode (cname = "struct libusb_interface_descriptor")]
174 public struct InterfaceDescriptor {
175 public uint8 bLength;
176 public uint8 bDescriptorType;
177 public uint8 bInterfaceNumber;
178 public uint8 bAlternateSetting;
179 public uint8 bNumEndpoints;
180 public uint8 bInterfaceClass;
181 public uint8 bInterfaceSubClass;
182 public uint8 bInterfaceProtocol;
183 public uint8 iInterface;
184 [CCode (array_length_cname = "bNumEndpoints", array_length_type = "uint8_t")]
185 public EndpointDescriptor[] endpoint;
186 [CCode (array_length_cname = "extra_length")]
187 public uint8[] extra;
190 [CCode (cname = "struct libusb_interface")]
191 public struct Interface {
192 [CCode (array_length_cname = "num_altsetting")]
193 public InterfaceDescriptor[] altsetting;
196 [Compact, CCode (cname = "struct libusb_config_descriptor", free_function = "libusb_free_config_descriptor")]
197 public class ConfigDescriptor {
198 public uint8 bLength;
199 public uint8 bDescriptorType;
200 public uint16 wTotalLength;
201 public uint8 bNumInterfaces;
202 public uint8 bConfigurationValue;
203 public uint8 iConfiguration;
204 public uint8 bmAttributes;
205 public uint8 MaxPower;
206 [CCode (array_length_cname = "bNumInterfaces")]
207 public Interface[] @interface;
208 [CCode (array_length_cname = "extra_length")]
209 public uint8[] extra;
213 [Compact, CCode (cname = "libusb_device_handle", cprefix = "libusb_", free_function = "libusb_close")]
214 public class DeviceHandle {
215 public DeviceHandle (Device device) {
217 device.open(out handle);
220 [CCode (cname = "libusb_open_device_with_vid_pid")]
221 public DeviceHandle.from_vid_pid (Context? context, uint16 vendor_id, uint16 product_id);
222 public unowned Device get_device ();
223 public int get_configuration (out int config);
224 public int set_configuration (int configuration);
225 public int claim_interface (int interface_number);
226 public int release_interface (int interface_number);
227 public int set_interface_alt_setting (int interface_number, int alternate_setting);
228 public int clear_halt (uchar endpoint);
229 [CCode (cname = "libusb_reset_device")]
231 public int kernel_driver_active (int @interface);
232 public int detach_kernel_driver (int @interface);
233 public int attach_kernel_driver (int @interface);
235 public int get_string_descriptor_ascii (uint8 desc_index, uint8[] data);
236 public int get_descriptor (uint8 desc_type, uint8 desc_index, uint8[] data);
237 public int get_string_descriptor (uint desc_index, uint16 langid, uint8[] data);
239 public int control_transfer (uint8 bmRequestType, uint8 bRequest, uint16 wValue, uint16 wIndex, [CCode (array_length = false)] uint8[] data, uint16 wLength, uint timeout);
240 public int bulk_transfer (uint8 endpoint, uint8[] data, out int transferred, uint timeout);
241 public int interrupt_transfer (uint8 endpoint, uint8[] data, out int transferred, uint timeout);
244 [CCode (cname = "libusb_device", cprefix = "libusb_", ref_function = "libusb_ref_device", unref_function = "libusb_unref_device")]
245 public class Device {
246 public uint8 get_bus_number ();
247 public uint8 get_device_address ();
248 public int get_max_packet_size (uint8 endpoint);
249 public int open (out DeviceHandle handle);
251 public int get_active_config_descriptor (out ConfigDescriptor config);
252 public int get_config_descriptor (uint8 config_index, out ConfigDescriptor config);
253 public int get_config_descriptor_by_value (uint8 ConfigurationValue, out ConfigDescriptor config);
254 public int get_device_descriptor (out DeviceDescriptor desc);
257 [Compact, CCode (cname = "libusb_context", cprefix = "libusb_", free_function = "libusb_exit")]
258 public class Context {
259 public static int init (out Context context);
260 public void set_debug (int level);
261 public ssize_t get_device_list ([CCode (array_length = false)] out Device[] list);
262 public DeviceHandle open_device_with_vid_pid (uint16 vendor_id, uint16 product_id);
264 public int try_lock_events ();
265 public void lock_events ();
266 public void unlock_events ();
267 public int event_handling_ok ();
268 public int event_handler_active ();
269 public void lock_event_waiters ();
270 public void unlock_event_waiters ();
271 public int wait_for_event (Posix.timeval tv);
272 public int handle_events_timeout (Posix.timeval tv);
273 public int handle_events ();
274 public int handle_events_locked (Posix.timeval tv);
275 public int get_next_timeout (out Posix.timeval tv);
276 public void set_pollfd_notifiers (pollfd_added_cb added_cb, pollfd_removed_cb removed_cb, void* user_data);
277 [CCode (array_length = false)]
278 public unowned PollFD[] get_pollfds ();
281 public static uint16 le16_to_cpu (uint16 n);
282 public static uint16 cpu_to_le16 (uint16 n);
283 [CCode (cname = "malloc", cheader_filename = "stdlib.h")]
284 private static void* malloc (ulong n_bytes);
286 [Compact, CCode (cname = "struct libusb_control_setup")]
287 public class ControlSetup {
288 public uint8 bmRequestType;
289 public int8 bRequest;
290 public uint16 wValue;
291 public uint16 wIndex;
292 public uint16 wLength;
295 [CCode (cname = "enum libusb_transfer_status", cprefix = "LIBUSB_TRANSFER_")]
296 public enum TransferStatus {
306 [CCode (cname = "struct libusb_iso_packet_descriptor")]
307 public struct IsoPacketDescriptor {
309 public uint actual_length;
310 public TransferStatus status;
313 [CCode (has_target = false)]
314 public delegate void transfer_cb_fn (Transfer transfer);
316 [Compact, CCode (cname = "struct libusb_transfer", cprefix = "libusb_", free_function = "libusb_free_transfer")]
317 public class Transfer {
318 public DeviceHandle dev_handle;
320 public uint8 endpoint;
323 public TransferStatus status;
325 public int actual_length;
326 public transfer_cb_fn @callback;
327 public void* user_data;
328 [CCode (array_length_cname = "length")]
329 public uint8[] buffer;
330 public int num_iso_packets;
331 [CCode (array_length = false)]
332 public IsoPacketDescriptor[] iso_packet_desc;
334 [CCode (cname = "libusb_alloc_transfer")]
335 public Transfer (int iso_packets = 0);
336 [CCode (cname = "libusb_submit_transfer")]
337 public int submit ();
338 [CCode (cname = "libusb_cancel_transfer")]
339 public int cancel ();
340 [CCode (cname = "libusb_contrel_transfer_get_data", array_length = false)]
341 public unowned char[] control_get_data ();
342 [CCode (cname = "libusb_control_transfer_get_setup")]
343 public unowned ControlSetup control_get_setup ();
345 public static void fill_control_setup ([CCode (array_length = false)] uint8[] buffer, uint8 bmRequestType, uint8 bRequest, uint16 wValue, uint16 wIndex, uint16 wLength);
346 public void fill_control_transfer (DeviceHandle dev_handle, [CCode (array_length = false)] uint8[] buffer, transfer_cb_fn @callback, void* user_data, uint timeout);
347 public void fill_bulk_transfer (DeviceHandle dev_handle, uint8 endpoint, uint8[] buffer, transfer_cb_fn @callback, void* user_data, uint timeout);
348 public void fill_interrupt_transfer (DeviceHandle dev_handle, uint8 endpoint, uint8[] buffer, transfer_cb_fn @callback, void* user_data, uint timeout);
349 public void fill_iso_transfer (DeviceHandle dev_handle, uint8 endpoint, uint8[] buffer, int num_iso_packets, transfer_cb_fn @callback, void* user_data, uint timeout);
350 public void set_packet_lengths (uint length);
351 [CCode (array_length = false)]
352 public unowned uint8[] get_iso_packet_buffer (uint packet);
353 [CCode (array_length = false)]
354 public unowned uint8[] get_iso_packet_buffer_simple (int packet);
357 [CCode (has_target = false)]
358 public delegate void pollfd_added_cb (int fd, short events, void* user_data);
359 [CCode (has_target = false)]
360 public delegate void pollfd_removed_cb (int fd, void* user_data);
362 [Compact, CCode (cname = "struct libusb_pollfd")]
363 public class PollFD {