YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 5 | |
| 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; |
| 9 | |
| 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 |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 19 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 20 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | SOFTWARE IS DISCLAIMED. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * RFCOMM sockets. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
Gustavo Padovan | 8c520a5 | 2012-05-23 04:04:22 -0300 | [diff] [blame] | 28 | #include <linux/export.h> |
Marcel Holtmann | aef7d97 | 2010-03-21 05:27:45 +0100 | [diff] [blame] | 29 | #include <linux/debugfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <net/bluetooth/bluetooth.h> |
| 32 | #include <net/bluetooth/hci_core.h> |
| 33 | #include <net/bluetooth/l2cap.h> |
| 34 | #include <net/bluetooth/rfcomm.h> |
| 35 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 36 | static const struct proto_ops rfcomm_sock_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | static struct bt_sock_list rfcomm_sk_list = { |
Robert P. J. Day | d5fb296 | 2008-03-28 16:17:38 -0700 | [diff] [blame] | 39 | .lock = __RW_LOCK_UNLOCKED(rfcomm_sk_list.lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | static void rfcomm_sock_close(struct sock *sk); |
| 43 | static void rfcomm_sock_kill(struct sock *sk); |
| 44 | |
| 45 | /* ---- DLC callbacks ---- |
| 46 | * |
| 47 | * called under rfcomm_dlc_lock() |
| 48 | */ |
| 49 | static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb) |
| 50 | { |
| 51 | struct sock *sk = d->owner; |
| 52 | if (!sk) |
| 53 | return; |
| 54 | |
| 55 | atomic_add(skb->len, &sk->sk_rmem_alloc); |
| 56 | skb_queue_tail(&sk->sk_receive_queue, skb); |
| 57 | sk->sk_data_ready(sk, skb->len); |
| 58 | |
| 59 | if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) |
| 60 | rfcomm_dlc_throttle(d); |
| 61 | } |
| 62 | |
| 63 | static void rfcomm_sk_state_change(struct rfcomm_dlc *d, int err) |
| 64 | { |
| 65 | struct sock *sk = d->owner, *parent; |
Gustavo F. Padovan | fad003b | 2010-08-14 00:48:07 -0300 | [diff] [blame] | 66 | unsigned long flags; |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | if (!sk) |
| 69 | return; |
| 70 | |
| 71 | BT_DBG("dlc %p state %ld err %d", d, d->state, err); |
| 72 | |
Gustavo F. Padovan | fad003b | 2010-08-14 00:48:07 -0300 | [diff] [blame] | 73 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | bh_lock_sock(sk); |
| 75 | |
| 76 | if (err) |
| 77 | sk->sk_err = err; |
| 78 | |
| 79 | sk->sk_state = d->state; |
| 80 | |
| 81 | parent = bt_sk(sk)->parent; |
| 82 | if (parent) { |
| 83 | if (d->state == BT_CLOSED) { |
| 84 | sock_set_flag(sk, SOCK_ZAPPED); |
| 85 | bt_accept_unlink(sk); |
| 86 | } |
| 87 | parent->sk_data_ready(parent, 0); |
| 88 | } else { |
| 89 | if (d->state == BT_CONNECTED) |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 90 | rfcomm_session_getaddr(d->session, |
| 91 | &rfcomm_pi(sk)->src, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | sk->sk_state_change(sk); |
| 93 | } |
| 94 | |
| 95 | bh_unlock_sock(sk); |
Gustavo F. Padovan | fad003b | 2010-08-14 00:48:07 -0300 | [diff] [blame] | 96 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | if (parent && sock_flag(sk, SOCK_ZAPPED)) { |
| 99 | /* We have to drop DLC lock here, otherwise |
| 100 | * rfcomm_sock_destruct() will dead lock. */ |
| 101 | rfcomm_dlc_unlock(d); |
| 102 | rfcomm_sock_kill(sk); |
| 103 | rfcomm_dlc_lock(d); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* ---- Socket functions ---- */ |
| 108 | static struct sock *__rfcomm_get_sock_by_addr(u8 channel, bdaddr_t *src) |
| 109 | { |
| 110 | struct sock *sk = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 112 | sk_for_each(sk, &rfcomm_sk_list.head) { |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 113 | if (rfcomm_pi(sk)->channel == channel && |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 114 | !bacmp(&rfcomm_pi(sk)->src, src)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 118 | return sk ? sk : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /* Find socket with channel and source bdaddr. |
| 122 | * Returns closest match. |
| 123 | */ |
Gustavo F. Padovan | eeb3665 | 2010-11-01 18:43:53 +0000 | [diff] [blame] | 124 | static struct sock *rfcomm_get_sock_by_channel(int state, u8 channel, bdaddr_t *src) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
| 126 | struct sock *sk = NULL, *sk1 = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Gustavo F. Padovan | eeb3665 | 2010-11-01 18:43:53 +0000 | [diff] [blame] | 128 | read_lock(&rfcomm_sk_list.lock); |
| 129 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 130 | sk_for_each(sk, &rfcomm_sk_list.head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | if (state && sk->sk_state != state) |
| 132 | continue; |
| 133 | |
| 134 | if (rfcomm_pi(sk)->channel == channel) { |
| 135 | /* Exact match. */ |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 136 | if (!bacmp(&rfcomm_pi(sk)->src, src)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | break; |
| 138 | |
| 139 | /* Closest match */ |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 140 | if (!bacmp(&rfcomm_pi(sk)->src, BDADDR_ANY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | sk1 = sk; |
| 142 | } |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | read_unlock(&rfcomm_sk_list.lock); |
Gustavo F. Padovan | eeb3665 | 2010-11-01 18:43:53 +0000 | [diff] [blame] | 146 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 147 | return sk ? sk : sk1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static void rfcomm_sock_destruct(struct sock *sk) |
| 151 | { |
| 152 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; |
| 153 | |
| 154 | BT_DBG("sk %p dlc %p", sk, d); |
| 155 | |
| 156 | skb_queue_purge(&sk->sk_receive_queue); |
| 157 | skb_queue_purge(&sk->sk_write_queue); |
| 158 | |
| 159 | rfcomm_dlc_lock(d); |
| 160 | rfcomm_pi(sk)->dlc = NULL; |
| 161 | |
| 162 | /* Detach DLC if it's owned by this socket */ |
| 163 | if (d->owner == sk) |
| 164 | d->owner = NULL; |
| 165 | rfcomm_dlc_unlock(d); |
| 166 | |
| 167 | rfcomm_dlc_put(d); |
| 168 | } |
| 169 | |
| 170 | static void rfcomm_sock_cleanup_listen(struct sock *parent) |
| 171 | { |
| 172 | struct sock *sk; |
| 173 | |
| 174 | BT_DBG("parent %p", parent); |
| 175 | |
| 176 | /* Close not yet accepted dlcs */ |
| 177 | while ((sk = bt_accept_dequeue(parent, NULL))) { |
| 178 | rfcomm_sock_close(sk); |
| 179 | rfcomm_sock_kill(sk); |
| 180 | } |
| 181 | |
| 182 | parent->sk_state = BT_CLOSED; |
| 183 | sock_set_flag(parent, SOCK_ZAPPED); |
| 184 | } |
| 185 | |
| 186 | /* Kill socket (only if zapped and orphan) |
| 187 | * Must be called on unlocked socket. |
| 188 | */ |
| 189 | static void rfcomm_sock_kill(struct sock *sk) |
| 190 | { |
| 191 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
| 192 | return; |
| 193 | |
| 194 | BT_DBG("sk %p state %d refcnt %d", sk, sk->sk_state, atomic_read(&sk->sk_refcnt)); |
| 195 | |
| 196 | /* Kill poor orphan */ |
| 197 | bt_sock_unlink(&rfcomm_sk_list, sk); |
| 198 | sock_set_flag(sk, SOCK_DEAD); |
| 199 | sock_put(sk); |
| 200 | } |
| 201 | |
| 202 | static void __rfcomm_sock_close(struct sock *sk) |
| 203 | { |
| 204 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; |
| 205 | |
| 206 | BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket); |
| 207 | |
| 208 | switch (sk->sk_state) { |
| 209 | case BT_LISTEN: |
| 210 | rfcomm_sock_cleanup_listen(sk); |
| 211 | break; |
| 212 | |
| 213 | case BT_CONNECT: |
| 214 | case BT_CONNECT2: |
| 215 | case BT_CONFIG: |
| 216 | case BT_CONNECTED: |
| 217 | rfcomm_dlc_close(d, 0); |
| 218 | |
| 219 | default: |
| 220 | sock_set_flag(sk, SOCK_ZAPPED); |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /* Close socket. |
| 226 | * Must be called on unlocked socket. |
| 227 | */ |
| 228 | static void rfcomm_sock_close(struct sock *sk) |
| 229 | { |
| 230 | lock_sock(sk); |
| 231 | __rfcomm_sock_close(sk); |
| 232 | release_sock(sk); |
| 233 | } |
| 234 | |
| 235 | static void rfcomm_sock_init(struct sock *sk, struct sock *parent) |
| 236 | { |
| 237 | struct rfcomm_pinfo *pi = rfcomm_pi(sk); |
| 238 | |
| 239 | BT_DBG("sk %p", sk); |
| 240 | |
| 241 | if (parent) { |
| 242 | sk->sk_type = parent->sk_type; |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 243 | pi->dlc->defer_setup = test_bit(BT_SK_DEFER_SETUP, |
| 244 | &bt_sk(parent)->flags); |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 245 | |
| 246 | pi->sec_level = rfcomm_pi(parent)->sec_level; |
| 247 | pi->role_switch = rfcomm_pi(parent)->role_switch; |
Paul Moore | 6230c9b | 2011-10-07 09:40:59 +0000 | [diff] [blame] | 248 | |
| 249 | security_sk_clone(parent, sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } else { |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 251 | pi->dlc->defer_setup = 0; |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 252 | |
| 253 | pi->sec_level = BT_SECURITY_LOW; |
| 254 | pi->role_switch = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 257 | pi->dlc->sec_level = pi->sec_level; |
| 258 | pi->dlc->role_switch = pi->role_switch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static struct proto rfcomm_proto = { |
| 262 | .name = "RFCOMM", |
| 263 | .owner = THIS_MODULE, |
| 264 | .obj_size = sizeof(struct rfcomm_pinfo) |
| 265 | }; |
| 266 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 267 | static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
| 269 | struct rfcomm_dlc *d; |
| 270 | struct sock *sk; |
| 271 | |
Pavel Emelyanov | 6257ff2 | 2007-11-01 00:39:31 -0700 | [diff] [blame] | 272 | sk = sk_alloc(net, PF_BLUETOOTH, prio, &rfcomm_proto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (!sk) |
| 274 | return NULL; |
| 275 | |
| 276 | sock_init_data(sock, sk); |
| 277 | INIT_LIST_HEAD(&bt_sk(sk)->accept_q); |
| 278 | |
| 279 | d = rfcomm_dlc_alloc(prio); |
| 280 | if (!d) { |
| 281 | sk_free(sk); |
| 282 | return NULL; |
| 283 | } |
| 284 | |
| 285 | d->data_ready = rfcomm_sk_data_ready; |
| 286 | d->state_change = rfcomm_sk_state_change; |
| 287 | |
| 288 | rfcomm_pi(sk)->dlc = d; |
| 289 | d->owner = sk; |
| 290 | |
| 291 | sk->sk_destruct = rfcomm_sock_destruct; |
| 292 | sk->sk_sndtimeo = RFCOMM_CONN_TIMEOUT; |
| 293 | |
Marcel Holtmann | 77db198 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 294 | sk->sk_sndbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10; |
| 295 | sk->sk_rcvbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 298 | |
| 299 | sk->sk_protocol = proto; |
Marcel Holtmann | 77db198 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 300 | sk->sk_state = BT_OPEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | bt_sock_link(&rfcomm_sk_list, sk); |
| 303 | |
| 304 | BT_DBG("sk %p", sk); |
| 305 | return sk; |
| 306 | } |
| 307 | |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 308 | static int rfcomm_sock_create(struct net *net, struct socket *sock, |
| 309 | int protocol, int kern) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
| 311 | struct sock *sk; |
| 312 | |
| 313 | BT_DBG("sock %p", sock); |
| 314 | |
| 315 | sock->state = SS_UNCONNECTED; |
| 316 | |
| 317 | if (sock->type != SOCK_STREAM && sock->type != SOCK_RAW) |
| 318 | return -ESOCKTNOSUPPORT; |
| 319 | |
| 320 | sock->ops = &rfcomm_sock_ops; |
| 321 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 322 | sk = rfcomm_sock_alloc(net, sock, protocol, GFP_ATOMIC); |
Marcel Holtmann | 74da626 | 2006-10-15 17:31:14 +0200 | [diff] [blame] | 323 | if (!sk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return -ENOMEM; |
| 325 | |
| 326 | rfcomm_sock_init(sk, NULL); |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) |
| 331 | { |
| 332 | struct sockaddr_rc *sa = (struct sockaddr_rc *) addr; |
| 333 | struct sock *sk = sock->sk; |
| 334 | int err = 0; |
| 335 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 336 | BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | if (!addr || addr->sa_family != AF_BLUETOOTH) |
| 339 | return -EINVAL; |
| 340 | |
| 341 | lock_sock(sk); |
| 342 | |
| 343 | if (sk->sk_state != BT_OPEN) { |
| 344 | err = -EBADFD; |
| 345 | goto done; |
| 346 | } |
| 347 | |
Marcel Holtmann | 354d28d | 2005-09-13 01:32:31 +0200 | [diff] [blame] | 348 | if (sk->sk_type != SOCK_STREAM) { |
| 349 | err = -EINVAL; |
| 350 | goto done; |
| 351 | } |
| 352 | |
Gustavo F. Padovan | 95ca83f | 2011-12-27 15:28:44 -0200 | [diff] [blame] | 353 | write_lock(&rfcomm_sk_list.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) { |
| 356 | err = -EADDRINUSE; |
| 357 | } else { |
| 358 | /* Save source address */ |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 359 | bacpy(&rfcomm_pi(sk)->src, &sa->rc_bdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | rfcomm_pi(sk)->channel = sa->rc_channel; |
| 361 | sk->sk_state = BT_BOUND; |
| 362 | } |
| 363 | |
Gustavo F. Padovan | 95ca83f | 2011-12-27 15:28:44 -0200 | [diff] [blame] | 364 | write_unlock(&rfcomm_sk_list.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | done: |
| 367 | release_sock(sk); |
| 368 | return err; |
| 369 | } |
| 370 | |
| 371 | static int rfcomm_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags) |
| 372 | { |
| 373 | struct sockaddr_rc *sa = (struct sockaddr_rc *) addr; |
| 374 | struct sock *sk = sock->sk; |
| 375 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; |
| 376 | int err = 0; |
| 377 | |
| 378 | BT_DBG("sk %p", sk); |
| 379 | |
Changli Gao | 6503d96 | 2010-03-31 22:58:26 +0000 | [diff] [blame] | 380 | if (alen < sizeof(struct sockaddr_rc) || |
| 381 | addr->sa_family != AF_BLUETOOTH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return -EINVAL; |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | lock_sock(sk); |
| 385 | |
Marcel Holtmann | 354d28d | 2005-09-13 01:32:31 +0200 | [diff] [blame] | 386 | if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) { |
| 387 | err = -EBADFD; |
| 388 | goto done; |
| 389 | } |
| 390 | |
| 391 | if (sk->sk_type != SOCK_STREAM) { |
| 392 | err = -EINVAL; |
| 393 | goto done; |
| 394 | } |
| 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | sk->sk_state = BT_CONNECT; |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 397 | bacpy(&rfcomm_pi(sk)->dst, &sa->rc_bdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | rfcomm_pi(sk)->channel = sa->rc_channel; |
| 399 | |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 400 | d->sec_level = rfcomm_pi(sk)->sec_level; |
| 401 | d->role_switch = rfcomm_pi(sk)->role_switch; |
Marcel Holtmann | 77db198 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 402 | |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 403 | err = rfcomm_dlc_open(d, &rfcomm_pi(sk)->src, &sa->rc_bdaddr, |
| 404 | sa->rc_channel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (!err) |
| 406 | err = bt_sock_wait_state(sk, BT_CONNECTED, |
| 407 | sock_sndtimeo(sk, flags & O_NONBLOCK)); |
| 408 | |
Marcel Holtmann | 354d28d | 2005-09-13 01:32:31 +0200 | [diff] [blame] | 409 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | release_sock(sk); |
| 411 | return err; |
| 412 | } |
| 413 | |
| 414 | static int rfcomm_sock_listen(struct socket *sock, int backlog) |
| 415 | { |
| 416 | struct sock *sk = sock->sk; |
| 417 | int err = 0; |
| 418 | |
| 419 | BT_DBG("sk %p backlog %d", sk, backlog); |
| 420 | |
| 421 | lock_sock(sk); |
| 422 | |
| 423 | if (sk->sk_state != BT_BOUND) { |
| 424 | err = -EBADFD; |
| 425 | goto done; |
| 426 | } |
| 427 | |
Marcel Holtmann | 354d28d | 2005-09-13 01:32:31 +0200 | [diff] [blame] | 428 | if (sk->sk_type != SOCK_STREAM) { |
| 429 | err = -EINVAL; |
| 430 | goto done; |
| 431 | } |
| 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if (!rfcomm_pi(sk)->channel) { |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 434 | bdaddr_t *src = &rfcomm_pi(sk)->src; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | u8 channel; |
| 436 | |
| 437 | err = -EINVAL; |
| 438 | |
Gustavo F. Padovan | 95ca83f | 2011-12-27 15:28:44 -0200 | [diff] [blame] | 439 | write_lock(&rfcomm_sk_list.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | for (channel = 1; channel < 31; channel++) |
| 442 | if (!__rfcomm_get_sock_by_addr(channel, src)) { |
| 443 | rfcomm_pi(sk)->channel = channel; |
| 444 | err = 0; |
| 445 | break; |
| 446 | } |
| 447 | |
Gustavo F. Padovan | 95ca83f | 2011-12-27 15:28:44 -0200 | [diff] [blame] | 448 | write_unlock(&rfcomm_sk_list.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | if (err < 0) |
| 451 | goto done; |
| 452 | } |
| 453 | |
| 454 | sk->sk_max_ack_backlog = backlog; |
| 455 | sk->sk_ack_backlog = 0; |
| 456 | sk->sk_state = BT_LISTEN; |
| 457 | |
| 458 | done: |
| 459 | release_sock(sk); |
| 460 | return err; |
| 461 | } |
| 462 | |
| 463 | static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags) |
| 464 | { |
| 465 | DECLARE_WAITQUEUE(wait, current); |
| 466 | struct sock *sk = sock->sk, *nsk; |
| 467 | long timeo; |
| 468 | int err = 0; |
| 469 | |
Gustavo Padovan | dc2a0e2 | 2012-11-20 23:25:54 -0200 | [diff] [blame] | 470 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Marcel Holtmann | 354d28d | 2005-09-13 01:32:31 +0200 | [diff] [blame] | 472 | if (sk->sk_type != SOCK_STREAM) { |
| 473 | err = -EINVAL; |
| 474 | goto done; |
| 475 | } |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 478 | |
| 479 | BT_DBG("sk %p timeo %ld", sk, timeo); |
| 480 | |
| 481 | /* Wait for an incoming connection. (wake-one). */ |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 482 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
Peter Hurley | 950e2d5 | 2011-07-24 00:10:41 -0400 | [diff] [blame] | 483 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | set_current_state(TASK_INTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | if (sk->sk_state != BT_LISTEN) { |
| 487 | err = -EBADFD; |
| 488 | break; |
| 489 | } |
| 490 | |
Peter Hurley | 950e2d5 | 2011-07-24 00:10:41 -0400 | [diff] [blame] | 491 | nsk = bt_accept_dequeue(sk, newsock); |
| 492 | if (nsk) |
| 493 | break; |
| 494 | |
| 495 | if (!timeo) { |
| 496 | err = -EAGAIN; |
| 497 | break; |
| 498 | } |
| 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (signal_pending(current)) { |
| 501 | err = sock_intr_errno(timeo); |
| 502 | break; |
| 503 | } |
Peter Hurley | 950e2d5 | 2011-07-24 00:10:41 -0400 | [diff] [blame] | 504 | |
| 505 | release_sock(sk); |
| 506 | timeo = schedule_timeout(timeo); |
Gustavo Padovan | dc2a0e2 | 2012-11-20 23:25:54 -0200 | [diff] [blame] | 507 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
Peter Hurley | 950e2d5 | 2011-07-24 00:10:41 -0400 | [diff] [blame] | 509 | __set_current_state(TASK_RUNNING); |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 510 | remove_wait_queue(sk_sleep(sk), &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | if (err) |
| 513 | goto done; |
| 514 | |
| 515 | newsock->state = SS_CONNECTED; |
| 516 | |
| 517 | BT_DBG("new socket %p", nsk); |
| 518 | |
| 519 | done: |
| 520 | release_sock(sk); |
| 521 | return err; |
| 522 | } |
| 523 | |
| 524 | static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *len, int peer) |
| 525 | { |
| 526 | struct sockaddr_rc *sa = (struct sockaddr_rc *) addr; |
| 527 | struct sock *sk = sock->sk; |
| 528 | |
| 529 | BT_DBG("sock %p, sk %p", sock, sk); |
| 530 | |
Mathias Krause | 9344a97 | 2012-08-15 11:31:50 +0000 | [diff] [blame] | 531 | memset(sa, 0, sizeof(*sa)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | sa->rc_family = AF_BLUETOOTH; |
| 533 | sa->rc_channel = rfcomm_pi(sk)->channel; |
| 534 | if (peer) |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 535 | bacpy(&sa->rc_bdaddr, &rfcomm_pi(sk)->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | else |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 537 | bacpy(&sa->rc_bdaddr, &rfcomm_pi(sk)->src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | *len = sizeof(struct sockaddr_rc); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | static int rfcomm_sock_sendmsg(struct kiocb *iocb, struct socket *sock, |
| 544 | struct msghdr *msg, size_t len) |
| 545 | { |
| 546 | struct sock *sk = sock->sk; |
| 547 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; |
| 548 | struct sk_buff *skb; |
Johan Hedberg | e793dcf | 2013-09-16 13:05:19 +0300 | [diff] [blame] | 549 | int sent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 551 | if (test_bit(RFCOMM_DEFER_SETUP, &d->flags)) |
| 552 | return -ENOTCONN; |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | if (msg->msg_flags & MSG_OOB) |
| 555 | return -EOPNOTSUPP; |
| 556 | |
| 557 | if (sk->sk_shutdown & SEND_SHUTDOWN) |
| 558 | return -EPIPE; |
| 559 | |
| 560 | BT_DBG("sock %p, sk %p", sock, sk); |
| 561 | |
| 562 | lock_sock(sk); |
| 563 | |
Johan Hedberg | e793dcf | 2013-09-16 13:05:19 +0300 | [diff] [blame] | 564 | sent = bt_sock_wait_ready(sk, msg->msg_flags); |
| 565 | if (sent) |
| 566 | goto done; |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | while (len) { |
| 569 | size_t size = min_t(size_t, len, d->mtu); |
Marcel Holtmann | 4d6a218 | 2007-01-08 02:16:31 +0100 | [diff] [blame] | 570 | int err; |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | skb = sock_alloc_send_skb(sk, size + RFCOMM_SKB_RESERVE, |
| 573 | msg->msg_flags & MSG_DONTWAIT, &err); |
Victor Shcherbatyuk | 91aa35a | 2009-01-15 21:52:12 +0100 | [diff] [blame] | 574 | if (!skb) { |
| 575 | if (sent == 0) |
| 576 | sent = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | break; |
Victor Shcherbatyuk | 91aa35a | 2009-01-15 21:52:12 +0100 | [diff] [blame] | 578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | skb_reserve(skb, RFCOMM_SKB_HEAD_RESERVE); |
| 580 | |
| 581 | err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size); |
| 582 | if (err) { |
| 583 | kfree_skb(skb); |
Marcel Holtmann | 4d6a218 | 2007-01-08 02:16:31 +0100 | [diff] [blame] | 584 | if (sent == 0) |
| 585 | sent = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | break; |
| 587 | } |
| 588 | |
Luiz Augusto von Dentz | 262038f | 2011-11-01 10:58:58 +0200 | [diff] [blame] | 589 | skb->priority = sk->sk_priority; |
| 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | err = rfcomm_dlc_send(d, skb); |
| 592 | if (err < 0) { |
| 593 | kfree_skb(skb); |
Marcel Holtmann | 4d6a218 | 2007-01-08 02:16:31 +0100 | [diff] [blame] | 594 | if (sent == 0) |
| 595 | sent = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | break; |
| 597 | } |
| 598 | |
| 599 | sent += size; |
| 600 | len -= size; |
| 601 | } |
| 602 | |
Johan Hedberg | e793dcf | 2013-09-16 13:05:19 +0300 | [diff] [blame] | 603 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | release_sock(sk); |
| 605 | |
Marcel Holtmann | 4d6a218 | 2007-01-08 02:16:31 +0100 | [diff] [blame] | 606 | return sent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock, |
| 610 | struct msghdr *msg, size_t size, int flags) |
| 611 | { |
| 612 | struct sock *sk = sock->sk; |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 613 | struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc; |
Mat Martineau | 3d7d01d | 2010-09-08 10:05:28 -0700 | [diff] [blame] | 614 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 616 | if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) { |
| 617 | rfcomm_dlc_accept(d); |
Mathias Krause | e11e045 | 2013-04-07 01:51:50 +0000 | [diff] [blame] | 618 | msg->msg_namelen = 0; |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
Mat Martineau | 3d7d01d | 2010-09-08 10:05:28 -0700 | [diff] [blame] | 622 | len = bt_sock_stream_recvmsg(iocb, sock, msg, size, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | lock_sock(sk); |
Mat Martineau | 3d7d01d | 2010-09-08 10:05:28 -0700 | [diff] [blame] | 625 | if (!(flags & MSG_PEEK) && len > 0) |
| 626 | atomic_sub(len, &sk->sk_rmem_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | if (atomic_read(&sk->sk_rmem_alloc) <= (sk->sk_rcvbuf >> 2)) |
| 629 | rfcomm_dlc_unthrottle(rfcomm_pi(sk)->dlc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | release_sock(sk); |
Mat Martineau | 3d7d01d | 2010-09-08 10:05:28 -0700 | [diff] [blame] | 631 | |
| 632 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 635 | static int rfcomm_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
| 637 | struct sock *sk = sock->sk; |
| 638 | int err = 0; |
| 639 | u32 opt; |
| 640 | |
| 641 | BT_DBG("sk %p", sk); |
| 642 | |
| 643 | lock_sock(sk); |
| 644 | |
| 645 | switch (optname) { |
| 646 | case RFCOMM_LM: |
| 647 | if (get_user(opt, (u32 __user *) optval)) { |
| 648 | err = -EFAULT; |
| 649 | break; |
| 650 | } |
| 651 | |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 652 | if (opt & RFCOMM_LM_AUTH) |
| 653 | rfcomm_pi(sk)->sec_level = BT_SECURITY_LOW; |
| 654 | if (opt & RFCOMM_LM_ENCRYPT) |
| 655 | rfcomm_pi(sk)->sec_level = BT_SECURITY_MEDIUM; |
| 656 | if (opt & RFCOMM_LM_SECURE) |
| 657 | rfcomm_pi(sk)->sec_level = BT_SECURITY_HIGH; |
| 658 | |
| 659 | rfcomm_pi(sk)->role_switch = (opt & RFCOMM_LM_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | default: |
| 663 | err = -ENOPROTOOPT; |
| 664 | break; |
| 665 | } |
| 666 | |
| 667 | release_sock(sk); |
| 668 | return err; |
| 669 | } |
| 670 | |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 671 | static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen) |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 672 | { |
| 673 | struct sock *sk = sock->sk; |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 674 | struct bt_security sec; |
Stephen Boyd | d0fad89 | 2011-05-12 16:50:09 -0700 | [diff] [blame] | 675 | int err = 0; |
| 676 | size_t len; |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 677 | u32 opt; |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 678 | |
| 679 | BT_DBG("sk %p", sk); |
| 680 | |
| 681 | if (level == SOL_RFCOMM) |
| 682 | return rfcomm_sock_setsockopt_old(sock, optname, optval, optlen); |
| 683 | |
Marcel Holtmann | 0588d94 | 2009-01-16 10:06:13 +0100 | [diff] [blame] | 684 | if (level != SOL_BLUETOOTH) |
| 685 | return -ENOPROTOOPT; |
| 686 | |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 687 | lock_sock(sk); |
| 688 | |
| 689 | switch (optname) { |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 690 | case BT_SECURITY: |
Marcel Holtmann | 0588d94 | 2009-01-16 10:06:13 +0100 | [diff] [blame] | 691 | if (sk->sk_type != SOCK_STREAM) { |
| 692 | err = -EINVAL; |
| 693 | break; |
| 694 | } |
| 695 | |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 696 | sec.level = BT_SECURITY_LOW; |
| 697 | |
| 698 | len = min_t(unsigned int, sizeof(sec), optlen); |
| 699 | if (copy_from_user((char *) &sec, optval, len)) { |
| 700 | err = -EFAULT; |
| 701 | break; |
| 702 | } |
| 703 | |
| 704 | if (sec.level > BT_SECURITY_HIGH) { |
| 705 | err = -EINVAL; |
| 706 | break; |
| 707 | } |
| 708 | |
| 709 | rfcomm_pi(sk)->sec_level = sec.level; |
| 710 | break; |
| 711 | |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 712 | case BT_DEFER_SETUP: |
| 713 | if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { |
| 714 | err = -EINVAL; |
| 715 | break; |
| 716 | } |
| 717 | |
| 718 | if (get_user(opt, (u32 __user *) optval)) { |
| 719 | err = -EFAULT; |
| 720 | break; |
| 721 | } |
| 722 | |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 723 | if (opt) |
| 724 | set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); |
| 725 | else |
| 726 | clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); |
| 727 | |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 728 | break; |
| 729 | |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 730 | default: |
| 731 | err = -ENOPROTOOPT; |
| 732 | break; |
| 733 | } |
| 734 | |
| 735 | release_sock(sk); |
| 736 | return err; |
| 737 | } |
| 738 | |
| 739 | static int rfcomm_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | { |
| 741 | struct sock *sk = sock->sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | struct rfcomm_conninfo cinfo; |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 743 | struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | int len, err = 0; |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 745 | u32 opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
| 747 | BT_DBG("sk %p", sk); |
| 748 | |
| 749 | if (get_user(len, optlen)) |
| 750 | return -EFAULT; |
| 751 | |
| 752 | lock_sock(sk); |
| 753 | |
| 754 | switch (optname) { |
| 755 | case RFCOMM_LM: |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 756 | switch (rfcomm_pi(sk)->sec_level) { |
| 757 | case BT_SECURITY_LOW: |
| 758 | opt = RFCOMM_LM_AUTH; |
| 759 | break; |
| 760 | case BT_SECURITY_MEDIUM: |
| 761 | opt = RFCOMM_LM_AUTH | RFCOMM_LM_ENCRYPT; |
| 762 | break; |
| 763 | case BT_SECURITY_HIGH: |
| 764 | opt = RFCOMM_LM_AUTH | RFCOMM_LM_ENCRYPT | |
| 765 | RFCOMM_LM_SECURE; |
| 766 | break; |
| 767 | default: |
| 768 | opt = 0; |
| 769 | break; |
| 770 | } |
| 771 | |
| 772 | if (rfcomm_pi(sk)->role_switch) |
| 773 | opt |= RFCOMM_LM_MASTER; |
| 774 | |
| 775 | if (put_user(opt, (u32 __user *) optval)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | err = -EFAULT; |
| 777 | break; |
| 778 | |
| 779 | case RFCOMM_CONNINFO: |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 780 | if (sk->sk_state != BT_CONNECTED && |
| 781 | !rfcomm_pi(sk)->dlc->defer_setup) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | err = -ENOTCONN; |
| 783 | break; |
| 784 | } |
| 785 | |
Filip Palian | 8d03e97 | 2011-05-12 19:32:46 +0200 | [diff] [blame] | 786 | memset(&cinfo, 0, sizeof(cinfo)); |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 787 | cinfo.hci_handle = conn->hcon->handle; |
| 788 | memcpy(cinfo.dev_class, conn->hcon->dev_class, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | len = min_t(unsigned int, len, sizeof(cinfo)); |
| 791 | if (copy_to_user(optval, (char *) &cinfo, len)) |
| 792 | err = -EFAULT; |
| 793 | |
| 794 | break; |
| 795 | |
| 796 | default: |
| 797 | err = -ENOPROTOOPT; |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | release_sock(sk); |
| 802 | return err; |
| 803 | } |
| 804 | |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 805 | static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen) |
| 806 | { |
| 807 | struct sock *sk = sock->sk; |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 808 | struct bt_security sec; |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 809 | int len, err = 0; |
| 810 | |
| 811 | BT_DBG("sk %p", sk); |
| 812 | |
| 813 | if (level == SOL_RFCOMM) |
| 814 | return rfcomm_sock_getsockopt_old(sock, optname, optval, optlen); |
| 815 | |
Marcel Holtmann | 0588d94 | 2009-01-16 10:06:13 +0100 | [diff] [blame] | 816 | if (level != SOL_BLUETOOTH) |
| 817 | return -ENOPROTOOPT; |
| 818 | |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 819 | if (get_user(len, optlen)) |
| 820 | return -EFAULT; |
| 821 | |
| 822 | lock_sock(sk); |
| 823 | |
| 824 | switch (optname) { |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 825 | case BT_SECURITY: |
Marcel Holtmann | 0588d94 | 2009-01-16 10:06:13 +0100 | [diff] [blame] | 826 | if (sk->sk_type != SOCK_STREAM) { |
| 827 | err = -EINVAL; |
| 828 | break; |
| 829 | } |
| 830 | |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 831 | sec.level = rfcomm_pi(sk)->sec_level; |
Mathias Krause | 9ad2de4 | 2012-08-15 11:31:48 +0000 | [diff] [blame] | 832 | sec.key_size = 0; |
Marcel Holtmann | 9f2c8a0 | 2009-01-15 21:58:40 +0100 | [diff] [blame] | 833 | |
| 834 | len = min_t(unsigned int, len, sizeof(sec)); |
| 835 | if (copy_to_user(optval, (char *) &sec, len)) |
| 836 | err = -EFAULT; |
| 837 | |
| 838 | break; |
| 839 | |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 840 | case BT_DEFER_SETUP: |
| 841 | if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { |
| 842 | err = -EINVAL; |
| 843 | break; |
| 844 | } |
| 845 | |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 846 | if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags), |
| 847 | (u32 __user *) optval)) |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 848 | err = -EFAULT; |
| 849 | |
| 850 | break; |
| 851 | |
Marcel Holtmann | d58daf4 | 2009-01-15 21:52:14 +0100 | [diff] [blame] | 852 | default: |
| 853 | err = -ENOPROTOOPT; |
| 854 | break; |
| 855 | } |
| 856 | |
| 857 | release_sock(sk); |
| 858 | return err; |
| 859 | } |
| 860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | static int rfcomm_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 862 | { |
David S. Miller | e19caae | 2008-12-09 01:04:27 -0800 | [diff] [blame] | 863 | struct sock *sk __maybe_unused = sock->sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | int err; |
| 865 | |
David S. Miller | e19caae | 2008-12-09 01:04:27 -0800 | [diff] [blame] | 866 | BT_DBG("sk %p cmd %x arg %lx", sk, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
Marcel Holtmann | 3241ad8 | 2008-07-14 20:13:50 +0200 | [diff] [blame] | 868 | err = bt_sock_ioctl(sock, cmd, arg); |
| 869 | |
| 870 | if (err == -ENOIOCTLCMD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | #ifdef CONFIG_BT_RFCOMM_TTY |
Marcel Holtmann | 3241ad8 | 2008-07-14 20:13:50 +0200 | [diff] [blame] | 872 | lock_sock(sk); |
| 873 | err = rfcomm_dev_ioctl(sk, cmd, (void __user *) arg); |
| 874 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | #else |
Marcel Holtmann | 3241ad8 | 2008-07-14 20:13:50 +0200 | [diff] [blame] | 876 | err = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | #endif |
Marcel Holtmann | 3241ad8 | 2008-07-14 20:13:50 +0200 | [diff] [blame] | 878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | return err; |
| 881 | } |
| 882 | |
| 883 | static int rfcomm_sock_shutdown(struct socket *sock, int how) |
| 884 | { |
| 885 | struct sock *sk = sock->sk; |
| 886 | int err = 0; |
| 887 | |
| 888 | BT_DBG("sock %p, sk %p", sock, sk); |
| 889 | |
Andrei Emeltchenko | 285b4e9 | 2010-12-01 16:58:23 +0200 | [diff] [blame] | 890 | if (!sk) |
| 891 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | lock_sock(sk); |
| 894 | if (!sk->sk_shutdown) { |
| 895 | sk->sk_shutdown = SHUTDOWN_MASK; |
| 896 | __rfcomm_sock_close(sk); |
| 897 | |
| 898 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) |
| 899 | err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime); |
| 900 | } |
| 901 | release_sock(sk); |
| 902 | return err; |
| 903 | } |
| 904 | |
| 905 | static int rfcomm_sock_release(struct socket *sock) |
| 906 | { |
| 907 | struct sock *sk = sock->sk; |
| 908 | int err; |
| 909 | |
| 910 | BT_DBG("sock %p, sk %p", sock, sk); |
| 911 | |
| 912 | if (!sk) |
| 913 | return 0; |
| 914 | |
| 915 | err = rfcomm_sock_shutdown(sock, 2); |
| 916 | |
| 917 | sock_orphan(sk); |
| 918 | rfcomm_sock_kill(sk); |
| 919 | return err; |
| 920 | } |
| 921 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 922 | /* ---- RFCOMM core layer callbacks ---- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | * |
| 924 | * called under rfcomm_lock() |
| 925 | */ |
| 926 | int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc **d) |
| 927 | { |
| 928 | struct sock *sk, *parent; |
| 929 | bdaddr_t src, dst; |
| 930 | int result = 0; |
| 931 | |
| 932 | BT_DBG("session %p channel %d", s, channel); |
| 933 | |
| 934 | rfcomm_session_getaddr(s, &src, &dst); |
| 935 | |
| 936 | /* Check if we have socket listening on channel */ |
| 937 | parent = rfcomm_get_sock_by_channel(BT_LISTEN, channel, &src); |
| 938 | if (!parent) |
| 939 | return 0; |
| 940 | |
Gustavo F. Padovan | eeb3665 | 2010-11-01 18:43:53 +0000 | [diff] [blame] | 941 | bh_lock_sock(parent); |
| 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | /* Check for backlog size */ |
| 944 | if (sk_acceptq_is_full(parent)) { |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 945 | BT_DBG("backlog full %d", parent->sk_ack_backlog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | goto done; |
| 947 | } |
| 948 | |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 949 | sk = rfcomm_sock_alloc(sock_net(parent), NULL, BTPROTO_RFCOMM, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | if (!sk) |
| 951 | goto done; |
| 952 | |
Octavian Purdila | b5a30dd | 2012-01-22 00:28:34 +0200 | [diff] [blame] | 953 | bt_sock_reclassify_lock(sk, BTPROTO_RFCOMM); |
| 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | rfcomm_sock_init(sk, parent); |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 956 | bacpy(&rfcomm_pi(sk)->src, &src); |
| 957 | bacpy(&rfcomm_pi(sk)->dst, &dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | rfcomm_pi(sk)->channel = channel; |
| 959 | |
| 960 | sk->sk_state = BT_CONFIG; |
| 961 | bt_accept_enqueue(parent, sk); |
| 962 | |
| 963 | /* Accept connection and return socket DLC */ |
| 964 | *d = rfcomm_pi(sk)->dlc; |
| 965 | result = 1; |
| 966 | |
| 967 | done: |
| 968 | bh_unlock_sock(parent); |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 969 | |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 970 | if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags)) |
Marcel Holtmann | bb23c0a | 2009-01-15 21:56:48 +0100 | [diff] [blame] | 971 | parent->sk_state_change(parent); |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return result; |
| 974 | } |
| 975 | |
Marcel Holtmann | aef7d97 | 2010-03-21 05:27:45 +0100 | [diff] [blame] | 976 | static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | { |
| 978 | struct sock *sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
Gustavo F. Padovan | 95ca83f | 2011-12-27 15:28:44 -0200 | [diff] [blame] | 980 | read_lock(&rfcomm_sk_list.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 982 | sk_for_each(sk, &rfcomm_sk_list.head) { |
Andrei Emeltchenko | fcb7333 | 2012-09-25 12:49:44 +0300 | [diff] [blame] | 983 | seq_printf(f, "%pMR %pMR %d %d\n", |
Marcel Holtmann | 94a86df | 2013-10-13 10:34:02 -0700 | [diff] [blame] | 984 | &rfcomm_pi(sk)->src, &rfcomm_pi(sk)->dst, |
Andrei Emeltchenko | fcb7333 | 2012-09-25 12:49:44 +0300 | [diff] [blame] | 985 | sk->sk_state, rfcomm_pi(sk)->channel); |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Gustavo F. Padovan | 95ca83f | 2011-12-27 15:28:44 -0200 | [diff] [blame] | 988 | read_unlock(&rfcomm_sk_list.lock); |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 989 | |
Marcel Holtmann | aef7d97 | 2010-03-21 05:27:45 +0100 | [diff] [blame] | 990 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Marcel Holtmann | aef7d97 | 2010-03-21 05:27:45 +0100 | [diff] [blame] | 993 | static int rfcomm_sock_debugfs_open(struct inode *inode, struct file *file) |
| 994 | { |
| 995 | return single_open(file, rfcomm_sock_debugfs_show, inode->i_private); |
| 996 | } |
| 997 | |
| 998 | static const struct file_operations rfcomm_sock_debugfs_fops = { |
| 999 | .open = rfcomm_sock_debugfs_open, |
| 1000 | .read = seq_read, |
| 1001 | .llseek = seq_lseek, |
| 1002 | .release = single_release, |
| 1003 | }; |
| 1004 | |
| 1005 | static struct dentry *rfcomm_sock_debugfs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 1007 | static const struct proto_ops rfcomm_sock_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | .family = PF_BLUETOOTH, |
| 1009 | .owner = THIS_MODULE, |
| 1010 | .release = rfcomm_sock_release, |
| 1011 | .bind = rfcomm_sock_bind, |
| 1012 | .connect = rfcomm_sock_connect, |
| 1013 | .listen = rfcomm_sock_listen, |
| 1014 | .accept = rfcomm_sock_accept, |
| 1015 | .getname = rfcomm_sock_getname, |
| 1016 | .sendmsg = rfcomm_sock_sendmsg, |
| 1017 | .recvmsg = rfcomm_sock_recvmsg, |
| 1018 | .shutdown = rfcomm_sock_shutdown, |
| 1019 | .setsockopt = rfcomm_sock_setsockopt, |
| 1020 | .getsockopt = rfcomm_sock_getsockopt, |
| 1021 | .ioctl = rfcomm_sock_ioctl, |
| 1022 | .poll = bt_sock_poll, |
| 1023 | .socketpair = sock_no_socketpair, |
| 1024 | .mmap = sock_no_mmap |
| 1025 | }; |
| 1026 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 1027 | static const struct net_proto_family rfcomm_sock_family_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | .family = PF_BLUETOOTH, |
| 1029 | .owner = THIS_MODULE, |
| 1030 | .create = rfcomm_sock_create |
| 1031 | }; |
| 1032 | |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 1033 | int __init rfcomm_init_sockets(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
| 1035 | int err; |
| 1036 | |
| 1037 | err = proto_register(&rfcomm_proto, 0); |
| 1038 | if (err < 0) |
| 1039 | return err; |
| 1040 | |
| 1041 | err = bt_sock_register(BTPROTO_RFCOMM, &rfcomm_sock_family_ops); |
Masatake YAMATO | c6f5df16 | 2012-07-26 01:29:49 +0900 | [diff] [blame] | 1042 | if (err < 0) { |
| 1043 | BT_ERR("RFCOMM socket layer registration failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | goto error; |
Masatake YAMATO | c6f5df16 | 2012-07-26 01:29:49 +0900 | [diff] [blame] | 1045 | } |
| 1046 | |
Al Viro | b031661 | 2013-04-04 19:14:33 -0400 | [diff] [blame] | 1047 | err = bt_procfs_init(&init_net, "rfcomm", &rfcomm_sk_list, NULL); |
Masatake YAMATO | c6f5df16 | 2012-07-26 01:29:49 +0900 | [diff] [blame] | 1048 | if (err < 0) { |
| 1049 | BT_ERR("Failed to create RFCOMM proc file"); |
| 1050 | bt_sock_unregister(BTPROTO_RFCOMM); |
| 1051 | goto error; |
| 1052 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | BT_INFO("RFCOMM socket layer initialized"); |
| 1055 | |
Marcel Holtmann | 1120e4b | 2013-10-17 17:24:16 -0700 | [diff] [blame] | 1056 | if (IS_ERR_OR_NULL(bt_debugfs)) |
| 1057 | return 0; |
| 1058 | |
| 1059 | rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444, |
| 1060 | bt_debugfs, NULL, |
| 1061 | &rfcomm_sock_debugfs_fops); |
| 1062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | return 0; |
| 1064 | |
| 1065 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | proto_unregister(&rfcomm_proto); |
| 1067 | return err; |
| 1068 | } |
| 1069 | |
Gustavo F. Padovan | 2f8362a | 2010-07-24 02:04:45 -0300 | [diff] [blame] | 1070 | void __exit rfcomm_cleanup_sockets(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | { |
Masatake YAMATO | c6f5df16 | 2012-07-26 01:29:49 +0900 | [diff] [blame] | 1072 | bt_procfs_cleanup(&init_net, "rfcomm"); |
| 1073 | |
Marcel Holtmann | aef7d97 | 2010-03-21 05:27:45 +0100 | [diff] [blame] | 1074 | debugfs_remove(rfcomm_sock_debugfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
David Herrmann | 5e9d7f8 | 2013-02-24 19:36:51 +0100 | [diff] [blame] | 1076 | bt_sock_unregister(BTPROTO_RFCOMM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
| 1078 | proto_unregister(&rfcomm_proto); |
| 1079 | } |