-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_controller.c
67 lines (58 loc) · 1.97 KB
/
fix_controller.c
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
#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>
int main() {
int res;
libusb_device **devices;
libusb_device_handle *device_handle;
struct libusb_device_descriptor desc;
res = libusb_init(NULL);
if (res < 0) {
fprintf(stderr, "libusb_init error: %d\n", res);
return EXIT_FAILURE;
}
if (geteuid() != 0) {
printf("You need to run this program with sudo\n");
libusb_exit(NULL);
return EXIT_FAILURE;
}
ssize_t cnt = libusb_get_device_list(NULL, &devices);
if (cnt < 0) {
fprintf(stderr, "libusb_get_device_list error: %zd\n", cnt);
libusb_exit(NULL);
return EXIT_FAILURE;
}
for (ssize_t i = 0; i < cnt; ++i) {
libusb_device *device = devices[i];
libusb_get_device_descriptor(device, &desc);
// "Xbox" controller, actually is a fake ps3 controller
if (desc.idVendor == 0x045e && desc.idProduct == 0x028e) {
res = libusb_open(device, &device_handle);
if (res < 0) {
fprintf(stderr, "libusb_open error: %d\n", res);
libusb_free_device_list(devices, 1);
libusb_exit(NULL);
return EXIT_FAILURE;
}
/*
libusb_device_handle *device_handle,
uint8_t bmRequestType: 0xc1 = 11000001 (request to interface),
uint8_t bRequest,
uint16_t wValue,
uint16_t wIndex,
unsigned char *data,
uint16_t wLength,
unsigned int timeout
*/
res = libusb_control_transfer(device_handle, 0xc1, 0x01, 0x0100, 0x00, NULL, 0, 0);
if (res < 0) {
fprintf(stderr, "libusb_control_transfer error: %d\n", res);
}
libusb_close(device_handle);
break;
}
}
libusb_free_device_list(devices, 1);
libusb_exit(NULL);
return EXIT_SUCCESS;
}