Bluetooth: SMP: Return errors from authentication APIs
This way we can pass any errors back to the application. Change-Id: Ic53b858a73436e1c9c4d03e358aeffae7fd837ab Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
432c2db4d8
commit
672bf0d63c
3 changed files with 29 additions and 24 deletions
|
@ -2699,7 +2699,7 @@ int bt_auth_passkey_confirm(struct bt_conn *conn, bool match)
|
||||||
};
|
};
|
||||||
#if defined(CONFIG_BLUETOOTH_SMP)
|
#if defined(CONFIG_BLUETOOTH_SMP)
|
||||||
if (conn->type == BT_CONN_TYPE_LE) {
|
if (conn->type == BT_CONN_TYPE_LE) {
|
||||||
bt_smp_auth_passkey_confirm(conn, match);
|
return bt_smp_auth_passkey_confirm(conn, match);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLUETOOTH_SMP */
|
#endif /* CONFIG_BLUETOOTH_SMP */
|
||||||
|
|
||||||
|
@ -2713,8 +2713,7 @@ int bt_auth_cancel(struct bt_conn *conn)
|
||||||
}
|
}
|
||||||
#if defined(CONFIG_BLUETOOTH_SMP)
|
#if defined(CONFIG_BLUETOOTH_SMP)
|
||||||
if (conn->type == BT_CONN_TYPE_LE) {
|
if (conn->type == BT_CONN_TYPE_LE) {
|
||||||
bt_smp_auth_cancel(conn);
|
return bt_smp_auth_cancel(conn);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLUETOOTH_SMP */
|
#endif /* CONFIG_BLUETOOTH_SMP */
|
||||||
#if defined(CONFIG_BLUETOOTH_BREDR)
|
#if defined(CONFIG_BLUETOOTH_BREDR)
|
||||||
|
|
|
@ -794,7 +794,7 @@ static void smp_send(struct bt_smp *smp, struct net_buf *buf)
|
||||||
smp_restart_timer(smp);
|
smp_restart_timer(smp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void smp_error(struct bt_smp *smp, uint8_t reason)
|
static int smp_error(struct bt_smp *smp, uint8_t reason)
|
||||||
{
|
{
|
||||||
struct bt_smp_pairing_fail *rsp;
|
struct bt_smp_pairing_fail *rsp;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
@ -805,7 +805,7 @@ static void smp_error(struct bt_smp *smp, uint8_t reason)
|
||||||
buf = smp_create_pdu(smp->chan.conn, BT_SMP_CMD_PAIRING_FAIL,
|
buf = smp_create_pdu(smp->chan.conn, BT_SMP_CMD_PAIRING_FAIL,
|
||||||
sizeof(*rsp));
|
sizeof(*rsp));
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
return;
|
return -ENOBUFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp = net_buf_add(buf, sizeof(*rsp));
|
rsp = net_buf_add(buf, sizeof(*rsp));
|
||||||
|
@ -813,6 +813,8 @@ static void smp_error(struct bt_smp *smp, uint8_t reason)
|
||||||
|
|
||||||
/* SMP timer is not restarted for PairingFailed so don't use smp_send */
|
/* SMP timer is not restarted for PairingFailed so don't use smp_send */
|
||||||
bt_l2cap_send(smp->chan.conn, BT_L2CAP_CID_SMP, buf);
|
bt_l2cap_send(smp->chan.conn, BT_L2CAP_CID_SMP, buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t smp_send_pairing_random(struct bt_smp *smp)
|
static uint8_t smp_send_pairing_random(struct bt_smp *smp)
|
||||||
|
@ -3168,23 +3170,23 @@ static inline int smp_self_test(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
|
int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
|
||||||
{
|
{
|
||||||
struct bt_smp *smp;
|
struct bt_smp *smp;
|
||||||
|
|
||||||
smp = smp_chan_get(conn);
|
smp = smp_chan_get(conn);
|
||||||
if (!smp) {
|
if (!smp) {
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) {
|
if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) {
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(CONFIG_BLUETOOTH_SMP_SC_ONLY)
|
#if !defined(CONFIG_BLUETOOTH_SMP_SC_ONLY)
|
||||||
if (!atomic_test_bit(&smp->flags, SMP_FLAG_SC)) {
|
if (!atomic_test_bit(&smp->flags, SMP_FLAG_SC)) {
|
||||||
legacy_passkey_entry(smp, passkey);
|
legacy_passkey_entry(smp, passkey);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* !CONFIG_BLUETOOTH_SMP_SC_ONLY */
|
#endif /* !CONFIG_BLUETOOTH_SMP_SC_ONLY */
|
||||||
|
|
||||||
|
@ -3194,46 +3196,48 @@ void bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey)
|
||||||
if (smp->chan.conn->role == BT_HCI_ROLE_MASTER) {
|
if (smp->chan.conn->role == BT_HCI_ROLE_MASTER) {
|
||||||
if (smp_send_pairing_confirm(smp)) {
|
if (smp_send_pairing_confirm(smp)) {
|
||||||
smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM);
|
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLUETOOTH_CENTRAL */
|
#endif /* CONFIG_BLUETOOTH_CENTRAL */
|
||||||
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
|
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
|
||||||
if (atomic_test_bit(&smp->flags, SMP_FLAG_CFM_DELAYED)) {
|
if (atomic_test_bit(&smp->flags, SMP_FLAG_CFM_DELAYED)) {
|
||||||
if (smp_send_pairing_confirm(smp)) {
|
if (smp_send_pairing_confirm(smp)) {
|
||||||
smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
|
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
|
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_smp_auth_passkey_confirm(struct bt_conn *conn, bool match)
|
int bt_smp_auth_passkey_confirm(struct bt_conn *conn, bool match)
|
||||||
{
|
{
|
||||||
struct bt_smp *smp;
|
struct bt_smp *smp;
|
||||||
|
|
||||||
smp = smp_chan_get(conn);
|
smp = smp_chan_get(conn);
|
||||||
if (!smp) {
|
if (!smp) {
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) {
|
if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) {
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if passkey doen't match abort pairing */
|
/* if passkey doen't match abort pairing */
|
||||||
if (!match) {
|
if (!match) {
|
||||||
smp_error(smp, BT_SMP_ERR_CONFIRM_FAILED);
|
smp_error(smp, BT_SMP_ERR_CONFIRM_FAILED);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait for DHKey being generated */
|
/* wait for DHKey being generated */
|
||||||
if (atomic_test_bit(&smp->flags, SMP_FLAG_DHKEY_PENDING)) {
|
if (atomic_test_bit(&smp->flags, SMP_FLAG_DHKEY_PENDING)) {
|
||||||
atomic_set_bit(&smp->flags, SMP_FLAG_DHKEY_SEND);
|
atomic_set_bit(&smp->flags, SMP_FLAG_DHKEY_SEND);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_test_bit(&smp->flags, SMP_FLAG_DHKEY_SEND)) {
|
if (atomic_test_bit(&smp->flags, SMP_FLAG_DHKEY_SEND)) {
|
||||||
|
@ -3244,7 +3248,7 @@ void bt_smp_auth_passkey_confirm(struct bt_conn *conn, bool match)
|
||||||
if (err) {
|
if (err) {
|
||||||
smp_error(smp, err);
|
smp_error(smp, err);
|
||||||
}
|
}
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLUETOOTH_CENTRAL */
|
#endif /* CONFIG_BLUETOOTH_CENTRAL */
|
||||||
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
|
#if defined(CONFIG_BLUETOOTH_PERIPHERAL)
|
||||||
|
@ -3254,18 +3258,20 @@ void bt_smp_auth_passkey_confirm(struct bt_conn *conn, bool match)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
|
#endif /* CONFIG_BLUETOOTH_PERIPHERAL */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_smp_auth_cancel(struct bt_conn *conn)
|
int bt_smp_auth_cancel(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
struct bt_smp *smp;
|
struct bt_smp *smp;
|
||||||
|
|
||||||
smp = smp_chan_get(conn);
|
smp = smp_chan_get(conn);
|
||||||
if (!smp) {
|
if (!smp) {
|
||||||
return;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
return smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_smp_update_keys(struct bt_conn *conn)
|
void bt_smp_update_keys(struct bt_conn *conn)
|
||||||
|
|
|
@ -141,9 +141,9 @@ void bt_smp_pkey_ready(void);
|
||||||
|
|
||||||
int bt_smp_init(void);
|
int bt_smp_init(void);
|
||||||
|
|
||||||
void bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
|
int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
|
||||||
void bt_smp_auth_passkey_confirm(struct bt_conn *conn, bool match);
|
int bt_smp_auth_passkey_confirm(struct bt_conn *conn, bool match);
|
||||||
void bt_smp_auth_cancel(struct bt_conn *conn);
|
int bt_smp_auth_cancel(struct bt_conn *conn);
|
||||||
|
|
||||||
/** brief Verify signed message
|
/** brief Verify signed message
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue