Lines Matching refs:smp
216 #define DISPLAY_FIXED(smp) (IS_ENABLED(CONFIG_BT_FIXED_PASSKEY) && \ argument
218 (smp)->method == PASSKEY_DISPLAY)
306 static const struct bt_conn_auth_cb *latch_auth_cb(struct bt_smp *smp) in latch_auth_cb() argument
308 atomic_ptr_cas(&smp->auth_cb, BT_SMP_AUTH_CB_UNINITIALIZED, (atomic_ptr_val_t)bt_auth); in latch_auth_cb()
310 return atomic_ptr_get(&smp->auth_cb); in latch_auth_cb()
313 static uint8_t get_io_capa(struct bt_smp *smp) in get_io_capa() argument
315 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in get_io_capa()
356 static uint8_t legacy_get_pair_method(struct bt_smp *smp, uint8_t remote_io);
395 static uint8_t get_pair_method(struct bt_smp *smp, uint8_t remote_io) in get_pair_method() argument
398 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in get_pair_method()
399 return legacy_get_pair_method(smp, remote_io); in get_pair_method()
406 req = (struct bt_smp_pairing *)&smp->preq[1]; in get_pair_method()
407 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in get_pair_method()
425 return gen_method_sc[remote_io][get_io_capa(smp)]; in get_pair_method()
486 static struct net_buf *smp_create_pdu(struct bt_smp *smp, uint8_t op, size_t len) in smp_create_pdu() argument
493 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_create_pdu()
507 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_create_pdu()
517 static uint8_t get_encryption_key_size(struct bt_smp *smp) in get_encryption_key_size() argument
521 req = (struct bt_smp_pairing *)&smp->preq[1]; in get_encryption_key_size()
522 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in get_encryption_key_size()
535 static bool update_keys_check(struct bt_smp *smp, struct bt_keys *keys) in update_keys_check() argument
538 !atomic_test_bit(smp->flags, SMP_FLAG_SC) && in update_keys_check()
539 smp->method != LEGACY_OOB) { in update_keys_check()
544 smp->method != LEGACY_OOB) { in update_keys_check()
553 if (keys->enc_size > get_encryption_key_size(smp)) { in update_keys_check()
558 !atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in update_keys_check()
563 smp->method == JUST_WORKS) { in update_keys_check()
569 && smp->method == JUST_WORKS)) { in update_keys_check()
571 (keys->id == smp->chan.chan.conn->id)) { in update_keys_check()
579 static bool update_debug_keys_check(struct bt_smp *smp) in update_debug_keys_check() argument
581 struct bt_conn *conn = smp->chan.chan.conn; in update_debug_keys_check()
602 static void smp_pairing_complete(struct bt_smp *smp, uint8_t status);
604 static void smp_pairing_br_complete(struct bt_smp_br *smp, uint8_t status);
612 struct bt_smp *smp; in smp_check_complete() local
617 smp = CONTAINER_OF(chan, struct bt_smp, chan); in smp_check_complete()
618 smp->local_dist &= ~dist_complete; in smp_check_complete()
621 if (!smp->local_dist && !smp->remote_dist) { in smp_check_complete()
622 smp_pairing_complete(smp, 0); in smp_check_complete()
630 struct bt_smp_br *smp; in smp_check_complete() local
635 smp = CONTAINER_OF(chan, struct bt_smp_br, chan); in smp_check_complete()
636 smp->local_dist &= ~dist_complete; in smp_check_complete()
639 if (!smp->local_dist && !smp->remote_dist) { in smp_check_complete()
640 smp_pairing_br_complete(smp, 0); in smp_check_complete()
666 static void sc_derive_link_key(struct bt_smp *smp) in sc_derive_link_key() argument
670 struct bt_conn *conn = smp->chan.chan.conn; in sc_derive_link_key()
687 if (atomic_test_bit(smp->flags, SMP_FLAG_CT2)) { in sc_derive_link_key()
721 static void smp_br_reset(struct bt_smp_br *smp) in smp_br_reset() argument
726 atomic_set(smp->flags, 0); in smp_br_reset()
732 (void)k_work_cancel_delayable(&smp->work); in smp_br_reset()
734 atomic_set(smp->allowed_cmds, 0); in smp_br_reset()
736 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ); in smp_br_reset()
739 static void smp_pairing_br_complete(struct bt_smp_br *smp, uint8_t status) in smp_pairing_br_complete() argument
741 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_br_complete()
764 listener->pairing_failed(smp->chan.chan.conn, in smp_pairing_br_complete()
769 bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_br_complete()
779 listener->pairing_complete(smp->chan.chan.conn, in smp_pairing_br_complete()
785 smp_br_reset(smp); in smp_pairing_br_complete()
791 struct bt_smp_br *smp = CONTAINER_OF(dwork, struct bt_smp_br, work); in smp_br_timeout() local
795 smp_pairing_br_complete(smp, BT_SMP_ERR_UNSPECIFIED); in smp_br_timeout()
796 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_br_timeout()
799 static void smp_br_send(struct bt_smp_br *smp, struct net_buf *buf, in smp_br_send() argument
802 int err = bt_l2cap_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_BR_SMP, buf, cb, NULL); in smp_br_send()
813 k_work_reschedule(&smp->work, SMP_TIMEOUT); in smp_br_send()
818 struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan); in bt_smp_br_connected() local
823 atomic_set_bit(smp->flags, SMP_FLAG_BR_CONNECTED); in bt_smp_br_connected()
829 if (atomic_test_bit(smp->flags, SMP_FLAG_BR_PAIR)) { in bt_smp_br_connected()
836 struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan); in bt_smp_br_disconnected() local
844 (void)k_work_cancel_delayable(&smp->work); in bt_smp_br_disconnected()
846 (void)memset(smp, 0, sizeof(*smp)); in bt_smp_br_disconnected()
849 static void smp_br_init(struct bt_smp_br *smp) in smp_br_init() argument
854 (void)memset(smp, 0, offsetof(struct bt_smp_br, chan)); in smp_br_init()
856 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_FAIL); in smp_br_init()
859 static void smp_br_derive_ltk(struct bt_smp_br *smp) in smp_br_derive_ltk() argument
863 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_derive_ltk()
892 if (atomic_test_bit(smp->flags, SMP_FLAG_CT2)) { in smp_br_derive_ltk()
920 keys->enc_size = smp->enc_key_size; in smp_br_derive_ltk()
931 static struct net_buf *smp_br_create_pdu(struct bt_smp_br *smp, uint8_t op, in smp_br_create_pdu() argument
939 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_br_create_pdu()
953 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_br_create_pdu()
963 static void smp_br_distribute_keys(struct bt_smp_br *smp) in smp_br_distribute_keys() argument
965 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_distribute_keys()
983 if (smp->local_dist & BT_SMP_DIST_ID_KEY) { in smp_br_distribute_keys()
988 smp->local_dist &= ~BT_SMP_DIST_ID_KEY; in smp_br_distribute_keys()
990 buf = smp_br_create_pdu(smp, BT_SMP_CMD_IDENT_INFO, in smp_br_distribute_keys()
1000 smp_br_send(smp, buf, NULL); in smp_br_distribute_keys()
1002 buf = smp_br_create_pdu(smp, BT_SMP_CMD_IDENT_ADDR_INFO, in smp_br_distribute_keys()
1012 smp_br_send(smp, buf, smp_id_sent); in smp_br_distribute_keys()
1017 if (smp->local_dist & BT_SMP_DIST_SIGN) { in smp_br_distribute_keys()
1021 smp->local_dist &= ~BT_SMP_DIST_SIGN; in smp_br_distribute_keys()
1023 buf = smp_br_create_pdu(smp, BT_SMP_CMD_SIGNING_INFO, in smp_br_distribute_keys()
1037 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_br_distribute_keys()
1043 smp_br_send(smp, buf, smp_sign_info_sent); in smp_br_distribute_keys()
1048 static bool smp_br_pairing_allowed(struct bt_smp_br *smp) in smp_br_pairing_allowed() argument
1050 if (smp->chan.chan.conn->encrypt == 0x02) { in smp_br_pairing_allowed()
1055 smp->chan.chan.conn->encrypt == 0x01) { in smp_br_pairing_allowed()
1063 static uint8_t smp_br_pairing_req(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_pairing_req() argument
1066 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_pairing_req()
1083 if (!smp_br_pairing_allowed(smp)) { in smp_br_pairing_req()
1097 rsp_buf = smp_br_create_pdu(smp, BT_SMP_CMD_PAIRING_RSP, sizeof(*rsp)); in smp_br_pairing_req()
1102 smp_br_init(smp); in smp_br_pairing_req()
1103 smp->enc_key_size = max_key_size; in smp_br_pairing_req()
1120 smp->local_dist = rsp->resp_key_dist; in smp_br_pairing_req()
1121 smp->remote_dist = rsp->init_key_dist; in smp_br_pairing_req()
1128 smp_br_send(smp, rsp_buf, NULL); in smp_br_pairing_req()
1130 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in smp_br_pairing_req()
1133 if ((smp->local_dist & BT_SMP_DIST_ENC_KEY) && in smp_br_pairing_req()
1134 (smp->remote_dist & BT_SMP_DIST_ENC_KEY)) { in smp_br_pairing_req()
1135 smp_br_derive_ltk(smp); in smp_br_pairing_req()
1137 smp->local_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_req()
1138 smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_req()
1141 smp_br_distribute_keys(smp); in smp_br_pairing_req()
1143 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_br_pairing_req()
1144 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in smp_br_pairing_req()
1145 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_br_pairing_req()
1146 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_br_pairing_req()
1150 if (!smp->local_dist && !smp->remote_dist) { in smp_br_pairing_req()
1151 smp_pairing_br_complete(smp, 0); in smp_br_pairing_req()
1157 static uint8_t smp_br_pairing_rsp(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_pairing_rsp() argument
1160 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_pairing_rsp()
1178 smp->local_dist &= rsp->init_key_dist; in smp_br_pairing_rsp()
1179 smp->remote_dist &= rsp->resp_key_dist; in smp_br_pairing_rsp()
1181 smp->local_dist &= SEND_KEYS_SC; in smp_br_pairing_rsp()
1182 smp->remote_dist &= RECV_KEYS_SC; in smp_br_pairing_rsp()
1186 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_br_pairing_rsp()
1187 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in smp_br_pairing_rsp()
1188 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_br_pairing_rsp()
1189 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_br_pairing_rsp()
1193 if ((smp->local_dist & BT_SMP_DIST_ENC_KEY) && in smp_br_pairing_rsp()
1194 (smp->remote_dist & BT_SMP_DIST_ENC_KEY)) { in smp_br_pairing_rsp()
1195 smp_br_derive_ltk(smp); in smp_br_pairing_rsp()
1197 smp->local_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_rsp()
1198 smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_rsp()
1201 if (smp->remote_dist) { in smp_br_pairing_rsp()
1205 smp_br_distribute_keys(smp); in smp_br_pairing_rsp()
1208 if (!smp->local_dist && !smp->remote_dist) { in smp_br_pairing_rsp()
1209 smp_pairing_br_complete(smp, 0); in smp_br_pairing_rsp()
1215 static uint8_t smp_br_pairing_failed(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_pairing_failed() argument
1221 smp_pairing_br_complete(smp, req->reason); in smp_br_pairing_failed()
1222 smp_br_reset(smp); in smp_br_pairing_failed()
1228 static uint8_t smp_br_ident_info(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_ident_info() argument
1231 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_ident_info()
1254 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_ADDR_INFO); in smp_br_ident_info()
1259 static uint8_t smp_br_ident_addr_info(struct bt_smp_br *smp, in smp_br_ident_addr_info() argument
1262 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_ident_addr_info()
1281 smp->remote_dist &= ~BT_SMP_DIST_ID_KEY; in smp_br_ident_addr_info()
1283 if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_br_ident_addr_info()
1284 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_br_ident_addr_info()
1287 if (conn->role == BT_CONN_ROLE_CENTRAL && !smp->remote_dist) { in smp_br_ident_addr_info()
1288 smp_br_distribute_keys(smp); in smp_br_ident_addr_info()
1292 if (!smp->local_dist && !smp->remote_dist) { in smp_br_ident_addr_info()
1293 smp_pairing_br_complete(smp, 0); in smp_br_ident_addr_info()
1300 static uint8_t smp_br_signing_info(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_signing_info() argument
1303 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_signing_info()
1324 smp->remote_dist &= ~BT_SMP_DIST_SIGN; in smp_br_signing_info()
1326 if (conn->role == BT_CONN_ROLE_CENTRAL && !smp->remote_dist) { in smp_br_signing_info()
1327 smp_br_distribute_keys(smp); in smp_br_signing_info()
1331 if (!smp->local_dist && !smp->remote_dist) { in smp_br_signing_info()
1332 smp_pairing_br_complete(smp, 0); in smp_br_signing_info()
1338 static uint8_t smp_br_signing_info(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_signing_info() argument
1345 uint8_t (*func)(struct bt_smp_br *smp, struct net_buf *buf);
1364 static int smp_br_error(struct bt_smp_br *smp, uint8_t reason) in smp_br_error() argument
1370 smp_br_reset(smp); in smp_br_error()
1372 buf = smp_br_create_pdu(smp, BT_SMP_CMD_PAIRING_FAIL, sizeof(*rsp)); in smp_br_error()
1384 if (bt_l2cap_send(smp->chan.chan.conn, BT_L2CAP_CID_SMP, buf)) { in smp_br_error()
1393 struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan); in bt_smp_br_recv() local
1410 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in bt_smp_br_recv()
1418 smp_br_error(smp, BT_SMP_ERR_CMD_NOTSUPP); in bt_smp_br_recv()
1422 if (!atomic_test_and_clear_bit(smp->allowed_cmds, hdr->code)) { in bt_smp_br_recv()
1424 smp_br_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_br_recv()
1430 smp_br_error(smp, BT_SMP_ERR_INVALID_PARAMS); in bt_smp_br_recv()
1434 err = br_handlers[hdr->code].func(smp, buf); in bt_smp_br_recv()
1436 smp_br_error(smp, err); in bt_smp_br_recv()
1469 struct bt_smp_br *smp = &bt_smp_br_pool[i]; in bt_smp_br_accept() local
1471 if (smp->chan.chan.conn) { in bt_smp_br_accept()
1475 smp->chan.chan.ops = &ops; in bt_smp_br_accept()
1477 *chan = &smp->chan.chan; in bt_smp_br_accept()
1479 k_work_init_delayable(&smp->work, smp_br_timeout); in bt_smp_br_accept()
1480 smp_br_reset(smp); in bt_smp_br_accept()
1508 struct bt_smp_br *smp; in bt_smp_br_send_pairing_req() local
1510 smp = smp_br_chan_get(conn); in bt_smp_br_send_pairing_req()
1511 if (!smp) { in bt_smp_br_send_pairing_req()
1516 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in bt_smp_br_send_pairing_req()
1521 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_br_send_pairing_req()
1526 if (!smp_br_pairing_allowed(smp)) { in bt_smp_br_send_pairing_req()
1531 if (!atomic_test_bit(smp->flags, SMP_FLAG_BR_CONNECTED)) { in bt_smp_br_send_pairing_req()
1532 atomic_set_bit(smp->flags, SMP_FLAG_BR_PAIR); in bt_smp_br_send_pairing_req()
1542 smp_br_init(smp); in bt_smp_br_send_pairing_req()
1543 smp->enc_key_size = max_key_size; in bt_smp_br_send_pairing_req()
1545 req_buf = smp_br_create_pdu(smp, BT_SMP_CMD_PAIRING_REQ, sizeof(*req)); in bt_smp_br_send_pairing_req()
1566 smp_br_send(smp, req_buf, NULL); in bt_smp_br_send_pairing_req()
1568 smp->local_dist = BR_SEND_KEYS_SC; in bt_smp_br_send_pairing_req()
1569 smp->remote_dist = BR_RECV_KEYS_SC; in bt_smp_br_send_pairing_req()
1571 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RSP); in bt_smp_br_send_pairing_req()
1573 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in bt_smp_br_send_pairing_req()
1579 static void smp_reset(struct bt_smp *smp) in smp_reset() argument
1581 struct bt_conn *conn = smp->chan.chan.conn; in smp_reset()
1586 atomic_set(smp->flags, 0); in smp_reset()
1592 (void)k_work_cancel_delayable(&smp->work); in smp_reset()
1594 smp->method = JUST_WORKS; in smp_reset()
1595 atomic_set(smp->allowed_cmds, 0); in smp_reset()
1599 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in smp_reset()
1604 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ); in smp_reset()
1631 static void smp_pairing_complete(struct bt_smp *smp, uint8_t status) in smp_pairing_complete() argument
1633 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_complete()
1643 if (atomic_test_bit(smp->flags, SMP_FLAG_DERIVE_LK) && in smp_pairing_complete()
1644 (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) || in smp_pairing_complete()
1646 sc_derive_link_key(smp); in smp_pairing_complete()
1649 bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_complete()
1675 atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR))) { in smp_pairing_complete()
1680 if (!atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) { in smp_pairing_complete()
1689 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_pairing_complete()
1702 smp_reset(smp); in smp_pairing_complete()
1711 struct bt_smp *smp = CONTAINER_OF(work, struct bt_smp, work); in smp_timeout() local
1715 smp_pairing_complete(smp, BT_SMP_ERR_UNSPECIFIED); in smp_timeout()
1720 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_timeout()
1723 static void smp_send(struct bt_smp *smp, struct net_buf *buf, in smp_send() argument
1726 int err = bt_l2cap_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_SMP, buf, cb, NULL); in smp_send()
1737 k_work_reschedule(&smp->work, SMP_TIMEOUT); in smp_send()
1740 static int smp_error(struct bt_smp *smp, uint8_t reason) in smp_error() argument
1749 remote_already_completed = (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR) && in smp_error()
1750 !smp->local_dist && !smp->remote_dist); in smp_error()
1752 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING) || in smp_error()
1753 atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING) || in smp_error()
1754 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in smp_error()
1756 smp_pairing_complete(smp, reason); in smp_error()
1768 bt_conn_disconnect(smp->chan.chan.conn, BT_HCI_ERR_AUTH_FAIL); in smp_error()
1772 buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_FAIL, sizeof(*rsp)); in smp_error()
1781 if (bt_l2cap_send(smp->chan.chan.conn, BT_L2CAP_CID_SMP, buf)) { in smp_error()
1788 static uint8_t smp_send_pairing_random(struct bt_smp *smp) in smp_send_pairing_random() argument
1793 rsp_buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_RANDOM, sizeof(*req)); in smp_send_pairing_random()
1799 memcpy(req->val, smp->prnd, sizeof(req->val)); in smp_send_pairing_random()
1801 smp_send(smp, rsp_buf, NULL, NULL); in smp_send_pairing_random()
1862 static uint8_t smp_send_pairing_confirm(struct bt_smp *smp) in smp_send_pairing_confirm() argument
1868 switch (smp->method) { in smp_send_pairing_confirm()
1882 r = (smp->passkey >> smp->passkey_round) & 0x01; in smp_send_pairing_confirm()
1886 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_send_pairing_confirm()
1890 buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_CONFIRM, sizeof(*req)); in smp_send_pairing_confirm()
1897 if (bt_crypto_f4(sc_public_key, smp->pkey, smp->prnd, r, req->val)) { in smp_send_pairing_confirm()
1902 smp_send(smp, buf, NULL, NULL); in smp_send_pairing_confirm()
1904 atomic_clear_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in smp_send_pairing_confirm()
1917 static void legacy_distribute_keys(struct bt_smp *smp) in legacy_distribute_keys() argument
1919 struct bt_conn *conn = smp->chan.chan.conn; in legacy_distribute_keys()
1922 if (smp->local_dist & BT_SMP_DIST_ENC_KEY) { in legacy_distribute_keys()
1938 buf = smp_create_pdu(smp, BT_SMP_CMD_ENCRYPT_INFO, in legacy_distribute_keys()
1954 smp_send(smp, buf, NULL, NULL); in legacy_distribute_keys()
1956 buf = smp_create_pdu(smp, BT_SMP_CMD_CENTRAL_IDENT, in legacy_distribute_keys()
1967 smp_send(smp, buf, smp_ident_sent, NULL); in legacy_distribute_keys()
1969 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in legacy_distribute_keys()
1983 static uint8_t bt_smp_distribute_keys(struct bt_smp *smp) in bt_smp_distribute_keys() argument
1985 struct bt_conn *conn = smp->chan.chan.conn; in bt_smp_distribute_keys()
1995 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_distribute_keys()
1996 legacy_distribute_keys(smp); in bt_smp_distribute_keys()
2001 if (smp->local_dist & BT_SMP_DIST_ID_KEY) { in bt_smp_distribute_keys()
2006 buf = smp_create_pdu(smp, BT_SMP_CMD_IDENT_INFO, in bt_smp_distribute_keys()
2016 smp_send(smp, buf, NULL, NULL); in bt_smp_distribute_keys()
2018 buf = smp_create_pdu(smp, BT_SMP_CMD_IDENT_ADDR_INFO, in bt_smp_distribute_keys()
2028 smp_send(smp, buf, smp_id_sent, NULL); in bt_smp_distribute_keys()
2033 if (smp->local_dist & BT_SMP_DIST_SIGN) { in bt_smp_distribute_keys()
2037 buf = smp_create_pdu(smp, BT_SMP_CMD_SIGNING_INFO, in bt_smp_distribute_keys()
2050 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in bt_smp_distribute_keys()
2056 smp_send(smp, buf, smp_sign_info_sent, NULL); in bt_smp_distribute_keys()
2064 static uint8_t send_pairing_rsp(struct bt_smp *smp) in send_pairing_rsp() argument
2069 rsp_buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_RSP, sizeof(*rsp)); in send_pairing_rsp()
2075 memcpy(rsp, smp->prsp + 1, sizeof(*rsp)); in send_pairing_rsp()
2077 smp_send(smp, rsp_buf, NULL, NULL); in send_pairing_rsp()
2083 static uint8_t smp_pairing_accept_query(struct bt_smp *smp, struct bt_smp_pairing *pairing) in smp_pairing_accept_query() argument
2086 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_accept_query()
2087 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_accept_query()
2124 static uint8_t legacy_get_pair_method(struct bt_smp *smp, uint8_t remote_io) in legacy_get_pair_method() argument
2133 req = (struct bt_smp_pairing *)&smp->preq[1]; in legacy_get_pair_method()
2134 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in legacy_get_pair_method()
2146 method = gen_method_legacy[remote_io][get_io_capa(smp)]; in legacy_get_pair_method()
2152 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in legacy_get_pair_method()
2162 static uint8_t legacy_request_tk(struct bt_smp *smp) in legacy_request_tk() argument
2164 struct bt_conn *conn = smp->chan.chan.conn; in legacy_request_tk()
2165 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in legacy_request_tk()
2176 smp->method == JUST_WORKS) { in legacy_request_tk()
2181 switch (smp->method) { in legacy_request_tk()
2188 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_request_tk()
2189 smp_auth_cb->oob_data_request(smp->chan.chan.conn, &info); in legacy_request_tk()
2212 atomic_set_bit(smp->flags, SMP_FLAG_DISPLAY); in legacy_request_tk()
2216 sys_put_le32(passkey, smp->tk); in legacy_request_tk()
2220 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_request_tk()
2226 LOG_ERR("Unknown pairing method (%u)", smp->method); in legacy_request_tk()
2233 static uint8_t legacy_send_pairing_confirm(struct bt_smp *smp) in legacy_send_pairing_confirm() argument
2235 struct bt_conn *conn = smp->chan.chan.conn; in legacy_send_pairing_confirm()
2239 buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_CONFIRM, sizeof(*req)); in legacy_send_pairing_confirm()
2246 if (smp_c1(smp->tk, smp->prnd, smp->preq, smp->prsp, in legacy_send_pairing_confirm()
2252 smp_send(smp, buf, NULL, NULL); in legacy_send_pairing_confirm()
2254 atomic_clear_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in legacy_send_pairing_confirm()
2260 static uint8_t legacy_pairing_req(struct bt_smp *smp) in legacy_pairing_req() argument
2262 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in legacy_pairing_req()
2267 ret = legacy_request_tk(smp); in legacy_pairing_req()
2273 if ((DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in legacy_pairing_req()
2274 !atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in legacy_pairing_req()
2276 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_pairing_req()
2277 smp_auth_cb->pairing_confirm(smp->chan.chan.conn); in legacy_pairing_req()
2281 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_pairing_req()
2282 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in legacy_pairing_req()
2283 return send_pairing_rsp(smp); in legacy_pairing_req()
2287 static uint8_t legacy_pairing_random(struct bt_smp *smp) in legacy_pairing_random() argument
2289 struct bt_conn *conn = smp->chan.chan.conn; in legacy_pairing_random()
2296 err = smp_c1(smp->tk, smp->rrnd, smp->preq, smp->prsp, in legacy_pairing_random()
2302 LOG_DBG("pcnf %s", bt_hex(smp->pcnf, 16)); in legacy_pairing_random()
2305 if (memcmp(smp->pcnf, tmp, sizeof(smp->pcnf))) { in legacy_pairing_random()
2314 err = smp_s1(smp->tk, smp->rrnd, smp->prnd, tmp); in legacy_pairing_random()
2323 get_encryption_key_size(smp))) { in legacy_pairing_random()
2328 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in legacy_pairing_random()
2331 if (smp->remote_dist & BT_SMP_DIST_ENC_KEY) { in legacy_pairing_random()
2332 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_random()
2334 } else if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in legacy_pairing_random()
2335 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_random()
2337 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in legacy_pairing_random()
2338 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_random()
2347 err = smp_s1(smp->tk, smp->prnd, smp->rrnd, tmp); in legacy_pairing_random()
2353 memcpy(smp->tk, tmp, sizeof(smp->tk)); in legacy_pairing_random()
2354 LOG_DBG("generated STK %s", bt_hex(smp->tk, 16)); in legacy_pairing_random()
2356 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in legacy_pairing_random()
2358 return smp_send_pairing_random(smp); in legacy_pairing_random()
2364 static uint8_t legacy_pairing_confirm(struct bt_smp *smp) in legacy_pairing_confirm() argument
2369 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in legacy_pairing_confirm()
2370 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_pairing_confirm()
2371 return legacy_send_pairing_confirm(smp); in legacy_pairing_confirm()
2375 if (!atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in legacy_pairing_confirm()
2376 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_confirm()
2378 return legacy_send_pairing_confirm(smp); in legacy_pairing_confirm()
2381 atomic_set_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in legacy_pairing_confirm()
2387 static void legacy_user_tk_entry(struct bt_smp *smp) in legacy_user_tk_entry() argument
2389 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_CFM_DELAYED)) { in legacy_user_tk_entry()
2394 if (legacy_pairing_confirm(smp)) { in legacy_user_tk_entry()
2395 smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in legacy_user_tk_entry()
2400 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in legacy_user_tk_entry()
2401 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_user_tk_entry()
2406 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in legacy_user_tk_entry()
2410 static void legacy_passkey_entry(struct bt_smp *smp, unsigned int passkey) in legacy_passkey_entry() argument
2413 memcpy(smp->tk, &passkey, sizeof(passkey)); in legacy_passkey_entry()
2415 legacy_user_tk_entry(smp); in legacy_passkey_entry()
2418 static uint8_t smp_encrypt_info(struct bt_smp *smp, struct net_buf *buf) in smp_encrypt_info() argument
2422 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_encrypt_info()
2424 struct bt_conn *conn = smp->chan.chan.conn; in smp_encrypt_info()
2436 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_CENTRAL_IDENT); in smp_encrypt_info()
2441 static uint8_t smp_central_ident(struct bt_smp *smp, struct net_buf *buf) in smp_central_ident() argument
2443 struct bt_conn *conn = smp->chan.chan.conn; in smp_central_ident()
2448 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_central_ident()
2462 smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_central_ident()
2464 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_central_ident()
2465 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in smp_central_ident()
2466 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_central_ident()
2467 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_central_ident()
2471 conn->role == BT_HCI_ROLE_CENTRAL && !smp->remote_dist) { in smp_central_ident()
2472 err = bt_smp_distribute_keys(smp); in smp_central_ident()
2479 if (!smp->local_dist && !smp->remote_dist) { in smp_central_ident()
2480 smp_pairing_complete(smp, 0); in smp_central_ident()
2487 static uint8_t legacy_pairing_rsp(struct bt_smp *smp) in legacy_pairing_rsp() argument
2489 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in legacy_pairing_rsp()
2494 ret = legacy_request_tk(smp); in legacy_pairing_rsp()
2500 if ((DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in legacy_pairing_rsp()
2501 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in legacy_pairing_rsp()
2503 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_pairing_rsp()
2504 smp_auth_cb->pairing_confirm(smp->chan.chan.conn); in legacy_pairing_rsp()
2508 if (!atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in legacy_pairing_rsp()
2509 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_pairing_rsp()
2510 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in legacy_pairing_rsp()
2511 return legacy_send_pairing_confirm(smp); in legacy_pairing_rsp()
2514 atomic_set_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in legacy_pairing_rsp()
2520 static uint8_t smp_encrypt_info(struct bt_smp *smp, struct net_buf *buf) in smp_encrypt_info() argument
2525 static uint8_t smp_central_ident(struct bt_smp *smp, struct net_buf *buf) in smp_central_ident() argument
2531 static int smp_init(struct bt_smp *smp) in smp_init() argument
2536 (void)memset(smp, 0, offsetof(struct bt_smp, chan)); in smp_init()
2539 if (bt_rand(smp->prnd, 16)) { in smp_init()
2543 LOG_DBG("prnd %s", bt_hex(smp->prnd, 16)); in smp_init()
2545 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_FAIL); in smp_init()
2569 static uint8_t get_auth(struct bt_smp *smp, uint8_t auth) in get_auth() argument
2571 struct bt_conn *conn = smp->chan.chan.conn; in get_auth()
2579 if ((get_io_capa(smp) == BT_SMP_IO_NO_INPUT_OUTPUT) || in get_auth()
2602 static uint8_t remote_sec_level_reachable(struct bt_smp *smp) in remote_sec_level_reachable() argument
2604 bt_security_t sec = smp->chan.chan.conn->required_sec_level; in remote_sec_level_reachable()
2619 if (get_encryption_key_size(smp) != BT_SMP_MAX_ENC_KEY_SIZE) { in remote_sec_level_reachable()
2623 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in remote_sec_level_reachable()
2628 if (smp->method == JUST_WORKS) { in remote_sec_level_reachable()
2638 static bool sec_level_reachable(struct bt_smp *smp) in sec_level_reachable() argument
2640 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in sec_level_reachable()
2642 switch (smp->chan.chan.conn->required_sec_level) { in sec_level_reachable()
2647 return get_io_capa(smp) != BT_SMP_IO_NO_INPUT_OUTPUT || in sec_level_reachable()
2650 return (get_io_capa(smp) != BT_SMP_IO_NO_INPUT_OUTPUT || in sec_level_reachable()
2672 struct bt_smp *smp; in bt_smp_request_ltk() local
2675 smp = smp_chan_get(conn); in bt_smp_request_ltk()
2676 if (!smp) { in bt_smp_request_ltk()
2685 atomic_test_bit(smp->flags, SMP_FLAG_PAIRING) && in bt_smp_request_ltk()
2686 atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in bt_smp_request_ltk()
2687 enc_size = get_encryption_key_size(smp); in bt_smp_request_ltk()
2693 memcpy(ltk, smp->tk, enc_size); in bt_smp_request_ltk()
2699 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_request_ltk()
2722 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_request_ltk()
2738 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_request_ltk()
2743 if (atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in bt_smp_request_ltk()
2751 smp_reset(smp); in bt_smp_request_ltk()
2758 struct bt_smp *smp; in smp_send_security_req() local
2764 smp = smp_chan_get(conn); in smp_send_security_req()
2765 if (!smp) { in smp_send_security_req()
2770 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_send_security_req()
2775 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_send_security_req()
2779 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in smp_send_security_req()
2784 if (!(sec_level_reachable(smp) || smp_keys_check(conn))) { in smp_send_security_req()
2795 if (smp_init(smp) != 0) { in smp_send_security_req()
2799 req_buf = smp_create_pdu(smp, BT_SMP_CMD_SECURITY_REQUEST, in smp_send_security_req()
2806 req->auth_req = get_auth(smp, BT_SMP_AUTH_DEFAULT); in smp_send_security_req()
2815 atomic_set_bit(smp->flags, SMP_FLAG_SEC_REQ); in smp_send_security_req()
2816 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ); in smp_send_security_req()
2821 static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_req() argument
2823 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_req()
2824 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_req()
2851 if (!atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in smp_pairing_req()
2852 int ret = smp_init(smp); in smp_pairing_req()
2860 smp->preq[0] = BT_SMP_CMD_PAIRING_REQ; in smp_pairing_req()
2861 memcpy(smp->preq + 1, req, sizeof(*req)); in smp_pairing_req()
2864 smp->prsp[0] = BT_SMP_CMD_PAIRING_RSP; in smp_pairing_req()
2865 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in smp_pairing_req()
2867 rsp->auth_req = get_auth(smp, req->auth_req); in smp_pairing_req()
2868 rsp->io_capability = get_io_capa(smp); in smp_pairing_req()
2875 atomic_set_bit(smp->flags, SMP_FLAG_SC); in smp_pairing_req()
2881 if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_req()
2891 atomic_set_bit(smp->flags, SMP_FLAG_CT2); in smp_pairing_req()
2896 atomic_set_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_req()
2906 smp->local_dist = rsp->resp_key_dist; in smp_pairing_req()
2907 smp->remote_dist = rsp->init_key_dist; in smp_pairing_req()
2909 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in smp_pairing_req()
2911 smp->method = get_pair_method(smp, req->io_capability); in smp_pairing_req()
2913 if (!update_keys_check(smp, conn->le.keys)) { in smp_pairing_req()
2917 err = remote_sec_level_reachable(smp); in smp_pairing_req()
2922 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_req()
2927 err = smp_pairing_accept_query(smp, req); in smp_pairing_req()
2933 return legacy_pairing_req(smp); in smp_pairing_req()
2938 err = smp_pairing_accept_query(smp, req); in smp_pairing_req()
2945 (DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in smp_pairing_req()
2946 !atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in smp_pairing_req()
2948 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_req()
2953 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in smp_pairing_req()
2960 return send_pairing_rsp(smp); in smp_pairing_req()
2963 static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_req() argument
2969 static uint8_t sc_send_public_key(struct bt_smp *smp) in sc_send_public_key() argument
2974 req_buf = smp_create_pdu(smp, BT_SMP_CMD_PUBLIC_KEY, sizeof(*req)); in sc_send_public_key()
2984 smp_send(smp, req_buf, NULL, NULL); in sc_send_public_key()
2987 atomic_set_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY); in sc_send_public_key()
2996 struct bt_smp *smp; in smp_send_pairing_req() local
3002 smp = smp_chan_get(conn); in smp_send_pairing_req()
3003 if (!smp) { in smp_send_pairing_req()
3008 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_send_pairing_req()
3015 if (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) { in smp_send_pairing_req()
3020 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_send_pairing_req()
3025 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in smp_send_pairing_req()
3030 if (!sec_level_reachable(smp)) { in smp_send_pairing_req()
3041 if (smp_init(smp)) { in smp_send_pairing_req()
3045 req_buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_REQ, sizeof(*req)); in smp_send_pairing_req()
3052 req->auth_req = get_auth(smp, BT_SMP_AUTH_DEFAULT); in smp_send_pairing_req()
3053 req->io_capability = get_io_capa(smp); in smp_send_pairing_req()
3072 smp->local_dist = req->init_key_dist; in smp_send_pairing_req()
3073 smp->remote_dist = req->resp_key_dist; in smp_send_pairing_req()
3076 smp->preq[0] = BT_SMP_CMD_PAIRING_REQ; in smp_send_pairing_req()
3077 memcpy(smp->preq + 1, req, sizeof(*req)); in smp_send_pairing_req()
3084 smp_send(smp, req_buf, NULL, NULL); in smp_send_pairing_req()
3086 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RSP); in smp_send_pairing_req()
3087 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in smp_send_pairing_req()
3088 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in smp_send_pairing_req()
3093 static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_rsp() argument
3095 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_rsp()
3096 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_rsp()
3098 struct bt_smp_pairing *req = (struct bt_smp_pairing *)&smp->preq[1]; in smp_pairing_rsp()
3111 smp->local_dist &= rsp->init_key_dist; in smp_pairing_rsp()
3112 smp->remote_dist &= rsp->resp_key_dist; in smp_pairing_rsp()
3115 smp->prsp[0] = BT_SMP_CMD_PAIRING_RSP; in smp_pairing_rsp()
3116 memcpy(smp->prsp + 1, rsp, sizeof(*rsp)); in smp_pairing_rsp()
3120 atomic_set_bit(smp->flags, SMP_FLAG_SC); in smp_pairing_rsp()
3125 atomic_set_bit(smp->flags, SMP_FLAG_CT2); in smp_pairing_rsp()
3130 atomic_set_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_rsp()
3136 smp->local_dist = 0; in smp_pairing_rsp()
3137 smp->remote_dist = 0; in smp_pairing_rsp()
3140 smp->method = get_pair_method(smp, rsp->io_capability); in smp_pairing_rsp()
3142 if (!update_keys_check(smp, conn->le.keys)) { in smp_pairing_rsp()
3146 err = remote_sec_level_reachable(smp); in smp_pairing_rsp()
3151 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_rsp()
3156 err = smp_pairing_accept_query(smp, rsp); in smp_pairing_rsp()
3162 return legacy_pairing_rsp(smp); in smp_pairing_rsp()
3166 smp->local_dist &= SEND_KEYS_SC; in smp_pairing_rsp()
3167 smp->remote_dist &= RECV_KEYS_SC; in smp_pairing_rsp()
3170 err = smp_pairing_accept_query(smp, rsp); in smp_pairing_rsp()
3177 (DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in smp_pairing_rsp()
3178 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in smp_pairing_rsp()
3180 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_rsp()
3186 atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND); in smp_pairing_rsp()
3190 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in smp_pairing_rsp()
3191 atomic_clear_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in smp_pairing_rsp()
3193 return sc_send_public_key(smp); in smp_pairing_rsp()
3196 static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_rsp() argument
3202 static uint8_t smp_pairing_confirm(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_confirm() argument
3208 atomic_clear_bit(smp->flags, SMP_FLAG_DISPLAY); in smp_pairing_confirm()
3210 memcpy(smp->pcnf, req->val, sizeof(smp->pcnf)); in smp_pairing_confirm()
3213 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_pairing_confirm()
3214 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_pairing_confirm()
3215 return smp_send_pairing_random(smp); in smp_pairing_confirm()
3223 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_confirm()
3224 return legacy_pairing_confirm(smp); in smp_pairing_confirm()
3228 switch (smp->method) { in smp_pairing_confirm()
3230 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_pairing_confirm()
3231 return smp_send_pairing_confirm(smp); in smp_pairing_confirm()
3233 if (atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in smp_pairing_confirm()
3234 atomic_set_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in smp_pairing_confirm()
3238 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_pairing_confirm()
3239 return smp_send_pairing_confirm(smp); in smp_pairing_confirm()
3243 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_pairing_confirm()
3248 static uint8_t sc_smp_send_dhkey_check(struct bt_smp *smp, const uint8_t *e) in sc_smp_send_dhkey_check() argument
3255 buf = smp_create_pdu(smp, BT_SMP_DHKEY_CHECK, sizeof(*req)); in sc_smp_send_dhkey_check()
3263 smp_send(smp, buf, NULL, NULL); in sc_smp_send_dhkey_check()
3269 static uint8_t compute_and_send_central_dhcheck(struct bt_smp *smp) in compute_and_send_central_dhcheck() argument
3275 switch (smp->method) { in compute_and_send_central_dhcheck()
3281 memcpy(r, &smp->passkey, sizeof(smp->passkey)); in compute_and_send_central_dhcheck()
3284 if (smp->oobd_remote) { in compute_and_send_central_dhcheck()
3285 memcpy(r, smp->oobd_remote->r, sizeof(r)); in compute_and_send_central_dhcheck()
3289 LOG_ERR("Unknown pairing method (%u)", smp->method); in compute_and_send_central_dhcheck()
3294 if (bt_crypto_f5(smp->dhkey, smp->prnd, smp->rrnd, &smp->chan.chan.conn->le.init_addr, in compute_and_send_central_dhcheck()
3295 &smp->chan.chan.conn->le.resp_addr, smp->mackey, smp->tk)) { in compute_and_send_central_dhcheck()
3300 if (bt_crypto_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->preq[1], in compute_and_send_central_dhcheck()
3301 &smp->chan.chan.conn->le.init_addr, &smp->chan.chan.conn->le.resp_addr, in compute_and_send_central_dhcheck()
3307 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in compute_and_send_central_dhcheck()
3308 return sc_smp_send_dhkey_check(smp, e); in compute_and_send_central_dhcheck()
3313 static uint8_t compute_and_check_and_send_periph_dhcheck(struct bt_smp *smp) in compute_and_check_and_send_periph_dhcheck() argument
3320 switch (smp->method) { in compute_and_check_and_send_periph_dhcheck()
3326 memcpy(r, &smp->passkey, sizeof(smp->passkey)); in compute_and_check_and_send_periph_dhcheck()
3329 if (smp->oobd_remote) { in compute_and_check_and_send_periph_dhcheck()
3330 memcpy(r, smp->oobd_remote->r, sizeof(r)); in compute_and_check_and_send_periph_dhcheck()
3334 LOG_ERR("Unknown pairing method (%u)", smp->method); in compute_and_check_and_send_periph_dhcheck()
3339 if (bt_crypto_f5(smp->dhkey, smp->rrnd, smp->prnd, &smp->chan.chan.conn->le.init_addr, in compute_and_check_and_send_periph_dhcheck()
3340 &smp->chan.chan.conn->le.resp_addr, smp->mackey, smp->tk)) { in compute_and_check_and_send_periph_dhcheck()
3346 if (bt_crypto_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->prsp[1], in compute_and_check_and_send_periph_dhcheck()
3347 &smp->chan.chan.conn->le.resp_addr, &smp->chan.chan.conn->le.init_addr, in compute_and_check_and_send_periph_dhcheck()
3353 if (smp->method == LE_SC_OOB) { in compute_and_check_and_send_periph_dhcheck()
3354 if (smp->oobd_local) { in compute_and_check_and_send_periph_dhcheck()
3355 memcpy(r, smp->oobd_local->r, sizeof(r)); in compute_and_check_and_send_periph_dhcheck()
3362 if (bt_crypto_f6(smp->mackey, smp->rrnd, smp->prnd, r, &smp->preq[1], in compute_and_check_and_send_periph_dhcheck()
3363 &smp->chan.chan.conn->le.init_addr, &smp->chan.chan.conn->le.resp_addr, in compute_and_check_and_send_periph_dhcheck()
3370 if (memcmp(smp->e, re, 16)) { in compute_and_check_and_send_periph_dhcheck()
3375 err = sc_smp_send_dhkey_check(smp, e); in compute_and_check_and_send_periph_dhcheck()
3380 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in compute_and_check_and_send_periph_dhcheck()
3386 static uint8_t smp_dhkey_generate(struct bt_smp *smp) in smp_dhkey_generate() argument
3390 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_GEN); in smp_dhkey_generate()
3391 err = bt_dh_key_gen(smp->pkey, bt_smp_dhkey_ready); in smp_dhkey_generate()
3393 atomic_clear_bit(smp->flags, SMP_FLAG_DHKEY_GEN); in smp_dhkey_generate()
3402 static uint8_t smp_dhkey_ready(struct bt_smp *smp, const uint8_t *dhkey) in smp_dhkey_ready() argument
3408 atomic_clear_bit(smp->flags, SMP_FLAG_DHKEY_PENDING); in smp_dhkey_ready()
3409 memcpy(smp->dhkey, dhkey, BT_DH_KEY_LEN); in smp_dhkey_ready()
3412 if (atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in smp_dhkey_ready()
3413 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_ready()
3418 if (atomic_test_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT)) { in smp_dhkey_ready()
3419 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_ready()
3423 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_SEND)) { in smp_dhkey_ready()
3425 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_dhkey_ready()
3426 return compute_and_send_central_dhcheck(smp); in smp_dhkey_ready()
3432 return compute_and_check_and_send_periph_dhcheck(smp); in smp_dhkey_ready()
3455 struct bt_smp *smp = smp_find(SMP_FLAG_DHKEY_GEN); in bt_smp_dhkey_ready() local
3456 if (smp) { in bt_smp_dhkey_ready()
3457 atomic_clear_bit(smp->flags, SMP_FLAG_DHKEY_GEN); in bt_smp_dhkey_ready()
3458 err = smp_dhkey_ready(smp, dhkey); in bt_smp_dhkey_ready()
3460 smp_error(smp, err); in bt_smp_dhkey_ready()
3466 smp = smp_find(SMP_FLAG_DHKEY_PENDING); in bt_smp_dhkey_ready()
3467 if (smp) { in bt_smp_dhkey_ready()
3468 err = smp_dhkey_generate(smp); in bt_smp_dhkey_ready()
3470 smp_error(smp, err); in bt_smp_dhkey_ready()
3473 } while (smp && err); in bt_smp_dhkey_ready()
3476 static uint8_t sc_smp_check_confirm(struct bt_smp *smp) in sc_smp_check_confirm() argument
3481 switch (smp->method) { in sc_smp_check_confirm()
3497 r = (smp->passkey >> smp->passkey_round) & 0x01; in sc_smp_check_confirm()
3501 LOG_ERR("Unknown pairing method (%u)", smp->method); in sc_smp_check_confirm()
3505 if (bt_crypto_f4(smp->pkey, sc_public_key, smp->rrnd, r, cfm)) { in sc_smp_check_confirm()
3510 LOG_DBG("pcnf %s", bt_hex(smp->pcnf, 16)); in sc_smp_check_confirm()
3513 if (memcmp(smp->pcnf, cfm, 16)) { in sc_smp_check_confirm()
3520 static bool le_sc_oob_data_req_check(struct bt_smp *smp) in le_sc_oob_data_req_check() argument
3522 struct bt_smp_pairing *req = (struct bt_smp_pairing *)&smp->preq[1]; in le_sc_oob_data_req_check()
3527 static bool le_sc_oob_data_rsp_check(struct bt_smp *smp) in le_sc_oob_data_rsp_check() argument
3529 struct bt_smp_pairing *rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in le_sc_oob_data_rsp_check()
3534 static void le_sc_oob_config_set(struct bt_smp *smp, in le_sc_oob_config_set() argument
3537 bool req_oob_present = le_sc_oob_data_req_check(smp); in le_sc_oob_config_set()
3538 bool rsp_oob_present = le_sc_oob_data_rsp_check(smp); in le_sc_oob_config_set()
3542 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in le_sc_oob_config_set()
3565 static uint8_t smp_pairing_random(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_random() argument
3567 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_random()
3574 memcpy(smp->rrnd, req->val, sizeof(smp->rrnd)); in smp_pairing_random()
3577 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_random()
3578 return legacy_pairing_random(smp); in smp_pairing_random()
3583 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_pairing_random()
3584 err = sc_smp_check_confirm(smp); in smp_pairing_random()
3589 switch (smp->method) { in smp_pairing_random()
3592 if (bt_crypto_g2(sc_public_key, smp->pkey, smp->prnd, smp->rrnd, in smp_pairing_random()
3597 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_random()
3598 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_pairing_random()
3599 smp_auth_cb->passkey_confirm(smp->chan.chan.conn, passkey); in smp_pairing_random()
3607 smp->passkey_round++; in smp_pairing_random()
3608 if (smp->passkey_round == 20U) { in smp_pairing_random()
3612 if (bt_rand(smp->prnd, 16)) { in smp_pairing_random()
3616 atomic_set_bit(smp->allowed_cmds, in smp_pairing_random()
3618 return smp_send_pairing_confirm(smp); in smp_pairing_random()
3620 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_pairing_random()
3625 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_PENDING)) { in smp_pairing_random()
3626 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_pairing_random()
3630 return compute_and_send_central_dhcheck(smp); in smp_pairing_random()
3635 switch (smp->method) { in smp_pairing_random()
3637 if (bt_crypto_g2(smp->pkey, sc_public_key, smp->rrnd, smp->prnd, &passkey)) { in smp_pairing_random()
3641 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_random()
3642 smp_auth_cb->passkey_confirm(smp->chan.chan.conn, passkey); in smp_pairing_random()
3648 err = sc_smp_check_confirm(smp); in smp_pairing_random()
3653 atomic_set_bit(smp->allowed_cmds, in smp_pairing_random()
3655 err = smp_send_pairing_random(smp); in smp_pairing_random()
3660 smp->passkey_round++; in smp_pairing_random()
3661 if (smp->passkey_round == 20U) { in smp_pairing_random()
3662 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in smp_pairing_random()
3663 atomic_set_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in smp_pairing_random()
3667 if (bt_rand(smp->prnd, 16)) { in smp_pairing_random()
3674 if (bt_rand(smp->prnd, 16)) { in smp_pairing_random()
3684 le_sc_oob_config_set(smp, &info); in smp_pairing_random()
3686 smp->oobd_local = NULL; in smp_pairing_random()
3687 smp->oobd_remote = NULL; in smp_pairing_random()
3689 atomic_set_bit(smp->flags, SMP_FLAG_OOB_PENDING); in smp_pairing_random()
3690 smp_auth_cb->oob_data_request(smp->chan.chan.conn, &info); in smp_pairing_random()
3697 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_pairing_random()
3701 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in smp_pairing_random()
3702 atomic_set_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in smp_pairing_random()
3703 return smp_send_pairing_random(smp); in smp_pairing_random()
3709 static uint8_t smp_pairing_failed(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_failed() argument
3711 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_failed()
3712 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_failed()
3717 if (atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER) || in smp_pairing_failed()
3718 atomic_test_and_clear_bit(smp->flags, SMP_FLAG_DISPLAY)) { in smp_pairing_failed()
3724 smp_pairing_complete(smp, req->reason); in smp_pairing_failed()
3730 static uint8_t smp_ident_info(struct bt_smp *smp, struct net_buf *buf) in smp_ident_info() argument
3734 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_ident_info()
3736 struct bt_conn *conn = smp->chan.chan.conn; in smp_ident_info()
3748 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_ADDR_INFO); in smp_ident_info()
3753 static uint8_t smp_id_add_replace(struct bt_smp *smp, struct bt_keys *new_bond) in smp_id_add_replace() argument
3760 __ASSERT_NO_MSG(!(smp->remote_dist & BT_SMP_DIST_ID_KEY)); in smp_id_add_replace()
3776 trust_ok = update_keys_check(smp, conflict); in smp_id_add_replace()
3793 static uint8_t smp_ident_addr_info(struct bt_smp *smp, struct net_buf *buf) in smp_ident_addr_info() argument
3795 struct bt_conn *conn = smp->chan.chan.conn; in smp_ident_addr_info()
3801 smp->remote_dist &= ~BT_SMP_DIST_ID_KEY; in smp_ident_addr_info()
3813 if (!update_keys_check(smp, keys)) { in smp_ident_addr_info()
3821 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_ident_addr_info()
3861 err = smp_id_add_replace(smp, keys); in smp_ident_addr_info()
3867 if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_ident_addr_info()
3868 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_ident_addr_info()
3872 conn->role == BT_HCI_ROLE_CENTRAL && !smp->remote_dist) { in smp_ident_addr_info()
3873 err = bt_smp_distribute_keys(smp); in smp_ident_addr_info()
3880 if (!smp->local_dist && !smp->remote_dist) { in smp_ident_addr_info()
3881 smp_pairing_complete(smp, 0); in smp_ident_addr_info()
3888 static uint8_t smp_signing_info(struct bt_smp *smp, struct net_buf *buf) in smp_signing_info() argument
3890 struct bt_conn *conn = smp->chan.chan.conn; in smp_signing_info()
3895 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_signing_info()
3910 smp->remote_dist &= ~BT_SMP_DIST_SIGN; in smp_signing_info()
3913 conn->role == BT_HCI_ROLE_CENTRAL && !smp->remote_dist) { in smp_signing_info()
3914 err = bt_smp_distribute_keys(smp); in smp_signing_info()
3921 if (!smp->local_dist && !smp->remote_dist) { in smp_signing_info()
3922 smp_pairing_complete(smp, 0); in smp_signing_info()
3928 static uint8_t smp_signing_info(struct bt_smp *smp, struct net_buf *buf) in smp_signing_info() argument
3935 static uint8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf) in smp_security_request() argument
3937 struct bt_conn *conn = smp->chan.chan.conn; in smp_security_request()
3946 if (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) { in smp_security_request()
3950 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_security_request()
3955 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in smp_security_request()
3999 if (get_io_capa(smp) != BT_SMP_IO_NO_INPUT_OUTPUT) { in smp_security_request()
4023 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in smp_security_request()
4031 atomic_set_bit(smp->flags, SMP_FLAG_SEC_REQ); in smp_security_request()
4036 static uint8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf) in smp_security_request() argument
4042 static uint8_t generate_dhkey(struct bt_smp *smp) in generate_dhkey() argument
4048 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_PENDING); in generate_dhkey()
4050 return smp_dhkey_generate(smp); in generate_dhkey()
4056 static uint8_t display_passkey(struct bt_smp *smp) in display_passkey() argument
4058 struct bt_conn *conn = smp->chan.chan.conn; in display_passkey()
4059 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in display_passkey()
4063 smp->passkey = fixed_passkey; in display_passkey()
4065 if (bt_rand(&smp->passkey, sizeof(smp->passkey))) { in display_passkey()
4069 smp->passkey %= 1000000; in display_passkey()
4072 smp->passkey_round = 0U; in display_passkey()
4075 atomic_set_bit(smp->flags, SMP_FLAG_DISPLAY); in display_passkey()
4076 smp_auth_cb->passkey_display(conn, smp->passkey); in display_passkey()
4079 smp->passkey = sys_cpu_to_le32(smp->passkey); in display_passkey()
4085 static uint8_t smp_public_key_periph(struct bt_smp *smp) in smp_public_key_periph() argument
4087 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_public_key_periph()
4090 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) && in smp_public_key_periph()
4091 memcmp(smp->pkey, sc_public_key, BT_PUB_KEY_COORD_LEN) == 0) { in smp_public_key_periph()
4099 err = sc_send_public_key(smp); in smp_public_key_periph()
4104 switch (smp->method) { in smp_public_key_periph()
4107 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_public_key_periph()
4109 err = smp_send_pairing_confirm(smp); in smp_public_key_periph()
4115 err = display_passkey(smp); in smp_public_key_periph()
4120 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in smp_public_key_periph()
4121 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_public_key_periph()
4124 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in smp_public_key_periph()
4125 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_public_key_periph()
4126 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_public_key_periph()
4127 smp_auth_cb->passkey_entry(smp->chan.chan.conn); in smp_public_key_periph()
4130 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_public_key_periph()
4133 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_public_key_periph()
4137 return generate_dhkey(smp); in smp_public_key_periph()
4141 static uint8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf) in smp_public_key() argument
4143 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_public_key()
4149 memcpy(smp->pkey, req->x, BT_PUB_KEY_COORD_LEN); in smp_public_key()
4150 memcpy(&smp->pkey[BT_PUB_KEY_COORD_LEN], req->y, BT_PUB_KEY_COORD_LEN); in smp_public_key()
4153 if (bt_pub_key_is_debug(smp->pkey)) { in smp_public_key()
4155 atomic_set_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY); in smp_public_key()
4160 if (!update_debug_keys_check(smp)) { in smp_public_key()
4166 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_public_key()
4167 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) && in smp_public_key()
4168 memcmp(smp->pkey, sc_public_key, BT_PUB_KEY_COORD_LEN) == 0) { in smp_public_key()
4176 switch (smp->method) { in smp_public_key()
4179 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4183 err = display_passkey(smp); in smp_public_key()
4188 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4191 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4194 err = smp_send_pairing_confirm(smp); in smp_public_key()
4200 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_public_key()
4201 smp_auth_cb->passkey_entry(smp->chan.chan.conn); in smp_public_key()
4203 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4209 if (bt_rand(smp->prnd, 16)) { in smp_public_key()
4219 le_sc_oob_config_set(smp, &info); in smp_public_key()
4221 smp->oobd_local = NULL; in smp_public_key()
4222 smp->oobd_remote = NULL; in smp_public_key()
4224 atomic_set_bit(smp->flags, in smp_public_key()
4226 smp_auth_cb->oob_data_request(smp->chan.chan.conn, &info); in smp_public_key()
4232 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_public_key()
4236 return generate_dhkey(smp); in smp_public_key()
4241 atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND); in smp_public_key()
4245 err = smp_public_key_periph(smp); in smp_public_key()
4254 static uint8_t smp_dhkey_check(struct bt_smp *smp, struct net_buf *buf) in smp_dhkey_check() argument
4261 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_dhkey_check()
4267 switch (smp->method) { in smp_dhkey_check()
4273 memcpy(r, &smp->passkey, sizeof(smp->passkey)); in smp_dhkey_check()
4276 if (smp->oobd_local) { in smp_dhkey_check()
4277 memcpy(r, smp->oobd_local->r, sizeof(r)); in smp_dhkey_check()
4281 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_dhkey_check()
4286 if (bt_crypto_f6(smp->mackey, smp->rrnd, smp->prnd, r, &smp->prsp[1], in smp_dhkey_check()
4287 &smp->chan.chan.conn->le.resp_addr, in smp_dhkey_check()
4288 &smp->chan.chan.conn->le.init_addr, e)) { in smp_dhkey_check()
4296 enc_size = get_encryption_key_size(smp); in smp_dhkey_check()
4301 if (bt_conn_le_start_encryption(smp->chan.chan.conn, rand, ediv, in smp_dhkey_check()
4302 smp->tk, enc_size) < 0) { in smp_dhkey_check()
4307 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in smp_dhkey_check()
4310 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_dhkey_check()
4311 atomic_set_bit(smp->allowed_cmds, in smp_dhkey_check()
4313 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_dhkey_check()
4314 atomic_set_bit(smp->allowed_cmds, in smp_dhkey_check()
4323 if (smp->chan.chan.conn->role == BT_HCI_ROLE_PERIPHERAL) { in smp_dhkey_check()
4324 atomic_clear_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in smp_dhkey_check()
4325 memcpy(smp->e, req->e, sizeof(smp->e)); in smp_dhkey_check()
4328 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_PENDING)) { in smp_dhkey_check()
4329 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_check()
4334 if (atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in smp_dhkey_check()
4335 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_check()
4339 return compute_and_check_and_send_periph_dhcheck(smp); in smp_dhkey_check()
4347 static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) in smp_keypress_notif() argument
4349 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_keypress_notif()
4350 struct bt_conn *conn = smp->chan.chan.conn; in smp_keypress_notif()
4360 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_keypress_notif()
4370 k_work_reschedule(&smp->work, SMP_TIMEOUT); in smp_keypress_notif()
4379 static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) in smp_keypress_notif() argument
4381 ARG_UNUSED(smp); in smp_keypress_notif()
4387 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_keypress_notif()
4393 uint8_t (*func)(struct bt_smp *smp, struct net_buf *buf);
4413 static bool is_in_pairing_procedure(struct bt_smp *smp) in is_in_pairing_procedure() argument
4415 return atomic_test_bit(smp->flags, SMP_FLAG_PAIRING); in is_in_pairing_procedure()
4420 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan); in bt_smp_recv() local
4437 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in bt_smp_recv()
4454 smp_error(smp, BT_SMP_ERR_CMD_NOTSUPP); in bt_smp_recv()
4458 if (!atomic_test_and_clear_bit(smp->allowed_cmds, hdr->code)) { in bt_smp_recv()
4461 if (is_in_pairing_procedure(smp)) { in bt_smp_recv()
4462 smp_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_recv()
4469 smp_error(smp, BT_SMP_ERR_INVALID_PARAMS); in bt_smp_recv()
4473 err = handlers[hdr->code].func(smp, buf); in bt_smp_recv()
4475 smp_error(smp, err); in bt_smp_recv()
4497 struct bt_smp *smp = &bt_smp_pool[i]; in bt_smp_pkey_ready() local
4500 if (!atomic_test_bit(smp->flags, SMP_FLAG_PKEY_SEND)) { in bt_smp_pkey_ready()
4505 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in bt_smp_pkey_ready()
4506 err = sc_send_public_key(smp); in bt_smp_pkey_ready()
4508 smp_error(smp, err); in bt_smp_pkey_ready()
4511 atomic_set_bit(smp->allowed_cmds, in bt_smp_pkey_ready()
4517 err = smp_public_key_periph(smp); in bt_smp_pkey_ready()
4519 smp_error(smp, err); in bt_smp_pkey_ready()
4527 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan); in bt_smp_connected() local
4532 k_work_init_delayable(&smp->work, smp_timeout); in bt_smp_connected()
4533 smp_reset(smp); in bt_smp_connected()
4535 atomic_ptr_set(&smp->auth_cb, BT_SMP_AUTH_CB_UNINITIALIZED); in bt_smp_connected()
4540 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan); in bt_smp_disconnected() local
4549 (void)k_work_cancel_delayable(&smp->work); in bt_smp_disconnected()
4551 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING) || in bt_smp_disconnected()
4552 atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING) || in bt_smp_disconnected()
4553 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in bt_smp_disconnected()
4555 smp_pairing_complete(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_disconnected()
4569 (void)memset(smp, 0, sizeof(*smp)); in bt_smp_disconnected()
4575 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan); in bt_smp_encrypt_change() local
4581 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in bt_smp_encrypt_change()
4590 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_encrypt_change()
4595 atomic_set_bit(smp->flags, SMP_FLAG_KEYS_DISTR); in bt_smp_encrypt_change()
4596 smp_pairing_complete(smp, smp_err); in bt_smp_encrypt_change()
4610 if (!atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_encrypt_change()
4611 smp_reset(smp); in bt_smp_encrypt_change()
4616 if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_encrypt_change()
4617 if ((smp->local_dist & BT_SMP_DIST_LINK_KEY) && in bt_smp_encrypt_change()
4618 (smp->remote_dist & BT_SMP_DIST_LINK_KEY)) { in bt_smp_encrypt_change()
4623 atomic_set_bit(smp->flags, SMP_FLAG_DERIVE_LK); in bt_smp_encrypt_change()
4629 smp->local_dist &= ~BT_SMP_DIST_LINK_KEY; in bt_smp_encrypt_change()
4630 smp->remote_dist &= ~BT_SMP_DIST_LINK_KEY; in bt_smp_encrypt_change()
4633 if (smp->remote_dist & BT_SMP_DIST_ENC_KEY) { in bt_smp_encrypt_change()
4634 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_ENCRYPT_INFO); in bt_smp_encrypt_change()
4635 } else if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in bt_smp_encrypt_change()
4636 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in bt_smp_encrypt_change()
4637 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in bt_smp_encrypt_change()
4638 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in bt_smp_encrypt_change()
4662 !(smp->remote_dist & BT_SMP_DIST_ID_KEY)) { in bt_smp_encrypt_change()
4665 smp_err = smp_id_add_replace(smp, conn->le.keys); in bt_smp_encrypt_change()
4667 smp_pairing_complete(smp, smp_err); in bt_smp_encrypt_change()
4671 atomic_set_bit(smp->flags, SMP_FLAG_KEYS_DISTR); in bt_smp_encrypt_change()
4675 conn->role == BT_HCI_ROLE_CENTRAL && smp->remote_dist) { in bt_smp_encrypt_change()
4687 if (bt_smp_distribute_keys(smp)) { in bt_smp_encrypt_change()
4692 if (!smp->local_dist && !smp->remote_dist) { in bt_smp_encrypt_change()
4693 smp_pairing_complete(smp, 0); in bt_smp_encrypt_change()
5288 struct bt_smp *smp; in bt_smp_auth_cb_overlay() local
5290 smp = smp_chan_get(conn); in bt_smp_auth_cb_overlay()
5291 if (!smp) { in bt_smp_auth_cb_overlay()
5295 if (atomic_ptr_cas(&smp->auth_cb, BT_SMP_AUTH_CB_UNINITIALIZED, (atomic_ptr_val_t)cb)) { in bt_smp_auth_cb_overlay()
5303 static int smp_send_keypress_notif(struct bt_smp *smp, uint8_t type) in smp_send_keypress_notif() argument
5308 buf = smp_create_pdu(smp, BT_SMP_KEYPRESS_NOTIFICATION, sizeof(*req)); in smp_send_keypress_notif()
5316 smp_send(smp, buf, NULL, NULL); in smp_send_keypress_notif()
5325 struct bt_smp *smp; in bt_smp_auth_keypress_notify() local
5327 smp = smp_chan_get(conn); in bt_smp_auth_keypress_notify()
5328 if (!smp) { in bt_smp_auth_keypress_notify()
5339 if (smp->method != PASSKEY_INPUT || in bt_smp_auth_keypress_notify()
5340 !atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_keypress_notify()
5345 return smp_send_keypress_notif(smp, type); in bt_smp_auth_keypress_notify()
5351 struct bt_smp *smp; in bt_smp_auth_passkey_entry() local
5354 smp = smp_chan_get(conn); in bt_smp_auth_passkey_entry()
5355 if (!smp) { in bt_smp_auth_passkey_entry()
5359 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_passkey_entry()
5364 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_auth_passkey_entry()
5365 legacy_passkey_entry(smp, passkey); in bt_smp_auth_passkey_entry()
5370 smp->passkey = sys_cpu_to_le32(passkey); in bt_smp_auth_passkey_entry()
5373 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in bt_smp_auth_passkey_entry()
5374 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in bt_smp_auth_passkey_entry()
5375 err = smp_send_pairing_confirm(smp); in bt_smp_auth_passkey_entry()
5377 smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in bt_smp_auth_passkey_entry()
5384 atomic_test_bit(smp->flags, SMP_FLAG_CFM_DELAYED)) { in bt_smp_auth_passkey_entry()
5385 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in bt_smp_auth_passkey_entry()
5386 err = smp_send_pairing_confirm(smp); in bt_smp_auth_passkey_entry()
5388 smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in bt_smp_auth_passkey_entry()
5398 struct bt_smp *smp; in bt_smp_auth_passkey_confirm() local
5400 smp = smp_chan_get(conn); in bt_smp_auth_passkey_confirm()
5401 if (!smp) { in bt_smp_auth_passkey_confirm()
5405 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_passkey_confirm()
5410 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_PENDING)) { in bt_smp_auth_passkey_confirm()
5411 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in bt_smp_auth_passkey_confirm()
5416 if (atomic_test_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT)) { in bt_smp_auth_passkey_confirm()
5417 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in bt_smp_auth_passkey_confirm()
5421 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_SEND)) { in bt_smp_auth_passkey_confirm()
5425 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in bt_smp_auth_passkey_confirm()
5426 err = compute_and_send_central_dhcheck(smp); in bt_smp_auth_passkey_confirm()
5428 smp_error(smp, err); in bt_smp_auth_passkey_confirm()
5435 err = compute_and_check_and_send_periph_dhcheck(smp); in bt_smp_auth_passkey_confirm()
5437 smp_error(smp, err); in bt_smp_auth_passkey_confirm()
5448 struct bt_smp *smp; in bt_smp_le_oob_set_tk() local
5450 smp = smp_chan_get(conn); in bt_smp_le_oob_set_tk()
5451 if (!smp || !tk) { in bt_smp_le_oob_set_tk()
5457 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_le_oob_set_tk()
5468 memcpy(smp->tk, tk, 16*sizeof(uint8_t)); in bt_smp_le_oob_set_tk()
5470 legacy_user_tk_entry(smp); in bt_smp_le_oob_set_tk()
5515 static bool le_sc_oob_data_check(struct bt_smp *smp, bool oobd_local_present, in le_sc_oob_data_check() argument
5518 bool req_oob_present = le_sc_oob_data_req_check(smp); in le_sc_oob_data_check()
5519 bool rsp_oob_present = le_sc_oob_data_rsp_check(smp); in le_sc_oob_data_check()
5522 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in le_sc_oob_data_check()
5537 static int le_sc_oob_pairing_continue(struct bt_smp *smp) in le_sc_oob_pairing_continue() argument
5539 if (smp->oobd_remote) { in le_sc_oob_pairing_continue()
5543 err = bt_crypto_f4(smp->pkey, smp->pkey, smp->oobd_remote->r, 0, c); in le_sc_oob_pairing_continue()
5548 bool match = (memcmp(c, smp->oobd_remote->c, sizeof(c)) == 0); in le_sc_oob_pairing_continue()
5551 smp_error(smp, BT_SMP_ERR_CONFIRM_FAILED); in le_sc_oob_pairing_continue()
5557 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in le_sc_oob_pairing_continue()
5558 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in le_sc_oob_pairing_continue()
5560 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in le_sc_oob_pairing_continue()
5561 atomic_set_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in le_sc_oob_pairing_continue()
5564 return smp_send_pairing_random(smp); in le_sc_oob_pairing_continue()
5571 struct bt_smp *smp; in bt_smp_le_oob_set_sc_data() local
5573 smp = smp_chan_get(conn); in bt_smp_le_oob_set_sc_data()
5574 if (!smp) { in bt_smp_le_oob_set_sc_data()
5578 if (!le_sc_oob_data_check(smp, (oobd_local != NULL), in bt_smp_le_oob_set_sc_data()
5583 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_OOB_PENDING)) { in bt_smp_le_oob_set_sc_data()
5587 smp->oobd_local = oobd_local; in bt_smp_le_oob_set_sc_data()
5588 smp->oobd_remote = oobd_remote; in bt_smp_le_oob_set_sc_data()
5590 return le_sc_oob_pairing_continue(smp); in bt_smp_le_oob_set_sc_data()
5597 struct bt_smp *smp; in bt_smp_le_oob_get_sc_data() local
5599 smp = smp_chan_get(conn); in bt_smp_le_oob_get_sc_data()
5600 if (!smp) { in bt_smp_le_oob_get_sc_data()
5604 if (!smp->oobd_local && !smp->oobd_remote) { in bt_smp_le_oob_get_sc_data()
5609 *oobd_local = smp->oobd_local; in bt_smp_le_oob_get_sc_data()
5613 *oobd_remote = smp->oobd_remote; in bt_smp_le_oob_get_sc_data()
5622 struct bt_smp *smp; in bt_smp_auth_cancel() local
5624 smp = smp_chan_get(conn); in bt_smp_auth_cancel()
5625 if (!smp) { in bt_smp_auth_cancel()
5629 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_cancel()
5635 switch (smp->method) { in bt_smp_auth_cancel()
5638 return smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in bt_smp_auth_cancel()
5640 return smp_error(smp, BT_SMP_ERR_CONFIRM_FAILED); in bt_smp_auth_cancel()
5643 return smp_error(smp, BT_SMP_ERR_OOB_NOT_AVAIL); in bt_smp_auth_cancel()
5645 return smp_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_auth_cancel()
5647 LOG_ERR("Unknown pairing method (%u)", smp->method); in bt_smp_auth_cancel()
5655 struct bt_smp *smp; in bt_smp_auth_pairing_confirm() local
5657 smp = smp_chan_get(conn); in bt_smp_auth_pairing_confirm()
5658 if (!smp) { in bt_smp_auth_pairing_confirm()
5662 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_pairing_confirm()
5668 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_auth_pairing_confirm()
5669 atomic_set_bit(smp->allowed_cmds, in bt_smp_auth_pairing_confirm()
5671 return legacy_send_pairing_confirm(smp); in bt_smp_auth_pairing_confirm()
5675 atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND); in bt_smp_auth_pairing_confirm()
5679 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in bt_smp_auth_pairing_confirm()
5680 return sc_send_public_key(smp); in bt_smp_auth_pairing_confirm()
5684 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_auth_pairing_confirm()
5685 atomic_set_bit(smp->allowed_cmds, in bt_smp_auth_pairing_confirm()
5687 return send_pairing_rsp(smp); in bt_smp_auth_pairing_confirm()
5690 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in bt_smp_auth_pairing_confirm()
5691 if (send_pairing_rsp(smp)) { in bt_smp_auth_pairing_confirm()
5730 struct bt_smp *smp; in bt_smp_start_security() local
5732 smp = smp_chan_get(conn); in bt_smp_start_security()
5733 if (!smp) { in bt_smp_start_security()
5738 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_start_security()
5743 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in bt_smp_start_security()
5761 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in bt_smp_start_security()
5762 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_start_security()
5777 struct bt_smp *smp; in bt_smp_update_keys() local
5779 smp = smp_chan_get(conn); in bt_smp_update_keys()
5780 if (!smp) { in bt_smp_update_keys()
5784 if (!atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_update_keys()
5799 smp_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_update_keys()
5804 if (atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY)) { in bt_smp_update_keys()
5813 switch (smp->method) { in bt_smp_update_keys()
5831 conn->le.keys->enc_size = get_encryption_key_size(smp); in bt_smp_update_keys()
5838 if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_update_keys()
5841 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in bt_smp_update_keys()
5843 memcpy(conn->le.keys->ltk.val, smp->tk, in bt_smp_update_keys()
5852 sys_memcpy_swap(ltk, smp->tk, conn->le.keys->enc_size); in bt_smp_update_keys()
5873 struct bt_smp *smp = &bt_smp_pool[i]; in bt_smp_accept() local
5875 if (smp->chan.chan.conn) { in bt_smp_accept()
5879 smp->chan.chan.ops = &ops; in bt_smp_accept()
5881 *chan = &smp->chan.chan; in bt_smp_accept()