1*7e2790cfSdsl /* $NetBSD: freebsd_ioctl.c,v 1.15 2007/12/20 23:02:47 dsl Exp $ */
263bb46e7Smycroft
363bb46e7Smycroft /*
463bb46e7Smycroft * Copyright (c) 1995 Frank van der Linden
563bb46e7Smycroft * All rights reserved.
663bb46e7Smycroft *
763bb46e7Smycroft * Redistribution and use in source and binary forms, with or without
863bb46e7Smycroft * modification, are permitted provided that the following conditions
963bb46e7Smycroft * are met:
1063bb46e7Smycroft * 1. Redistributions of source code must retain the above copyright
1163bb46e7Smycroft * notice, this list of conditions and the following disclaimer.
1263bb46e7Smycroft * 2. Redistributions in binary form must reproduce the above copyright
1363bb46e7Smycroft * notice, this list of conditions and the following disclaimer in the
1463bb46e7Smycroft * documentation and/or other materials provided with the distribution.
1563bb46e7Smycroft * 3. All advertising materials mentioning features or use of this software
1663bb46e7Smycroft * must display the following acknowledgement:
1763bb46e7Smycroft * This product includes software developed for the NetBSD Project
1863bb46e7Smycroft * by Frank van der Linden
1963bb46e7Smycroft * 4. The name of the author may not be used to endorse or promote products
2063bb46e7Smycroft * derived from this software without specific prior written permission
2163bb46e7Smycroft *
2263bb46e7Smycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2363bb46e7Smycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2463bb46e7Smycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2563bb46e7Smycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2663bb46e7Smycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2763bb46e7Smycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2863bb46e7Smycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2963bb46e7Smycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3063bb46e7Smycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3163bb46e7Smycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3263bb46e7Smycroft */
3363bb46e7Smycroft
34dab6ef8bSlukem #include <sys/cdefs.h>
35*7e2790cfSdsl __KERNEL_RCSID(0, "$NetBSD: freebsd_ioctl.c,v 1.15 2007/12/20 23:02:47 dsl Exp $");
36dab6ef8bSlukem
3763bb46e7Smycroft #include <sys/param.h>
3863bb46e7Smycroft #include <sys/systm.h>
3963bb46e7Smycroft #include <sys/proc.h>
4063bb46e7Smycroft #include <sys/mount.h>
41eb1f8f2aSonoe #include <sys/sockio.h>
4263bb46e7Smycroft
4363bb46e7Smycroft #include <sys/syscallargs.h>
4463bb46e7Smycroft
45eb1f8f2aSonoe #include <net/if.h>
46eb1f8f2aSonoe
4720bfd989Schristos #include <compat/sys/sockio.h>
4820bfd989Schristos
4963bb46e7Smycroft #include <compat/freebsd/freebsd_syscallargs.h>
5001040d97Sjdolecek #include <compat/common/compat_util.h>
5163bb46e7Smycroft #include <compat/freebsd/freebsd_ioctl.h>
5263bb46e7Smycroft
5332801cf3Saugustss #include <compat/ossaudio/ossaudio.h>
547d386f10Saugustss #include <compat/ossaudio/ossaudiovar.h>
557d386f10Saugustss
567d386f10Saugustss /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */
57*7e2790cfSdsl static void freebsd_to_oss(const struct freebsd_sys_ioctl_args *,
587d386f10Saugustss struct oss_sys_ioctl_args *);
597d386f10Saugustss
607d386f10Saugustss static void
freebsd_to_oss(const struct freebsd_sys_ioctl_args * uap,struct oss_sys_ioctl_args * rap)61*7e2790cfSdsl freebsd_to_oss(const struct freebsd_sys_ioctl_args *uap, struct oss_sys_ioctl_args *rap)
627d386f10Saugustss {
637d386f10Saugustss u_long ocmd, ncmd;
647d386f10Saugustss
657d386f10Saugustss ocmd = SCARG(uap, com);
667d386f10Saugustss ncmd = ocmd &~ FREEBSD_IOC_DIRMASK;
677d386f10Saugustss switch(ocmd & FREEBSD_IOC_DIRMASK) {
687d386f10Saugustss case FREEBSD_IOC_VOID: ncmd |= OSS_IOC_VOID; break;
697d386f10Saugustss case FREEBSD_IOC_OUT: ncmd |= OSS_IOC_OUT; break;
707d386f10Saugustss case FREEBSD_IOC_IN: ncmd |= OSS_IOC_IN; break;
717d386f10Saugustss case FREEBSD_IOC_INOUT: ncmd |= OSS_IOC_INOUT; break;
727d386f10Saugustss }
737d386f10Saugustss SCARG(rap, fd) = SCARG(uap, fd);
747d386f10Saugustss SCARG(rap, com) = ncmd;
757d386f10Saugustss SCARG(rap, data) = SCARG(uap, data);
767d386f10Saugustss }
7732801cf3Saugustss
78eb1f8f2aSonoe
79*7e2790cfSdsl static void freebsd_to_netbsd_ifioctl(const struct freebsd_sys_ioctl_args *uap,
80eb1f8f2aSonoe struct sys_ioctl_args *nap);
81eb1f8f2aSonoe
82eb1f8f2aSonoe static void
freebsd_to_netbsd_ifioctl(const struct freebsd_sys_ioctl_args * uap,struct sys_ioctl_args * nap)83*7e2790cfSdsl freebsd_to_netbsd_ifioctl(const struct freebsd_sys_ioctl_args *uap, struct sys_ioctl_args *nap)
84eb1f8f2aSonoe {
85eb1f8f2aSonoe u_long ocmd, ncmd;
86eb1f8f2aSonoe ocmd = SCARG(uap, com);
87eb1f8f2aSonoe switch (ocmd) {
88eb1f8f2aSonoe case FREEBSD_SIOCALIFADDR:
89eb1f8f2aSonoe ncmd =SIOCALIFADDR;
90eb1f8f2aSonoe break;
91eb1f8f2aSonoe case FREEBSD_SIOCGLIFADDR:
92eb1f8f2aSonoe ncmd =SIOCGLIFADDR;
93eb1f8f2aSonoe break;
94eb1f8f2aSonoe case FREEBSD_SIOCDLIFADDR:
95eb1f8f2aSonoe ncmd =SIOCDLIFADDR;
96eb1f8f2aSonoe break;
97eb1f8f2aSonoe case FREEBSD_SIOCGIFMTU:
98eb1f8f2aSonoe ncmd = SIOCGIFMTU;
99eb1f8f2aSonoe break;
100eb1f8f2aSonoe case FREEBSD_SIOCSIFMTU:
101eb1f8f2aSonoe ncmd = SIOCSIFMTU;
102eb1f8f2aSonoe break;
103eb1f8f2aSonoe default:
104eb1f8f2aSonoe ncmd = ocmd;
105eb1f8f2aSonoe break;
106eb1f8f2aSonoe }
107eb1f8f2aSonoe SCARG(nap, fd) = SCARG(uap, fd);
108eb1f8f2aSonoe SCARG(nap, com) = ncmd;
109eb1f8f2aSonoe SCARG(nap, data) = SCARG(uap, data);
110eb1f8f2aSonoe }
111eb1f8f2aSonoe
11263bb46e7Smycroft int
freebsd_sys_ioctl(struct lwp * l,const struct freebsd_sys_ioctl_args * uap,register_t * retval)113*7e2790cfSdsl freebsd_sys_ioctl(struct lwp *l, const struct freebsd_sys_ioctl_args *uap, register_t *retval)
11463bb46e7Smycroft {
115*7e2790cfSdsl /* {
11663bb46e7Smycroft syscallarg(int) fd;
11763bb46e7Smycroft syscallarg(u_long) com;
11853524e44Schristos syscallarg(void *) data;
119*7e2790cfSdsl } */
1207d386f10Saugustss struct oss_sys_ioctl_args ap;
121eb1f8f2aSonoe struct sys_ioctl_args nap;
12263bb46e7Smycroft
12363bb46e7Smycroft /*
12463bb46e7Smycroft * XXX - <sys/cdio.h>'s incompatibility
12563bb46e7Smycroft * _IO('c', 25..27, *): incompatible
12663bb46e7Smycroft * _IO('c', 28... , *): not exist
12763bb46e7Smycroft */
12863bb46e7Smycroft /* XXX - <sys/mtio.h> */
12963bb46e7Smycroft /* XXX - <sys/scsiio.h> */
13063bb46e7Smycroft /* XXX - should convert machine dependent ioctl()s */
13132801cf3Saugustss
13232801cf3Saugustss switch (FREEBSD_IOCGROUP(SCARG(uap, com))) {
13332801cf3Saugustss case 'M':
1347d386f10Saugustss freebsd_to_oss(uap, &ap);
13595e1ffb1Schristos return oss_ioctl_mixer(l, &ap, retval);
13632801cf3Saugustss case 'Q':
1377d386f10Saugustss freebsd_to_oss(uap, &ap);
13895e1ffb1Schristos return oss_ioctl_sequencer(l, &ap, retval);
13932801cf3Saugustss case 'P':
1407d386f10Saugustss freebsd_to_oss(uap, &ap);
14195e1ffb1Schristos return oss_ioctl_audio(l, &ap, retval);
142eb1f8f2aSonoe case 'i':
143eb1f8f2aSonoe freebsd_to_netbsd_ifioctl(uap, &nap);
1446762b37eSthorpej return sys_ioctl(l, &nap, retval);
14532801cf3Saugustss default:
146*7e2790cfSdsl return sys_ioctl(l, (const void *)uap, retval);
14763bb46e7Smycroft }
14832801cf3Saugustss }
149