Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* ATM ioctl handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) /* 2003 John Levon  <levon@movementarian.org> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/net.h>		/* struct socket, struct proto_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/atm.h>		/* ATM stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/atmdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/atmclip.h>	/* CLIP_*ENCAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/atmarp.h>	/* manifest constants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/sonet.h>	/* for ioctls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/atmsvc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/atmmpc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/atmclip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/atmlec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/ioctls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "resources.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "signaling.h"		/* for WAITING and sigd_attach */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static DEFINE_MUTEX(ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static LIST_HEAD(ioctl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) void register_atm_ioctl(struct atm_ioctl *ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	mutex_lock(&ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	list_add_tail(&ioctl->list, &ioctl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	mutex_unlock(&ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) EXPORT_SYMBOL(register_atm_ioctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) void deregister_atm_ioctl(struct atm_ioctl *ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	mutex_lock(&ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	list_del(&ioctl->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	mutex_unlock(&ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) EXPORT_SYMBOL(deregister_atm_ioctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			unsigned long arg, int compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct atm_vcc *vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct list_head *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	void __user *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int __user *len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	vcc = ATM_SD(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case SIOCOUTQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		if (sock->state != SS_CONNECTED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		    !test_bit(ATM_VF_READY, &vcc->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			error =  -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		error = put_user(sk->sk_sndbuf - sk_wmem_alloc_get(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 				 (int __user *)argp) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	case SIOCINQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (sock->state != SS_CONNECTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		skb = skb_peek(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		error = put_user(skb ? skb->len : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				 (int __user *)argp) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	case ATM_SETSC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		net_warn_ratelimited("ATM_SETSC is obsolete; used by %s:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				     current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	case ATMSIGD_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (!capable(CAP_NET_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		 * The user/kernel protocol for exchanging signalling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		 * info uses kernel pointers as opaque references,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 * so the holder of the file descriptor can scribble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		 * on the kernel... so we should make sure that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 * have the same privileges that /proc/kcore needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (!capable(CAP_SYS_RAWIO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			error = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		/* WTF? I don't even want to _think_ about making this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		   work for 32-bit userspace. TBH I don't really want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		   to think about it at all. dwmw2. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		if (compat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			net_warn_ratelimited("32-bit task cannot be atmsigd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		error = sigd_attach(vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	case ATM_SETBACKEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	case ATM_NEWBACKENDIF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		atm_backend_t backend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		error = get_user(backend, (atm_backend_t __user *)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		switch (backend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		case ATM_BACKEND_PPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			request_module("pppoatm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		case ATM_BACKEND_BR2684:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			request_module("br2684");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case ATMMPC_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	case ATMMPC_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		request_module("mpoa");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	case ATMARPD_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		request_module("clip");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case ATMLEC_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		request_module("lec");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	error = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	mutex_lock(&ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	list_for_each(pos, &ioctl_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		struct atm_ioctl *ic = list_entry(pos, struct atm_ioctl, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if (try_module_get(ic->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			error = ic->ioctl(sock, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			module_put(ic->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			if (error != -ENOIOCTLCMD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	mutex_unlock(&ioctl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (error != -ENOIOCTLCMD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (cmd == ATM_GETNAMES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (IS_ENABLED(CONFIG_COMPAT) && compat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			struct compat_atm_iobuf __user *ciobuf = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			compat_uptr_t cbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			len = &ciobuf->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			if (get_user(cbuf, &ciobuf->buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			buf = compat_ptr(cbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			struct atm_iobuf __user *iobuf = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			len = &iobuf->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			if (get_user(buf, &iobuf->buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		error = atm_getnames(buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		int number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (IS_ENABLED(CONFIG_COMPAT) && compat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			struct compat_atmif_sioc __user *csioc = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			compat_uptr_t carg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			len = &csioc->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			if (get_user(carg, &csioc->arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			buf = compat_ptr(carg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			if (get_user(number, &csioc->number))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			struct atmif_sioc __user *sioc = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			len = &sioc->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			if (get_user(buf, &sioc->arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			if (get_user(number, &sioc->number))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		error = atm_dev_ioctl(cmd, buf, len, number, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return do_vcc_ioctl(sock, cmd, arg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * FIXME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * The compat_ioctl handling is duplicated, using both these conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * routines and the compat argument to the actual handlers. Both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * versions are somewhat incomplete and should be merged, e.g. by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * moving the ioctl number translation into the actual handlers and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * killing the conversion code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * -arnd, November 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #define ATM_GETNAMES32    _IOW('a', ATMIOC_ITF+3, struct compat_atm_iobuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define ATM_GETTYPE32     _IOW('a', ATMIOC_ITF+4, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define ATM_GETESI32	  _IOW('a', ATMIOC_ITF+5, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define ATM_GETADDR32	  _IOW('a', ATMIOC_ITF+6, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #define ATM_RSTADDR32	  _IOW('a', ATMIOC_ITF+7, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define ATM_ADDADDR32	  _IOW('a', ATMIOC_ITF+8, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define ATM_DELADDR32	  _IOW('a', ATMIOC_ITF+9, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define ATM_GETCIRANGE32  _IOW('a', ATMIOC_ITF+10, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define ATM_SETCIRANGE32  _IOW('a', ATMIOC_ITF+11, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define ATM_SETESI32      _IOW('a', ATMIOC_ITF+12, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define ATM_SETESIF32     _IOW('a', ATMIOC_ITF+13, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define ATM_GETSTAT32     _IOW('a', ATMIOC_SARCOM+0, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define ATM_GETSTATZ32    _IOW('a', ATMIOC_SARCOM+1, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define ATM_GETLOOP32	  _IOW('a', ATMIOC_SARCOM+2, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define ATM_SETLOOP32	  _IOW('a', ATMIOC_SARCOM+3, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define ATM_QUERYLOOP32	  _IOW('a', ATMIOC_SARCOM+4, struct compat_atmif_sioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	unsigned int cmd32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	unsigned int cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) } atm_ioctl_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	{ ATM_GETLINKRATE32, ATM_GETLINKRATE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	{ ATM_GETNAMES32,    ATM_GETNAMES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	{ ATM_GETTYPE32,     ATM_GETTYPE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	{ ATM_GETESI32,	     ATM_GETESI },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	{ ATM_GETADDR32,     ATM_GETADDR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	{ ATM_RSTADDR32,     ATM_RSTADDR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	{ ATM_ADDADDR32,     ATM_ADDADDR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	{ ATM_DELADDR32,     ATM_DELADDR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	{ ATM_GETCIRANGE32,  ATM_GETCIRANGE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	{ ATM_SETCIRANGE32,  ATM_SETCIRANGE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	{ ATM_SETESI32,	     ATM_SETESI },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	{ ATM_SETESIF32,     ATM_SETESIF },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	{ ATM_GETSTAT32,     ATM_GETSTAT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	{ ATM_GETSTATZ32,    ATM_GETSTATZ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	{ ATM_GETLOOP32,     ATM_GETLOOP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	{ ATM_SETLOOP32,     ATM_SETLOOP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	{ ATM_QUERYLOOP32,   ATM_QUERYLOOP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int do_atm_iobuf(struct socket *sock, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct compat_atm_iobuf __user *iobuf32 = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (get_user(data, &iobuf32->buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	return atm_getnames(&iobuf32->length, compat_ptr(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static int do_atmif_sioc(struct socket *sock, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			 unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct compat_atmif_sioc __user *sioc32 = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	int number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (get_user(data, &sioc32->arg) || get_user(number, &sioc32->number))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return atm_dev_ioctl(cmd, compat_ptr(data), &sioc32->length, number, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int do_atm_ioctl(struct socket *sock, unsigned int cmd32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	unsigned int cmd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	switch (cmd32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	case SONET_GETSTAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	case SONET_GETSTATZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	case SONET_GETDIAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	case SONET_SETDIAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	case SONET_CLRDIAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	case SONET_SETFRAMING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	case SONET_GETFRAMING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	case SONET_GETFRSENSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		return do_atmif_sioc(sock, cmd32, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	for (i = 0; i < NR_ATM_IOCTL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		if (cmd32 == atm_ioctl_map[i].cmd32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			cmd = atm_ioctl_map[i].cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (i == NR_ATM_IOCTL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	case ATM_GETNAMES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return do_atm_iobuf(sock, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	case ATM_GETLINKRATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	case ATM_GETTYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	case ATM_GETESI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	case ATM_GETADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	case ATM_RSTADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	case ATM_ADDADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	case ATM_DELADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	case ATM_GETCIRANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	case ATM_SETCIRANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	case ATM_SETESI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	case ATM_SETESIF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	case ATM_GETSTAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	case ATM_GETSTATZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	case ATM_GETLOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	case ATM_SETLOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	case ATM_QUERYLOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return do_atmif_sioc(sock, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int vcc_compat_ioctl(struct socket *sock, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		     unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	ret = do_vcc_ioctl(sock, cmd, arg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (ret != -ENOIOCTLCMD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	return do_atm_ioctl(sock, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #endif