Bluetooth: Add support for returning the encryption key size
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>
Fri, 8 Jul 2011 21:31:46 +0000 (18:31 -0300)
committerGustavo F. Padovan <padovan@profusion.mobi>
Fri, 8 Jul 2011 21:39:31 +0000 (18:39 -0300)
This will be useful when userspace wants to restrict some kinds of
operations based on the length of the key size used to encrypt the
link.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
include/net/bluetooth/bluetooth.h
net/bluetooth/l2cap_sock.c

index 0cfa75bdd6096a2dc2f4480e03fd05b7d39e81eb..e727555d4ee9bc479df54d32fc5b9e6ce9ac52cd 100644 (file)
@@ -56,6 +56,7 @@
 #define BT_SECURITY    4
 struct bt_security {
        __u8 level;
+       __u8 key_size;
 };
 #define BT_SECURITY_SDP                0
 #define BT_SECURITY_LOW                1
index 146b614d10ed1ed72b521165eec3907ce9fbd0f1..5c36b3e8739cb706f9aa47e74a0ed9c5f72b8e24 100644 (file)
@@ -422,8 +422,12 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
                        break;
                }
 
+               memset(&sec, 0, sizeof(sec));
                sec.level = chan->sec_level;
 
+               if (sk->sk_state == BT_CONNECTED)
+                       sec.key_size = chan->conn->hcon->enc_key_size;
+
                len = min_t(unsigned int, len, sizeof(sec));
                if (copy_to_user(optval, (char *) &sec, len))
                        err = -EFAULT;