summaryrefslogtreecommitdiffstats
path: root/host/main.c
blob: a779cc1ffb908a181d1d59fb4091fd6b40d48b80 (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
#include "project.h"



static void poke(libusb_device_handle *devh)
{
uint32_t timeout=4000;
char buf[128];
int len;

len=    libusb_control_transfer( devh,
        /* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_INTERFACE,
        /* bRequest      */ 0x34,
        /* wValue        */ 0x1234,
        /* wIndex        */ 0x5678,
        /* Data          */ buf,
        /* wLength       */ sizeof(buf), timeout );




if (len>=0)
hexdump(">",buf,len);


}



static void poke_device(libusb_device *dev, struct libusb_device_descriptor *desc)
{
int ret;
libusb_device_handle *devh;

ret=libusb_open(dev, &devh);

if (ret) {
	warn("unable to open device: %i",ret);
	return;
}

printf("poke\n");

poke(devh);

libusb_close(devh);

}

void probe_devices(libusb_context *ctx)
{
        libusb_device **list;
        ssize_t num_devs;
        ssize_t i;

        num_devs = libusb_get_device_list(ctx, &list);
        for (i = 0; i < num_devs; ++i) {
                struct libusb_device_descriptor desc;
                struct libusb_device *dev = list[i];

                if (libusb_get_device_descriptor(dev, &desc))
                        continue;


		if (desc.idVendor!=0x1d6b) continue;
		if (desc.idProduct!=0x1932) continue;

		poke_device(dev,&desc);

        }
        libusb_free_device_list(list, 0);
}





int main(int argc,char *argv)
{
	int ret;

        libusb_context *ctx;


        ret = libusb_init(&ctx);
        if (ret) 
                errx(EX_IOERR, "unable to initialize libusb: %i", ret);


	libusb_set_debug(ctx, 255);

        probe_devices(ctx);

	return 0;
}