Skip to content

Commit

Permalink
Bluetooth: SMP: Stop new pairing early if MAX_PAIR has been reached
Browse files Browse the repository at this point in the history
Stop the pairing procedure in the request phase if no storage is
available for the keys. This avoids the pairing procedure from failing
during the key distribution phase.

Signed-off-by: Joakim Andersson <[email protected]>
  • Loading branch information
joerchan authored and carlescufi committed Aug 26, 2019
1 parent 3263f93 commit f1c7371
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/bluetooth/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ typedef enum __packed {
*
* This function may return error if required level of security is not possible
* to achieve due to local or remote device limitation (e.g., input output
* capabilities).
* capabilities), or if the maximum number of paired devices has been reached.
*
* @param conn Connection object.
* @param sec Requested security level.
Expand Down
21 changes: 21 additions & 0 deletions subsys/bluetooth/host/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,13 @@ int bt_smp_send_security_req(struct bt_conn *conn)
return -EINVAL;
}

if (!conn->le.keys) {
conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst);
if (!conn->le.keys) {
return -ENOMEM;
}
}

if (smp_init(smp) != 0) {
return -ENOBUFS;
}
Expand Down Expand Up @@ -2457,6 +2464,13 @@ static u8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
return BT_SMP_ERR_ENC_KEY_SIZE;
}

if (!conn->le.keys) {
conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst);
if (!conn->le.keys) {
return BT_SMP_ERR_UNSPECIFIED;
}
}

/* If we already sent a security request then the SMP context
* is already initialized.
*/
Expand Down Expand Up @@ -2601,6 +2615,13 @@ int bt_smp_send_pairing_req(struct bt_conn *conn)
return -EINVAL;
}

if (!conn->le.keys) {
conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst);
if (!conn->le.keys) {
return -ENOMEM;
}
}

if (smp_init(smp)) {
return -ENOBUFS;
}
Expand Down

0 comments on commit f1c7371

Please sign in to comment.