Bluetooth: BR/EDR: Refactor link key notify handler

Makes proper link key handling based on its type.

Change-Id: I052cc4629e531ea9ae7da95a7268778e633bdba5
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2016-03-22 18:58:56 +01:00 committed by Gerrit Code Review
commit 5cecd07ba2

View file

@ -1051,21 +1051,9 @@ static void link_key_notify(struct net_buf *buf)
return;
}
/*
* Populate key storage with link key if SSP persistent bond is required
* or legacy link key is generated. Mark no-bond link key flag for
* connection on the contrary.
*/
if (evt->key_type == BT_LK_COMBINATION ||
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) {
switch (evt->key_type) {
case BT_LK_COMBINATION:
atomic_set_bit(&conn->keys->flags, BT_KEYS_BR_LEGACY);
/*
* Setting Combination Link Key as AUTHENTICATED means it was
* successfully generated by 16 digits wide PIN code.
@ -1075,8 +1063,28 @@ static void link_key_notify(struct net_buf *buf)
atomic_set_bit(&conn->keys->flags,
BT_KEYS_AUTHENTICATED);
}
} else if (evt->key_type == BT_LK_AUTH_COMBINATION_P192) {
atomic_set_bit(&conn->keys->flags, BT_KEYS_AUTHENTICATED);
memcpy(conn->keys->link_key.val, evt->link_key, 16);
break;
case BT_LK_UNAUTH_COMBINATION_P192:
case BT_LK_AUTH_COMBINATION_P192:
if (evt->key_type == BT_LK_AUTH_COMBINATION_P192) {
atomic_set_bit(&conn->keys->flags,
BT_KEYS_AUTHENTICATED);
}
/*
* Update keys database if authentication bond is required to
* be persistent. 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);
}
break;
default:
BT_WARN("Link key type unsupported/unimplemented");
break;
}
bt_conn_unref(conn);