-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
55 lines (46 loc) · 1.09 KB
/
main.c
File metadata and controls
55 lines (46 loc) · 1.09 KB
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
/**
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <libusb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
unsigned char cmd[1] = { 0x14 };
libusb_device_handle *h;
libusb_context *c = NULL;
int r;
/* we need to be able to send control transfer messages
* maybe we could find a better way but for now this will
* do
*/
if (geteuid() != 0) {
fprintf(stderr, "You need to run as root or use sudo");
return 1;
}
r = libusb_init(&c);
if (r) {
fprintf(stderr, "Unable to initialize libusb: %s\n", libusb_strerror(r));
return 1;
}
h = libusb_open_device_with_vid_pid(c, 0x045e, 0x028e);
if (h == NULL) {
fprintf(stderr, "Unable to open usb device\n");
goto cleanup;
}
/*
* see https://gist.github.com/dnmodder/de2df973323b7c6acf45f40dc66e8db3
*/
r = libusb_control_transfer(h, 0xc1, 0x01, 0x0100, 0x00, cmd, sizeof(cmd), 0);
if (r < 0) {
fprintf(stderr, "Control transfer failed: %s\n", libusb_strerror(r));
goto cleanup;
}
cleanup:
if (h)
libusb_close(h);
libusb_exit(c);
return 0;
}