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>
5 * Copyright (c) 1996-2001 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
32 #include <asm/ioctl.h>
33 #include "xlat/ioctl_dirs.h"
35 #ifdef HAVE_LINUX_INPUT_H
36 # include <linux/input.h>
39 #include "xlat/evdev_abs.h"
40 #include "xlat/evdev_ev.h"
43 compare(const void *a, const void *b)
45 const unsigned int code1 = (const unsigned long) a;
46 const unsigned int code2 = ((struct_ioctlent *) b)->code;
47 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
50 const struct_ioctlent *
51 ioctl_lookup(const unsigned int code)
55 iop = bsearch((const void *) (const unsigned long) code, ioctlent,
56 nioctlents, sizeof(ioctlent[0]), compare);
57 while (iop > ioctlent) {
59 if (iop->code != code) {
67 const struct_ioctlent *
68 ioctl_next_match(const struct_ioctlent *iop)
70 const unsigned int code = iop->code;
72 if (iop < ioctlent + nioctlents && iop->code == code)
78 ioctl_print_code(const unsigned int code)
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));
87 evdev_decode_number(unsigned int arg)
89 unsigned int nr = _IOC_NR(arg);
91 if (_IOC_DIR(arg) == _IOC_WRITE) {
92 if (nr >= 0xc0 && nr <= 0xc0 + 0x3f) {
93 tprints("EVIOCSABS(");
94 printxval(evdev_abs, nr - 0xc0, "EV_???");
100 if (_IOC_DIR(arg) != _IOC_READ)
103 if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
104 tprints("EVIOCGBIT(");
105 printxval(evdev_ev, nr - 0x20, "EV_???");
106 tprintf(", %u)", _IOC_SIZE(arg));
108 } else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {
109 tprints("EVIOCGABS(");
110 printxval(evdev_abs, nr - 0x40, "ABS_???");
115 switch (_IOC_NR(nr)) {
117 tprintf("EVIOCGNAME(%u)", _IOC_SIZE(arg));
120 tprintf("EVIOCGPHYS(%u)", _IOC_SIZE(arg));
123 tprintf("EVIOCGUNIQ(%u)", _IOC_SIZE(arg));
126 tprintf("EVIOCGPROP(%u)", _IOC_SIZE(arg));
129 tprintf("EVIOCGMTSLOTS(%u)", _IOC_SIZE(arg));
132 tprintf("EVIOCGKEY(%u)", _IOC_SIZE(arg));
135 tprintf("EVIOCGLED(%u)", _IOC_SIZE(arg));
138 tprintf("EVIOCGSND(%u)", _IOC_SIZE(arg));
141 tprintf("EVIOCGSW(%u)", _IOC_SIZE(arg));
149 hiddev_decode_number(unsigned int arg)
151 if (_IOC_DIR(arg) == _IOC_READ) {
152 switch (_IOC_NR(arg)) {
154 tprintf("HIDIOCGRAWNAME(%u)", _IOC_SIZE(arg));
157 tprintf("HIDIOCGRAWPHYS(%u)", _IOC_SIZE(arg));
160 tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(arg));
163 tprintf("HIDIOCGPHYS(%u)", _IOC_SIZE(arg));
168 } else if (_IOC_DIR(arg) == (_IOC_READ | _IOC_WRITE)) {
169 switch (_IOC_NR(arg)) {
171 tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(arg));
174 tprintf("HIDIOCGFEATURE(%u)", _IOC_SIZE(arg));
185 ioctl_decode_command_number(unsigned int arg)
187 switch (_IOC_TYPE(arg)) {
189 return evdev_decode_number(arg);
191 return hiddev_decode_number(arg);
193 if (_IOC_DIR(arg) == _IOC_WRITE) {
194 tprintf("MIXER_WRITE(%u)", _IOC_NR(arg));
196 } else if (_IOC_DIR(arg) == _IOC_READ) {
197 tprintf("MIXER_READ(%u)", _IOC_NR(arg));
202 if (_IOC_DIR(arg) == _IOC_READ && _IOC_NR(arg) == 0x2c) {
203 tprintf("UI_GET_SYSNAME(%u)", _IOC_SIZE(arg));
208 if (_IOC_DIR(arg) == _IOC_READ && _IOC_NR(arg) == 0x13) {
209 tprintf("JSIOCGNAME(%u)", _IOC_SIZE(arg));
214 if (_IOC_DIR(arg) == _IOC_WRITE && _IOC_NR(arg) == 0) {
215 tprintf("SPI_IOC_MESSAGE(%u)", _IOC_SIZE(arg));
225 ioctl_decode(struct tcb *tcp, unsigned int code, long arg)
227 switch (_IOC_TYPE(code)) {
228 #if defined(ALPHA) || defined(POWERPC)
229 case 'f': case 't': case 'T':
233 return term_ioctl(tcp, code, arg);
235 return sock_ioctl(tcp, code, arg);
237 return rtc_ioctl(tcp, code, arg);
241 return block_ioctl(tcp, code, arg);
242 #ifdef HAVE_SCSI_SG_H
244 return scsi_ioctl(tcp, code, arg);
247 return loop_ioctl(tcp, code, arg);
249 return mtd_ioctl(tcp, code, arg);
252 return ubi_ioctl(tcp, code, arg);
254 return v4l2_ioctl(tcp, code, arg);
256 return ptp_ioctl(tcp, code, arg);
257 #ifdef HAVE_LINUX_INPUT_H
259 return evdev_ioctl(tcp, code, arg);
268 * Registry of ioctl characters, culled from
269 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
271 * char file where defined notes
272 * ---- ------------------ -----
276 * M sundev/mcpcmd.h *overlap*
277 * M sys/modem.h *overlap*
279 * T sys/termio.h -no overlap-
280 * T sys/termios.h -no overlap-
283 * d sun/dkio.h -no overlap with sys/des.h-
284 * d sys/des.h (possible overlap)
285 * d vax/dkio.h (possible overlap)
286 * d vaxuba/rxreg.h (possible overlap)
288 * g sunwindow/win_ioctl.h -no overlap-
289 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
290 * h sundev/hrc_common.h
291 * i sys/sockio.h *overlap*
292 * i vaxuba/ikreg.h *overlap*
294 * m sundev/msio.h (possible overlap)
295 * m sundev/msreg.h (possible overlap)
296 * m sys/mtio.h (possible overlap)
298 * p net/nit_buf.h (possible overlap)
299 * p net/nit_if.h (possible overlap)
300 * p net/nit_pf.h (possible overlap)
301 * p sundev/fpareg.h (possible overlap)
302 * p sys/sockio.h (possible overlap)
303 * p vaxuba/psreg.h (possible overlap)
307 * t sys/ttold.h (possible overlap)
308 * t sys/ttycom.h (possible overlap)
309 * v sundev/vuid_event.h *overlap*
310 * v sys/vcmd.h *overlap*
311 * V linux/videodev2.h