Lines Matching refs:smp
54 #define SMP_ALLOW_CMD(smp, code) set_bit(code, &smp->allow_cmd) argument
514 struct smp_dev *smp; in smp_irk_matches() local
521 smp = chan->data; in smp_irk_matches()
525 err = smp_ah(smp->tfm_aes, irk, &bdaddr->b[3], hash); in smp_irk_matches()
535 struct smp_dev *smp; in smp_generate_rpa() local
541 smp = chan->data; in smp_generate_rpa()
548 err = smp_ah(smp->tfm_aes, irk, &rpa->b[3], rpa->b); in smp_generate_rpa()
560 struct smp_dev *smp; in smp_generate_oob() local
566 smp = chan->data; in smp_generate_oob()
570 err = set_ecdh_privkey(smp->tfm_ecdh, debug_sk); in smp_generate_oob()
573 memcpy(smp->local_pk, debug_pk, 64); in smp_generate_oob()
574 smp->debug_key = true; in smp_generate_oob()
578 err = generate_ecdh_keys(smp->tfm_ecdh, smp->local_pk); in smp_generate_oob()
585 if (crypto_memneq(smp->local_pk, debug_pk, 64)) in smp_generate_oob()
588 smp->debug_key = false; in smp_generate_oob()
591 SMP_DBG("OOB Public Key X: %32phN", smp->local_pk); in smp_generate_oob()
592 SMP_DBG("OOB Public Key Y: %32phN", smp->local_pk + 32); in smp_generate_oob()
594 get_random_bytes(smp->local_rand, 16); in smp_generate_oob()
596 err = smp_f4(smp->tfm_cmac, smp->local_pk, smp->local_pk, in smp_generate_oob()
597 smp->local_rand, 0, hash); in smp_generate_oob()
601 memcpy(rand, smp->local_rand, 16); in smp_generate_oob()
603 smp->local_oob = true; in smp_generate_oob()
610 struct l2cap_chan *chan = conn->smp; in smp_send_cmd()
611 struct smp_chan *smp; in smp_send_cmd() local
635 smp = chan->data; in smp_send_cmd()
637 cancel_delayed_work_sync(&smp->security_timer); in smp_send_cmd()
638 schedule_delayed_work(&smp->security_timer, SMP_TIMEOUT); in smp_send_cmd()
670 struct l2cap_chan *chan = conn->smp; in build_pairing_cmd()
671 struct smp_chan *smp = chan->data; in build_pairing_cmd() local
708 set_bit(SMP_FLAG_REMOTE_OOB, &smp->flags); in build_pairing_cmd()
710 memcpy(smp->rr, oob_data->rand256, 16); in build_pairing_cmd()
711 memcpy(smp->pcnf, oob_data->hash256, 16); in build_pairing_cmd()
712 SMP_DBG("OOB Remote Confirmation: %16phN", smp->pcnf); in build_pairing_cmd()
713 SMP_DBG("OOB Remote Random: %16phN", smp->rr); in build_pairing_cmd()
728 smp->remote_key_dist = remote_dist; in build_pairing_cmd()
739 smp->remote_key_dist = rsp->init_key_dist; in build_pairing_cmd()
744 struct l2cap_chan *chan = conn->smp; in check_enc_key_size()
746 struct smp_chan *smp = chan->data; in check_enc_key_size() local
752 smp->enc_key_size = max_key_size; in check_enc_key_size()
759 struct l2cap_chan *chan = conn->smp; in smp_chan_destroy()
760 struct smp_chan *smp = chan->data; in smp_chan_destroy() local
764 BUG_ON(!smp); in smp_chan_destroy()
766 cancel_delayed_work_sync(&smp->security_timer); in smp_chan_destroy()
768 complete = test_bit(SMP_FLAG_COMPLETE, &smp->flags); in smp_chan_destroy()
771 kzfree(smp->csrk); in smp_chan_destroy()
772 kzfree(smp->slave_csrk); in smp_chan_destroy()
773 kzfree(smp->link_key); in smp_chan_destroy()
775 crypto_free_cipher(smp->tfm_aes); in smp_chan_destroy()
776 crypto_free_shash(smp->tfm_cmac); in smp_chan_destroy()
777 crypto_free_kpp(smp->tfm_ecdh); in smp_chan_destroy()
782 if (smp->ltk && smp->ltk->type == SMP_LTK_P256_DEBUG && in smp_chan_destroy()
784 list_del_rcu(&smp->ltk->list); in smp_chan_destroy()
785 kfree_rcu(smp->ltk, rcu); in smp_chan_destroy()
786 smp->ltk = NULL; in smp_chan_destroy()
791 if (smp->ltk) { in smp_chan_destroy()
792 list_del_rcu(&smp->ltk->list); in smp_chan_destroy()
793 kfree_rcu(smp->ltk, rcu); in smp_chan_destroy()
796 if (smp->slave_ltk) { in smp_chan_destroy()
797 list_del_rcu(&smp->slave_ltk->list); in smp_chan_destroy()
798 kfree_rcu(smp->slave_ltk, rcu); in smp_chan_destroy()
801 if (smp->remote_irk) { in smp_chan_destroy()
802 list_del_rcu(&smp->remote_irk->list); in smp_chan_destroy()
803 kfree_rcu(smp->remote_irk, rcu); in smp_chan_destroy()
808 kzfree(smp); in smp_chan_destroy()
815 struct l2cap_chan *chan = conn->smp; in smp_failure()
851 static u8 get_auth_method(struct smp_chan *smp, u8 local_io, u8 remote_io) in get_auth_method() argument
860 if (test_bit(SMP_FLAG_SC, &smp->flags)) in get_auth_method()
870 struct l2cap_chan *chan = conn->smp; in tk_request()
871 struct smp_chan *smp = chan->data; in tk_request() local
876 memset(smp->tk, 0, sizeof(smp->tk)); in tk_request()
877 clear_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
888 smp->method = JUST_CFM; in tk_request()
890 smp->method = get_auth_method(smp, local_io, remote_io); in tk_request()
893 if (smp->method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, in tk_request()
894 &smp->flags)) in tk_request()
895 smp->method = JUST_WORKS; in tk_request()
898 if (smp->method == JUST_CFM && in tk_request()
900 smp->method = JUST_WORKS; in tk_request()
903 if (smp->method == JUST_WORKS) { in tk_request()
904 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
911 if (test_bit(SMP_FLAG_SC, &smp->flags)) in tk_request()
915 if (smp->method != JUST_CFM) { in tk_request()
916 set_bit(SMP_FLAG_MITM_AUTH, &smp->flags); in tk_request()
924 if (smp->method == OVERLAP) { in tk_request()
926 smp->method = CFM_PASSKEY; in tk_request()
928 smp->method = REQ_PASSKEY; in tk_request()
932 if (smp->method == CFM_PASSKEY) { in tk_request()
933 memset(smp->tk, 0, sizeof(smp->tk)); in tk_request()
936 put_unaligned_le32(passkey, smp->tk); in tk_request()
938 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
941 if (smp->method == REQ_PASSKEY) in tk_request()
944 else if (smp->method == JUST_CFM) in tk_request()
956 static u8 smp_confirm(struct smp_chan *smp) in smp_confirm() argument
958 struct l2cap_conn *conn = smp->conn; in smp_confirm()
964 ret = smp_c1(smp->tfm_aes, smp->tk, smp->prnd, smp->preq, smp->prsp, in smp_confirm()
971 clear_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_confirm()
973 smp_send_cmd(smp->conn, SMP_CMD_PAIRING_CONFIRM, sizeof(cp), &cp); in smp_confirm()
976 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_confirm()
978 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_confirm()
983 static u8 smp_random(struct smp_chan *smp) in smp_random() argument
985 struct l2cap_conn *conn = smp->conn; in smp_random()
990 if (IS_ERR_OR_NULL(smp->tfm_aes)) in smp_random()
995 ret = smp_c1(smp->tfm_aes, smp->tk, smp->rrnd, smp->preq, smp->prsp, in smp_random()
1001 if (crypto_memneq(smp->pcnf, confirm, sizeof(smp->pcnf))) { in smp_random()
1012 smp_s1(smp->tfm_aes, smp->tk, smp->rrnd, smp->prnd, stk); in smp_random()
1017 hci_le_start_enc(hcon, ediv, rand, stk, smp->enc_key_size); in smp_random()
1018 hcon->enc_key_size = smp->enc_key_size; in smp_random()
1025 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_random()
1026 smp->prnd); in smp_random()
1028 smp_s1(smp->tfm_aes, smp->tk, smp->prnd, smp->rrnd, stk); in smp_random()
1040 SMP_STK, auth, stk, smp->enc_key_size, ediv, rand); in smp_random()
1048 struct l2cap_chan *chan = conn->smp; in smp_notify_keys()
1049 struct smp_chan *smp = chan->data; in smp_notify_keys() local
1052 struct smp_cmd_pairing *req = (void *) &smp->preq[1]; in smp_notify_keys()
1053 struct smp_cmd_pairing *rsp = (void *) &smp->prsp[1]; in smp_notify_keys()
1071 if (smp->remote_irk) { in smp_notify_keys()
1072 mgmt_new_irk(hdev, smp->remote_irk, persistent); in smp_notify_keys()
1079 bacpy(&hcon->dst, &smp->remote_irk->bdaddr); in smp_notify_keys()
1080 hcon->dst_type = smp->remote_irk->addr_type; in smp_notify_keys()
1085 if (smp->csrk) { in smp_notify_keys()
1086 smp->csrk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1087 bacpy(&smp->csrk->bdaddr, &hcon->dst); in smp_notify_keys()
1088 mgmt_new_csrk(hdev, smp->csrk, persistent); in smp_notify_keys()
1091 if (smp->slave_csrk) { in smp_notify_keys()
1092 smp->slave_csrk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1093 bacpy(&smp->slave_csrk->bdaddr, &hcon->dst); in smp_notify_keys()
1094 mgmt_new_csrk(hdev, smp->slave_csrk, persistent); in smp_notify_keys()
1097 if (smp->ltk) { in smp_notify_keys()
1098 smp->ltk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1099 bacpy(&smp->ltk->bdaddr, &hcon->dst); in smp_notify_keys()
1100 mgmt_new_ltk(hdev, smp->ltk, persistent); in smp_notify_keys()
1103 if (smp->slave_ltk) { in smp_notify_keys()
1104 smp->slave_ltk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1105 bacpy(&smp->slave_ltk->bdaddr, &hcon->dst); in smp_notify_keys()
1106 mgmt_new_ltk(hdev, smp->slave_ltk, persistent); in smp_notify_keys()
1109 if (smp->link_key) { in smp_notify_keys()
1113 if (test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags)) in smp_notify_keys()
1120 key = hci_add_link_key(hdev, smp->conn->hcon, &hcon->dst, in smp_notify_keys()
1121 smp->link_key, type, 0, &persistent); in smp_notify_keys()
1137 static void sc_add_ltk(struct smp_chan *smp) in sc_add_ltk() argument
1139 struct hci_conn *hcon = smp->conn->hcon; in sc_add_ltk()
1142 if (test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags)) in sc_add_ltk()
1152 smp->ltk = hci_add_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, in sc_add_ltk()
1153 key_type, auth, smp->tk, smp->enc_key_size, in sc_add_ltk()
1157 static void sc_generate_link_key(struct smp_chan *smp) in sc_generate_link_key() argument
1162 smp->link_key = kzalloc(16, GFP_KERNEL); in sc_generate_link_key()
1163 if (!smp->link_key) in sc_generate_link_key()
1166 if (test_bit(SMP_FLAG_CT2, &smp->flags)) { in sc_generate_link_key()
1170 if (smp_h7(smp->tfm_cmac, smp->tk, salt, smp->link_key)) { in sc_generate_link_key()
1171 kzfree(smp->link_key); in sc_generate_link_key()
1172 smp->link_key = NULL; in sc_generate_link_key()
1179 if (smp_h6(smp->tfm_cmac, smp->tk, tmp1, smp->link_key)) { in sc_generate_link_key()
1180 kzfree(smp->link_key); in sc_generate_link_key()
1181 smp->link_key = NULL; in sc_generate_link_key()
1186 if (smp_h6(smp->tfm_cmac, smp->link_key, lebr, smp->link_key)) { in sc_generate_link_key()
1187 kzfree(smp->link_key); in sc_generate_link_key()
1188 smp->link_key = NULL; in sc_generate_link_key()
1193 static void smp_allow_key_dist(struct smp_chan *smp) in smp_allow_key_dist() argument
1199 if (smp->remote_key_dist & SMP_DIST_ENC_KEY) in smp_allow_key_dist()
1200 SMP_ALLOW_CMD(smp, SMP_CMD_ENCRYPT_INFO); in smp_allow_key_dist()
1201 else if (smp->remote_key_dist & SMP_DIST_ID_KEY) in smp_allow_key_dist()
1202 SMP_ALLOW_CMD(smp, SMP_CMD_IDENT_INFO); in smp_allow_key_dist()
1203 else if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_allow_key_dist()
1204 SMP_ALLOW_CMD(smp, SMP_CMD_SIGN_INFO); in smp_allow_key_dist()
1207 static void sc_generate_ltk(struct smp_chan *smp) in sc_generate_ltk() argument
1211 struct hci_conn *hcon = smp->conn->hcon; in sc_generate_ltk()
1222 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_generate_ltk()
1224 if (test_bit(SMP_FLAG_CT2, &smp->flags)) { in sc_generate_ltk()
1228 if (smp_h7(smp->tfm_cmac, key->val, salt, smp->tk)) in sc_generate_ltk()
1234 if (smp_h6(smp->tfm_cmac, key->val, tmp2, smp->tk)) in sc_generate_ltk()
1238 if (smp_h6(smp->tfm_cmac, smp->tk, brle, smp->tk)) in sc_generate_ltk()
1241 sc_add_ltk(smp); in sc_generate_ltk()
1244 static void smp_distribute_keys(struct smp_chan *smp) in smp_distribute_keys() argument
1247 struct l2cap_conn *conn = smp->conn; in smp_distribute_keys()
1254 rsp = (void *) &smp->prsp[1]; in smp_distribute_keys()
1257 if (hcon->out && (smp->remote_key_dist & KEY_DIST_MASK)) { in smp_distribute_keys()
1258 smp_allow_key_dist(smp); in smp_distribute_keys()
1262 req = (void *) &smp->preq[1]; in smp_distribute_keys()
1272 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_distribute_keys()
1274 sc_generate_link_key(smp); in smp_distribute_keys()
1276 sc_generate_ltk(smp); in smp_distribute_keys()
1296 get_random_bytes(enc.ltk, smp->enc_key_size); in smp_distribute_keys()
1297 memset(enc.ltk + smp->enc_key_size, 0, in smp_distribute_keys()
1298 sizeof(enc.ltk) - smp->enc_key_size); in smp_distribute_keys()
1308 smp->enc_key_size, ediv, rand); in smp_distribute_keys()
1309 smp->slave_ltk = ltk; in smp_distribute_keys()
1357 smp->slave_csrk = csrk; in smp_distribute_keys()
1365 if (smp->remote_key_dist & KEY_DIST_MASK) { in smp_distribute_keys()
1366 smp_allow_key_dist(smp); in smp_distribute_keys()
1370 set_bit(SMP_FLAG_COMPLETE, &smp->flags); in smp_distribute_keys()
1378 struct smp_chan *smp = container_of(work, struct smp_chan, in smp_timeout() local
1380 struct l2cap_conn *conn = smp->conn; in smp_timeout()
1389 struct l2cap_chan *chan = conn->smp; in smp_chan_create()
1390 struct smp_chan *smp; in smp_chan_create() local
1392 smp = kzalloc(sizeof(*smp), GFP_ATOMIC); in smp_chan_create()
1393 if (!smp) in smp_chan_create()
1396 smp->tfm_aes = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC); in smp_chan_create()
1397 if (IS_ERR(smp->tfm_aes)) { in smp_chan_create()
1402 smp->tfm_cmac = crypto_alloc_shash("cmac(aes)", 0, 0); in smp_chan_create()
1403 if (IS_ERR(smp->tfm_cmac)) { in smp_chan_create()
1408 smp->tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0); in smp_chan_create()
1409 if (IS_ERR(smp->tfm_ecdh)) { in smp_chan_create()
1414 smp->conn = conn; in smp_chan_create()
1415 chan->data = smp; in smp_chan_create()
1417 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_FAIL); in smp_chan_create()
1419 INIT_DELAYED_WORK(&smp->security_timer, smp_timeout); in smp_chan_create()
1423 return smp; in smp_chan_create()
1426 crypto_free_shash(smp->tfm_cmac); in smp_chan_create()
1428 crypto_free_cipher(smp->tfm_aes); in smp_chan_create()
1430 kzfree(smp); in smp_chan_create()
1434 static int sc_mackey_and_ltk(struct smp_chan *smp, u8 mackey[16], u8 ltk[16]) in sc_mackey_and_ltk() argument
1436 struct hci_conn *hcon = smp->conn->hcon; in sc_mackey_and_ltk()
1440 na = smp->prnd; in sc_mackey_and_ltk()
1441 nb = smp->rrnd; in sc_mackey_and_ltk()
1443 na = smp->rrnd; in sc_mackey_and_ltk()
1444 nb = smp->prnd; in sc_mackey_and_ltk()
1452 return smp_f5(smp->tfm_cmac, smp->dhkey, na, nb, a, b, mackey, ltk); in sc_mackey_and_ltk()
1455 static void sc_dhkey_check(struct smp_chan *smp) in sc_dhkey_check() argument
1457 struct hci_conn *hcon = smp->conn->hcon; in sc_dhkey_check()
1470 memcpy(io_cap, &smp->preq[1], 3); in sc_dhkey_check()
1474 memcpy(io_cap, &smp->prsp[1], 3); in sc_dhkey_check()
1479 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in sc_dhkey_check()
1482 if (smp->method == REQ_OOB) in sc_dhkey_check()
1483 memcpy(r, smp->rr, 16); in sc_dhkey_check()
1485 smp_f6(smp->tfm_cmac, smp->mackey, smp->prnd, smp->rrnd, r, io_cap, in sc_dhkey_check()
1488 smp_send_cmd(smp->conn, SMP_CMD_DHKEY_CHECK, sizeof(check), &check); in sc_dhkey_check()
1491 static u8 sc_passkey_send_confirm(struct smp_chan *smp) in sc_passkey_send_confirm() argument
1493 struct l2cap_conn *conn = smp->conn; in sc_passkey_send_confirm()
1498 r = ((hcon->passkey_notify >> smp->passkey_round) & 0x01); in sc_passkey_send_confirm()
1501 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in sc_passkey_send_confirm()
1503 if (smp_f4(smp->tfm_cmac, smp->local_pk, smp->remote_pk, smp->prnd, r, in sc_passkey_send_confirm()
1512 static u8 sc_passkey_round(struct smp_chan *smp, u8 smp_op) in sc_passkey_round() argument
1514 struct l2cap_conn *conn = smp->conn; in sc_passkey_round()
1520 if (smp->passkey_round >= 20) in sc_passkey_round()
1525 r = ((hcon->passkey_notify >> smp->passkey_round) & 0x01); in sc_passkey_round()
1528 if (smp_f4(smp->tfm_cmac, smp->remote_pk, smp->local_pk, in sc_passkey_round()
1529 smp->rrnd, r, cfm)) in sc_passkey_round()
1532 if (crypto_memneq(smp->pcnf, cfm, 16)) in sc_passkey_round()
1535 smp->passkey_round++; in sc_passkey_round()
1537 if (smp->passkey_round == 20) { in sc_passkey_round()
1539 if (sc_mackey_and_ltk(smp, smp->mackey, smp->tk)) in sc_passkey_round()
1548 sizeof(smp->prnd), smp->prnd); in sc_passkey_round()
1549 if (smp->passkey_round == 20) in sc_passkey_round()
1550 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in sc_passkey_round()
1552 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in sc_passkey_round()
1557 if (smp->passkey_round != 20) in sc_passkey_round()
1558 return sc_passkey_round(smp, 0); in sc_passkey_round()
1561 sc_dhkey_check(smp); in sc_passkey_round()
1562 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in sc_passkey_round()
1567 if (test_bit(SMP_FLAG_WAIT_USER, &smp->flags)) { in sc_passkey_round()
1568 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in sc_passkey_round()
1572 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in sc_passkey_round()
1576 sizeof(smp->prnd), smp->prnd); in sc_passkey_round()
1580 return sc_passkey_send_confirm(smp); in sc_passkey_round()
1589 smp->passkey_round + 1); in sc_passkey_round()
1591 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in sc_passkey_round()
1593 return sc_passkey_send_confirm(smp); in sc_passkey_round()
1599 static int sc_user_reply(struct smp_chan *smp, u16 mgmt_op, __le32 passkey) in sc_user_reply() argument
1601 struct l2cap_conn *conn = smp->conn; in sc_user_reply()
1605 clear_bit(SMP_FLAG_WAIT_USER, &smp->flags); in sc_user_reply()
1609 smp_failure(smp->conn, SMP_PASSKEY_ENTRY_FAILED); in sc_user_reply()
1612 smp_failure(smp->conn, SMP_NUMERIC_COMP_FAILED); in sc_user_reply()
1616 smp->passkey_round = 0; in sc_user_reply()
1618 if (test_and_clear_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) in sc_user_reply()
1623 if (sc_passkey_round(smp, smp_op)) in sc_user_reply()
1631 sc_dhkey_check(smp); in sc_user_reply()
1632 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in sc_user_reply()
1633 } else if (test_and_clear_bit(SMP_FLAG_DHKEY_PENDING, &smp->flags)) { in sc_user_reply()
1634 sc_dhkey_check(smp); in sc_user_reply()
1635 sc_add_ltk(smp); in sc_user_reply()
1645 struct smp_chan *smp; in smp_user_confirm_reply() local
1654 chan = conn->smp; in smp_user_confirm_reply()
1664 smp = chan->data; in smp_user_confirm_reply()
1666 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_user_confirm_reply()
1667 err = sc_user_reply(smp, mgmt_op, passkey); in smp_user_confirm_reply()
1674 memset(smp->tk, 0, sizeof(smp->tk)); in smp_user_confirm_reply()
1676 put_unaligned_le32(value, smp->tk); in smp_user_confirm_reply()
1679 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in smp_user_confirm_reply()
1695 if (test_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) { in smp_user_confirm_reply()
1696 u8 rsp = smp_confirm(smp); in smp_user_confirm_reply()
1706 static void build_bredr_pairing_cmd(struct smp_chan *smp, in build_bredr_pairing_cmd() argument
1710 struct l2cap_conn *conn = smp->conn; in build_bredr_pairing_cmd()
1733 smp->remote_key_dist = remote_dist; in build_bredr_pairing_cmd()
1745 smp->remote_key_dist = rsp->init_key_dist; in build_bredr_pairing_cmd()
1751 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_req()
1753 struct smp_chan *smp; in smp_cmd_pairing_req() local
1766 smp = smp_chan_create(conn); in smp_cmd_pairing_req()
1768 smp = chan->data; in smp_cmd_pairing_req()
1770 if (!smp) in smp_cmd_pairing_req()
1783 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_cmd_pairing_req()
1784 memcpy(&smp->preq[1], req, sizeof(*req)); in smp_cmd_pairing_req()
1792 set_bit(SMP_FLAG_LOCAL_OOB, &smp->flags); in smp_cmd_pairing_req()
1801 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_req()
1803 build_bredr_pairing_cmd(smp, req, &rsp); in smp_cmd_pairing_req()
1806 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_req()
1813 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_req()
1815 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_req()
1816 memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); in smp_cmd_pairing_req()
1819 smp_distribute_keys(smp); in smp_cmd_pairing_req()
1826 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_req()
1829 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_req()
1844 method = get_auth_method(smp, conn->hcon->io_capability, in smp_cmd_pairing_req()
1854 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in smp_cmd_pairing_req()
1856 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_req()
1857 memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); in smp_cmd_pairing_req()
1861 clear_bit(SMP_FLAG_INITIATOR, &smp->flags); in smp_cmd_pairing_req()
1868 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_pairing_req()
1870 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_req()
1871 SMP_ALLOW_CMD(smp, SMP_CMD_PUBLIC_KEY); in smp_cmd_pairing_req()
1873 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_req()
1886 static u8 sc_send_public_key(struct smp_chan *smp) in sc_send_public_key() argument
1888 struct hci_dev *hdev = smp->conn->hcon->hdev; in sc_send_public_key()
1892 if (test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) { in sc_send_public_key()
1901 memcpy(smp->local_pk, smp_dev->local_pk, 64); in sc_send_public_key()
1902 memcpy(smp->lr, smp_dev->local_rand, 16); in sc_send_public_key()
1905 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_send_public_key()
1912 if (set_ecdh_privkey(smp->tfm_ecdh, debug_sk)) in sc_send_public_key()
1914 memcpy(smp->local_pk, debug_pk, 64); in sc_send_public_key()
1915 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_send_public_key()
1919 if (generate_ecdh_keys(smp->tfm_ecdh, smp->local_pk)) in sc_send_public_key()
1925 if (crypto_memneq(smp->local_pk, debug_pk, 64)) in sc_send_public_key()
1931 SMP_DBG("Local Public Key X: %32phN", smp->local_pk); in sc_send_public_key()
1932 SMP_DBG("Local Public Key Y: %32phN", smp->local_pk + 32); in sc_send_public_key()
1934 smp_send_cmd(smp->conn, SMP_CMD_PUBLIC_KEY, 64, smp->local_pk); in sc_send_public_key()
1942 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_rsp()
1943 struct smp_chan *smp = chan->data; in smp_cmd_pairing_rsp() local
1958 req = (void *) &smp->preq[1]; in smp_cmd_pairing_rsp()
1974 set_bit(SMP_FLAG_LOCAL_OOB, &smp->flags); in smp_cmd_pairing_rsp()
1976 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_rsp()
1977 memcpy(&smp->prsp[1], rsp, sizeof(*rsp)); in smp_cmd_pairing_rsp()
1982 smp->remote_key_dist &= rsp->resp_key_dist; in smp_cmd_pairing_rsp()
1985 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_rsp()
1990 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_rsp()
1991 smp_distribute_keys(smp); in smp_cmd_pairing_rsp()
1996 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_rsp()
2004 method = get_auth_method(smp, req->io_capability, in smp_cmd_pairing_rsp()
2010 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in smp_cmd_pairing_rsp()
2015 smp->remote_key_dist &= rsp->resp_key_dist; in smp_cmd_pairing_rsp()
2017 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_rsp()
2019 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_rsp()
2020 SMP_ALLOW_CMD(smp, SMP_CMD_PUBLIC_KEY); in smp_cmd_pairing_rsp()
2021 return sc_send_public_key(smp); in smp_cmd_pairing_rsp()
2030 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_cmd_pairing_rsp()
2033 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags)) in smp_cmd_pairing_rsp()
2034 return smp_confirm(smp); in smp_cmd_pairing_rsp()
2039 static u8 sc_check_confirm(struct smp_chan *smp) in sc_check_confirm() argument
2041 struct l2cap_conn *conn = smp->conn; in sc_check_confirm()
2045 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in sc_check_confirm()
2046 return sc_passkey_round(smp, SMP_CMD_PAIRING_CONFIRM); in sc_check_confirm()
2049 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in sc_check_confirm()
2050 smp->prnd); in sc_check_confirm()
2051 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in sc_check_confirm()
2061 static int fixup_sc_false_positive(struct smp_chan *smp) in fixup_sc_false_positive() argument
2063 struct l2cap_conn *conn = smp->conn; in fixup_sc_false_positive()
2080 req = (void *) &smp->preq[1]; in fixup_sc_false_positive()
2081 rsp = (void *) &smp->prsp[1]; in fixup_sc_false_positive()
2084 smp->remote_key_dist = (req->init_key_dist & rsp->resp_key_dist); in fixup_sc_false_positive()
2093 clear_bit(SMP_FLAG_SC, &smp->flags); in fixup_sc_false_positive()
2100 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_confirm()
2101 struct smp_chan *smp = chan->data; in smp_cmd_pairing_confirm() local
2105 if (skb->len < sizeof(smp->pcnf)) in smp_cmd_pairing_confirm()
2108 memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf)); in smp_cmd_pairing_confirm()
2109 skb_pull(skb, sizeof(smp->pcnf)); in smp_cmd_pairing_confirm()
2111 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_confirm()
2115 if (test_bit(SMP_FLAG_REMOTE_PK, &smp->flags)) in smp_cmd_pairing_confirm()
2116 return sc_check_confirm(smp); in smp_cmd_pairing_confirm()
2120 ret = fixup_sc_false_positive(smp); in smp_cmd_pairing_confirm()
2126 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_cmd_pairing_confirm()
2127 smp->prnd); in smp_cmd_pairing_confirm()
2128 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_pairing_confirm()
2132 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags)) in smp_cmd_pairing_confirm()
2133 return smp_confirm(smp); in smp_cmd_pairing_confirm()
2135 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_cmd_pairing_confirm()
2142 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_random()
2143 struct smp_chan *smp = chan->data; in smp_cmd_pairing_random() local
2151 if (skb->len < sizeof(smp->rrnd)) in smp_cmd_pairing_random()
2154 memcpy(smp->rrnd, skb->data, sizeof(smp->rrnd)); in smp_cmd_pairing_random()
2155 skb_pull(skb, sizeof(smp->rrnd)); in smp_cmd_pairing_random()
2157 if (!test_bit(SMP_FLAG_SC, &smp->flags)) in smp_cmd_pairing_random()
2158 return smp_random(smp); in smp_cmd_pairing_random()
2161 pkax = smp->local_pk; in smp_cmd_pairing_random()
2162 pkbx = smp->remote_pk; in smp_cmd_pairing_random()
2163 na = smp->prnd; in smp_cmd_pairing_random()
2164 nb = smp->rrnd; in smp_cmd_pairing_random()
2166 pkax = smp->remote_pk; in smp_cmd_pairing_random()
2167 pkbx = smp->local_pk; in smp_cmd_pairing_random()
2168 na = smp->rrnd; in smp_cmd_pairing_random()
2169 nb = smp->prnd; in smp_cmd_pairing_random()
2172 if (smp->method == REQ_OOB) { in smp_cmd_pairing_random()
2175 sizeof(smp->prnd), smp->prnd); in smp_cmd_pairing_random()
2176 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in smp_cmd_pairing_random()
2181 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in smp_cmd_pairing_random()
2182 return sc_passkey_round(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_pairing_random()
2187 err = smp_f4(smp->tfm_cmac, smp->remote_pk, smp->local_pk, in smp_cmd_pairing_random()
2188 smp->rrnd, 0, cfm); in smp_cmd_pairing_random()
2192 if (crypto_memneq(smp->pcnf, cfm, 16)) in smp_cmd_pairing_random()
2195 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_cmd_pairing_random()
2196 smp->prnd); in smp_cmd_pairing_random()
2197 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in smp_cmd_pairing_random()
2202 err = sc_mackey_and_ltk(smp, smp->mackey, smp->tk); in smp_cmd_pairing_random()
2206 if (smp->method == JUST_WORKS || smp->method == REQ_OOB) { in smp_cmd_pairing_random()
2208 sc_dhkey_check(smp); in smp_cmd_pairing_random()
2209 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); in smp_cmd_pairing_random()
2214 err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey); in smp_cmd_pairing_random()
2223 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in smp_cmd_pairing_random()
2281 struct smp_chan *smp; in smp_cmd_security_req() local
2317 smp = smp_chan_create(conn); in smp_cmd_security_req()
2318 if (!smp) in smp_cmd_security_req()
2330 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_cmd_security_req()
2331 memcpy(&smp->preq[1], &cp, sizeof(cp)); in smp_cmd_security_req()
2334 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RSP); in smp_cmd_security_req()
2343 struct smp_chan *smp; in smp_conn_security() local
2366 chan = conn->smp; in smp_conn_security()
2380 smp = smp_chan_create(conn); in smp_conn_security()
2381 if (!smp) { in smp_conn_security()
2405 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_conn_security()
2406 memcpy(&smp->preq[1], &cp, sizeof(cp)); in smp_conn_security()
2409 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RSP); in smp_conn_security()
2414 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_REQ); in smp_conn_security()
2417 set_bit(SMP_FLAG_INITIATOR, &smp->flags); in smp_conn_security()
2431 struct smp_chan *smp; in smp_cancel_and_remove_pairing() local
2445 chan = conn->smp; in smp_cancel_and_remove_pairing()
2451 smp = chan->data; in smp_cancel_and_remove_pairing()
2452 if (smp) { in smp_cancel_and_remove_pairing()
2455 smp->ltk = NULL; in smp_cancel_and_remove_pairing()
2456 smp->slave_ltk = NULL; in smp_cancel_and_remove_pairing()
2457 smp->remote_irk = NULL; in smp_cancel_and_remove_pairing()
2459 if (test_bit(SMP_FLAG_COMPLETE, &smp->flags)) in smp_cancel_and_remove_pairing()
2475 struct l2cap_chan *chan = conn->smp; in smp_cmd_encrypt_info()
2476 struct smp_chan *smp = chan->data; in smp_cmd_encrypt_info() local
2483 SMP_ALLOW_CMD(smp, SMP_CMD_MASTER_IDENT); in smp_cmd_encrypt_info()
2487 memcpy(smp->tk, rp->ltk, sizeof(smp->tk)); in smp_cmd_encrypt_info()
2495 struct l2cap_chan *chan = conn->smp; in smp_cmd_master_ident()
2496 struct smp_chan *smp = chan->data; in smp_cmd_master_ident() local
2508 smp->remote_key_dist &= ~SMP_DIST_ENC_KEY; in smp_cmd_master_ident()
2510 if (smp->remote_key_dist & SMP_DIST_ID_KEY) in smp_cmd_master_ident()
2511 SMP_ALLOW_CMD(smp, SMP_CMD_IDENT_INFO); in smp_cmd_master_ident()
2512 else if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_cmd_master_ident()
2513 SMP_ALLOW_CMD(smp, SMP_CMD_SIGN_INFO); in smp_cmd_master_ident()
2519 authenticated, smp->tk, smp->enc_key_size, in smp_cmd_master_ident()
2521 smp->ltk = ltk; in smp_cmd_master_ident()
2522 if (!(smp->remote_key_dist & KEY_DIST_MASK)) in smp_cmd_master_ident()
2523 smp_distribute_keys(smp); in smp_cmd_master_ident()
2531 struct l2cap_chan *chan = conn->smp; in smp_cmd_ident_info()
2532 struct smp_chan *smp = chan->data; in smp_cmd_ident_info() local
2539 SMP_ALLOW_CMD(smp, SMP_CMD_IDENT_ADDR_INFO); in smp_cmd_ident_info()
2543 memcpy(smp->irk, info->irk, 16); in smp_cmd_ident_info()
2552 struct l2cap_chan *chan = conn->smp; in smp_cmd_ident_addr_info()
2553 struct smp_chan *smp = chan->data; in smp_cmd_ident_addr_info() local
2563 smp->remote_key_dist &= ~SMP_DIST_ID_KEY; in smp_cmd_ident_addr_info()
2565 if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_cmd_ident_addr_info()
2566 SMP_ALLOW_CMD(smp, SMP_CMD_SIGN_INFO); in smp_cmd_ident_addr_info()
2586 bacpy(&smp->id_addr, &info->bdaddr); in smp_cmd_ident_addr_info()
2587 smp->id_addr_type = info->addr_type; in smp_cmd_ident_addr_info()
2594 smp->remote_irk = hci_add_irk(conn->hcon->hdev, &smp->id_addr, in smp_cmd_ident_addr_info()
2595 smp->id_addr_type, smp->irk, &rpa); in smp_cmd_ident_addr_info()
2598 if (!(smp->remote_key_dist & KEY_DIST_MASK)) in smp_cmd_ident_addr_info()
2599 smp_distribute_keys(smp); in smp_cmd_ident_addr_info()
2607 struct l2cap_chan *chan = conn->smp; in smp_cmd_sign_info()
2608 struct smp_chan *smp = chan->data; in smp_cmd_sign_info() local
2617 smp->remote_key_dist &= ~SMP_DIST_SIGN; in smp_cmd_sign_info()
2629 smp->csrk = csrk; in smp_cmd_sign_info()
2630 smp_distribute_keys(smp); in smp_cmd_sign_info()
2635 static u8 sc_select_method(struct smp_chan *smp) in sc_select_method() argument
2637 struct l2cap_conn *conn = smp->conn; in sc_select_method()
2642 if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags) || in sc_select_method()
2643 test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) in sc_select_method()
2652 local = (void *) &smp->preq[1]; in sc_select_method()
2653 remote = (void *) &smp->prsp[1]; in sc_select_method()
2655 local = (void *) &smp->prsp[1]; in sc_select_method()
2656 remote = (void *) &smp->preq[1]; in sc_select_method()
2669 method = get_auth_method(smp, local_io, remote_io); in sc_select_method()
2674 if (method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, &smp->flags)) in sc_select_method()
2684 struct l2cap_chan *chan = conn->smp; in smp_cmd_public_key()
2685 struct smp_chan *smp = chan->data; in smp_cmd_public_key() local
2696 memcpy(smp->remote_pk, key, 64); in smp_cmd_public_key()
2698 if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags)) { in smp_cmd_public_key()
2699 err = smp_f4(smp->tfm_cmac, smp->remote_pk, smp->remote_pk, in smp_cmd_public_key()
2700 smp->rr, 0, cfm.confirm_val); in smp_cmd_public_key()
2704 if (crypto_memneq(cfm.confirm_val, smp->pcnf, 16)) in smp_cmd_public_key()
2712 err = sc_send_public_key(smp); in smp_cmd_public_key()
2717 SMP_DBG("Remote Public Key X: %32phN", smp->remote_pk); in smp_cmd_public_key()
2718 SMP_DBG("Remote Public Key Y: %32phN", smp->remote_pk + 32); in smp_cmd_public_key()
2723 if (test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) { in smp_cmd_public_key()
2734 tfm_ecdh = smp->tfm_ecdh; in smp_cmd_public_key()
2737 if (compute_ecdh_secret(tfm_ecdh, smp->remote_pk, smp->dhkey)) in smp_cmd_public_key()
2740 SMP_DBG("DHKey %32phN", smp->dhkey); in smp_cmd_public_key()
2742 set_bit(SMP_FLAG_REMOTE_PK, &smp->flags); in smp_cmd_public_key()
2744 smp->method = sc_select_method(smp); in smp_cmd_public_key()
2746 BT_DBG("%s selected method 0x%02x", hdev->name, smp->method); in smp_cmd_public_key()
2749 if (smp->method == JUST_WORKS || smp->method == JUST_CFM) in smp_cmd_public_key()
2754 if (!crypto_memneq(debug_pk, smp->remote_pk, 64)) in smp_cmd_public_key()
2755 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in smp_cmd_public_key()
2757 if (smp->method == DSP_PASSKEY) { in smp_cmd_public_key()
2762 smp->passkey_round = 0; in smp_cmd_public_key()
2768 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_public_key()
2769 return sc_passkey_round(smp, SMP_CMD_PUBLIC_KEY); in smp_cmd_public_key()
2772 if (smp->method == REQ_OOB) { in smp_cmd_public_key()
2775 sizeof(smp->prnd), smp->prnd); in smp_cmd_public_key()
2777 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_public_key()
2783 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_public_key()
2785 if (smp->method == REQ_PASSKEY) { in smp_cmd_public_key()
2789 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_CONFIRM); in smp_cmd_public_key()
2790 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in smp_cmd_public_key()
2800 err = smp_f4(smp->tfm_cmac, smp->local_pk, smp->remote_pk, smp->prnd, in smp_cmd_public_key()
2806 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RANDOM); in smp_cmd_public_key()
2814 struct l2cap_chan *chan = conn->smp; in smp_cmd_dhkey_check()
2816 struct smp_chan *smp = chan->data; in smp_cmd_dhkey_check() local
2834 memcpy(io_cap, &smp->prsp[1], 3); in smp_cmd_dhkey_check()
2838 memcpy(io_cap, &smp->preq[1], 3); in smp_cmd_dhkey_check()
2843 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in smp_cmd_dhkey_check()
2845 else if (smp->method == REQ_OOB) in smp_cmd_dhkey_check()
2846 memcpy(r, smp->lr, 16); in smp_cmd_dhkey_check()
2848 err = smp_f6(smp->tfm_cmac, smp->mackey, smp->rrnd, smp->prnd, r, in smp_cmd_dhkey_check()
2857 if (test_bit(SMP_FLAG_WAIT_USER, &smp->flags)) { in smp_cmd_dhkey_check()
2858 set_bit(SMP_FLAG_DHKEY_PENDING, &smp->flags); in smp_cmd_dhkey_check()
2863 sc_dhkey_check(smp); in smp_cmd_dhkey_check()
2866 sc_add_ltk(smp); in smp_cmd_dhkey_check()
2869 hci_le_start_enc(hcon, 0, 0, smp->tk, smp->enc_key_size); in smp_cmd_dhkey_check()
2870 hcon->enc_key_size = smp->enc_key_size; in smp_cmd_dhkey_check()
2890 struct smp_chan *smp; in smp_sig_channel() local
2905 smp = chan->data; in smp_sig_channel()
2910 if (smp && !test_and_clear_bit(code, &smp->allow_cmd)) in smp_sig_channel()
2916 if (!smp && code != SMP_CMD_PAIRING_REQ && code != SMP_CMD_SECURITY_REQ) in smp_sig_channel()
3008 conn->smp = NULL; in smp_teardown_cb()
3018 struct smp_chan *smp; in bredr_pairing() local
3059 smp = smp_chan_create(conn); in bredr_pairing()
3060 if (!smp) { in bredr_pairing()
3065 set_bit(SMP_FLAG_SC, &smp->flags); in bredr_pairing()
3070 build_bredr_pairing_cmd(smp, &req, NULL); in bredr_pairing()
3072 smp->preq[0] = SMP_CMD_PAIRING_REQ; in bredr_pairing()
3073 memcpy(&smp->preq[1], &req, sizeof(req)); in bredr_pairing()
3076 SMP_ALLOW_CMD(smp, SMP_CMD_PAIRING_RSP); in bredr_pairing()
3081 struct smp_chan *smp = chan->data; in smp_resume_cb() local
3092 if (!smp) in smp_resume_cb()
3098 cancel_delayed_work(&smp->security_timer); in smp_resume_cb()
3100 smp_distribute_keys(smp); in smp_resume_cb()
3116 conn->smp = chan; in smp_ready_cb()
3130 struct smp_chan *smp = chan->data; in smp_recv_cb() local
3132 if (smp) in smp_recv_cb()
3133 cancel_delayed_work_sync(&smp->security_timer); in smp_recv_cb()
3225 struct smp_dev *smp; in smp_add_cid() local
3231 smp = NULL; in smp_add_cid()
3235 smp = kzalloc(sizeof(*smp), GFP_KERNEL); in smp_add_cid()
3236 if (!smp) in smp_add_cid()
3242 kzfree(smp); in smp_add_cid()
3250 kzfree(smp); in smp_add_cid()
3259 kzfree(smp); in smp_add_cid()
3263 smp->local_oob = false; in smp_add_cid()
3264 smp->tfm_aes = tfm_aes; in smp_add_cid()
3265 smp->tfm_cmac = tfm_cmac; in smp_add_cid()
3266 smp->tfm_ecdh = tfm_ecdh; in smp_add_cid()
3267 smp->min_key_size = SMP_MIN_ENC_KEY_SIZE; in smp_add_cid()
3268 smp->max_key_size = SMP_MAX_ENC_KEY_SIZE; in smp_add_cid()
3273 if (smp) { in smp_add_cid()
3274 crypto_free_cipher(smp->tfm_aes); in smp_add_cid()
3275 crypto_free_shash(smp->tfm_cmac); in smp_add_cid()
3276 crypto_free_kpp(smp->tfm_ecdh); in smp_add_cid()
3277 kzfree(smp); in smp_add_cid()
3282 chan->data = smp; in smp_add_cid()
3315 struct smp_dev *smp; in smp_del_chan() local
3319 smp = chan->data; in smp_del_chan()
3320 if (smp) { in smp_del_chan()
3322 crypto_free_cipher(smp->tfm_aes); in smp_del_chan()
3323 crypto_free_shash(smp->tfm_cmac); in smp_del_chan()
3324 crypto_free_kpp(smp->tfm_ecdh); in smp_del_chan()
3325 kzfree(smp); in smp_del_chan()