Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1 | /* |
| 2 | BlueZ - Bluetooth protocol stack for Linux |
| 3 | Copyright (C) 2000-2001 Qualcomm Incorporated |
| 4 | Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org> |
| 5 | Copyright (C) 2010 Google Inc. |
Gustavo F. Padovan | 590051d | 2011-12-18 13:39:33 -0200 | [diff] [blame] | 6 | Copyright (C) 2011 ProFUSION Embedded Systems |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 7 | |
| 8 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License version 2 as |
| 12 | published by the Free Software Foundation; |
| 13 | |
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 17 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
| 18 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 21 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 24 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
| 25 | SOFTWARE IS DISCLAIMED. |
| 26 | */ |
| 27 | |
| 28 | /* Bluetooth L2CAP sockets. */ |
| 29 | |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 30 | #include <linux/export.h> |
Paul Moore | 6230c9b | 2011-10-07 09:40:59 +0000 | [diff] [blame] | 31 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 32 | #include <net/bluetooth/bluetooth.h> |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 33 | #include <net/bluetooth/hci_core.h> |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 34 | #include <net/bluetooth/l2cap.h> |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 35 | #include <net/bluetooth/smp.h> |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 36 | |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 37 | static struct bt_sock_list l2cap_sk_list = { |
| 38 | .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock) |
| 39 | }; |
| 40 | |
Gustavo F. Padovan | cf2f90f | 2011-04-27 18:40:39 -0300 | [diff] [blame] | 41 | static const struct proto_ops l2cap_sock_ops; |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 42 | static void l2cap_sock_init(struct sock *sk, struct sock *parent); |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 43 | static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, |
| 44 | int proto, gfp_t prio); |
Gustavo F. Padovan | cf2f90f | 2011-04-27 18:40:39 -0300 | [diff] [blame] | 45 | |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 46 | static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) |
| 47 | { |
| 48 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 49 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 50 | struct sockaddr_l2 la; |
| 51 | int len, err = 0; |
| 52 | |
| 53 | BT_DBG("sk %p", sk); |
| 54 | |
| 55 | if (!addr || addr->sa_family != AF_BLUETOOTH) |
| 56 | return -EINVAL; |
| 57 | |
| 58 | memset(&la, 0, sizeof(la)); |
| 59 | len = min_t(unsigned int, sizeof(la), alen); |
| 60 | memcpy(&la, addr, len); |
| 61 | |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 62 | if (la.l2_cid && la.l2_psm) |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 63 | return -EINVAL; |
| 64 | |
| 65 | lock_sock(sk); |
| 66 | |
| 67 | if (sk->sk_state != BT_OPEN) { |
| 68 | err = -EBADFD; |
| 69 | goto done; |
| 70 | } |
| 71 | |
| 72 | if (la.l2_psm) { |
| 73 | __u16 psm = __le16_to_cpu(la.l2_psm); |
| 74 | |
| 75 | /* PSM must be odd and lsb of upper byte must be 0 */ |
| 76 | if ((psm & 0x0101) != 0x0001) { |
| 77 | err = -EINVAL; |
| 78 | goto done; |
| 79 | } |
| 80 | |
| 81 | /* Restrict usage of well-known PSMs */ |
| 82 | if (psm < 0x1001 && !capable(CAP_NET_BIND_SERVICE)) { |
| 83 | err = -EACCES; |
| 84 | goto done; |
| 85 | } |
| 86 | } |
| 87 | |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 88 | if (la.l2_cid) |
Santosh Nayak | 6e4aff1 | 2012-03-01 22:46:36 +0530 | [diff] [blame] | 89 | err = l2cap_add_scid(chan, __le16_to_cpu(la.l2_cid)); |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 90 | else |
| 91 | err = l2cap_add_psm(chan, &la.l2_bdaddr, la.l2_psm); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 92 | |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 93 | if (err < 0) |
| 94 | goto done; |
| 95 | |
Andrei Emeltchenko | 2983fd6 | 2012-05-24 15:42:50 +0300 | [diff] [blame] | 96 | if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_SDP || |
| 97 | __le16_to_cpu(la.l2_psm) == L2CAP_PSM_RFCOMM) |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 98 | chan->sec_level = BT_SECURITY_SDP; |
| 99 | |
| 100 | bacpy(&bt_sk(sk)->src, &la.l2_bdaddr); |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 101 | |
| 102 | chan->state = BT_BOUND; |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 103 | sk->sk_state = BT_BOUND; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 104 | |
| 105 | done: |
| 106 | release_sock(sk); |
| 107 | return err; |
| 108 | } |
| 109 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 110 | static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, |
| 111 | int alen, int flags) |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 112 | { |
| 113 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 114 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 115 | struct sockaddr_l2 la; |
| 116 | int len, err = 0; |
| 117 | |
| 118 | BT_DBG("sk %p", sk); |
| 119 | |
| 120 | if (!addr || alen < sizeof(addr->sa_family) || |
| 121 | addr->sa_family != AF_BLUETOOTH) |
| 122 | return -EINVAL; |
| 123 | |
| 124 | memset(&la, 0, sizeof(la)); |
| 125 | len = min_t(unsigned int, sizeof(la), alen); |
| 126 | memcpy(&la, addr, len); |
| 127 | |
Ville Tervo | acd7d37 | 2011-02-10 22:38:49 -0300 | [diff] [blame] | 128 | if (la.l2_cid && la.l2_psm) |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 129 | return -EINVAL; |
| 130 | |
Santosh Nayak | 6e4aff1 | 2012-03-01 22:46:36 +0530 | [diff] [blame] | 131 | err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid), |
Andre Guedes | 8e9f989 | 2012-04-24 21:02:55 -0300 | [diff] [blame] | 132 | &la.l2_bdaddr, la.l2_bdaddr_type); |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 133 | if (err) |
Andrei Emeltchenko | b3fb611 | 2012-02-22 17:11:57 +0200 | [diff] [blame] | 134 | return err; |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 135 | |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 136 | lock_sock(sk); |
| 137 | |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 138 | err = bt_sock_wait_state(sk, BT_CONNECTED, |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 139 | sock_sndtimeo(sk, flags & O_NONBLOCK)); |
Andrei Emeltchenko | b3fb611 | 2012-02-22 17:11:57 +0200 | [diff] [blame] | 140 | |
| 141 | release_sock(sk); |
| 142 | |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 143 | return err; |
| 144 | } |
| 145 | |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 146 | static int l2cap_sock_listen(struct socket *sock, int backlog) |
| 147 | { |
| 148 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 149 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 150 | int err = 0; |
| 151 | |
| 152 | BT_DBG("sk %p backlog %d", sk, backlog); |
| 153 | |
| 154 | lock_sock(sk); |
| 155 | |
Marcel Holtmann | 6b3af73 | 2012-04-19 13:43:51 +0200 | [diff] [blame] | 156 | if (sk->sk_state != BT_BOUND) { |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 157 | err = -EBADFD; |
| 158 | goto done; |
| 159 | } |
| 160 | |
Marcel Holtmann | 6b3af73 | 2012-04-19 13:43:51 +0200 | [diff] [blame] | 161 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM) { |
| 162 | err = -EINVAL; |
| 163 | goto done; |
| 164 | } |
| 165 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 166 | switch (chan->mode) { |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 167 | case L2CAP_MODE_BASIC: |
| 168 | break; |
| 169 | case L2CAP_MODE_ERTM: |
| 170 | case L2CAP_MODE_STREAMING: |
| 171 | if (!disable_ertm) |
| 172 | break; |
| 173 | /* fall through */ |
| 174 | default: |
| 175 | err = -ENOTSUPP; |
| 176 | goto done; |
| 177 | } |
| 178 | |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 179 | sk->sk_max_ack_backlog = backlog; |
| 180 | sk->sk_ack_backlog = 0; |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 181 | |
| 182 | chan->state = BT_LISTEN; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 183 | sk->sk_state = BT_LISTEN; |
| 184 | |
| 185 | done: |
| 186 | release_sock(sk); |
| 187 | return err; |
| 188 | } |
| 189 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 190 | static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, |
| 191 | int flags) |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 192 | { |
| 193 | DECLARE_WAITQUEUE(wait, current); |
| 194 | struct sock *sk = sock->sk, *nsk; |
| 195 | long timeo; |
| 196 | int err = 0; |
| 197 | |
| 198 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
| 199 | |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 200 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 201 | |
| 202 | BT_DBG("sk %p timeo %ld", sk, timeo); |
| 203 | |
| 204 | /* Wait for an incoming connection. (wake-one). */ |
| 205 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 206 | while (1) { |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 207 | set_current_state(TASK_INTERRUPTIBLE); |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 208 | |
| 209 | if (sk->sk_state != BT_LISTEN) { |
| 210 | err = -EBADFD; |
| 211 | break; |
| 212 | } |
| 213 | |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 214 | nsk = bt_accept_dequeue(sk, newsock); |
| 215 | if (nsk) |
| 216 | break; |
| 217 | |
| 218 | if (!timeo) { |
| 219 | err = -EAGAIN; |
| 220 | break; |
| 221 | } |
| 222 | |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 223 | if (signal_pending(current)) { |
| 224 | err = sock_intr_errno(timeo); |
| 225 | break; |
| 226 | } |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 227 | |
| 228 | release_sock(sk); |
| 229 | timeo = schedule_timeout(timeo); |
| 230 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 231 | } |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 232 | __set_current_state(TASK_RUNNING); |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 233 | remove_wait_queue(sk_sleep(sk), &wait); |
| 234 | |
| 235 | if (err) |
| 236 | goto done; |
| 237 | |
| 238 | newsock->state = SS_CONNECTED; |
| 239 | |
| 240 | BT_DBG("new socket %p", nsk); |
| 241 | |
| 242 | done: |
| 243 | release_sock(sk); |
| 244 | return err; |
| 245 | } |
| 246 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 247 | static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, |
| 248 | int *len, int peer) |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 249 | { |
| 250 | struct sockaddr_l2 *la = (struct sockaddr_l2 *) addr; |
| 251 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 252 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 253 | |
| 254 | BT_DBG("sock %p, sk %p", sock, sk); |
| 255 | |
| 256 | addr->sa_family = AF_BLUETOOTH; |
| 257 | *len = sizeof(struct sockaddr_l2); |
| 258 | |
| 259 | if (peer) { |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 260 | la->l2_psm = chan->psm; |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 261 | bacpy(&la->l2_bdaddr, &bt_sk(sk)->dst); |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 262 | la->l2_cid = cpu_to_le16(chan->dcid); |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 263 | } else { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 264 | la->l2_psm = chan->sport; |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 265 | bacpy(&la->l2_bdaddr, &bt_sk(sk)->src); |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 266 | la->l2_cid = cpu_to_le16(chan->scid); |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 272 | static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, |
| 273 | char __user *optval, int __user *optlen) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 274 | { |
| 275 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 276 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 277 | struct l2cap_options opts; |
| 278 | struct l2cap_conninfo cinfo; |
| 279 | int len, err = 0; |
| 280 | u32 opt; |
| 281 | |
| 282 | BT_DBG("sk %p", sk); |
| 283 | |
| 284 | if (get_user(len, optlen)) |
| 285 | return -EFAULT; |
| 286 | |
| 287 | lock_sock(sk); |
| 288 | |
| 289 | switch (optname) { |
| 290 | case L2CAP_OPTIONS: |
Vasiliy Kulikov | e3fb592 | 2011-02-10 20:59:42 +0300 | [diff] [blame] | 291 | memset(&opts, 0, sizeof(opts)); |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 292 | opts.imtu = chan->imtu; |
| 293 | opts.omtu = chan->omtu; |
| 294 | opts.flush_to = chan->flush_to; |
| 295 | opts.mode = chan->mode; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 296 | opts.fcs = chan->fcs; |
| 297 | opts.max_tx = chan->max_tx; |
Andrei Emeltchenko | 6327eb9 | 2011-10-11 13:37:42 +0300 | [diff] [blame] | 298 | opts.txwin_size = chan->tx_win; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 299 | |
| 300 | len = min_t(unsigned int, len, sizeof(opts)); |
| 301 | if (copy_to_user(optval, (char *) &opts, len)) |
| 302 | err = -EFAULT; |
| 303 | |
| 304 | break; |
| 305 | |
| 306 | case L2CAP_LM: |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 307 | switch (chan->sec_level) { |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 308 | case BT_SECURITY_LOW: |
| 309 | opt = L2CAP_LM_AUTH; |
| 310 | break; |
| 311 | case BT_SECURITY_MEDIUM: |
| 312 | opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT; |
| 313 | break; |
| 314 | case BT_SECURITY_HIGH: |
| 315 | opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 316 | L2CAP_LM_SECURE; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 317 | break; |
| 318 | default: |
| 319 | opt = 0; |
| 320 | break; |
| 321 | } |
| 322 | |
Andrei Emeltchenko | 43bd0f3 | 2011-10-11 14:04:34 +0300 | [diff] [blame] | 323 | if (test_bit(FLAG_ROLE_SWITCH, &chan->flags)) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 324 | opt |= L2CAP_LM_MASTER; |
| 325 | |
Andrei Emeltchenko | ecf61bd | 2011-10-11 14:04:32 +0300 | [diff] [blame] | 326 | if (test_bit(FLAG_FORCE_RELIABLE, &chan->flags)) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 327 | opt |= L2CAP_LM_RELIABLE; |
| 328 | |
| 329 | if (put_user(opt, (u32 __user *) optval)) |
| 330 | err = -EFAULT; |
| 331 | break; |
| 332 | |
| 333 | case L2CAP_CONNINFO: |
| 334 | if (sk->sk_state != BT_CONNECTED && |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 335 | !(sk->sk_state == BT_CONNECT2 && |
| 336 | test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) { |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 337 | err = -ENOTCONN; |
| 338 | break; |
| 339 | } |
| 340 | |
Filip Palian | 8d03e97 | 2011-05-12 19:32:46 +0200 | [diff] [blame] | 341 | memset(&cinfo, 0, sizeof(cinfo)); |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 342 | cinfo.hci_handle = chan->conn->hcon->handle; |
| 343 | memcpy(cinfo.dev_class, chan->conn->hcon->dev_class, 3); |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 344 | |
| 345 | len = min_t(unsigned int, len, sizeof(cinfo)); |
| 346 | if (copy_to_user(optval, (char *) &cinfo, len)) |
| 347 | err = -EFAULT; |
| 348 | |
| 349 | break; |
| 350 | |
| 351 | default: |
| 352 | err = -ENOPROTOOPT; |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | release_sock(sk); |
| 357 | return err; |
| 358 | } |
| 359 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 360 | static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, |
| 361 | char __user *optval, int __user *optlen) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 362 | { |
| 363 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 364 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 365 | struct bt_security sec; |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 366 | struct bt_power pwr; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 367 | int len, err = 0; |
| 368 | |
| 369 | BT_DBG("sk %p", sk); |
| 370 | |
| 371 | if (level == SOL_L2CAP) |
| 372 | return l2cap_sock_getsockopt_old(sock, optname, optval, optlen); |
| 373 | |
| 374 | if (level != SOL_BLUETOOTH) |
| 375 | return -ENOPROTOOPT; |
| 376 | |
| 377 | if (get_user(len, optlen)) |
| 378 | return -EFAULT; |
| 379 | |
| 380 | lock_sock(sk); |
| 381 | |
| 382 | switch (optname) { |
| 383 | case BT_SECURITY: |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 384 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 385 | chan->chan_type != L2CAP_CHAN_RAW) { |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 386 | err = -EINVAL; |
| 387 | break; |
| 388 | } |
| 389 | |
Vinicius Costa Gomes | 8f36011 | 2011-07-08 18:31:46 -0300 | [diff] [blame] | 390 | memset(&sec, 0, sizeof(sec)); |
Andrei Emeltchenko | 85e3436 | 2012-10-05 16:56:54 +0300 | [diff] [blame] | 391 | if (chan->conn) { |
Gustavo Padovan | c6585a4 | 2012-05-07 03:07:26 -0300 | [diff] [blame] | 392 | sec.level = chan->conn->hcon->sec_level; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 393 | |
Andrei Emeltchenko | 85e3436 | 2012-10-05 16:56:54 +0300 | [diff] [blame] | 394 | if (sk->sk_state == BT_CONNECTED) |
| 395 | sec.key_size = chan->conn->hcon->enc_key_size; |
| 396 | } else { |
| 397 | sec.level = chan->sec_level; |
| 398 | } |
Vinicius Costa Gomes | 8f36011 | 2011-07-08 18:31:46 -0300 | [diff] [blame] | 399 | |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 400 | len = min_t(unsigned int, len, sizeof(sec)); |
| 401 | if (copy_to_user(optval, (char *) &sec, len)) |
| 402 | err = -EFAULT; |
| 403 | |
| 404 | break; |
| 405 | |
| 406 | case BT_DEFER_SETUP: |
| 407 | if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { |
| 408 | err = -EINVAL; |
| 409 | break; |
| 410 | } |
| 411 | |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 412 | if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags), |
| 413 | (u32 __user *) optval)) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 414 | err = -EFAULT; |
| 415 | |
| 416 | break; |
| 417 | |
| 418 | case BT_FLUSHABLE: |
Andrei Emeltchenko | d57b0e8 | 2011-10-11 14:04:31 +0300 | [diff] [blame] | 419 | if (put_user(test_bit(FLAG_FLUSHABLE, &chan->flags), |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 420 | (u32 __user *) optval)) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 421 | err = -EFAULT; |
| 422 | |
| 423 | break; |
| 424 | |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 425 | case BT_POWER: |
| 426 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 427 | && sk->sk_type != SOCK_RAW) { |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 428 | err = -EINVAL; |
| 429 | break; |
| 430 | } |
| 431 | |
Andrei Emeltchenko | 15770b1 | 2011-10-11 14:04:33 +0300 | [diff] [blame] | 432 | pwr.force_active = test_bit(FLAG_FORCE_ACTIVE, &chan->flags); |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 433 | |
| 434 | len = min_t(unsigned int, len, sizeof(pwr)); |
| 435 | if (copy_to_user(optval, (char *) &pwr, len)) |
| 436 | err = -EFAULT; |
| 437 | |
| 438 | break; |
| 439 | |
Mat Martineau | 2ea6648 | 2011-11-02 16:18:30 -0700 | [diff] [blame] | 440 | case BT_CHANNEL_POLICY: |
| 441 | if (!enable_hs) { |
| 442 | err = -ENOPROTOOPT; |
| 443 | break; |
| 444 | } |
| 445 | |
| 446 | if (put_user(chan->chan_policy, (u32 __user *) optval)) |
| 447 | err = -EFAULT; |
| 448 | break; |
| 449 | |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 450 | default: |
| 451 | err = -ENOPROTOOPT; |
| 452 | break; |
| 453 | } |
| 454 | |
| 455 | release_sock(sk); |
| 456 | return err; |
| 457 | } |
| 458 | |
Andre Guedes | 682877c | 2012-05-31 17:01:34 -0300 | [diff] [blame] | 459 | static bool l2cap_valid_mtu(struct l2cap_chan *chan, u16 mtu) |
| 460 | { |
| 461 | switch (chan->scid) { |
| 462 | case L2CAP_CID_LE_DATA: |
Andre Guedes | 8c3a4f0 | 2012-05-31 17:01:35 -0300 | [diff] [blame] | 463 | if (mtu < L2CAP_LE_MIN_MTU) |
Andre Guedes | 682877c | 2012-05-31 17:01:34 -0300 | [diff] [blame] | 464 | return false; |
| 465 | break; |
| 466 | |
| 467 | default: |
| 468 | if (mtu < L2CAP_DEFAULT_MIN_MTU) |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | return true; |
| 473 | } |
| 474 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 475 | static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, |
| 476 | char __user *optval, unsigned int optlen) |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 477 | { |
| 478 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 479 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 480 | struct l2cap_options opts; |
| 481 | int len, err = 0; |
| 482 | u32 opt; |
| 483 | |
| 484 | BT_DBG("sk %p", sk); |
| 485 | |
| 486 | lock_sock(sk); |
| 487 | |
| 488 | switch (optname) { |
| 489 | case L2CAP_OPTIONS: |
| 490 | if (sk->sk_state == BT_CONNECTED) { |
| 491 | err = -EINVAL; |
| 492 | break; |
| 493 | } |
| 494 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 495 | opts.imtu = chan->imtu; |
| 496 | opts.omtu = chan->omtu; |
| 497 | opts.flush_to = chan->flush_to; |
| 498 | opts.mode = chan->mode; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 499 | opts.fcs = chan->fcs; |
| 500 | opts.max_tx = chan->max_tx; |
Andrei Emeltchenko | 6327eb9 | 2011-10-11 13:37:42 +0300 | [diff] [blame] | 501 | opts.txwin_size = chan->tx_win; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 502 | |
| 503 | len = min_t(unsigned int, sizeof(opts), optlen); |
| 504 | if (copy_from_user((char *) &opts, optval, len)) { |
| 505 | err = -EFAULT; |
| 506 | break; |
| 507 | } |
| 508 | |
Andrei Emeltchenko | 6327eb9 | 2011-10-11 13:37:42 +0300 | [diff] [blame] | 509 | if (opts.txwin_size > L2CAP_DEFAULT_EXT_WINDOW) { |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 510 | err = -EINVAL; |
| 511 | break; |
| 512 | } |
| 513 | |
Andre Guedes | 682877c | 2012-05-31 17:01:34 -0300 | [diff] [blame] | 514 | if (!l2cap_valid_mtu(chan, opts.imtu)) { |
| 515 | err = -EINVAL; |
| 516 | break; |
| 517 | } |
| 518 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 519 | chan->mode = opts.mode; |
| 520 | switch (chan->mode) { |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 521 | case L2CAP_MODE_BASIC: |
Gustavo F. Padovan | c1360a1 | 2011-06-10 17:02:12 -0300 | [diff] [blame] | 522 | clear_bit(CONF_STATE2_DEVICE, &chan->conf_state); |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 523 | break; |
| 524 | case L2CAP_MODE_ERTM: |
| 525 | case L2CAP_MODE_STREAMING: |
| 526 | if (!disable_ertm) |
| 527 | break; |
| 528 | /* fall through */ |
| 529 | default: |
| 530 | err = -EINVAL; |
| 531 | break; |
| 532 | } |
| 533 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 534 | chan->imtu = opts.imtu; |
| 535 | chan->omtu = opts.omtu; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 536 | chan->fcs = opts.fcs; |
| 537 | chan->max_tx = opts.max_tx; |
Andrei Emeltchenko | 6327eb9 | 2011-10-11 13:37:42 +0300 | [diff] [blame] | 538 | chan->tx_win = opts.txwin_size; |
Andrei Emeltchenko | 12d5978 | 2012-10-10 17:38:26 +0300 | [diff] [blame] | 539 | chan->flush_to = opts.flush_to; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 540 | break; |
| 541 | |
| 542 | case L2CAP_LM: |
| 543 | if (get_user(opt, (u32 __user *) optval)) { |
| 544 | err = -EFAULT; |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | if (opt & L2CAP_LM_AUTH) |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 549 | chan->sec_level = BT_SECURITY_LOW; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 550 | if (opt & L2CAP_LM_ENCRYPT) |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 551 | chan->sec_level = BT_SECURITY_MEDIUM; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 552 | if (opt & L2CAP_LM_SECURE) |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 553 | chan->sec_level = BT_SECURITY_HIGH; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 554 | |
Andrei Emeltchenko | 43bd0f3 | 2011-10-11 14:04:34 +0300 | [diff] [blame] | 555 | if (opt & L2CAP_LM_MASTER) |
| 556 | set_bit(FLAG_ROLE_SWITCH, &chan->flags); |
| 557 | else |
| 558 | clear_bit(FLAG_ROLE_SWITCH, &chan->flags); |
Andrei Emeltchenko | ecf61bd | 2011-10-11 14:04:32 +0300 | [diff] [blame] | 559 | |
| 560 | if (opt & L2CAP_LM_RELIABLE) |
| 561 | set_bit(FLAG_FORCE_RELIABLE, &chan->flags); |
| 562 | else |
| 563 | clear_bit(FLAG_FORCE_RELIABLE, &chan->flags); |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 564 | break; |
| 565 | |
| 566 | default: |
| 567 | err = -ENOPROTOOPT; |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | release_sock(sk); |
| 572 | return err; |
| 573 | } |
| 574 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 575 | static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, |
| 576 | char __user *optval, unsigned int optlen) |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 577 | { |
| 578 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 579 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 580 | struct bt_security sec; |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 581 | struct bt_power pwr; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 582 | struct l2cap_conn *conn; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 583 | int len, err = 0; |
| 584 | u32 opt; |
| 585 | |
| 586 | BT_DBG("sk %p", sk); |
| 587 | |
| 588 | if (level == SOL_L2CAP) |
| 589 | return l2cap_sock_setsockopt_old(sock, optname, optval, optlen); |
| 590 | |
| 591 | if (level != SOL_BLUETOOTH) |
| 592 | return -ENOPROTOOPT; |
| 593 | |
| 594 | lock_sock(sk); |
| 595 | |
| 596 | switch (optname) { |
| 597 | case BT_SECURITY: |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 598 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 599 | chan->chan_type != L2CAP_CHAN_RAW) { |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 600 | err = -EINVAL; |
| 601 | break; |
| 602 | } |
| 603 | |
| 604 | sec.level = BT_SECURITY_LOW; |
| 605 | |
| 606 | len = min_t(unsigned int, sizeof(sec), optlen); |
| 607 | if (copy_from_user((char *) &sec, optval, len)) { |
| 608 | err = -EFAULT; |
| 609 | break; |
| 610 | } |
| 611 | |
| 612 | if (sec.level < BT_SECURITY_LOW || |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 613 | sec.level > BT_SECURITY_HIGH) { |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 614 | err = -EINVAL; |
| 615 | break; |
| 616 | } |
| 617 | |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 618 | chan->sec_level = sec.level; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 619 | |
Gustavo F. Padovan | 0bee1d6 | 2011-11-05 19:58:31 -0200 | [diff] [blame] | 620 | if (!chan->conn) |
| 621 | break; |
| 622 | |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 623 | conn = chan->conn; |
Gustavo F. Padovan | 0bee1d6 | 2011-11-05 19:58:31 -0200 | [diff] [blame] | 624 | |
| 625 | /*change security for LE channels */ |
| 626 | if (chan->scid == L2CAP_CID_LE_DATA) { |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 627 | if (!conn->hcon->out) { |
| 628 | err = -EINVAL; |
| 629 | break; |
| 630 | } |
| 631 | |
Vinicius Costa Gomes | cc11092 | 2012-08-23 21:32:43 -0300 | [diff] [blame] | 632 | if (smp_conn_security(conn->hcon, sec.level)) |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 633 | break; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 634 | sk->sk_state = BT_CONFIG; |
Gustavo F. Padovan | 3542b854 | 2011-12-28 13:54:17 -0200 | [diff] [blame] | 635 | chan->state = BT_CONFIG; |
Gustavo F. Padovan | 0bee1d6 | 2011-11-05 19:58:31 -0200 | [diff] [blame] | 636 | |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 637 | /* or for ACL link */ |
| 638 | } else if ((sk->sk_state == BT_CONNECT2 && |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 639 | test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) || |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 640 | sk->sk_state == BT_CONNECTED) { |
| 641 | if (!l2cap_chan_check_security(chan)) |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 642 | set_bit(BT_SK_SUSPEND, &bt_sk(sk)->flags); |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 643 | else |
| 644 | sk->sk_state_change(sk); |
Gustavo F. Padovan | 0bee1d6 | 2011-11-05 19:58:31 -0200 | [diff] [blame] | 645 | } else { |
| 646 | err = -EINVAL; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 647 | } |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 648 | break; |
| 649 | |
| 650 | case BT_DEFER_SETUP: |
| 651 | if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { |
| 652 | err = -EINVAL; |
| 653 | break; |
| 654 | } |
| 655 | |
| 656 | if (get_user(opt, (u32 __user *) optval)) { |
| 657 | err = -EFAULT; |
| 658 | break; |
| 659 | } |
| 660 | |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 661 | if (opt) |
| 662 | set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); |
| 663 | else |
| 664 | clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 665 | break; |
| 666 | |
| 667 | case BT_FLUSHABLE: |
| 668 | if (get_user(opt, (u32 __user *) optval)) { |
| 669 | err = -EFAULT; |
| 670 | break; |
| 671 | } |
| 672 | |
| 673 | if (opt > BT_FLUSHABLE_ON) { |
| 674 | err = -EINVAL; |
| 675 | break; |
| 676 | } |
| 677 | |
| 678 | if (opt == BT_FLUSHABLE_OFF) { |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 679 | struct l2cap_conn *conn = chan->conn; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 680 | /* proceed further only when we have l2cap_conn and |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 681 | No Flush support in the LM */ |
| 682 | if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) { |
| 683 | err = -EINVAL; |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | |
Andrei Emeltchenko | d57b0e8 | 2011-10-11 14:04:31 +0300 | [diff] [blame] | 688 | if (opt) |
| 689 | set_bit(FLAG_FLUSHABLE, &chan->flags); |
| 690 | else |
| 691 | clear_bit(FLAG_FLUSHABLE, &chan->flags); |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 692 | break; |
| 693 | |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 694 | case BT_POWER: |
| 695 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 696 | chan->chan_type != L2CAP_CHAN_RAW) { |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 697 | err = -EINVAL; |
| 698 | break; |
| 699 | } |
| 700 | |
| 701 | pwr.force_active = BT_POWER_FORCE_ACTIVE_ON; |
| 702 | |
| 703 | len = min_t(unsigned int, sizeof(pwr), optlen); |
| 704 | if (copy_from_user((char *) &pwr, optval, len)) { |
| 705 | err = -EFAULT; |
| 706 | break; |
| 707 | } |
Andrei Emeltchenko | 15770b1 | 2011-10-11 14:04:33 +0300 | [diff] [blame] | 708 | |
| 709 | if (pwr.force_active) |
| 710 | set_bit(FLAG_FORCE_ACTIVE, &chan->flags); |
| 711 | else |
| 712 | clear_bit(FLAG_FORCE_ACTIVE, &chan->flags); |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 713 | break; |
| 714 | |
Mat Martineau | 2ea6648 | 2011-11-02 16:18:30 -0700 | [diff] [blame] | 715 | case BT_CHANNEL_POLICY: |
| 716 | if (!enable_hs) { |
| 717 | err = -ENOPROTOOPT; |
| 718 | break; |
| 719 | } |
| 720 | |
| 721 | if (get_user(opt, (u32 __user *) optval)) { |
| 722 | err = -EFAULT; |
| 723 | break; |
| 724 | } |
| 725 | |
| 726 | if (opt > BT_CHANNEL_POLICY_AMP_PREFERRED) { |
| 727 | err = -EINVAL; |
| 728 | break; |
| 729 | } |
| 730 | |
| 731 | if (chan->mode != L2CAP_MODE_ERTM && |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 732 | chan->mode != L2CAP_MODE_STREAMING) { |
Mat Martineau | 2ea6648 | 2011-11-02 16:18:30 -0700 | [diff] [blame] | 733 | err = -EOPNOTSUPP; |
| 734 | break; |
| 735 | } |
| 736 | |
| 737 | chan->chan_policy = (u8) opt; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | default: |
| 741 | err = -ENOPROTOOPT; |
| 742 | break; |
| 743 | } |
| 744 | |
| 745 | release_sock(sk); |
| 746 | return err; |
| 747 | } |
| 748 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 749 | static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, |
| 750 | struct msghdr *msg, size_t len) |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 751 | { |
| 752 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 753 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 754 | int err; |
| 755 | |
| 756 | BT_DBG("sock %p, sk %p", sock, sk); |
| 757 | |
| 758 | err = sock_error(sk); |
| 759 | if (err) |
| 760 | return err; |
| 761 | |
| 762 | if (msg->msg_flags & MSG_OOB) |
| 763 | return -EOPNOTSUPP; |
| 764 | |
Mat Martineau | a6a5568 | 2012-05-04 14:20:31 -0700 | [diff] [blame] | 765 | if (sk->sk_state != BT_CONNECTED) |
Gustavo F. Padovan | 9a91a04 | 2011-04-28 18:50:17 -0300 | [diff] [blame] | 766 | return -ENOTCONN; |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 767 | |
Mat Martineau | a6a5568 | 2012-05-04 14:20:31 -0700 | [diff] [blame] | 768 | l2cap_chan_lock(chan); |
Luiz Augusto von Dentz | 5e59b79 | 2011-11-01 10:58:57 +0200 | [diff] [blame] | 769 | err = l2cap_chan_send(chan, msg, len, sk->sk_priority); |
Mat Martineau | a6a5568 | 2012-05-04 14:20:31 -0700 | [diff] [blame] | 770 | l2cap_chan_unlock(chan); |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 771 | |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 772 | return err; |
| 773 | } |
| 774 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 775 | static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, |
| 776 | struct msghdr *msg, size_t len, int flags) |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 777 | { |
| 778 | struct sock *sk = sock->sk; |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 779 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
| 780 | int err; |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 781 | |
| 782 | lock_sock(sk); |
| 783 | |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 784 | if (sk->sk_state == BT_CONNECT2 && test_bit(BT_SK_DEFER_SETUP, |
| 785 | &bt_sk(sk)->flags)) { |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 786 | sk->sk_state = BT_CONFIG; |
Gustavo F. Padovan | 3542b854 | 2011-12-28 13:54:17 -0200 | [diff] [blame] | 787 | pi->chan->state = BT_CONFIG; |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 788 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 789 | __l2cap_connect_rsp_defer(pi->chan); |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 790 | release_sock(sk); |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | release_sock(sk); |
| 795 | |
| 796 | if (sock->type == SOCK_STREAM) |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 797 | err = bt_sock_stream_recvmsg(iocb, sock, msg, len, flags); |
| 798 | else |
| 799 | err = bt_sock_recvmsg(iocb, sock, msg, len, flags); |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 800 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 801 | if (pi->chan->mode != L2CAP_MODE_ERTM) |
| 802 | return err; |
| 803 | |
| 804 | /* Attempt to put pending rx data in the socket buffer */ |
| 805 | |
| 806 | lock_sock(sk); |
| 807 | |
| 808 | if (!test_bit(CONN_LOCAL_BUSY, &pi->chan->conn_state)) |
| 809 | goto done; |
| 810 | |
| 811 | if (pi->rx_busy_skb) { |
| 812 | if (!sock_queue_rcv_skb(sk, pi->rx_busy_skb)) |
| 813 | pi->rx_busy_skb = NULL; |
| 814 | else |
| 815 | goto done; |
| 816 | } |
| 817 | |
| 818 | /* Restore data flow when half of the receive buffer is |
| 819 | * available. This avoids resending large numbers of |
| 820 | * frames. |
| 821 | */ |
| 822 | if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf >> 1) |
| 823 | l2cap_chan_busy(pi->chan, 0); |
| 824 | |
| 825 | done: |
| 826 | release_sock(sk); |
| 827 | return err; |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 828 | } |
| 829 | |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 830 | /* Kill socket (only if zapped and orphan) |
| 831 | * Must be called on unlocked socket. |
| 832 | */ |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 833 | static void l2cap_sock_kill(struct sock *sk) |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 834 | { |
| 835 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
| 836 | return; |
| 837 | |
Andrei Emeltchenko | e05dcc3 | 2012-02-17 11:40:56 +0200 | [diff] [blame] | 838 | BT_DBG("sk %p state %s", sk, state_to_string(sk->sk_state)); |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 839 | |
| 840 | /* Kill poor orphan */ |
Gustavo F. Padovan | 6ff5abb | 2011-04-25 15:10:41 -0300 | [diff] [blame] | 841 | |
Jaganath Kanakkassery | 4af66c6 | 2012-07-13 18:17:55 +0530 | [diff] [blame] | 842 | l2cap_chan_put(l2cap_pi(sk)->chan); |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 843 | sock_set_flag(sk, SOCK_DEAD); |
| 844 | sock_put(sk); |
| 845 | } |
| 846 | |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 847 | static int l2cap_sock_shutdown(struct socket *sock, int how) |
| 848 | { |
| 849 | struct sock *sk = sock->sk; |
Andrei Emeltchenko | 7ddb6e0 | 2012-02-14 15:12:57 +0200 | [diff] [blame] | 850 | struct l2cap_chan *chan; |
Andrei Emeltchenko | 3df91ea | 2012-02-21 12:54:55 +0200 | [diff] [blame] | 851 | struct l2cap_conn *conn; |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 852 | int err = 0; |
| 853 | |
| 854 | BT_DBG("sock %p, sk %p", sock, sk); |
| 855 | |
| 856 | if (!sk) |
| 857 | return 0; |
| 858 | |
Andrei Emeltchenko | 7ddb6e0 | 2012-02-14 15:12:57 +0200 | [diff] [blame] | 859 | chan = l2cap_pi(sk)->chan; |
Andrei Emeltchenko | 3df91ea | 2012-02-21 12:54:55 +0200 | [diff] [blame] | 860 | conn = chan->conn; |
| 861 | |
| 862 | if (conn) |
| 863 | mutex_lock(&conn->chan_lock); |
Andrei Emeltchenko | 7ddb6e0 | 2012-02-14 15:12:57 +0200 | [diff] [blame] | 864 | |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 865 | l2cap_chan_lock(chan); |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 866 | lock_sock(sk); |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 867 | |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 868 | if (!sk->sk_shutdown) { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 869 | if (chan->mode == L2CAP_MODE_ERTM) |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 870 | err = __l2cap_wait_ack(sk); |
| 871 | |
| 872 | sk->sk_shutdown = SHUTDOWN_MASK; |
Andrei Emeltchenko | 3df91ea | 2012-02-21 12:54:55 +0200 | [diff] [blame] | 873 | |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 874 | release_sock(sk); |
Gustavo F. Padovan | 0f85272 | 2011-05-04 19:42:50 -0300 | [diff] [blame] | 875 | l2cap_chan_close(chan, 0); |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 876 | lock_sock(sk); |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 877 | |
| 878 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) |
| 879 | err = bt_sock_wait_state(sk, BT_CLOSED, |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 880 | sk->sk_lingertime); |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | if (!err && sk->sk_err) |
| 884 | err = -sk->sk_err; |
| 885 | |
| 886 | release_sock(sk); |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 887 | l2cap_chan_unlock(chan); |
Andrei Emeltchenko | 3df91ea | 2012-02-21 12:54:55 +0200 | [diff] [blame] | 888 | |
| 889 | if (conn) |
| 890 | mutex_unlock(&conn->chan_lock); |
| 891 | |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 892 | return err; |
| 893 | } |
| 894 | |
Gustavo F. Padovan | 554f05b | 2011-02-04 02:36:42 -0200 | [diff] [blame] | 895 | static int l2cap_sock_release(struct socket *sock) |
| 896 | { |
| 897 | struct sock *sk = sock->sk; |
| 898 | int err; |
| 899 | |
| 900 | BT_DBG("sock %p, sk %p", sock, sk); |
| 901 | |
| 902 | if (!sk) |
| 903 | return 0; |
| 904 | |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 905 | bt_sock_unlink(&l2cap_sk_list, sk); |
| 906 | |
Gustavo F. Padovan | 554f05b | 2011-02-04 02:36:42 -0200 | [diff] [blame] | 907 | err = l2cap_sock_shutdown(sock, 2); |
| 908 | |
| 909 | sock_orphan(sk); |
| 910 | l2cap_sock_kill(sk); |
| 911 | return err; |
| 912 | } |
| 913 | |
Andrei Emeltchenko | c0df7f6 | 2012-05-27 22:27:52 -0300 | [diff] [blame] | 914 | static void l2cap_sock_cleanup_listen(struct sock *parent) |
| 915 | { |
| 916 | struct sock *sk; |
| 917 | |
| 918 | BT_DBG("parent %p", parent); |
| 919 | |
| 920 | /* Close not yet accepted channels */ |
| 921 | while ((sk = bt_accept_dequeue(parent, NULL))) { |
| 922 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
| 923 | |
| 924 | l2cap_chan_lock(chan); |
| 925 | __clear_chan_timer(chan); |
| 926 | l2cap_chan_close(chan, ECONNRESET); |
| 927 | l2cap_chan_unlock(chan); |
| 928 | |
| 929 | l2cap_sock_kill(sk); |
| 930 | } |
| 931 | } |
| 932 | |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 933 | static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan) |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 934 | { |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 935 | struct sock *sk, *parent = chan->data; |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 936 | |
Gustavo Padovan | 5382669 | 2012-05-27 22:27:55 -0300 | [diff] [blame] | 937 | /* Check for backlog size */ |
| 938 | if (sk_acceptq_is_full(parent)) { |
| 939 | BT_DBG("backlog full %d", parent->sk_ack_backlog); |
| 940 | return NULL; |
| 941 | } |
| 942 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 943 | sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP, |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 944 | GFP_ATOMIC); |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 945 | if (!sk) |
| 946 | return NULL; |
| 947 | |
Octavian Purdila | d22015a | 2012-01-22 00:28:34 +0200 | [diff] [blame] | 948 | bt_sock_reclassify_lock(sk, BTPROTO_L2CAP); |
| 949 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 950 | l2cap_sock_init(sk, parent); |
| 951 | |
Gustavo Padovan | 644912e | 2012-10-12 19:35:23 +0800 | [diff] [blame^] | 952 | bt_accept_enqueue(parent, sk); |
| 953 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 954 | return l2cap_pi(sk)->chan; |
| 955 | } |
| 956 | |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 957 | static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 958 | { |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 959 | int err; |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 960 | struct sock *sk = chan->data; |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 961 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 962 | |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 963 | lock_sock(sk); |
| 964 | |
| 965 | if (pi->rx_busy_skb) { |
| 966 | err = -ENOMEM; |
| 967 | goto done; |
| 968 | } |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 969 | |
| 970 | err = sock_queue_rcv_skb(sk, skb); |
| 971 | |
| 972 | /* For ERTM, handle one skb that doesn't fit into the recv |
| 973 | * buffer. This is important to do because the data frames |
| 974 | * have already been acked, so the skb cannot be discarded. |
| 975 | * |
| 976 | * Notify the l2cap core that the buffer is full, so the |
| 977 | * LOCAL_BUSY state is entered and no more frames are |
| 978 | * acked and reassembled until there is buffer space |
| 979 | * available. |
| 980 | */ |
| 981 | if (err < 0 && pi->chan->mode == L2CAP_MODE_ERTM) { |
| 982 | pi->rx_busy_skb = skb; |
| 983 | l2cap_chan_busy(pi->chan, 1); |
| 984 | err = 0; |
| 985 | } |
| 986 | |
Andrei Emeltchenko | 6be3655 | 2012-02-22 17:11:56 +0200 | [diff] [blame] | 987 | done: |
| 988 | release_sock(sk); |
| 989 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 990 | return err; |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 991 | } |
| 992 | |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 993 | static void l2cap_sock_close_cb(struct l2cap_chan *chan) |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 994 | { |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 995 | struct sock *sk = chan->data; |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 996 | |
| 997 | l2cap_sock_kill(sk); |
| 998 | } |
| 999 | |
Andrei Emeltchenko | c0df7f6 | 2012-05-27 22:27:52 -0300 | [diff] [blame] | 1000 | static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err) |
| 1001 | { |
| 1002 | struct sock *sk = chan->data; |
| 1003 | struct sock *parent; |
| 1004 | |
| 1005 | lock_sock(sk); |
| 1006 | |
| 1007 | parent = bt_sk(sk)->parent; |
| 1008 | |
| 1009 | sock_set_flag(sk, SOCK_ZAPPED); |
| 1010 | |
| 1011 | switch (chan->state) { |
| 1012 | case BT_OPEN: |
| 1013 | case BT_BOUND: |
| 1014 | case BT_CLOSED: |
| 1015 | break; |
| 1016 | case BT_LISTEN: |
| 1017 | l2cap_sock_cleanup_listen(sk); |
| 1018 | sk->sk_state = BT_CLOSED; |
| 1019 | chan->state = BT_CLOSED; |
| 1020 | |
| 1021 | break; |
| 1022 | default: |
| 1023 | sk->sk_state = BT_CLOSED; |
| 1024 | chan->state = BT_CLOSED; |
| 1025 | |
| 1026 | sk->sk_err = err; |
| 1027 | |
| 1028 | if (parent) { |
| 1029 | bt_accept_unlink(sk); |
| 1030 | parent->sk_data_ready(parent, 0); |
| 1031 | } else { |
| 1032 | sk->sk_state_change(sk); |
| 1033 | } |
| 1034 | |
| 1035 | break; |
| 1036 | } |
| 1037 | |
| 1038 | release_sock(sk); |
| 1039 | } |
| 1040 | |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 1041 | static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state) |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 1042 | { |
Gustavo Padovan | 80b9802 | 2012-05-27 22:27:51 -0300 | [diff] [blame] | 1043 | struct sock *sk = chan->data; |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 1044 | |
| 1045 | sk->sk_state = state; |
| 1046 | } |
| 1047 | |
Andrei Emeltchenko | 2f7719c | 2012-01-20 14:08:03 +0200 | [diff] [blame] | 1048 | static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan, |
Gustavo Padovan | 9033894 | 2012-04-06 20:15:47 -0300 | [diff] [blame] | 1049 | unsigned long len, int nb) |
Andrei Emeltchenko | 2f7719c | 2012-01-20 14:08:03 +0200 | [diff] [blame] | 1050 | { |
Gustavo Padovan | 9033894 | 2012-04-06 20:15:47 -0300 | [diff] [blame] | 1051 | struct sk_buff *skb; |
| 1052 | int err; |
Andrei Emeltchenko | 2f7719c | 2012-01-20 14:08:03 +0200 | [diff] [blame] | 1053 | |
Mat Martineau | a6a5568 | 2012-05-04 14:20:31 -0700 | [diff] [blame] | 1054 | l2cap_chan_unlock(chan); |
Gustavo Padovan | 9033894 | 2012-04-06 20:15:47 -0300 | [diff] [blame] | 1055 | skb = bt_skb_send_alloc(chan->sk, len, nb, &err); |
Mat Martineau | a6a5568 | 2012-05-04 14:20:31 -0700 | [diff] [blame] | 1056 | l2cap_chan_lock(chan); |
| 1057 | |
Gustavo Padovan | 9033894 | 2012-04-06 20:15:47 -0300 | [diff] [blame] | 1058 | if (!skb) |
| 1059 | return ERR_PTR(err); |
| 1060 | |
| 1061 | return skb; |
Andrei Emeltchenko | 2f7719c | 2012-01-20 14:08:03 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Andrei Emeltchenko | 54a59aa | 2012-05-27 22:27:53 -0300 | [diff] [blame] | 1064 | static void l2cap_sock_ready_cb(struct l2cap_chan *chan) |
| 1065 | { |
| 1066 | struct sock *sk = chan->data; |
| 1067 | struct sock *parent; |
| 1068 | |
| 1069 | lock_sock(sk); |
| 1070 | |
| 1071 | parent = bt_sk(sk)->parent; |
| 1072 | |
| 1073 | BT_DBG("sk %p, parent %p", sk, parent); |
| 1074 | |
| 1075 | sk->sk_state = BT_CONNECTED; |
| 1076 | sk->sk_state_change(sk); |
| 1077 | |
| 1078 | if (parent) |
| 1079 | parent->sk_data_ready(parent, 0); |
| 1080 | |
| 1081 | release_sock(sk); |
| 1082 | } |
| 1083 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 1084 | static struct l2cap_ops l2cap_chan_ops = { |
| 1085 | .name = "L2CAP Socket Interface", |
| 1086 | .new_connection = l2cap_sock_new_connection_cb, |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 1087 | .recv = l2cap_sock_recv_cb, |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 1088 | .close = l2cap_sock_close_cb, |
Andrei Emeltchenko | c0df7f6 | 2012-05-27 22:27:52 -0300 | [diff] [blame] | 1089 | .teardown = l2cap_sock_teardown_cb, |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 1090 | .state_change = l2cap_sock_state_change_cb, |
Andrei Emeltchenko | 54a59aa | 2012-05-27 22:27:53 -0300 | [diff] [blame] | 1091 | .ready = l2cap_sock_ready_cb, |
Andrei Emeltchenko | 2f7719c | 2012-01-20 14:08:03 +0200 | [diff] [blame] | 1092 | .alloc_skb = l2cap_sock_alloc_skb_cb, |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 1093 | }; |
| 1094 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1095 | static void l2cap_sock_destruct(struct sock *sk) |
| 1096 | { |
| 1097 | BT_DBG("sk %p", sk); |
| 1098 | |
Sasha Levin | 23d3a86 | 2012-10-08 16:48:32 -0400 | [diff] [blame] | 1099 | if (l2cap_pi(sk)->chan) |
| 1100 | l2cap_chan_put(l2cap_pi(sk)->chan); |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 1101 | if (l2cap_pi(sk)->rx_busy_skb) { |
| 1102 | kfree_skb(l2cap_pi(sk)->rx_busy_skb); |
| 1103 | l2cap_pi(sk)->rx_busy_skb = NULL; |
| 1104 | } |
| 1105 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1106 | skb_queue_purge(&sk->sk_receive_queue); |
| 1107 | skb_queue_purge(&sk->sk_write_queue); |
| 1108 | } |
| 1109 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 1110 | static void l2cap_sock_init(struct sock *sk, struct sock *parent) |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1111 | { |
| 1112 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 1113 | struct l2cap_chan *chan = pi->chan; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1114 | |
| 1115 | BT_DBG("sk %p", sk); |
| 1116 | |
| 1117 | if (parent) { |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 1118 | struct l2cap_chan *pchan = l2cap_pi(parent)->chan; |
| 1119 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1120 | sk->sk_type = parent->sk_type; |
Gustavo Padovan | c5daa68 | 2012-05-16 12:17:10 -0300 | [diff] [blame] | 1121 | bt_sk(sk)->flags = bt_sk(parent)->flags; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1122 | |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 1123 | chan->chan_type = pchan->chan_type; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 1124 | chan->imtu = pchan->imtu; |
| 1125 | chan->omtu = pchan->omtu; |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 1126 | chan->conf_state = pchan->conf_state; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 1127 | chan->mode = pchan->mode; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 1128 | chan->fcs = pchan->fcs; |
| 1129 | chan->max_tx = pchan->max_tx; |
| 1130 | chan->tx_win = pchan->tx_win; |
Andrei Emeltchenko | 6b3c710 | 2011-11-02 09:57:10 +0200 | [diff] [blame] | 1131 | chan->tx_win_max = pchan->tx_win_max; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 1132 | chan->sec_level = pchan->sec_level; |
Andrei Emeltchenko | d57b0e8 | 2011-10-11 14:04:31 +0300 | [diff] [blame] | 1133 | chan->flags = pchan->flags; |
Paul Moore | 6230c9b | 2011-10-07 09:40:59 +0000 | [diff] [blame] | 1134 | |
| 1135 | security_sk_clone(parent, sk); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1136 | } else { |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 1137 | |
| 1138 | switch (sk->sk_type) { |
| 1139 | case SOCK_RAW: |
| 1140 | chan->chan_type = L2CAP_CHAN_RAW; |
| 1141 | break; |
| 1142 | case SOCK_DGRAM: |
| 1143 | chan->chan_type = L2CAP_CHAN_CONN_LESS; |
| 1144 | break; |
| 1145 | case SOCK_SEQPACKET: |
| 1146 | case SOCK_STREAM: |
| 1147 | chan->chan_type = L2CAP_CHAN_CONN_ORIENTED; |
| 1148 | break; |
| 1149 | } |
| 1150 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 1151 | chan->imtu = L2CAP_DEFAULT_MTU; |
| 1152 | chan->omtu = 0; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1153 | if (!disable_ertm && sk->sk_type == SOCK_STREAM) { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 1154 | chan->mode = L2CAP_MODE_ERTM; |
Gustavo F. Padovan | c1360a1 | 2011-06-10 17:02:12 -0300 | [diff] [blame] | 1155 | set_bit(CONF_STATE2_DEVICE, &chan->conf_state); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1156 | } else { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 1157 | chan->mode = L2CAP_MODE_BASIC; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1158 | } |
Andrei Emeltchenko | bd4b165 | 2012-03-28 16:31:25 +0300 | [diff] [blame] | 1159 | |
| 1160 | l2cap_chan_set_defaults(chan); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /* Default config options */ |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 1164 | chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 1165 | |
| 1166 | chan->data = sk; |
| 1167 | chan->ops = &l2cap_chan_ops; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | static struct proto l2cap_proto = { |
| 1171 | .name = "L2CAP", |
| 1172 | .owner = THIS_MODULE, |
| 1173 | .obj_size = sizeof(struct l2cap_pinfo) |
| 1174 | }; |
| 1175 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 1176 | static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, |
| 1177 | int proto, gfp_t prio) |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1178 | { |
| 1179 | struct sock *sk; |
Gustavo F. Padovan | dc50a06 | 2011-05-16 16:42:01 -0300 | [diff] [blame] | 1180 | struct l2cap_chan *chan; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1181 | |
| 1182 | sk = sk_alloc(net, PF_BLUETOOTH, prio, &l2cap_proto); |
| 1183 | if (!sk) |
| 1184 | return NULL; |
| 1185 | |
| 1186 | sock_init_data(sock, sk); |
| 1187 | INIT_LIST_HEAD(&bt_sk(sk)->accept_q); |
| 1188 | |
| 1189 | sk->sk_destruct = l2cap_sock_destruct; |
Marcel Holtmann | ba13ccd | 2012-03-01 14:25:33 -0800 | [diff] [blame] | 1190 | sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1191 | |
| 1192 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 1193 | |
| 1194 | sk->sk_protocol = proto; |
| 1195 | sk->sk_state = BT_OPEN; |
| 1196 | |
Gustavo Padovan | eef1d9b | 2012-03-25 13:59:16 -0300 | [diff] [blame] | 1197 | chan = l2cap_chan_create(); |
Gustavo F. Padovan | dc50a06 | 2011-05-16 16:42:01 -0300 | [diff] [blame] | 1198 | if (!chan) { |
Jaganath Kanakkassery | 49dfbb9 | 2012-07-19 12:54:04 +0530 | [diff] [blame] | 1199 | sk_free(sk); |
Gustavo F. Padovan | dc50a06 | 2011-05-16 16:42:01 -0300 | [diff] [blame] | 1200 | return NULL; |
| 1201 | } |
| 1202 | |
Mat Martineau | 61d6ef3 | 2012-04-27 16:50:50 -0700 | [diff] [blame] | 1203 | l2cap_chan_hold(chan); |
| 1204 | |
Gustavo Padovan | eef1d9b | 2012-03-25 13:59:16 -0300 | [diff] [blame] | 1205 | chan->sk = sk; |
| 1206 | |
Gustavo F. Padovan | dc50a06 | 2011-05-16 16:42:01 -0300 | [diff] [blame] | 1207 | l2cap_pi(sk)->chan = chan; |
| 1208 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1209 | return sk; |
| 1210 | } |
| 1211 | |
| 1212 | static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol, |
| 1213 | int kern) |
| 1214 | { |
| 1215 | struct sock *sk; |
| 1216 | |
| 1217 | BT_DBG("sock %p", sock); |
| 1218 | |
| 1219 | sock->state = SS_UNCONNECTED; |
| 1220 | |
| 1221 | if (sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM && |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 1222 | sock->type != SOCK_DGRAM && sock->type != SOCK_RAW) |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1223 | return -ESOCKTNOSUPPORT; |
| 1224 | |
| 1225 | if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW)) |
| 1226 | return -EPERM; |
| 1227 | |
| 1228 | sock->ops = &l2cap_sock_ops; |
| 1229 | |
| 1230 | sk = l2cap_sock_alloc(net, sock, protocol, GFP_ATOMIC); |
| 1231 | if (!sk) |
| 1232 | return -ENOMEM; |
| 1233 | |
| 1234 | l2cap_sock_init(sk, NULL); |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 1235 | bt_sock_link(&l2cap_sk_list, sk); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1236 | return 0; |
| 1237 | } |
| 1238 | |
Gustavo F. Padovan | cf2f90f | 2011-04-27 18:40:39 -0300 | [diff] [blame] | 1239 | static const struct proto_ops l2cap_sock_ops = { |
Gustavo F. Padovan | 6539058 | 2011-02-04 02:33:56 -0200 | [diff] [blame] | 1240 | .family = PF_BLUETOOTH, |
| 1241 | .owner = THIS_MODULE, |
| 1242 | .release = l2cap_sock_release, |
| 1243 | .bind = l2cap_sock_bind, |
| 1244 | .connect = l2cap_sock_connect, |
| 1245 | .listen = l2cap_sock_listen, |
| 1246 | .accept = l2cap_sock_accept, |
| 1247 | .getname = l2cap_sock_getname, |
| 1248 | .sendmsg = l2cap_sock_sendmsg, |
| 1249 | .recvmsg = l2cap_sock_recvmsg, |
| 1250 | .poll = bt_sock_poll, |
| 1251 | .ioctl = bt_sock_ioctl, |
| 1252 | .mmap = sock_no_mmap, |
| 1253 | .socketpair = sock_no_socketpair, |
| 1254 | .shutdown = l2cap_sock_shutdown, |
| 1255 | .setsockopt = l2cap_sock_setsockopt, |
| 1256 | .getsockopt = l2cap_sock_getsockopt |
| 1257 | }; |
| 1258 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1259 | static const struct net_proto_family l2cap_sock_family_ops = { |
| 1260 | .family = PF_BLUETOOTH, |
| 1261 | .owner = THIS_MODULE, |
| 1262 | .create = l2cap_sock_create, |
| 1263 | }; |
| 1264 | |
| 1265 | int __init l2cap_init_sockets(void) |
| 1266 | { |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1267 | int err; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1268 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1269 | err = proto_register(&l2cap_proto, 0); |
| 1270 | if (err < 0) |
| 1271 | return err; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1272 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1273 | err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops); |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 1274 | if (err < 0) { |
| 1275 | BT_ERR("L2CAP socket registration failed"); |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1276 | goto error; |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 1277 | } |
| 1278 | |
Gustavo Padovan | 2d79281 | 2012-10-06 10:07:01 +0100 | [diff] [blame] | 1279 | err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list, |
| 1280 | NULL); |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 1281 | if (err < 0) { |
| 1282 | BT_ERR("Failed to create L2CAP proc file"); |
| 1283 | bt_sock_unregister(BTPROTO_L2CAP); |
| 1284 | goto error; |
| 1285 | } |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1286 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1287 | BT_INFO("L2CAP socket layer initialized"); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1288 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1289 | return 0; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1290 | |
| 1291 | error: |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1292 | proto_unregister(&l2cap_proto); |
| 1293 | return err; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | void l2cap_cleanup_sockets(void) |
| 1297 | { |
Masatake YAMATO | 5b28d95 | 2012-07-26 01:29:25 +0900 | [diff] [blame] | 1298 | bt_procfs_cleanup(&init_net, "l2cap"); |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1299 | if (bt_sock_unregister(BTPROTO_L2CAP) < 0) |
| 1300 | BT_ERR("L2CAP socket unregistration failed"); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1301 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1302 | proto_unregister(&l2cap_proto); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1303 | } |