blob: a2b42ba6a3860bbc37b56ec1b583028807558557 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkermanc6c1ea52001-08-03 21:52:13 +00005 * Copyright (c) 1996-2001 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkermana9667852001-03-17 17:26:34 +000032#include <asm/ioctl.h>
Dmitry V. Levin924996a2015-01-20 00:24:36 +000033#include "xlat/ioctl_dirs.h"
Wichert Akkermana9667852001-03-17 17:26:34 +000034
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010035#ifdef HAVE_LINUX_INPUT_H
36# include <linux/input.h>
37#endif
38
39#include "xlat/evdev_abs.h"
40#include "xlat/evdev_ev.h"
41
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042static int
Denys Vlasenko12014262011-05-30 14:00:14 +020043compare(const void *a, const void *b)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000045 const unsigned int code1 = (const unsigned long) a;
46 const unsigned int code2 = ((struct_ioctlent *) b)->code;
Denys Vlasenkofeb40c42012-03-20 13:11:51 +010047 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048}
49
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010050const struct_ioctlent *
Dmitry V. Levindf7aa2b2015-01-19 17:02:16 +000051ioctl_lookup(const unsigned int code)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052{
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010053 struct_ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000055 iop = bsearch((const void *) (const unsigned long) code, ioctlent,
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010056 nioctlents, sizeof(ioctlent[0]), compare);
57 while (iop > ioctlent) {
58 iop--;
59 if (iop->code != code) {
Roland McGrath2843a4e2003-11-14 02:54:03 +000060 iop++;
61 break;
62 }
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010063 }
Roland McGrath2843a4e2003-11-14 02:54:03 +000064 return iop;
65}
66
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010067const struct_ioctlent *
68ioctl_next_match(const struct_ioctlent *iop)
Roland McGrath2843a4e2003-11-14 02:54:03 +000069{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000070 const unsigned int code = iop->code;
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010071 iop++;
Roland McGrath2843a4e2003-11-14 02:54:03 +000072 if (iop < ioctlent + nioctlents && iop->code == code)
73 return iop;
74 return NULL;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000075}
76
Dmitry V. Levin924996a2015-01-20 00:24:36 +000077void
78ioctl_print_code(const unsigned int code)
79{
80 tprints("_IOC(");
81 printflags(ioctl_dirs, _IOC_DIR(code), "_IOC_???");
82 tprintf(", 0x%02x, 0x%02x, 0x%02x)",
83 _IOC_TYPE(code), _IOC_NR(code), _IOC_SIZE(code));
84}
85
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010086static int
87evdev_decode_number(unsigned int arg)
88{
89 unsigned int nr = _IOC_NR(arg);
90
91 if (_IOC_DIR(arg) == _IOC_WRITE) {
92 if (nr >= 0xc0 && nr <= 0xc0 + 0x3f) {
93 tprints("EVIOCSABS(");
94 printxval(evdev_abs, nr - 0xc0, "EV_???");
95 tprints(")");
96 return 1;
97 }
98 }
99
100 if (_IOC_DIR(arg) != _IOC_READ)
101 return 0;
102
103 if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
104 tprints("EVIOCGBIT(");
105 printxval(evdev_ev, nr - 0x20, "EV_???");
106 tprintf(", %u)", _IOC_SIZE(arg));
107 return 1;
108 } else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {
109 tprints("EVIOCGABS(");
110 printxval(evdev_abs, nr - 0x40, "ABS_???");
111 tprints(")");
112 return 1;
113 }
114
115 switch (_IOC_NR(nr)) {
116 case 0x06:
117 tprintf("EVIOCGNAME(%u)", _IOC_SIZE(arg));
118 return 1;
119 case 0x07:
120 tprintf("EVIOCGPHYS(%u)", _IOC_SIZE(arg));
121 return 1;
122 case 0x08:
123 tprintf("EVIOCGUNIQ(%u)", _IOC_SIZE(arg));
124 return 1;
125 case 0x09:
126 tprintf("EVIOCGPROP(%u)", _IOC_SIZE(arg));
127 return 1;
128 case 0x0a:
129 tprintf("EVIOCGMTSLOTS(%u)", _IOC_SIZE(arg));
130 return 1;
131 case 0x18:
132 tprintf("EVIOCGKEY(%u)", _IOC_SIZE(arg));
133 return 1;
134 case 0x19:
135 tprintf("EVIOCGLED(%u)", _IOC_SIZE(arg));
136 return 1;
137 case 0x1a:
138 tprintf("EVIOCGSND(%u)", _IOC_SIZE(arg));
139 return 1;
140 case 0x1b:
141 tprintf("EVIOCGSW(%u)", _IOC_SIZE(arg));
142 return 1;
143 default:
144 return 0;
145 }
146}
147
148static int
149hiddev_decode_number(unsigned int arg)
150{
151 if (_IOC_DIR(arg) == _IOC_READ) {
152 switch (_IOC_NR(arg)) {
153 case 0x04:
154 tprintf("HIDIOCGRAWNAME(%u)", _IOC_SIZE(arg));
155 return 1;
156 case 0x05:
157 tprintf("HIDIOCGRAWPHYS(%u)", _IOC_SIZE(arg));
158 return 1;
159 case 0x06:
160 tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(arg));
161 return 1;
162 case 0x12:
163 tprintf("HIDIOCGPHYS(%u)", _IOC_SIZE(arg));
164 return 1;
165 default:
166 return 0;
167 }
168 } else if (_IOC_DIR(arg) == (_IOC_READ | _IOC_WRITE)) {
169 switch (_IOC_NR(arg)) {
170 case 0x06:
171 tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(arg));
172 return 1;
173 case 0x07:
174 tprintf("HIDIOCGFEATURE(%u)", _IOC_SIZE(arg));
175 return 1;
176 default:
177 return 0;
178 }
179 }
180
181 return 0;
182}
183
184int
185ioctl_decode_command_number(unsigned int arg)
186{
187 switch (_IOC_TYPE(arg)) {
188 case 'E':
189 return evdev_decode_number(arg);
190 case 'H':
191 return hiddev_decode_number(arg);
192 case 'M':
193 if (_IOC_DIR(arg) == _IOC_WRITE) {
194 tprintf("MIXER_WRITE(%u)", _IOC_NR(arg));
195 return 1;
196 } else if (_IOC_DIR(arg) == _IOC_READ) {
197 tprintf("MIXER_READ(%u)", _IOC_NR(arg));
198 return 1;
199 }
200 return 0;
201 case 'U':
202 if (_IOC_DIR(arg) == _IOC_READ && _IOC_NR(arg) == 0x2c) {
203 tprintf("UI_GET_SYSNAME(%u)", _IOC_SIZE(arg));
204 return 1;
205 }
206 return 0;
207 case 'j':
208 if (_IOC_DIR(arg) == _IOC_READ && _IOC_NR(arg) == 0x13) {
209 tprintf("JSIOCGNAME(%u)", _IOC_SIZE(arg));
210 return 1;
211 }
212 return 0;
213 case 'k':
214 if (_IOC_DIR(arg) == _IOC_WRITE && _IOC_NR(arg) == 0) {
215 tprintf("SPI_IOC_MESSAGE(%u)", _IOC_SIZE(arg));
216 return 1;
217 }
218 return 0;
219 default:
220 return 0;
221 }
222}
223
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224int
Dmitry V. Levinc7afb482015-01-19 18:44:21 +0000225ioctl_decode(struct tcb *tcp, unsigned int code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +0000227 switch (_IOC_TYPE(code)) {
Roland McGrathbb3af522003-01-14 07:53:34 +0000228#if defined(ALPHA) || defined(POWERPC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229 case 'f': case 't': case 'T':
230#else /* !ALPHA */
231 case 0x54:
232#endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233 return term_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234 case 0x89:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 return sock_ioctl(tcp, code, arg);
Roland McGrathd83c50b2004-10-06 22:27:43 +0000236 case 'p':
237 return rtc_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +0000238 case 0x03:
239 case 0x12:
Mike Frysinger5b886082014-11-21 16:13:16 -0500240 case 'X':
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +0000241 return block_ioctl(tcp, code, arg);
Dmitry V. Levinfdb896e2014-02-25 23:04:55 +0000242#ifdef HAVE_SCSI_SG_H
Dmitry V. Levinb011af52007-06-30 11:37:09 +0000243 case 0x22:
244 return scsi_ioctl(tcp, code, arg);
Dmitry V. Levinfdb896e2014-02-25 23:04:55 +0000245#endif
Mike Frysingerebee04c2012-04-17 22:19:31 -0400246 case 'L':
247 return loop_ioctl(tcp, code, arg);
Mike Frysinger0cbed352012-04-04 22:22:01 -0400248 case 'M':
249 return mtd_ioctl(tcp, code, arg);
Mike Frysingerd648f292013-05-01 23:35:30 -0400250 case 'o':
251 case 'O':
252 return ubi_ioctl(tcp, code, arg);
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100253 case 'V':
254 return v4l2_ioctl(tcp, code, arg);
Stefan Sørensenb88a6f82014-01-31 12:01:01 +0100255 case '=':
256 return ptp_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257 default:
258 break;
259 }
260 return 0;
261}
262
263/*
264 * Registry of ioctl characters, culled from
265 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
266 *
267 * char file where defined notes
268 * ---- ------------------ -----
269 * F sun/fbio.h
270 * G sun/gpio.h
271 * H vaxif/if_hy.h
272 * M sundev/mcpcmd.h *overlap*
273 * M sys/modem.h *overlap*
274 * S sys/stropts.h
275 * T sys/termio.h -no overlap-
276 * T sys/termios.h -no overlap-
277 * V sundev/mdreg.h
278 * a vaxuba/adreg.h
279 * d sun/dkio.h -no overlap with sys/des.h-
280 * d sys/des.h (possible overlap)
281 * d vax/dkio.h (possible overlap)
282 * d vaxuba/rxreg.h (possible overlap)
283 * f sys/filio.h
284 * g sunwindow/win_ioctl.h -no overlap-
285 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
286 * h sundev/hrc_common.h
287 * i sys/sockio.h *overlap*
288 * i vaxuba/ikreg.h *overlap*
289 * k sundev/kbio.h
290 * m sundev/msio.h (possible overlap)
291 * m sundev/msreg.h (possible overlap)
292 * m sys/mtio.h (possible overlap)
293 * n sun/ndio.h
294 * p net/nit_buf.h (possible overlap)
295 * p net/nit_if.h (possible overlap)
296 * p net/nit_pf.h (possible overlap)
297 * p sundev/fpareg.h (possible overlap)
298 * p sys/sockio.h (possible overlap)
299 * p vaxuba/psreg.h (possible overlap)
300 * q sun/sqz.h
301 * r sys/sockio.h
302 * s sys/sockio.h
303 * t sys/ttold.h (possible overlap)
304 * t sys/ttycom.h (possible overlap)
305 * v sundev/vuid_event.h *overlap*
306 * v sys/vcmd.h *overlap*
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100307 * V linux/videodev2.h
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308 *
309 * End of Registry
310 */