Bluetooth: SMP: Refactor Pairing Failed sending
smp_reset is always called after Pairing Failed was sent so just move it inside this function. This makes sure that new code won't be missing reset after error. Also rename send_err_rsp to smp_error as it now accept smp context instead of conn. Change-Id: I25cdca066817f79f6c2f83d9f9bd0876b7909085 Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
parent
7955cf9911
commit
f2c4f06b15
1 changed files with 12 additions and 16 deletions
|
@ -693,12 +693,16 @@ struct net_buf *bt_smp_create_pdu(struct bt_conn *conn, uint8_t op, size_t len)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static void send_err_rsp(struct bt_conn *conn, uint8_t reason)
|
||||
static void smp_error(struct bt_smp *smp, uint8_t reason)
|
||||
{
|
||||
struct bt_smp_pairing_fail *rsp;
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = bt_smp_create_pdu(conn, BT_SMP_CMD_PAIRING_FAIL, sizeof(*rsp));
|
||||
/* reset context */
|
||||
smp_reset(smp);
|
||||
|
||||
buf = bt_smp_create_pdu(smp->chan.conn, BT_SMP_CMD_PAIRING_FAIL,
|
||||
sizeof(*rsp));
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
|
@ -706,7 +710,7 @@ static void send_err_rsp(struct bt_conn *conn, uint8_t reason)
|
|||
rsp = net_buf_add(buf, sizeof(*rsp));
|
||||
rsp->reason = reason;
|
||||
|
||||
bt_l2cap_send(conn, BT_L2CAP_CID_SMP, buf);
|
||||
bt_l2cap_send(smp->chan.conn, BT_L2CAP_CID_SMP, buf);
|
||||
}
|
||||
|
||||
static int smp_init(struct bt_smp *smp)
|
||||
|
@ -1419,8 +1423,7 @@ void bt_smp_dhkey_ready(const uint8_t *dhkey)
|
|||
}
|
||||
|
||||
if (!dhkey && atomic_test_bit(&smp->flags, SMP_FLAG_DHKEY_SEND)) {
|
||||
send_err_rsp(smp->chan.conn, BT_SMP_ERR_DHKEY_CHECK_FAILED);
|
||||
smp_reset(smp);
|
||||
smp_error(smp, BT_SMP_ERR_DHKEY_CHECK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1455,16 +1458,13 @@ void bt_smp_dhkey_ready(const uint8_t *dhkey)
|
|||
if (smp_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->preq[1],
|
||||
&smp->chan.conn->le.init_addr,
|
||||
&smp->chan.conn->le.resp_addr, re)) {
|
||||
send_err_rsp(smp->chan.conn, BT_SMP_ERR_UNSPECIFIED);
|
||||
smp_reset(smp);
|
||||
smp_error(smp, BT_SMP_ERR_UNSPECIFIED);
|
||||
return;
|
||||
}
|
||||
|
||||
/* compare received E with calculated remote */
|
||||
if (memcmp(smp->e, re, 16)) {
|
||||
send_err_rsp(smp->chan.conn,
|
||||
BT_SMP_ERR_DHKEY_CHECK_FAILED);
|
||||
smp_reset(smp);
|
||||
smp_error(smp, BT_SMP_ERR_DHKEY_CHECK_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2221,9 +2221,7 @@ static void bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
|
|||
}
|
||||
|
||||
if (err) {
|
||||
send_err_rsp(chan->conn, err);
|
||||
|
||||
smp_reset(smp);
|
||||
smp_error(smp, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2849,9 +2847,7 @@ void bt_auth_cancel(struct bt_conn *conn)
|
|||
return;
|
||||
}
|
||||
|
||||
send_err_rsp(conn, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
||||
|
||||
smp_reset(smp);
|
||||
smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
||||
}
|
||||
|
||||
static int bt_smp_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue