2 /* This file is generated with usbsnoop2libusb.pl from a usbsnoop log file. */
3 /* Latest version of the script should be in http://iki.fi/lindi/usb/usbsnoop2libusb.pl */
12 #include <linux/usbdevice_fs.h>
13 #define LIBUSB_AUGMENT
14 #include "libusb_augment.h"
17 struct usb_dev_handle
*devh
;
19 void release_usb_device(int dummy
) {
21 ret
= usb_release_interface(devh
, 0);
23 printf("failed to release interface: %d\n", ret
);
26 printf("failed to close interface: %d\n", ret
);
30 struct usb_device
*find_device(int vendor
, int product
) {
33 for (bus
= usb_get_busses(); bus
; bus
= bus
->next
) {
34 struct usb_device
*dev
;
36 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
37 if (dev
->descriptor
.idVendor
== vendor
38 && dev
->descriptor
.idProduct
== product
)
45 void print_bytes(char *bytes
, int len
) {
48 for (i
=0; i
<len
; i
++) {
49 printf("%02x ", (int)((unsigned char)bytes
[i
]));
52 for (i
=0; i
<len
; i
++) {
53 printf("%c", isprint(bytes
[i
]) ? bytes
[i
] : '.');
60 int main(int argc
, char **argv
) {
61 int ret
, vendor
, product
;
62 struct usb_device
*dev
;
63 char buf
[65535], *endptr
;
71 dev
= find_device(vendor
, product
);
77 signal(SIGTERM
, release_usb_device
);
79 ret
= usb_get_driver_np(devh
, 0, buf
, sizeof(buf
));
81 printf("interface 0 already claimed by driver \"%s\", attempting to detach it\n", buf
);
82 ret
= usb_detach_kernel_driver_np(devh
, 0);
83 printf("usb_detach_kernel_driver_np returned %d\n", ret
);
85 ret
= usb_claim_interface(devh
, 0);
87 printf("claim failed with error %d\n", ret
);
91 ret
= usb_set_altinterface(devh
, 0);
94 ret
= usb_get_descriptor(devh
, 0x0000001, 0x0000000, buf
, 0x0000012);
96 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000009);
98 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000027);
100 ret
= usb_release_interface(devh
, 0);
101 if (ret
!= 0) printf("failed to release interface before set_configuration: %d\n", ret
);
102 ret
= usb_set_configuration(devh
, 0x0000001);
103 ret
= usb_claim_interface(devh
, 0);
104 if (ret
!= 0) printf("claim after set_configuration failed with error %d\n", ret
);
105 ret
= usb_set_altinterface(devh
, 0);
107 // 9207: close down aperture
109 memcpy(buf
, "\x10\x00\x00\x00\x01\x00\x07\x92\x10\x01\x00\x00\x07\x50\x00\x00", 0x0000010);
110 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000010, 1000);
112 memcpy(buf
, "\x0d\x00\x00\x00\x02\x00\x07\x92\x10\x01\x00\x00\x01", 0x000000d);
113 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000d, 1000);
115 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
116 ret
= usb_release_interface(devh
, 0);
118 ret
= usb_close(devh
);