Bluetooth: Refactor bt_conn_security function
Separate connection master role related parts in single block making it simpler to split. This is a preparation for being able to compile in only central or peripheral role support. Change-Id: I27dc9b32048bf4e682149d5f1d5edbd994155e2b Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
parent
a9382fde50
commit
6fc9e71d09
1 changed files with 14 additions and 15 deletions
|
@ -552,8 +552,6 @@ const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn)
|
|||
|
||||
int bt_conn_security(struct bt_conn *conn, bt_security_t sec)
|
||||
{
|
||||
struct bt_keys *keys;
|
||||
|
||||
if (conn->state != BT_CONN_CONNECTED) {
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
@ -570,24 +568,25 @@ int bt_conn_security(struct bt_conn *conn, bt_security_t sec)
|
|||
|
||||
conn->required_sec_level = sec;
|
||||
|
||||
if (conn->role == BT_HCI_ROLE_SLAVE) {
|
||||
return bt_smp_send_security_req(conn);
|
||||
}
|
||||
if (conn->role == BT_HCI_ROLE_MASTER) {
|
||||
struct bt_keys *keys;
|
||||
|
||||
keys = bt_keys_find(BT_KEYS_LTK, &conn->dst);
|
||||
if (keys) {
|
||||
if (sec > BT_SECURITY_MEDIUM &&
|
||||
keys->type != BT_KEYS_AUTHENTICATED) {
|
||||
goto pair;
|
||||
keys = bt_keys_find(BT_KEYS_LTK, &conn->dst);
|
||||
if (keys) {
|
||||
if (sec > BT_SECURITY_MEDIUM &&
|
||||
keys->type != BT_KEYS_AUTHENTICATED) {
|
||||
return bt_smp_send_pairing_req(conn);
|
||||
}
|
||||
|
||||
return bt_conn_le_start_encryption(conn, keys->ltk.rand,
|
||||
keys->ltk.ediv,
|
||||
keys->ltk.val);
|
||||
}
|
||||
|
||||
return bt_conn_le_start_encryption(conn, keys->ltk.rand,
|
||||
keys->ltk.ediv,
|
||||
keys->ltk.val);
|
||||
return bt_smp_send_pairing_req(conn);
|
||||
}
|
||||
|
||||
pair:
|
||||
return bt_smp_send_pairing_req(conn);
|
||||
return bt_smp_send_security_req(conn);
|
||||
}
|
||||
|
||||
void bt_conn_set_auto_conn(struct bt_conn *conn, bool auto_conn)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue