2 RFCOMM implementation for Linux Bluetooth stack (BlueZ).
3 Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
4 Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21 SOFTWARE IS DISCLAIMED.
28 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/errno.h>
32 #include <linux/kernel.h>
33 #include <linux/sched.h>
34 #include <linux/slab.h>
35 #include <linux/poll.h>
36 #include <linux/fcntl.h>
37 #include <linux/init.h>
38 #include <linux/interrupt.h>
39 #include <linux/socket.h>
40 #include <linux/skbuff.h>
41 #include <linux/list.h>
42 #include <linux/device.h>
43 #include <linux/debugfs.h>
44 #include <linux/seq_file.h>
47 #include <asm/system.h>
48 #include <linux/uaccess.h>
50 #include <net/bluetooth/bluetooth.h>
51 #include <net/bluetooth/hci_core.h>
52 #include <net/bluetooth/l2cap.h>
53 #include <net/bluetooth/rfcomm.h>
55 static const struct proto_ops rfcomm_sock_ops;
57 static struct bt_sock_list rfcomm_sk_list = {
58 .lock = __RW_LOCK_UNLOCKED(rfcomm_sk_list.lock)
61 static void rfcomm_sock_close(struct sock *sk);
62 static void rfcomm_sock_kill(struct sock *sk);
64 /* ---- DLC callbacks ----
66 * called under rfcomm_dlc_lock()
68 static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb)
70 struct sock *sk = d->owner;
74 atomic_add(skb->len, &sk->sk_rmem_alloc);
75 skb_queue_tail(&sk->sk_receive_queue, skb);
76 sk->sk_data_ready(sk, skb->len);
78 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf)
79 rfcomm_dlc_throttle(d);
82 static void rfcomm_sk_state_change(struct rfcomm_dlc *d, int err)
84 struct sock *sk = d->owner, *parent;
90 BT_DBG("dlc %p state %ld err %d", d, d->state, err);
92 local_irq_save(flags);
98 sk->sk_state = d->state;
100 parent = bt_sk(sk)->parent;
102 if (d->state == BT_CLOSED) {
103 sock_set_flag(sk, SOCK_ZAPPED);
104 bt_accept_unlink(sk);
106 parent->sk_data_ready(parent, 0);
108 if (d->state == BT_CONNECTED)
109 rfcomm_session_getaddr(d->session, &bt_sk(sk)->src, NULL);
110 sk->sk_state_change(sk);
114 local_irq_restore(flags);
116 if (parent && sock_flag(sk, SOCK_ZAPPED)) {
117 /* We have to drop DLC lock here, otherwise
118 * rfcomm_sock_destruct() will dead lock. */
119 rfcomm_dlc_unlock(d);
120 rfcomm_sock_kill(sk);
125 /* ---- Socket functions ---- */
126 static struct sock *__rfcomm_get_sock_by_addr(u8 channel, bdaddr_t *src)
128 struct sock *sk = NULL;
129 struct hlist_node *node;
131 sk_for_each(sk, node, &rfcomm_sk_list.head) {
132 if (rfcomm_pi(sk)->channel == channel &&
133 !bacmp(&bt_sk(sk)->src, src))
137 return node ? sk : NULL;
140 /* Find socket with channel and source bdaddr.
141 * Returns closest match.
143 static struct sock *rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t *src)
145 struct sock *sk = NULL, *sk1 = NULL;
146 struct hlist_node *node;
148 read_lock(&rfcomm_sk_list.lock);
150 sk_for_each(sk, node, &rfcomm_sk_list.head) {
151 if (state && sk->sk_state != state)
154 if (rfcomm_pi(sk)->channel == channel) {
156 if (!bacmp(&bt_sk(sk)->src, src))
160 if (!bacmp(&bt_sk(sk)->src, BDADDR_ANY))
165 read_unlock(&rfcomm_sk_list.lock);
167 return node ? sk : sk1;
170 static void rfcomm_sock_destruct(struct sock *sk)
172 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
174 BT_DBG("sk %p dlc %p", sk, d);
176 skb_queue_purge(&sk->sk_receive_queue);
177 skb_queue_purge(&sk->sk_write_queue);
180 rfcomm_pi(sk)->dlc = NULL;
182 /* Detach DLC if it's owned by this socket */
185 rfcomm_dlc_unlock(d);
190 static void rfcomm_sock_cleanup_listen(struct sock *parent)
194 BT_DBG("parent %p", parent);
196 /* Close not yet accepted dlcs */
197 while ((sk = bt_accept_dequeue(parent, NULL))) {
198 rfcomm_sock_close(sk);
199 rfcomm_sock_kill(sk);
202 parent->sk_state = BT_CLOSED;
203 sock_set_flag(parent, SOCK_ZAPPED);
206 /* Kill socket (only if zapped and orphan)
207 * Must be called on unlocked socket.
209 static void rfcomm_sock_kill(struct sock *sk)
211 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket)
214 BT_DBG("sk %p state %d refcnt %d", sk, sk->sk_state, atomic_read(&sk->sk_refcnt));
216 /* Kill poor orphan */
217 bt_sock_unlink(&rfcomm_sk_list, sk);
218 sock_set_flag(sk, SOCK_DEAD);
222 static void __rfcomm_sock_close(struct sock *sk)
224 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
226 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
228 switch (sk->sk_state) {
230 rfcomm_sock_cleanup_listen(sk);
237 rfcomm_dlc_close(d, 0);
240 sock_set_flag(sk, SOCK_ZAPPED);
246 * Must be called on unlocked socket.
248 static void rfcomm_sock_close(struct sock *sk)
251 __rfcomm_sock_close(sk);
255 static void rfcomm_sock_init(struct sock *sk, struct sock *parent)
257 struct rfcomm_pinfo *pi = rfcomm_pi(sk);
262 sk->sk_type = parent->sk_type;
263 pi->dlc->defer_setup = bt_sk(parent)->defer_setup;
265 pi->sec_level = rfcomm_pi(parent)->sec_level;
266 pi->role_switch = rfcomm_pi(parent)->role_switch;
268 pi->dlc->defer_setup = 0;
270 pi->sec_level = BT_SECURITY_LOW;
274 pi->dlc->sec_level = pi->sec_level;
275 pi->dlc->role_switch = pi->role_switch;
278 static struct proto rfcomm_proto = {
280 .owner = THIS_MODULE,
281 .obj_size = sizeof(struct rfcomm_pinfo)
284 static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
286 struct rfcomm_dlc *d;
289 sk = sk_alloc(net, PF_BLUETOOTH, prio, &rfcomm_proto);
293 sock_init_data(sock, sk);
294 INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
296 d = rfcomm_dlc_alloc(prio);
302 d->data_ready = rfcomm_sk_data_ready;
303 d->state_change = rfcomm_sk_state_change;
305 rfcomm_pi(sk)->dlc = d;
308 sk->sk_destruct = rfcomm_sock_destruct;
309 sk->sk_sndtimeo = RFCOMM_CONN_TIMEOUT;
311 sk->sk_sndbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10;
312 sk->sk_rcvbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10;
314 sock_reset_flag(sk, SOCK_ZAPPED);
316 sk->sk_protocol = proto;
317 sk->sk_state = BT_OPEN;
319 bt_sock_link(&rfcomm_sk_list, sk);
325 static int rfcomm_sock_create(struct net *net, struct socket *sock,
326 int protocol, int kern)
330 BT_DBG("sock %p", sock);
332 sock->state = SS_UNCONNECTED;
334 if (sock->type != SOCK_STREAM && sock->type != SOCK_RAW)
335 return -ESOCKTNOSUPPORT;
337 sock->ops = &rfcomm_sock_ops;
339 sk = rfcomm_sock_alloc(net, sock, protocol, GFP_ATOMIC);
343 rfcomm_sock_init(sk, NULL);
347 static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
349 struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
350 struct sock *sk = sock->sk;
353 BT_DBG("sk %p %s", sk, batostr(&sa->rc_bdaddr));
355 if (!addr || addr->sa_family != AF_BLUETOOTH)
360 if (sk->sk_state != BT_OPEN) {
365 if (sk->sk_type != SOCK_STREAM) {
370 write_lock_bh(&rfcomm_sk_list.lock);
372 if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) {
375 /* Save source address */
376 bacpy(&bt_sk(sk)->src, &sa->rc_bdaddr);
377 rfcomm_pi(sk)->channel = sa->rc_channel;
378 sk->sk_state = BT_BOUND;
381 write_unlock_bh(&rfcomm_sk_list.lock);
388 static int rfcomm_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags)
390 struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
391 struct sock *sk = sock->sk;
392 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
397 if (alen < sizeof(struct sockaddr_rc) ||
398 addr->sa_family != AF_BLUETOOTH)
403 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) {
408 if (sk->sk_type != SOCK_STREAM) {
413 sk->sk_state = BT_CONNECT;
414 bacpy(&bt_sk(sk)->dst, &sa->rc_bdaddr);
415 rfcomm_pi(sk)->channel = sa->rc_channel;
417 d->sec_level = rfcomm_pi(sk)->sec_level;
418 d->role_switch = rfcomm_pi(sk)->role_switch;
420 err = rfcomm_dlc_open(d, &bt_sk(sk)->src, &sa->rc_bdaddr, sa->rc_channel);
422 err = bt_sock_wait_state(sk, BT_CONNECTED,
423 sock_sndtimeo(sk, flags & O_NONBLOCK));
430 static int rfcomm_sock_listen(struct socket *sock, int backlog)
432 struct sock *sk = sock->sk;
435 BT_DBG("sk %p backlog %d", sk, backlog);
439 if (sk->sk_state != BT_BOUND) {
444 if (sk->sk_type != SOCK_STREAM) {
449 if (!rfcomm_pi(sk)->channel) {
450 bdaddr_t *src = &bt_sk(sk)->src;
455 write_lock_bh(&rfcomm_sk_list.lock);
457 for (channel = 1; channel < 31; channel++)
458 if (!__rfcomm_get_sock_by_addr(channel, src)) {
459 rfcomm_pi(sk)->channel = channel;
464 write_unlock_bh(&rfcomm_sk_list.lock);
470 sk->sk_max_ack_backlog = backlog;
471 sk->sk_ack_backlog = 0;
472 sk->sk_state = BT_LISTEN;
479 static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags)
481 DECLARE_WAITQUEUE(wait, current);
482 struct sock *sk = sock->sk, *nsk;
488 if (sk->sk_state != BT_LISTEN) {
493 if (sk->sk_type != SOCK_STREAM) {
498 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
500 BT_DBG("sk %p timeo %ld", sk, timeo);
502 /* Wait for an incoming connection. (wake-one). */
503 add_wait_queue_exclusive(sk_sleep(sk), &wait);
504 while (!(nsk = bt_accept_dequeue(sk, newsock))) {
505 set_current_state(TASK_INTERRUPTIBLE);
512 timeo = schedule_timeout(timeo);
515 if (sk->sk_state != BT_LISTEN) {
520 if (signal_pending(current)) {
521 err = sock_intr_errno(timeo);
525 set_current_state(TASK_RUNNING);
526 remove_wait_queue(sk_sleep(sk), &wait);
531 newsock->state = SS_CONNECTED;
533 BT_DBG("new socket %p", nsk);
540 static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *len, int peer)
542 struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
543 struct sock *sk = sock->sk;
545 BT_DBG("sock %p, sk %p", sock, sk);
547 sa->rc_family = AF_BLUETOOTH;
548 sa->rc_channel = rfcomm_pi(sk)->channel;
550 bacpy(&sa->rc_bdaddr, &bt_sk(sk)->dst);
552 bacpy(&sa->rc_bdaddr, &bt_sk(sk)->src);
554 *len = sizeof(struct sockaddr_rc);
558 static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
559 struct msghdr *msg, size_t len)
561 struct sock *sk = sock->sk;
562 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
566 if (test_bit(RFCOMM_DEFER_SETUP, &d->flags))
569 if (msg->msg_flags & MSG_OOB)
572 if (sk->sk_shutdown & SEND_SHUTDOWN)
575 BT_DBG("sock %p, sk %p", sock, sk);
580 size_t size = min_t(size_t, len, d->mtu);
583 skb = sock_alloc_send_skb(sk, size + RFCOMM_SKB_RESERVE,
584 msg->msg_flags & MSG_DONTWAIT, &err);
590 skb_reserve(skb, RFCOMM_SKB_HEAD_RESERVE);
592 err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
600 err = rfcomm_dlc_send(d, skb);
617 static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
618 struct msghdr *msg, size_t size, int flags)
620 struct sock *sk = sock->sk;
621 struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
624 if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) {
625 rfcomm_dlc_accept(d);
629 len = bt_sock_stream_recvmsg(iocb, sock, msg, size, flags);
632 if (!(flags & MSG_PEEK) && len > 0)
633 atomic_sub(len, &sk->sk_rmem_alloc);
635 if (atomic_read(&sk->sk_rmem_alloc) <= (sk->sk_rcvbuf >> 2))
636 rfcomm_dlc_unthrottle(rfcomm_pi(sk)->dlc);
642 static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen)
644 struct sock *sk = sock->sk;
654 if (get_user(opt, (u32 __user *) optval)) {
659 if (opt & RFCOMM_LM_AUTH)
660 rfcomm_pi(sk)->sec_level = BT_SECURITY_LOW;
661 if (opt & RFCOMM_LM_ENCRYPT)
662 rfcomm_pi(sk)->sec_level = BT_SECURITY_MEDIUM;
663 if (opt & RFCOMM_LM_SECURE)
664 rfcomm_pi(sk)->sec_level = BT_SECURITY_HIGH;
666 rfcomm_pi(sk)->role_switch = (opt & RFCOMM_LM_MASTER);
678 static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
680 struct sock *sk = sock->sk;
681 struct bt_security sec;
687 if (level == SOL_RFCOMM)
688 return rfcomm_sock_setsockopt_old(sock, optname, optval, optlen);
690 if (level != SOL_BLUETOOTH)
697 if (sk->sk_type != SOCK_STREAM) {
702 sec.level = BT_SECURITY_LOW;
704 len = min_t(unsigned int, sizeof(sec), optlen);
705 if (copy_from_user((char *) &sec, optval, len)) {
710 if (sec.level > BT_SECURITY_HIGH) {
715 rfcomm_pi(sk)->sec_level = sec.level;
719 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
724 if (get_user(opt, (u32 __user *) optval)) {
729 bt_sk(sk)->defer_setup = opt;
741 static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen)
743 struct sock *sk = sock->sk;
744 struct sock *l2cap_sk;
745 struct rfcomm_conninfo cinfo;
746 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
752 if (get_user(len, optlen))
759 switch (rfcomm_pi(sk)->sec_level) {
760 case BT_SECURITY_LOW:
761 opt = RFCOMM_LM_AUTH;
763 case BT_SECURITY_MEDIUM:
764 opt = RFCOMM_LM_AUTH | RFCOMM_LM_ENCRYPT;
766 case BT_SECURITY_HIGH:
767 opt = RFCOMM_LM_AUTH | RFCOMM_LM_ENCRYPT |
775 if (rfcomm_pi(sk)->role_switch)
776 opt |= RFCOMM_LM_MASTER;
778 if (put_user(opt, (u32 __user *) optval))
782 case RFCOMM_CONNINFO:
783 if (sk->sk_state != BT_CONNECTED &&
784 !rfcomm_pi(sk)->dlc->defer_setup) {
789 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
791 cinfo.hci_handle = conn->hcon->handle;
792 memcpy(cinfo.dev_class, conn->hcon->dev_class, 3);
794 len = min_t(unsigned int, len, sizeof(cinfo));
795 if (copy_to_user(optval, (char *) &cinfo, len))
809 static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen)
811 struct sock *sk = sock->sk;
812 struct bt_security sec;
817 if (level == SOL_RFCOMM)
818 return rfcomm_sock_getsockopt_old(sock, optname, optval, optlen);
820 if (level != SOL_BLUETOOTH)
823 if (get_user(len, optlen))
830 if (sk->sk_type != SOCK_STREAM) {
835 sec.level = rfcomm_pi(sk)->sec_level;
837 len = min_t(unsigned int, len, sizeof(sec));
838 if (copy_to_user(optval, (char *) &sec, len))
844 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
849 if (put_user(bt_sk(sk)->defer_setup, (u32 __user *) optval))
863 static int rfcomm_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
865 struct sock *sk __maybe_unused = sock->sk;
868 BT_DBG("sk %p cmd %x arg %lx", sk, cmd, arg);
870 err = bt_sock_ioctl(sock, cmd, arg);
872 if (err == -ENOIOCTLCMD) {
873 #ifdef CONFIG_BT_RFCOMM_TTY
875 err = rfcomm_dev_ioctl(sk, cmd, (void __user *) arg);
885 static int rfcomm_sock_shutdown(struct socket *sock, int how)
887 struct sock *sk = sock->sk;
890 BT_DBG("sock %p, sk %p", sock, sk);
896 if (!sk->sk_shutdown) {
897 sk->sk_shutdown = SHUTDOWN_MASK;
898 __rfcomm_sock_close(sk);
900 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
901 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
907 static int rfcomm_sock_release(struct socket *sock)
909 struct sock *sk = sock->sk;
912 BT_DBG("sock %p, sk %p", sock, sk);
917 err = rfcomm_sock_shutdown(sock, 2);
920 rfcomm_sock_kill(sk);
924 /* ---- RFCOMM core layer callbacks ----
926 * called under rfcomm_lock()
928 int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc **d)
930 struct sock *sk, *parent;
934 BT_DBG("session %p channel %d", s, channel);
936 rfcomm_session_getaddr(s, &src, &dst);
938 /* Check if we have socket listening on channel */
939 parent = rfcomm_get_sock_by_channel(BT_LISTEN, channel, &src);
943 bh_lock_sock(parent);
945 /* Check for backlog size */
946 if (sk_acceptq_is_full(parent)) {
947 BT_DBG("backlog full %d", parent->sk_ack_backlog);
951 sk = rfcomm_sock_alloc(sock_net(parent), NULL, BTPROTO_RFCOMM, GFP_ATOMIC);
955 rfcomm_sock_init(sk, parent);
956 bacpy(&bt_sk(sk)->src, &src);
957 bacpy(&bt_sk(sk)->dst, &dst);
958 rfcomm_pi(sk)->channel = channel;
960 sk->sk_state = BT_CONFIG;
961 bt_accept_enqueue(parent, sk);
963 /* Accept connection and return socket DLC */
964 *d = rfcomm_pi(sk)->dlc;
968 bh_unlock_sock(parent);
970 if (bt_sk(parent)->defer_setup)
971 parent->sk_state_change(parent);
976 static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p)
979 struct hlist_node *node;
981 read_lock_bh(&rfcomm_sk_list.lock);
983 sk_for_each(sk, node, &rfcomm_sk_list.head) {
984 seq_printf(f, "%s %s %d %d\n",
985 batostr(&bt_sk(sk)->src),
986 batostr(&bt_sk(sk)->dst),
987 sk->sk_state, rfcomm_pi(sk)->channel);
990 read_unlock_bh(&rfcomm_sk_list.lock);
995 static int rfcomm_sock_debugfs_open(struct inode *inode, struct file *file)
997 return single_open(file, rfcomm_sock_debugfs_show, inode->i_private);
1000 static const struct file_operations rfcomm_sock_debugfs_fops = {
1001 .open = rfcomm_sock_debugfs_open,
1003 .llseek = seq_lseek,
1004 .release = single_release,
1007 static struct dentry *rfcomm_sock_debugfs;
1009 static const struct proto_ops rfcomm_sock_ops = {
1010 .family = PF_BLUETOOTH,
1011 .owner = THIS_MODULE,
1012 .release = rfcomm_sock_release,
1013 .bind = rfcomm_sock_bind,
1014 .connect = rfcomm_sock_connect,
1015 .listen = rfcomm_sock_listen,
1016 .accept = rfcomm_sock_accept,
1017 .getname = rfcomm_sock_getname,
1018 .sendmsg = rfcomm_sock_sendmsg,
1019 .recvmsg = rfcomm_sock_recvmsg,
1020 .shutdown = rfcomm_sock_shutdown,
1021 .setsockopt = rfcomm_sock_setsockopt,
1022 .getsockopt = rfcomm_sock_getsockopt,
1023 .ioctl = rfcomm_sock_ioctl,
1024 .poll = bt_sock_poll,
1025 .socketpair = sock_no_socketpair,
1026 .mmap = sock_no_mmap
1029 static const struct net_proto_family rfcomm_sock_family_ops = {
1030 .family = PF_BLUETOOTH,
1031 .owner = THIS_MODULE,
1032 .create = rfcomm_sock_create
1035 int __init rfcomm_init_sockets(void)
1039 err = proto_register(&rfcomm_proto, 0);
1043 err = bt_sock_register(BTPROTO_RFCOMM, &rfcomm_sock_family_ops);
1048 rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444,
1049 bt_debugfs, NULL, &rfcomm_sock_debugfs_fops);
1050 if (!rfcomm_sock_debugfs)
1051 BT_ERR("Failed to create RFCOMM debug file");
1054 BT_INFO("RFCOMM socket layer initialized");
1059 BT_ERR("RFCOMM socket layer registration failed");
1060 proto_unregister(&rfcomm_proto);
1064 void __exit rfcomm_cleanup_sockets(void)
1066 debugfs_remove(rfcomm_sock_debugfs);
1068 if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
1069 BT_ERR("RFCOMM socket layer unregistration failed");
1071 proto_unregister(&rfcomm_proto);