2 BNEP implementation for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2001-2002 Inventel Systemes
5 David Libault <david.libault@inventel.fr>
7 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
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;
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.
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.
28 * $Id: sock.c,v 1.4 2002/08/04 21:23:58 maxk Exp $
31 #include <linux/module.h>
33 #include <linux/types.h>
34 #include <linux/capability.h>
35 #include <linux/errno.h>
36 #include <linux/kernel.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/poll.h>
40 #include <linux/fcntl.h>
41 #include <linux/skbuff.h>
42 #include <linux/socket.h>
43 #include <linux/ioctl.h>
44 #include <linux/file.h>
45 #include <linux/init.h>
46 #include <linux/compat.h>
49 #include <asm/system.h>
50 #include <asm/uaccess.h>
54 #ifndef CONFIG_BT_BNEP_DEBUG
56 #define BT_DBG( A... )
59 static int bnep_sock_release(struct socket
*sock
)
61 struct sock
*sk
= sock
->sk
;
63 BT_DBG("sock %p sk %p", sock
, sk
);
73 static int bnep_sock_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
75 struct bnep_connlist_req cl
;
76 struct bnep_connadd_req ca
;
77 struct bnep_conndel_req cd
;
78 struct bnep_conninfo ci
;
80 void __user
*argp
= (void __user
*)arg
;
83 BT_DBG("cmd %x arg %lx", cmd
, arg
);
87 if (!capable(CAP_NET_ADMIN
))
90 if (copy_from_user(&ca
, argp
, sizeof(ca
)))
93 nsock
= sockfd_lookup(ca
.sock
, &err
);
97 if (nsock
->sk
->sk_state
!= BT_CONNECTED
) {
102 err
= bnep_add_connection(&ca
, nsock
);
104 if (copy_to_user(argp
, &ca
, sizeof(ca
)))
112 if (!capable(CAP_NET_ADMIN
))
115 if (copy_from_user(&cd
, argp
, sizeof(cd
)))
118 return bnep_del_connection(&cd
);
120 case BNEPGETCONNLIST
:
121 if (copy_from_user(&cl
, argp
, sizeof(cl
)))
127 err
= bnep_get_connlist(&cl
);
128 if (!err
&& copy_to_user(argp
, &cl
, sizeof(cl
)))
133 case BNEPGETCONNINFO
:
134 if (copy_from_user(&ci
, argp
, sizeof(ci
)))
137 err
= bnep_get_conninfo(&ci
);
138 if (!err
&& copy_to_user(argp
, &ci
, sizeof(ci
)))
151 static int bnep_sock_compat_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
153 if (cmd
== BNEPGETCONNLIST
) {
154 struct bnep_connlist_req cl
;
158 if (get_user(cl
.cnum
, (uint32_t __user
*) arg
) ||
159 get_user(uci
, (u32 __user
*) (arg
+ 4)))
162 cl
.ci
= compat_ptr(uci
);
167 err
= bnep_get_connlist(&cl
);
169 if (!err
&& put_user(cl
.cnum
, (uint32_t __user
*) arg
))
175 return bnep_sock_ioctl(sock
, cmd
, arg
);
179 static const struct proto_ops bnep_sock_ops
= {
180 .family
= PF_BLUETOOTH
,
181 .owner
= THIS_MODULE
,
182 .release
= bnep_sock_release
,
183 .ioctl
= bnep_sock_ioctl
,
185 .compat_ioctl
= bnep_sock_compat_ioctl
,
187 .bind
= sock_no_bind
,
188 .getname
= sock_no_getname
,
189 .sendmsg
= sock_no_sendmsg
,
190 .recvmsg
= sock_no_recvmsg
,
191 .poll
= sock_no_poll
,
192 .listen
= sock_no_listen
,
193 .shutdown
= sock_no_shutdown
,
194 .setsockopt
= sock_no_setsockopt
,
195 .getsockopt
= sock_no_getsockopt
,
196 .connect
= sock_no_connect
,
197 .socketpair
= sock_no_socketpair
,
198 .accept
= sock_no_accept
,
202 static struct proto bnep_proto
= {
204 .owner
= THIS_MODULE
,
205 .obj_size
= sizeof(struct bt_sock
)
208 static int bnep_sock_create(struct socket
*sock
, int protocol
)
212 BT_DBG("sock %p", sock
);
214 if (sock
->type
!= SOCK_RAW
)
215 return -ESOCKTNOSUPPORT
;
217 sk
= sk_alloc(PF_BLUETOOTH
, GFP_KERNEL
, &bnep_proto
, 1);
221 sock_init_data(sock
, sk
);
223 sock
->ops
= &bnep_sock_ops
;
225 sock
->state
= SS_UNCONNECTED
;
227 sock_reset_flag(sk
, SOCK_ZAPPED
);
229 sk
->sk_protocol
= protocol
;
230 sk
->sk_state
= BT_OPEN
;
235 static struct net_proto_family bnep_sock_family_ops
= {
236 .family
= PF_BLUETOOTH
,
237 .owner
= THIS_MODULE
,
238 .create
= bnep_sock_create
241 int __init
bnep_sock_init(void)
245 err
= proto_register(&bnep_proto
, 0);
249 err
= bt_sock_register(BTPROTO_BNEP
, &bnep_sock_family_ops
);
256 BT_ERR("Can't register BNEP socket");
257 proto_unregister(&bnep_proto
);
261 int __exit
bnep_sock_cleanup(void)
263 if (bt_sock_unregister(BTPROTO_BNEP
) < 0)
264 BT_ERR("Can't unregister BNEP socket");
266 proto_unregister(&bnep_proto
);