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
) {
49 for (i
=0; i
<len
; i
++) {
50 printf("%02x ", (int)((unsigned char)bytes
[i
]));
51 if ((i
+ 1) % 10 == 0) {
53 printf("%02d: ", (i
/ 10) + 1);
60 void print_interpretation(char *buf
) {
61 // byte 35 and 36 are 100 * fstop
62 long fstop_scaled
= buf
[35] & 255;
63 fstop_scaled
|= (buf
[36] << 8);
65 fstop
= (fstop_scaled
/ 100.0);
66 printf("f%2.1f\n", fstop
);
70 // byte 93 and 94 are 1/time
71 printf("using 1/s\n");
72 long time
= (buf
[93] & 255) | (buf
[94] << 8);
73 printf("1/%ds\n", time
);
76 // byte 95 and 96 are 10*s (or bulb if 0)
77 long time
= (buf
[95] & 255) | (buf
[96] << 8);
80 time_s
= (time
/ 10.0);
81 printf("%2.1fs\n", time_s
);
87 // byte 41 identifies the focusing type
91 else if (buf
[41] == 4) {
94 else if (buf
[41] == 5) {
97 else if (buf
[41] == 2) {
101 // bytes 71/72 identify drive/bracketing type
103 printf("Singleshot\n");
105 else if (buf
[71] == 2) {
106 printf("Continuous drive (high)\n");
108 else if (buf
[71] == 0x12) {
109 printf("Continuous drive (low)\n");
111 else if (buf
[71] == 4) {
112 printf("Timer (10s)\n");
114 else if (buf
[71] == 5) {
115 printf("Timer (2s)\n");
117 else if (buf
[71] == '\x37' && buf
[72] == '\x83') {
118 printf("Continuous bracketing (0.3 f-stops, 3 pictures)\n");
120 else if (buf
[71] == '\x37' && buf
[72] == '\x85') {
121 printf("Continuous bracketing (0.3 f-stops, 5 pictures)\n");
123 else if (buf
[71] == '\x57' && buf
[72] == '\x83') {
124 printf("Continuous bracketing (0.5 f-stops, 3 pictures)\n");
126 else if (buf
[71] == '\x57' && buf
[72] == '\x85') {
127 printf("Continuous bracketing (0.5 f-stops, 5 pictures)\n");
129 else if (buf
[71] == '\x77' && buf
[72] == '\x83') {
130 printf("Continuous bracketing (0.7 f-stops, 3 pictures)\n");
132 else if (buf
[71] == '\x77' && buf
[72] == '\x85') {
133 printf("Continuous bracketing (0.7 f-stops, 5 pictures)\n");
135 else if (buf
[71] == '\x47') {
136 printf("Continuous bracketing (2 f-stops, 3 pictures)\n");
138 else if (buf
[71] == '\x29') {
139 printf("DR-+ bracketing (high)\n");
141 else if (buf
[71] == '\x19') {
142 printf("DR-+ bracketing (low)\n");
144 else if (buf
[71] == '\x36' && buf
[72] == '\x83') {
145 printf("Single bracketing (0.3 f-stops, 3 pictures)\n");
147 else if (buf
[71] == '\x36' && buf
[72] == '\x85') {
148 printf("Single bracketing (0.3 f-stops, 5 pictures)\n");
150 else if (buf
[71] == '\x56' && buf
[72] == '\x83') {
151 printf("Single bracketing (0.5 f-stops, 3 pictures)\n");
153 else if (buf
[71] == '\x56' && buf
[72] == '\x85') {
154 printf("Single bracketing (0.5 f-stops, 5 pictures)\n");
156 else if (buf
[71] == '\x76' && buf
[72] == '\x83') {
157 printf("Single bracketing (0.7 f-stops, 3 pictures)\n");
159 else if (buf
[71] == '\x76' && buf
[72] == '\x85') {
160 printf("Single bracketing (0.7 f-stops, 5 pictures)\n");
162 else if (buf
[71] == '\x46') {
163 printf("Single bracketing (2 f-stops, 3 pictures)\n");
165 else if (buf
[71] == '\x28') {
166 printf("WB bracketing (high)\n");
168 else if (buf
[71] == '\x18') {
169 printf("WB bracketing (low)\n");
171 else if (buf
[71] == '\x0a') {
172 printf("Remote control\n");
176 int main(int argc
, char **argv
) {
177 int ret
, vendor
, product
;
178 struct usb_device
*dev
;
179 char buf
[65535], *endptr
;
187 dev
= find_device(vendor
, product
);
190 devh
= usb_open(dev
);
193 signal(SIGTERM
, release_usb_device
);
195 ret
= usb_get_driver_np(devh
, 0, buf
, sizeof(buf
));
197 printf("interface 0 already claimed by driver \"%s\", attempting to detach it\n", buf
);
198 ret
= usb_detach_kernel_driver_np(devh
, 0);
199 printf("usb_detach_kernel_driver_np returned %d\n", ret
);
201 ret
= usb_claim_interface(devh
, 0);
203 printf("claim failed with error %d\n", ret
);
207 ret
= usb_set_altinterface(devh
, 0);
210 ret
= usb_get_descriptor(devh
, 0x0000001, 0x0000000, buf
, 0x0000012);
212 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000009);
214 ret
= usb_get_descriptor(devh
, 0x0000002, 0x0000000, buf
, 0x0000027);
216 ret
= usb_release_interface(devh
, 0);
217 if (ret
!= 0) printf("failed to release interface before set_configuration: %d\n", ret
);
218 ret
= usb_set_configuration(devh
, 0x0000001);
219 ret
= usb_claim_interface(devh
, 0);
220 if (ret
!= 0) printf("claim after set_configuration failed with error %d\n", ret
);
221 ret
= usb_set_altinterface(devh
, 0);
223 // get info (bulk read 62)
225 memcpy(buf
, "\x0c\x00\x00\x00\x01\x00\x08\x92\x0f\x00\x00\x00", 0x000000c);
226 ret
= usb_bulk_write(devh
, 0x00000001, buf
, 0x000000c, 1000);
228 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
230 print_interpretation(buf
);
232 print_bytes(buf
, ret
);
234 ret
= usb_bulk_read(devh
, 0x00000082, buf
, 0x0000200, 1030);
235 ret
= usb_release_interface(devh
, 0);
237 ret
= usb_close(devh
);