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 int main(int argc
, char **argv
) {
45 int ret
, vendor
, product
;
46 struct usb_device
*dev
;
47 char buf
[65535], *endptr
;
53 // vendor and product code for Sony alpha 700
56 dev
= find_device(vendor
, product
);
62 signal(SIGTERM
, release_usb_device
);
64 ret
= usb_get_driver_np(devh
, 0, buf
, sizeof(buf
));
65 ret
= usb_claim_interface(devh
, 0);
67 printf("claim failed with error %d\n", ret
);
71 ret
= usb_set_altinterface(devh
, 0);
74 ret
= usb_get_descriptor(devh
, 0x0000001, 0x0000000, buf
, 0x0000012);
76 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000009);
78 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000027);
80 ret
= usb_release_interface(devh
, 0);
81 if (ret
!= 0) printf("failed to release interface before set_configuration: %d\n", ret
);
82 ret
= usb_set_configuration(devh
, 0x0000001);
83 ret
= usb_claim_interface(devh
, 0);
84 if (ret
!= 0) printf("claim after set_configuration failed with error %d\n", ret
);
85 ret
= usb_set_altinterface(devh
, 0);
87 memcpy(buf
, "\x10\x00\x00\x00\x01\x00\x02\x10\x00\x00\x00\x00\x01\x00\x00\x00", 0x0000010);
88 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000010, 1000);
90 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
92 printf("not yet initialized, initializing ...\n");
95 printf("already initialized, no need to do it again\n");
100 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x01\x10\x01\x00\x00\x00", 0x000000c);
101 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
103 ret
= usb_interrupt_read(devh
, 0x00000083, buf
, 0x0000008, 1000);
105 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
107 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
109 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x04\x10\x02\x00\x00\x00", 0x000000c);
110 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
112 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
114 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
115 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x03\x10\x03\x00\x00\x00", 0x000000c);
116 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
118 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
119 memcpy(buf
, "\x10\x00\x00\x00\x01\x00\x02\x10\x00\x00\x00\x00\x01\x00\x00\x00", 0x0000010);
120 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000010, 1000);
122 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
124 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x01\x10\x01\x00\x00\x00", 0x000000c);
125 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
127 ret
= usb_interrupt_read(devh
, 0x00000083, buf
, 0x0000008, 1000);
129 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
131 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
133 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x04\x10\x02\x00\x00\x00", 0x000000c);
134 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
136 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
138 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
140 memcpy(buf
, "\x18\x00\x00\x00\x01\x00\x01\x92\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0000018);
141 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000018, 1000);
143 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
145 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
147 memcpy(buf
, "\x18\x00\x00\x00\x01\x00\x01\x92\x04\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0000018);
148 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000018, 1000);
150 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
152 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
154 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x02\x92\x05\x00\x00\x00", 0x000000c);
155 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
157 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
159 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
161 memcpy(buf
, "\x18\x00\x00\x00\x01\x00\x01\x92\x06\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0000018);
162 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x0000018, 1000);
164 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
165 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
166 ret
= usb_release_interface(devh
, 0);
168 ret
= usb_close(devh
);