aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel/sunos_ioctl32.c
blob: 3f619ead22cc89a70ed5905e782a041153626463 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* $Id: sunos_ioctl32.c,v 1.11 2000/07/30 23:12:24 davem Exp $
 * sunos_ioctl32.c: SunOS ioctl compatibility on sparc64.
 *
 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
 * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
 */

#include <asm/uaccess.h>

#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/termios.h>
#include <linux/ioctl.h>
#include <linux/route.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/mm.h>
#include <linux/smp.h>
#include <linux/smp_lock.h>
#include <linux/syscalls.h>
#include <linux/compat.h>

#define SUNOS_NR_OPEN	256

struct rtentry32 {
        u32   		rt_pad1;
        struct sockaddr rt_dst;         /* target address               */
        struct sockaddr rt_gateway;     /* gateway addr (RTF_GATEWAY)   */
        struct sockaddr rt_genmask;     /* target network mask (IP)     */
        unsigned short  rt_flags;
        short           rt_pad2;
        u32   		rt_pad3;
        unsigned char   rt_tos;
        unsigned char   rt_class;
        short           rt_pad4;
        short           rt_metric;      /* +1 for binary compatibility! */
        /* char * */ u32 rt_dev;        /* forcing the device at add    */
        u32   		rt_mtu;         /* per route MTU/Window         */
        u32   		rt_window;      /* Window clamping              */
        unsigned short  rt_irtt;        /* Initial RTT                  */

};

struct ifmap32 {
	u32 mem_start;
	u32 mem_end;
	unsigned short base_addr;
	unsigned char irq;
	unsigned char dma;
	unsigned char port;
};

struct ifreq32 {
#define IFHWADDRLEN     6
#define IFNAMSIZ        16
        union {
                char    ifrn_name[IFNAMSIZ];            /* if name, e.g. "en0" */
        } ifr_ifrn;
        union {
                struct  sockaddr ifru_addr;
                struct  sockaddr ifru_dstaddr;
                struct  sockaddr ifru_broadaddr;
                struct  sockaddr ifru_netmask;
                struct  sockaddr ifru_hwaddr;
                short   ifru_flags;
                int     ifru_ivalue;
                int     ifru_mtu;
                struct  ifmap32 ifru_map;
                char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
                compat_caddr_t ifru_data;
        } ifr_ifru;
};

struct ifconf32 {
        int     ifc_len;                        /* size of buffer       */
        compat_caddr_t  ifcbuf;
};

extern asmlinkage int compat_sys_ioctl(unsigned int, unsigned int, u32);

asmlinkage int sunos_ioctl (int fd, u32 cmd, u32 arg)
{
	int ret = -EBADF;

	if(fd >= SUNOS_NR_OPEN)
		goto out;
	if(!fcheck(fd))
		goto out;

	if(cmd == TIOCSETD) {
		mm_segment_t old_fs = get_fs();
		int __user *p;
		int ntty = N_TTY;
		int tmp;

		p = (int __user *) (unsigned long) arg;
		ret = -EFAULT;
		if(get_user(tmp, p))
			goto out;
		if(tmp == 2) {
			set_fs(KERNEL_DS);
			ret = sys_ioctl(fd, cmd, (unsigned long) &ntty);
			set_fs(old_fs);
			ret = (ret == -EINVAL ? -EOPNOTSUPP : ret);
			goto out;
		}
	}
	if(cmd == TIOCNOTTY) {
		ret = sys_setsid();
		goto out;
	}
	switch(cmd) {
	case _IOW('r', 10, struct rtentry32):
		ret = compat_sys_ioctl(fd, SIOCADDRT, arg);
		goto out;
	case _IOW('r', 11, struct rtentry32):
		ret = compat_sys_ioctl(fd, SIOCDELRT, arg);
		goto out;

	case _IOW('i', 12, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFADDR, arg);
		goto out;
	case _IOWR('i', 13, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFADDR, arg);
		goto out;
	case _IOW('i', 14, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFDSTADDR, arg);
		goto out;
	case _IOWR('i', 15, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFDSTADDR, arg);
		goto out;
	case _IOW('i', 16, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFFLAGS, arg);
		goto out;
	case _IOWR('i', 17, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFFLAGS, arg);
		goto out;
	case _IOW('i', 18, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFMEM, arg);
		goto out;
	case _IOWR('i', 19, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFMEM, arg);
		goto out;

	case _IOWR('i', 20, struct ifconf32):
		ret = compat_sys_ioctl(fd, SIOCGIFCONF, arg);
		goto out;

	case _IOW('i', 21, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFMTU, arg);
		goto out;

	case _IOWR('i', 22, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFMTU, arg);
		goto out;

	case _IOWR('i', 23, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFBRDADDR, arg);
		goto out;
	case _IOW('i', 24, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFBRDADDR, arg);
		goto out;
	case _IOWR('i', 25, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFNETMASK, arg);
		goto out;
	case _IOW('i', 26, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFNETMASK, arg);
		goto out;
	case _IOWR('i', 27, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCGIFMETRIC, arg);
		goto out;
	case _IOW('i', 28, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCSIFMETRIC, arg);
		goto out;

	case _IOW('i', 30, struct arpreq):
		ret = compat_sys_ioctl(fd, SIOCSARP, arg);
		goto out;
	case _IOWR('i', 31, struct arpreq):
		ret = compat_sys_ioctl(fd, SIOCGARP, arg);
		goto out;
	case _IOW('i', 32, struct arpreq):
		ret = compat_sys_ioctl(fd, SIOCDARP, arg);
		goto out;

	case _IOW('i', 40, struct ifreq32): /* SIOCUPPER */
	case _IOW('i', 41, struct ifreq32): /* SIOCLOWER */
	case _IOW('i', 44, struct ifreq32): /* SIOCSETSYNC */
	case _IOW('i', 45, struct ifreq32): /* SIOCGETSYNC */
	case _IOW('i', 46, struct ifreq32): /* SIOCSSDSTATS */
	case _IOW('i', 47, struct ifreq32): /* SIOCSSESTATS */
	case _IOW('i', 48, struct ifreq32): /* SIOCSPROMISC */
		ret = -EOPNOTSUPP;
		goto out;

	case _IOW('i', 49, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCADDMULTI, arg);
		goto out;
	case _IOW('i', 50, struct ifreq32):
		ret = compat_sys_ioctl(fd, SIOCDELMULTI, arg);
		goto out;

	/* FDDI interface ioctls, unsupported. */
		
	case _IOW('i', 51, struct ifreq32): /* SIOCFDRESET */
	case _IOW('i', 52, struct ifreq32): /* SIOCFDSLEEP */
	case _IOW('i', 53, struct ifreq32): /* SIOCSTRTFMWAR */
	case _IOW('i', 54, struct ifreq32): /* SIOCLDNSTRTFW */
	case _IOW('i', 55, struct ifreq32): /* SIOCGETFDSTAT */
	case _IOW('i', 56, struct ifreq32): /* SIOCFDNMIINT */
	case _IOW('i', 57, struct ifreq32): /* SIOCFDEXUSER */
	case _IOW('i', 58, struct ifreq32): /* SIOCFDGNETMAP */
	case _IOW('i', 59, struct ifreq32): /* SIOCFDGIOCTL */
		printk("FDDI ioctl, returning EOPNOTSUPP\n");
		ret = -EOPNOTSUPP;
		goto out;

	case _IOW('t', 125, int):
		/* More stupid tty sunos ioctls, just
		 * say it worked.
		 */
		ret = 0;
		goto out;

	/* Non posix grp */
	case _IOW('t', 118, int): {
		int oldval, newval, __user *ptr;

		cmd = TIOCSPGRP;
		ptr = (int __user *) (unsigned long) arg;
		ret = -EFAULT;
		if(get_user(oldval, ptr))
			goto out;
		ret = compat_sys_ioctl(fd, cmd, arg);
		__get_user(newval, ptr);
		if(newval == -1) {
			__put_user(oldval, ptr);
			ret = -EIO;
		}
		if(ret == -ENOTTY)
			ret = -EIO;
		goto out;
	}

	case _IOR('t', 119, int): {
		int oldval, newval, __user *ptr;

		cmd = TIOCGPGRP;
		ptr = (int __user *) (unsigned long) arg;
		ret = -EFAULT;
		if(get_user(oldval, ptr))
			goto out;
		ret = compat_sys_ioctl(fd, cmd, arg);
		__get_user(newval, ptr);
		if(newval == -1) {
			__put_user(oldval, ptr);
			ret = -EIO;
		}
		if(ret == -ENOTTY)
			ret = -EIO;
		goto out;
	}
	};

	ret = compat_sys_ioctl(fd, cmd, arg);
	/* so stupid... */
	ret = (ret == -EINVAL ? -EOPNOTSUPP : ret);
out:
	return ret;
}