1 /* $NetBSD: freebsd_ioctl.c,v 1.5 2000/12/01 12:28:31 jdolecek 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/param.h> 35 #include <sys/systm.h> 36 #include <sys/proc.h> 37 #include <sys/mount.h> 38 #include <sys/sockio.h> 39 40 #include <sys/syscallargs.h> 41 42 #include <net/if.h> 43 44 #include <compat/freebsd/freebsd_syscallargs.h> 45 #include <compat/common/compat_util.h> 46 #include <compat/freebsd/freebsd_ioctl.h> 47 48 #include <compat/ossaudio/ossaudio.h> 49 #include <compat/ossaudio/ossaudiovar.h> 50 51 /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */ 52 static void freebsd_to_oss(struct freebsd_sys_ioctl_args *, 53 struct oss_sys_ioctl_args *); 54 55 static void 56 freebsd_to_oss(uap, rap) 57 struct freebsd_sys_ioctl_args *uap; 58 struct oss_sys_ioctl_args *rap; 59 { 60 u_long ocmd, ncmd; 61 62 ocmd = SCARG(uap, com); 63 ncmd = ocmd &~ FREEBSD_IOC_DIRMASK; 64 switch(ocmd & FREEBSD_IOC_DIRMASK) { 65 case FREEBSD_IOC_VOID: ncmd |= OSS_IOC_VOID; break; 66 case FREEBSD_IOC_OUT: ncmd |= OSS_IOC_OUT; break; 67 case FREEBSD_IOC_IN: ncmd |= OSS_IOC_IN; break; 68 case FREEBSD_IOC_INOUT: ncmd |= OSS_IOC_INOUT; break; 69 } 70 SCARG(rap, fd) = SCARG(uap, fd); 71 SCARG(rap, com) = ncmd; 72 SCARG(rap, data) = SCARG(uap, data); 73 } 74 75 76 static void freebsd_to_netbsd_ifioctl(struct freebsd_sys_ioctl_args *uap, 77 struct sys_ioctl_args *nap); 78 79 static void 80 freebsd_to_netbsd_ifioctl(uap, nap) 81 struct freebsd_sys_ioctl_args *uap; 82 struct sys_ioctl_args *nap; 83 { 84 u_long ocmd, ncmd; 85 ocmd = SCARG(uap, com); 86 switch (ocmd) { 87 case FREEBSD_SIOCALIFADDR: 88 ncmd =SIOCALIFADDR; 89 break; 90 case FREEBSD_SIOCGLIFADDR: 91 ncmd =SIOCGLIFADDR; 92 break; 93 case FREEBSD_SIOCDLIFADDR: 94 ncmd =SIOCDLIFADDR; 95 break; 96 case FREEBSD_SIOCGIFMTU: 97 ncmd = SIOCGIFMTU; 98 break; 99 case FREEBSD_SIOCSIFMTU: 100 ncmd = SIOCSIFMTU; 101 break; 102 default: 103 ncmd = ocmd; 104 break; 105 } 106 SCARG(nap, fd) = SCARG(uap, fd); 107 SCARG(nap, com) = ncmd; 108 SCARG(nap, data) = SCARG(uap, data); 109 } 110 111 int 112 freebsd_sys_ioctl(p, v, retval) 113 struct proc *p; 114 void *v; 115 register_t *retval; 116 { 117 struct freebsd_sys_ioctl_args /* { 118 syscallarg(int) fd; 119 syscallarg(u_long) com; 120 syscallarg(caddr_t) data; 121 } */ *uap = v; 122 struct oss_sys_ioctl_args ap; 123 struct sys_ioctl_args nap; 124 125 /* 126 * XXX - <sys/cdio.h>'s incompatibility 127 * _IO('c', 25..27, *): incompatible 128 * _IO('c', 28... , *): not exist 129 */ 130 /* XXX - <sys/mtio.h> */ 131 /* XXX - <sys/scsiio.h> */ 132 /* XXX - should convert machine dependent ioctl()s */ 133 134 switch (FREEBSD_IOCGROUP(SCARG(uap, com))) { 135 case 'M': 136 freebsd_to_oss(uap, &ap); 137 return oss_ioctl_mixer(p, &ap, retval); 138 case 'Q': 139 freebsd_to_oss(uap, &ap); 140 return oss_ioctl_sequencer(p, &ap, retval); 141 case 'P': 142 freebsd_to_oss(uap, &ap); 143 return oss_ioctl_audio(p, &ap, retval); 144 case 'i': 145 freebsd_to_netbsd_ifioctl(uap, &nap); 146 return sys_ioctl(p, &nap, retval); 147 default: 148 return sys_ioctl(p, uap, retval); 149 } 150 } 151