1 /* This file is generated with usbsnoop2libusb.pl from a usbsnoop log file. */
2 /* Latest version of the script should be in http://iki.fi/lindi/usb/usbsnoop2libusb.pl */
11 #include <linux/usbdevice_fs.h>
12 #define LIBUSB_AUGMENT
13 #include "libusb_augment.h"
16 struct usb_dev_handle
*devh
;
18 void release_usb_device(int dummy
) {
20 ret
= usb_release_interface(devh
, 0);
22 printf("failed to release interface: %d\n", ret
);
25 printf("failed to close interface: %d\n", ret
);
29 struct usb_device
*find_device(int vendor
, int product
) {
32 for (bus
= usb_get_busses(); bus
; bus
= bus
->next
) {
33 struct usb_device
*dev
;
35 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
36 if (dev
->descriptor
.idVendor
== vendor
37 && dev
->descriptor
.idProduct
== product
)
44 void print_bytes(char *bytes
, int len
) {
47 for (i
=0; i
<len
; i
++) {
48 printf("%02x ", (int)((unsigned char)bytes
[i
]));
51 for (i
=0; i
<len
; i
++) {
52 printf("%c", isprint(bytes
[i
]) ? bytes
[i
] : '.');
59 int main(int argc
, char **argv
) {
60 int ret
, vendor
, product
;
61 struct usb_device
*dev
;
62 char buf
[65535], *endptr
;
70 dev
= find_device(vendor
, product
);
76 signal(SIGTERM
, release_usb_device
);
78 ret
= usb_get_driver_np(devh
, 0, buf
, sizeof(buf
));
80 printf("interface 0 already claimed by driver \"%s\", attempting to detach it\n", buf
);
81 ret
= usb_detach_kernel_driver_np(devh
, 0);
82 printf("usb_detach_kernel_driver_np returned %d\n", ret
);
84 ret
= usb_claim_interface(devh
, 0);
86 printf("claim failed with error %d\n", ret
);
90 ret
= usb_set_altinterface(devh
, 0);
93 ret
= usb_get_descriptor(devh
, 0x0000001, 0x0000000, buf
, 0x0000012);
95 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000009);
97 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000027);
99 ret
= usb_release_interface(devh
, 0);
100 if (ret
!= 0) printf("failed to release interface before set_configuration: %d\n", ret
);
101 ret
= usb_set_configuration(devh
, 0x0000001);
102 ret
= usb_claim_interface(devh
, 0);
103 if (ret
!= 0) printf("claim after set_configuration failed with error %d\n", ret
);
104 ret
= usb_set_altinterface(devh
, 0);
106 // 9207: open up aperture
108 memcpy(buf
, "\x10\x00\x00\x00\x01\x00\x07\x92\x78\x00\x00\x00\x07\x50\x00\x00", 0x0000010);
109 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000010, 1000);
111 memcpy(buf
, "\x0d\x00\x00\x00\x02\x00\x07\x92\x78\x00\x00\x00\xff", 0x000000d);
112 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000d, 1000);
113 ret
= usb_release_interface(devh
, 0);
115 ret
= usb_close(devh
);