Bluetooth: BR/EDR: Add no-bond keys flag

When bond is required only for current connection session, don't store
the link key value in keys database when such link key is generated.
Release the link key storage on disconnection complete.

> HCI Event: IO Capability Response (0x32) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: DisplayOnly (0x00)
	OOB data: Authentication data not present (0x00)
	Authentication: No Bonding - MITM required (0x01)
> HCI Event: IO Capability Request (0x31) plen 6
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
< HCI Command: IO Capability Request Reply (0x01|0x002b) plen 9
	Address: 00:1A:7D:DA:71:13 (cyber-blue(HK)Ltd)
	IO capability: KeyboardOnly (0x02)
	OOB data: Authentication data not present (0x00)
	Authentication: No Bonding - MITM required (0x01)
> HCI Event: Command Complete (0x0e) plen 10

Change-Id: Ibd29457a9183f33f28264b857dd2de01f96d266f
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2016-03-04 14:50:29 +01:00 committed by Johan Hedberg
commit b0bc48370d
2 changed files with 20 additions and 1 deletions

View file

@ -32,6 +32,7 @@ enum {
BT_CONN_BR_LEGACY_SECURE, /* 16 digits legacy PIN tracker */
BT_CONN_USER, /* user I/O when pairing */
BT_CONN_BR_PAIRING, /* BR connection in pairing context */
BT_CONN_BR_NOBOND, /* SSP no bond pairing tracker */
};
struct bt_conn_le {

View file

@ -504,6 +504,16 @@ static void hci_disconn_complete(struct net_buf *buf)
conn->handle = 0;
if (conn->type != BT_CONN_TYPE_LE) {
#if defined(CONFIG_BLUETOOTH_BREDR)
/*
* If only for one connection session bond was set, clear keys
* database row for this connection.
*/
if (conn->type == BT_CONN_TYPE_BR &&
atomic_test_and_clear_bit(conn->flags, BT_CONN_BR_NOBOND)) {
bt_keys_clear(conn->keys, BT_KEYS_LINK_KEY);
}
#endif
bt_conn_unref(conn);
return;
}
@ -1041,7 +1051,15 @@ static void link_key_notify(struct net_buf *buf)
return;
}
/*
* Populate key storage with link key if bonding is required. Mark
* no-bond link key flag for connection on the contrary.
*/
if (bt_conn_ssp_get_auth(conn) > BT_HCI_NO_BONDING_MITM) {
memcpy(conn->keys->link_key.val, evt->link_key, 16);
} else {
atomic_set_bit(conn->flags, BT_CONN_BR_NOBOND);
}
if (evt->key_type == BT_LK_COMBINATION) {
atomic_set_bit(&conn->keys->flags, BT_KEYS_BR_LEGACY);