summaryrefslogtreecommitdiff
path: root/btio
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2012-01-24 10:57:19 -0300
committerJohan Hedberg <johan.hedberg@intel.com>2012-01-24 16:19:19 +0200
commit51886914ef77f6c7331347a5e023cf8cde65629c (patch)
tree551a22079aace9bcca5f7073d044c03217dbf585 /btio
parentfaa7b5c70b287f1398d4853e263d519dfbf2da5c (diff)
downloadbluez-51886914ef77f6c7331347a5e023cf8cde65629c.tar.gz
btio: Add support for getting the Encryption Key Size via btio
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.
Diffstat (limited to 'btio')
-rw-r--r--btio/btio.c19
-rw-r--r--btio/btio.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/btio/btio.c b/btio/btio.c
index a45a9cc33..77ddb1df3 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -511,6 +511,21 @@ static int set_priority(int sock, uint32_t prio)
return 0;
}
+static gboolean get_key_size(int sock, 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)
@@ -875,6 +890,10 @@ 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, 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 ae55b618a..7e3e130eb 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,