summaryrefslogtreecommitdiff
path: root/vapi/libusb.vapi
blob: c34e4a41480f94cfba2b27b709af9c6b3ede75ce (plain)
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
[CCode (cprefix = "usb_", cheader_filename = "usb.h")]
namespace USB {
	[CCode (cprefix = "USB_CLASS_", cheader_filename = "usb.h", has_type_id = false)]
	public enum Class {
		PER_INTERFACE,
		AUDIO,
		COMM,
		HID,
		PRINTER,
		PTP,
		MASS_STORAGE,
		HUB,
		DATA,
		VENDOR_SPEC
	}

	[CCode (cprefix = "USB_DT_", cheader_filename = "usb.h", has_type_id = false)]
	public enum DescriptorType {
		DEVICE,
		CONFIG,
		STRING,
		INTERFACE,
		ENDPOINT,
		HID,
		REPORT,
		PHYSICAL,
		HUB
	}

	[CCode (cprefix = "USB_DT_", cheader_filename = "usb.h", has_type_id = false)]
	public enum DescriptorSize {
		[CCode (cname = "USB_DT_DEVICE_SIZE")]
		DEVICE,
		[CCode (cname = "USB_DT_CONFIG_SIZE")]
		CONFIG,
		[CCode (cname = "USB_DT_INTERFACE_SIZE")]
		INTERFACE,
		[CCode (cname = "USB_DT_ENDPOINT_SIZE")]
		ENDPOINT,
		[CCode (cname = "USB_DT_ENDPOINT_AUDIO_SIZE")]
		ENDPOINT_AUDIO,
		[CCode (cname = "USB_DT_HUB_NONVAR_SIZE")]
		HUB_NONVAR
	}

	[CCode (cprefix = "USB_ENDPOINT_", cheader_filename = "usb.h", has_type_id = false)]
	public enum EndpointAttribute {
		ADDRESS_MASK,
		IN,
		OUT,
		TYPE_MASK,
		TYPE_CONTROL,
		TYPE_ISOCHRONOUS,
		TYPE_BULK,
		TYPE_INTERRUPT,
	}

	[CCode (cprefix = "USB_ENDPOINT_", cheader_filename = "usb.h", has_type_id = false)]
	public enum EndpointAddress {
		ADDRESS_MASK,
		DIR_MASK,
		IN,
		OUT
	}

	[CCode (cprefix = "USB_REQ_", cheader_filename = "usb.h", has_type_id = false)]
	public enum Request {
		GET_STATUS,
		CLEAR_FEATURE,
		SET_FEATURE,
		SET_ADDRESS,
		GET_DESCRIPTOR,
		SET_DESCRIPTOR,
		GET_CONFIGURATION,
		SET_CONFIGURATION,
		GET_INTERFACE,
		SET_INTERFACE,
		SYNCH_FRAME
	}

	[CCode (cprefix = "USB_TYPE_", cheader_filename = "usb.h", has_type_id = false)]
	public enum Type {
		STANDARD,
		CLASS,
		VENDOR,
		RESERVED
	}

	[CCode (cname = "struct usb_endpoint_descriptor", cheader_filename = "usb.h", has_type_id = false)]
	public struct EndpointDescriptor {
		public uint8 bLength;
		public uint8 bDescriptorType;
		public uint8 bEndpointAddress;
		public uint8 bmAttributes;
		public uint16 wMaxPacketSize;
		public uint8 bInterval;
		public uint8 bRefresh;
		public uint8 bSynchAddress;

		[CCode (array_length_cname = "extralen")]
		public uchar[] extra;
	}

	[CCode (cname = "struct usb_interface_descriptor", cheader_filename = "usb.h", has_type_id = false)]
	public struct InterfaceDescriptor {
		public uint8 bLength;
		public uint8 bDescriptorType;
		public uint8 bInterfaceNumber;
		public uint8 bAlternateSetting;
		public uint8 bNumEndpoints;
		public uint8 bInterfaceClass;
		public uint8 bInterfaceSubClass;
		public uint8 bInterfaceProtocol;
		public uint8 iInterface;

		[CCode (array_length_cname = "bNumEndpoints", array_length_type = "uint8_t")]
		public EndpointDescriptor[] endpoint;

		[CCode (array_length_cname = "extralen")]
		public uchar[] extra;
	}

	[CCode (cname = "struct usb_interface", cheader_filename = "usb.h", has_type_id = false)]
	public struct Interface {
		[CCode (array_length_cname = "num_altsetting")]
		public InterfaceDescriptor[] altsetting;
	}

	[Compact, CCode (cname = "struct usb_config_descriptor")]
	public class ConfigDescriptor {
		public uint8 bLength;
		public uint8 bDescriptorType;
		public uint16 wTotalLength;
		public uint8 bNumInterfaces;
		public uint8 bConfigurationValue;
		public uint8 iConfiguration;
		public uint8 bmAttributes;
		public uint8 MaxPower;

		[CCode (array_length_cname = "bNumInterfaces", array_length_type = "uint8_t")]
		public Interface[] @interface;
          [CCode (array_length_cname = "extralen")]
		public uchar[] extra;
	}

	[CCode (cname = "struct usb_device_descriptor", cheader_filename = "usb.h", has_type_id = false)]
	public struct DeviceDescriptor {
		public uint8 bLength;
		public uint8 bDescriptorType;
		public uint16 bcdUSB;
		public uint8 bDeviceClass;
		public uint8 bDeviceSubClass;
		public uint8 bDeviceProtocol;
		public uint8 bMaxPacketSize0;
		public uint16 idVendor;
		public uint16 idProduct;
		public uint16 bcdDevice;
		public uint8 iManufacturer;
		public uint8 iProduct;
		public uint8 iSerialNumber;
		public uint8 bNumConfigurations;
	}

	[Compact, CCode (cname = "struct usb_device", cprefix = "usb_", cheader_filename = "usb.h")]
	public class Device {
		public Device next;
		public Device prev;
		public string filename;
		public Bus bus;
		public DeviceDescriptor descriptor;
		[CCode (array_length = false)]
		public ConfigDescriptor config;
		public void * dev;
		public uint8 devnum;
		public uchar num_children;
		[CCode (array_length_cname = "num_children", array_length_type = "unsigned char")]
		public Device[] children;
	}

	[Compact, CCode (cname = "struct usb_bus", cheader_filename = "usb.h")]
	public class Bus {
		public Bus next;
		public Bus prev;
		public string dirname;
		public Device devices;
		public uint32 location;
		public Device root_dev;
	}

	[Compact, CCode (cname = "usb_dev_handle", cprefix = "usb_", cheader_filename = "usb.h", free_function = "usb_close")]
	public class DeviceHandle {
		[CCode (cname = "usb_open")]
		public DeviceHandle (Device dev);
		public int get_string (int index, int langid, [CCode (array_length = false)] char[] buf, size_t buflen);
		public int get_string_simple (int index, [CCode (array_length = false)] char[] buf, size_t buflen);

		public int get_descriptor_by_endpoint (int ep, uchar type, uchar index, void * buf, int size);
		public int get_descriptor (uchar type, uchar index, void * buf, int size);
		public int bulk_write (int ep, [CCode (array_length = false)] char[] bytes, int size, int timeout);
		public int bulk_read (int ep, [CCode (array_length = false)] char[] bytes, int size, int timeout);
		public int interrupt_write (int ep, [CCode (array_length = false)] char[] bytes, int size, int timeout);
		public int interrupt_read (int ep, [CCode (array_length = false)] char[] bytes, int size, int timeout);
		public int control_msg (int requesttype, int request, int value, int index, [CCode (array_length = false)] char[] bytes, int size, int timeout);
		public int set_configuration (int configuration);
		public int claim_interface (int @interface);
		public int release_interface (int @interface);
		public int set_altinterface (int alternate);
		public int resetep (uint ep);
		public int clear_halt (uint ep);
		public int reset ();
		public unowned Device device ();
	}

	[CCode (array_length = false)]
	public static unowned char[] strerror ();
	public static void init ();
	public static void set_debug (int level);
	public static int find_busses ();
	public static int find_devices ();
	public static unowned Bus get_busses ();
	[CCode (cname = "USB_LE16_TO_CPU")]
	public static uint16 le16_to_cpu (uint16 x);
}