aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/bnep/sock.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/bluetooth/bnep/sock.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/bluetooth/bnep/sock.c')
-rw-r--r--net/bluetooth/bnep/sock.c237
1 files changed, 237 insertions, 0 deletions
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
new file mode 100644
index 000000000000..9a8d99a39b6d
--- /dev/null
+++ b/net/bluetooth/bnep/sock.c
@@ -0,0 +1,237 @@
1/*
2 BNEP implementation for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2001-2002 Inventel Systemes
4 Written 2001-2002 by
5 David Libault <david.libault@inventel.fr>
6
7 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation;
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
16 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
17 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
18 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
24 SOFTWARE IS DISCLAIMED.
25*/
26
27/*
28 * $Id: sock.c,v 1.4 2002/08/04 21:23:58 maxk Exp $
29 */
30
31#include <linux/config.h>
32#include <linux/module.h>
33
34#include <linux/types.h>
35#include <linux/errno.h>
36#include <linux/kernel.h>
37#include <linux/major.h>
38#include <linux/sched.h>
39#include <linux/slab.h>
40#include <linux/poll.h>
41#include <linux/fcntl.h>
42#include <linux/skbuff.h>
43#include <linux/socket.h>
44#include <linux/ioctl.h>
45#include <linux/file.h>
46#include <linux/init.h>
47#include <net/sock.h>
48
49#include <asm/system.h>
50#include <asm/uaccess.h>
51
52#include "bnep.h"
53
54#ifndef CONFIG_BT_BNEP_DEBUG
55#undef BT_DBG
56#define BT_DBG( A... )
57#endif
58
59static int bnep_sock_release(struct socket *sock)
60{
61 struct sock *sk = sock->sk;
62
63 BT_DBG("sock %p sk %p", sock, sk);
64
65 if (!sk)
66 return 0;
67
68 sock_orphan(sk);
69 sock_put(sk);
70 return 0;
71}
72
73static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
74{
75 struct bnep_connlist_req cl;
76 struct bnep_connadd_req ca;
77 struct bnep_conndel_req cd;
78 struct bnep_conninfo ci;
79 struct socket *nsock;
80 void __user *argp = (void __user *)arg;
81 int err;
82
83 BT_DBG("cmd %x arg %lx", cmd, arg);
84
85 switch (cmd) {
86 case BNEPCONNADD:
87 if (!capable(CAP_NET_ADMIN))
88 return -EACCES;
89
90 if (copy_from_user(&ca, argp, sizeof(ca)))
91 return -EFAULT;
92
93 nsock = sockfd_lookup(ca.sock, &err);
94 if (!nsock)
95 return err;
96
97 if (nsock->sk->sk_state != BT_CONNECTED) {
98 fput(nsock->file);
99 return -EBADFD;
100 }
101
102 err = bnep_add_connection(&ca, nsock);
103 if (!err) {
104 if (copy_to_user(argp, &ca, sizeof(ca)))
105 err = -EFAULT;
106 } else
107 fput(nsock->file);
108
109 return err;
110
111 case BNEPCONNDEL:
112 if (!capable(CAP_NET_ADMIN))
113 return -EACCES;
114
115 if (copy_from_user(&cd, argp, sizeof(cd)))
116 return -EFAULT;
117
118 return bnep_del_connection(&cd);
119
120 case BNEPGETCONNLIST:
121 if (copy_from_user(&cl, argp, sizeof(cl)))
122 return -EFAULT;
123
124 if (cl.cnum <= 0)
125 return -EINVAL;
126
127 err = bnep_get_connlist(&cl);
128 if (!err && copy_to_user(argp, &cl, sizeof(cl)))
129 return -EFAULT;
130
131 return err;
132
133 case BNEPGETCONNINFO:
134 if (copy_from_user(&ci, argp, sizeof(ci)))
135 return -EFAULT;
136
137 err = bnep_get_conninfo(&ci);
138 if (!err && copy_to_user(argp, &ci, sizeof(ci)))
139 return -EFAULT;
140
141 return err;
142
143 default:
144 return -EINVAL;
145 }
146
147 return 0;
148}
149
150static struct proto_ops bnep_sock_ops = {
151 .family = PF_BLUETOOTH,
152 .owner = THIS_MODULE,
153 .release = bnep_sock_release,
154 .ioctl = bnep_sock_ioctl,
155 .bind = sock_no_bind,
156 .getname = sock_no_getname,
157 .sendmsg = sock_no_sendmsg,
158 .recvmsg = sock_no_recvmsg,
159 .poll = sock_no_poll,
160 .listen = sock_no_listen,
161 .shutdown = sock_no_shutdown,
162 .setsockopt = sock_no_setsockopt,
163 .getsockopt = sock_no_getsockopt,
164 .connect = sock_no_connect,
165 .socketpair = sock_no_socketpair,
166 .accept = sock_no_accept,
167 .mmap = sock_no_mmap
168};
169
170static struct proto bnep_proto = {
171 .name = "BNEP",
172 .owner = THIS_MODULE,
173 .obj_size = sizeof(struct bt_sock)
174};
175
176static int bnep_sock_create(struct socket *sock, int protocol)
177{
178 struct sock *sk;
179
180 BT_DBG("sock %p", sock);
181
182 if (sock->type != SOCK_RAW)
183 return -ESOCKTNOSUPPORT;
184
185 sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, &bnep_proto, 1);
186 if (!sk)
187 return -ENOMEM;
188
189 sock_init_data(sock, sk);
190
191 sock->ops = &bnep_sock_ops;
192
193 sock->state = SS_UNCONNECTED;
194
195 sock_reset_flag(sk, SOCK_ZAPPED);
196
197 sk->sk_protocol = protocol;
198 sk->sk_state = BT_OPEN;
199
200 return 0;
201}
202
203static struct net_proto_family bnep_sock_family_ops = {
204 .family = PF_BLUETOOTH,
205 .owner = THIS_MODULE,
206 .create = bnep_sock_create
207};
208
209int __init bnep_sock_init(void)
210{
211 int err;
212
213 err = proto_register(&bnep_proto, 0);
214 if (err < 0)
215 return err;
216
217 err = bt_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops);
218 if (err < 0)
219 goto error;
220
221 return 0;
222
223error:
224 BT_ERR("Can't register BNEP socket");
225 proto_unregister(&bnep_proto);
226 return err;
227}
228
229int __exit bnep_sock_cleanup(void)
230{
231 if (bt_sock_unregister(BTPROTO_BNEP) < 0)
232 BT_ERR("Can't unregister BNEP socket");
233
234 proto_unregister(&bnep_proto);
235
236 return 0;
237}