Bluetooth: Fix returning peer address in pending connect state
authorJohan Hedberg <johan.hedberg@intel.com>
Wed, 26 Mar 2014 13:49:18 +0000 (15:49 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 26 Mar 2014 16:31:33 +0000 (09:31 -0700)
We should let user space request the peer address also in the pending
connect states, i.e. BT_CONNECT and BT_CONNECT2. There is existing user
space code that tries to do this and will fail without extending the set
of allowed states for the peer address information.

This patch adds the two states to the allowed ones in the L2CAP and
RFCOMM sock_getname functions, thereby preventing ENOTCONN from being
returned.

Reported-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Tested-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/l2cap_sock.c
net/bluetooth/rfcomm/sock.c

index 33cd5615ff1e04ad9b33a7a794c73a4ffc7e4005..f59e00c2daa9cb5e485cb7832cb80486660ca6bf 100644 (file)
@@ -360,7 +360,8 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr,
 
        BT_DBG("sock %p, sk %p", sock, sk);
 
-       if (peer && sk->sk_state != BT_CONNECTED)
+       if (peer && sk->sk_state != BT_CONNECTED &&
+           sk->sk_state != BT_CONNECT && sk->sk_state != BT_CONNECT2)
                return -ENOTCONN;
 
        memset(la, 0, sizeof(struct sockaddr_l2));
index c024e715512fdff242616c4ac403fa8315b13289..eabd25ab5ad96a14b07624ef6fdfa48715384f45 100644 (file)
@@ -534,7 +534,8 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
 
        BT_DBG("sock %p, sk %p", sock, sk);
 
-       if (peer && sk->sk_state != BT_CONNECTED)
+       if (peer && sk->sk_state != BT_CONNECTED &&
+           sk->sk_state != BT_CONNECT && sk->sk_state != BT_CONNECT2)
                return -ENOTCONN;
 
        memset(sa, 0, sizeof(*sa));