Lines Matching full:smp

38 #include "smp.h"
55 #define SMP_ALLOW_CMD(smp, code) set_bit(code, &smp->allow_cmd) argument
101 u8 preq[7]; /* SMP Pairing Request */
102 u8 prsp[7]; /* SMP Pairing Response */
103 u8 prnd[16]; /* SMP Pairing Random (local) */
104 u8 rrnd[16]; /* SMP Pairing Random (remote) */
105 u8 pcnf[16]; /* SMP Pairing Confirm */
106 u8 tk[16]; /* SMP Temporary Key */
134 /* These debug key values are defined in the SMP section of the core
165 /* The following functions map to the LE SC SMP crypto functions
237 * the SMP section of the Bluetooth core specification. In ASCII in smp_f5()
371 /* The following functions map to the legacy SMP crypto functions e, c1,
541 struct smp_dev *smp; in smp_generate_oob() local
547 smp = chan->data; in smp_generate_oob()
551 err = set_ecdh_privkey(smp->tfm_ecdh, debug_sk); in smp_generate_oob()
554 memcpy(smp->local_pk, debug_pk, 64); in smp_generate_oob()
555 smp->debug_key = true; in smp_generate_oob()
559 err = generate_ecdh_keys(smp->tfm_ecdh, smp->local_pk); in smp_generate_oob()
566 if (crypto_memneq(smp->local_pk, debug_pk, 64)) in smp_generate_oob()
569 smp->debug_key = false; in smp_generate_oob()
572 SMP_DBG("OOB Public Key X: %32phN", smp->local_pk); in smp_generate_oob()
573 SMP_DBG("OOB Public Key Y: %32phN", smp->local_pk + 32); in smp_generate_oob()
575 get_random_bytes(smp->local_rand, 16); in smp_generate_oob()
577 err = smp_f4(smp->tfm_cmac, smp->local_pk, smp->local_pk, in smp_generate_oob()
578 smp->local_rand, 0, hash); in smp_generate_oob()
582 memcpy(rand, smp->local_rand, 16); in smp_generate_oob()
584 smp->local_oob = true; in smp_generate_oob()
591 struct l2cap_chan *chan = conn->smp; in smp_send_cmd()
592 struct smp_chan *smp; in smp_send_cmd() local
616 smp = chan->data; in smp_send_cmd()
618 cancel_delayed_work_sync(&smp->security_timer); in smp_send_cmd()
619 schedule_delayed_work(&smp->security_timer, SMP_TIMEOUT); in smp_send_cmd()
651 struct l2cap_chan *chan = conn->smp; in build_pairing_cmd()
652 struct smp_chan *smp = chan->data; in build_pairing_cmd() local
689 set_bit(SMP_FLAG_REMOTE_OOB, &smp->flags); in build_pairing_cmd()
691 memcpy(smp->rr, oob_data->rand256, 16); in build_pairing_cmd()
692 memcpy(smp->pcnf, oob_data->hash256, 16); in build_pairing_cmd()
693 SMP_DBG("OOB Remote Confirmation: %16phN", smp->pcnf); in build_pairing_cmd()
694 SMP_DBG("OOB Remote Random: %16phN", smp->rr); in build_pairing_cmd()
709 smp->remote_key_dist = remote_dist; in build_pairing_cmd()
720 smp->remote_key_dist = rsp->init_key_dist; in build_pairing_cmd()
725 struct l2cap_chan *chan = conn->smp; in check_enc_key_size()
727 struct smp_chan *smp = chan->data; in check_enc_key_size() local
737 smp->enc_key_size = max_key_size; in check_enc_key_size()
744 struct l2cap_chan *chan = conn->smp; in smp_chan_destroy()
745 struct smp_chan *smp = chan->data; in smp_chan_destroy() local
749 BUG_ON(!smp); in smp_chan_destroy()
751 cancel_delayed_work_sync(&smp->security_timer); in smp_chan_destroy()
753 complete = test_bit(SMP_FLAG_COMPLETE, &smp->flags); in smp_chan_destroy()
756 kfree_sensitive(smp->csrk); in smp_chan_destroy()
757 kfree_sensitive(smp->slave_csrk); in smp_chan_destroy()
758 kfree_sensitive(smp->link_key); in smp_chan_destroy()
760 crypto_free_shash(smp->tfm_cmac); in smp_chan_destroy()
761 crypto_free_kpp(smp->tfm_ecdh); in smp_chan_destroy()
766 if (smp->ltk && smp->ltk->type == SMP_LTK_P256_DEBUG && in smp_chan_destroy()
768 list_del_rcu(&smp->ltk->list); in smp_chan_destroy()
769 kfree_rcu(smp->ltk, rcu); in smp_chan_destroy()
770 smp->ltk = NULL; in smp_chan_destroy()
775 if (smp->ltk) { in smp_chan_destroy()
776 list_del_rcu(&smp->ltk->list); in smp_chan_destroy()
777 kfree_rcu(smp->ltk, rcu); in smp_chan_destroy()
780 if (smp->slave_ltk) { in smp_chan_destroy()
781 list_del_rcu(&smp->slave_ltk->list); in smp_chan_destroy()
782 kfree_rcu(smp->slave_ltk, rcu); in smp_chan_destroy()
785 if (smp->remote_irk) { in smp_chan_destroy()
786 list_del_rcu(&smp->remote_irk->list); in smp_chan_destroy()
787 kfree_rcu(smp->remote_irk, rcu); in smp_chan_destroy()
792 kfree_sensitive(smp); in smp_chan_destroy()
799 struct l2cap_chan *chan = conn->smp; in smp_failure()
835 static u8 get_auth_method(struct smp_chan *smp, u8 local_io, u8 remote_io) in get_auth_method() argument
844 if (test_bit(SMP_FLAG_SC, &smp->flags)) in get_auth_method()
854 struct l2cap_chan *chan = conn->smp; in tk_request()
855 struct smp_chan *smp = chan->data; in tk_request() local
860 memset(smp->tk, 0, sizeof(smp->tk)); in tk_request()
861 clear_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
872 smp->method = JUST_CFM; in tk_request()
874 smp->method = get_auth_method(smp, local_io, remote_io); in tk_request()
877 if (smp->method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, in tk_request()
878 &smp->flags)) in tk_request()
879 smp->method = JUST_WORKS; in tk_request()
882 if (smp->method == JUST_CFM && in tk_request()
884 smp->method = JUST_WORKS; in tk_request()
888 if (smp->method == JUST_WORKS) { in tk_request()
895 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in tk_request()
902 if (test_bit(SMP_FLAG_SC, &smp->flags)) in tk_request()
906 if (smp->method != JUST_CFM) { in tk_request()
907 set_bit(SMP_FLAG_MITM_AUTH, &smp->flags); in tk_request()
915 if (smp->method == OVERLAP) { in tk_request()
917 smp->method = CFM_PASSKEY; in tk_request()
919 smp->method = REQ_PASSKEY; in tk_request()
923 if (smp->method == CFM_PASSKEY) { in tk_request()
924 memset(smp->tk, 0, sizeof(smp->tk)); in tk_request()
927 put_unaligned_le32(passkey, smp->tk); in tk_request()
929 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
932 if (smp->method == REQ_PASSKEY) in tk_request()
935 else if (smp->method == JUST_CFM) in tk_request()
947 static u8 smp_confirm(struct smp_chan *smp) in smp_confirm() argument
949 struct l2cap_conn *conn = smp->conn; in smp_confirm()
955 ret = smp_c1(smp->tk, smp->prnd, smp->preq, smp->prsp, in smp_confirm()
962 clear_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_confirm()
964 smp_send_cmd(smp->conn, SMP_CMD_PAIRING_CONFIRM, sizeof(cp), &cp); in smp_confirm()
967 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_confirm()
969 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_confirm()
974 static u8 smp_random(struct smp_chan *smp) in smp_random() argument
976 struct l2cap_conn *conn = smp->conn; in smp_random()
983 ret = smp_c1(smp->tk, smp->rrnd, smp->preq, smp->prsp, in smp_random()
989 if (crypto_memneq(smp->pcnf, confirm, sizeof(smp->pcnf))) { in smp_random()
1000 smp_s1(smp->tk, smp->rrnd, smp->prnd, stk); in smp_random()
1005 hci_le_start_enc(hcon, ediv, rand, stk, smp->enc_key_size); in smp_random()
1006 hcon->enc_key_size = smp->enc_key_size; in smp_random()
1013 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_random()
1014 smp->prnd); in smp_random()
1016 smp_s1(smp->tk, smp->prnd, smp->rrnd, stk); in smp_random()
1028 SMP_STK, auth, stk, smp->enc_key_size, ediv, rand); in smp_random()
1036 struct l2cap_chan *chan = conn->smp; in smp_notify_keys()
1037 struct smp_chan *smp = chan->data; in smp_notify_keys() local
1040 struct smp_cmd_pairing *req = (void *) &smp->preq[1]; in smp_notify_keys()
1041 struct smp_cmd_pairing *rsp = (void *) &smp->prsp[1]; in smp_notify_keys()
1059 if (smp->remote_irk) { in smp_notify_keys()
1060 mgmt_new_irk(hdev, smp->remote_irk, persistent); in smp_notify_keys()
1067 bacpy(&hcon->dst, &smp->remote_irk->bdaddr); in smp_notify_keys()
1068 hcon->dst_type = smp->remote_irk->addr_type; in smp_notify_keys()
1073 if (smp->csrk) { in smp_notify_keys()
1074 smp->csrk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1075 bacpy(&smp->csrk->bdaddr, &hcon->dst); in smp_notify_keys()
1076 mgmt_new_csrk(hdev, smp->csrk, persistent); in smp_notify_keys()
1079 if (smp->slave_csrk) { in smp_notify_keys()
1080 smp->slave_csrk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1081 bacpy(&smp->slave_csrk->bdaddr, &hcon->dst); in smp_notify_keys()
1082 mgmt_new_csrk(hdev, smp->slave_csrk, persistent); in smp_notify_keys()
1085 if (smp->ltk) { in smp_notify_keys()
1086 smp->ltk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1087 bacpy(&smp->ltk->bdaddr, &hcon->dst); in smp_notify_keys()
1088 mgmt_new_ltk(hdev, smp->ltk, persistent); in smp_notify_keys()
1091 if (smp->slave_ltk) { in smp_notify_keys()
1092 smp->slave_ltk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1093 bacpy(&smp->slave_ltk->bdaddr, &hcon->dst); in smp_notify_keys()
1094 mgmt_new_ltk(hdev, smp->slave_ltk, persistent); in smp_notify_keys()
1097 if (smp->link_key) { in smp_notify_keys()
1101 if (test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags)) in smp_notify_keys()
1108 key = hci_add_link_key(hdev, smp->conn->hcon, &hcon->dst, in smp_notify_keys()
1109 smp->link_key, type, 0, &persistent); in smp_notify_keys()
1125 static void sc_add_ltk(struct smp_chan *smp) in sc_add_ltk() argument
1127 struct hci_conn *hcon = smp->conn->hcon; in sc_add_ltk()
1130 if (test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags)) in sc_add_ltk()
1140 smp->ltk = hci_add_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, in sc_add_ltk()
1141 key_type, auth, smp->tk, smp->enc_key_size, in sc_add_ltk()
1145 static void sc_generate_link_key(struct smp_chan *smp) in sc_generate_link_key() argument
1150 smp->link_key = kzalloc(16, GFP_KERNEL); in sc_generate_link_key()
1151 if (!smp->link_key) in sc_generate_link_key()
1154 if (test_bit(SMP_FLAG_CT2, &smp->flags)) { in sc_generate_link_key()
1158 if (smp_h7(smp->tfm_cmac, smp->tk, salt, smp->link_key)) { in sc_generate_link_key()
1159 kfree_sensitive(smp->link_key); in sc_generate_link_key()
1160 smp->link_key = NULL; in sc_generate_link_key()
1167 if (smp_h6(smp->tfm_cmac, smp->tk, tmp1, smp->link_key)) { in sc_generate_link_key()
1168 kfree_sensitive(smp->link_key); in sc_generate_link_key()
1169 smp->link_key = NULL; in sc_generate_link_key()
1174 if (smp_h6(smp->tfm_cmac, smp->link_key, lebr, smp->link_key)) { in sc_generate_link_key()
1175 kfree_sensitive(smp->link_key); in sc_generate_link_key()
1176 smp->link_key = NULL; in sc_generate_link_key()
1181 static void smp_allow_key_dist(struct smp_chan *smp) in smp_allow_key_dist() argument
1187 if (smp->remote_key_dist & SMP_DIST_ENC_KEY) in smp_allow_key_dist()
1188 SMP_ALLOW_CMD(smp, SMP_CMD_ENCRYPT_INFO); in smp_allow_key_dist()
1189 else if (smp->remote_key_dist & SMP_DIST_ID_KEY) in smp_allow_key_dist()
1190 SMP_ALLOW_CMD(smp, SMP_CMD_IDENT_INFO); in smp_allow_key_dist()
1191 else if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_allow_key_dist()
1192 SMP_ALLOW_CMD(smp, SMP_CMD_SIGN_INFO); in smp_allow_key_dist()
1195 static void sc_generate_ltk(struct smp_chan *smp) in sc_generate_ltk() argument
1199 struct hci_conn *hcon = smp->conn->hcon; in sc_generate_ltk()
1210 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_generate_ltk()
1212 if (test_bit(SMP_FLAG_CT2, &smp->flags)) { in sc_generate_ltk()
1216 if (smp_h7(smp->tfm_cmac, key->val, salt, smp->tk)) in sc_generate_ltk()
1222 if (smp_h6(smp->tfm_cmac, key->val, tmp2, smp->tk)) in sc_generate_ltk()
1226 if (smp_h6(smp->tfm_cmac, smp->tk, brle, smp->tk)) in sc_generate_ltk()
1229 sc_add_ltk(smp); in sc_generate_ltk()
1232 static void smp_distribute_keys(struct smp_chan *smp) in smp_distribute_keys() argument
1235 struct l2cap_conn *conn = smp->conn; in smp_distribute_keys()
1242 rsp = (void *) &smp->prsp[1]; in smp_distribute_keys()
1245 if (hcon->out && (smp->remote_key_dist & KEY_DIST_MASK)) { in smp_distribute_keys()
1246 smp_allow_key_dist(smp); in smp_distribute_keys()
1250 req = (void *) &smp->preq[1]; in smp_distribute_keys()
1260 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_distribute_keys()
1262 sc_generate_link_key(smp); in smp_distribute_keys()
1264 sc_generate_ltk(smp); in smp_distribute_keys()
1284 get_random_bytes(enc.ltk, smp->enc_key_size); in smp_distribute_keys()
1285 memset(enc.ltk + smp->enc_key_size, 0, in smp_distribute_keys()
1286 sizeof(enc.ltk) - smp->enc_key_size); in smp_distribute_keys()
1296 smp->enc_key_size, ediv, rand); in smp_distribute_keys()
1297 smp->slave_ltk = ltk; in smp_distribute_keys()
1345 smp->slave_csrk = csrk; in smp_distribute_keys()
1353 if (smp->remote_key_dist & KEY_DIST_MASK) { in smp_distribute_keys()
1354 smp_allow_key_dist(smp); in smp_distribute_keys()
1358 set_bit(SMP_FLAG_COMPLETE, &smp->flags); in smp_distribute_keys()
1366 struct smp_chan *smp = container_of(work, struct smp_chan, in smp_timeout() local
1368 struct l2cap_conn *conn = smp->conn; in smp_timeout()
1377 struct l2cap_chan *chan = conn->smp; in smp_chan_create()
1378 struct smp_chan *smp; in smp_chan_create() local
1380 smp = kzalloc(sizeof(*smp), GFP_ATOMIC); in smp_chan_create()
1381 if (!smp) in smp_chan_create()
1384 smp->tfm_cmac = crypto_alloc_shash("cmac(aes)", 0, 0); in smp_chan_create()
1385 if (IS_ERR(smp->tfm_cmac)) { in smp_chan_create()
1390 smp->tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); in smp_chan_create()
1391 if (IS_ERR(smp->tfm_ecdh)) { in smp_chan_create()
1396 smp->conn = conn; in smp_chan_create()
1397 chan->data = smp; in smp_chan_create()
1399 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_FAIL); in smp_chan_create()
1401 INIT_DELAYED_WORK(&smp->security_timer, smp_timeout); in smp_chan_create()
1405 return smp; in smp_chan_create()
1408 crypto_free_shash(smp->tfm_cmac); in smp_chan_create()
1410 kfree_sensitive(smp); in smp_chan_create()
1414 static int sc_mackey_and_ltk(struct smp_chan *smp, u8 mackey[16], u8 ltk[16]) in sc_mackey_and_ltk() argument
1416 struct hci_conn *hcon = smp->conn->hcon; in sc_mackey_and_ltk()
1420 na = smp->prnd; in sc_mackey_and_ltk()
1421 nb = smp->rrnd; in sc_mackey_and_ltk()
1423 na = smp->rrnd; in sc_mackey_and_ltk()
1424 nb = smp->prnd; in sc_mackey_and_ltk()
1432 return smp_f5(smp->tfm_cmac, smp->dhkey, na, nb, a, b, mackey, ltk); in sc_mackey_and_ltk()
1435 static void sc_dhkey_check(struct smp_chan *smp) in sc_dhkey_check() argument
1437 struct hci_conn *hcon = smp->conn->hcon; in sc_dhkey_check()
1450 memcpy(io_cap, &smp->preq[1], 3); in sc_dhkey_check()
1454 memcpy(io_cap, &smp->prsp[1], 3); in sc_dhkey_check()
1459 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in sc_dhkey_check()
1462 if (smp->method == REQ_OOB) in sc_dhkey_check()
1463 memcpy(r, smp->rr, 16); in sc_dhkey_check()
1465 smp_f6(smp->tfm_cmac, smp->mackey, smp->prnd, smp->rrnd, r, io_cap, in sc_dhkey_check()
1468 smp_send_cmd(smp->conn, SMP_CMD_DHKEY_CHECK, sizeof(check), &check); in sc_dhkey_check()
1471 static u8 sc_passkey_send_confirm(struct smp_chan *smp) in sc_passkey_send_confirm() argument
1473 struct l2cap_conn *conn = smp->conn; in sc_passkey_send_confirm()
1478 r = ((hcon->passkey_notify >> smp->passkey_round) & 0x01); in sc_passkey_send_confirm()
1481 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in sc_passkey_send_confirm()
1483 if (smp_f4(smp->tfm_cmac, smp->local_pk, smp->remote_pk, smp->prnd, r, in sc_passkey_send_confirm()
1492 static u8 sc_passkey_round(struct smp_chan *smp, u8 smp_op) in sc_passkey_round() argument
1494 struct l2cap_conn *conn = smp->conn; in sc_passkey_round()
1500 if (smp->passkey_round >= 20) in sc_passkey_round()
1505 r = ((hcon->passkey_notify >> smp->passkey_round) & 0x01); in sc_passkey_round()
1508 if (smp_f4(smp->tfm_cmac, smp->remote_pk, smp->local_pk, in sc_passkey_round()
1509 smp->rrnd, r, cfm)) in sc_passkey_round()
1512 if (crypto_memneq(smp->pcnf, cfm, 16)) in sc_passkey_round()
1515 smp->passkey_round++; in sc_passkey_round()
1517 if (smp->passkey_round == 20) { in sc_passkey_round()
1519 if (sc_mackey_and_ltk(smp, smp->mackey, smp->tk)) in sc_passkey_round()
1528 sizeof(smp->prnd), smp->prnd); in sc_passkey_round()
1529 if (smp->passkey_round == 20) in sc_passkey_round()
1530 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in sc_passkey_round()
1532 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in sc_passkey_round()
1537 if (smp->passkey_round != 20) in sc_passkey_round()
1538 return sc_passkey_round(smp, 0); in sc_passkey_round()
1541 sc_dhkey_check(smp); in sc_passkey_round()
1542 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in sc_passkey_round()
1547 if (test_bit(SMP_FLAG_WAIT_USER, &smp->flags)) { in sc_passkey_round()
1548 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in sc_passkey_round()
1552 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in sc_passkey_round()
1556 sizeof(smp->prnd), smp->prnd); in sc_passkey_round()
1560 return sc_passkey_send_confirm(smp); in sc_passkey_round()
1569 smp->passkey_round + 1); in sc_passkey_round()
1571 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in sc_passkey_round()
1573 return sc_passkey_send_confirm(smp); in sc_passkey_round()
1579 static int sc_user_reply(struct smp_chan *smp, u16 mgmt_op, __le32 passkey) in sc_user_reply() argument
1581 struct l2cap_conn *conn = smp->conn; in sc_user_reply()
1585 clear_bit(SMP_FLAG_WAIT_USER, &smp->flags); in sc_user_reply()
1589 smp_failure(smp->conn, SMP_PASSKEY_ENTRY_FAILED); in sc_user_reply()
1592 smp_failure(smp->conn, SMP_NUMERIC_COMP_FAILED); in sc_user_reply()
1596 smp->passkey_round = 0; in sc_user_reply()
1598 if (test_and_clear_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) in sc_user_reply()
1603 if (sc_passkey_round(smp, smp_op)) in sc_user_reply()
1611 sc_dhkey_check(smp); in sc_user_reply()
1612 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in sc_user_reply()
1613 } else if (test_and_clear_bit(SMP_FLAG_DHKEY_PENDING, &smp->flags)) { in sc_user_reply()
1614 sc_dhkey_check(smp); in sc_user_reply()
1615 sc_add_ltk(smp); in sc_user_reply()
1625 struct smp_chan *smp; in smp_user_confirm_reply() local
1634 chan = conn->smp; in smp_user_confirm_reply()
1644 smp = chan->data; in smp_user_confirm_reply()
1646 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_user_confirm_reply()
1647 err = sc_user_reply(smp, mgmt_op, passkey); in smp_user_confirm_reply()
1654 memset(smp->tk, 0, sizeof(smp->tk)); in smp_user_confirm_reply()
1656 put_unaligned_le32(value, smp->tk); in smp_user_confirm_reply()
1659 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in smp_user_confirm_reply()
1675 if (test_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) { in smp_user_confirm_reply()
1676 u8 rsp = smp_confirm(smp); in smp_user_confirm_reply()
1686 static void build_bredr_pairing_cmd(struct smp_chan *smp, in build_bredr_pairing_cmd() argument
1690 struct l2cap_conn *conn = smp->conn; in build_bredr_pairing_cmd()
1713 smp->remote_key_dist = remote_dist; in build_bredr_pairing_cmd()
1725 smp->remote_key_dist = rsp->init_key_dist; in build_bredr_pairing_cmd()
1731 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_req()
1733 struct smp_chan *smp; in smp_cmd_pairing_req() local
1746 smp = smp_chan_create(conn); in smp_cmd_pairing_req()
1748 smp = chan->data; in smp_cmd_pairing_req()
1750 if (!smp) in smp_cmd_pairing_req()
1763 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_cmd_pairing_req()
1764 memcpy(&smp->preq[1], req, sizeof(*req)); in smp_cmd_pairing_req()
1772 set_bit(SMP_FLAG_LOCAL_OOB, &smp->flags); in smp_cmd_pairing_req()
1774 /* SMP over BR/EDR requires special treatment */ in smp_cmd_pairing_req()
1781 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_req()
1783 build_bredr_pairing_cmd(smp, req, &rsp); in smp_cmd_pairing_req()
1786 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_req()
1793 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_req()
1795 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_req()
1796 memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); in smp_cmd_pairing_req()
1799 smp_distribute_keys(smp); in smp_cmd_pairing_req()
1806 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_req()
1809 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_req()
1824 method = get_auth_method(smp, conn->hcon->io_capability, in smp_cmd_pairing_req()
1834 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in smp_cmd_pairing_req()
1836 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_req()
1837 memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); in smp_cmd_pairing_req()
1841 clear_bit(SMP_FLAG_INITIATOR, &smp->flags); in smp_cmd_pairing_req()
1848 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_pairing_req()
1850 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_req()
1851 SMP_ALLOW_CMD(smp, SMP_CMD_PUBLIC_KEY); in smp_cmd_pairing_req()
1853 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_req()
1866 static u8 sc_send_public_key(struct smp_chan *smp) in sc_send_public_key() argument
1868 struct hci_dev *hdev = smp->conn->hcon->hdev; in sc_send_public_key()
1872 if (test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) { in sc_send_public_key()
1881 memcpy(smp->local_pk, smp_dev->local_pk, 64); in sc_send_public_key()
1882 memcpy(smp->lr, smp_dev->local_rand, 16); in sc_send_public_key()
1885 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_send_public_key()
1892 if (set_ecdh_privkey(smp->tfm_ecdh, debug_sk)) in sc_send_public_key()
1894 memcpy(smp->local_pk, debug_pk, 64); in sc_send_public_key()
1895 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_send_public_key()
1899 if (generate_ecdh_keys(smp->tfm_ecdh, smp->local_pk)) in sc_send_public_key()
1905 if (crypto_memneq(smp->local_pk, debug_pk, 64)) in sc_send_public_key()
1911 SMP_DBG("Local Public Key X: %32phN", smp->local_pk); in sc_send_public_key()
1912 SMP_DBG("Local Public Key Y: %32phN", smp->local_pk + 32); in sc_send_public_key()
1914 smp_send_cmd(smp->conn, SMP_CMD_PUBLIC_KEY, 64, smp->local_pk); in sc_send_public_key()
1922 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_rsp()
1923 struct smp_chan *smp = chan->data; in smp_cmd_pairing_rsp() local
1938 req = (void *) &smp->preq[1]; in smp_cmd_pairing_rsp()
1954 set_bit(SMP_FLAG_LOCAL_OOB, &smp->flags); in smp_cmd_pairing_rsp()
1956 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_rsp()
1957 memcpy(&smp->prsp[1], rsp, sizeof(*rsp)); in smp_cmd_pairing_rsp()
1962 smp->remote_key_dist &= rsp->resp_key_dist; in smp_cmd_pairing_rsp()
1965 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_rsp()
1970 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_rsp()
1971 smp_distribute_keys(smp); in smp_cmd_pairing_rsp()
1976 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_rsp()
1984 method = get_auth_method(smp, req->io_capability, in smp_cmd_pairing_rsp()
1990 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in smp_cmd_pairing_rsp()
1995 smp->remote_key_dist &= rsp->resp_key_dist; in smp_cmd_pairing_rsp()
1997 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_rsp()
1999 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_rsp()
2000 SMP_ALLOW_CMD(smp, SMP_CMD_PUBLIC_KEY); in smp_cmd_pairing_rsp()
2001 return sc_send_public_key(smp); in smp_cmd_pairing_rsp()
2010 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_cmd_pairing_rsp()
2013 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags)) in smp_cmd_pairing_rsp()
2014 return smp_confirm(smp); in smp_cmd_pairing_rsp()
2019 static u8 sc_check_confirm(struct smp_chan *smp) in sc_check_confirm() argument
2021 struct l2cap_conn *conn = smp->conn; in sc_check_confirm()
2025 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in sc_check_confirm()
2026 return sc_passkey_round(smp, SMP_CMD_PAIRING_CONFIRM); in sc_check_confirm()
2029 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in sc_check_confirm()
2030 smp->prnd); in sc_check_confirm()
2031 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in sc_check_confirm()
2041 static int fixup_sc_false_positive(struct smp_chan *smp) in fixup_sc_false_positive() argument
2043 struct l2cap_conn *conn = smp->conn; in fixup_sc_false_positive()
2058 bt_dev_err(hdev, "trying to fall back to legacy SMP"); in fixup_sc_false_positive()
2060 req = (void *) &smp->preq[1]; in fixup_sc_false_positive()
2061 rsp = (void *) &smp->prsp[1]; in fixup_sc_false_positive()
2064 smp->remote_key_dist = (req->init_key_dist & rsp->resp_key_dist); in fixup_sc_false_positive()
2069 bt_dev_err(hdev, "failed to fall back to legacy SMP"); in fixup_sc_false_positive()
2073 clear_bit(SMP_FLAG_SC, &smp->flags); in fixup_sc_false_positive()
2080 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_confirm()
2081 struct smp_chan *smp = chan->data; in smp_cmd_pairing_confirm() local
2085 if (skb->len < sizeof(smp->pcnf)) in smp_cmd_pairing_confirm()
2088 memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf)); in smp_cmd_pairing_confirm()
2089 skb_pull(skb, sizeof(smp->pcnf)); in smp_cmd_pairing_confirm()
2091 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_confirm()
2095 if (test_bit(SMP_FLAG_REMOTE_PK, &smp->flags)) in smp_cmd_pairing_confirm()
2096 return sc_check_confirm(smp); in smp_cmd_pairing_confirm()
2098 BT_ERR("Unexpected SMP Pairing Confirm"); in smp_cmd_pairing_confirm()
2100 ret = fixup_sc_false_positive(smp); in smp_cmd_pairing_confirm()
2106 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_cmd_pairing_confirm()
2107 smp->prnd); in smp_cmd_pairing_confirm()
2108 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_pairing_confirm()
2112 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags)) in smp_cmd_pairing_confirm()
2113 return smp_confirm(smp); in smp_cmd_pairing_confirm()
2115 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_cmd_pairing_confirm()
2122 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_random()
2123 struct smp_chan *smp = chan->data; in smp_cmd_pairing_random() local
2131 if (skb->len < sizeof(smp->rrnd)) in smp_cmd_pairing_random()
2134 memcpy(smp->rrnd, skb->data, sizeof(smp->rrnd)); in smp_cmd_pairing_random()
2135 skb_pull(skb, sizeof(smp->rrnd)); in smp_cmd_pairing_random()
2137 if (!test_bit(SMP_FLAG_SC, &smp->flags)) in smp_cmd_pairing_random()
2138 return smp_random(smp); in smp_cmd_pairing_random()
2141 pkax = smp->local_pk; in smp_cmd_pairing_random()
2142 pkbx = smp->remote_pk; in smp_cmd_pairing_random()
2143 na = smp->prnd; in smp_cmd_pairing_random()
2144 nb = smp->rrnd; in smp_cmd_pairing_random()
2146 pkax = smp->remote_pk; in smp_cmd_pairing_random()
2147 pkbx = smp->local_pk; in smp_cmd_pairing_random()
2148 na = smp->rrnd; in smp_cmd_pairing_random()
2149 nb = smp->prnd; in smp_cmd_pairing_random()
2152 if (smp->method == REQ_OOB) { in smp_cmd_pairing_random()
2155 sizeof(smp->prnd), smp->prnd); in smp_cmd_pairing_random()
2156 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in smp_cmd_pairing_random()
2161 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in smp_cmd_pairing_random()
2162 return sc_passkey_round(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_pairing_random()
2167 err = smp_f4(smp->tfm_cmac, smp->remote_pk, smp->local_pk, in smp_cmd_pairing_random()
2168 smp->rrnd, 0, cfm); in smp_cmd_pairing_random()
2172 if (crypto_memneq(smp->pcnf, cfm, 16)) in smp_cmd_pairing_random()
2175 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_cmd_pairing_random()
2176 smp->prnd); in smp_cmd_pairing_random()
2177 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in smp_cmd_pairing_random()
2180 if (smp->method != JUST_WORKS) in smp_cmd_pairing_random()
2200 err = sc_mackey_and_ltk(smp, smp->mackey, smp->tk); in smp_cmd_pairing_random()
2204 if (smp->method == REQ_OOB) { in smp_cmd_pairing_random()
2206 sc_dhkey_check(smp); in smp_cmd_pairing_random()
2207 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in smp_cmd_pairing_random()
2212 err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey); in smp_cmd_pairing_random()
2219 if (smp->method == JUST_WORKS) in smp_cmd_pairing_random()
2227 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in smp_cmd_pairing_random()
2285 struct smp_chan *smp; in smp_cmd_security_req() local
2321 smp = smp_chan_create(conn); in smp_cmd_security_req()
2322 if (!smp) in smp_cmd_security_req()
2334 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_cmd_security_req()
2335 memcpy(&smp->preq[1], &cp, sizeof(cp)); in smp_cmd_security_req()
2338 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RSP); in smp_cmd_security_req()
2347 struct smp_chan *smp; in smp_conn_security() local
2370 chan = conn->smp; in smp_conn_security()
2378 /* If SMP is already in progress ignore this request */ in smp_conn_security()
2384 smp = smp_chan_create(conn); in smp_conn_security()
2385 if (!smp) { in smp_conn_security()
2414 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_conn_security()
2415 memcpy(&smp->preq[1], &cp, sizeof(cp)); in smp_conn_security()
2418 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RSP); in smp_conn_security()
2423 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_REQ); in smp_conn_security()
2426 set_bit(SMP_FLAG_INITIATOR, &smp->flags); in smp_conn_security()
2440 struct smp_chan *smp; in smp_cancel_and_remove_pairing() local
2454 chan = conn->smp; in smp_cancel_and_remove_pairing()
2460 smp = chan->data; in smp_cancel_and_remove_pairing()
2461 if (smp) { in smp_cancel_and_remove_pairing()
2464 smp->ltk = NULL; in smp_cancel_and_remove_pairing()
2465 smp->slave_ltk = NULL; in smp_cancel_and_remove_pairing()
2466 smp->remote_irk = NULL; in smp_cancel_and_remove_pairing()
2468 if (test_bit(SMP_FLAG_COMPLETE, &smp->flags)) in smp_cancel_and_remove_pairing()
2484 struct l2cap_chan *chan = conn->smp; in smp_cmd_encrypt_info()
2485 struct smp_chan *smp = chan->data; in smp_cmd_encrypt_info() local
2501 SMP_ALLOW_CMD(smp, SMP_CMD_MASTER_IDENT); in smp_cmd_encrypt_info()
2505 memcpy(smp->tk, rp->ltk, sizeof(smp->tk)); in smp_cmd_encrypt_info()
2513 struct l2cap_chan *chan = conn->smp; in smp_cmd_master_ident()
2514 struct smp_chan *smp = chan->data; in smp_cmd_master_ident() local
2526 smp->remote_key_dist &= ~SMP_DIST_ENC_KEY; in smp_cmd_master_ident()
2528 if (smp->remote_key_dist & SMP_DIST_ID_KEY) in smp_cmd_master_ident()
2529 SMP_ALLOW_CMD(smp, SMP_CMD_IDENT_INFO); in smp_cmd_master_ident()
2530 else if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_cmd_master_ident()
2531 SMP_ALLOW_CMD(smp, SMP_CMD_SIGN_INFO); in smp_cmd_master_ident()
2537 authenticated, smp->tk, smp->enc_key_size, in smp_cmd_master_ident()
2539 smp->ltk = ltk; in smp_cmd_master_ident()
2540 if (!(smp->remote_key_dist & KEY_DIST_MASK)) in smp_cmd_master_ident()
2541 smp_distribute_keys(smp); in smp_cmd_master_ident()
2549 struct l2cap_chan *chan = conn->smp; in smp_cmd_ident_info()
2550 struct smp_chan *smp = chan->data; in smp_cmd_ident_info() local
2566 SMP_ALLOW_CMD(smp, SMP_CMD_IDENT_ADDR_INFO); in smp_cmd_ident_info()
2570 memcpy(smp->irk, info->irk, 16); in smp_cmd_ident_info()
2579 struct l2cap_chan *chan = conn->smp; in smp_cmd_ident_addr_info()
2580 struct smp_chan *smp = chan->data; in smp_cmd_ident_addr_info() local
2590 smp->remote_key_dist &= ~SMP_DIST_ID_KEY; in smp_cmd_ident_addr_info()
2592 if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_cmd_ident_addr_info()
2593 SMP_ALLOW_CMD(smp, SMP_CMD_SIGN_INFO); in smp_cmd_ident_addr_info()
2626 bacpy(&smp->id_addr, &info->bdaddr); in smp_cmd_ident_addr_info()
2627 smp->id_addr_type = info->addr_type; in smp_cmd_ident_addr_info()
2634 smp->remote_irk = hci_add_irk(conn->hcon->hdev, &smp->id_addr, in smp_cmd_ident_addr_info()
2635 smp->id_addr_type, smp->irk, &rpa); in smp_cmd_ident_addr_info()
2638 if (!(smp->remote_key_dist & KEY_DIST_MASK)) in smp_cmd_ident_addr_info()
2639 smp_distribute_keys(smp); in smp_cmd_ident_addr_info()
2647 struct l2cap_chan *chan = conn->smp; in smp_cmd_sign_info()
2648 struct smp_chan *smp = chan->data; in smp_cmd_sign_info() local
2657 smp->remote_key_dist &= ~SMP_DIST_SIGN; in smp_cmd_sign_info()
2669 smp->csrk = csrk; in smp_cmd_sign_info()
2670 smp_distribute_keys(smp); in smp_cmd_sign_info()
2675 static u8 sc_select_method(struct smp_chan *smp) in sc_select_method() argument
2677 struct l2cap_conn *conn = smp->conn; in sc_select_method()
2682 if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags) || in sc_select_method()
2683 test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) in sc_select_method()
2692 local = (void *) &smp->preq[1]; in sc_select_method()
2693 remote = (void *) &smp->prsp[1]; in sc_select_method()
2695 local = (void *) &smp->prsp[1]; in sc_select_method()
2696 remote = (void *) &smp->preq[1]; in sc_select_method()
2709 method = get_auth_method(smp, local_io, remote_io); in sc_select_method()
2714 if (method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, &smp->flags)) in sc_select_method()
2724 struct l2cap_chan *chan = conn->smp; in smp_cmd_public_key()
2725 struct smp_chan *smp = chan->data; in smp_cmd_public_key() local
2736 memcpy(smp->remote_pk, key, 64); in smp_cmd_public_key()
2738 if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags)) { in smp_cmd_public_key()
2739 err = smp_f4(smp->tfm_cmac, smp->remote_pk, smp->remote_pk, in smp_cmd_public_key()
2740 smp->rr, 0, cfm.confirm_val); in smp_cmd_public_key()
2744 if (crypto_memneq(cfm.confirm_val, smp->pcnf, 16)) in smp_cmd_public_key()
2752 err = sc_send_public_key(smp); in smp_cmd_public_key()
2757 SMP_DBG("Remote Public Key X: %32phN", smp->remote_pk); in smp_cmd_public_key()
2758 SMP_DBG("Remote Public Key Y: %32phN", smp->remote_pk + 32); in smp_cmd_public_key()
2763 if (test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) { in smp_cmd_public_key()
2774 tfm_ecdh = smp->tfm_ecdh; in smp_cmd_public_key()
2777 if (compute_ecdh_secret(tfm_ecdh, smp->remote_pk, smp->dhkey)) in smp_cmd_public_key()
2780 SMP_DBG("DHKey %32phN", smp->dhkey); in smp_cmd_public_key()
2782 set_bit(SMP_FLAG_REMOTE_PK, &smp->flags); in smp_cmd_public_key()
2784 smp->method = sc_select_method(smp); in smp_cmd_public_key()
2786 BT_DBG("%s selected method 0x%02x", hdev->name, smp->method); in smp_cmd_public_key()
2789 if (smp->method == JUST_WORKS || smp->method == JUST_CFM) in smp_cmd_public_key()
2794 if (!crypto_memneq(debug_pk, smp->remote_pk, 64)) in smp_cmd_public_key()
2795 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in smp_cmd_public_key()
2797 if (smp->method == DSP_PASSKEY) { in smp_cmd_public_key()
2802 smp->passkey_round = 0; in smp_cmd_public_key()
2808 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_public_key()
2809 return sc_passkey_round(smp, SMP_CMD_PUBLIC_KEY); in smp_cmd_public_key()
2812 if (smp->method == REQ_OOB) { in smp_cmd_public_key()
2815 sizeof(smp->prnd), smp->prnd); in smp_cmd_public_key()
2817 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_public_key()
2823 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_public_key()
2825 if (smp->method == REQ_PASSKEY) { in smp_cmd_public_key()
2829 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_public_key()
2830 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in smp_cmd_public_key()
2840 err = smp_f4(smp->tfm_cmac, smp->local_pk, smp->remote_pk, smp->prnd, in smp_cmd_public_key()
2846 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_public_key()
2854 struct l2cap_chan *chan = conn->smp; in smp_cmd_dhkey_check()
2856 struct smp_chan *smp = chan->data; in smp_cmd_dhkey_check() local
2874 memcpy(io_cap, &smp->prsp[1], 3); in smp_cmd_dhkey_check()
2878 memcpy(io_cap, &smp->preq[1], 3); in smp_cmd_dhkey_check()
2883 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in smp_cmd_dhkey_check()
2885 else if (smp->method == REQ_OOB) in smp_cmd_dhkey_check()
2886 memcpy(r, smp->lr, 16); in smp_cmd_dhkey_check()
2888 err = smp_f6(smp->tfm_cmac, smp->mackey, smp->rrnd, smp->prnd, r, in smp_cmd_dhkey_check()
2897 if (test_bit(SMP_FLAG_WAIT_USER, &smp->flags)) { in smp_cmd_dhkey_check()
2898 set_bit(SMP_FLAG_DHKEY_PENDING, &smp->flags); in smp_cmd_dhkey_check()
2903 sc_dhkey_check(smp); in smp_cmd_dhkey_check()
2906 sc_add_ltk(smp); in smp_cmd_dhkey_check()
2909 hci_le_start_enc(hcon, 0, 0, smp->tk, smp->enc_key_size); in smp_cmd_dhkey_check()
2910 hcon->enc_key_size = smp->enc_key_size; in smp_cmd_dhkey_check()
2930 struct smp_chan *smp; in smp_sig_channel() local
2945 smp = chan->data; in smp_sig_channel()
2950 if (smp && !test_and_clear_bit(code, &smp->allow_cmd)) in smp_sig_channel()
2956 if (!smp && code != SMP_CMD_PAIRING_REQ && code != SMP_CMD_SECURITY_REQ) in smp_sig_channel()
3033 bt_dev_err(hcon->hdev, "unexpected SMP command 0x%02x from %pMR", in smp_sig_channel()
3048 conn->smp = NULL; in smp_teardown_cb()
3058 struct smp_chan *smp; in bredr_pairing() local
3070 /* Only master may initiate SMP over BR/EDR */ in bredr_pairing()
3078 /* BR/EDR must use Secure Connections for SMP */ in bredr_pairing()
3091 /* Remote must support SMP fixed chan for BR/EDR */ in bredr_pairing()
3095 /* Don't bother if SMP is already ongoing */ in bredr_pairing()
3099 smp = smp_chan_create(conn); in bredr_pairing()
3100 if (!smp) { in bredr_pairing()
3101 bt_dev_err(hdev, "unable to create SMP context for BR/EDR"); in bredr_pairing()
3105 set_bit(SMP_FLAG_SC, &smp->flags); in bredr_pairing()
3107 BT_DBG("%s starting SMP over BR/EDR", hdev->name); in bredr_pairing()
3109 /* Prepare and send the BR/EDR SMP Pairing Request */ in bredr_pairing()
3110 build_bredr_pairing_cmd(smp, &req, NULL); in bredr_pairing()
3112 smp->preq[0] = SMP_CMD_PAIRING_REQ; in bredr_pairing()
3113 memcpy(&smp->preq[1], &req, sizeof(req)); in bredr_pairing()
3116 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RSP); in bredr_pairing()
3121 struct smp_chan *smp = chan->data; in smp_resume_cb() local
3132 if (!smp) in smp_resume_cb()
3138 cancel_delayed_work(&smp->security_timer); in smp_resume_cb()
3140 smp_distribute_keys(smp); in smp_resume_cb()
3156 conn->smp = chan; in smp_ready_cb()
3170 struct smp_chan *smp = chan->data; in smp_recv_cb() local
3172 if (smp) in smp_recv_cb()
3173 cancel_delayed_work_sync(&smp->security_timer); in smp_recv_cb()
3232 /* Other L2CAP channels may request SMP routines in order to in smp_new_conn_cb()
3233 * change the security level. This means that the SMP channel in smp_new_conn_cb()
3265 struct smp_dev *smp; in smp_add_cid() local
3270 smp = NULL; in smp_add_cid()
3274 smp = kzalloc(sizeof(*smp), GFP_KERNEL); in smp_add_cid()
3275 if (!smp) in smp_add_cid()
3281 kfree_sensitive(smp); in smp_add_cid()
3289 kfree_sensitive(smp); in smp_add_cid()
3293 smp->local_oob = false; in smp_add_cid()
3294 smp->tfm_cmac = tfm_cmac; in smp_add_cid()
3295 smp->tfm_ecdh = tfm_ecdh; in smp_add_cid()
3300 if (smp) { in smp_add_cid()
3301 crypto_free_shash(smp->tfm_cmac); in smp_add_cid()
3302 crypto_free_kpp(smp->tfm_ecdh); in smp_add_cid()
3303 kfree_sensitive(smp); in smp_add_cid()
3308 chan->data = smp; in smp_add_cid()
3341 struct smp_dev *smp; in smp_del_chan() local
3345 smp = chan->data; in smp_del_chan()
3346 if (smp) { in smp_del_chan()
3348 crypto_free_shash(smp->tfm_cmac); in smp_del_chan()
3349 crypto_free_kpp(smp->tfm_ecdh); in smp_del_chan()
3350 kfree_sensitive(smp); in smp_del_chan()
3419 * there is also no need to register any SMP channel. in smp_register()
3437 * feature, then the BR/EDR SMP channel shall not be present. in smp_register()
3440 * switch that allows forcing BR/EDR SMP support and accepting in smp_register()
3823 BT_INFO("SMP test passed in %llu usecs", duration); in run_selftests()