Skip to content

Commit

Permalink
Bluetooth: Add proper shutdown support to SCO sockets
Browse files Browse the repository at this point in the history
The SCO sockets for Bluetooth audio setup and streaming are missing the
shutdown implementation. This hasn't been a problem so far, but with a
more deeper integration with PulseAudio it is important to shutdown SCO
sockets properly.

Also the Headset profile 1.2 has more detailed qualification tests that
require that SCO and RFCOMM channels are terminated in the right order. A
proper shutdown function is necessary for this.

Based on a report by Johan Hedberg <johan.hedberg@nokia.com>

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Tested-by: Johan Hedberg <johan.hedberg@nokia.com>
  • Loading branch information
holtmann committed Aug 22, 2009
1 parent f8f2109 commit fd0b3ff
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions net/bluetooth/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,20 +359,9 @@ static void sco_sock_kill(struct sock *sk)
sock_put(sk);
}

/* Close socket.
* Must be called on unlocked socket.
*/
static void sco_sock_close(struct sock *sk)
static void __sco_sock_close(struct sock *sk)
{
struct sco_conn *conn;

sco_sock_clear_timer(sk);

lock_sock(sk);

conn = sco_pi(sk)->conn;

BT_DBG("sk %p state %d conn %p socket %p", sk, sk->sk_state, conn, sk->sk_socket);
BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);

switch (sk->sk_state) {
case BT_LISTEN:
Expand All @@ -390,9 +379,15 @@ static void sco_sock_close(struct sock *sk)
sock_set_flag(sk, SOCK_ZAPPED);
break;
}
}

/* Must be called on unlocked socket. */
static void sco_sock_close(struct sock *sk)
{
sco_sock_clear_timer(sk);
lock_sock(sk);
__sco_sock_close(sk);
release_sock(sk);

sco_sock_kill(sk);
}

Expand Down Expand Up @@ -748,6 +743,30 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char
return err;
}

static int sco_sock_shutdown(struct socket *sock, int how)
{
struct sock *sk = sock->sk;
int err = 0;

BT_DBG("sock %p, sk %p", sock, sk);

if (!sk)
return 0;

lock_sock(sk);
if (!sk->sk_shutdown) {
sk->sk_shutdown = SHUTDOWN_MASK;
sco_sock_clear_timer(sk);
__sco_sock_close(sk);

if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
err = bt_sock_wait_state(sk, BT_CLOSED,
sk->sk_lingertime);
}
release_sock(sk);
return err;
}

static int sco_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
Expand Down Expand Up @@ -969,7 +988,7 @@ static const struct proto_ops sco_sock_ops = {
.ioctl = bt_sock_ioctl,
.mmap = sock_no_mmap,
.socketpair = sock_no_socketpair,
.shutdown = sock_no_shutdown,
.shutdown = sco_sock_shutdown,
.setsockopt = sco_sock_setsockopt,
.getsockopt = sco_sock_getsockopt
};
Expand Down

0 comments on commit fd0b3ff

Please sign in to comment.