linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/5] Add support for getting the Encryption Key Size via btio
@ 2011-12-13 23:57 Vinicius Costa Gomes
  2011-12-13 23:57 ` [PATCH BlueZ 2/5] Add support for passing the CID to btiotest Vinicius Costa Gomes
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Vinicius Costa Gomes @ 2011-12-13 23:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Vinicius Costa Gomes

Some profiles specify some restriction depending on the length
of the key used to encrypt the link, this adds an way to retrieve
that value from the kernel.

Current kernels don't provide this information so the size is
always zero.
---
 btio/btio.c     |   21 +++++++++++++++++++++
 btio/btio.h     |    1 +
 lib/bluetooth.h |    1 +
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/btio/btio.c b/btio/btio.c
index 0d177a3..5641a9c 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -513,6 +513,22 @@ static int set_priority(int sock, uint32_t prio)
 	return 0;
 }
 
+static gboolean get_key_size(int sock, BtIOType type, int *size,
+								GError **err)
+{
+	struct bt_security sec;
+	socklen_t len;
+
+	memset(&sec, 0, sizeof(sec));
+	len = sizeof(sec);
+	if (getsockopt(sock, SOL_BLUETOOTH, BT_SECURITY, &sec, &len) == 0) {
+		*size = sec.key_size;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 static gboolean l2cap_set(int sock, int sec_level, uint16_t imtu,
 				uint16_t omtu, uint8_t mode, int master,
 				int flushable, uint32_t priority, GError **err)
@@ -880,6 +896,11 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 						va_arg(args, int *), err))
 				return FALSE;
 			break;
+		case BT_IO_OPT_KEY_SIZE:
+			if (!get_key_size(sock, BT_IO_L2CAP,
+						va_arg(args, int *), err))
+				return FALSE;
+			break;
 		case BT_IO_OPT_PSM:
 			*(va_arg(args, uint16_t *)) = src.l2_psm ?
 					btohs(src.l2_psm) : btohs(dst.l2_psm);
diff --git a/btio/btio.h b/btio/btio.h
index ae55b61..7e3e130 100644
--- a/btio/btio.h
+++ b/btio/btio.h
@@ -52,6 +52,7 @@ typedef enum {
 	BT_IO_OPT_DEST_BDADDR,
 	BT_IO_OPT_DEFER_TIMEOUT,
 	BT_IO_OPT_SEC_LEVEL,
+	BT_IO_OPT_KEY_SIZE,
 	BT_IO_OPT_CHANNEL,
 	BT_IO_OPT_SOURCE_CHANNEL,
 	BT_IO_OPT_DEST_CHANNEL,
diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 5bd4f03..1dee6df 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -63,6 +63,7 @@ extern "C" {
 #define BT_SECURITY	4
 struct bt_security {
 	uint8_t level;
+	uint8_t key_size;
 };
 #define BT_SECURITY_SDP		0
 #define BT_SECURITY_LOW		1
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-01-23 11:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-13 23:57 [PATCH BlueZ 1/5] Add support for getting the Encryption Key Size via btio Vinicius Costa Gomes
2011-12-13 23:57 ` [PATCH BlueZ 2/5] Add support for passing the CID to btiotest Vinicius Costa Gomes
2011-12-13 23:57 ` [PATCH BlueZ 3/5] Add support for btiotest to returning the key size Vinicius Costa Gomes
2011-12-13 23:57 ` [PATCH BlueZ 4/5] Remove the default security level from btio Vinicius Costa Gomes
2011-12-14 11:43   ` Ganir, Chen
2011-12-14 13:56     ` Vinicius Gomes
2011-12-13 23:57 ` [PATCH BlueZ 5/5] Fix btio users to not expect a default security level Vinicius Costa Gomes
2011-12-14 12:09 ` [PATCH BlueZ 1/5] Add support for getting the Encryption Key Size via btio Luiz Augusto von Dentz
2011-12-14 16:35   ` Vinicius Costa Gomes
2011-12-14 17:02 ` Vinicius Costa Gomes
2011-12-15 11:37 ` Johan Hedberg
2011-12-15 19:18   ` Vinicius Costa Gomes
2012-01-22 20:29     ` Anderson Lizardo
2012-01-23 11:15       ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).