YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | BlueZ - Bluetooth protocol stack for Linux |
| 3 | Copyright (C) 2000-2001 Qualcomm Incorporated |
| 4 | |
| 5 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License version 2 as |
| 9 | published by the Free Software Foundation; |
| 10 | |
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 12 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 14 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 15 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 20 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 21 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | SOFTWARE IS DISCLAIMED. |
| 23 | */ |
| 24 | |
| 25 | /* Bluetooth SCO sockets. */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/errno.h> |
| 31 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/sched.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/poll.h> |
| 35 | #include <linux/fcntl.h> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/interrupt.h> |
| 38 | #include <linux/socket.h> |
| 39 | #include <linux/skbuff.h> |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 40 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/list.h> |
| 42 | #include <net/sock.h> |
| 43 | |
| 44 | #include <asm/system.h> |
| 45 | #include <asm/uaccess.h> |
| 46 | |
| 47 | #include <net/bluetooth/bluetooth.h> |
| 48 | #include <net/bluetooth/hci_core.h> |
| 49 | #include <net/bluetooth/sco.h> |
| 50 | |
| 51 | #ifndef CONFIG_BT_SCO_DEBUG |
| 52 | #undef BT_DBG |
| 53 | #define BT_DBG(D...) |
| 54 | #endif |
| 55 | |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 56 | #define VERSION "0.5" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 58 | static const struct proto_ops sco_sock_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | static struct bt_sock_list sco_sk_list = { |
| 61 | .lock = RW_LOCK_UNLOCKED |
| 62 | }; |
| 63 | |
| 64 | static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent); |
| 65 | static void sco_chan_del(struct sock *sk, int err); |
| 66 | |
| 67 | static int sco_conn_del(struct hci_conn *conn, int err); |
| 68 | |
| 69 | static void sco_sock_close(struct sock *sk); |
| 70 | static void sco_sock_kill(struct sock *sk); |
| 71 | |
| 72 | /* ---- SCO timers ---- */ |
| 73 | static void sco_sock_timeout(unsigned long arg) |
| 74 | { |
| 75 | struct sock *sk = (struct sock *) arg; |
| 76 | |
| 77 | BT_DBG("sock %p state %d", sk, sk->sk_state); |
| 78 | |
| 79 | bh_lock_sock(sk); |
| 80 | sk->sk_err = ETIMEDOUT; |
| 81 | sk->sk_state_change(sk); |
| 82 | bh_unlock_sock(sk); |
| 83 | |
| 84 | sco_sock_kill(sk); |
| 85 | sock_put(sk); |
| 86 | } |
| 87 | |
| 88 | static void sco_sock_set_timer(struct sock *sk, long timeout) |
| 89 | { |
| 90 | BT_DBG("sock %p state %d timeout %ld", sk, sk->sk_state, timeout); |
| 91 | sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout); |
| 92 | } |
| 93 | |
| 94 | static void sco_sock_clear_timer(struct sock *sk) |
| 95 | { |
| 96 | BT_DBG("sock %p state %d", sk, sk->sk_state); |
| 97 | sk_stop_timer(sk, &sk->sk_timer); |
| 98 | } |
| 99 | |
| 100 | static void sco_sock_init_timer(struct sock *sk) |
| 101 | { |
| 102 | init_timer(&sk->sk_timer); |
| 103 | sk->sk_timer.function = sco_sock_timeout; |
| 104 | sk->sk_timer.data = (unsigned long)sk; |
| 105 | } |
| 106 | |
| 107 | /* ---- SCO connections ---- */ |
| 108 | static struct sco_conn *sco_conn_add(struct hci_conn *hcon, __u8 status) |
| 109 | { |
| 110 | struct hci_dev *hdev = hcon->hdev; |
Marcel Holtmann | 25ea6db | 2006-07-06 15:40:09 +0200 | [diff] [blame] | 111 | struct sco_conn *conn = hcon->sco_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Marcel Holtmann | 25ea6db | 2006-07-06 15:40:09 +0200 | [diff] [blame] | 113 | if (conn || status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return conn; |
| 115 | |
Marcel Holtmann | 25ea6db | 2006-07-06 15:40:09 +0200 | [diff] [blame] | 116 | conn = kzalloc(sizeof(struct sco_conn), GFP_ATOMIC); |
| 117 | if (!conn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | spin_lock_init(&conn->lock); |
| 121 | |
| 122 | hcon->sco_data = conn; |
| 123 | conn->hcon = hcon; |
| 124 | |
| 125 | conn->src = &hdev->bdaddr; |
| 126 | conn->dst = &hcon->dst; |
| 127 | |
| 128 | if (hdev->sco_mtu > 0) |
| 129 | conn->mtu = hdev->sco_mtu; |
| 130 | else |
| 131 | conn->mtu = 60; |
| 132 | |
| 133 | BT_DBG("hcon %p conn %p", hcon, conn); |
Marcel Holtmann | 25ea6db | 2006-07-06 15:40:09 +0200 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | return conn; |
| 136 | } |
| 137 | |
| 138 | static inline struct sock *sco_chan_get(struct sco_conn *conn) |
| 139 | { |
| 140 | struct sock *sk = NULL; |
| 141 | sco_conn_lock(conn); |
| 142 | sk = conn->sk; |
| 143 | sco_conn_unlock(conn); |
| 144 | return sk; |
| 145 | } |
| 146 | |
| 147 | static int sco_conn_del(struct hci_conn *hcon, int err) |
| 148 | { |
| 149 | struct sco_conn *conn; |
| 150 | struct sock *sk; |
| 151 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 152 | if (!(conn = hcon->sco_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | return 0; |
| 154 | |
| 155 | BT_DBG("hcon %p conn %p, err %d", hcon, conn, err); |
| 156 | |
| 157 | /* Kill socket */ |
| 158 | if ((sk = sco_chan_get(conn))) { |
| 159 | bh_lock_sock(sk); |
| 160 | sco_sock_clear_timer(sk); |
| 161 | sco_chan_del(sk, err); |
| 162 | bh_unlock_sock(sk); |
| 163 | sco_sock_kill(sk); |
| 164 | } |
| 165 | |
| 166 | hcon->sco_data = NULL; |
| 167 | kfree(conn); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static inline int sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent) |
| 172 | { |
| 173 | int err = 0; |
| 174 | |
| 175 | sco_conn_lock(conn); |
| 176 | if (conn->sk) { |
| 177 | err = -EBUSY; |
| 178 | } else { |
| 179 | __sco_chan_add(conn, sk, parent); |
| 180 | } |
| 181 | sco_conn_unlock(conn); |
| 182 | return err; |
| 183 | } |
| 184 | |
| 185 | static int sco_connect(struct sock *sk) |
| 186 | { |
| 187 | bdaddr_t *src = &bt_sk(sk)->src; |
| 188 | bdaddr_t *dst = &bt_sk(sk)->dst; |
| 189 | struct sco_conn *conn; |
| 190 | struct hci_conn *hcon; |
| 191 | struct hci_dev *hdev; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 192 | int err, type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | BT_DBG("%s -> %s", batostr(src), batostr(dst)); |
| 195 | |
| 196 | if (!(hdev = hci_get_route(dst, src))) |
| 197 | return -EHOSTUNREACH; |
| 198 | |
| 199 | hci_dev_lock_bh(hdev); |
| 200 | |
| 201 | err = -ENOMEM; |
| 202 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 203 | type = lmp_esco_capable(hdev) ? ESCO_LINK : SCO_LINK; |
| 204 | |
| 205 | hcon = hci_connect(hdev, type, dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | if (!hcon) |
| 207 | goto done; |
| 208 | |
| 209 | conn = sco_conn_add(hcon, 0); |
| 210 | if (!conn) { |
| 211 | hci_conn_put(hcon); |
| 212 | goto done; |
| 213 | } |
| 214 | |
| 215 | /* Update source addr of the socket */ |
| 216 | bacpy(src, conn->src); |
| 217 | |
| 218 | err = sco_chan_add(conn, sk, NULL); |
| 219 | if (err) |
| 220 | goto done; |
| 221 | |
| 222 | if (hcon->state == BT_CONNECTED) { |
| 223 | sco_sock_clear_timer(sk); |
| 224 | sk->sk_state = BT_CONNECTED; |
| 225 | } else { |
| 226 | sk->sk_state = BT_CONNECT; |
| 227 | sco_sock_set_timer(sk, sk->sk_sndtimeo); |
| 228 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | done: |
| 231 | hci_dev_unlock_bh(hdev); |
| 232 | hci_dev_put(hdev); |
| 233 | return err; |
| 234 | } |
| 235 | |
| 236 | static inline int sco_send_frame(struct sock *sk, struct msghdr *msg, int len) |
| 237 | { |
| 238 | struct sco_conn *conn = sco_pi(sk)->conn; |
| 239 | struct sk_buff *skb; |
| 240 | int err, count; |
| 241 | |
| 242 | /* Check outgoing MTU */ |
| 243 | if (len > conn->mtu) |
| 244 | return -EINVAL; |
| 245 | |
| 246 | BT_DBG("sk %p len %d", sk, len); |
| 247 | |
| 248 | count = min_t(unsigned int, conn->mtu, len); |
| 249 | if (!(skb = bt_skb_send_alloc(sk, count, msg->msg_flags & MSG_DONTWAIT, &err))) |
| 250 | return err; |
| 251 | |
| 252 | if (memcpy_fromiovec(skb_put(skb, count), msg->msg_iov, count)) { |
| 253 | err = -EFAULT; |
| 254 | goto fail; |
| 255 | } |
| 256 | |
| 257 | if ((err = hci_send_sco(conn->hcon, skb)) < 0) |
Eric Sesterhenn | cdee575 | 2006-04-05 22:28:14 -0700 | [diff] [blame] | 258 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | return count; |
| 261 | |
| 262 | fail: |
| 263 | kfree_skb(skb); |
| 264 | return err; |
| 265 | } |
| 266 | |
| 267 | static inline void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) |
| 268 | { |
| 269 | struct sock *sk = sco_chan_get(conn); |
| 270 | |
| 271 | if (!sk) |
| 272 | goto drop; |
| 273 | |
| 274 | BT_DBG("sk %p len %d", sk, skb->len); |
| 275 | |
| 276 | if (sk->sk_state != BT_CONNECTED) |
| 277 | goto drop; |
| 278 | |
| 279 | if (!sock_queue_rcv_skb(sk, skb)) |
| 280 | return; |
| 281 | |
| 282 | drop: |
| 283 | kfree_skb(skb); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | /* -------- Socket interface ---------- */ |
| 288 | static struct sock *__sco_get_sock_by_addr(bdaddr_t *ba) |
| 289 | { |
| 290 | struct sock *sk; |
| 291 | struct hlist_node *node; |
| 292 | |
| 293 | sk_for_each(sk, node, &sco_sk_list.head) |
| 294 | if (!bacmp(&bt_sk(sk)->src, ba)) |
| 295 | goto found; |
| 296 | sk = NULL; |
| 297 | found: |
| 298 | return sk; |
| 299 | } |
| 300 | |
| 301 | /* Find socket listening on source bdaddr. |
| 302 | * Returns closest match. |
| 303 | */ |
| 304 | static struct sock *sco_get_sock_listen(bdaddr_t *src) |
| 305 | { |
| 306 | struct sock *sk = NULL, *sk1 = NULL; |
| 307 | struct hlist_node *node; |
| 308 | |
| 309 | read_lock(&sco_sk_list.lock); |
| 310 | |
| 311 | sk_for_each(sk, node, &sco_sk_list.head) { |
| 312 | if (sk->sk_state != BT_LISTEN) |
| 313 | continue; |
| 314 | |
| 315 | /* Exact match. */ |
| 316 | if (!bacmp(&bt_sk(sk)->src, src)) |
| 317 | break; |
| 318 | |
| 319 | /* Closest match */ |
| 320 | if (!bacmp(&bt_sk(sk)->src, BDADDR_ANY)) |
| 321 | sk1 = sk; |
| 322 | } |
| 323 | |
| 324 | read_unlock(&sco_sk_list.lock); |
| 325 | |
| 326 | return node ? sk : sk1; |
| 327 | } |
| 328 | |
| 329 | static void sco_sock_destruct(struct sock *sk) |
| 330 | { |
| 331 | BT_DBG("sk %p", sk); |
| 332 | |
| 333 | skb_queue_purge(&sk->sk_receive_queue); |
| 334 | skb_queue_purge(&sk->sk_write_queue); |
| 335 | } |
| 336 | |
| 337 | static void sco_sock_cleanup_listen(struct sock *parent) |
| 338 | { |
| 339 | struct sock *sk; |
| 340 | |
| 341 | BT_DBG("parent %p", parent); |
| 342 | |
| 343 | /* Close not yet accepted channels */ |
| 344 | while ((sk = bt_accept_dequeue(parent, NULL))) { |
| 345 | sco_sock_close(sk); |
| 346 | sco_sock_kill(sk); |
| 347 | } |
| 348 | |
| 349 | parent->sk_state = BT_CLOSED; |
| 350 | sock_set_flag(parent, SOCK_ZAPPED); |
| 351 | } |
| 352 | |
| 353 | /* Kill socket (only if zapped and orphan) |
| 354 | * Must be called on unlocked socket. |
| 355 | */ |
| 356 | static void sco_sock_kill(struct sock *sk) |
| 357 | { |
| 358 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
| 359 | return; |
| 360 | |
| 361 | BT_DBG("sk %p state %d", sk, sk->sk_state); |
| 362 | |
| 363 | /* Kill poor orphan */ |
| 364 | bt_sock_unlink(&sco_sk_list, sk); |
| 365 | sock_set_flag(sk, SOCK_DEAD); |
| 366 | sock_put(sk); |
| 367 | } |
| 368 | |
| 369 | /* Close socket. |
| 370 | * Must be called on unlocked socket. |
| 371 | */ |
| 372 | static void sco_sock_close(struct sock *sk) |
| 373 | { |
| 374 | struct sco_conn *conn; |
| 375 | |
| 376 | sco_sock_clear_timer(sk); |
| 377 | |
| 378 | lock_sock(sk); |
| 379 | |
| 380 | conn = sco_pi(sk)->conn; |
| 381 | |
| 382 | BT_DBG("sk %p state %d conn %p socket %p", sk, sk->sk_state, conn, sk->sk_socket); |
| 383 | |
| 384 | switch (sk->sk_state) { |
| 385 | case BT_LISTEN: |
| 386 | sco_sock_cleanup_listen(sk); |
| 387 | break; |
| 388 | |
| 389 | case BT_CONNECTED: |
| 390 | case BT_CONFIG: |
| 391 | case BT_CONNECT: |
| 392 | case BT_DISCONN: |
| 393 | sco_chan_del(sk, ECONNRESET); |
| 394 | break; |
| 395 | |
| 396 | default: |
| 397 | sock_set_flag(sk, SOCK_ZAPPED); |
| 398 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | release_sock(sk); |
| 402 | |
| 403 | sco_sock_kill(sk); |
| 404 | } |
| 405 | |
| 406 | static void sco_sock_init(struct sock *sk, struct sock *parent) |
| 407 | { |
| 408 | BT_DBG("sk %p", sk); |
| 409 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 410 | if (parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | sk->sk_type = parent->sk_type; |
| 412 | } |
| 413 | |
| 414 | static struct proto sco_proto = { |
| 415 | .name = "SCO", |
| 416 | .owner = THIS_MODULE, |
| 417 | .obj_size = sizeof(struct sco_pinfo) |
| 418 | }; |
| 419 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 420 | static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | struct sock *sk; |
| 423 | |
Pavel Emelyanov | 6257ff2 | 2007-11-01 00:39:31 -0700 | [diff] [blame] | 424 | sk = sk_alloc(net, PF_BLUETOOTH, prio, &sco_proto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | if (!sk) |
| 426 | return NULL; |
| 427 | |
| 428 | sock_init_data(sock, sk); |
| 429 | INIT_LIST_HEAD(&bt_sk(sk)->accept_q); |
| 430 | |
| 431 | sk->sk_destruct = sco_sock_destruct; |
| 432 | sk->sk_sndtimeo = SCO_CONN_TIMEOUT; |
| 433 | |
| 434 | sock_reset_flag(sk, SOCK_ZAPPED); |
| 435 | |
| 436 | sk->sk_protocol = proto; |
| 437 | sk->sk_state = BT_OPEN; |
| 438 | |
| 439 | sco_sock_init_timer(sk); |
| 440 | |
| 441 | bt_sock_link(&sco_sk_list, sk); |
| 442 | return sk; |
| 443 | } |
| 444 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 445 | static int sco_sock_create(struct net *net, struct socket *sock, int protocol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | struct sock *sk; |
| 448 | |
| 449 | BT_DBG("sock %p", sock); |
| 450 | |
| 451 | sock->state = SS_UNCONNECTED; |
| 452 | |
| 453 | if (sock->type != SOCK_SEQPACKET) |
| 454 | return -ESOCKTNOSUPPORT; |
| 455 | |
| 456 | sock->ops = &sco_sock_ops; |
| 457 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 458 | sk = sco_sock_alloc(net, sock, protocol, GFP_ATOMIC); |
Marcel Holtmann | 74da626 | 2006-10-15 17:31:14 +0200 | [diff] [blame] | 459 | if (!sk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | return -ENOMEM; |
| 461 | |
| 462 | sco_sock_init(sk, NULL); |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static int sco_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) |
| 467 | { |
| 468 | struct sockaddr_sco *sa = (struct sockaddr_sco *) addr; |
| 469 | struct sock *sk = sock->sk; |
| 470 | bdaddr_t *src = &sa->sco_bdaddr; |
| 471 | int err = 0; |
| 472 | |
| 473 | BT_DBG("sk %p %s", sk, batostr(&sa->sco_bdaddr)); |
| 474 | |
| 475 | if (!addr || addr->sa_family != AF_BLUETOOTH) |
| 476 | return -EINVAL; |
| 477 | |
| 478 | lock_sock(sk); |
| 479 | |
| 480 | if (sk->sk_state != BT_OPEN) { |
| 481 | err = -EBADFD; |
| 482 | goto done; |
| 483 | } |
| 484 | |
| 485 | write_lock_bh(&sco_sk_list.lock); |
| 486 | |
| 487 | if (bacmp(src, BDADDR_ANY) && __sco_get_sock_by_addr(src)) { |
| 488 | err = -EADDRINUSE; |
| 489 | } else { |
| 490 | /* Save source address */ |
| 491 | bacpy(&bt_sk(sk)->src, &sa->sco_bdaddr); |
| 492 | sk->sk_state = BT_BOUND; |
| 493 | } |
| 494 | |
| 495 | write_unlock_bh(&sco_sk_list.lock); |
| 496 | |
| 497 | done: |
| 498 | release_sock(sk); |
| 499 | return err; |
| 500 | } |
| 501 | |
| 502 | static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen, int flags) |
| 503 | { |
| 504 | struct sockaddr_sco *sa = (struct sockaddr_sco *) addr; |
| 505 | struct sock *sk = sock->sk; |
| 506 | int err = 0; |
| 507 | |
| 508 | |
| 509 | BT_DBG("sk %p", sk); |
| 510 | |
| 511 | if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_sco)) |
| 512 | return -EINVAL; |
| 513 | |
| 514 | if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) |
| 515 | return -EBADFD; |
| 516 | |
| 517 | if (sk->sk_type != SOCK_SEQPACKET) |
| 518 | return -EINVAL; |
| 519 | |
| 520 | lock_sock(sk); |
| 521 | |
| 522 | /* Set destination address and psm */ |
| 523 | bacpy(&bt_sk(sk)->dst, &sa->sco_bdaddr); |
| 524 | |
| 525 | if ((err = sco_connect(sk))) |
| 526 | goto done; |
| 527 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 528 | err = bt_sock_wait_state(sk, BT_CONNECTED, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | sock_sndtimeo(sk, flags & O_NONBLOCK)); |
| 530 | |
| 531 | done: |
| 532 | release_sock(sk); |
| 533 | return err; |
| 534 | } |
| 535 | |
| 536 | static int sco_sock_listen(struct socket *sock, int backlog) |
| 537 | { |
| 538 | struct sock *sk = sock->sk; |
| 539 | int err = 0; |
| 540 | |
| 541 | BT_DBG("sk %p backlog %d", sk, backlog); |
| 542 | |
| 543 | lock_sock(sk); |
| 544 | |
| 545 | if (sk->sk_state != BT_BOUND || sock->type != SOCK_SEQPACKET) { |
| 546 | err = -EBADFD; |
| 547 | goto done; |
| 548 | } |
| 549 | |
| 550 | sk->sk_max_ack_backlog = backlog; |
| 551 | sk->sk_ack_backlog = 0; |
| 552 | sk->sk_state = BT_LISTEN; |
| 553 | |
| 554 | done: |
| 555 | release_sock(sk); |
| 556 | return err; |
| 557 | } |
| 558 | |
| 559 | static int sco_sock_accept(struct socket *sock, struct socket *newsock, int flags) |
| 560 | { |
| 561 | DECLARE_WAITQUEUE(wait, current); |
| 562 | struct sock *sk = sock->sk, *ch; |
| 563 | long timeo; |
| 564 | int err = 0; |
| 565 | |
| 566 | lock_sock(sk); |
| 567 | |
| 568 | if (sk->sk_state != BT_LISTEN) { |
| 569 | err = -EBADFD; |
| 570 | goto done; |
| 571 | } |
| 572 | |
| 573 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
| 574 | |
| 575 | BT_DBG("sk %p timeo %ld", sk, timeo); |
| 576 | |
| 577 | /* Wait for an incoming connection. (wake-one). */ |
| 578 | add_wait_queue_exclusive(sk->sk_sleep, &wait); |
| 579 | while (!(ch = bt_accept_dequeue(sk, newsock))) { |
| 580 | set_current_state(TASK_INTERRUPTIBLE); |
| 581 | if (!timeo) { |
| 582 | err = -EAGAIN; |
| 583 | break; |
| 584 | } |
| 585 | |
| 586 | release_sock(sk); |
| 587 | timeo = schedule_timeout(timeo); |
| 588 | lock_sock(sk); |
| 589 | |
| 590 | if (sk->sk_state != BT_LISTEN) { |
| 591 | err = -EBADFD; |
| 592 | break; |
| 593 | } |
| 594 | |
| 595 | if (signal_pending(current)) { |
| 596 | err = sock_intr_errno(timeo); |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | set_current_state(TASK_RUNNING); |
| 601 | remove_wait_queue(sk->sk_sleep, &wait); |
| 602 | |
| 603 | if (err) |
| 604 | goto done; |
| 605 | |
| 606 | newsock->state = SS_CONNECTED; |
| 607 | |
| 608 | BT_DBG("new socket %p", ch); |
| 609 | |
| 610 | done: |
| 611 | release_sock(sk); |
| 612 | return err; |
| 613 | } |
| 614 | |
| 615 | static int sco_sock_getname(struct socket *sock, struct sockaddr *addr, int *len, int peer) |
| 616 | { |
| 617 | struct sockaddr_sco *sa = (struct sockaddr_sco *) addr; |
| 618 | struct sock *sk = sock->sk; |
| 619 | |
| 620 | BT_DBG("sock %p, sk %p", sock, sk); |
| 621 | |
| 622 | addr->sa_family = AF_BLUETOOTH; |
| 623 | *len = sizeof(struct sockaddr_sco); |
| 624 | |
| 625 | if (peer) |
| 626 | bacpy(&sa->sco_bdaddr, &bt_sk(sk)->dst); |
| 627 | else |
| 628 | bacpy(&sa->sco_bdaddr, &bt_sk(sk)->src); |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 633 | static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | struct msghdr *msg, size_t len) |
| 635 | { |
| 636 | struct sock *sk = sock->sk; |
| 637 | int err = 0; |
| 638 | |
| 639 | BT_DBG("sock %p, sk %p", sock, sk); |
| 640 | |
Benjamin LaHaise | c1cbe4b | 2005-12-13 23:22:19 -0800 | [diff] [blame] | 641 | err = sock_error(sk); |
| 642 | if (err) |
| 643 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | if (msg->msg_flags & MSG_OOB) |
| 646 | return -EOPNOTSUPP; |
| 647 | |
| 648 | lock_sock(sk); |
| 649 | |
| 650 | if (sk->sk_state == BT_CONNECTED) |
| 651 | err = sco_send_frame(sk, msg, len); |
| 652 | else |
| 653 | err = -ENOTCONN; |
| 654 | |
| 655 | release_sock(sk); |
| 656 | return err; |
| 657 | } |
| 658 | |
| 659 | static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen) |
| 660 | { |
| 661 | struct sock *sk = sock->sk; |
| 662 | int err = 0; |
| 663 | |
| 664 | BT_DBG("sk %p", sk); |
| 665 | |
| 666 | lock_sock(sk); |
| 667 | |
| 668 | switch (optname) { |
| 669 | default: |
| 670 | err = -ENOPROTOOPT; |
| 671 | break; |
| 672 | } |
| 673 | |
| 674 | release_sock(sk); |
| 675 | return err; |
| 676 | } |
| 677 | |
| 678 | static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen) |
| 679 | { |
| 680 | struct sock *sk = sock->sk; |
| 681 | struct sco_options opts; |
| 682 | struct sco_conninfo cinfo; |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 683 | int len, err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
| 685 | BT_DBG("sk %p", sk); |
| 686 | |
| 687 | if (get_user(len, optlen)) |
| 688 | return -EFAULT; |
| 689 | |
| 690 | lock_sock(sk); |
| 691 | |
| 692 | switch (optname) { |
| 693 | case SCO_OPTIONS: |
| 694 | if (sk->sk_state != BT_CONNECTED) { |
| 695 | err = -ENOTCONN; |
| 696 | break; |
| 697 | } |
| 698 | |
| 699 | opts.mtu = sco_pi(sk)->conn->mtu; |
| 700 | |
| 701 | BT_DBG("mtu %d", opts.mtu); |
| 702 | |
| 703 | len = min_t(unsigned int, len, sizeof(opts)); |
| 704 | if (copy_to_user(optval, (char *)&opts, len)) |
| 705 | err = -EFAULT; |
| 706 | |
| 707 | break; |
| 708 | |
| 709 | case SCO_CONNINFO: |
| 710 | if (sk->sk_state != BT_CONNECTED) { |
| 711 | err = -ENOTCONN; |
| 712 | break; |
| 713 | } |
| 714 | |
| 715 | cinfo.hci_handle = sco_pi(sk)->conn->hcon->handle; |
| 716 | memcpy(cinfo.dev_class, sco_pi(sk)->conn->hcon->dev_class, 3); |
| 717 | |
| 718 | len = min_t(unsigned int, len, sizeof(cinfo)); |
| 719 | if (copy_to_user(optval, (char *)&cinfo, len)) |
| 720 | err = -EFAULT; |
| 721 | |
| 722 | break; |
| 723 | |
| 724 | default: |
| 725 | err = -ENOPROTOOPT; |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | release_sock(sk); |
| 730 | return err; |
| 731 | } |
| 732 | |
| 733 | static int sco_sock_release(struct socket *sock) |
| 734 | { |
| 735 | struct sock *sk = sock->sk; |
| 736 | int err = 0; |
| 737 | |
| 738 | BT_DBG("sock %p, sk %p", sock, sk); |
| 739 | |
| 740 | if (!sk) |
| 741 | return 0; |
| 742 | |
| 743 | sco_sock_close(sk); |
| 744 | |
| 745 | if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) { |
| 746 | lock_sock(sk); |
| 747 | err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime); |
| 748 | release_sock(sk); |
| 749 | } |
| 750 | |
| 751 | sock_orphan(sk); |
| 752 | sco_sock_kill(sk); |
| 753 | return err; |
| 754 | } |
| 755 | |
| 756 | static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent) |
| 757 | { |
| 758 | BT_DBG("conn %p", conn); |
| 759 | |
| 760 | sco_pi(sk)->conn = conn; |
| 761 | conn->sk = sk; |
| 762 | |
| 763 | if (parent) |
| 764 | bt_accept_enqueue(parent, sk); |
| 765 | } |
| 766 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 767 | /* Delete channel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | * Must be called on the locked socket. */ |
| 769 | static void sco_chan_del(struct sock *sk, int err) |
| 770 | { |
| 771 | struct sco_conn *conn; |
| 772 | |
| 773 | conn = sco_pi(sk)->conn; |
| 774 | |
| 775 | BT_DBG("sk %p, conn %p, err %d", sk, conn, err); |
| 776 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 777 | if (conn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | sco_conn_lock(conn); |
| 779 | conn->sk = NULL; |
| 780 | sco_pi(sk)->conn = NULL; |
| 781 | sco_conn_unlock(conn); |
| 782 | hci_conn_put(conn->hcon); |
| 783 | } |
| 784 | |
| 785 | sk->sk_state = BT_CLOSED; |
| 786 | sk->sk_err = err; |
| 787 | sk->sk_state_change(sk); |
| 788 | |
| 789 | sock_set_flag(sk, SOCK_ZAPPED); |
| 790 | } |
| 791 | |
| 792 | static void sco_conn_ready(struct sco_conn *conn) |
| 793 | { |
| 794 | struct sock *parent, *sk; |
| 795 | |
| 796 | BT_DBG("conn %p", conn); |
| 797 | |
| 798 | sco_conn_lock(conn); |
| 799 | |
| 800 | if ((sk = conn->sk)) { |
| 801 | sco_sock_clear_timer(sk); |
| 802 | bh_lock_sock(sk); |
| 803 | sk->sk_state = BT_CONNECTED; |
| 804 | sk->sk_state_change(sk); |
| 805 | bh_unlock_sock(sk); |
| 806 | } else { |
| 807 | parent = sco_get_sock_listen(conn->src); |
| 808 | if (!parent) |
| 809 | goto done; |
| 810 | |
| 811 | bh_lock_sock(parent); |
| 812 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 813 | sk = sco_sock_alloc(parent->sk_net, NULL, BTPROTO_SCO, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | if (!sk) { |
| 815 | bh_unlock_sock(parent); |
| 816 | goto done; |
| 817 | } |
| 818 | |
| 819 | sco_sock_init(sk, parent); |
| 820 | |
| 821 | bacpy(&bt_sk(sk)->src, conn->src); |
| 822 | bacpy(&bt_sk(sk)->dst, conn->dst); |
| 823 | |
| 824 | hci_conn_hold(conn->hcon); |
| 825 | __sco_chan_add(conn, sk, parent); |
| 826 | |
| 827 | sk->sk_state = BT_CONNECTED; |
| 828 | |
| 829 | /* Wake up parent */ |
| 830 | parent->sk_data_ready(parent, 1); |
| 831 | |
| 832 | bh_unlock_sock(parent); |
| 833 | } |
| 834 | |
| 835 | done: |
| 836 | sco_conn_unlock(conn); |
| 837 | } |
| 838 | |
| 839 | /* ----- SCO interface with lower layer (HCI) ----- */ |
| 840 | static int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type) |
| 841 | { |
| 842 | BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr)); |
| 843 | |
| 844 | /* Always accept connection */ |
| 845 | return HCI_LM_ACCEPT; |
| 846 | } |
| 847 | |
| 848 | static int sco_connect_cfm(struct hci_conn *hcon, __u8 status) |
| 849 | { |
| 850 | BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status); |
| 851 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 852 | if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | return 0; |
| 854 | |
| 855 | if (!status) { |
| 856 | struct sco_conn *conn; |
| 857 | |
| 858 | conn = sco_conn_add(hcon, status); |
| 859 | if (conn) |
| 860 | sco_conn_ready(conn); |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 861 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | sco_conn_del(hcon, bt_err(status)); |
| 863 | |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | static int sco_disconn_ind(struct hci_conn *hcon, __u8 reason) |
| 868 | { |
| 869 | BT_DBG("hcon %p reason %d", hcon, reason); |
| 870 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 871 | if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | return 0; |
| 873 | |
| 874 | sco_conn_del(hcon, bt_err(reason)); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb) |
| 880 | { |
| 881 | struct sco_conn *conn = hcon->sco_data; |
| 882 | |
| 883 | if (!conn) |
| 884 | goto drop; |
| 885 | |
| 886 | BT_DBG("conn %p len %d", conn, skb->len); |
| 887 | |
| 888 | if (skb->len) { |
| 889 | sco_recv_frame(conn, skb); |
| 890 | return 0; |
| 891 | } |
| 892 | |
| 893 | drop: |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 894 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | return 0; |
| 896 | } |
| 897 | |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 898 | static ssize_t sco_sysfs_show(struct class *dev, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
| 900 | struct sock *sk; |
| 901 | struct hlist_node *node; |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 902 | char *str = buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | read_lock_bh(&sco_sk_list.lock); |
| 905 | |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 906 | sk_for_each(sk, node, &sco_sk_list.head) { |
| 907 | str += sprintf(str, "%s %s %d\n", |
| 908 | batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), |
| 909 | sk->sk_state); |
| 910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | read_unlock_bh(&sco_sk_list.lock); |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 913 | |
| 914 | return (str - buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Marcel Holtmann | be9d122 | 2005-11-08 09:57:38 -0800 | [diff] [blame] | 917 | static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 919 | static const struct proto_ops sco_sock_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | .family = PF_BLUETOOTH, |
| 921 | .owner = THIS_MODULE, |
| 922 | .release = sco_sock_release, |
| 923 | .bind = sco_sock_bind, |
| 924 | .connect = sco_sock_connect, |
| 925 | .listen = sco_sock_listen, |
| 926 | .accept = sco_sock_accept, |
| 927 | .getname = sco_sock_getname, |
| 928 | .sendmsg = sco_sock_sendmsg, |
| 929 | .recvmsg = bt_sock_recvmsg, |
| 930 | .poll = bt_sock_poll, |
| 931 | .ioctl = sock_no_ioctl, |
| 932 | .mmap = sock_no_mmap, |
| 933 | .socketpair = sock_no_socketpair, |
| 934 | .shutdown = sock_no_shutdown, |
| 935 | .setsockopt = sco_sock_setsockopt, |
| 936 | .getsockopt = sco_sock_getsockopt |
| 937 | }; |
| 938 | |
| 939 | static struct net_proto_family sco_sock_family_ops = { |
| 940 | .family = PF_BLUETOOTH, |
| 941 | .owner = THIS_MODULE, |
| 942 | .create = sco_sock_create, |
| 943 | }; |
| 944 | |
| 945 | static struct hci_proto sco_hci_proto = { |
| 946 | .name = "SCO", |
| 947 | .id = HCI_PROTO_SCO, |
| 948 | .connect_ind = sco_connect_ind, |
| 949 | .connect_cfm = sco_connect_cfm, |
| 950 | .disconn_ind = sco_disconn_ind, |
| 951 | .recv_scodata = sco_recv_scodata |
| 952 | }; |
| 953 | |
| 954 | static int __init sco_init(void) |
| 955 | { |
| 956 | int err; |
| 957 | |
| 958 | err = proto_register(&sco_proto, 0); |
| 959 | if (err < 0) |
| 960 | return err; |
| 961 | |
| 962 | err = bt_sock_register(BTPROTO_SCO, &sco_sock_family_ops); |
| 963 | if (err < 0) { |
| 964 | BT_ERR("SCO socket registration failed"); |
| 965 | goto error; |
| 966 | } |
| 967 | |
| 968 | err = hci_register_proto(&sco_hci_proto); |
| 969 | if (err < 0) { |
| 970 | BT_ERR("SCO protocol registration failed"); |
| 971 | bt_sock_unregister(BTPROTO_SCO); |
| 972 | goto error; |
| 973 | } |
| 974 | |
Marcel Holtmann | df5c37e | 2006-10-15 17:30:45 +0200 | [diff] [blame] | 975 | if (class_create_file(bt_class, &class_attr_sco) < 0) |
| 976 | BT_ERR("Failed to create SCO info file"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | BT_INFO("SCO (Voice Link) ver %s", VERSION); |
| 979 | BT_INFO("SCO socket layer initialized"); |
| 980 | |
| 981 | return 0; |
| 982 | |
| 983 | error: |
| 984 | proto_unregister(&sco_proto); |
| 985 | return err; |
| 986 | } |
| 987 | |
| 988 | static void __exit sco_exit(void) |
| 989 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 990 | class_remove_file(bt_class, &class_attr_sco); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | if (bt_sock_unregister(BTPROTO_SCO) < 0) |
| 993 | BT_ERR("SCO socket unregistration failed"); |
| 994 | |
| 995 | if (hci_unregister_proto(&sco_hci_proto) < 0) |
| 996 | BT_ERR("SCO protocol unregistration failed"); |
| 997 | |
| 998 | proto_unregister(&sco_proto); |
| 999 | } |
| 1000 | |
| 1001 | module_init(sco_init); |
| 1002 | module_exit(sco_exit); |
| 1003 | |
| 1004 | MODULE_AUTHOR("Maxim Krasnyansky <maxk@qualcomm.com>, Marcel Holtmann <marcel@holtmann.org>"); |
| 1005 | MODULE_DESCRIPTION("Bluetooth SCO ver " VERSION); |
| 1006 | MODULE_VERSION(VERSION); |
| 1007 | MODULE_LICENSE("GPL"); |
| 1008 | MODULE_ALIAS("bt-proto-2"); |