diff --git a/include/bluetooth/conn.h b/include/bluetooth/conn.h index afeaa7bacf903..8c6df6d28e966 100644 --- a/include/bluetooth/conn.h +++ b/include/bluetooth/conn.h @@ -751,6 +751,9 @@ enum bt_security_err { /** Invalid parameters. */ BT_SECURITY_ERR_INVALID_PARAM, + /** Distributed Key Rejected */ + BT_SECURITY_ERR_KEY_REJECTED, + /** Pairing failed but the exact reason could not be specified. */ BT_SECURITY_ERR_UNSPECIFIED, }; diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 3cdbc537b7049..c879f88d00ab5 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -430,6 +430,8 @@ static enum bt_security_err security_err_get(uint8_t smp_err) return BT_SECURITY_ERR_PAIR_NOT_ALLOWED; case BT_SMP_ERR_INVALID_PARAMS: return BT_SECURITY_ERR_INVALID_PARAM; + case BT_SMP_ERR_KEY_REJECTED: + return BT_SECURITY_ERR_KEY_REJECTED; case BT_SMP_ERR_UNSPECIFIED: default: return BT_SECURITY_ERR_UNSPECIFIED; diff --git a/subsys/bluetooth/host/smp.h b/subsys/bluetooth/host/smp.h index 6660f76bb20e1..e1f20094bc455 100644 --- a/subsys/bluetooth/host/smp.h +++ b/subsys/bluetooth/host/smp.h @@ -27,6 +27,7 @@ struct bt_smp_hdr { #define BT_SMP_ERR_NUMERIC_COMP_FAILED 0x0c #define BT_SMP_ERR_BREDR_PAIRING_IN_PROGRESS 0x0d #define BT_SMP_ERR_CROSS_TRANSP_NOT_ALLOWED 0x0e +#define BT_SMP_ERR_KEY_REJECTED 0x0f #define BT_SMP_IO_DISPLAY_ONLY 0x00 #define BT_SMP_IO_DISPLAY_YESNO 0x01 diff --git a/tests/bluetooth/tester/src/bttester.h b/tests/bluetooth/tester/src/bttester.h index acbc5b8f2a8a7..71e51cd1fc2a7 100644 --- a/tests/bluetooth/tester/src/bttester.h +++ b/tests/bluetooth/tester/src/bttester.h @@ -373,6 +373,13 @@ struct gap_bond_lost_ev { uint8_t address[6]; } __packed; +#define GAP_EV_PAIRING_FAILED 0x8c +struct gap_bond_pairing_failed_ev { + uint8_t address_type; + uint8_t address[6]; + uint8_t reason; +} __packed; + /* GATT Service */ /* commands */ #define GATT_READ_SUPPORTED_COMMANDS 0x01 diff --git a/tests/bluetooth/tester/src/gap.c b/tests/bluetooth/tester/src/gap.c index 6cbb3a7587948..c40ec69dc257a 100644 --- a/tests/bluetooth/tester/src/gap.c +++ b/tests/bluetooth/tester/src/gap.c @@ -825,6 +825,19 @@ enum bt_security_err auth_pairing_accept(struct bt_conn *conn, return BT_SECURITY_ERR_SUCCESS; } +void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason) +{ + struct gap_bond_pairing_failed_ev ev; + const bt_addr_le_t *addr = bt_conn_get_dst(conn); + + memcpy(ev.address, addr->a.val, sizeof(ev.address)); + ev.address_type = addr->type; + ev.reason = reason; + + tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PAIRING_FAILED, CONTROLLER_INDEX, + (uint8_t *)&ev, sizeof(ev)); +} + static void set_io_cap(const uint8_t *data, uint16_t len) { const struct gap_set_io_cap_cmd *cmd = (void *) data; @@ -862,6 +875,7 @@ static void set_io_cap(const uint8_t *data, uint16_t len) } cb.pairing_accept = auth_pairing_accept; + cb.pairing_failed = auth_pairing_failed; if (bt_conn_auth_cb_register(&cb)) { status = BTP_STATUS_FAILED;