-
Notifications
You must be signed in to change notification settings - Fork 4
/
ioctl.go
189 lines (152 loc) · 4.23 KB
/
ioctl.go
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// This file is subject to a 1-clause BSD license.
// Its contents can be found in the enclosed LICENSE file.
package evdev
import (
"fmt"
"syscall"
"unsafe"
)
func ioctl(fd, name uintptr, data interface{}) error {
var v uintptr
switch dd := data.(type) {
case unsafe.Pointer:
v = uintptr(dd)
case int:
v = uintptr(dd)
case uintptr:
v = dd
default:
return fmt.Errorf("ioctl: Invalid argument: %T", data)
}
_, _, errno := syscall.RawSyscall(syscall.SYS_IOCTL, fd, name, v)
if errno == 0 {
return nil
}
return errno
}
var (
_EVIOCGVERSION uintptr
_EVIOCGID uintptr
_EVIOCGREP uintptr
_EVIOCSREP uintptr
_EVIOCGKEYCODE uintptr
_EVIOCGKEYCODE_V2 uintptr
_EVIOCSKEYCODE uintptr
_EVIOCSKEYCODE_V2 uintptr
_EVIOCSFF uintptr
_EVIOCRMFF uintptr
_EVIOCGEFFECTS uintptr
_EVIOCGRAB uintptr
_EVIOCSCLOCKID uintptr
)
func init() {
var i int32
var id Id
var ke KeymapEntry
var ffe Effect
sizeof_int := int(unsafe.Sizeof(i))
sizeof_int2 := sizeof_int << 1
sizeof_id := int(unsafe.Sizeof(id))
sizeof_keymap_entry := int(unsafe.Sizeof(ke))
sizeof_effect := int(unsafe.Sizeof(ffe))
_EVIOCGVERSION = _IOR('E', 0x01, sizeof_int)
_EVIOCGID = _IOR('E', 0x02, sizeof_id)
_EVIOCGREP = _IOR('E', 0x03, sizeof_int2)
_EVIOCSREP = _IOW('E', 0x03, sizeof_int2)
_EVIOCGKEYCODE = _IOR('E', 0x04, sizeof_int2)
_EVIOCGKEYCODE_V2 = _IOR('E', 0x04, sizeof_keymap_entry)
_EVIOCSKEYCODE = _IOW('E', 0x04, sizeof_int2)
_EVIOCSKEYCODE_V2 = _IOW('E', 0x04, sizeof_keymap_entry)
_EVIOCSFF = _IOC(_IOC_WRITE, 'E', 0x80, sizeof_effect)
_EVIOCRMFF = _IOW('E', 0x81, sizeof_int)
_EVIOCGEFFECTS = _IOR('E', 0x84, sizeof_int)
_EVIOCGRAB = _IOW('E', 0x90, sizeof_int)
_EVIOCSCLOCKID = _IOW('E', 0xa0, sizeof_int)
}
func _EVIOCGNAME(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x06, len)
}
func _EVIOCGPHYS(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x07, len)
}
func _EVIOCGUNIQ(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x08, len)
}
func _EVIOCGPROP(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x09, len)
}
func _EVIOCGMTSLOTS(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x0a, len)
}
func _EVIOCGKEY(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x18, len)
}
func _EVIOCGLED(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x19, len)
}
func _EVIOCGSND(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x1a, len)
}
func _EVIOCGSW(len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x1b, len)
}
func _EVIOCGBIT(ev, len int) uintptr {
return _IOC(_IOC_READ, 'E', 0x20+ev, len)
}
func _EVIOCGABS(abs int) uintptr {
var v AbsInfo
return _IOR('E', 0x40+abs, int(unsafe.Sizeof(v)))
}
func _EVIOCSABS(abs int) uintptr {
var v AbsInfo
return _IOW('E', 0xc0+abs, int(unsafe.Sizeof(v)))
}
const (
_IOC_NONE = 0x0
_IOC_WRITE = 0x1
_IOC_READ = 0x2
_IOC_NRBITS = 8
_IOC_TYPEBITS = 8
_IOC_SIZEBITS = 14
_IOC_DIRBITS = 2
_IOC_NRSHIFT = 0
_IOC_NRMASK = (1 << _IOC_NRBITS) - 1
_IOC_TYPEMASK = (1 << _IOC_TYPEBITS) - 1
_IOC_SIZEMASK = (1 << _IOC_SIZEBITS) - 1
_IOC_DIRMASK = (1 << _IOC_DIRBITS) - 1
_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS
_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS
_IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS
_IOC_IN = _IOC_WRITE << _IOC_DIRSHIFT
_IOC_OUT = _IOC_READ << _IOC_DIRSHIFT
_IOC_INOUT = (_IOC_WRITE | _IOC_READ) << _IOC_DIRSHIFT
_IOCSIZE_MASK = _IOC_SIZEMASK << _IOC_SIZESHIFT
)
func _IOC(dir, t, nr, size int) uintptr {
return uintptr((dir << _IOC_DIRSHIFT) | (t << _IOC_TYPESHIFT) |
(nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT))
}
func _IO(t, nr int) uintptr {
return _IOC(_IOC_NONE, t, nr, 0)
}
func _IOR(t, nr, size int) uintptr {
return _IOC(_IOC_READ, t, nr, size)
}
func _IOW(t, nr, size int) uintptr {
return _IOC(_IOC_WRITE, t, nr, size)
}
func _IOWR(t, nr, size int) uintptr {
return _IOC(_IOC_READ|_IOC_WRITE, t, nr, size)
}
func _IOC_DIR(nr int) uintptr {
return uintptr(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
}
func _IOC_TYPE(nr int) uintptr {
return uintptr(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
}
func _IOC_NR(nr int) uintptr {
return uintptr(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
}
func _IOC_SIZE(nr int) uintptr {
return uintptr(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
}