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. |
| 6 | |
| 7 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License version 2 as |
| 11 | published by the Free Software Foundation; |
| 12 | |
| 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 14 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 16 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
| 17 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 18 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 19 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 20 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | |
| 22 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 23 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
| 24 | SOFTWARE IS DISCLAIMED. |
| 25 | */ |
| 26 | |
| 27 | /* Bluetooth L2CAP sockets. */ |
| 28 | |
Paul Moore | 6230c9b | 2011-10-07 09:40:59 +0000 | [diff] [blame] | 29 | #include <linux/security.h> |
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 | |
Gustavo F. Padovan | cf2f90f | 2011-04-27 18:40:39 -0300 | [diff] [blame] | 37 | static const struct proto_ops l2cap_sock_ops; |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 38 | static void l2cap_sock_init(struct sock *sk, struct sock *parent); |
| 39 | static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio); |
Gustavo F. Padovan | cf2f90f | 2011-04-27 18:40:39 -0300 | [diff] [blame] | 40 | |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 41 | static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) |
| 42 | { |
| 43 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 44 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 45 | struct sockaddr_l2 la; |
| 46 | int len, err = 0; |
| 47 | |
| 48 | BT_DBG("sk %p", sk); |
| 49 | |
| 50 | if (!addr || addr->sa_family != AF_BLUETOOTH) |
| 51 | return -EINVAL; |
| 52 | |
| 53 | memset(&la, 0, sizeof(la)); |
| 54 | len = min_t(unsigned int, sizeof(la), alen); |
| 55 | memcpy(&la, addr, len); |
| 56 | |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 57 | if (la.l2_cid && la.l2_psm) |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 58 | return -EINVAL; |
| 59 | |
| 60 | lock_sock(sk); |
| 61 | |
| 62 | if (sk->sk_state != BT_OPEN) { |
| 63 | err = -EBADFD; |
| 64 | goto done; |
| 65 | } |
| 66 | |
| 67 | if (la.l2_psm) { |
| 68 | __u16 psm = __le16_to_cpu(la.l2_psm); |
| 69 | |
| 70 | /* PSM must be odd and lsb of upper byte must be 0 */ |
| 71 | if ((psm & 0x0101) != 0x0001) { |
| 72 | err = -EINVAL; |
| 73 | goto done; |
| 74 | } |
| 75 | |
| 76 | /* Restrict usage of well-known PSMs */ |
| 77 | if (psm < 0x1001 && !capable(CAP_NET_BIND_SERVICE)) { |
| 78 | err = -EACCES; |
| 79 | goto done; |
| 80 | } |
| 81 | } |
| 82 | |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 83 | if (la.l2_cid) |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 84 | err = l2cap_add_scid(chan, la.l2_cid); |
| 85 | else |
| 86 | err = l2cap_add_psm(chan, &la.l2_bdaddr, la.l2_psm); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 87 | |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 88 | if (err < 0) |
| 89 | goto done; |
| 90 | |
| 91 | if (__le16_to_cpu(la.l2_psm) == 0x0001 || |
| 92 | __le16_to_cpu(la.l2_psm) == 0x0003) |
| 93 | chan->sec_level = BT_SECURITY_SDP; |
| 94 | |
| 95 | bacpy(&bt_sk(sk)->src, &la.l2_bdaddr); |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 96 | |
| 97 | chan->state = BT_BOUND; |
Gustavo F. Padovan | 9e4425f | 2011-04-18 18:38:43 -0300 | [diff] [blame] | 98 | sk->sk_state = BT_BOUND; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 99 | |
| 100 | done: |
| 101 | release_sock(sk); |
| 102 | return err; |
| 103 | } |
| 104 | |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 105 | static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags) |
| 106 | { |
| 107 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 108 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 109 | struct sockaddr_l2 la; |
| 110 | int len, err = 0; |
| 111 | |
| 112 | BT_DBG("sk %p", sk); |
| 113 | |
| 114 | if (!addr || alen < sizeof(addr->sa_family) || |
| 115 | addr->sa_family != AF_BLUETOOTH) |
| 116 | return -EINVAL; |
| 117 | |
| 118 | memset(&la, 0, sizeof(la)); |
| 119 | len = min_t(unsigned int, sizeof(la), alen); |
| 120 | memcpy(&la, addr, len); |
| 121 | |
Ville Tervo | acd7d37 | 2011-02-10 22:38:49 -0300 | [diff] [blame] | 122 | if (la.l2_cid && la.l2_psm) |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | |
| 125 | lock_sock(sk); |
| 126 | |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 127 | if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED |
Ville Tervo | acd7d37 | 2011-02-10 22:38:49 -0300 | [diff] [blame] | 128 | && !(la.l2_psm || la.l2_cid)) { |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 129 | err = -EINVAL; |
| 130 | goto done; |
| 131 | } |
| 132 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 133 | switch (chan->mode) { |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 134 | case L2CAP_MODE_BASIC: |
| 135 | break; |
| 136 | case L2CAP_MODE_ERTM: |
| 137 | case L2CAP_MODE_STREAMING: |
| 138 | if (!disable_ertm) |
| 139 | break; |
| 140 | /* fall through */ |
| 141 | default: |
| 142 | err = -ENOTSUPP; |
| 143 | goto done; |
| 144 | } |
| 145 | |
| 146 | switch (sk->sk_state) { |
| 147 | case BT_CONNECT: |
| 148 | case BT_CONNECT2: |
| 149 | case BT_CONFIG: |
| 150 | /* Already connecting */ |
| 151 | goto wait; |
| 152 | |
| 153 | case BT_CONNECTED: |
| 154 | /* Already connected */ |
| 155 | err = -EISCONN; |
| 156 | goto done; |
| 157 | |
| 158 | case BT_OPEN: |
| 159 | case BT_BOUND: |
| 160 | /* Can connect */ |
| 161 | break; |
| 162 | |
| 163 | default: |
| 164 | err = -EBADFD; |
| 165 | goto done; |
| 166 | } |
| 167 | |
| 168 | /* PSM must be odd and lsb of upper byte must be 0 */ |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 169 | if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 && !la.l2_cid && |
| 170 | chan->chan_type != L2CAP_CHAN_RAW) { |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 171 | err = -EINVAL; |
| 172 | goto done; |
| 173 | } |
| 174 | |
| 175 | /* Set destination address and psm */ |
| 176 | bacpy(&bt_sk(sk)->dst, &la.l2_bdaddr); |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 177 | chan->psm = la.l2_psm; |
| 178 | chan->dcid = la.l2_cid; |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 179 | |
Gustavo F. Padovan | 77a74c7 | 2011-04-12 18:17:14 -0300 | [diff] [blame] | 180 | err = l2cap_chan_connect(l2cap_pi(sk)->chan); |
Gustavo F. Padovan | 4e34c50 | 2011-02-04 02:56:13 -0200 | [diff] [blame] | 181 | if (err) |
| 182 | goto done; |
| 183 | |
| 184 | wait: |
| 185 | err = bt_sock_wait_state(sk, BT_CONNECTED, |
| 186 | sock_sndtimeo(sk, flags & O_NONBLOCK)); |
| 187 | done: |
| 188 | release_sock(sk); |
| 189 | return err; |
| 190 | } |
| 191 | |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 192 | static int l2cap_sock_listen(struct socket *sock, int backlog) |
| 193 | { |
| 194 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 195 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 196 | int err = 0; |
| 197 | |
| 198 | BT_DBG("sk %p backlog %d", sk, backlog); |
| 199 | |
| 200 | lock_sock(sk); |
| 201 | |
| 202 | if ((sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM) |
| 203 | || sk->sk_state != BT_BOUND) { |
| 204 | err = -EBADFD; |
| 205 | goto done; |
| 206 | } |
| 207 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 208 | switch (chan->mode) { |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 209 | case L2CAP_MODE_BASIC: |
| 210 | break; |
| 211 | case L2CAP_MODE_ERTM: |
| 212 | case L2CAP_MODE_STREAMING: |
| 213 | if (!disable_ertm) |
| 214 | break; |
| 215 | /* fall through */ |
| 216 | default: |
| 217 | err = -ENOTSUPP; |
| 218 | goto done; |
| 219 | } |
| 220 | |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 221 | sk->sk_max_ack_backlog = backlog; |
| 222 | sk->sk_ack_backlog = 0; |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 223 | |
| 224 | chan->state = BT_LISTEN; |
Gustavo F. Padovan | af6bcd8 | 2011-02-04 02:40:28 -0200 | [diff] [blame] | 225 | sk->sk_state = BT_LISTEN; |
| 226 | |
| 227 | done: |
| 228 | release_sock(sk); |
| 229 | return err; |
| 230 | } |
| 231 | |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 232 | static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, int flags) |
| 233 | { |
| 234 | DECLARE_WAITQUEUE(wait, current); |
| 235 | struct sock *sk = sock->sk, *nsk; |
| 236 | long timeo; |
| 237 | int err = 0; |
| 238 | |
| 239 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
| 240 | |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 241 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 242 | |
| 243 | BT_DBG("sk %p timeo %ld", sk, timeo); |
| 244 | |
| 245 | /* Wait for an incoming connection. (wake-one). */ |
| 246 | add_wait_queue_exclusive(sk_sleep(sk), &wait); |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 247 | while (1) { |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 248 | set_current_state(TASK_INTERRUPTIBLE); |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 249 | |
| 250 | if (sk->sk_state != BT_LISTEN) { |
| 251 | err = -EBADFD; |
| 252 | break; |
| 253 | } |
| 254 | |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 255 | nsk = bt_accept_dequeue(sk, newsock); |
| 256 | if (nsk) |
| 257 | break; |
| 258 | |
| 259 | if (!timeo) { |
| 260 | err = -EAGAIN; |
| 261 | break; |
| 262 | } |
| 263 | |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 264 | if (signal_pending(current)) { |
| 265 | err = sock_intr_errno(timeo); |
| 266 | break; |
| 267 | } |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 268 | |
| 269 | release_sock(sk); |
| 270 | timeo = schedule_timeout(timeo); |
| 271 | lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 272 | } |
Peter Hurley | f9a3c20 | 2011-07-24 00:10:52 -0400 | [diff] [blame] | 273 | __set_current_state(TASK_RUNNING); |
Gustavo F. Padovan | c47b7c7 | 2011-02-04 02:42:23 -0200 | [diff] [blame] | 274 | remove_wait_queue(sk_sleep(sk), &wait); |
| 275 | |
| 276 | if (err) |
| 277 | goto done; |
| 278 | |
| 279 | newsock->state = SS_CONNECTED; |
| 280 | |
| 281 | BT_DBG("new socket %p", nsk); |
| 282 | |
| 283 | done: |
| 284 | release_sock(sk); |
| 285 | return err; |
| 286 | } |
| 287 | |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 288 | static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *len, int peer) |
| 289 | { |
| 290 | struct sockaddr_l2 *la = (struct sockaddr_l2 *) addr; |
| 291 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 292 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 293 | |
| 294 | BT_DBG("sock %p, sk %p", sock, sk); |
| 295 | |
| 296 | addr->sa_family = AF_BLUETOOTH; |
| 297 | *len = sizeof(struct sockaddr_l2); |
| 298 | |
| 299 | if (peer) { |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 300 | la->l2_psm = chan->psm; |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 301 | bacpy(&la->l2_bdaddr, &bt_sk(sk)->dst); |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 302 | la->l2_cid = cpu_to_le16(chan->dcid); |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 303 | } else { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 304 | la->l2_psm = chan->sport; |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 305 | bacpy(&la->l2_bdaddr, &bt_sk(sk)->src); |
Gustavo F. Padovan | fe4128e | 2011-04-13 19:50:45 -0300 | [diff] [blame] | 306 | la->l2_cid = cpu_to_le16(chan->scid); |
Gustavo F. Padovan | d7175d5 | 2011-02-04 02:43:46 -0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 312 | static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen) |
| 313 | { |
| 314 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 315 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 316 | struct l2cap_options opts; |
| 317 | struct l2cap_conninfo cinfo; |
| 318 | int len, err = 0; |
| 319 | u32 opt; |
| 320 | |
| 321 | BT_DBG("sk %p", sk); |
| 322 | |
| 323 | if (get_user(len, optlen)) |
| 324 | return -EFAULT; |
| 325 | |
| 326 | lock_sock(sk); |
| 327 | |
| 328 | switch (optname) { |
| 329 | case L2CAP_OPTIONS: |
Vasiliy Kulikov | e3fb592 | 2011-02-10 20:59:42 +0300 | [diff] [blame] | 330 | memset(&opts, 0, sizeof(opts)); |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 331 | opts.imtu = chan->imtu; |
| 332 | opts.omtu = chan->omtu; |
| 333 | opts.flush_to = chan->flush_to; |
| 334 | opts.mode = chan->mode; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 335 | opts.fcs = chan->fcs; |
| 336 | opts.max_tx = chan->max_tx; |
| 337 | opts.txwin_size = (__u16)chan->tx_win; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 338 | |
| 339 | len = min_t(unsigned int, len, sizeof(opts)); |
| 340 | if (copy_to_user(optval, (char *) &opts, len)) |
| 341 | err = -EFAULT; |
| 342 | |
| 343 | break; |
| 344 | |
| 345 | case L2CAP_LM: |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 346 | switch (chan->sec_level) { |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 347 | case BT_SECURITY_LOW: |
| 348 | opt = L2CAP_LM_AUTH; |
| 349 | break; |
| 350 | case BT_SECURITY_MEDIUM: |
| 351 | opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT; |
| 352 | break; |
| 353 | case BT_SECURITY_HIGH: |
| 354 | opt = L2CAP_LM_AUTH | L2CAP_LM_ENCRYPT | |
| 355 | L2CAP_LM_SECURE; |
| 356 | break; |
| 357 | default: |
| 358 | opt = 0; |
| 359 | break; |
| 360 | } |
| 361 | |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 362 | if (chan->role_switch) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 363 | opt |= L2CAP_LM_MASTER; |
| 364 | |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 365 | if (chan->force_reliable) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 366 | opt |= L2CAP_LM_RELIABLE; |
| 367 | |
| 368 | if (put_user(opt, (u32 __user *) optval)) |
| 369 | err = -EFAULT; |
| 370 | break; |
| 371 | |
| 372 | case L2CAP_CONNINFO: |
| 373 | if (sk->sk_state != BT_CONNECTED && |
| 374 | !(sk->sk_state == BT_CONNECT2 && |
| 375 | bt_sk(sk)->defer_setup)) { |
| 376 | err = -ENOTCONN; |
| 377 | break; |
| 378 | } |
| 379 | |
Filip Palian | 8d03e97 | 2011-05-12 19:32:46 +0200 | [diff] [blame] | 380 | memset(&cinfo, 0, sizeof(cinfo)); |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 381 | cinfo.hci_handle = chan->conn->hcon->handle; |
| 382 | memcpy(cinfo.dev_class, chan->conn->hcon->dev_class, 3); |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 383 | |
| 384 | len = min_t(unsigned int, len, sizeof(cinfo)); |
| 385 | if (copy_to_user(optval, (char *) &cinfo, len)) |
| 386 | err = -EFAULT; |
| 387 | |
| 388 | break; |
| 389 | |
| 390 | default: |
| 391 | err = -ENOPROTOOPT; |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | release_sock(sk); |
| 396 | return err; |
| 397 | } |
| 398 | |
| 399 | static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen) |
| 400 | { |
| 401 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 402 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 403 | struct bt_security sec; |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 404 | struct bt_power pwr; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 405 | int len, err = 0; |
| 406 | |
| 407 | BT_DBG("sk %p", sk); |
| 408 | |
| 409 | if (level == SOL_L2CAP) |
| 410 | return l2cap_sock_getsockopt_old(sock, optname, optval, optlen); |
| 411 | |
| 412 | if (level != SOL_BLUETOOTH) |
| 413 | return -ENOPROTOOPT; |
| 414 | |
| 415 | if (get_user(len, optlen)) |
| 416 | return -EFAULT; |
| 417 | |
| 418 | lock_sock(sk); |
| 419 | |
| 420 | switch (optname) { |
| 421 | case BT_SECURITY: |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 422 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
| 423 | chan->chan_type != L2CAP_CHAN_RAW) { |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 424 | err = -EINVAL; |
| 425 | break; |
| 426 | } |
| 427 | |
Vinicius Costa Gomes | 8f36011 | 2011-07-08 18:31:46 -0300 | [diff] [blame] | 428 | memset(&sec, 0, sizeof(sec)); |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 429 | sec.level = chan->sec_level; |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 430 | |
Vinicius Costa Gomes | 8f36011 | 2011-07-08 18:31:46 -0300 | [diff] [blame] | 431 | if (sk->sk_state == BT_CONNECTED) |
| 432 | sec.key_size = chan->conn->hcon->enc_key_size; |
| 433 | |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 434 | len = min_t(unsigned int, len, sizeof(sec)); |
| 435 | if (copy_to_user(optval, (char *) &sec, len)) |
| 436 | err = -EFAULT; |
| 437 | |
| 438 | break; |
| 439 | |
| 440 | case BT_DEFER_SETUP: |
| 441 | if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { |
| 442 | err = -EINVAL; |
| 443 | break; |
| 444 | } |
| 445 | |
| 446 | if (put_user(bt_sk(sk)->defer_setup, (u32 __user *) optval)) |
| 447 | err = -EFAULT; |
| 448 | |
| 449 | break; |
| 450 | |
| 451 | case BT_FLUSHABLE: |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 452 | if (put_user(chan->flushable, (u32 __user *) optval)) |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 453 | err = -EFAULT; |
| 454 | |
| 455 | break; |
| 456 | |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 457 | case BT_POWER: |
| 458 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM |
| 459 | && sk->sk_type != SOCK_RAW) { |
| 460 | err = -EINVAL; |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | pwr.force_active = chan->force_active; |
| 465 | |
| 466 | len = min_t(unsigned int, len, sizeof(pwr)); |
| 467 | if (copy_to_user(optval, (char *) &pwr, len)) |
| 468 | err = -EFAULT; |
| 469 | |
| 470 | break; |
| 471 | |
Gustavo F. Padovan | 99f4808 | 2011-02-04 02:52:55 -0200 | [diff] [blame] | 472 | default: |
| 473 | err = -ENOPROTOOPT; |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | release_sock(sk); |
| 478 | return err; |
| 479 | } |
| 480 | |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 481 | static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen) |
| 482 | { |
| 483 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 484 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 485 | struct l2cap_options opts; |
| 486 | int len, err = 0; |
| 487 | u32 opt; |
| 488 | |
| 489 | BT_DBG("sk %p", sk); |
| 490 | |
| 491 | lock_sock(sk); |
| 492 | |
| 493 | switch (optname) { |
| 494 | case L2CAP_OPTIONS: |
| 495 | if (sk->sk_state == BT_CONNECTED) { |
| 496 | err = -EINVAL; |
| 497 | break; |
| 498 | } |
| 499 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 500 | opts.imtu = chan->imtu; |
| 501 | opts.omtu = chan->omtu; |
| 502 | opts.flush_to = chan->flush_to; |
| 503 | opts.mode = chan->mode; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 504 | opts.fcs = chan->fcs; |
| 505 | opts.max_tx = chan->max_tx; |
| 506 | opts.txwin_size = (__u16)chan->tx_win; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 507 | |
| 508 | len = min_t(unsigned int, sizeof(opts), optlen); |
| 509 | if (copy_from_user((char *) &opts, optval, len)) { |
| 510 | err = -EFAULT; |
| 511 | break; |
| 512 | } |
| 513 | |
| 514 | if (opts.txwin_size > L2CAP_DEFAULT_TX_WINDOW) { |
| 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; |
| 538 | chan->tx_win = (__u8)opts.txwin_size; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | case L2CAP_LM: |
| 542 | if (get_user(opt, (u32 __user *) optval)) { |
| 543 | err = -EFAULT; |
| 544 | break; |
| 545 | } |
| 546 | |
| 547 | if (opt & L2CAP_LM_AUTH) |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 548 | chan->sec_level = BT_SECURITY_LOW; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 549 | if (opt & L2CAP_LM_ENCRYPT) |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 550 | chan->sec_level = BT_SECURITY_MEDIUM; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 551 | if (opt & L2CAP_LM_SECURE) |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 552 | chan->sec_level = BT_SECURITY_HIGH; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 553 | |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 554 | chan->role_switch = (opt & L2CAP_LM_MASTER); |
| 555 | chan->force_reliable = (opt & L2CAP_LM_RELIABLE); |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 556 | break; |
| 557 | |
| 558 | default: |
| 559 | err = -ENOPROTOOPT; |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | release_sock(sk); |
| 564 | return err; |
| 565 | } |
| 566 | |
| 567 | static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen) |
| 568 | { |
| 569 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 570 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 571 | struct bt_security sec; |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 572 | struct bt_power pwr; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 573 | struct l2cap_conn *conn; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 574 | int len, err = 0; |
| 575 | u32 opt; |
| 576 | |
| 577 | BT_DBG("sk %p", sk); |
| 578 | |
| 579 | if (level == SOL_L2CAP) |
| 580 | return l2cap_sock_setsockopt_old(sock, optname, optval, optlen); |
| 581 | |
| 582 | if (level != SOL_BLUETOOTH) |
| 583 | return -ENOPROTOOPT; |
| 584 | |
| 585 | lock_sock(sk); |
| 586 | |
| 587 | switch (optname) { |
| 588 | case BT_SECURITY: |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 589 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
| 590 | chan->chan_type != L2CAP_CHAN_RAW) { |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 591 | err = -EINVAL; |
| 592 | break; |
| 593 | } |
| 594 | |
| 595 | sec.level = BT_SECURITY_LOW; |
| 596 | |
| 597 | len = min_t(unsigned int, sizeof(sec), optlen); |
| 598 | if (copy_from_user((char *) &sec, optval, len)) { |
| 599 | err = -EFAULT; |
| 600 | break; |
| 601 | } |
| 602 | |
| 603 | if (sec.level < BT_SECURITY_LOW || |
| 604 | sec.level > BT_SECURITY_HIGH) { |
| 605 | err = -EINVAL; |
| 606 | break; |
| 607 | } |
| 608 | |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 609 | chan->sec_level = sec.level; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 610 | |
| 611 | conn = chan->conn; |
| 612 | if (conn && chan->scid == L2CAP_CID_LE_DATA) { |
| 613 | if (!conn->hcon->out) { |
| 614 | err = -EINVAL; |
| 615 | break; |
| 616 | } |
| 617 | |
| 618 | if (smp_conn_security(conn, sec.level)) |
| 619 | break; |
| 620 | |
| 621 | err = 0; |
| 622 | sk->sk_state = BT_CONFIG; |
| 623 | } |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 624 | break; |
| 625 | |
| 626 | case BT_DEFER_SETUP: |
| 627 | if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { |
| 628 | err = -EINVAL; |
| 629 | break; |
| 630 | } |
| 631 | |
| 632 | if (get_user(opt, (u32 __user *) optval)) { |
| 633 | err = -EFAULT; |
| 634 | break; |
| 635 | } |
| 636 | |
| 637 | bt_sk(sk)->defer_setup = opt; |
| 638 | break; |
| 639 | |
| 640 | case BT_FLUSHABLE: |
| 641 | if (get_user(opt, (u32 __user *) optval)) { |
| 642 | err = -EFAULT; |
| 643 | break; |
| 644 | } |
| 645 | |
| 646 | if (opt > BT_FLUSHABLE_ON) { |
| 647 | err = -EINVAL; |
| 648 | break; |
| 649 | } |
| 650 | |
| 651 | if (opt == BT_FLUSHABLE_OFF) { |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 652 | struct l2cap_conn *conn = chan->conn; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 653 | /* proceed further only when we have l2cap_conn and |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 654 | No Flush support in the LM */ |
| 655 | if (!conn || !lmp_no_flush_capable(conn->hcon->hdev)) { |
| 656 | err = -EINVAL; |
| 657 | break; |
| 658 | } |
| 659 | } |
| 660 | |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 661 | chan->flushable = opt; |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 662 | break; |
| 663 | |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 664 | case BT_POWER: |
| 665 | if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED && |
| 666 | chan->chan_type != L2CAP_CHAN_RAW) { |
| 667 | err = -EINVAL; |
| 668 | break; |
| 669 | } |
| 670 | |
| 671 | pwr.force_active = BT_POWER_FORCE_ACTIVE_ON; |
| 672 | |
| 673 | len = min_t(unsigned int, sizeof(pwr), optlen); |
| 674 | if (copy_from_user((char *) &pwr, optval, len)) { |
| 675 | err = -EFAULT; |
| 676 | break; |
| 677 | } |
| 678 | chan->force_active = pwr.force_active; |
| 679 | break; |
| 680 | |
Gustavo F. Padovan | 33575df | 2011-02-04 02:48:48 -0200 | [diff] [blame] | 681 | default: |
| 682 | err = -ENOPROTOOPT; |
| 683 | break; |
| 684 | } |
| 685 | |
| 686 | release_sock(sk); |
| 687 | return err; |
| 688 | } |
| 689 | |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 690 | static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len) |
| 691 | { |
| 692 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 693 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 694 | int err; |
| 695 | |
| 696 | BT_DBG("sock %p, sk %p", sock, sk); |
| 697 | |
| 698 | err = sock_error(sk); |
| 699 | if (err) |
| 700 | return err; |
| 701 | |
| 702 | if (msg->msg_flags & MSG_OOB) |
| 703 | return -EOPNOTSUPP; |
| 704 | |
| 705 | lock_sock(sk); |
| 706 | |
| 707 | if (sk->sk_state != BT_CONNECTED) { |
Gustavo F. Padovan | 9a91a04 | 2011-04-28 18:50:17 -0300 | [diff] [blame] | 708 | release_sock(sk); |
| 709 | return -ENOTCONN; |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 710 | } |
| 711 | |
Gustavo F. Padovan | 9a91a04 | 2011-04-28 18:50:17 -0300 | [diff] [blame] | 712 | err = l2cap_chan_send(chan, msg, len); |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 713 | |
Gustavo F. Padovan | fd83ccd | 2011-02-04 03:20:52 -0200 | [diff] [blame] | 714 | release_sock(sk); |
| 715 | return err; |
| 716 | } |
| 717 | |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 718 | static int l2cap_sock_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, size_t len, int flags) |
| 719 | { |
| 720 | struct sock *sk = sock->sk; |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 721 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
| 722 | int err; |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 723 | |
| 724 | lock_sock(sk); |
| 725 | |
| 726 | if (sk->sk_state == BT_CONNECT2 && bt_sk(sk)->defer_setup) { |
Gustavo F. Padovan | 8c1d787 | 2011-04-13 20:23:55 -0300 | [diff] [blame] | 727 | sk->sk_state = BT_CONFIG; |
| 728 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 729 | __l2cap_connect_rsp_defer(pi->chan); |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 730 | release_sock(sk); |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | release_sock(sk); |
| 735 | |
| 736 | if (sock->type == SOCK_STREAM) |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 737 | err = bt_sock_stream_recvmsg(iocb, sock, msg, len, flags); |
| 738 | else |
| 739 | err = bt_sock_recvmsg(iocb, sock, msg, len, flags); |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 740 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 741 | if (pi->chan->mode != L2CAP_MODE_ERTM) |
| 742 | return err; |
| 743 | |
| 744 | /* Attempt to put pending rx data in the socket buffer */ |
| 745 | |
| 746 | lock_sock(sk); |
| 747 | |
| 748 | if (!test_bit(CONN_LOCAL_BUSY, &pi->chan->conn_state)) |
| 749 | goto done; |
| 750 | |
| 751 | if (pi->rx_busy_skb) { |
| 752 | if (!sock_queue_rcv_skb(sk, pi->rx_busy_skb)) |
| 753 | pi->rx_busy_skb = NULL; |
| 754 | else |
| 755 | goto done; |
| 756 | } |
| 757 | |
| 758 | /* Restore data flow when half of the receive buffer is |
| 759 | * available. This avoids resending large numbers of |
| 760 | * frames. |
| 761 | */ |
| 762 | if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf >> 1) |
| 763 | l2cap_chan_busy(pi->chan, 0); |
| 764 | |
| 765 | done: |
| 766 | release_sock(sk); |
| 767 | return err; |
Gustavo F. Padovan | 6898325 | 2011-02-04 03:02:31 -0200 | [diff] [blame] | 768 | } |
| 769 | |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 770 | /* Kill socket (only if zapped and orphan) |
| 771 | * Must be called on unlocked socket. |
| 772 | */ |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 773 | static void l2cap_sock_kill(struct sock *sk) |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 774 | { |
| 775 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
| 776 | return; |
| 777 | |
| 778 | BT_DBG("sk %p state %d", sk, sk->sk_state); |
| 779 | |
| 780 | /* Kill poor orphan */ |
Gustavo F. Padovan | 6ff5abb | 2011-04-25 15:10:41 -0300 | [diff] [blame] | 781 | |
Gustavo F. Padovan | 23691d7 | 2011-04-27 18:26:32 -0300 | [diff] [blame] | 782 | l2cap_chan_destroy(l2cap_pi(sk)->chan); |
Gustavo F. Padovan | 05fc157 | 2011-02-04 03:26:01 -0200 | [diff] [blame] | 783 | sock_set_flag(sk, SOCK_DEAD); |
| 784 | sock_put(sk); |
| 785 | } |
| 786 | |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 787 | static int l2cap_sock_shutdown(struct socket *sock, int how) |
| 788 | { |
| 789 | struct sock *sk = sock->sk; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 790 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 791 | int err = 0; |
| 792 | |
| 793 | BT_DBG("sock %p, sk %p", sock, sk); |
| 794 | |
| 795 | if (!sk) |
| 796 | return 0; |
| 797 | |
| 798 | lock_sock(sk); |
| 799 | if (!sk->sk_shutdown) { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 800 | if (chan->mode == L2CAP_MODE_ERTM) |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 801 | err = __l2cap_wait_ack(sk); |
| 802 | |
| 803 | sk->sk_shutdown = SHUTDOWN_MASK; |
Gustavo F. Padovan | 0f85272 | 2011-05-04 19:42:50 -0300 | [diff] [blame] | 804 | l2cap_chan_close(chan, 0); |
Gustavo F. Padovan | dcba0db | 2011-02-04 03:08:36 -0200 | [diff] [blame] | 805 | |
| 806 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) |
| 807 | err = bt_sock_wait_state(sk, BT_CLOSED, |
| 808 | sk->sk_lingertime); |
| 809 | } |
| 810 | |
| 811 | if (!err && sk->sk_err) |
| 812 | err = -sk->sk_err; |
| 813 | |
| 814 | release_sock(sk); |
| 815 | return err; |
| 816 | } |
| 817 | |
Gustavo F. Padovan | 554f05b | 2011-02-04 02:36:42 -0200 | [diff] [blame] | 818 | static int l2cap_sock_release(struct socket *sock) |
| 819 | { |
| 820 | struct sock *sk = sock->sk; |
| 821 | int err; |
| 822 | |
| 823 | BT_DBG("sock %p, sk %p", sock, sk); |
| 824 | |
| 825 | if (!sk) |
| 826 | return 0; |
| 827 | |
| 828 | err = l2cap_sock_shutdown(sock, 2); |
| 829 | |
| 830 | sock_orphan(sk); |
| 831 | l2cap_sock_kill(sk); |
| 832 | return err; |
| 833 | } |
| 834 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 835 | static struct l2cap_chan *l2cap_sock_new_connection_cb(void *data) |
| 836 | { |
| 837 | struct sock *sk, *parent = data; |
| 838 | |
| 839 | sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP, |
| 840 | GFP_ATOMIC); |
| 841 | if (!sk) |
| 842 | return NULL; |
| 843 | |
| 844 | l2cap_sock_init(sk, parent); |
| 845 | |
| 846 | return l2cap_pi(sk)->chan; |
| 847 | } |
| 848 | |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 849 | static int l2cap_sock_recv_cb(void *data, struct sk_buff *skb) |
| 850 | { |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 851 | int err; |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 852 | struct sock *sk = data; |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 853 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 854 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 855 | if (pi->rx_busy_skb) |
| 856 | return -ENOMEM; |
| 857 | |
| 858 | err = sock_queue_rcv_skb(sk, skb); |
| 859 | |
| 860 | /* For ERTM, handle one skb that doesn't fit into the recv |
| 861 | * buffer. This is important to do because the data frames |
| 862 | * have already been acked, so the skb cannot be discarded. |
| 863 | * |
| 864 | * Notify the l2cap core that the buffer is full, so the |
| 865 | * LOCAL_BUSY state is entered and no more frames are |
| 866 | * acked and reassembled until there is buffer space |
| 867 | * available. |
| 868 | */ |
| 869 | if (err < 0 && pi->chan->mode == L2CAP_MODE_ERTM) { |
| 870 | pi->rx_busy_skb = skb; |
| 871 | l2cap_chan_busy(pi->chan, 1); |
| 872 | err = 0; |
| 873 | } |
| 874 | |
| 875 | return err; |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 876 | } |
| 877 | |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 878 | static void l2cap_sock_close_cb(void *data) |
| 879 | { |
| 880 | struct sock *sk = data; |
| 881 | |
| 882 | l2cap_sock_kill(sk); |
| 883 | } |
| 884 | |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 885 | static void l2cap_sock_state_change_cb(void *data, int state) |
| 886 | { |
| 887 | struct sock *sk = data; |
| 888 | |
| 889 | sk->sk_state = state; |
| 890 | } |
| 891 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 892 | static struct l2cap_ops l2cap_chan_ops = { |
| 893 | .name = "L2CAP Socket Interface", |
| 894 | .new_connection = l2cap_sock_new_connection_cb, |
Gustavo F. Padovan | 2307049 | 2011-05-16 17:57:22 -0300 | [diff] [blame] | 895 | .recv = l2cap_sock_recv_cb, |
Gustavo F. Padovan | ba3bd0e | 2011-05-16 18:23:24 -0300 | [diff] [blame] | 896 | .close = l2cap_sock_close_cb, |
Gustavo F. Padovan | 89bc500 | 2011-06-03 00:19:47 -0300 | [diff] [blame] | 897 | .state_change = l2cap_sock_state_change_cb, |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 898 | }; |
| 899 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 900 | static void l2cap_sock_destruct(struct sock *sk) |
| 901 | { |
| 902 | BT_DBG("sk %p", sk); |
| 903 | |
Mat Martineau | e328140 | 2011-07-07 09:39:02 -0700 | [diff] [blame] | 904 | if (l2cap_pi(sk)->rx_busy_skb) { |
| 905 | kfree_skb(l2cap_pi(sk)->rx_busy_skb); |
| 906 | l2cap_pi(sk)->rx_busy_skb = NULL; |
| 907 | } |
| 908 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 909 | skb_queue_purge(&sk->sk_receive_queue); |
| 910 | skb_queue_purge(&sk->sk_write_queue); |
| 911 | } |
| 912 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 913 | static void l2cap_sock_init(struct sock *sk, struct sock *parent) |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 914 | { |
| 915 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 916 | struct l2cap_chan *chan = pi->chan; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 917 | |
| 918 | BT_DBG("sk %p", sk); |
| 919 | |
| 920 | if (parent) { |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 921 | struct l2cap_chan *pchan = l2cap_pi(parent)->chan; |
| 922 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 923 | sk->sk_type = parent->sk_type; |
| 924 | bt_sk(sk)->defer_setup = bt_sk(parent)->defer_setup; |
| 925 | |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 926 | chan->chan_type = pchan->chan_type; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 927 | chan->imtu = pchan->imtu; |
| 928 | chan->omtu = pchan->omtu; |
Gustavo F. Padovan | b445003 | 2011-04-12 18:15:09 -0300 | [diff] [blame] | 929 | chan->conf_state = pchan->conf_state; |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 930 | chan->mode = pchan->mode; |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 931 | chan->fcs = pchan->fcs; |
| 932 | chan->max_tx = pchan->max_tx; |
| 933 | chan->tx_win = pchan->tx_win; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 934 | chan->sec_level = pchan->sec_level; |
| 935 | chan->role_switch = pchan->role_switch; |
| 936 | chan->force_reliable = pchan->force_reliable; |
| 937 | chan->flushable = pchan->flushable; |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 938 | chan->force_active = pchan->force_active; |
Paul Moore | 6230c9b | 2011-10-07 09:40:59 +0000 | [diff] [blame] | 939 | |
| 940 | security_sk_clone(parent, sk); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 941 | } else { |
Gustavo F. Padovan | 715ec00 | 2011-05-02 17:13:55 -0300 | [diff] [blame] | 942 | |
| 943 | switch (sk->sk_type) { |
| 944 | case SOCK_RAW: |
| 945 | chan->chan_type = L2CAP_CHAN_RAW; |
| 946 | break; |
| 947 | case SOCK_DGRAM: |
| 948 | chan->chan_type = L2CAP_CHAN_CONN_LESS; |
| 949 | break; |
| 950 | case SOCK_SEQPACKET: |
| 951 | case SOCK_STREAM: |
| 952 | chan->chan_type = L2CAP_CHAN_CONN_ORIENTED; |
| 953 | break; |
| 954 | } |
| 955 | |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 956 | chan->imtu = L2CAP_DEFAULT_MTU; |
| 957 | chan->omtu = 0; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 958 | if (!disable_ertm && sk->sk_type == SOCK_STREAM) { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 959 | chan->mode = L2CAP_MODE_ERTM; |
Gustavo F. Padovan | c1360a1 | 2011-06-10 17:02:12 -0300 | [diff] [blame] | 960 | set_bit(CONF_STATE2_DEVICE, &chan->conf_state); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 961 | } else { |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 962 | chan->mode = L2CAP_MODE_BASIC; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 963 | } |
Gustavo F. Padovan | 47d1ec6 | 2011-04-13 15:57:03 -0300 | [diff] [blame] | 964 | chan->max_tx = L2CAP_DEFAULT_MAX_TX; |
| 965 | chan->fcs = L2CAP_FCS_CRC16; |
| 966 | chan->tx_win = L2CAP_DEFAULT_TX_WINDOW; |
Gustavo F. Padovan | 4343478 | 2011-04-12 18:31:57 -0300 | [diff] [blame] | 967 | chan->sec_level = BT_SECURITY_LOW; |
| 968 | chan->role_switch = 0; |
| 969 | chan->force_reliable = 0; |
| 970 | chan->flushable = BT_FLUSHABLE_OFF; |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 971 | chan->force_active = BT_POWER_FORCE_ACTIVE_ON; |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 972 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | /* Default config options */ |
Gustavo F. Padovan | 0c1bc5c | 2011-04-13 17:20:49 -0300 | [diff] [blame] | 976 | chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 977 | |
| 978 | chan->data = sk; |
| 979 | chan->ops = &l2cap_chan_ops; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static struct proto l2cap_proto = { |
| 983 | .name = "L2CAP", |
| 984 | .owner = THIS_MODULE, |
| 985 | .obj_size = sizeof(struct l2cap_pinfo) |
| 986 | }; |
| 987 | |
Gustavo F. Padovan | 80808e4 | 2011-05-16 17:24:37 -0300 | [diff] [blame] | 988 | static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio) |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 989 | { |
| 990 | struct sock *sk; |
Gustavo F. Padovan | dc50a06 | 2011-05-16 16:42:01 -0300 | [diff] [blame] | 991 | struct l2cap_chan *chan; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 992 | |
| 993 | sk = sk_alloc(net, PF_BLUETOOTH, prio, &l2cap_proto); |
| 994 | if (!sk) |
| 995 | return NULL; |
| 996 | |
| 997 | sock_init_data(sock, sk); |
| 998 | INIT_LIST_HEAD(&bt_sk(sk)->accept_q); |
| 999 | |
| 1000 | sk->sk_destruct = l2cap_sock_destruct; |
Chen Ganir | 6be6b11 | 2011-07-28 15:42:09 +0300 | [diff] [blame] | 1001 | sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1002 | |
| 1003 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 1004 | |
| 1005 | sk->sk_protocol = proto; |
| 1006 | sk->sk_state = BT_OPEN; |
| 1007 | |
Gustavo F. Padovan | dc50a06 | 2011-05-16 16:42:01 -0300 | [diff] [blame] | 1008 | chan = l2cap_chan_create(sk); |
| 1009 | if (!chan) { |
| 1010 | l2cap_sock_kill(sk); |
| 1011 | return NULL; |
| 1012 | } |
| 1013 | |
| 1014 | l2cap_pi(sk)->chan = chan; |
| 1015 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1016 | return sk; |
| 1017 | } |
| 1018 | |
| 1019 | static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol, |
| 1020 | int kern) |
| 1021 | { |
| 1022 | struct sock *sk; |
| 1023 | |
| 1024 | BT_DBG("sock %p", sock); |
| 1025 | |
| 1026 | sock->state = SS_UNCONNECTED; |
| 1027 | |
| 1028 | if (sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM && |
| 1029 | sock->type != SOCK_DGRAM && sock->type != SOCK_RAW) |
| 1030 | return -ESOCKTNOSUPPORT; |
| 1031 | |
| 1032 | if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW)) |
| 1033 | return -EPERM; |
| 1034 | |
| 1035 | sock->ops = &l2cap_sock_ops; |
| 1036 | |
| 1037 | sk = l2cap_sock_alloc(net, sock, protocol, GFP_ATOMIC); |
| 1038 | if (!sk) |
| 1039 | return -ENOMEM; |
| 1040 | |
| 1041 | l2cap_sock_init(sk, NULL); |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
Gustavo F. Padovan | cf2f90f | 2011-04-27 18:40:39 -0300 | [diff] [blame] | 1045 | static const struct proto_ops l2cap_sock_ops = { |
Gustavo F. Padovan | 6539058 | 2011-02-04 02:33:56 -0200 | [diff] [blame] | 1046 | .family = PF_BLUETOOTH, |
| 1047 | .owner = THIS_MODULE, |
| 1048 | .release = l2cap_sock_release, |
| 1049 | .bind = l2cap_sock_bind, |
| 1050 | .connect = l2cap_sock_connect, |
| 1051 | .listen = l2cap_sock_listen, |
| 1052 | .accept = l2cap_sock_accept, |
| 1053 | .getname = l2cap_sock_getname, |
| 1054 | .sendmsg = l2cap_sock_sendmsg, |
| 1055 | .recvmsg = l2cap_sock_recvmsg, |
| 1056 | .poll = bt_sock_poll, |
| 1057 | .ioctl = bt_sock_ioctl, |
| 1058 | .mmap = sock_no_mmap, |
| 1059 | .socketpair = sock_no_socketpair, |
| 1060 | .shutdown = l2cap_sock_shutdown, |
| 1061 | .setsockopt = l2cap_sock_setsockopt, |
| 1062 | .getsockopt = l2cap_sock_getsockopt |
| 1063 | }; |
| 1064 | |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1065 | static const struct net_proto_family l2cap_sock_family_ops = { |
| 1066 | .family = PF_BLUETOOTH, |
| 1067 | .owner = THIS_MODULE, |
| 1068 | .create = l2cap_sock_create, |
| 1069 | }; |
| 1070 | |
| 1071 | int __init l2cap_init_sockets(void) |
| 1072 | { |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1073 | int err; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1074 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1075 | err = proto_register(&l2cap_proto, 0); |
| 1076 | if (err < 0) |
| 1077 | return err; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1078 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1079 | err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops); |
| 1080 | if (err < 0) |
| 1081 | goto error; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1082 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1083 | BT_INFO("L2CAP socket layer initialized"); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1084 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1085 | return 0; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1086 | |
| 1087 | error: |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1088 | BT_ERR("L2CAP socket registration failed"); |
| 1089 | proto_unregister(&l2cap_proto); |
| 1090 | return err; |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | void l2cap_cleanup_sockets(void) |
| 1094 | { |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1095 | if (bt_sock_unregister(BTPROTO_L2CAP) < 0) |
| 1096 | BT_ERR("L2CAP socket unregistration failed"); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1097 | |
Gustavo F. Padovan | e2174ca | 2011-02-17 19:16:55 -0300 | [diff] [blame] | 1098 | proto_unregister(&l2cap_proto); |
Gustavo F. Padovan | bb58f74 | 2011-02-03 20:50:35 -0200 | [diff] [blame] | 1099 | } |