Lines Matching +full:y +full:- +full:rp

2    BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
40 ((struct smp_dev *)((struct l2cap_chan *)((hdev)->smp_data))->data)
42 /* Low-level debug macros to be used for stuff that we don't want
54 #define SMP_ALLOW_CMD(smp, code) set_bit(code, &smp->allow_cmd)
161 dst[len - 1 - i] = src[i]; in swap_buf()
165 * AES-CMAC, f4, f5, f6, g2 and h6.
175 return -EFBIG; in aes_cmac()
179 return -EINVAL; in aes_cmac()
313 const u8 x[16], const u8 y[16], u32 *val) in smp_g2()
320 SMP_DBG("x %16phN y %16phN", x, y); in smp_g2()
322 memcpy(m, y, 16); in smp_g2()
499 struct l2cap_chan *chan = hdev->smp_data; in smp_irk_matches()
503 if (!chan || !chan->data) in smp_irk_matches()
508 err = smp_ah(irk, &bdaddr->b[3], hash); in smp_irk_matches()
512 return !crypto_memneq(bdaddr->b, hash, 3); in smp_irk_matches()
517 struct l2cap_chan *chan = hdev->smp_data; in smp_generate_rpa()
520 if (!chan || !chan->data) in smp_generate_rpa()
521 return -EOPNOTSUPP; in smp_generate_rpa()
523 get_random_bytes(&rpa->b[3], 3); in smp_generate_rpa()
525 rpa->b[5] &= 0x3f; /* Clear two most significant bits */ in smp_generate_rpa()
526 rpa->b[5] |= 0x40; /* Set second most significant bit */ in smp_generate_rpa()
528 err = smp_ah(irk, &rpa->b[3], rpa->b); in smp_generate_rpa()
539 struct l2cap_chan *chan = hdev->smp_data; in smp_generate_oob()
543 if (!chan || !chan->data) in smp_generate_oob()
544 return -EOPNOTSUPP; in smp_generate_oob()
546 smp = chan->data; in smp_generate_oob()
550 err = set_ecdh_privkey(smp->tfm_ecdh, debug_sk); in smp_generate_oob()
553 memcpy(smp->local_pk, debug_pk, 64); in smp_generate_oob()
554 smp->debug_key = true; in smp_generate_oob()
558 err = generate_ecdh_keys(smp->tfm_ecdh, smp->local_pk); in smp_generate_oob()
565 if (crypto_memneq(smp->local_pk, debug_pk, 64)) in smp_generate_oob()
568 smp->debug_key = false; in smp_generate_oob()
571 SMP_DBG("OOB Public Key X: %32phN", smp->local_pk); in smp_generate_oob()
572 SMP_DBG("OOB Public Key Y: %32phN", smp->local_pk + 32); in smp_generate_oob()
574 get_random_bytes(smp->local_rand, 16); in smp_generate_oob()
576 err = smp_f4(smp->tfm_cmac, smp->local_pk, smp->local_pk, in smp_generate_oob()
577 smp->local_rand, 0, hash); in smp_generate_oob()
581 memcpy(rand, smp->local_rand, 16); in smp_generate_oob()
583 smp->local_oob = true; in smp_generate_oob()
590 struct l2cap_chan *chan = conn->smp; in smp_send_cmd()
598 bt_dev_dbg(conn->hcon->hdev, "code 0x%2.2x", code); in smp_send_cmd()
612 if (!chan->data) in smp_send_cmd()
615 smp = chan->data; in smp_send_cmd()
617 cancel_delayed_work_sync(&smp->security_timer); in smp_send_cmd()
618 schedule_delayed_work(&smp->security_timer, SMP_TIMEOUT); in smp_send_cmd()
650 struct l2cap_chan *chan = conn->smp; in build_pairing_cmd()
651 struct smp_chan *smp = chan->data; in build_pairing_cmd()
652 struct hci_conn *hcon = conn->hcon; in build_pairing_cmd()
653 struct hci_dev *hdev = hcon->hdev; in build_pairing_cmd()
680 if (hcon->dst_type == ADDR_LE_DEV_PUBLIC) in build_pairing_cmd()
685 oob_data = hci_find_remote_oob_data(hdev, &hcon->dst, in build_pairing_cmd()
687 if (oob_data && oob_data->present) { in build_pairing_cmd()
688 set_bit(SMP_FLAG_REMOTE_OOB, &smp->flags); in build_pairing_cmd()
690 memcpy(smp->rr, oob_data->rand256, 16); in build_pairing_cmd()
691 memcpy(smp->pcnf, oob_data->hash256, 16); in build_pairing_cmd()
692 SMP_DBG("OOB Remote Confirmation: %16phN", smp->pcnf); in build_pairing_cmd()
693 SMP_DBG("OOB Remote Random: %16phN", smp->rr); in build_pairing_cmd()
701 req->io_capability = conn->hcon->io_capability; in build_pairing_cmd()
702 req->oob_flag = oob_flag; in build_pairing_cmd()
703 req->max_key_size = hdev->le_max_key_size; in build_pairing_cmd()
704 req->init_key_dist = local_dist; in build_pairing_cmd()
705 req->resp_key_dist = remote_dist; in build_pairing_cmd()
706 req->auth_req = (authreq & AUTH_REQ_MASK(hdev)); in build_pairing_cmd()
708 smp->remote_key_dist = remote_dist; in build_pairing_cmd()
712 rsp->io_capability = conn->hcon->io_capability; in build_pairing_cmd()
713 rsp->oob_flag = oob_flag; in build_pairing_cmd()
714 rsp->max_key_size = hdev->le_max_key_size; in build_pairing_cmd()
715 rsp->init_key_dist = req->init_key_dist & remote_dist; in build_pairing_cmd()
716 rsp->resp_key_dist = req->resp_key_dist & local_dist; in build_pairing_cmd()
717 rsp->auth_req = (authreq & AUTH_REQ_MASK(hdev)); in build_pairing_cmd()
719 smp->remote_key_dist = rsp->init_key_dist; in build_pairing_cmd()
724 struct l2cap_chan *chan = conn->smp; in check_enc_key_size()
725 struct hci_dev *hdev = conn->hcon->hdev; in check_enc_key_size()
726 struct smp_chan *smp = chan->data; in check_enc_key_size()
728 if (conn->hcon->pending_sec_level == BT_SECURITY_FIPS && in check_enc_key_size()
732 if (max_key_size > hdev->le_max_key_size || in check_enc_key_size()
736 smp->enc_key_size = max_key_size; in check_enc_key_size()
743 struct l2cap_chan *chan = conn->smp; in smp_chan_destroy()
744 struct smp_chan *smp = chan->data; in smp_chan_destroy()
745 struct hci_conn *hcon = conn->hcon; in smp_chan_destroy()
750 cancel_delayed_work_sync(&smp->security_timer); in smp_chan_destroy()
752 complete = test_bit(SMP_FLAG_COMPLETE, &smp->flags); in smp_chan_destroy()
755 kfree_sensitive(smp->csrk); in smp_chan_destroy()
756 kfree_sensitive(smp->responder_csrk); in smp_chan_destroy()
757 kfree_sensitive(smp->link_key); in smp_chan_destroy()
759 crypto_free_shash(smp->tfm_cmac); in smp_chan_destroy()
760 crypto_free_kpp(smp->tfm_ecdh); in smp_chan_destroy()
765 if (smp->ltk && smp->ltk->type == SMP_LTK_P256_DEBUG && in smp_chan_destroy()
766 !hci_dev_test_flag(hcon->hdev, HCI_KEEP_DEBUG_KEYS)) { in smp_chan_destroy()
767 list_del_rcu(&smp->ltk->list); in smp_chan_destroy()
768 kfree_rcu(smp->ltk, rcu); in smp_chan_destroy()
769 smp->ltk = NULL; in smp_chan_destroy()
774 if (smp->ltk) { in smp_chan_destroy()
775 list_del_rcu(&smp->ltk->list); in smp_chan_destroy()
776 kfree_rcu(smp->ltk, rcu); in smp_chan_destroy()
779 if (smp->responder_ltk) { in smp_chan_destroy()
780 list_del_rcu(&smp->responder_ltk->list); in smp_chan_destroy()
781 kfree_rcu(smp->responder_ltk, rcu); in smp_chan_destroy()
784 if (smp->remote_irk) { in smp_chan_destroy()
785 list_del_rcu(&smp->remote_irk->list); in smp_chan_destroy()
786 kfree_rcu(smp->remote_irk, rcu); in smp_chan_destroy()
790 chan->data = NULL; in smp_chan_destroy()
797 struct hci_conn *hcon = conn->hcon; in smp_failure()
798 struct l2cap_chan *chan = conn->smp; in smp_failure()
806 if (chan->data) in smp_failure()
843 if (test_bit(SMP_FLAG_SC, &smp->flags)) in get_auth_method()
852 struct hci_conn *hcon = conn->hcon; in tk_request()
853 struct l2cap_chan *chan = conn->smp; in tk_request()
854 struct smp_chan *smp = chan->data; in tk_request()
859 memset(smp->tk, 0, sizeof(smp->tk)); in tk_request()
860 clear_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
862 bt_dev_dbg(hcon->hdev, "auth:%u lcl:%u rem:%u", auth, local_io, in tk_request()
866 * request or use just-works for outgoing ones. The JUST_CFM 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()
883 hcon->io_capability == HCI_IO_NO_INPUT_OUTPUT) in tk_request()
884 smp->method = JUST_WORKS; in tk_request()
886 /* If Just Works, Continue with Zero TK and ask user-space for in tk_request()
888 if (smp->method == JUST_WORKS) { in tk_request()
889 ret = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, in tk_request()
890 hcon->type, in tk_request()
891 hcon->dst_type, in tk_request()
895 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in tk_request()
899 /* If this function is used for SC -> legacy fallback we in tk_request()
900 * can only recover the just-works case. in tk_request()
902 if (test_bit(SMP_FLAG_SC, &smp->flags)) in tk_request()
903 return -EINVAL; in tk_request()
906 if (smp->method != JUST_CFM) { in tk_request()
907 set_bit(SMP_FLAG_MITM_AUTH, &smp->flags); in tk_request()
908 if (hcon->pending_sec_level < BT_SECURITY_HIGH) in tk_request()
909 hcon->pending_sec_level = BT_SECURITY_HIGH; in tk_request()
912 /* If both devices have Keyboard-Display I/O, the initiator in tk_request()
915 if (smp->method == OVERLAP) { in tk_request()
916 if (hcon->role == HCI_ROLE_MASTER) 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()
928 bt_dev_dbg(hcon->hdev, "PassKey: %u", passkey); in tk_request()
929 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in tk_request()
932 if (smp->method == REQ_PASSKEY) in tk_request()
933 ret = mgmt_user_passkey_request(hcon->hdev, &hcon->dst, in tk_request()
934 hcon->type, hcon->dst_type); in tk_request()
935 else if (smp->method == JUST_CFM) in tk_request()
936 ret = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, in tk_request()
937 hcon->type, hcon->dst_type, in tk_request()
940 ret = mgmt_user_passkey_notify(hcon->hdev, &hcon->dst, in tk_request()
941 hcon->type, hcon->dst_type, in tk_request()
949 struct l2cap_conn *conn = smp->conn; in smp_confirm()
953 bt_dev_dbg(conn->hcon->hdev, "conn %p", conn); in smp_confirm()
955 ret = smp_c1(smp->tk, smp->prnd, smp->preq, smp->prsp, in smp_confirm()
956 conn->hcon->init_addr_type, &conn->hcon->init_addr, in smp_confirm()
957 conn->hcon->resp_addr_type, &conn->hcon->resp_addr, 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()
966 if (conn->hcon->out) in smp_confirm()
976 struct l2cap_conn *conn = smp->conn; in smp_random()
977 struct hci_conn *hcon = conn->hcon; in smp_random()
981 bt_dev_dbg(conn->hcon->hdev, "conn %p %s", conn, in smp_random()
982 conn->hcon->out ? "initiator" : "responder"); in smp_random()
984 ret = smp_c1(smp->tk, smp->rrnd, smp->preq, smp->prsp, in smp_random()
985 hcon->init_addr_type, &hcon->init_addr, in smp_random()
986 hcon->resp_addr_type, &hcon->resp_addr, confirm); in smp_random()
990 if (crypto_memneq(smp->pcnf, confirm, sizeof(smp->pcnf))) { in smp_random()
991 bt_dev_err(hcon->hdev, "pairing failed " in smp_random()
996 if (hcon->out) { in smp_random()
1001 smp_s1(smp->tk, smp->rrnd, smp->prnd, stk); in smp_random()
1003 if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) in smp_random()
1006 hci_le_start_enc(hcon, ediv, rand, stk, smp->enc_key_size); in smp_random()
1007 hcon->enc_key_size = smp->enc_key_size; in smp_random()
1008 set_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags); in smp_random()
1014 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_random()
1015 smp->prnd); in smp_random()
1017 smp_s1(smp->tk, smp->prnd, smp->rrnd, stk); in smp_random()
1019 if (hcon->pending_sec_level == BT_SECURITY_HIGH) in smp_random()
1028 hci_add_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, in smp_random()
1029 SMP_STK, auth, stk, smp->enc_key_size, ediv, rand); in smp_random()
1037 struct l2cap_chan *chan = conn->smp; in smp_notify_keys()
1038 struct smp_chan *smp = chan->data; in smp_notify_keys()
1039 struct hci_conn *hcon = conn->hcon; in smp_notify_keys()
1040 struct hci_dev *hdev = hcon->hdev; in smp_notify_keys()
1041 struct smp_cmd_pairing *req = (void *) &smp->preq[1]; in smp_notify_keys()
1042 struct smp_cmd_pairing *rsp = (void *) &smp->prsp[1]; in smp_notify_keys()
1045 if (hcon->type == ACL_LINK) { in smp_notify_keys()
1046 if (hcon->key_type == HCI_LK_DEBUG_COMBINATION) in smp_notify_keys()
1050 &hcon->flags); in smp_notify_keys()
1056 persistent = !!((req->auth_req & rsp->auth_req) & in smp_notify_keys()
1060 if (smp->remote_irk) { in smp_notify_keys()
1061 mgmt_new_irk(hdev, smp->remote_irk, persistent); in smp_notify_keys()
1067 if (hcon->type == LE_LINK) { in smp_notify_keys()
1068 bacpy(&hcon->dst, &smp->remote_irk->bdaddr); in smp_notify_keys()
1069 hcon->dst_type = smp->remote_irk->addr_type; in smp_notify_keys()
1070 queue_work(hdev->workqueue, &conn->id_addr_update_work); in smp_notify_keys()
1074 if (smp->csrk) { in smp_notify_keys()
1075 smp->csrk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1076 bacpy(&smp->csrk->bdaddr, &hcon->dst); in smp_notify_keys()
1077 mgmt_new_csrk(hdev, smp->csrk, persistent); in smp_notify_keys()
1080 if (smp->responder_csrk) { in smp_notify_keys()
1081 smp->responder_csrk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1082 bacpy(&smp->responder_csrk->bdaddr, &hcon->dst); in smp_notify_keys()
1083 mgmt_new_csrk(hdev, smp->responder_csrk, persistent); in smp_notify_keys()
1086 if (smp->ltk) { in smp_notify_keys()
1087 smp->ltk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1088 bacpy(&smp->ltk->bdaddr, &hcon->dst); in smp_notify_keys()
1089 mgmt_new_ltk(hdev, smp->ltk, persistent); in smp_notify_keys()
1092 if (smp->responder_ltk) { in smp_notify_keys()
1093 smp->responder_ltk->bdaddr_type = hcon->dst_type; in smp_notify_keys()
1094 bacpy(&smp->responder_ltk->bdaddr, &hcon->dst); in smp_notify_keys()
1095 mgmt_new_ltk(hdev, smp->responder_ltk, persistent); in smp_notify_keys()
1098 if (smp->link_key) { in smp_notify_keys()
1102 if (test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags)) in smp_notify_keys()
1104 else if (hcon->sec_level == BT_SECURITY_FIPS) in smp_notify_keys()
1109 key = hci_add_link_key(hdev, smp->conn->hcon, &hcon->dst, in smp_notify_keys()
1110 smp->link_key, type, 0, &persistent); in smp_notify_keys()
1118 key->type == HCI_LK_DEBUG_COMBINATION) { in smp_notify_keys()
1119 list_del_rcu(&key->list); in smp_notify_keys()
1128 struct hci_conn *hcon = smp->conn->hcon; in sc_add_ltk()
1131 if (test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags)) in sc_add_ltk()
1136 if (hcon->pending_sec_level == BT_SECURITY_FIPS) in sc_add_ltk()
1141 smp->ltk = hci_add_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, in sc_add_ltk()
1142 key_type, auth, smp->tk, smp->enc_key_size, in sc_add_ltk()
1151 smp->link_key = kzalloc(16, GFP_KERNEL); in sc_generate_link_key()
1152 if (!smp->link_key) in sc_generate_link_key()
1155 if (test_bit(SMP_FLAG_CT2, &smp->flags)) { in sc_generate_link_key()
1159 if (smp_h7(smp->tfm_cmac, smp->tk, salt, smp->link_key)) { in sc_generate_link_key()
1160 kfree_sensitive(smp->link_key); in sc_generate_link_key()
1161 smp->link_key = NULL; in sc_generate_link_key()
1168 if (smp_h6(smp->tfm_cmac, smp->tk, tmp1, smp->link_key)) { in sc_generate_link_key()
1169 kfree_sensitive(smp->link_key); in sc_generate_link_key()
1170 smp->link_key = NULL; in sc_generate_link_key()
1175 if (smp_h6(smp->tfm_cmac, smp->link_key, lebr, smp->link_key)) { in sc_generate_link_key()
1176 kfree_sensitive(smp->link_key); in sc_generate_link_key()
1177 smp->link_key = NULL; in sc_generate_link_key()
1188 if (smp->remote_key_dist & SMP_DIST_ENC_KEY) in smp_allow_key_dist()
1190 else if (smp->remote_key_dist & SMP_DIST_ID_KEY) in smp_allow_key_dist()
1192 else if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_allow_key_dist()
1200 struct hci_conn *hcon = smp->conn->hcon; in sc_generate_ltk()
1201 struct hci_dev *hdev = hcon->hdev; in sc_generate_ltk()
1204 key = hci_find_link_key(hdev, &hcon->dst); in sc_generate_ltk()
1210 if (key->type == HCI_LK_DEBUG_COMBINATION) in sc_generate_ltk()
1211 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_generate_ltk()
1213 if (test_bit(SMP_FLAG_CT2, &smp->flags)) { in sc_generate_ltk()
1217 if (smp_h7(smp->tfm_cmac, key->val, salt, smp->tk)) in sc_generate_ltk()
1223 if (smp_h6(smp->tfm_cmac, key->val, tmp2, smp->tk)) in sc_generate_ltk()
1227 if (smp_h6(smp->tfm_cmac, smp->tk, brle, smp->tk)) in sc_generate_ltk()
1236 struct l2cap_conn *conn = smp->conn; in smp_distribute_keys()
1237 struct hci_conn *hcon = conn->hcon; in smp_distribute_keys()
1238 struct hci_dev *hdev = hcon->hdev; in smp_distribute_keys()
1243 rsp = (void *) &smp->prsp[1]; in smp_distribute_keys()
1246 if (hcon->out && (smp->remote_key_dist & KEY_DIST_MASK)) { in smp_distribute_keys()
1251 req = (void *) &smp->preq[1]; in smp_distribute_keys()
1253 if (hcon->out) { in smp_distribute_keys()
1254 keydist = &rsp->init_key_dist; in smp_distribute_keys()
1255 *keydist &= req->init_key_dist; in smp_distribute_keys()
1257 keydist = &rsp->resp_key_dist; in smp_distribute_keys()
1258 *keydist &= req->resp_key_dist; in smp_distribute_keys()
1261 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_distribute_keys()
1262 if (hcon->type == LE_LINK && (*keydist & SMP_DIST_LINK_KEY)) in smp_distribute_keys()
1264 if (hcon->type == ACL_LINK && (*keydist & SMP_DIST_ENC_KEY)) in smp_distribute_keys()
1285 get_random_bytes(enc.ltk, smp->enc_key_size); in smp_distribute_keys()
1286 memset(enc.ltk + smp->enc_key_size, 0, in smp_distribute_keys()
1287 sizeof(enc.ltk) - smp->enc_key_size); in smp_distribute_keys()
1294 authenticated = hcon->sec_level == BT_SECURITY_HIGH; in smp_distribute_keys()
1295 ltk = hci_add_ltk(hdev, &hcon->dst, hcon->dst_type, in smp_distribute_keys()
1297 smp->enc_key_size, ediv, rand); in smp_distribute_keys()
1298 smp->responder_ltk = ltk; in smp_distribute_keys()
1313 memcpy(idinfo.irk, hdev->irk, sizeof(idinfo.irk)); in smp_distribute_keys()
1323 bacpy(&addrinfo.bdaddr, &hcon->src); in smp_distribute_keys()
1324 addrinfo.addr_type = hcon->src_type; in smp_distribute_keys()
1341 if (hcon->sec_level > BT_SECURITY_MEDIUM) in smp_distribute_keys()
1342 csrk->type = MGMT_CSRK_LOCAL_AUTHENTICATED; in smp_distribute_keys()
1344 csrk->type = MGMT_CSRK_LOCAL_UNAUTHENTICATED; in smp_distribute_keys()
1345 memcpy(csrk->val, sign.csrk, sizeof(csrk->val)); in smp_distribute_keys()
1347 smp->responder_csrk = csrk; in smp_distribute_keys()
1355 if (smp->remote_key_dist & KEY_DIST_MASK) { in smp_distribute_keys()
1360 set_bit(SMP_FLAG_COMPLETE, &smp->flags); in smp_distribute_keys()
1370 struct l2cap_conn *conn = smp->conn; in smp_timeout()
1372 bt_dev_dbg(conn->hcon->hdev, "conn %p", conn); in smp_timeout()
1374 hci_disconnect(conn->hcon, HCI_ERROR_REMOTE_USER_TERM); in smp_timeout()
1379 struct hci_conn *hcon = conn->hcon; in smp_chan_create()
1380 struct l2cap_chan *chan = conn->smp; in smp_chan_create()
1387 smp->tfm_cmac = crypto_alloc_shash("cmac(aes)", 0, 0); in smp_chan_create()
1388 if (IS_ERR(smp->tfm_cmac)) { in smp_chan_create()
1389 bt_dev_err(hcon->hdev, "Unable to create CMAC crypto context"); in smp_chan_create()
1393 smp->tfm_ecdh = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); in smp_chan_create()
1394 if (IS_ERR(smp->tfm_ecdh)) { in smp_chan_create()
1395 bt_dev_err(hcon->hdev, "Unable to create ECDH crypto context"); in smp_chan_create()
1399 smp->conn = conn; in smp_chan_create()
1400 chan->data = smp; in smp_chan_create()
1404 INIT_DELAYED_WORK(&smp->security_timer, smp_timeout); in smp_chan_create()
1411 crypto_free_shash(smp->tfm_cmac); in smp_chan_create()
1419 struct hci_conn *hcon = smp->conn->hcon; in sc_mackey_and_ltk()
1422 if (hcon->out) { in sc_mackey_and_ltk()
1423 na = smp->prnd; in sc_mackey_and_ltk()
1424 nb = smp->rrnd; in sc_mackey_and_ltk()
1426 na = smp->rrnd; in sc_mackey_and_ltk()
1427 nb = smp->prnd; in sc_mackey_and_ltk()
1430 memcpy(a, &hcon->init_addr, 6); in sc_mackey_and_ltk()
1431 memcpy(b, &hcon->resp_addr, 6); in sc_mackey_and_ltk()
1432 a[6] = hcon->init_addr_type; in sc_mackey_and_ltk()
1433 b[6] = hcon->resp_addr_type; in sc_mackey_and_ltk()
1435 return smp_f5(smp->tfm_cmac, smp->dhkey, na, nb, a, b, mackey, ltk); in sc_mackey_and_ltk()
1440 struct hci_conn *hcon = smp->conn->hcon; in sc_dhkey_check()
1445 memcpy(a, &hcon->init_addr, 6); in sc_dhkey_check()
1446 memcpy(b, &hcon->resp_addr, 6); in sc_dhkey_check()
1447 a[6] = hcon->init_addr_type; in sc_dhkey_check()
1448 b[6] = hcon->resp_addr_type; in sc_dhkey_check()
1450 if (hcon->out) { in sc_dhkey_check()
1453 memcpy(io_cap, &smp->preq[1], 3); in sc_dhkey_check()
1457 memcpy(io_cap, &smp->prsp[1], 3); in sc_dhkey_check()
1462 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in sc_dhkey_check()
1463 put_unaligned_le32(hcon->passkey_notify, r); in sc_dhkey_check()
1465 if (smp->method == REQ_OOB) in sc_dhkey_check()
1466 memcpy(r, smp->rr, 16); in sc_dhkey_check()
1468 smp_f6(smp->tfm_cmac, smp->mackey, smp->prnd, smp->rrnd, r, io_cap, in sc_dhkey_check()
1471 smp_send_cmd(smp->conn, SMP_CMD_DHKEY_CHECK, sizeof(check), &check); in sc_dhkey_check()
1476 struct l2cap_conn *conn = smp->conn; in sc_passkey_send_confirm()
1477 struct hci_conn *hcon = conn->hcon; in sc_passkey_send_confirm()
1481 r = ((hcon->passkey_notify >> smp->passkey_round) & 0x01); in sc_passkey_send_confirm()
1484 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in sc_passkey_send_confirm()
1486 if (smp_f4(smp->tfm_cmac, smp->local_pk, smp->remote_pk, smp->prnd, r, in sc_passkey_send_confirm()
1497 struct l2cap_conn *conn = smp->conn; in sc_passkey_round()
1498 struct hci_conn *hcon = conn->hcon; in sc_passkey_round()
1499 struct hci_dev *hdev = hcon->hdev; in sc_passkey_round()
1502 /* Ignore the PDU if we've already done 20 rounds (0 - 19) */ in sc_passkey_round()
1503 if (smp->passkey_round >= 20) in sc_passkey_round()
1508 r = ((hcon->passkey_notify >> smp->passkey_round) & 0x01); in sc_passkey_round()
1511 if (smp_f4(smp->tfm_cmac, smp->remote_pk, smp->local_pk, in sc_passkey_round()
1512 smp->rrnd, r, cfm)) in sc_passkey_round()
1515 if (crypto_memneq(smp->pcnf, cfm, 16)) in sc_passkey_round()
1518 smp->passkey_round++; in sc_passkey_round()
1520 if (smp->passkey_round == 20) { in sc_passkey_round()
1522 if (sc_mackey_and_ltk(smp, smp->mackey, smp->tk)) in sc_passkey_round()
1529 if (!hcon->out) { in sc_passkey_round()
1531 sizeof(smp->prnd), smp->prnd); in sc_passkey_round()
1532 if (smp->passkey_round == 20) in sc_passkey_round()
1540 if (smp->passkey_round != 20) in sc_passkey_round()
1543 /* Passkey rounds are complete - start DHKey Check */ in sc_passkey_round()
1550 if (test_bit(SMP_FLAG_WAIT_USER, &smp->flags)) { in sc_passkey_round()
1551 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in sc_passkey_round()
1557 if (hcon->out) { in sc_passkey_round()
1559 sizeof(smp->prnd), smp->prnd); in sc_passkey_round()
1568 if (!hcon->out) in sc_passkey_round()
1572 smp->passkey_round + 1); in sc_passkey_round()
1584 struct l2cap_conn *conn = smp->conn; in sc_user_reply()
1585 struct hci_conn *hcon = conn->hcon; in sc_user_reply()
1588 clear_bit(SMP_FLAG_WAIT_USER, &smp->flags); in sc_user_reply()
1592 smp_failure(smp->conn, SMP_PASSKEY_ENTRY_FAILED); in sc_user_reply()
1595 smp_failure(smp->conn, SMP_NUMERIC_COMP_FAILED); in sc_user_reply()
1598 hcon->passkey_notify = le32_to_cpu(passkey); in sc_user_reply()
1599 smp->passkey_round = 0; in sc_user_reply()
1601 if (test_and_clear_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) in sc_user_reply()
1607 return -EIO; in sc_user_reply()
1613 if (hcon->out) { in sc_user_reply()
1616 } else if (test_and_clear_bit(SMP_FLAG_DHKEY_PENDING, &smp->flags)) { in sc_user_reply()
1626 struct l2cap_conn *conn = hcon->l2cap_data; in smp_user_confirm_reply()
1633 return -ENOTCONN; in smp_user_confirm_reply()
1635 bt_dev_dbg(conn->hcon->hdev, ""); in smp_user_confirm_reply()
1637 chan = conn->smp; in smp_user_confirm_reply()
1639 return -ENOTCONN; in smp_user_confirm_reply()
1642 if (!chan->data) { in smp_user_confirm_reply()
1643 err = -ENOTCONN; in smp_user_confirm_reply()
1647 smp = chan->data; in smp_user_confirm_reply()
1649 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_user_confirm_reply()
1657 memset(smp->tk, 0, sizeof(smp->tk)); in smp_user_confirm_reply()
1658 bt_dev_dbg(conn->hcon->hdev, "PassKey: %u", value); in smp_user_confirm_reply()
1659 put_unaligned_le32(value, smp->tk); in smp_user_confirm_reply()
1662 set_bit(SMP_FLAG_TK_VALID, &smp->flags); in smp_user_confirm_reply()
1671 err = -EOPNOTSUPP; in smp_user_confirm_reply()
1678 if (test_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) { in smp_user_confirm_reply()
1693 struct l2cap_conn *conn = smp->conn; in build_bredr_pairing_cmd()
1694 struct hci_dev *hdev = conn->hcon->hdev; in build_bredr_pairing_cmd()
1711 req->auth_req = SMP_AUTH_CT2; in build_bredr_pairing_cmd()
1712 req->init_key_dist = local_dist; in build_bredr_pairing_cmd()
1713 req->resp_key_dist = remote_dist; in build_bredr_pairing_cmd()
1714 req->max_key_size = conn->hcon->enc_key_size; in build_bredr_pairing_cmd()
1716 smp->remote_key_dist = remote_dist; in build_bredr_pairing_cmd()
1723 rsp->auth_req = SMP_AUTH_CT2; in build_bredr_pairing_cmd()
1724 rsp->max_key_size = conn->hcon->enc_key_size; in build_bredr_pairing_cmd()
1725 rsp->init_key_dist = req->init_key_dist & remote_dist; in build_bredr_pairing_cmd()
1726 rsp->resp_key_dist = req->resp_key_dist & local_dist; in build_bredr_pairing_cmd()
1728 smp->remote_key_dist = rsp->init_key_dist; in build_bredr_pairing_cmd()
1733 struct smp_cmd_pairing rsp, *req = (void *) skb->data; in smp_cmd_pairing_req()
1734 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_req()
1735 struct hci_dev *hdev = conn->hcon->hdev; in smp_cmd_pairing_req()
1742 if (skb->len < sizeof(*req)) in smp_cmd_pairing_req()
1745 if (conn->hcon->role != HCI_ROLE_SLAVE) in smp_cmd_pairing_req()
1748 if (!chan->data) in smp_cmd_pairing_req()
1751 smp = chan->data; in smp_cmd_pairing_req()
1757 auth = req->auth_req & AUTH_REQ_MASK(hdev); in smp_cmd_pairing_req()
1766 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_cmd_pairing_req()
1767 memcpy(&smp->preq[1], req, sizeof(*req)); in smp_cmd_pairing_req()
1771 * successfully received our local OOB data - therefore set the in smp_cmd_pairing_req()
1774 if (req->oob_flag == SMP_OOB_PRESENT && SMP_DEV(hdev)->local_oob) in smp_cmd_pairing_req()
1775 set_bit(SMP_FLAG_LOCAL_OOB, &smp->flags); in smp_cmd_pairing_req()
1778 if (conn->hcon->type == ACL_LINK) { in smp_cmd_pairing_req()
1780 if (!test_bit(HCI_CONN_AES_CCM, &conn->hcon->flags) && in smp_cmd_pairing_req()
1784 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_req()
1788 if (req->auth_req & SMP_AUTH_CT2) in smp_cmd_pairing_req()
1789 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_req()
1791 key_size = min(req->max_key_size, rsp.max_key_size); in smp_cmd_pairing_req()
1796 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_req()
1798 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_req()
1799 memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); in smp_cmd_pairing_req()
1809 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_req()
1812 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_req()
1815 if (conn->hcon->io_capability == HCI_IO_NO_INPUT_OUTPUT) in smp_cmd_pairing_req()
1820 if (sec_level > conn->hcon->pending_sec_level) in smp_cmd_pairing_req()
1821 conn->hcon->pending_sec_level = sec_level; in smp_cmd_pairing_req()
1824 if (conn->hcon->pending_sec_level >= BT_SECURITY_HIGH) { in smp_cmd_pairing_req()
1827 method = get_auth_method(smp, conn->hcon->io_capability, in smp_cmd_pairing_req()
1828 req->io_capability); in smp_cmd_pairing_req()
1833 key_size = min(req->max_key_size, rsp.max_key_size); in smp_cmd_pairing_req()
1837 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in smp_cmd_pairing_req()
1839 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_req()
1840 memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); in smp_cmd_pairing_req()
1844 clear_bit(SMP_FLAG_INITIATOR, &smp->flags); in smp_cmd_pairing_req()
1853 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_req()
1856 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_req()
1862 ret = tk_request(conn, 0, auth, rsp.io_capability, req->io_capability); in smp_cmd_pairing_req()
1871 struct hci_dev *hdev = smp->conn->hcon->hdev; in sc_send_public_key()
1875 if (test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) { in sc_send_public_key()
1876 struct l2cap_chan *chan = hdev->smp_data; in sc_send_public_key()
1879 if (!chan || !chan->data) in sc_send_public_key()
1882 smp_dev = chan->data; in sc_send_public_key()
1884 memcpy(smp->local_pk, smp_dev->local_pk, 64); in sc_send_public_key()
1885 memcpy(smp->lr, smp_dev->local_rand, 16); in sc_send_public_key()
1887 if (smp_dev->debug_key) in sc_send_public_key()
1888 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_send_public_key()
1895 if (set_ecdh_privkey(smp->tfm_ecdh, debug_sk)) in sc_send_public_key()
1897 memcpy(smp->local_pk, debug_pk, 64); in sc_send_public_key()
1898 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in sc_send_public_key()
1902 if (generate_ecdh_keys(smp->tfm_ecdh, smp->local_pk)) in sc_send_public_key()
1908 if (crypto_memneq(smp->local_pk, debug_pk, 64)) in sc_send_public_key()
1914 SMP_DBG("Local Public Key X: %32phN", smp->local_pk); in sc_send_public_key()
1915 SMP_DBG("Local Public Key Y: %32phN", smp->local_pk + 32); in sc_send_public_key()
1917 smp_send_cmd(smp->conn, SMP_CMD_PUBLIC_KEY, 64, smp->local_pk); in sc_send_public_key()
1924 struct smp_cmd_pairing *req, *rsp = (void *) skb->data; in smp_cmd_pairing_rsp()
1925 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_rsp()
1926 struct smp_chan *smp = chan->data; in smp_cmd_pairing_rsp()
1927 struct hci_dev *hdev = conn->hcon->hdev; in smp_cmd_pairing_rsp()
1933 if (skb->len < sizeof(*rsp)) in smp_cmd_pairing_rsp()
1936 if (conn->hcon->role != HCI_ROLE_MASTER) in smp_cmd_pairing_rsp()
1941 req = (void *) &smp->preq[1]; in smp_cmd_pairing_rsp()
1943 key_size = min(req->max_key_size, rsp->max_key_size); in smp_cmd_pairing_rsp()
1947 auth = rsp->auth_req & AUTH_REQ_MASK(hdev); in smp_cmd_pairing_rsp()
1953 * successfully received our local OOB data - therefore set the in smp_cmd_pairing_rsp()
1956 if (rsp->oob_flag == SMP_OOB_PRESENT && SMP_DEV(hdev)->local_oob) in smp_cmd_pairing_rsp()
1957 set_bit(SMP_FLAG_LOCAL_OOB, &smp->flags); in smp_cmd_pairing_rsp()
1959 smp->prsp[0] = SMP_CMD_PAIRING_RSP; in smp_cmd_pairing_rsp()
1960 memcpy(&smp->prsp[1], rsp, sizeof(*rsp)); in smp_cmd_pairing_rsp()
1965 smp->remote_key_dist &= rsp->resp_key_dist; in smp_cmd_pairing_rsp()
1967 if ((req->auth_req & SMP_AUTH_CT2) && (auth & SMP_AUTH_CT2)) in smp_cmd_pairing_rsp()
1968 set_bit(SMP_FLAG_CT2, &smp->flags); in smp_cmd_pairing_rsp()
1971 if (conn->hcon->type == ACL_LINK) { in smp_cmd_pairing_rsp()
1973 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_rsp()
1978 if ((req->auth_req & SMP_AUTH_SC) && (auth & SMP_AUTH_SC)) in smp_cmd_pairing_rsp()
1979 set_bit(SMP_FLAG_SC, &smp->flags); in smp_cmd_pairing_rsp()
1980 else if (conn->hcon->pending_sec_level > BT_SECURITY_HIGH) in smp_cmd_pairing_rsp()
1981 conn->hcon->pending_sec_level = BT_SECURITY_HIGH; in smp_cmd_pairing_rsp()
1984 if (conn->hcon->pending_sec_level >= BT_SECURITY_HIGH) { in smp_cmd_pairing_rsp()
1987 method = get_auth_method(smp, req->io_capability, in smp_cmd_pairing_rsp()
1988 rsp->io_capability); in smp_cmd_pairing_rsp()
1993 get_random_bytes(smp->prnd, sizeof(smp->prnd)); in smp_cmd_pairing_rsp()
1998 smp->remote_key_dist &= rsp->resp_key_dist; in smp_cmd_pairing_rsp()
2000 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_rsp()
2002 smp->remote_key_dist &= ~SMP_SC_NO_DIST; in smp_cmd_pairing_rsp()
2007 auth |= req->auth_req; in smp_cmd_pairing_rsp()
2009 ret = tk_request(conn, 0, auth, req->io_capability, rsp->io_capability); in smp_cmd_pairing_rsp()
2013 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_cmd_pairing_rsp()
2016 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags)) in smp_cmd_pairing_rsp()
2024 struct l2cap_conn *conn = smp->conn; in sc_check_confirm()
2026 bt_dev_dbg(conn->hcon->hdev, ""); in sc_check_confirm()
2028 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in sc_check_confirm()
2031 if (conn->hcon->out) { in sc_check_confirm()
2032 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in sc_check_confirm()
2033 smp->prnd); in sc_check_confirm()
2040 /* Work-around for some implementations that incorrectly copy RFU bits
2046 struct l2cap_conn *conn = smp->conn; in fixup_sc_false_positive()
2047 struct hci_conn *hcon = conn->hcon; in fixup_sc_false_positive()
2048 struct hci_dev *hdev = hcon->hdev; in fixup_sc_false_positive()
2053 if (hcon->out) in fixup_sc_false_positive()
2057 bt_dev_err(hdev, "refusing legacy fallback in SC-only mode"); in fixup_sc_false_positive()
2063 req = (void *) &smp->preq[1]; in fixup_sc_false_positive()
2064 rsp = (void *) &smp->prsp[1]; in fixup_sc_false_positive()
2067 smp->remote_key_dist = (req->init_key_dist & rsp->resp_key_dist); in fixup_sc_false_positive()
2069 auth = req->auth_req & AUTH_REQ_MASK(hdev); in fixup_sc_false_positive()
2071 if (tk_request(conn, 0, auth, rsp->io_capability, req->io_capability)) { in fixup_sc_false_positive()
2076 clear_bit(SMP_FLAG_SC, &smp->flags); in fixup_sc_false_positive()
2083 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_confirm()
2084 struct smp_chan *smp = chan->data; in smp_cmd_pairing_confirm()
2085 struct hci_conn *hcon = conn->hcon; in smp_cmd_pairing_confirm()
2086 struct hci_dev *hdev = hcon->hdev; in smp_cmd_pairing_confirm()
2089 hcon->out ? "initiator" : "responder"); in smp_cmd_pairing_confirm()
2091 if (skb->len < sizeof(smp->pcnf)) in smp_cmd_pairing_confirm()
2094 memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf)); in smp_cmd_pairing_confirm()
2095 skb_pull(skb, sizeof(smp->pcnf)); in smp_cmd_pairing_confirm()
2097 if (test_bit(SMP_FLAG_SC, &smp->flags)) { in smp_cmd_pairing_confirm()
2101 if (test_bit(SMP_FLAG_REMOTE_PK, &smp->flags)) in smp_cmd_pairing_confirm()
2111 if (conn->hcon->out) { in smp_cmd_pairing_confirm()
2112 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_cmd_pairing_confirm()
2113 smp->prnd); in smp_cmd_pairing_confirm()
2118 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags)) in smp_cmd_pairing_confirm()
2121 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags); in smp_cmd_pairing_confirm()
2128 struct l2cap_chan *chan = conn->smp; in smp_cmd_pairing_random()
2129 struct smp_chan *smp = chan->data; in smp_cmd_pairing_random()
2130 struct hci_conn *hcon = conn->hcon; in smp_cmd_pairing_random()
2135 bt_dev_dbg(hcon->hdev, "conn %p", conn); in smp_cmd_pairing_random()
2137 if (skb->len < sizeof(smp->rrnd)) in smp_cmd_pairing_random()
2140 memcpy(smp->rrnd, skb->data, sizeof(smp->rrnd)); in smp_cmd_pairing_random()
2141 skb_pull(skb, sizeof(smp->rrnd)); in smp_cmd_pairing_random()
2143 if (!test_bit(SMP_FLAG_SC, &smp->flags)) in smp_cmd_pairing_random()
2146 if (hcon->out) { in smp_cmd_pairing_random()
2147 pkax = smp->local_pk; in smp_cmd_pairing_random()
2148 pkbx = smp->remote_pk; in smp_cmd_pairing_random()
2149 na = smp->prnd; in smp_cmd_pairing_random()
2150 nb = smp->rrnd; in smp_cmd_pairing_random()
2152 pkax = smp->remote_pk; in smp_cmd_pairing_random()
2153 pkbx = smp->local_pk; in smp_cmd_pairing_random()
2154 na = smp->rrnd; in smp_cmd_pairing_random()
2155 nb = smp->prnd; in smp_cmd_pairing_random()
2158 if (smp->method == REQ_OOB) { in smp_cmd_pairing_random()
2159 if (!hcon->out) in smp_cmd_pairing_random()
2161 sizeof(smp->prnd), smp->prnd); in smp_cmd_pairing_random()
2167 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in smp_cmd_pairing_random()
2170 if (hcon->out) { in smp_cmd_pairing_random()
2173 err = smp_f4(smp->tfm_cmac, smp->remote_pk, smp->local_pk, in smp_cmd_pairing_random()
2174 smp->rrnd, 0, cfm); in smp_cmd_pairing_random()
2178 if (crypto_memneq(smp->pcnf, cfm, 16)) in smp_cmd_pairing_random()
2181 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), in smp_cmd_pairing_random()
2182 smp->prnd); in smp_cmd_pairing_random()
2185 /* Only Just-Works pairing requires extra checks */ in smp_cmd_pairing_random()
2186 if (smp->method != JUST_WORKS) in smp_cmd_pairing_random()
2193 if (hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, in smp_cmd_pairing_random()
2194 hcon->role)) { in smp_cmd_pairing_random()
2206 err = sc_mackey_and_ltk(smp, smp->mackey, smp->tk); in smp_cmd_pairing_random()
2210 if (smp->method == REQ_OOB) { in smp_cmd_pairing_random()
2211 if (hcon->out) { in smp_cmd_pairing_random()
2218 err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey); in smp_cmd_pairing_random()
2225 if (smp->method == JUST_WORKS) in smp_cmd_pairing_random()
2228 err = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, hcon->type, in smp_cmd_pairing_random()
2229 hcon->dst_type, passkey, confirm_hint); in smp_cmd_pairing_random()
2233 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in smp_cmd_pairing_random()
2241 struct hci_conn *hcon = conn->hcon; in smp_ltk_encrypt()
2243 key = hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, hcon->role); in smp_ltk_encrypt()
2250 if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) in smp_ltk_encrypt()
2253 hci_le_start_enc(hcon, key->ediv, key->rand, key->val, key->enc_size); in smp_ltk_encrypt()
2254 hcon->enc_key_size = key->enc_size; in smp_ltk_encrypt()
2257 clear_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags); in smp_ltk_encrypt()
2270 * connection to be re-encrypted with an LTK, even if the LTK in smp_sufficient_security()
2275 test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags) && in smp_sufficient_security()
2276 hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, hcon->role)) in smp_sufficient_security()
2279 if (hcon->sec_level >= sec_level) in smp_sufficient_security()
2287 struct smp_cmd_security_req *rp = (void *) skb->data; in smp_cmd_security_req() local
2289 struct hci_conn *hcon = conn->hcon; in smp_cmd_security_req()
2290 struct hci_dev *hdev = hcon->hdev; in smp_cmd_security_req()
2296 if (skb->len < sizeof(*rp)) in smp_cmd_security_req()
2299 if (hcon->role != HCI_ROLE_MASTER) in smp_cmd_security_req()
2302 auth = rp->auth_req & AUTH_REQ_MASK(hdev); in smp_cmd_security_req()
2307 if (hcon->io_capability == HCI_IO_NO_INPUT_OUTPUT) in smp_cmd_security_req()
2317 smp_ltk_encrypt(conn, hcon->sec_level); in smp_cmd_security_req()
2321 if (sec_level > hcon->pending_sec_level) in smp_cmd_security_req()
2322 hcon->pending_sec_level = sec_level; in smp_cmd_security_req()
2324 if (smp_ltk_encrypt(conn, hcon->pending_sec_level)) in smp_cmd_security_req()
2335 skb_pull(skb, sizeof(*rp)); in smp_cmd_security_req()
2340 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_cmd_security_req()
2341 memcpy(&smp->preq[1], &cp, sizeof(cp)); in smp_cmd_security_req()
2351 struct l2cap_conn *conn = hcon->l2cap_data; in smp_conn_security()
2357 bt_dev_dbg(hcon->hdev, "conn %p hcon %p level 0x%2.2x", conn, hcon, in smp_conn_security()
2364 if (!hci_dev_test_flag(hcon->hdev, HCI_LE_ENABLED)) in smp_conn_security()
2370 if (sec_level > hcon->pending_sec_level) in smp_conn_security()
2371 hcon->pending_sec_level = sec_level; in smp_conn_security()
2373 if (hcon->role == HCI_ROLE_MASTER) in smp_conn_security()
2374 if (smp_ltk_encrypt(conn, hcon->pending_sec_level)) in smp_conn_security()
2377 chan = conn->smp; in smp_conn_security()
2379 bt_dev_err(hcon->hdev, "security requested but not available"); in smp_conn_security()
2386 if (chan->data) { in smp_conn_security()
2399 if (hci_dev_test_flag(hcon->hdev, HCI_SC_ENABLED)) { in smp_conn_security()
2401 if (hci_dev_test_flag(hcon->hdev, HCI_SSP_ENABLED)) in smp_conn_security()
2406 * Needed to pass certification test SM/MAS/PKE/BV-01-C in smp_conn_security()
2408 if (!hci_dev_test_flag(hcon->hdev, HCI_FORCE_NO_MITM)) { in smp_conn_security()
2412 if (hcon->io_capability != HCI_IO_NO_INPUT_OUTPUT || in smp_conn_security()
2413 hcon->pending_sec_level > BT_SECURITY_MEDIUM) in smp_conn_security()
2417 if (hcon->role == HCI_ROLE_MASTER) { in smp_conn_security()
2421 smp->preq[0] = SMP_CMD_PAIRING_REQ; in smp_conn_security()
2422 memcpy(&smp->preq[1], &cp, sizeof(cp)); in smp_conn_security()
2433 set_bit(SMP_FLAG_INITIATOR, &smp->flags); in smp_conn_security()
2457 conn = hcon->l2cap_data; in smp_cancel_and_remove_pairing()
2461 chan = conn->smp; in smp_cancel_and_remove_pairing()
2467 smp = chan->data; in smp_cancel_and_remove_pairing()
2471 smp->ltk = NULL; in smp_cancel_and_remove_pairing()
2472 smp->responder_ltk = NULL; in smp_cancel_and_remove_pairing()
2473 smp->remote_irk = NULL; in smp_cancel_and_remove_pairing()
2475 if (test_bit(SMP_FLAG_COMPLETE, &smp->flags)) in smp_cancel_and_remove_pairing()
2490 struct smp_cmd_encrypt_info *rp = (void *) skb->data; in smp_cmd_encrypt_info() local
2491 struct l2cap_chan *chan = conn->smp; in smp_cmd_encrypt_info()
2492 struct smp_chan *smp = chan->data; in smp_cmd_encrypt_info()
2494 bt_dev_dbg(conn->hcon->hdev, "conn %p", conn); in smp_cmd_encrypt_info()
2496 if (skb->len < sizeof(*rp)) in smp_cmd_encrypt_info()
2500 if (hci_is_blocked_key(conn->hcon->hdev, HCI_BLOCKED_KEY_TYPE_LTK, in smp_cmd_encrypt_info()
2501 rp->ltk)) { in smp_cmd_encrypt_info()
2502 bt_dev_warn_ratelimited(conn->hcon->hdev, in smp_cmd_encrypt_info()
2504 &conn->hcon->dst); in smp_cmd_encrypt_info()
2510 skb_pull(skb, sizeof(*rp)); in smp_cmd_encrypt_info()
2512 memcpy(smp->tk, rp->ltk, sizeof(smp->tk)); in smp_cmd_encrypt_info()
2519 struct smp_cmd_initiator_ident *rp = (void *)skb->data; in smp_cmd_initiator_ident() local
2520 struct l2cap_chan *chan = conn->smp; in smp_cmd_initiator_ident()
2521 struct smp_chan *smp = chan->data; in smp_cmd_initiator_ident()
2522 struct hci_dev *hdev = conn->hcon->hdev; in smp_cmd_initiator_ident()
2523 struct hci_conn *hcon = conn->hcon; in smp_cmd_initiator_ident()
2529 if (skb->len < sizeof(*rp)) in smp_cmd_initiator_ident()
2533 smp->remote_key_dist &= ~SMP_DIST_ENC_KEY; in smp_cmd_initiator_ident()
2535 if (smp->remote_key_dist & SMP_DIST_ID_KEY) in smp_cmd_initiator_ident()
2537 else if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_cmd_initiator_ident()
2540 skb_pull(skb, sizeof(*rp)); in smp_cmd_initiator_ident()
2542 authenticated = (hcon->sec_level == BT_SECURITY_HIGH); in smp_cmd_initiator_ident()
2543 ltk = hci_add_ltk(hdev, &hcon->dst, hcon->dst_type, SMP_LTK, in smp_cmd_initiator_ident()
2544 authenticated, smp->tk, smp->enc_key_size, in smp_cmd_initiator_ident()
2545 rp->ediv, rp->rand); in smp_cmd_initiator_ident()
2546 smp->ltk = ltk; in smp_cmd_initiator_ident()
2547 if (!(smp->remote_key_dist & KEY_DIST_MASK)) in smp_cmd_initiator_ident()
2555 struct smp_cmd_ident_info *info = (void *) skb->data; in smp_cmd_ident_info()
2556 struct l2cap_chan *chan = conn->smp; in smp_cmd_ident_info()
2557 struct smp_chan *smp = chan->data; in smp_cmd_ident_info()
2559 bt_dev_dbg(conn->hcon->hdev, ""); in smp_cmd_ident_info()
2561 if (skb->len < sizeof(*info)) in smp_cmd_ident_info()
2565 if (hci_is_blocked_key(conn->hcon->hdev, HCI_BLOCKED_KEY_TYPE_IRK, in smp_cmd_ident_info()
2566 info->irk)) { in smp_cmd_ident_info()
2567 bt_dev_warn_ratelimited(conn->hcon->hdev, in smp_cmd_ident_info()
2569 &conn->hcon->dst); in smp_cmd_ident_info()
2577 memcpy(smp->irk, info->irk, 16); in smp_cmd_ident_info()
2585 struct smp_cmd_ident_addr_info *info = (void *) skb->data; in smp_cmd_ident_addr_info()
2586 struct l2cap_chan *chan = conn->smp; in smp_cmd_ident_addr_info()
2587 struct smp_chan *smp = chan->data; in smp_cmd_ident_addr_info()
2588 struct hci_conn *hcon = conn->hcon; in smp_cmd_ident_addr_info()
2591 bt_dev_dbg(hcon->hdev, ""); in smp_cmd_ident_addr_info()
2593 if (skb->len < sizeof(*info)) in smp_cmd_ident_addr_info()
2597 smp->remote_key_dist &= ~SMP_DIST_ID_KEY; in smp_cmd_ident_addr_info()
2599 if (smp->remote_key_dist & SMP_DIST_SIGN) in smp_cmd_ident_addr_info()
2614 if (!bacmp(&info->bdaddr, BDADDR_ANY) || in smp_cmd_ident_addr_info()
2615 !hci_is_identity_address(&info->bdaddr, info->addr_type)) { in smp_cmd_ident_addr_info()
2616 bt_dev_err(hcon->hdev, "ignoring IRK with no identity address"); in smp_cmd_ident_addr_info()
2625 if (hci_is_identity_address(&hcon->dst, hcon->dst_type) && in smp_cmd_ident_addr_info()
2626 (bacmp(&info->bdaddr, &hcon->dst) || in smp_cmd_ident_addr_info()
2627 info->addr_type != hcon->dst_type)) { in smp_cmd_ident_addr_info()
2628 bt_dev_err(hcon->hdev, in smp_cmd_ident_addr_info()
2633 bacpy(&smp->id_addr, &info->bdaddr); in smp_cmd_ident_addr_info()
2634 smp->id_addr_type = info->addr_type; in smp_cmd_ident_addr_info()
2636 if (hci_bdaddr_is_rpa(&hcon->dst, hcon->dst_type)) in smp_cmd_ident_addr_info()
2637 bacpy(&rpa, &hcon->dst); in smp_cmd_ident_addr_info()
2641 smp->remote_irk = hci_add_irk(conn->hcon->hdev, &smp->id_addr, in smp_cmd_ident_addr_info()
2642 smp->id_addr_type, smp->irk, &rpa); in smp_cmd_ident_addr_info()
2645 if (!(smp->remote_key_dist & KEY_DIST_MASK)) in smp_cmd_ident_addr_info()
2653 struct smp_cmd_sign_info *rp = (void *) skb->data; in smp_cmd_sign_info() local
2654 struct l2cap_chan *chan = conn->smp; in smp_cmd_sign_info()
2655 struct smp_chan *smp = chan->data; in smp_cmd_sign_info()
2658 bt_dev_dbg(conn->hcon->hdev, "conn %p", conn); in smp_cmd_sign_info()
2660 if (skb->len < sizeof(*rp)) in smp_cmd_sign_info()
2664 smp->remote_key_dist &= ~SMP_DIST_SIGN; in smp_cmd_sign_info()
2666 skb_pull(skb, sizeof(*rp)); in smp_cmd_sign_info()
2670 if (conn->hcon->sec_level > BT_SECURITY_MEDIUM) in smp_cmd_sign_info()
2671 csrk->type = MGMT_CSRK_REMOTE_AUTHENTICATED; in smp_cmd_sign_info()
2673 csrk->type = MGMT_CSRK_REMOTE_UNAUTHENTICATED; in smp_cmd_sign_info()
2674 memcpy(csrk->val, rp->csrk, sizeof(csrk->val)); in smp_cmd_sign_info()
2676 smp->csrk = csrk; in smp_cmd_sign_info()
2684 struct l2cap_conn *conn = smp->conn; in sc_select_method()
2685 struct hci_conn *hcon = conn->hcon; in sc_select_method()
2689 if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags) || in sc_select_method()
2690 test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) in sc_select_method()
2698 if (hcon->out) { in sc_select_method()
2699 local = (void *) &smp->preq[1]; in sc_select_method()
2700 remote = (void *) &smp->prsp[1]; in sc_select_method()
2702 local = (void *) &smp->prsp[1]; in sc_select_method()
2703 remote = (void *) &smp->preq[1]; in sc_select_method()
2706 local_io = local->io_capability; in sc_select_method()
2707 remote_io = remote->io_capability; in sc_select_method()
2709 local_mitm = (local->auth_req & SMP_AUTH_MITM); in sc_select_method()
2710 remote_mitm = (remote->auth_req & SMP_AUTH_MITM); in sc_select_method()
2721 if (method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, &smp->flags)) in sc_select_method()
2729 struct smp_cmd_public_key *key = (void *) skb->data; in smp_cmd_public_key()
2730 struct hci_conn *hcon = conn->hcon; in smp_cmd_public_key()
2731 struct l2cap_chan *chan = conn->smp; in smp_cmd_public_key()
2732 struct smp_chan *smp = chan->data; in smp_cmd_public_key()
2733 struct hci_dev *hdev = hcon->hdev; in smp_cmd_public_key()
2740 if (skb->len < sizeof(*key)) in smp_cmd_public_key()
2746 if (!test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags) && in smp_cmd_public_key()
2747 !crypto_memneq(key, smp->local_pk, 64)) { in smp_cmd_public_key()
2752 memcpy(smp->remote_pk, key, 64); in smp_cmd_public_key()
2754 if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags)) { in smp_cmd_public_key()
2755 err = smp_f4(smp->tfm_cmac, smp->remote_pk, smp->remote_pk, in smp_cmd_public_key()
2756 smp->rr, 0, cfm.confirm_val); in smp_cmd_public_key()
2760 if (crypto_memneq(cfm.confirm_val, smp->pcnf, 16)) in smp_cmd_public_key()
2764 /* Non-initiating device sends its public key after receiving in smp_cmd_public_key()
2767 if (!hcon->out) { in smp_cmd_public_key()
2773 SMP_DBG("Remote Public Key X: %32phN", smp->remote_pk); in smp_cmd_public_key()
2774 SMP_DBG("Remote Public Key Y: %32phN", smp->remote_pk + 32); in smp_cmd_public_key()
2779 if (test_bit(SMP_FLAG_LOCAL_OOB, &smp->flags)) { in smp_cmd_public_key()
2780 struct l2cap_chan *hchan = hdev->smp_data; in smp_cmd_public_key()
2783 if (!hchan || !hchan->data) in smp_cmd_public_key()
2786 smp_dev = hchan->data; in smp_cmd_public_key()
2788 tfm_ecdh = smp_dev->tfm_ecdh; in smp_cmd_public_key()
2790 tfm_ecdh = smp->tfm_ecdh; in smp_cmd_public_key()
2793 if (compute_ecdh_secret(tfm_ecdh, smp->remote_pk, smp->dhkey)) in smp_cmd_public_key()
2796 SMP_DBG("DHKey %32phN", smp->dhkey); in smp_cmd_public_key()
2798 set_bit(SMP_FLAG_REMOTE_PK, &smp->flags); in smp_cmd_public_key()
2800 smp->method = sc_select_method(smp); in smp_cmd_public_key()
2802 bt_dev_dbg(hdev, "selected method 0x%02x", smp->method); in smp_cmd_public_key()
2805 if (smp->method == JUST_WORKS || smp->method == JUST_CFM) in smp_cmd_public_key()
2806 hcon->pending_sec_level = BT_SECURITY_MEDIUM; in smp_cmd_public_key()
2808 hcon->pending_sec_level = BT_SECURITY_FIPS; in smp_cmd_public_key()
2810 if (!crypto_memneq(debug_pk, smp->remote_pk, 64)) in smp_cmd_public_key()
2811 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); in smp_cmd_public_key()
2813 if (smp->method == DSP_PASSKEY) { in smp_cmd_public_key()
2814 get_random_bytes(&hcon->passkey_notify, in smp_cmd_public_key()
2815 sizeof(hcon->passkey_notify)); in smp_cmd_public_key()
2816 hcon->passkey_notify %= 1000000; in smp_cmd_public_key()
2817 hcon->passkey_entered = 0; in smp_cmd_public_key()
2818 smp->passkey_round = 0; in smp_cmd_public_key()
2819 if (mgmt_user_passkey_notify(hdev, &hcon->dst, hcon->type, in smp_cmd_public_key()
2820 hcon->dst_type, in smp_cmd_public_key()
2821 hcon->passkey_notify, in smp_cmd_public_key()
2822 hcon->passkey_entered)) in smp_cmd_public_key()
2828 if (smp->method == REQ_OOB) { in smp_cmd_public_key()
2829 if (hcon->out) in smp_cmd_public_key()
2831 sizeof(smp->prnd), smp->prnd); in smp_cmd_public_key()
2838 if (hcon->out) in smp_cmd_public_key()
2841 if (smp->method == REQ_PASSKEY) { in smp_cmd_public_key()
2842 if (mgmt_user_passkey_request(hdev, &hcon->dst, hcon->type, in smp_cmd_public_key()
2843 hcon->dst_type)) in smp_cmd_public_key()
2846 set_bit(SMP_FLAG_WAIT_USER, &smp->flags); in smp_cmd_public_key()
2850 /* The Initiating device waits for the non-initiating device to in smp_cmd_public_key()
2853 if (conn->hcon->out) in smp_cmd_public_key()
2856 err = smp_f4(smp->tfm_cmac, smp->local_pk, smp->remote_pk, smp->prnd, in smp_cmd_public_key()
2869 struct smp_cmd_dhkey_check *check = (void *) skb->data; in smp_cmd_dhkey_check()
2870 struct l2cap_chan *chan = conn->smp; in smp_cmd_dhkey_check()
2871 struct hci_conn *hcon = conn->hcon; in smp_cmd_dhkey_check()
2872 struct smp_chan *smp = chan->data; in smp_cmd_dhkey_check()
2877 bt_dev_dbg(hcon->hdev, "conn %p", conn); in smp_cmd_dhkey_check()
2879 if (skb->len < sizeof(*check)) in smp_cmd_dhkey_check()
2882 memcpy(a, &hcon->init_addr, 6); in smp_cmd_dhkey_check()
2883 memcpy(b, &hcon->resp_addr, 6); in smp_cmd_dhkey_check()
2884 a[6] = hcon->init_addr_type; in smp_cmd_dhkey_check()
2885 b[6] = hcon->resp_addr_type; in smp_cmd_dhkey_check()
2887 if (hcon->out) { in smp_cmd_dhkey_check()
2890 memcpy(io_cap, &smp->prsp[1], 3); in smp_cmd_dhkey_check()
2894 memcpy(io_cap, &smp->preq[1], 3); in smp_cmd_dhkey_check()
2899 if (smp->method == REQ_PASSKEY || smp->method == DSP_PASSKEY) in smp_cmd_dhkey_check()
2900 put_unaligned_le32(hcon->passkey_notify, r); in smp_cmd_dhkey_check()
2901 else if (smp->method == REQ_OOB) in smp_cmd_dhkey_check()
2902 memcpy(r, smp->lr, 16); in smp_cmd_dhkey_check()
2904 err = smp_f6(smp->tfm_cmac, smp->mackey, smp->rrnd, smp->prnd, r, in smp_cmd_dhkey_check()
2909 if (crypto_memneq(check->e, e, 16)) in smp_cmd_dhkey_check()
2912 if (!hcon->out) { in smp_cmd_dhkey_check()
2913 if (test_bit(SMP_FLAG_WAIT_USER, &smp->flags)) { in smp_cmd_dhkey_check()
2914 set_bit(SMP_FLAG_DHKEY_PENDING, &smp->flags); in smp_cmd_dhkey_check()
2924 if (hcon->out) { in smp_cmd_dhkey_check()
2925 hci_le_start_enc(hcon, 0, 0, smp->tk, smp->enc_key_size); in smp_cmd_dhkey_check()
2926 hcon->enc_key_size = smp->enc_key_size; in smp_cmd_dhkey_check()
2935 struct smp_cmd_keypress_notify *kp = (void *) skb->data; in smp_cmd_keypress_notify()
2937 bt_dev_dbg(conn->hcon->hdev, "value 0x%02x", kp->value); in smp_cmd_keypress_notify()
2944 struct l2cap_conn *conn = chan->conn; in smp_sig_channel()
2945 struct hci_conn *hcon = conn->hcon; in smp_sig_channel()
2950 if (skb->len < 1) in smp_sig_channel()
2951 return -EILSEQ; in smp_sig_channel()
2953 if (!hci_dev_test_flag(hcon->hdev, HCI_LE_ENABLED)) { in smp_sig_channel()
2958 code = skb->data[0]; in smp_sig_channel()
2961 smp = chan->data; in smp_sig_channel()
2966 if (smp && !test_and_clear_bit(code, &smp->allow_cmd)) in smp_sig_channel()
2982 err = -EPERM; in smp_sig_channel()
3034 bt_dev_dbg(hcon->hdev, "Unknown command code 0x%2.2x", code); in smp_sig_channel()
3049 bt_dev_err(hcon->hdev, "unexpected SMP command 0x%02x from %pMR", in smp_sig_channel()
3050 code, &hcon->dst); in smp_sig_channel()
3057 struct l2cap_conn *conn = chan->conn; in smp_teardown_cb()
3059 bt_dev_dbg(conn->hcon->hdev, "chan %p", chan); in smp_teardown_cb()
3061 if (chan->data) in smp_teardown_cb()
3064 conn->smp = NULL; in smp_teardown_cb()
3070 struct l2cap_conn *conn = chan->conn; in bredr_pairing()
3071 struct hci_conn *hcon = conn->hcon; in bredr_pairing()
3072 struct hci_dev *hdev = hcon->hdev; in bredr_pairing()
3079 if (!test_bit(HCI_CONN_NEW_LINK_KEY, &hcon->flags)) in bredr_pairing()
3083 if (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) in bredr_pairing()
3087 if (hcon->role != HCI_ROLE_MASTER) in bredr_pairing()
3095 if (!test_bit(HCI_CONN_AES_CCM, &hcon->flags) && in bredr_pairing()
3108 if (!(conn->remote_fixed_chan & L2CAP_FC_SMP_BREDR)) in bredr_pairing()
3112 if (chan->data) in bredr_pairing()
3121 set_bit(SMP_FLAG_SC, &smp->flags); in bredr_pairing()
3128 smp->preq[0] = SMP_CMD_PAIRING_REQ; in bredr_pairing()
3129 memcpy(&smp->preq[1], &req, sizeof(req)); in bredr_pairing()
3137 struct smp_chan *smp = chan->data; in smp_resume_cb()
3138 struct l2cap_conn *conn = chan->conn; in smp_resume_cb()
3139 struct hci_conn *hcon = conn->hcon; in smp_resume_cb()
3141 bt_dev_dbg(hcon->hdev, "chan %p", chan); in smp_resume_cb()
3143 if (hcon->type == ACL_LINK) { in smp_resume_cb()
3151 if (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) in smp_resume_cb()
3154 cancel_delayed_work(&smp->security_timer); in smp_resume_cb()
3161 struct l2cap_conn *conn = chan->conn; in smp_ready_cb()
3162 struct hci_conn *hcon = conn->hcon; in smp_ready_cb()
3164 bt_dev_dbg(hcon->hdev, "chan %p", chan); in smp_ready_cb()
3172 conn->smp = chan; in smp_ready_cb()
3174 if (hcon->type == ACL_LINK && test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) in smp_ready_cb()
3182 bt_dev_dbg(chan->conn->hcon->hdev, "chan %p", chan); in smp_recv_cb()
3186 struct smp_chan *smp = chan->data; in smp_recv_cb()
3189 cancel_delayed_work_sync(&smp->security_timer); in smp_recv_cb()
3191 hci_disconnect(chan->conn->hcon, HCI_ERROR_AUTH_FAILURE); in smp_recv_cb()
3205 return ERR_PTR(-ENOMEM); in smp_alloc_skb_cb()
3207 skb->priority = HCI_PRIO_MAX; in smp_alloc_skb_cb()
3208 bt_cb(skb)->l2cap.chan = chan; in smp_alloc_skb_cb()
3240 chan->chan_type = pchan->chan_type; in smp_new_conn_cb()
3241 chan->ops = &smp_chan_ops; in smp_new_conn_cb()
3242 chan->scid = pchan->scid; in smp_new_conn_cb()
3243 chan->dcid = chan->scid; in smp_new_conn_cb()
3244 chan->imtu = pchan->imtu; in smp_new_conn_cb()
3245 chan->omtu = pchan->omtu; in smp_new_conn_cb()
3246 chan->mode = pchan->mode; in smp_new_conn_cb()
3253 atomic_set(&chan->nesting, L2CAP_NESTING_SMP); in smp_new_conn_cb()
3292 return ERR_PTR(-ENOMEM); in smp_add_cid()
3301 tfm_ecdh = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); in smp_add_cid()
3309 smp->local_oob = false; in smp_add_cid()
3310 smp->tfm_cmac = tfm_cmac; in smp_add_cid()
3311 smp->tfm_ecdh = tfm_ecdh; in smp_add_cid()
3317 crypto_free_shash(smp->tfm_cmac); in smp_add_cid()
3318 crypto_free_kpp(smp->tfm_ecdh); in smp_add_cid()
3321 return ERR_PTR(-ENOMEM); in smp_add_cid()
3324 chan->data = smp; in smp_add_cid()
3333 hci_copy_identity_address(hdev, &chan->src, &bdaddr_type); in smp_add_cid()
3336 chan->src_type = BDADDR_LE_PUBLIC; in smp_add_cid()
3338 chan->src_type = BDADDR_LE_RANDOM; in smp_add_cid()
3340 bacpy(&chan->src, &hdev->bdaddr); in smp_add_cid()
3341 chan->src_type = BDADDR_BREDR; in smp_add_cid()
3344 chan->state = BT_LISTEN; in smp_add_cid()
3345 chan->mode = L2CAP_MODE_BASIC; in smp_add_cid()
3346 chan->imtu = L2CAP_DEFAULT_MTU; in smp_add_cid()
3347 chan->ops = &smp_root_chan_ops; in smp_add_cid()
3350 atomic_set(&chan->nesting, L2CAP_NESTING_PARENT); in smp_add_cid()
3361 smp = chan->data; in smp_del_chan()
3363 chan->data = NULL; in smp_del_chan()
3364 crypto_free_shash(smp->tfm_cmac); in smp_del_chan()
3365 crypto_free_kpp(smp->tfm_ecdh); in smp_del_chan()
3375 return -EALREADY; in smp_force_bredr()
3384 hdev->smp_bredr_data = chan; in smp_force_bredr()
3388 chan = hdev->smp_bredr_data; in smp_force_bredr()
3389 hdev->smp_bredr_data = NULL; in smp_force_bredr()
3410 if (WARN_ON(hdev->smp_data)) { in smp_register()
3411 chan = hdev->smp_data; in smp_register()
3412 hdev->smp_data = NULL; in smp_register()
3420 hdev->smp_data = chan; in smp_register()
3428 if (WARN_ON(hdev->smp_bredr_data)) { in smp_register()
3429 chan = hdev->smp_bredr_data; in smp_register()
3430 hdev->smp_bredr_data = NULL; in smp_register()
3437 chan = hdev->smp_data; in smp_register()
3438 hdev->smp_data = NULL; in smp_register()
3443 hdev->smp_bredr_data = chan; in smp_register()
3452 if (hdev->smp_bredr_data) { in smp_unregister()
3453 chan = hdev->smp_bredr_data; in smp_unregister()
3454 hdev->smp_bredr_data = NULL; in smp_unregister()
3458 if (hdev->smp_data) { in smp_unregister()
3459 chan = hdev->smp_data; in smp_unregister()
3460 hdev->smp_data = NULL; in smp_unregister()
3481 return -EINVAL; in test_debug_key()
3501 return -EINVAL; in test_ah()
3531 return -EINVAL; in test_c1()
3556 return -EINVAL; in test_s1()
3588 return -EINVAL; in test_f4()
3622 return -EINVAL; in test_f5()
3625 return -EINVAL; in test_f5()
3658 return -EINVAL; in test_f6()
3678 const u8 y[16] = { in test_g2() local
3685 err = smp_g2(tfm_cmac, u, v, x, y, &val); in test_g2()
3690 return -EINVAL; in test_g2()
3712 return -EINVAL; in test_h6()
3826 tfm_ecdh = crypto_alloc_kpp("ecdh-nist-p256", 0, 0); in bt_selftest_smp()