-
Notifications
You must be signed in to change notification settings - Fork 4
/
set_touchmode.c
109 lines (89 loc) · 2.68 KB
/
set_touchmode.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
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
102
103
104
105
106
107
108
109
/*
* Utility to put MS Touch Mouse into raw touch events mode.
* Copyright (c) 2011 Maurus Cuelenaere <[email protected]>
*
* Based on samples/hidraw/hid-example.c from Linux kernel tree:
* Copyright (c) 2010 Alan Ott <[email protected]>
* Copyright (c) 2010 Signal 11 Software
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <linux/hidraw.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef HIDIOCSFEATURE
#warning Please use more recent kernel headers (>=2.6.38)
#endif
static int send_report(int fd, char *buf, size_t len) {
int res = ioctl(fd, HIDIOCSFEATURE(len), buf);
if (res < 0)
perror("HIDIOCSFEATURE failed");
return res;
}
static int get_report(int fd, char id, char *buf, size_t len) {
int i, res;
buf[0] = id;
res = ioctl(fd, HIDIOCGFEATURE(len), buf);
if (res < 0) {
perror("HIDIOCGFEATURE failed");
} else {
printf("Report data (%d):\n\t", id);
for (i = 0; i < res; i++)
printf("%hhx ", buf[i]);
puts("\n");
}
return res;
}
static int do_voodoo(int fd) {
int i;
char recv_buf[256];
static struct {
char buf[64];
size_t len;
} reports[] = {
{{18, 0x01}, 2},
{{18, 0x05}, 2},
{{23, 0x05}, 2},
{{23, 0x01}, 2},
{{23, 0x11}, 2},
{{40, 0x00, 0x02}, 3},
{{40, 0x10, 0x00}, 3},
{{0x22, 0x14, 0x01, 0x00, 0x06, 0x00, 0x00, 0x03, 0xe8, 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 27},
{{0x24, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x5e, 0x04, 0x73, 0x07, 0xf0, 0xe0, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 32},
};
for (i=0; i < sizeof(reports)/sizeof(reports[0]); i++) {
send_report(fd, reports[i].buf, reports[i].len);
get_report(fd, reports[i].buf[0], recv_buf, reports[i].len);
}
return 0;
}
static int do_simple_voodoo(int fd) {
char buffer[27];
get_report(fd, 0x22, buffer, sizeof(buffer));
if (buffer[0] != 0x22 || buffer[1] != 0x14)
return 1;
buffer[2] = 1;
if (!buffer[3] && buffer[4] != 0x6) {
buffer[4] = 0x6;
send_report(fd, buffer, sizeof(buffer));
}
return 0;
}
int main(int argc, char* argv[]) {
int fd, ret;
if (argc <= 1) {
printf("%s /dev/hidrawX \n", argv[0]);
return -1;
}
fd = open(argv[1], O_RDWR | O_NONBLOCK);
if (fd < 0) {
perror("Unable to open device");
return -2;
}
//ret = do_voodoo(fd);
ret = do_simple_voodoo(fd);
close(fd);
return ret;
}