3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2013-2014 Intel Corporation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <sys/socket.h>
38 #include "lib/bluetooth.h"
41 #include "src/shared/util.h"
42 #include "src/shared/crypto.h"
43 #include "src/shared/ecc.h"
44 #include "monitor/bt.h"
47 #define SMP_CID 0x0006
48 #define SMP_BREDR_CID 0x0007
50 #define L2CAP_FC_SMP_BREDR 0x80
52 #define SMP_PASSKEY_ENTRY_FAILED 0x01
53 #define SMP_OOB_NOT_AVAIL 0x02
54 #define SMP_AUTH_REQUIREMENTS 0x03
55 #define SMP_CONFIRM_FAILED 0x04
56 #define SMP_PAIRING_NOTSUPP 0x05
57 #define SMP_ENC_KEY_SIZE 0x06
58 #define SMP_CMD_NOTSUPP 0x07
59 #define SMP_UNSPECIFIED 0x08
60 #define SMP_REPEATED_ATTEMPTS 0x09
61 #define SMP_INVALID_PARAMS 0x0a
62 #define SMP_DHKEY_CHECK_FAILED 0x0b
63 #define SMP_NUMERIC_COMP_FAILED 0x0c
64 #define SMP_BREDR_PAIRING_IN_PROGRESS 0x0d
66 #define DIST_ENC_KEY 0x01
67 #define DIST_ID_KEY 0x02
68 #define DIST_SIGN 0x04
69 #define DIST_LINK_KEY 0x08
71 #define KEY_DIST (DIST_ENC_KEY | DIST_ID_KEY | DIST_SIGN)
73 #define SC_NO_DIST (DIST_ENC_KEY | DIST_LINK_KEY)
75 #define MAX_IO_CAP 0x04
77 #define SMP_AUTH_NONE 0x00
78 #define SMP_AUTH_BONDING 0x01
79 #define SMP_AUTH_MITM 0x04
80 #define SMP_AUTH_SC 0x08
81 #define SMP_AUTH_KEYPRESS 0x10
84 struct bthost *bthost;
85 struct smp_conn *conn;
86 struct bt_crypto *crypto;
97 uint8_t local_key_dist;
98 uint8_t remote_key_dist;
111 uint8_t local_sk[32];
112 uint8_t local_pk[64];
113 uint8_t remote_pk[64];
117 uint8_t passkey_notify;
118 uint8_t passkey_round;
131 static const uint8_t gen_method[5][5] = {
132 { JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY },
133 { JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY },
134 { CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, CFM_PASSKEY },
135 { JUST_WORKS, JUST_CFM, JUST_WORKS, JUST_WORKS, JUST_CFM },
136 { CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, OVERLAP },
139 static const uint8_t sc_method[5][5] = {
140 { JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY },
141 { JUST_WORKS, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, CFM_PASSKEY },
142 { DSP_PASSKEY, DSP_PASSKEY, REQ_PASSKEY, JUST_WORKS, DSP_PASSKEY },
143 { JUST_WORKS, JUST_CFM, JUST_WORKS, JUST_WORKS, JUST_CFM },
144 { DSP_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, CFM_PASSKEY },
147 static uint8_t get_auth_method(struct smp_conn *conn, uint8_t local_io,
150 /* If either side has unknown io_caps, use JUST_CFM (which gets
151 * converted later to JUST_WORKS if we're initiators.
153 if (local_io > MAX_IO_CAP || remote_io > MAX_IO_CAP)
157 return sc_method[remote_io][local_io];
159 return gen_method[remote_io][local_io];
162 static uint8_t sc_select_method(struct smp_conn *conn)
164 struct bt_l2cap_smp_pairing_request *local, *remote;
165 uint8_t local_mitm, remote_mitm, local_io, remote_io, method;
168 local = (void *) &conn->preq[1];
169 remote = (void *) &conn->prsp[1];
171 local = (void *) &conn->prsp[1];
172 remote = (void *) &conn->preq[1];
175 local_io = local->io_capa;
176 remote_io = remote->io_capa;
178 local_mitm = (local->auth_req & SMP_AUTH_MITM);
179 remote_mitm = (remote->auth_req & SMP_AUTH_MITM);
181 /* If either side wants MITM, look up the method from the table,
182 * otherwise use JUST WORKS.
184 if (local_mitm || remote_mitm)
185 method = get_auth_method(conn, local_io, remote_io);
189 /* Don't confirm locally initiated pairing attempts */
190 if (method == JUST_CFM && conn->initiator)
196 static void smp_send(struct smp_conn *conn, uint8_t smp_cmd, const void *data,
202 iov[0].iov_base = &smp_cmd;
205 iov[1].iov_base = (void *) data;
206 iov[1].iov_len = len;
208 if (conn->addr_type == BDADDR_BREDR)
213 bthost_send_cid_v(conn->smp->bthost, conn->handle, cid, iov, 2);
216 static bool send_public_key(struct smp_conn *conn)
218 if (!ecc_make_key(conn->local_pk, conn->local_sk))
221 smp_send(conn, BT_L2CAP_SMP_PUBLIC_KEY, conn->local_pk, 64);
226 static void sc_dhkey_check(struct smp_conn *conn)
228 uint8_t io_cap[3], r[16], a[7], b[7], *local_addr, *remote_addr;
229 struct bt_l2cap_smp_dhkey_check check;
231 memcpy(a, conn->ia, 6);
232 memcpy(b, conn->ra, 6);
233 a[6] = conn->ia_type;
234 b[6] = conn->ra_type;
239 memcpy(io_cap, &conn->preq[1], 3);
243 memcpy(io_cap, &conn->prsp[1], 3);
246 memset(r, 0, sizeof(r));
248 bt_crypto_f6(conn->smp->crypto, conn->mackey, conn->prnd, conn->rrnd,
249 r, io_cap, local_addr, remote_addr, check.e);
251 smp_send(conn, BT_L2CAP_SMP_DHKEY_CHECK, &check, sizeof(check));
254 static void sc_mackey_and_ltk(struct smp_conn *conn)
256 uint8_t *na, *nb, a[7], b[7];
266 memcpy(a, conn->ia, 6);
267 memcpy(b, conn->ra, 6);
268 a[6] = conn->ia_type;
269 b[6] = conn->ra_type;
271 bt_crypto_f5(conn->smp->crypto, conn->dhkey, na, nb, a, b,
272 conn->mackey, conn->ltk);
275 static uint8_t sc_passkey_send_confirm(struct smp_conn *conn)
277 struct bt_l2cap_smp_pairing_confirm cfm;
280 r = ((conn->passkey_notify >> conn->passkey_round) & 0x01);
283 if (!bt_crypto_f4(conn->smp->crypto, conn->local_pk, conn->remote_pk,
284 conn->prnd, r, cfm.value))
285 return SMP_UNSPECIFIED;
287 smp_send(conn, BT_L2CAP_SMP_PAIRING_CONFIRM, &cfm, sizeof(cfm));
292 static uint8_t sc_passkey_round(struct smp_conn *conn, uint8_t smp_op)
296 /* Ignore the PDU if we've already done 20 rounds (0 - 19) */
297 if (conn->passkey_round >= 20)
301 case BT_L2CAP_SMP_PAIRING_RANDOM:
302 r = ((conn->passkey_notify >> conn->passkey_round) & 0x01);
305 if (!bt_crypto_f4(conn->smp->crypto, conn->remote_pk,
306 conn->local_pk, conn->rrnd, r, cfm))
307 return SMP_UNSPECIFIED;
309 if (memcmp(conn->pcnf, cfm, 16))
310 return SMP_CONFIRM_FAILED;
312 conn->passkey_round++;
314 if (conn->passkey_round == 20) {
315 /* Generate MacKey and LTK */
316 sc_mackey_and_ltk(conn);
319 /* The round is only complete when the initiator
320 * receives pairing random.
323 smp_send(conn, BT_L2CAP_SMP_PAIRING_RANDOM,
324 conn->prnd, sizeof(conn->prnd));
328 /* Start the next round */
329 if (conn->passkey_round != 20)
330 return sc_passkey_round(conn, 0);
332 /* Passkey rounds are complete - start DHKey Check */
333 sc_dhkey_check(conn);
337 case BT_L2CAP_SMP_PAIRING_CONFIRM:
339 smp_send(conn, BT_L2CAP_SMP_PAIRING_RANDOM,
340 conn->prnd, sizeof(conn->prnd));
344 return sc_passkey_send_confirm(conn);
346 case BT_L2CAP_SMP_PUBLIC_KEY:
348 /* Initiating device starts the round */
352 return sc_passkey_send_confirm(conn);
358 static bool verify_random(struct smp_conn *conn, const uint8_t rnd[16])
362 if (!bt_crypto_c1(conn->smp->crypto, conn->tk, conn->rrnd, conn->prsp,
363 conn->preq, conn->ia_type, conn->ia,
364 conn->ra_type, conn->ra, confirm))
367 if (memcmp(conn->pcnf, confirm, sizeof(conn->pcnf) != 0)) {
368 printf("Confirmation values don't match\n");
373 bt_crypto_s1(conn->smp->crypto, conn->tk, conn->rrnd,
374 conn->prnd, conn->ltk);
375 bthost_le_start_encrypt(conn->smp->bthost, conn->handle,
378 bt_crypto_s1(conn->smp->crypto, conn->tk, conn->prnd,
379 conn->rrnd, conn->ltk);
385 static void distribute_keys(struct smp_conn *conn)
389 if (conn->local_key_dist & DIST_ENC_KEY) {
390 memset(buf, 0, sizeof(buf));
391 smp_send(conn, BT_L2CAP_SMP_ENCRYPT_INFO, buf, sizeof(buf));
392 smp_send(conn, BT_L2CAP_SMP_MASTER_IDENT, buf, 10);
395 if (conn->local_key_dist & DIST_ID_KEY) {
396 memset(buf, 0, sizeof(buf));
397 smp_send(conn, BT_L2CAP_SMP_IDENT_INFO, buf, sizeof(buf));
399 memset(buf, 0, sizeof(buf));
402 buf[0] = conn->ia_type;
403 memcpy(&buf[1], conn->ia, 6);
405 buf[0] = conn->ra_type;
406 memcpy(&buf[1], conn->ra, 6);
409 smp_send(conn, BT_L2CAP_SMP_IDENT_ADDR_INFO, buf, 7);
412 if (conn->local_key_dist & DIST_SIGN) {
413 memset(buf, 0, sizeof(buf));
414 smp_send(conn, BT_L2CAP_SMP_SIGNING_INFO, buf, sizeof(buf));
418 static void pairing_req(struct smp_conn *conn, const void *data, uint16_t len)
420 struct bthost *bthost = conn->smp->bthost;
421 struct bt_l2cap_smp_pairing_response rsp;
423 memcpy(conn->preq, data, sizeof(conn->preq));
425 if (conn->addr_type == BDADDR_BREDR) {
430 rsp.io_capa = bthost_get_io_capability(bthost);
432 rsp.auth_req = bthost_get_auth_req(bthost);
435 rsp.max_key_size = 0x10;
436 rsp.init_key_dist = conn->preq[5] & KEY_DIST;
437 rsp.resp_key_dist = conn->preq[6] & KEY_DIST;
439 conn->prsp[0] = BT_L2CAP_SMP_PAIRING_RESPONSE;
440 memcpy(&conn->prsp[1], &rsp, sizeof(rsp));
442 conn->local_key_dist = rsp.resp_key_dist;
443 conn->remote_key_dist = rsp.init_key_dist;
445 if (((conn->prsp[3] & 0x08) && (conn->preq[3] & 0x08)) ||
446 conn->addr_type == BDADDR_BREDR) {
448 conn->local_key_dist &= ~SC_NO_DIST;
449 conn->remote_key_dist &= ~SC_NO_DIST;
452 smp_send(conn, BT_L2CAP_SMP_PAIRING_RESPONSE, &rsp, sizeof(rsp));
454 if (conn->addr_type == BDADDR_BREDR)
455 distribute_keys(conn);
458 static void pairing_rsp(struct smp_conn *conn, const void *data, uint16_t len)
460 struct smp *smp = conn->smp;
463 memcpy(conn->prsp, data, sizeof(conn->prsp));
465 conn->local_key_dist = conn->prsp[5];
466 conn->remote_key_dist = conn->prsp[6];
468 if (conn->addr_type == BDADDR_BREDR) {
469 conn->local_key_dist &= ~SC_NO_DIST;
470 conn->remote_key_dist &= ~SC_NO_DIST;
471 distribute_keys(conn);
475 if (((conn->prsp[3] & 0x08) && (conn->preq[3] & 0x08)) ||
476 conn->addr_type == BDADDR_BREDR) {
478 conn->local_key_dist &= ~SC_NO_DIST;
479 conn->remote_key_dist &= ~SC_NO_DIST;
480 if (conn->addr_type == BDADDR_BREDR)
481 distribute_keys(conn);
483 send_public_key(conn);
487 bt_crypto_c1(smp->crypto, conn->tk, conn->prnd, conn->prsp,
488 conn->preq, conn->ia_type, conn->ia,
489 conn->ra_type, conn->ra, cfm);
491 smp_send(conn, BT_L2CAP_SMP_PAIRING_CONFIRM, cfm, sizeof(cfm));
493 static void sc_check_confirm(struct smp_conn *conn)
495 if (conn->method == REQ_PASSKEY || conn->method == DSP_PASSKEY) {
496 sc_passkey_round(conn, BT_L2CAP_SMP_PAIRING_CONFIRM);
501 smp_send(conn, BT_L2CAP_SMP_PAIRING_RANDOM, conn->prnd,
505 static void pairing_cfm(struct smp_conn *conn, const void *data, uint16_t len)
509 memcpy(conn->pcnf, data + 1, 16);
512 sc_check_confirm(conn);
517 memset(rsp, 0, sizeof(rsp));
518 smp_send(conn, BT_L2CAP_SMP_PAIRING_RANDOM, rsp, sizeof(rsp));
520 bt_crypto_c1(conn->smp->crypto, conn->tk, conn->prnd,
521 conn->prsp, conn->preq, conn->ia_type,
522 conn->ia, conn->ra_type, conn->ra, rsp);
523 smp_send(conn, BT_L2CAP_SMP_PAIRING_CONFIRM, rsp, sizeof(rsp));
527 static uint8_t sc_random(struct smp_conn *conn)
529 /* Passkey entry has special treatment */
530 if (conn->method == REQ_PASSKEY || conn->method == DSP_PASSKEY)
531 return sc_passkey_round(conn, BT_L2CAP_SMP_PAIRING_RANDOM);
536 bt_crypto_f4(conn->smp->crypto, conn->remote_pk,
537 conn->local_pk, conn->rrnd, 0, cfm);
539 if (memcmp(conn->pcnf, cfm, 16))
540 return 0x04; /* Confirm Value Failed */
542 smp_send(conn, BT_L2CAP_SMP_PAIRING_RANDOM, conn->prnd, 16);
545 sc_mackey_and_ltk(conn);
548 sc_dhkey_check(conn);
553 static void pairing_rnd(struct smp_conn *conn, const void *data, uint16_t len)
557 memcpy(conn->rrnd, data + 1, 16);
560 uint8_t reason = sc_random(conn);
562 smp_send(conn, BT_L2CAP_SMP_PAIRING_FAILED, &reason,
567 if (!verify_random(conn, data + 1))
573 memset(rsp, 0, sizeof(rsp));
574 smp_send(conn, BT_L2CAP_SMP_PAIRING_RANDOM, rsp, sizeof(rsp));
577 static void encrypt_info(struct smp_conn *conn, const void *data, uint16_t len)
581 static void master_ident(struct smp_conn *conn, const void *data, uint16_t len)
583 conn->remote_key_dist &= ~DIST_ENC_KEY;
585 if (conn->out && !conn->remote_key_dist)
586 distribute_keys(conn);
589 static void ident_addr_info(struct smp_conn *conn, const void *data,
594 static void ident_info(struct smp_conn *conn, const void *data, uint16_t len)
596 conn->remote_key_dist &= ~DIST_ID_KEY;
598 if (conn->out && !conn->remote_key_dist)
599 distribute_keys(conn);
602 static void signing_info(struct smp_conn *conn, const void *data, uint16_t len)
604 conn->remote_key_dist &= ~DIST_SIGN;
606 if (conn->out && !conn->remote_key_dist)
607 distribute_keys(conn);
610 static void public_key(struct smp_conn *conn, const void *data, uint16_t len)
612 struct smp *smp = conn->smp;
615 memcpy(conn->remote_pk, data + 1, 64);
618 if (!send_public_key(conn))
622 if (!ecdh_shared_secret(conn->remote_pk, conn->local_sk, conn->dhkey))
625 conn->method = sc_select_method(conn);
627 if (conn->method == DSP_PASSKEY || conn->method == REQ_PASSKEY) {
628 sc_passkey_round(conn, BT_L2CAP_SMP_PUBLIC_KEY);
635 if (!bt_crypto_f4(smp->crypto, conn->local_pk, conn->remote_pk,
639 smp_send(conn, BT_L2CAP_SMP_PAIRING_CONFIRM, buf, sizeof(buf));
642 static void dhkey_check(struct smp_conn *conn, const void *data, uint16_t len)
644 const struct bt_l2cap_smp_dhkey_check *cmd = data + 1;
645 uint8_t a[7], b[7], *local_addr, *remote_addr;
646 uint8_t io_cap[3], r[16], e[16];
648 memcpy(a, &conn->ia, 6);
649 memcpy(b, &conn->ra, 6);
650 a[6] = conn->ia_type;
651 b[6] = conn->ra_type;
656 memcpy(io_cap, &conn->prsp[1], 3);
660 memcpy(io_cap, &conn->preq[1], 3);
663 memset(r, 0, sizeof(r));
665 if (conn->method == REQ_PASSKEY || conn->method == DSP_PASSKEY)
666 put_le32(conn->passkey_notify, r);
668 if (!bt_crypto_f6(conn->smp->crypto, conn->mackey, conn->rrnd,
669 conn->prnd, r, io_cap, remote_addr, local_addr, e))
672 if (memcmp(cmd->e, e, 16)) {
673 uint8_t reason = 0x0b; /* DHKey Check Failed */
674 smp_send(conn, BT_L2CAP_SMP_PAIRING_FAILED, &reason,
679 bthost_le_start_encrypt(conn->smp->bthost, conn->handle,
682 sc_dhkey_check(conn);
685 void smp_pair(void *conn_data, uint8_t io_cap, uint8_t auth_req)
687 struct smp_conn *conn = conn_data;
688 struct bt_l2cap_smp_pairing_request req;
690 req.io_capa = io_cap;
692 req.auth_req = auth_req;
693 req.max_key_size = 0x10;
694 req.init_key_dist = KEY_DIST;
695 req.resp_key_dist = KEY_DIST;
697 conn->preq[0] = BT_L2CAP_SMP_PAIRING_REQUEST;
698 memcpy(&conn->preq[1], &req, sizeof(req));
700 smp_send(conn, BT_L2CAP_SMP_PAIRING_REQUEST, &req, sizeof(req));
703 void smp_data(void *conn_data, const void *data, uint16_t len)
705 struct smp_conn *conn = conn_data;
709 printf("Received too small SMP PDU\n");
713 if (conn->addr_type == BDADDR_BREDR) {
714 printf("Received BR/EDR SMP data on LE link\n");
718 opcode = *((const uint8_t *) data);
721 case BT_L2CAP_SMP_PAIRING_REQUEST:
722 pairing_req(conn, data, len);
724 case BT_L2CAP_SMP_PAIRING_RESPONSE:
725 pairing_rsp(conn, data, len);
727 case BT_L2CAP_SMP_PAIRING_CONFIRM:
728 pairing_cfm(conn, data, len);
730 case BT_L2CAP_SMP_PAIRING_RANDOM:
731 pairing_rnd(conn, data, len);
733 case BT_L2CAP_SMP_ENCRYPT_INFO:
734 encrypt_info(conn, data, len);
736 case BT_L2CAP_SMP_MASTER_IDENT:
737 master_ident(conn, data, len);
739 case BT_L2CAP_SMP_IDENT_ADDR_INFO:
740 ident_addr_info(conn, data, len);
742 case BT_L2CAP_SMP_IDENT_INFO:
743 ident_info(conn, data, len);
745 case BT_L2CAP_SMP_SIGNING_INFO:
746 signing_info(conn, data, len);
748 case BT_L2CAP_SMP_PUBLIC_KEY:
749 public_key(conn, data, len);
751 case BT_L2CAP_SMP_DHKEY_CHECK:
752 dhkey_check(conn, data, len);
759 void smp_bredr_data(void *conn_data, const void *data, uint16_t len)
761 struct smp_conn *conn = conn_data;
765 printf("Received too small SMP PDU\n");
769 if (conn->addr_type != BDADDR_BREDR) {
770 printf("Received LE SMP data on BR/EDR link\n");
774 opcode = *((const uint8_t *) data);
777 case BT_L2CAP_SMP_PAIRING_REQUEST:
778 pairing_req(conn, data, len);
780 case BT_L2CAP_SMP_PAIRING_RESPONSE:
781 pairing_rsp(conn, data, len);
788 int smp_get_ltk(void *smp_data, uint64_t rand, uint16_t ediv, uint8_t *ltk)
790 struct smp_conn *conn = smp_data;
791 static const uint8_t no_ltk[16] = { 0 };
793 if (!memcmp(conn->ltk, no_ltk, 16))
796 memcpy(ltk, conn->ltk, 16);
801 static void smp_conn_bredr(struct smp_conn *conn, uint8_t encrypt)
803 struct smp *smp = conn->smp;
804 struct bt_l2cap_smp_pairing_request req;
815 fixed_chan = bthost_conn_get_fixed_chan(smp->bthost, conn->handle);
816 if (!(fixed_chan & L2CAP_FC_SMP_BREDR))
819 memset(&req, 0, sizeof(req));
820 req.max_key_size = 0x10;
821 req.init_key_dist = KEY_DIST;
822 req.resp_key_dist = KEY_DIST;
824 smp_send(conn, BT_L2CAP_SMP_PAIRING_REQUEST, &req, sizeof(req));
827 void smp_conn_encrypted(void *conn_data, uint8_t encrypt)
829 struct smp_conn *conn = conn_data;
834 if (conn->addr_type == BDADDR_BREDR) {
835 smp_conn_bredr(conn, encrypt);
839 if (conn->out && conn->remote_key_dist)
842 distribute_keys(conn);
845 void *smp_conn_add(void *smp_data, uint16_t handle, const uint8_t *ia,
846 const uint8_t *ra, uint8_t addr_type, bool conn_init)
848 struct smp *smp = smp_data;
849 struct smp_conn *conn;
851 conn = malloc(sizeof(struct smp_conn));
855 memset(conn, 0, sizeof(*conn));
858 conn->handle = handle;
859 conn->addr_type = addr_type;
860 conn->out = conn_init;
862 conn->ia_type = LE_PUBLIC_ADDRESS;
863 conn->ra_type = LE_PUBLIC_ADDRESS;
864 memcpy(conn->ia, ia, 6);
865 memcpy(conn->ra, ra, 6);
870 void smp_conn_del(void *conn_data)
872 struct smp_conn *conn = conn_data;
877 void *smp_start(struct bthost *bthost)
881 smp = malloc(sizeof(struct smp));
885 memset(smp, 0, sizeof(*smp));
887 smp->crypto = bt_crypto_new();
893 smp->bthost = bthost;
898 void smp_stop(void *smp_data)
900 struct smp *smp = smp_data;
902 bt_crypto_unref(smp->crypto);