Lines Matching refs:smp
219 #define DISPLAY_FIXED(smp) (IS_ENABLED(CONFIG_BT_FIXED_PASSKEY) && \ argument
221 (smp)->method == PASSKEY_DISPLAY)
314 static const struct bt_conn_auth_cb *latch_auth_cb(struct bt_smp *smp) in latch_auth_cb() argument
316 (void)atomic_ptr_cas(&smp->auth_cb, BT_SMP_AUTH_CB_UNINITIALIZED, in latch_auth_cb()
319 return atomic_ptr_get(&smp->auth_cb); in latch_auth_cb()
322 static bool latch_bondable(struct bt_smp *smp) in latch_bondable() argument
324 (void)atomic_cas(&smp->bondable, BT_SMP_BONDABLE_UNINITIALIZED, (atomic_val_t)bondable); in latch_bondable()
326 return atomic_get(&smp->bondable); in latch_bondable()
329 static uint8_t get_io_capa(struct bt_smp *smp) in get_io_capa() argument
331 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in get_io_capa()
372 static uint8_t legacy_get_pair_method(struct bt_smp *smp, uint8_t remote_io);
411 static uint8_t get_pair_method(struct bt_smp *smp, uint8_t remote_io) in get_pair_method() argument
414 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in get_pair_method()
415 return legacy_get_pair_method(smp, remote_io); in get_pair_method()
422 req = (struct bt_smp_pairing *)&smp->preq[1]; in get_pair_method()
423 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in get_pair_method()
441 return gen_method_sc[remote_io][get_io_capa(smp)]; in get_pair_method()
564 static struct net_buf *smp_create_pdu(struct bt_smp *smp, uint8_t op, size_t len) in smp_create_pdu() argument
571 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_create_pdu()
585 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_create_pdu()
595 static uint8_t get_encryption_key_size(struct bt_smp *smp) in get_encryption_key_size() argument
599 req = (struct bt_smp_pairing *)&smp->preq[1]; in get_encryption_key_size()
600 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in get_encryption_key_size()
613 static bool update_keys_check(struct bt_smp *smp, struct bt_keys *keys) in update_keys_check() argument
616 !atomic_test_bit(smp->flags, SMP_FLAG_SC) && in update_keys_check()
617 smp->method != LEGACY_OOB) { in update_keys_check()
622 smp->method != LEGACY_OOB) { in update_keys_check()
631 if (keys->enc_size > get_encryption_key_size(smp)) { in update_keys_check()
636 !atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in update_keys_check()
641 smp->method == JUST_WORKS) { in update_keys_check()
647 && smp->method == JUST_WORKS)) { in update_keys_check()
649 (keys->id == smp->chan.chan.conn->id)) { in update_keys_check()
658 static bool update_debug_keys_check(struct bt_smp *smp) in update_debug_keys_check() argument
660 struct bt_conn *conn = smp->chan.chan.conn; in update_debug_keys_check()
682 static void smp_pairing_complete(struct bt_smp *smp, uint8_t status);
684 static void smp_pairing_br_complete(struct bt_smp_br *smp, uint8_t status);
692 struct bt_smp *smp; in smp_check_complete() local
697 smp = CONTAINER_OF(chan, struct bt_smp, chan.chan); in smp_check_complete()
698 smp->local_dist &= ~dist_complete; in smp_check_complete()
701 if (!smp->local_dist && !smp->remote_dist) { in smp_check_complete()
702 smp_pairing_complete(smp, 0); in smp_check_complete()
710 struct bt_smp_br *smp; in smp_check_complete() local
715 smp = CONTAINER_OF(chan, struct bt_smp_br, chan.chan); in smp_check_complete()
716 smp->local_dist &= ~dist_complete; in smp_check_complete()
719 if (!smp->local_dist && !smp->remote_dist) { in smp_check_complete()
720 smp_pairing_br_complete(smp, 0); in smp_check_complete()
746 static void sc_derive_link_key(struct bt_smp *smp) in sc_derive_link_key() argument
750 struct bt_conn *conn = smp->chan.chan.conn; in sc_derive_link_key()
767 if (atomic_test_bit(smp->flags, SMP_FLAG_CT2)) { in sc_derive_link_key()
801 static void smp_br_reset(struct bt_smp_br *smp) in smp_br_reset() argument
806 atomic_set(smp->flags, 0); in smp_br_reset()
812 (void)k_work_cancel_delayable(&smp->work); in smp_br_reset()
814 atomic_set(smp->allowed_cmds, 0); in smp_br_reset()
816 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ); in smp_br_reset()
819 static void smp_pairing_br_complete(struct bt_smp_br *smp, uint8_t status) in smp_pairing_br_complete() argument
821 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_br_complete()
844 listener->pairing_failed(smp->chan.chan.conn, in smp_pairing_br_complete()
849 bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_br_complete()
859 listener->pairing_complete(smp->chan.chan.conn, in smp_pairing_br_complete()
865 smp_br_reset(smp); in smp_pairing_br_complete()
871 struct bt_smp_br *smp = CONTAINER_OF(dwork, struct bt_smp_br, work); in smp_br_timeout() local
875 smp_pairing_br_complete(smp, BT_SMP_ERR_UNSPECIFIED); in smp_br_timeout()
876 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_br_timeout()
879 static void smp_br_send(struct bt_smp_br *smp, struct net_buf *buf, in smp_br_send() argument
882 int err = bt_l2cap_br_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_BR_SMP, buf, cb, NULL); in smp_br_send()
893 k_work_reschedule(&smp->work, SMP_TIMEOUT); in smp_br_send()
898 struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan.chan); in bt_smp_br_connected() local
903 atomic_set_bit(smp->flags, SMP_FLAG_BR_CONNECTED); in bt_smp_br_connected()
909 if (atomic_test_bit(smp->flags, SMP_FLAG_BR_PAIR)) { in bt_smp_br_connected()
916 struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan.chan); in bt_smp_br_disconnected() local
924 (void)k_work_cancel_delayable(&smp->work); in bt_smp_br_disconnected()
926 (void)memset(smp, 0, sizeof(*smp)); in bt_smp_br_disconnected()
929 static void smp_br_init(struct bt_smp_br *smp) in smp_br_init() argument
934 (void)memset(smp, 0, offsetof(struct bt_smp_br, chan)); in smp_br_init()
936 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_FAIL); in smp_br_init()
939 static void smp_br_derive_ltk(struct bt_smp_br *smp) in smp_br_derive_ltk() argument
943 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_derive_ltk()
972 if (atomic_test_bit(smp->flags, SMP_FLAG_CT2)) { in smp_br_derive_ltk()
1000 keys->enc_size = smp->enc_key_size; in smp_br_derive_ltk()
1011 static struct net_buf *smp_br_create_pdu(struct bt_smp_br *smp, uint8_t op, in smp_br_create_pdu() argument
1019 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_br_create_pdu()
1033 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_br_create_pdu()
1043 static void smp_br_distribute_keys(struct bt_smp_br *smp) in smp_br_distribute_keys() argument
1045 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_distribute_keys()
1063 if (smp->local_dist & BT_SMP_DIST_ID_KEY) { in smp_br_distribute_keys()
1068 smp->local_dist &= ~BT_SMP_DIST_ID_KEY; in smp_br_distribute_keys()
1070 buf = smp_br_create_pdu(smp, BT_SMP_CMD_IDENT_INFO, in smp_br_distribute_keys()
1080 smp_br_send(smp, buf, NULL); in smp_br_distribute_keys()
1082 buf = smp_br_create_pdu(smp, BT_SMP_CMD_IDENT_ADDR_INFO, in smp_br_distribute_keys()
1092 smp_br_send(smp, buf, smp_id_sent); in smp_br_distribute_keys()
1097 if (smp->local_dist & BT_SMP_DIST_SIGN) { in smp_br_distribute_keys()
1101 smp->local_dist &= ~BT_SMP_DIST_SIGN; in smp_br_distribute_keys()
1103 buf = smp_br_create_pdu(smp, BT_SMP_CMD_SIGNING_INFO, in smp_br_distribute_keys()
1117 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_br_distribute_keys()
1123 smp_br_send(smp, buf, smp_sign_info_sent); in smp_br_distribute_keys()
1128 static bool smp_br_pairing_allowed(struct bt_smp_br *smp) in smp_br_pairing_allowed() argument
1130 if (smp->chan.chan.conn->encrypt == 0x02) { in smp_br_pairing_allowed()
1135 smp->chan.chan.conn->encrypt == 0x01) { in smp_br_pairing_allowed()
1143 static uint8_t smp_br_pairing_req(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_pairing_req() argument
1146 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_pairing_req()
1163 if (!smp_br_pairing_allowed(smp)) { in smp_br_pairing_req()
1177 rsp_buf = smp_br_create_pdu(smp, BT_SMP_CMD_PAIRING_RSP, sizeof(*rsp)); in smp_br_pairing_req()
1182 smp_br_init(smp); in smp_br_pairing_req()
1183 smp->enc_key_size = max_key_size; in smp_br_pairing_req()
1200 smp->local_dist = rsp->resp_key_dist; in smp_br_pairing_req()
1201 smp->remote_dist = rsp->init_key_dist; in smp_br_pairing_req()
1208 smp_br_send(smp, rsp_buf, NULL); in smp_br_pairing_req()
1210 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in smp_br_pairing_req()
1215 atomic_set_bit(smp->flags, SMP_FLAG_CT2); in smp_br_pairing_req()
1219 if ((smp->local_dist & BT_SMP_DIST_ENC_KEY) && in smp_br_pairing_req()
1220 (smp->remote_dist & BT_SMP_DIST_ENC_KEY)) { in smp_br_pairing_req()
1221 smp_br_derive_ltk(smp); in smp_br_pairing_req()
1223 smp->local_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_req()
1224 smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_req()
1227 smp_br_distribute_keys(smp); in smp_br_pairing_req()
1229 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_br_pairing_req()
1230 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in smp_br_pairing_req()
1231 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_br_pairing_req()
1232 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_br_pairing_req()
1236 if (!smp->local_dist && !smp->remote_dist) { in smp_br_pairing_req()
1237 smp_pairing_br_complete(smp, 0); in smp_br_pairing_req()
1243 static uint8_t smp_br_pairing_rsp(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_pairing_rsp() argument
1246 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_pairing_rsp()
1264 smp->local_dist &= rsp->init_key_dist; in smp_br_pairing_rsp()
1265 smp->remote_dist &= rsp->resp_key_dist; in smp_br_pairing_rsp()
1267 smp->local_dist &= BR_SEND_KEYS_SC; in smp_br_pairing_rsp()
1268 smp->remote_dist &= BR_RECV_KEYS_SC; in smp_br_pairing_rsp()
1272 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_br_pairing_rsp()
1273 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in smp_br_pairing_rsp()
1274 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_br_pairing_rsp()
1275 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_br_pairing_rsp()
1283 atomic_set_bit(smp->flags, SMP_FLAG_CT2); in smp_br_pairing_rsp()
1287 if ((smp->local_dist & BT_SMP_DIST_ENC_KEY) && in smp_br_pairing_rsp()
1288 (smp->remote_dist & BT_SMP_DIST_ENC_KEY)) { in smp_br_pairing_rsp()
1289 smp_br_derive_ltk(smp); in smp_br_pairing_rsp()
1291 smp->local_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_rsp()
1292 smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_br_pairing_rsp()
1295 if (smp->remote_dist) { in smp_br_pairing_rsp()
1299 smp_br_distribute_keys(smp); in smp_br_pairing_rsp()
1302 if (!smp->local_dist && !smp->remote_dist) { in smp_br_pairing_rsp()
1303 smp_pairing_br_complete(smp, 0); in smp_br_pairing_rsp()
1309 static uint8_t smp_br_pairing_failed(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_pairing_failed() argument
1315 smp_pairing_br_complete(smp, req->reason); in smp_br_pairing_failed()
1316 smp_br_reset(smp); in smp_br_pairing_failed()
1322 static uint8_t smp_br_ident_info(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_ident_info() argument
1325 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_ident_info()
1348 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_ADDR_INFO); in smp_br_ident_info()
1353 static uint8_t smp_br_ident_addr_info(struct bt_smp_br *smp, in smp_br_ident_addr_info() argument
1356 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_ident_addr_info()
1375 smp->remote_dist &= ~BT_SMP_DIST_ID_KEY; in smp_br_ident_addr_info()
1377 if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_br_ident_addr_info()
1378 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_br_ident_addr_info()
1381 if (conn->role == BT_CONN_ROLE_CENTRAL && !smp->remote_dist) { in smp_br_ident_addr_info()
1382 smp_br_distribute_keys(smp); in smp_br_ident_addr_info()
1386 if (!smp->local_dist && !smp->remote_dist) { in smp_br_ident_addr_info()
1387 smp_pairing_br_complete(smp, 0); in smp_br_ident_addr_info()
1394 static uint8_t smp_br_signing_info(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_signing_info() argument
1397 struct bt_conn *conn = smp->chan.chan.conn; in smp_br_signing_info()
1418 smp->remote_dist &= ~BT_SMP_DIST_SIGN; in smp_br_signing_info()
1420 if (conn->role == BT_CONN_ROLE_CENTRAL && !smp->remote_dist) { in smp_br_signing_info()
1421 smp_br_distribute_keys(smp); in smp_br_signing_info()
1425 if (!smp->local_dist && !smp->remote_dist) { in smp_br_signing_info()
1426 smp_pairing_br_complete(smp, 0); in smp_br_signing_info()
1432 static uint8_t smp_br_signing_info(struct bt_smp_br *smp, struct net_buf *buf) in smp_br_signing_info() argument
1439 uint8_t (*func)(struct bt_smp_br *smp, struct net_buf *buf);
1458 static int smp_br_error(struct bt_smp_br *smp, uint8_t reason) in smp_br_error() argument
1464 smp_br_reset(smp); in smp_br_error()
1466 buf = smp_br_create_pdu(smp, BT_SMP_CMD_PAIRING_FAIL, sizeof(*rsp)); in smp_br_error()
1478 if (bt_l2cap_br_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_BR_SMP, buf, in smp_br_error()
1488 struct bt_smp_br *smp = CONTAINER_OF(chan, struct bt_smp_br, chan.chan); in bt_smp_br_recv() local
1505 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in bt_smp_br_recv()
1513 smp_br_error(smp, BT_SMP_ERR_CMD_NOTSUPP); in bt_smp_br_recv()
1517 if (!atomic_test_and_clear_bit(smp->allowed_cmds, hdr->code)) { in bt_smp_br_recv()
1519 smp_br_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_br_recv()
1525 smp_br_error(smp, BT_SMP_ERR_INVALID_PARAMS); in bt_smp_br_recv()
1529 err = br_handlers[hdr->code].func(smp, buf); in bt_smp_br_recv()
1531 smp_br_error(smp, err); in bt_smp_br_recv()
1564 struct bt_smp_br *smp = &bt_smp_br_pool[i]; in bt_smp_br_accept() local
1566 if (smp->chan.chan.conn) { in bt_smp_br_accept()
1570 smp->chan.chan.ops = &ops; in bt_smp_br_accept()
1572 *chan = &smp->chan.chan; in bt_smp_br_accept()
1574 k_work_init_delayable(&smp->work, smp_br_timeout); in bt_smp_br_accept()
1575 smp_br_reset(smp); in bt_smp_br_accept()
1603 struct bt_smp_br *smp; in bt_smp_br_send_pairing_req() local
1611 smp = smp_br_chan_get(conn); in bt_smp_br_send_pairing_req()
1612 if (!smp) { in bt_smp_br_send_pairing_req()
1617 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in bt_smp_br_send_pairing_req()
1622 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_br_send_pairing_req()
1627 if (!smp_br_pairing_allowed(smp)) { in bt_smp_br_send_pairing_req()
1632 if (!atomic_test_bit(smp->flags, SMP_FLAG_BR_CONNECTED)) { in bt_smp_br_send_pairing_req()
1633 atomic_set_bit(smp->flags, SMP_FLAG_BR_PAIR); in bt_smp_br_send_pairing_req()
1643 smp_br_init(smp); in bt_smp_br_send_pairing_req()
1644 smp->enc_key_size = max_key_size; in bt_smp_br_send_pairing_req()
1646 req_buf = smp_br_create_pdu(smp, BT_SMP_CMD_PAIRING_REQ, sizeof(*req)); in bt_smp_br_send_pairing_req()
1667 smp_br_send(smp, req_buf, NULL); in bt_smp_br_send_pairing_req()
1669 smp->local_dist = BR_SEND_KEYS_SC; in bt_smp_br_send_pairing_req()
1670 smp->remote_dist = BR_RECV_KEYS_SC; in bt_smp_br_send_pairing_req()
1672 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RSP); in bt_smp_br_send_pairing_req()
1674 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in bt_smp_br_send_pairing_req()
1680 static void smp_reset(struct bt_smp *smp) in smp_reset() argument
1682 struct bt_conn *conn = smp->chan.chan.conn; in smp_reset()
1687 atomic_set(smp->flags, 0); in smp_reset()
1693 (void)k_work_cancel_delayable(&smp->work); in smp_reset()
1695 smp->method = JUST_WORKS; in smp_reset()
1696 atomic_set(smp->allowed_cmds, 0); in smp_reset()
1700 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in smp_reset()
1705 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ); in smp_reset()
1732 static void smp_pairing_complete(struct bt_smp *smp, uint8_t status) in smp_pairing_complete() argument
1734 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_complete()
1752 if (atomic_test_bit(smp->flags, SMP_FLAG_DERIVE_LK) && in smp_pairing_complete()
1753 (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) || in smp_pairing_complete()
1755 sc_derive_link_key(smp); in smp_pairing_complete()
1758 bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_complete()
1784 atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR))) { in smp_pairing_complete()
1789 if (!atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) { in smp_pairing_complete()
1798 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_pairing_complete()
1811 smp_reset(smp); in smp_pairing_complete()
1821 struct bt_smp *smp = CONTAINER_OF(dwork, struct bt_smp, work); in smp_timeout() local
1825 smp_pairing_complete(smp, BT_SMP_ERR_UNSPECIFIED); in smp_timeout()
1830 atomic_set_bit(smp->flags, SMP_FLAG_TIMEOUT); in smp_timeout()
1833 static void smp_send(struct bt_smp *smp, struct net_buf *buf, in smp_send() argument
1838 int err = bt_l2cap_send_pdu(&smp->chan, buf, cb, NULL); in smp_send()
1849 k_work_reschedule(&smp->work, SMP_TIMEOUT); in smp_send()
1852 static int smp_error(struct bt_smp *smp, uint8_t reason) in smp_error() argument
1861 remote_already_completed = (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR) && in smp_error()
1862 !smp->local_dist && !smp->remote_dist); in smp_error()
1864 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING) || in smp_error()
1865 atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING) || in smp_error()
1866 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in smp_error()
1868 smp_pairing_complete(smp, reason); in smp_error()
1880 bt_conn_disconnect(smp->chan.chan.conn, BT_HCI_ERR_AUTH_FAIL); in smp_error()
1884 buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_FAIL, sizeof(*rsp)); in smp_error()
1893 if (bt_l2cap_send_pdu(&smp->chan, buf, NULL, NULL)) { in smp_error()
1900 static uint8_t smp_send_pairing_random(struct bt_smp *smp) in smp_send_pairing_random() argument
1905 rsp_buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_RANDOM, sizeof(*req)); in smp_send_pairing_random()
1911 memcpy(req->val, smp->prnd, sizeof(req->val)); in smp_send_pairing_random()
1913 smp_send(smp, rsp_buf, NULL, NULL); in smp_send_pairing_random()
1965 static uint8_t smp_send_pairing_confirm(struct bt_smp *smp) in smp_send_pairing_confirm() argument
1971 switch (smp->method) { in smp_send_pairing_confirm()
1985 r = (smp->passkey >> smp->passkey_round) & 0x01; in smp_send_pairing_confirm()
1989 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_send_pairing_confirm()
1993 buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_CONFIRM, sizeof(*req)); in smp_send_pairing_confirm()
2000 if (bt_crypto_f4(sc_public_key, smp->pkey, smp->prnd, r, req->val)) { in smp_send_pairing_confirm()
2005 smp_send(smp, buf, NULL, NULL); in smp_send_pairing_confirm()
2007 atomic_clear_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in smp_send_pairing_confirm()
2020 static void legacy_distribute_keys(struct bt_smp *smp) in legacy_distribute_keys() argument
2022 struct bt_conn *conn = smp->chan.chan.conn; in legacy_distribute_keys()
2025 if (smp->local_dist & BT_SMP_DIST_ENC_KEY) { in legacy_distribute_keys()
2041 buf = smp_create_pdu(smp, BT_SMP_CMD_ENCRYPT_INFO, in legacy_distribute_keys()
2057 smp_send(smp, buf, NULL, NULL); in legacy_distribute_keys()
2059 buf = smp_create_pdu(smp, BT_SMP_CMD_CENTRAL_IDENT, in legacy_distribute_keys()
2070 smp_send(smp, buf, smp_ident_sent, NULL); in legacy_distribute_keys()
2072 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in legacy_distribute_keys()
2086 static uint8_t bt_smp_distribute_keys(struct bt_smp *smp) in bt_smp_distribute_keys() argument
2088 struct bt_conn *conn = smp->chan.chan.conn; in bt_smp_distribute_keys()
2098 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_distribute_keys()
2099 legacy_distribute_keys(smp); in bt_smp_distribute_keys()
2104 if (smp->local_dist & BT_SMP_DIST_ID_KEY) { in bt_smp_distribute_keys()
2109 buf = smp_create_pdu(smp, BT_SMP_CMD_IDENT_INFO, in bt_smp_distribute_keys()
2119 smp_send(smp, buf, NULL, NULL); in bt_smp_distribute_keys()
2121 buf = smp_create_pdu(smp, BT_SMP_CMD_IDENT_ADDR_INFO, in bt_smp_distribute_keys()
2131 smp_send(smp, buf, smp_id_sent, NULL); in bt_smp_distribute_keys()
2136 if (smp->local_dist & BT_SMP_DIST_SIGN) { in bt_smp_distribute_keys()
2140 buf = smp_create_pdu(smp, BT_SMP_CMD_SIGNING_INFO, in bt_smp_distribute_keys()
2153 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in bt_smp_distribute_keys()
2159 smp_send(smp, buf, smp_sign_info_sent, NULL); in bt_smp_distribute_keys()
2167 static uint8_t send_pairing_rsp(struct bt_smp *smp) in send_pairing_rsp() argument
2172 rsp_buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_RSP, sizeof(*rsp)); in send_pairing_rsp()
2178 memcpy(rsp, smp->prsp + 1, sizeof(*rsp)); in send_pairing_rsp()
2180 smp_send(smp, rsp_buf, NULL, NULL); in send_pairing_rsp()
2186 static uint8_t smp_pairing_accept_query(struct bt_smp *smp, struct bt_smp_pairing *pairing) in smp_pairing_accept_query() argument
2189 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_accept_query()
2190 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_accept_query()
2227 static uint8_t legacy_get_pair_method(struct bt_smp *smp, uint8_t remote_io) in legacy_get_pair_method() argument
2236 req = (struct bt_smp_pairing *)&smp->preq[1]; in legacy_get_pair_method()
2237 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in legacy_get_pair_method()
2249 method = gen_method_legacy[remote_io][get_io_capa(smp)]; in legacy_get_pair_method()
2255 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in legacy_get_pair_method()
2265 static uint8_t legacy_request_tk(struct bt_smp *smp) in legacy_request_tk() argument
2267 struct bt_conn *conn = smp->chan.chan.conn; in legacy_request_tk()
2268 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in legacy_request_tk()
2279 smp->method == JUST_WORKS) { in legacy_request_tk()
2284 switch (smp->method) { in legacy_request_tk()
2291 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_request_tk()
2292 smp_auth_cb->oob_data_request(smp->chan.chan.conn, &info); in legacy_request_tk()
2315 atomic_set_bit(smp->flags, SMP_FLAG_DISPLAY); in legacy_request_tk()
2319 sys_put_le32(passkey, smp->tk); in legacy_request_tk()
2323 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_request_tk()
2329 LOG_ERR("Unknown pairing method (%u)", smp->method); in legacy_request_tk()
2336 static uint8_t legacy_send_pairing_confirm(struct bt_smp *smp) in legacy_send_pairing_confirm() argument
2338 struct bt_conn *conn = smp->chan.chan.conn; in legacy_send_pairing_confirm()
2342 buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_CONFIRM, sizeof(*req)); in legacy_send_pairing_confirm()
2349 if (smp_c1(smp->tk, smp->prnd, smp->preq, smp->prsp, in legacy_send_pairing_confirm()
2355 smp_send(smp, buf, NULL, NULL); in legacy_send_pairing_confirm()
2357 atomic_clear_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in legacy_send_pairing_confirm()
2363 static uint8_t legacy_pairing_req(struct bt_smp *smp) in legacy_pairing_req() argument
2365 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in legacy_pairing_req()
2370 ret = legacy_request_tk(smp); in legacy_pairing_req()
2376 if ((DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in legacy_pairing_req()
2377 !atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in legacy_pairing_req()
2379 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_pairing_req()
2380 smp_auth_cb->pairing_confirm(smp->chan.chan.conn); in legacy_pairing_req()
2384 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_pairing_req()
2385 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in legacy_pairing_req()
2386 return send_pairing_rsp(smp); in legacy_pairing_req()
2390 static uint8_t legacy_pairing_random(struct bt_smp *smp) in legacy_pairing_random() argument
2392 struct bt_conn *conn = smp->chan.chan.conn; in legacy_pairing_random()
2399 err = smp_c1(smp->tk, smp->rrnd, smp->preq, smp->prsp, in legacy_pairing_random()
2405 LOG_DBG("pcnf %s", bt_hex(smp->pcnf, 16)); in legacy_pairing_random()
2408 if (memcmp(smp->pcnf, tmp, sizeof(smp->pcnf))) { in legacy_pairing_random()
2417 err = smp_s1(smp->tk, smp->rrnd, smp->prnd, tmp); in legacy_pairing_random()
2426 get_encryption_key_size(smp))) { in legacy_pairing_random()
2431 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in legacy_pairing_random()
2434 if (smp->remote_dist & BT_SMP_DIST_ENC_KEY) { in legacy_pairing_random()
2435 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_random()
2437 } else if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in legacy_pairing_random()
2438 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_random()
2440 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in legacy_pairing_random()
2441 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_random()
2450 err = smp_s1(smp->tk, smp->prnd, smp->rrnd, tmp); in legacy_pairing_random()
2456 memcpy(smp->tk, tmp, sizeof(smp->tk)); in legacy_pairing_random()
2457 LOG_DBG("generated STK %s", bt_hex(smp->tk, 16)); in legacy_pairing_random()
2459 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in legacy_pairing_random()
2461 return smp_send_pairing_random(smp); in legacy_pairing_random()
2467 static uint8_t legacy_pairing_confirm(struct bt_smp *smp) in legacy_pairing_confirm() argument
2472 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in legacy_pairing_confirm()
2473 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_pairing_confirm()
2474 return legacy_send_pairing_confirm(smp); in legacy_pairing_confirm()
2478 if (!atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in legacy_pairing_confirm()
2479 atomic_set_bit(smp->allowed_cmds, in legacy_pairing_confirm()
2481 return legacy_send_pairing_confirm(smp); in legacy_pairing_confirm()
2484 atomic_set_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in legacy_pairing_confirm()
2490 static void legacy_user_tk_entry(struct bt_smp *smp) in legacy_user_tk_entry() argument
2492 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_CFM_DELAYED)) { in legacy_user_tk_entry()
2497 if (legacy_pairing_confirm(smp)) { in legacy_user_tk_entry()
2498 smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in legacy_user_tk_entry()
2503 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in legacy_user_tk_entry()
2504 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_user_tk_entry()
2509 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in legacy_user_tk_entry()
2513 static void legacy_passkey_entry(struct bt_smp *smp, unsigned int passkey) in legacy_passkey_entry() argument
2516 memcpy(smp->tk, &passkey, sizeof(passkey)); in legacy_passkey_entry()
2518 legacy_user_tk_entry(smp); in legacy_passkey_entry()
2521 static uint8_t smp_encrypt_info(struct bt_smp *smp, struct net_buf *buf) in smp_encrypt_info() argument
2525 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_encrypt_info()
2527 struct bt_conn *conn = smp->chan.chan.conn; in smp_encrypt_info()
2539 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_CENTRAL_IDENT); in smp_encrypt_info()
2544 static uint8_t smp_central_ident(struct bt_smp *smp, struct net_buf *buf) in smp_central_ident() argument
2546 struct bt_conn *conn = smp->chan.chan.conn; in smp_central_ident()
2551 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_central_ident()
2565 smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY; in smp_central_ident()
2567 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_central_ident()
2568 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in smp_central_ident()
2569 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_central_ident()
2570 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_central_ident()
2574 conn->role == BT_HCI_ROLE_CENTRAL && !smp->remote_dist) { in smp_central_ident()
2575 err = bt_smp_distribute_keys(smp); in smp_central_ident()
2582 if (!smp->local_dist && !smp->remote_dist) { in smp_central_ident()
2583 smp_pairing_complete(smp, 0); in smp_central_ident()
2590 static uint8_t legacy_pairing_rsp(struct bt_smp *smp) in legacy_pairing_rsp() argument
2592 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in legacy_pairing_rsp()
2597 ret = legacy_request_tk(smp); in legacy_pairing_rsp()
2603 if ((DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in legacy_pairing_rsp()
2604 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in legacy_pairing_rsp()
2606 atomic_set_bit(smp->flags, SMP_FLAG_USER); in legacy_pairing_rsp()
2607 smp_auth_cb->pairing_confirm(smp->chan.chan.conn); in legacy_pairing_rsp()
2611 if (!atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in legacy_pairing_rsp()
2612 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in legacy_pairing_rsp()
2613 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in legacy_pairing_rsp()
2614 return legacy_send_pairing_confirm(smp); in legacy_pairing_rsp()
2617 atomic_set_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in legacy_pairing_rsp()
2623 static uint8_t smp_encrypt_info(struct bt_smp *smp, struct net_buf *buf) in smp_encrypt_info() argument
2628 static uint8_t smp_central_ident(struct bt_smp *smp, struct net_buf *buf) in smp_central_ident() argument
2634 static int smp_init(struct bt_smp *smp) in smp_init() argument
2639 (void)memset(smp, 0, offsetof(struct bt_smp, chan)); in smp_init()
2642 if (bt_rand(smp->prnd, 16)) { in smp_init()
2646 LOG_DBG("prnd %s", bt_hex(smp->prnd, 16)); in smp_init()
2648 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_FAIL); in smp_init()
2677 static uint8_t get_auth(struct bt_smp *smp, uint8_t auth) in get_auth() argument
2679 struct bt_conn *conn = smp->chan.chan.conn; in get_auth()
2687 if ((get_io_capa(smp) == BT_SMP_IO_NO_INPUT_OUTPUT) || in get_auth()
2695 if (latch_bondable(smp)) { in get_auth()
2714 static uint8_t remote_sec_level_reachable(struct bt_smp *smp) in remote_sec_level_reachable() argument
2716 bt_security_t sec = smp->chan.chan.conn->required_sec_level; in remote_sec_level_reachable()
2731 if (get_encryption_key_size(smp) != BT_SMP_MAX_ENC_KEY_SIZE) { in remote_sec_level_reachable()
2735 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in remote_sec_level_reachable()
2740 if (smp->method == JUST_WORKS) { in remote_sec_level_reachable()
2750 static bool sec_level_reachable(struct bt_smp *smp) in sec_level_reachable() argument
2752 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in sec_level_reachable()
2754 switch (smp->chan.chan.conn->required_sec_level) { in sec_level_reachable()
2759 return get_io_capa(smp) != BT_SMP_IO_NO_INPUT_OUTPUT || in sec_level_reachable()
2762 return (get_io_capa(smp) != BT_SMP_IO_NO_INPUT_OUTPUT || in sec_level_reachable()
2784 struct bt_smp *smp; in bt_smp_request_ltk() local
2787 smp = smp_chan_get(conn); in bt_smp_request_ltk()
2788 if (!smp) { in bt_smp_request_ltk()
2797 atomic_test_bit(smp->flags, SMP_FLAG_PAIRING) && in bt_smp_request_ltk()
2798 atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in bt_smp_request_ltk()
2799 enc_size = get_encryption_key_size(smp); in bt_smp_request_ltk()
2805 memcpy(ltk, smp->tk, enc_size); in bt_smp_request_ltk()
2811 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_request_ltk()
2834 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_request_ltk()
2850 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_request_ltk()
2855 if (atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in bt_smp_request_ltk()
2863 smp_reset(smp); in bt_smp_request_ltk()
2870 struct bt_smp *smp; in smp_send_security_req() local
2876 smp = smp_chan_get(conn); in smp_send_security_req()
2877 if (!smp) { in smp_send_security_req()
2882 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_send_security_req()
2887 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_send_security_req()
2891 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in smp_send_security_req()
2896 if (!(sec_level_reachable(smp) || smp_keys_check(conn))) { in smp_send_security_req()
2907 if (smp_init(smp) != 0) { in smp_send_security_req()
2911 req_buf = smp_create_pdu(smp, BT_SMP_CMD_SECURITY_REQUEST, in smp_send_security_req()
2918 req->auth_req = get_auth(smp, BT_SMP_AUTH_DEFAULT); in smp_send_security_req()
2921 err = bt_l2cap_send_pdu(&smp->chan, req_buf, NULL, NULL); in smp_send_security_req()
2927 atomic_set_bit(smp->flags, SMP_FLAG_SEC_REQ); in smp_send_security_req()
2928 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_REQ); in smp_send_security_req()
2933 static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_req() argument
2935 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_req()
2936 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_req()
2963 if (!atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in smp_pairing_req()
2964 int ret = smp_init(smp); in smp_pairing_req()
2972 smp->preq[0] = BT_SMP_CMD_PAIRING_REQ; in smp_pairing_req()
2973 memcpy(smp->preq + 1, req, sizeof(*req)); in smp_pairing_req()
2976 smp->prsp[0] = BT_SMP_CMD_PAIRING_RSP; in smp_pairing_req()
2977 rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in smp_pairing_req()
2979 rsp->auth_req = get_auth(smp, req->auth_req); in smp_pairing_req()
2980 rsp->io_capability = get_io_capa(smp); in smp_pairing_req()
2987 atomic_set_bit(smp->flags, SMP_FLAG_SC); in smp_pairing_req()
2993 if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_req()
3003 atomic_set_bit(smp->flags, SMP_FLAG_CT2); in smp_pairing_req()
3008 atomic_set_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_req()
3018 smp->local_dist = rsp->resp_key_dist; in smp_pairing_req()
3019 smp->remote_dist = rsp->init_key_dist; in smp_pairing_req()
3021 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in smp_pairing_req()
3023 smp->method = get_pair_method(smp, req->io_capability); in smp_pairing_req()
3025 if (!update_keys_check(smp, conn->le.keys)) { in smp_pairing_req()
3029 err = remote_sec_level_reachable(smp); in smp_pairing_req()
3034 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_req()
3039 err = smp_pairing_accept_query(smp, req); in smp_pairing_req()
3045 return legacy_pairing_req(smp); in smp_pairing_req()
3050 err = smp_pairing_accept_query(smp, req); in smp_pairing_req()
3057 (DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in smp_pairing_req()
3058 !atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in smp_pairing_req()
3060 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_req()
3065 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in smp_pairing_req()
3072 return send_pairing_rsp(smp); in smp_pairing_req()
3075 static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_req() argument
3081 static uint8_t sc_send_public_key(struct bt_smp *smp) in sc_send_public_key() argument
3086 req_buf = smp_create_pdu(smp, BT_SMP_CMD_PUBLIC_KEY, sizeof(*req)); in sc_send_public_key()
3096 smp_send(smp, req_buf, NULL, NULL); in sc_send_public_key()
3099 atomic_set_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY); in sc_send_public_key()
3108 struct bt_smp *smp; in smp_send_pairing_req() local
3114 smp = smp_chan_get(conn); in smp_send_pairing_req()
3115 if (!smp) { in smp_send_pairing_req()
3120 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in smp_send_pairing_req()
3127 if (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) { in smp_send_pairing_req()
3132 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_send_pairing_req()
3137 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in smp_send_pairing_req()
3142 if (!sec_level_reachable(smp)) { in smp_send_pairing_req()
3153 if (smp_init(smp)) { in smp_send_pairing_req()
3157 req_buf = smp_create_pdu(smp, BT_SMP_CMD_PAIRING_REQ, sizeof(*req)); in smp_send_pairing_req()
3164 req->auth_req = get_auth(smp, BT_SMP_AUTH_DEFAULT); in smp_send_pairing_req()
3165 req->io_capability = get_io_capa(smp); in smp_send_pairing_req()
3184 smp->local_dist = req->init_key_dist; in smp_send_pairing_req()
3185 smp->remote_dist = req->resp_key_dist; in smp_send_pairing_req()
3188 smp->preq[0] = BT_SMP_CMD_PAIRING_REQ; in smp_send_pairing_req()
3189 memcpy(smp->preq + 1, req, sizeof(*req)); in smp_send_pairing_req()
3196 smp_send(smp, req_buf, NULL, NULL); in smp_send_pairing_req()
3198 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RSP); in smp_send_pairing_req()
3199 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in smp_send_pairing_req()
3200 atomic_set_bit(smp->flags, SMP_FLAG_PAIRING); in smp_send_pairing_req()
3205 static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_rsp() argument
3207 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_rsp()
3209 struct bt_smp_pairing *req = (struct bt_smp_pairing *)&smp->preq[1]; in smp_pairing_rsp()
3222 smp->local_dist &= rsp->init_key_dist; in smp_pairing_rsp()
3223 smp->remote_dist &= rsp->resp_key_dist; in smp_pairing_rsp()
3226 smp->prsp[0] = BT_SMP_CMD_PAIRING_RSP; in smp_pairing_rsp()
3227 memcpy(smp->prsp + 1, rsp, sizeof(*rsp)); in smp_pairing_rsp()
3231 atomic_set_bit(smp->flags, SMP_FLAG_SC); in smp_pairing_rsp()
3236 atomic_set_bit(smp->flags, SMP_FLAG_CT2); in smp_pairing_rsp()
3241 atomic_set_bit(smp->flags, SMP_FLAG_BOND); in smp_pairing_rsp()
3247 smp->local_dist = 0; in smp_pairing_rsp()
3248 smp->remote_dist = 0; in smp_pairing_rsp()
3251 smp->method = get_pair_method(smp, rsp->io_capability); in smp_pairing_rsp()
3253 if (!update_keys_check(smp, conn->le.keys)) { in smp_pairing_rsp()
3257 err = remote_sec_level_reachable(smp); in smp_pairing_rsp()
3272 !atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_rsp()
3277 err = smp_pairing_accept_query(smp, rsp); in smp_pairing_rsp()
3283 return legacy_pairing_rsp(smp); in smp_pairing_rsp()
3287 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_rsp()
3289 smp->local_dist &= SEND_KEYS_SC; in smp_pairing_rsp()
3290 smp->remote_dist &= RECV_KEYS_SC; in smp_pairing_rsp()
3293 err = smp_pairing_accept_query(smp, rsp); in smp_pairing_rsp()
3300 (DISPLAY_FIXED(smp) || smp->method == JUST_WORKS) && in smp_pairing_rsp()
3301 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ) && in smp_pairing_rsp()
3303 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_rsp()
3309 atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND); in smp_pairing_rsp()
3313 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in smp_pairing_rsp()
3314 atomic_clear_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in smp_pairing_rsp()
3316 return sc_send_public_key(smp); in smp_pairing_rsp()
3319 static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_rsp() argument
3325 static uint8_t smp_pairing_confirm(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_confirm() argument
3331 atomic_clear_bit(smp->flags, SMP_FLAG_DISPLAY); in smp_pairing_confirm()
3333 memcpy(smp->pcnf, req->val, sizeof(smp->pcnf)); in smp_pairing_confirm()
3336 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_pairing_confirm()
3337 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_pairing_confirm()
3338 return smp_send_pairing_random(smp); in smp_pairing_confirm()
3346 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_confirm()
3347 return legacy_pairing_confirm(smp); in smp_pairing_confirm()
3351 switch (smp->method) { in smp_pairing_confirm()
3353 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_pairing_confirm()
3354 return smp_send_pairing_confirm(smp); in smp_pairing_confirm()
3356 if (atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in smp_pairing_confirm()
3357 atomic_set_bit(smp->flags, SMP_FLAG_CFM_DELAYED); in smp_pairing_confirm()
3361 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_pairing_confirm()
3362 return smp_send_pairing_confirm(smp); in smp_pairing_confirm()
3366 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_pairing_confirm()
3371 static uint8_t sc_smp_send_dhkey_check(struct bt_smp *smp, const uint8_t *e) in sc_smp_send_dhkey_check() argument
3378 buf = smp_create_pdu(smp, BT_SMP_DHKEY_CHECK, sizeof(*req)); in sc_smp_send_dhkey_check()
3386 smp_send(smp, buf, NULL, NULL); in sc_smp_send_dhkey_check()
3392 static uint8_t compute_and_send_central_dhcheck(struct bt_smp *smp) in compute_and_send_central_dhcheck() argument
3398 switch (smp->method) { in compute_and_send_central_dhcheck()
3404 memcpy(r, &smp->passkey, sizeof(smp->passkey)); in compute_and_send_central_dhcheck()
3407 if (smp->oobd_remote) { in compute_and_send_central_dhcheck()
3408 memcpy(r, smp->oobd_remote->r, sizeof(r)); in compute_and_send_central_dhcheck()
3412 LOG_ERR("Unknown pairing method (%u)", smp->method); in compute_and_send_central_dhcheck()
3417 if (bt_crypto_f5(smp->dhkey, smp->prnd, smp->rrnd, &smp->chan.chan.conn->le.init_addr, in compute_and_send_central_dhcheck()
3418 &smp->chan.chan.conn->le.resp_addr, smp->mackey, smp->tk)) { in compute_and_send_central_dhcheck()
3423 if (bt_crypto_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->preq[1], in compute_and_send_central_dhcheck()
3424 &smp->chan.chan.conn->le.init_addr, &smp->chan.chan.conn->le.resp_addr, in compute_and_send_central_dhcheck()
3430 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in compute_and_send_central_dhcheck()
3431 return sc_smp_send_dhkey_check(smp, e); in compute_and_send_central_dhcheck()
3436 static uint8_t compute_and_check_and_send_periph_dhcheck(struct bt_smp *smp) in compute_and_check_and_send_periph_dhcheck() argument
3443 switch (smp->method) { in compute_and_check_and_send_periph_dhcheck()
3449 memcpy(r, &smp->passkey, sizeof(smp->passkey)); in compute_and_check_and_send_periph_dhcheck()
3452 if (smp->oobd_remote) { in compute_and_check_and_send_periph_dhcheck()
3453 memcpy(r, smp->oobd_remote->r, sizeof(r)); in compute_and_check_and_send_periph_dhcheck()
3457 LOG_ERR("Unknown pairing method (%u)", smp->method); in compute_and_check_and_send_periph_dhcheck()
3462 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()
3463 &smp->chan.chan.conn->le.resp_addr, smp->mackey, smp->tk)) { in compute_and_check_and_send_periph_dhcheck()
3469 if (bt_crypto_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->prsp[1], in compute_and_check_and_send_periph_dhcheck()
3470 &smp->chan.chan.conn->le.resp_addr, &smp->chan.chan.conn->le.init_addr, in compute_and_check_and_send_periph_dhcheck()
3476 if (smp->method == LE_SC_OOB) { in compute_and_check_and_send_periph_dhcheck()
3477 if (smp->oobd_local) { in compute_and_check_and_send_periph_dhcheck()
3478 memcpy(r, smp->oobd_local->r, sizeof(r)); in compute_and_check_and_send_periph_dhcheck()
3485 if (bt_crypto_f6(smp->mackey, smp->rrnd, smp->prnd, r, &smp->preq[1], in compute_and_check_and_send_periph_dhcheck()
3486 &smp->chan.chan.conn->le.init_addr, &smp->chan.chan.conn->le.resp_addr, in compute_and_check_and_send_periph_dhcheck()
3493 if (memcmp(smp->e, re, 16)) { in compute_and_check_and_send_periph_dhcheck()
3498 err = sc_smp_send_dhkey_check(smp, e); in compute_and_check_and_send_periph_dhcheck()
3503 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in compute_and_check_and_send_periph_dhcheck()
3509 static uint8_t smp_dhkey_generate(struct bt_smp *smp) in smp_dhkey_generate() argument
3513 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_GEN); in smp_dhkey_generate()
3514 err = bt_dh_key_gen(smp->pkey, bt_smp_dhkey_ready); in smp_dhkey_generate()
3516 atomic_clear_bit(smp->flags, SMP_FLAG_DHKEY_GEN); in smp_dhkey_generate()
3525 static uint8_t smp_dhkey_ready(struct bt_smp *smp, const uint8_t *dhkey) in smp_dhkey_ready() argument
3531 atomic_clear_bit(smp->flags, SMP_FLAG_DHKEY_PENDING); in smp_dhkey_ready()
3532 memcpy(smp->dhkey, dhkey, BT_DH_KEY_LEN); in smp_dhkey_ready()
3535 if (atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in smp_dhkey_ready()
3536 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_ready()
3541 if (atomic_test_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT)) { in smp_dhkey_ready()
3542 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_ready()
3546 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_SEND)) { in smp_dhkey_ready()
3548 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_dhkey_ready()
3549 return compute_and_send_central_dhcheck(smp); in smp_dhkey_ready()
3555 return compute_and_check_and_send_periph_dhcheck(smp); in smp_dhkey_ready()
3578 struct bt_smp *smp = smp_find(SMP_FLAG_DHKEY_GEN); in bt_smp_dhkey_ready() local
3579 if (smp) { in bt_smp_dhkey_ready()
3580 atomic_clear_bit(smp->flags, SMP_FLAG_DHKEY_GEN); in bt_smp_dhkey_ready()
3581 err = smp_dhkey_ready(smp, dhkey); in bt_smp_dhkey_ready()
3583 smp_error(smp, err); in bt_smp_dhkey_ready()
3589 smp = smp_find(SMP_FLAG_DHKEY_PENDING); in bt_smp_dhkey_ready()
3590 if (smp) { in bt_smp_dhkey_ready()
3591 err = smp_dhkey_generate(smp); in bt_smp_dhkey_ready()
3593 smp_error(smp, err); in bt_smp_dhkey_ready()
3596 } while (smp && err); in bt_smp_dhkey_ready()
3599 static uint8_t sc_smp_check_confirm(struct bt_smp *smp) in sc_smp_check_confirm() argument
3604 switch (smp->method) { in sc_smp_check_confirm()
3620 r = (smp->passkey >> smp->passkey_round) & 0x01; in sc_smp_check_confirm()
3624 LOG_ERR("Unknown pairing method (%u)", smp->method); in sc_smp_check_confirm()
3628 if (bt_crypto_f4(smp->pkey, sc_public_key, smp->rrnd, r, cfm)) { in sc_smp_check_confirm()
3633 LOG_DBG("pcnf %s", bt_hex(smp->pcnf, 16)); in sc_smp_check_confirm()
3636 if (memcmp(smp->pcnf, cfm, 16)) { in sc_smp_check_confirm()
3643 static bool le_sc_oob_data_req_check(struct bt_smp *smp) in le_sc_oob_data_req_check() argument
3645 struct bt_smp_pairing *req = (struct bt_smp_pairing *)&smp->preq[1]; in le_sc_oob_data_req_check()
3650 static bool le_sc_oob_data_rsp_check(struct bt_smp *smp) in le_sc_oob_data_rsp_check() argument
3652 struct bt_smp_pairing *rsp = (struct bt_smp_pairing *)&smp->prsp[1]; in le_sc_oob_data_rsp_check()
3657 __maybe_unused static void le_sc_oob_config_set(struct bt_smp *smp, in le_sc_oob_config_set() argument
3660 bool req_oob_present = le_sc_oob_data_req_check(smp); in le_sc_oob_config_set()
3661 bool rsp_oob_present = le_sc_oob_data_rsp_check(smp); in le_sc_oob_config_set()
3665 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in le_sc_oob_config_set()
3688 static uint8_t smp_pairing_random(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_random() argument
3690 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_random()
3697 memcpy(smp->rrnd, req->val, sizeof(smp->rrnd)); in smp_pairing_random()
3700 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in smp_pairing_random()
3701 return legacy_pairing_random(smp); in smp_pairing_random()
3706 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_pairing_random()
3707 err = sc_smp_check_confirm(smp); in smp_pairing_random()
3712 switch (smp->method) { in smp_pairing_random()
3715 if (bt_crypto_g2(sc_public_key, smp->pkey, smp->prnd, smp->rrnd, in smp_pairing_random()
3720 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_random()
3721 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_pairing_random()
3722 smp_auth_cb->passkey_confirm(smp->chan.chan.conn, passkey); in smp_pairing_random()
3730 smp->passkey_round++; in smp_pairing_random()
3731 if (smp->passkey_round == 20U) { in smp_pairing_random()
3735 if (bt_rand(smp->prnd, 16)) { in smp_pairing_random()
3739 atomic_set_bit(smp->allowed_cmds, in smp_pairing_random()
3741 return smp_send_pairing_confirm(smp); in smp_pairing_random()
3743 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_pairing_random()
3748 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_PENDING)) { in smp_pairing_random()
3749 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_pairing_random()
3753 return compute_and_send_central_dhcheck(smp); in smp_pairing_random()
3758 switch (smp->method) { in smp_pairing_random()
3760 if (bt_crypto_g2(smp->pkey, sc_public_key, smp->rrnd, smp->prnd, &passkey)) { in smp_pairing_random()
3764 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_pairing_random()
3765 smp_auth_cb->passkey_confirm(smp->chan.chan.conn, passkey); in smp_pairing_random()
3771 err = sc_smp_check_confirm(smp); in smp_pairing_random()
3776 atomic_set_bit(smp->allowed_cmds, in smp_pairing_random()
3778 err = smp_send_pairing_random(smp); in smp_pairing_random()
3783 smp->passkey_round++; in smp_pairing_random()
3784 if (smp->passkey_round == 20U) { in smp_pairing_random()
3785 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in smp_pairing_random()
3786 atomic_set_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in smp_pairing_random()
3790 if (bt_rand(smp->prnd, 16)) { in smp_pairing_random()
3797 if (bt_rand(smp->prnd, 16)) { in smp_pairing_random()
3808 le_sc_oob_config_set(smp, &info); in smp_pairing_random()
3810 smp->oobd_local = NULL; in smp_pairing_random()
3811 smp->oobd_remote = NULL; in smp_pairing_random()
3813 atomic_set_bit(smp->flags, SMP_FLAG_OOB_PENDING); in smp_pairing_random()
3814 smp_auth_cb->oob_data_request(smp->chan.chan.conn, &info); in smp_pairing_random()
3821 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_pairing_random()
3825 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in smp_pairing_random()
3826 atomic_set_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in smp_pairing_random()
3827 return smp_send_pairing_random(smp); in smp_pairing_random()
3833 static uint8_t smp_pairing_failed(struct bt_smp *smp, struct net_buf *buf) in smp_pairing_failed() argument
3835 struct bt_conn *conn = smp->chan.chan.conn; in smp_pairing_failed()
3836 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_pairing_failed()
3841 if (atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER) || in smp_pairing_failed()
3842 atomic_test_and_clear_bit(smp->flags, SMP_FLAG_DISPLAY)) { in smp_pairing_failed()
3848 smp_pairing_complete(smp, req->reason); in smp_pairing_failed()
3854 static uint8_t smp_ident_info(struct bt_smp *smp, struct net_buf *buf) in smp_ident_info() argument
3858 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_ident_info()
3860 struct bt_conn *conn = smp->chan.chan.conn; in smp_ident_info()
3872 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_ADDR_INFO); in smp_ident_info()
3877 static uint8_t smp_id_add_replace(struct bt_smp *smp, struct bt_keys *new_bond) in smp_id_add_replace() argument
3884 __ASSERT_NO_MSG(!(smp->remote_dist & BT_SMP_DIST_ID_KEY)); in smp_id_add_replace()
3900 trust_ok = update_keys_check(smp, conflict); in smp_id_add_replace()
3931 static uint8_t smp_ident_addr_info(struct bt_smp *smp, struct net_buf *buf) in smp_ident_addr_info() argument
3933 struct bt_conn *conn = smp->chan.chan.conn; in smp_ident_addr_info()
3939 smp->remote_dist &= ~BT_SMP_DIST_ID_KEY; in smp_ident_addr_info()
3951 if (!update_keys_check(smp, keys)) { in smp_ident_addr_info()
3959 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_ident_addr_info()
4006 err = smp_id_add_replace(smp, keys); in smp_ident_addr_info()
4012 if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_ident_addr_info()
4013 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in smp_ident_addr_info()
4017 conn->role == BT_HCI_ROLE_CENTRAL && !smp->remote_dist) { in smp_ident_addr_info()
4018 err = bt_smp_distribute_keys(smp); in smp_ident_addr_info()
4025 if (!smp->local_dist && !smp->remote_dist) { in smp_ident_addr_info()
4026 smp_pairing_complete(smp, 0); in smp_ident_addr_info()
4033 static uint8_t smp_signing_info(struct bt_smp *smp, struct net_buf *buf) in smp_signing_info() argument
4035 struct bt_conn *conn = smp->chan.chan.conn; in smp_signing_info()
4040 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in smp_signing_info()
4055 smp->remote_dist &= ~BT_SMP_DIST_SIGN; in smp_signing_info()
4058 conn->role == BT_HCI_ROLE_CENTRAL && !smp->remote_dist) { in smp_signing_info()
4059 err = bt_smp_distribute_keys(smp); in smp_signing_info()
4066 if (!smp->local_dist && !smp->remote_dist) { in smp_signing_info()
4067 smp_pairing_complete(smp, 0); in smp_signing_info()
4073 static uint8_t smp_signing_info(struct bt_smp *smp, struct net_buf *buf) in smp_signing_info() argument
4080 static uint8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf) in smp_security_request() argument
4082 struct bt_conn *conn = smp->chan.chan.conn; in smp_security_request()
4091 if (atomic_test_bit(smp->flags, SMP_FLAG_KEYS_DISTR)) { in smp_security_request()
4095 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in smp_security_request()
4100 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in smp_security_request()
4117 !(latch_bondable(smp) && (auth & BT_SMP_AUTH_BONDING))) { in smp_security_request()
4144 if (get_io_capa(smp) != BT_SMP_IO_NO_INPUT_OUTPUT) { in smp_security_request()
4168 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in smp_security_request()
4176 atomic_set_bit(smp->flags, SMP_FLAG_SEC_REQ); in smp_security_request()
4181 static uint8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf) in smp_security_request() argument
4187 __maybe_unused static uint8_t generate_dhkey(struct bt_smp *smp) in generate_dhkey() argument
4193 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_PENDING); in generate_dhkey()
4195 return smp_dhkey_generate(smp); in generate_dhkey()
4201 __maybe_unused static uint8_t display_passkey(struct bt_smp *smp) in display_passkey() argument
4203 struct bt_conn *conn = smp->chan.chan.conn; in display_passkey()
4204 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in display_passkey()
4208 smp->passkey = fixed_passkey; in display_passkey()
4210 if (bt_rand(&smp->passkey, sizeof(smp->passkey))) { in display_passkey()
4214 smp->passkey %= 1000000; in display_passkey()
4217 smp->passkey_round = 0U; in display_passkey()
4220 atomic_set_bit(smp->flags, SMP_FLAG_DISPLAY); in display_passkey()
4221 smp_auth_cb->passkey_display(conn, smp->passkey); in display_passkey()
4224 smp->passkey = sys_cpu_to_le32(smp->passkey); in display_passkey()
4230 static uint8_t smp_public_key_periph(struct bt_smp *smp) in smp_public_key_periph() argument
4232 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_public_key_periph()
4235 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) && in smp_public_key_periph()
4236 memcmp(smp->pkey, sc_public_key, BT_PUB_KEY_COORD_LEN) == 0) { in smp_public_key_periph()
4244 err = sc_send_public_key(smp); in smp_public_key_periph()
4249 switch (smp->method) { in smp_public_key_periph()
4252 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_public_key_periph()
4254 err = smp_send_pairing_confirm(smp); in smp_public_key_periph()
4260 err = display_passkey(smp); in smp_public_key_periph()
4265 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in smp_public_key_periph()
4266 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_public_key_periph()
4269 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in smp_public_key_periph()
4270 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_public_key_periph()
4271 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_public_key_periph()
4272 smp_auth_cb->passkey_entry(smp->chan.chan.conn); in smp_public_key_periph()
4275 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in smp_public_key_periph()
4278 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_public_key_periph()
4282 return generate_dhkey(smp); in smp_public_key_periph()
4287 static uint8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf) in smp_public_key() argument
4292 static uint8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf) in smp_public_key() argument
4294 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_public_key()
4300 memcpy(smp->pkey, req->x, BT_PUB_KEY_COORD_LEN); in smp_public_key()
4301 memcpy(&smp->pkey[BT_PUB_KEY_COORD_LEN], req->y, BT_PUB_KEY_COORD_LEN); in smp_public_key()
4304 if (bt_pub_key_is_debug(smp->pkey)) { in smp_public_key()
4306 atomic_set_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY); in smp_public_key()
4311 if (!update_debug_keys_check(smp)) { in smp_public_key()
4314 } else if (!bt_pub_key_is_valid(smp->pkey)) { in smp_public_key()
4320 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_public_key()
4321 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY) && in smp_public_key()
4322 memcmp(smp->pkey, sc_public_key, BT_PUB_KEY_COORD_LEN) == 0) { in smp_public_key()
4330 switch (smp->method) { in smp_public_key()
4333 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4337 err = display_passkey(smp); in smp_public_key()
4342 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4345 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4348 err = smp_send_pairing_confirm(smp); in smp_public_key()
4354 atomic_set_bit(smp->flags, SMP_FLAG_USER); in smp_public_key()
4355 smp_auth_cb->passkey_entry(smp->chan.chan.conn); in smp_public_key()
4357 atomic_set_bit(smp->allowed_cmds, in smp_public_key()
4363 if (bt_rand(smp->prnd, 16)) { in smp_public_key()
4373 le_sc_oob_config_set(smp, &info); in smp_public_key()
4375 smp->oobd_local = NULL; in smp_public_key()
4376 smp->oobd_remote = NULL; in smp_public_key()
4378 atomic_set_bit(smp->flags, in smp_public_key()
4380 smp_auth_cb->oob_data_request(smp->chan.chan.conn, &info); in smp_public_key()
4386 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_public_key()
4390 return generate_dhkey(smp); in smp_public_key()
4395 atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND); in smp_public_key()
4399 err = smp_public_key_periph(smp); in smp_public_key()
4409 static uint8_t smp_dhkey_check(struct bt_smp *smp, struct net_buf *buf) in smp_dhkey_check() argument
4416 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in smp_dhkey_check()
4422 switch (smp->method) { in smp_dhkey_check()
4428 memcpy(r, &smp->passkey, sizeof(smp->passkey)); in smp_dhkey_check()
4431 if (smp->oobd_local) { in smp_dhkey_check()
4432 memcpy(r, smp->oobd_local->r, sizeof(r)); in smp_dhkey_check()
4436 LOG_ERR("Unknown pairing method (%u)", smp->method); in smp_dhkey_check()
4441 if (bt_crypto_f6(smp->mackey, smp->rrnd, smp->prnd, r, &smp->prsp[1], in smp_dhkey_check()
4442 &smp->chan.chan.conn->le.resp_addr, in smp_dhkey_check()
4443 &smp->chan.chan.conn->le.init_addr, e)) { in smp_dhkey_check()
4451 enc_size = get_encryption_key_size(smp); in smp_dhkey_check()
4456 if (bt_conn_le_start_encryption(smp->chan.chan.conn, rand, ediv, in smp_dhkey_check()
4457 smp->tk, enc_size) < 0) { in smp_dhkey_check()
4462 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in smp_dhkey_check()
4465 if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in smp_dhkey_check()
4466 atomic_set_bit(smp->allowed_cmds, in smp_dhkey_check()
4468 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in smp_dhkey_check()
4469 atomic_set_bit(smp->allowed_cmds, in smp_dhkey_check()
4478 if (smp->chan.chan.conn->role == BT_HCI_ROLE_PERIPHERAL) { in smp_dhkey_check()
4479 atomic_clear_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in smp_dhkey_check()
4480 memcpy(smp->e, req->e, sizeof(smp->e)); in smp_dhkey_check()
4483 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_PENDING)) { in smp_dhkey_check()
4484 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_check()
4489 if (atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in smp_dhkey_check()
4490 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in smp_dhkey_check()
4494 return compute_and_check_and_send_periph_dhcheck(smp); in smp_dhkey_check()
4502 static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) in smp_keypress_notif() argument
4504 const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); in smp_keypress_notif()
4505 struct bt_conn *conn = smp->chan.chan.conn; in smp_keypress_notif()
4515 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_keypress_notif()
4525 k_work_reschedule(&smp->work, SMP_TIMEOUT); in smp_keypress_notif()
4534 static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) in smp_keypress_notif() argument
4536 ARG_UNUSED(smp); in smp_keypress_notif()
4542 atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); in smp_keypress_notif()
4548 uint8_t (*func)(struct bt_smp *smp, struct net_buf *buf);
4568 static bool is_in_pairing_procedure(struct bt_smp *smp) in is_in_pairing_procedure() argument
4570 return atomic_test_bit(smp->flags, SMP_FLAG_PAIRING); in is_in_pairing_procedure()
4575 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan.chan); in bt_smp_recv() local
4592 if (atomic_test_bit(smp->flags, SMP_FLAG_TIMEOUT)) { in bt_smp_recv()
4609 smp_error(smp, BT_SMP_ERR_CMD_NOTSUPP); in bt_smp_recv()
4613 if (!atomic_test_and_clear_bit(smp->allowed_cmds, hdr->code)) { in bt_smp_recv()
4616 if (is_in_pairing_procedure(smp)) { in bt_smp_recv()
4617 smp_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_recv()
4624 smp_error(smp, BT_SMP_ERR_INVALID_PARAMS); in bt_smp_recv()
4628 err = handlers[hdr->code].func(smp, buf); in bt_smp_recv()
4630 smp_error(smp, err); in bt_smp_recv()
4652 struct bt_smp *smp = &bt_smp_pool[i]; in bt_smp_pkey_ready() local
4655 if (!atomic_test_bit(smp->flags, SMP_FLAG_PKEY_SEND)) { in bt_smp_pkey_ready()
4660 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in bt_smp_pkey_ready()
4661 err = sc_send_public_key(smp); in bt_smp_pkey_ready()
4663 smp_error(smp, err); in bt_smp_pkey_ready()
4666 atomic_set_bit(smp->allowed_cmds, in bt_smp_pkey_ready()
4672 err = smp_public_key_periph(smp); in bt_smp_pkey_ready()
4674 smp_error(smp, err); in bt_smp_pkey_ready()
4682 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan.chan); in bt_smp_connected() local
4687 k_work_init_delayable(&smp->work, smp_timeout); in bt_smp_connected()
4688 smp_reset(smp); in bt_smp_connected()
4690 atomic_ptr_set(&smp->auth_cb, BT_SMP_AUTH_CB_UNINITIALIZED); in bt_smp_connected()
4691 atomic_set(&smp->bondable, BT_SMP_BONDABLE_UNINITIALIZED); in bt_smp_connected()
4696 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan.chan); in bt_smp_disconnected() local
4705 (void)k_work_cancel_delayable(&smp->work); in bt_smp_disconnected()
4707 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING) || in bt_smp_disconnected()
4708 atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING) || in bt_smp_disconnected()
4709 atomic_test_bit(smp->flags, SMP_FLAG_SEC_REQ)) { in bt_smp_disconnected()
4711 smp_pairing_complete(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_disconnected()
4725 (void)memset(smp, 0, sizeof(*smp)); in bt_smp_disconnected()
4731 struct bt_smp *smp = CONTAINER_OF(chan, struct bt_smp, chan.chan); in bt_smp_encrypt_change() local
4737 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in bt_smp_encrypt_change()
4746 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_encrypt_change()
4751 atomic_set_bit(smp->flags, SMP_FLAG_KEYS_DISTR); in bt_smp_encrypt_change()
4752 smp_pairing_complete(smp, smp_err); in bt_smp_encrypt_change()
4766 if (!atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_encrypt_change()
4767 smp_reset(smp); in bt_smp_encrypt_change()
4772 if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_encrypt_change()
4773 if ((smp->local_dist & BT_SMP_DIST_LINK_KEY) && in bt_smp_encrypt_change()
4774 (smp->remote_dist & BT_SMP_DIST_LINK_KEY)) { in bt_smp_encrypt_change()
4779 atomic_set_bit(smp->flags, SMP_FLAG_DERIVE_LK); in bt_smp_encrypt_change()
4785 smp->local_dist &= ~BT_SMP_DIST_LINK_KEY; in bt_smp_encrypt_change()
4786 smp->remote_dist &= ~BT_SMP_DIST_LINK_KEY; in bt_smp_encrypt_change()
4789 if (smp->remote_dist & BT_SMP_DIST_ENC_KEY) { in bt_smp_encrypt_change()
4790 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_ENCRYPT_INFO); in bt_smp_encrypt_change()
4791 } else if (smp->remote_dist & BT_SMP_DIST_ID_KEY) { in bt_smp_encrypt_change()
4792 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO); in bt_smp_encrypt_change()
4793 } else if (smp->remote_dist & BT_SMP_DIST_SIGN) { in bt_smp_encrypt_change()
4794 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO); in bt_smp_encrypt_change()
4819 !(smp->remote_dist & BT_SMP_DIST_ID_KEY)) { in bt_smp_encrypt_change()
4822 smp_err = smp_id_add_replace(smp, conn->le.keys); in bt_smp_encrypt_change()
4824 smp_pairing_complete(smp, smp_err); in bt_smp_encrypt_change()
4828 atomic_set_bit(smp->flags, SMP_FLAG_KEYS_DISTR); in bt_smp_encrypt_change()
4832 conn->role == BT_HCI_ROLE_CENTRAL && smp->remote_dist) { in bt_smp_encrypt_change()
4844 if (bt_smp_distribute_keys(smp)) { in bt_smp_encrypt_change()
4849 if (!smp->local_dist && !smp->remote_dist) { in bt_smp_encrypt_change()
4850 smp_pairing_complete(smp, 0); in bt_smp_encrypt_change()
5448 struct bt_smp *smp; in bt_conn_set_bondable() local
5460 smp = smp_chan_get(conn); in bt_conn_set_bondable()
5461 if (!smp) { in bt_conn_set_bondable()
5465 if (atomic_cas(&smp->bondable, BT_SMP_BONDABLE_UNINITIALIZED, (atomic_val_t)enable)) { in bt_conn_set_bondable()
5475 struct bt_smp *smp; in bt_smp_auth_cb_overlay() local
5477 smp = smp_chan_get(conn); in bt_smp_auth_cb_overlay()
5478 if (!smp) { in bt_smp_auth_cb_overlay()
5482 if (atomic_ptr_cas(&smp->auth_cb, BT_SMP_AUTH_CB_UNINITIALIZED, (atomic_ptr_val_t)cb)) { in bt_smp_auth_cb_overlay()
5490 static int smp_send_keypress_notif(struct bt_smp *smp, uint8_t type) in smp_send_keypress_notif() argument
5495 buf = smp_create_pdu(smp, BT_SMP_KEYPRESS_NOTIFICATION, sizeof(*req)); in smp_send_keypress_notif()
5503 smp_send(smp, buf, NULL, NULL); in smp_send_keypress_notif()
5512 struct bt_smp *smp; in bt_smp_auth_keypress_notify() local
5514 smp = smp_chan_get(conn); in bt_smp_auth_keypress_notify()
5515 if (!smp) { in bt_smp_auth_keypress_notify()
5526 if (smp->method != PASSKEY_INPUT || in bt_smp_auth_keypress_notify()
5527 !atomic_test_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_keypress_notify()
5532 return smp_send_keypress_notif(smp, type); in bt_smp_auth_keypress_notify()
5538 struct bt_smp *smp; in bt_smp_auth_passkey_entry() local
5541 smp = smp_chan_get(conn); in bt_smp_auth_passkey_entry()
5542 if (!smp) { in bt_smp_auth_passkey_entry()
5546 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_passkey_entry()
5551 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_auth_passkey_entry()
5552 legacy_passkey_entry(smp, passkey); in bt_smp_auth_passkey_entry()
5557 smp->passkey = sys_cpu_to_le32(passkey); in bt_smp_auth_passkey_entry()
5560 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in bt_smp_auth_passkey_entry()
5561 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_CONFIRM); in bt_smp_auth_passkey_entry()
5562 err = smp_send_pairing_confirm(smp); in bt_smp_auth_passkey_entry()
5564 smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in bt_smp_auth_passkey_entry()
5571 atomic_test_bit(smp->flags, SMP_FLAG_CFM_DELAYED)) { in bt_smp_auth_passkey_entry()
5572 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in bt_smp_auth_passkey_entry()
5573 err = smp_send_pairing_confirm(smp); in bt_smp_auth_passkey_entry()
5575 smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in bt_smp_auth_passkey_entry()
5585 struct bt_smp *smp; in bt_smp_auth_passkey_confirm() local
5587 smp = smp_chan_get(conn); in bt_smp_auth_passkey_confirm()
5588 if (!smp) { in bt_smp_auth_passkey_confirm()
5592 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_passkey_confirm()
5597 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_PENDING)) { in bt_smp_auth_passkey_confirm()
5598 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in bt_smp_auth_passkey_confirm()
5603 if (atomic_test_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT)) { in bt_smp_auth_passkey_confirm()
5604 atomic_set_bit(smp->flags, SMP_FLAG_DHKEY_SEND); in bt_smp_auth_passkey_confirm()
5608 if (atomic_test_bit(smp->flags, SMP_FLAG_DHKEY_SEND)) { in bt_smp_auth_passkey_confirm()
5612 if (smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in bt_smp_auth_passkey_confirm()
5613 err = compute_and_send_central_dhcheck(smp); in bt_smp_auth_passkey_confirm()
5615 smp_error(smp, err); in bt_smp_auth_passkey_confirm()
5622 err = compute_and_check_and_send_periph_dhcheck(smp); in bt_smp_auth_passkey_confirm()
5624 smp_error(smp, err); in bt_smp_auth_passkey_confirm()
5635 struct bt_smp *smp; in bt_smp_le_oob_set_tk() local
5637 smp = smp_chan_get(conn); in bt_smp_le_oob_set_tk()
5638 if (!smp || !tk) { in bt_smp_le_oob_set_tk()
5644 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_le_oob_set_tk()
5655 memcpy(smp->tk, tk, 16*sizeof(uint8_t)); in bt_smp_le_oob_set_tk()
5657 legacy_user_tk_entry(smp); in bt_smp_le_oob_set_tk()
5702 static bool le_sc_oob_data_check(struct bt_smp *smp, bool oobd_local_present, in le_sc_oob_data_check() argument
5705 bool req_oob_present = le_sc_oob_data_req_check(smp); in le_sc_oob_data_check()
5706 bool rsp_oob_present = le_sc_oob_data_rsp_check(smp); in le_sc_oob_data_check()
5709 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in le_sc_oob_data_check()
5724 static int le_sc_oob_pairing_continue(struct bt_smp *smp) in le_sc_oob_pairing_continue() argument
5726 if (smp->oobd_remote) { in le_sc_oob_pairing_continue()
5730 err = bt_crypto_f4(smp->pkey, smp->pkey, smp->oobd_remote->r, 0, c); in le_sc_oob_pairing_continue()
5735 bool match = (memcmp(c, smp->oobd_remote->c, sizeof(c)) == 0); in le_sc_oob_pairing_continue()
5738 smp_error(smp, BT_SMP_ERR_CONFIRM_FAILED); in le_sc_oob_pairing_continue()
5744 smp->chan.chan.conn->role == BT_HCI_ROLE_CENTRAL) { in le_sc_oob_pairing_continue()
5745 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM); in le_sc_oob_pairing_continue()
5747 atomic_set_bit(smp->allowed_cmds, BT_SMP_DHKEY_CHECK); in le_sc_oob_pairing_continue()
5748 atomic_set_bit(smp->flags, SMP_FLAG_DHCHECK_WAIT); in le_sc_oob_pairing_continue()
5751 return smp_send_pairing_random(smp); in le_sc_oob_pairing_continue()
5758 struct bt_smp *smp; in bt_smp_le_oob_set_sc_data() local
5760 smp = smp_chan_get(conn); in bt_smp_le_oob_set_sc_data()
5761 if (!smp) { in bt_smp_le_oob_set_sc_data()
5765 if (!le_sc_oob_data_check(smp, (oobd_local != NULL), in bt_smp_le_oob_set_sc_data()
5770 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_OOB_PENDING)) { in bt_smp_le_oob_set_sc_data()
5774 smp->oobd_local = oobd_local; in bt_smp_le_oob_set_sc_data()
5775 smp->oobd_remote = oobd_remote; in bt_smp_le_oob_set_sc_data()
5777 return le_sc_oob_pairing_continue(smp); in bt_smp_le_oob_set_sc_data()
5784 struct bt_smp *smp; in bt_smp_le_oob_get_sc_data() local
5786 smp = smp_chan_get(conn); in bt_smp_le_oob_get_sc_data()
5787 if (!smp) { in bt_smp_le_oob_get_sc_data()
5791 if (!smp->oobd_local && !smp->oobd_remote) { in bt_smp_le_oob_get_sc_data()
5796 *oobd_local = smp->oobd_local; in bt_smp_le_oob_get_sc_data()
5800 *oobd_remote = smp->oobd_remote; in bt_smp_le_oob_get_sc_data()
5809 struct bt_smp *smp; in bt_smp_auth_cancel() local
5811 smp = smp_chan_get(conn); in bt_smp_auth_cancel()
5812 if (!smp) { in bt_smp_auth_cancel()
5816 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_cancel()
5822 switch (smp->method) { in bt_smp_auth_cancel()
5825 return smp_error(smp, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); in bt_smp_auth_cancel()
5827 return smp_error(smp, BT_SMP_ERR_CONFIRM_FAILED); in bt_smp_auth_cancel()
5830 return smp_error(smp, BT_SMP_ERR_OOB_NOT_AVAIL); in bt_smp_auth_cancel()
5832 return smp_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_auth_cancel()
5834 LOG_ERR("Unknown pairing method (%u)", smp->method); in bt_smp_auth_cancel()
5842 struct bt_smp *smp; in bt_smp_auth_pairing_confirm() local
5844 smp = smp_chan_get(conn); in bt_smp_auth_pairing_confirm()
5845 if (!smp) { in bt_smp_auth_pairing_confirm()
5849 if (!atomic_test_and_clear_bit(smp->flags, SMP_FLAG_USER)) { in bt_smp_auth_pairing_confirm()
5855 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_auth_pairing_confirm()
5856 atomic_set_bit(smp->allowed_cmds, in bt_smp_auth_pairing_confirm()
5858 return legacy_send_pairing_confirm(smp); in bt_smp_auth_pairing_confirm()
5862 atomic_set_bit(smp->flags, SMP_FLAG_PKEY_SEND); in bt_smp_auth_pairing_confirm()
5866 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in bt_smp_auth_pairing_confirm()
5867 return sc_send_public_key(smp); in bt_smp_auth_pairing_confirm()
5871 if (!atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_auth_pairing_confirm()
5872 atomic_set_bit(smp->allowed_cmds, in bt_smp_auth_pairing_confirm()
5874 return send_pairing_rsp(smp); in bt_smp_auth_pairing_confirm()
5877 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_PUBLIC_KEY); in bt_smp_auth_pairing_confirm()
5878 if (send_pairing_rsp(smp)) { in bt_smp_auth_pairing_confirm()
5917 struct bt_smp *smp; in bt_smp_start_security() local
5919 smp = smp_chan_get(conn); in bt_smp_start_security()
5920 if (!smp) { in bt_smp_start_security()
5925 if (atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_start_security()
5930 if (atomic_test_bit(smp->flags, SMP_FLAG_ENC_PENDING)) { in bt_smp_start_security()
5948 atomic_set_bit(smp->allowed_cmds, BT_SMP_CMD_SECURITY_REQUEST); in bt_smp_start_security()
5949 atomic_set_bit(smp->flags, SMP_FLAG_ENC_PENDING); in bt_smp_start_security()
5964 struct bt_smp *smp; in bt_smp_update_keys() local
5966 smp = smp_chan_get(conn); in bt_smp_update_keys()
5967 if (!smp) { in bt_smp_update_keys()
5971 if (!atomic_test_bit(smp->flags, SMP_FLAG_PAIRING)) { in bt_smp_update_keys()
5986 smp_error(smp, BT_SMP_ERR_UNSPECIFIED); in bt_smp_update_keys()
5991 if (atomic_test_bit(smp->flags, SMP_FLAG_SC_DEBUG_KEY)) { in bt_smp_update_keys()
6000 switch (smp->method) { in bt_smp_update_keys()
6018 conn->le.keys->enc_size = get_encryption_key_size(smp); in bt_smp_update_keys()
6025 if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { in bt_smp_update_keys()
6028 if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { in bt_smp_update_keys()
6030 memcpy(conn->le.keys->ltk.val, smp->tk, in bt_smp_update_keys()
6039 sys_memcpy_swap(ltk, smp->tk, conn->le.keys->enc_size); in bt_smp_update_keys()
6060 struct bt_smp *smp = &bt_smp_pool[i]; in bt_smp_accept() local
6062 if (smp->chan.chan.conn) { in bt_smp_accept()
6066 smp->chan.chan.ops = &ops; in bt_smp_accept()
6068 *chan = &smp->chan.chan; in bt_smp_accept()