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 = "struct libusb_device_descriptor")]
132 public struct DeviceDescriptor {
133 public uint8 bLength;
134 public uint8 bDescriptorType;
135 public uint16 bcdUSB;
136 public uint8 bDeviceClass;
137 public uint8 bDeviceSubClass;
138 public uint8 bDeviceProtocol;
139 public uint8 bMaxPacketSize0;
140 public uint16 idVendor;
141 public uint16 idProduct;
142 public uint16 bcdDevice;
143 public uint8 iManufacturer;
144 public uint8 iProduct;
145 public uint8 iSerialNumber;
146 public uint8 bNumConfigurations;
148 [CCode (cname = "libusb_get_device_descriptor", instance_pos = -1)]
149 public DeviceDescriptor (Device device);
152 [CCode (cname = "struct libusb_endpoint_descriptor", cprefix = "libusb_")]
153 public struct EndpointDescriptor {
154 public uint8 bLength;
155 public uint8 bDescriptorType;
156 public uint8 bEndpointAddress;
157 public uint8 bmAttributes;
158 public uint16 wMaxPacketSize;
159 public uint8 bInterval;
160 public uint8 bRefresh;
161 public uint8 bSynchAddress;
162 [CCode (array_length_cname = "extra_length")]
166 [CCode (cname = "struct libusb_interface_descriptor")]
167 public struct InterfaceDescriptor {
168 public uint8 bLength;
169 public uint8 bDescriptorType;
170 public uint8 bInterfaceNumber;
171 public uint8 bAlternateSetting;
172 public uint8 bNumEndpoints;
173 public uint8 bInterfaceClass;
174 public uint8 bInterfaceSubClass;
175 public uint8 bInterfaceProtocol;
176 public uint8 iInterface;
177 [CCode (array_length_cname = "bNumEndpoints", array_length_type = "uint8_t")]
178 public EndpointDescriptor[] endpoint;
179 [CCode (array_length_cname = "extra_length")]
183 [CCode (cname = "struct libusb_interface")]
184 public struct Interface {
185 [CCode (array_length_cname = "num_altsetting")]
186 public InterfaceDescriptor[] altsetting;
189 [Compact, CCode (cname = "struct libusb_config_descriptor", free_function = "libusb_free_config_descriptor")]
190 public class ConfigDescriptor {
191 public uint8 bLength;
192 public uint8 bDescriptorType;
193 public uint16 wTotalLength;
194 public uint8 bNumInterfaces;
195 public uint8 bConfigurationValue;
196 public uint8 iConfiguration;
197 public uint8 bmAttributes;
198 public uint8 MaxPower;
199 [CCode (array_length_cname = "bNumInterfaces")]
200 public Interface[] @interface;
201 [CCode (array_length_cname = "extra_length")]
206 [Compact, CCode (cname = "libusb_device_handle", cprefix = "libusb_", free_function = "libusb_close")]
207 public class DeviceHandle {
208 public DeviceHandle (Device device) {
210 device.open(out handle);
213 [CCode (cname = "libusb_open_device_with_vid_pid")]
214 public DeviceHandle.from_vid_pid (Context context, uint16 vendor_id, uint16 product_id);
215 public unowned Device get_device ();
216 public int get_configuration (out int config);
217 public int set_configuration (int configuration);
218 public int claim_interface (int interface_number);
219 public int release_interface (int interface_number);
220 public int set_interface_alt_setting (int interface_number, int alternate_setting);
221 public int clear_halt (uchar endpoint);
222 [CCode (cname = "libusb_reset_device")]
224 public int kernel_driver_active (int @interface);
225 public int detach_kernel_driver (int @interface);
226 public int attach_kernel_driver (int @interface);
228 public int get_string_descriptor_ascii (uint8 desc_index, uchar[] data);
229 public int get_descriptor (uint8 desc_type, uint8 desc_index, uchar[] data);
230 public int get_string_descriptor (uint desc_index, uint16 langid, uchar[] data);
232 public int control_transfer (uint8 bmRequestType, uint8 bRequest, uint16 wValue, uint16 wIndex, [CCode (array_length = false)] uchar[] data, uint16 wLength, uint timeout);
233 public int bulk_transfer (uchar endpoint, uchar[] data, out int transferred, uint timeout);
234 public int interrupt_transfer (uchar endpoint, uchar[] data, out int transferred, uint timeout);
237 [CCode (cname = "libusb_device", cprefix = "libusb_", ref_function = "libusb_ref_device", unref_function = "libusb_unref_device")]
238 public class Device {
239 public uint8 get_bus_number ();
240 public uint8 get_device_address ();
241 public int get_max_packet_size (uchar endpoint);
242 public int open (out DeviceHandle handle);
244 public int get_active_config_descriptor (out ConfigDescriptor config);
245 public int get_config_descriptor (uint8 config_index, out ConfigDescriptor config);
246 public int get_config_descriptor_by_value (uint8 ConfigurationValue, out ConfigDescriptor config);
247 public int get_device_descriptor (out DeviceDescriptor desc);
250 [Compact, CCode (cname = "libusb_context", cprefix = "libusb_", free_function = "libusb_exit")]
251 public class Context {
252 public static int init (out Context context);
253 public void set_debug (int level);
254 public ssize_t get_device_list ([CCode (array_length = false)] out Device[] list);
255 public DeviceHandle open_device_with_vid_pid (uint16 vendor_id, uint16 product_id);
257 public int try_lock_events ();
258 public void lock_events ();
259 public void unlock_events ();
260 public int event_handling_ok ();
261 public int event_handler_active ();
262 public void lock_event_waiters ();
263 public void unlock_event_waiters ();
264 public int wait_for_event (GLib.TimeVal tv);
265 public int handle_events_timeout (GLib.TimeVal tv);
266 public int handle_events ();
267 public int handle_events_locked (GLib.TimeVal tv);
268 public int get_next_timeout (out Posix.timeval tv);
269 public void set_pollfd_notifiers (pollfd_added_cb added_cb, pollfd_removed_cb removed_cb, void* user_data);
270 [CCode (array_length = false)]
271 public unowned PollFD[] get_pollfds ();
274 public static uint16 le16_to_cpu (uint16 n);
275 public static uint16 cpu_to_le16 (uint16 n);
276 [CCode (cname = "malloc", cheader_filename = "stdlib.h")]
277 private static void* malloc (ulong n_bytes);
279 [Compact, CCode (cname = "struct libusb_control_setup")]
280 public class ControlSetup {
281 public uint8 bmRequestType;
282 public int8 bRequest;
283 public uint16 wValue;
284 public uint16 wIndex;
285 public uint16 wLength;
288 [CCode (cname = "enum libusb_transfer_status", cprefix = "LIBUSB_TRANSFER_")]
289 public enum TransferStatus {
299 [CCode (cname = "struct libusb_iso_packet_descriptor")]
300 public struct IsoPacketDescriptor {
302 public uint actual_length;
303 public TransferStatus status;
306 public static delegate void transfer_cb_fn (Transfer transfer);
308 [Compact, CCode (cname = "struct libusb_transfer", cprefix = "libusb_", free_function = "libusb_free_transfer")]
309 public class Transfer {
310 public DeviceHandle dev_handle;
312 public uchar endpoint;
315 public TransferStatus status;
317 public int actual_length;
318 public transfer_cb_fn @callback;
319 public void* user_data;
320 [CCode (array_length_cname = "length")]
321 public uchar[] buffer;
322 public int num_iso_packets;
323 [CCode (array_length = false)]
324 public IsoPacketDescriptor[] iso_packet_desc;
326 [CCode (cname = "libusb_alloc_transfer")]
327 public Transfer (int iso_packets = 0);
328 [CCode (cname = "libusb_submit_transfer")]
329 public int submit ();
330 [CCode (cname = "libusb_cancel_transfer")]
331 public int cancel ();
332 [CCode (cname = "libusb_contrel_transfer_get_data", array_length = false)]
333 public unowned char[] control_get_data ();
334 [CCode (cname = "libusb_control_transfer_get_setup")]
335 public unowned ControlSetup control_get_setup ();
337 public static void fill_control_setup ([CCode (array_length = false)] uchar[] buffer, uint8 bmRequestType, uint8 bRequest, uint16 wValue, uint16 wIndex, uint16 wLength);
338 public void fill_control_transfer (DeviceHandle dev_handle, [CCode (array_length = false)] uchar[] buffer, transfer_cb_fn @callback, void* user_data, uint timeout);
339 public void fill_bulk_transfer (DeviceHandle dev_handle, uchar endpoint, uchar[] buffer, transfer_cb_fn @callback, void* user_data, uint timeout);
340 public void fill_interrupt_transfer (DeviceHandle dev_handle, uchar endpoint, uchar[] buffer, transfer_cb_fn @callback, void* user_data, uint timeout);
341 public void fill_iso_transfer (DeviceHandle dev_handle, uchar endpoint, uchar[] buffer, int num_iso_packets, transfer_cb_fn @callback, void* user_data, uint timeout);
342 public void set_packet_lengths (uint length);
343 [CCode (array_length = false)]
344 public unowned uchar[] get_iso_packet_buffer (uint packet);
345 [CCode (array_length = false)]
346 public unowned uchar[] get_iso_packet_buffer_simple (int packet);
349 public static delegate void pollfd_added_cb (int fd, short events, void* user_data);
350 public static delegate void pollfd_removed_cb (int fd, void* user_data);
352 [Compact, CCode (cname = "struct libusb_pollfd")]
353 public class PollFD {