1 /* $NetBSD: freebsd_ioctl.c,v 1.13 2007/05/29 21:32:27 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Frank van der Linden 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed for the NetBSD Project 18 * by Frank van der Linden 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: freebsd_ioctl.c,v 1.13 2007/05/29 21:32:27 christos Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/proc.h> 40 #include <sys/mount.h> 41 #include <sys/sockio.h> 42 43 #include <sys/syscallargs.h> 44 45 #include <net/if.h> 46 47 #include <compat/sys/sockio.h> 48 49 #include <compat/freebsd/freebsd_syscallargs.h> 50 #include <compat/common/compat_util.h> 51 #include <compat/freebsd/freebsd_ioctl.h> 52 53 #include <compat/ossaudio/ossaudio.h> 54 #include <compat/ossaudio/ossaudiovar.h> 55 56 /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */ 57 static void freebsd_to_oss(struct freebsd_sys_ioctl_args *, 58 struct oss_sys_ioctl_args *); 59 60 static void 61 freebsd_to_oss(uap, rap) 62 struct freebsd_sys_ioctl_args *uap; 63 struct oss_sys_ioctl_args *rap; 64 { 65 u_long ocmd, ncmd; 66 67 ocmd = SCARG(uap, com); 68 ncmd = ocmd &~ FREEBSD_IOC_DIRMASK; 69 switch(ocmd & FREEBSD_IOC_DIRMASK) { 70 case FREEBSD_IOC_VOID: ncmd |= OSS_IOC_VOID; break; 71 case FREEBSD_IOC_OUT: ncmd |= OSS_IOC_OUT; break; 72 case FREEBSD_IOC_IN: ncmd |= OSS_IOC_IN; break; 73 case FREEBSD_IOC_INOUT: ncmd |= OSS_IOC_INOUT; break; 74 } 75 SCARG(rap, fd) = SCARG(uap, fd); 76 SCARG(rap, com) = ncmd; 77 SCARG(rap, data) = SCARG(uap, data); 78 } 79 80 81 static void freebsd_to_netbsd_ifioctl(struct freebsd_sys_ioctl_args *uap, 82 struct sys_ioctl_args *nap); 83 84 static void 85 freebsd_to_netbsd_ifioctl(uap, nap) 86 struct freebsd_sys_ioctl_args *uap; 87 struct sys_ioctl_args *nap; 88 { 89 u_long ocmd, ncmd; 90 ocmd = SCARG(uap, com); 91 switch (ocmd) { 92 case FREEBSD_SIOCALIFADDR: 93 ncmd =SIOCALIFADDR; 94 break; 95 case FREEBSD_SIOCGLIFADDR: 96 ncmd =SIOCGLIFADDR; 97 break; 98 case FREEBSD_SIOCDLIFADDR: 99 ncmd =SIOCDLIFADDR; 100 break; 101 case FREEBSD_SIOCGIFMTU: 102 ncmd = SIOCGIFMTU; 103 break; 104 case FREEBSD_SIOCSIFMTU: 105 ncmd = SIOCSIFMTU; 106 break; 107 default: 108 ncmd = ocmd; 109 break; 110 } 111 SCARG(nap, fd) = SCARG(uap, fd); 112 SCARG(nap, com) = ncmd; 113 SCARG(nap, data) = SCARG(uap, data); 114 } 115 116 int 117 freebsd_sys_ioctl(l, v, retval) 118 struct lwp *l; 119 void *v; 120 register_t *retval; 121 { 122 struct freebsd_sys_ioctl_args /* { 123 syscallarg(int) fd; 124 syscallarg(u_long) com; 125 syscallarg(void *) data; 126 } */ *uap = v; 127 struct oss_sys_ioctl_args ap; 128 struct sys_ioctl_args nap; 129 130 /* 131 * XXX - <sys/cdio.h>'s incompatibility 132 * _IO('c', 25..27, *): incompatible 133 * _IO('c', 28... , *): not exist 134 */ 135 /* XXX - <sys/mtio.h> */ 136 /* XXX - <sys/scsiio.h> */ 137 /* XXX - should convert machine dependent ioctl()s */ 138 139 switch (FREEBSD_IOCGROUP(SCARG(uap, com))) { 140 case 'M': 141 freebsd_to_oss(uap, &ap); 142 return oss_ioctl_mixer(l, &ap, retval); 143 case 'Q': 144 freebsd_to_oss(uap, &ap); 145 return oss_ioctl_sequencer(l, &ap, retval); 146 case 'P': 147 freebsd_to_oss(uap, &ap); 148 return oss_ioctl_audio(l, &ap, retval); 149 case 'i': 150 freebsd_to_netbsd_ifioctl(uap, &nap); 151 return sys_ioctl(l, &nap, retval); 152 default: 153 return sys_ioctl(l, uap, retval); 154 } 155 } 156