Skip to content

Commit 9fee4d7

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: SMP: Improve logging of unspecified pairing failure
Improve logging of pairing procedure when it fails with error code unspecified. Since this is returned in many places debugging this failure is not easy without adding additional debugging. Signed-off-by: Joakim Andersson <[email protected]>
1 parent a01a619 commit 9fee4d7

File tree

1 file changed

+31
-1
lines changed
  • subsys/bluetooth/host

1 file changed

+31
-1
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ static void smp_br_derive_ltk(struct bt_smp_br *smp)
11071107

11081108
keys = bt_keys_get_type(BT_KEYS_LTK_P256, conn->id, &addr);
11091109
if (!keys) {
1110-
BT_ERR("No keys space for %s", bt_addr_le_str(&addr));
1110+
BT_ERR("Unable to get keys for %s", bt_addr_le_str(&addr));
11111111
return;
11121112
}
11131113

@@ -1305,6 +1305,7 @@ static uint8_t smp_br_pairing_req(struct bt_smp_br *smp, struct net_buf *buf)
13051305

13061306
max_key_size = bt_conn_enc_key_size(conn);
13071307
if (!max_key_size) {
1308+
BT_DBG("Invalid encryption key size");
13081309
return BT_SMP_ERR_UNSPECIFIED;
13091310
}
13101311

@@ -1377,6 +1378,7 @@ static uint8_t smp_br_pairing_rsp(struct bt_smp_br *smp, struct net_buf *buf)
13771378

13781379
max_key_size = bt_conn_enc_key_size(conn);
13791380
if (!max_key_size) {
1381+
BT_DBG("Invalid encryption key size");
13801382
return BT_SMP_ERR_UNSPECIFIED;
13811383
}
13821384

@@ -1743,6 +1745,7 @@ int bt_smp_br_send_pairing_req(struct bt_conn *conn)
17431745

17441746
max_key_size = bt_conn_enc_key_size(conn);
17451747
if (!max_key_size) {
1748+
BT_DBG("Invalid encryption key size");
17461749
return -EIO;
17471750
}
17481751

@@ -2007,6 +2010,7 @@ static uint8_t smp_send_pairing_confirm(struct bt_smp *smp)
20072010
r |= 0x80;
20082011
break;
20092012
default:
2013+
BT_ERR("Unknown pairing method (%u)", smp->method);
20102014
return BT_SMP_ERR_UNSPECIFIED;
20112015
}
20122016

@@ -2459,6 +2463,7 @@ static uint8_t legacy_pairing_random(struct bt_smp *smp)
24592463
if (IS_ENABLED(CONFIG_BT_PERIPHERAL)) {
24602464
err = smp_s1(smp->tk, smp->prnd, smp->rrnd, tmp);
24612465
if (err) {
2466+
BT_ERR("Calculate STK failed");
24622467
return BT_SMP_ERR_UNSPECIFIED;
24632468
}
24642469

@@ -2889,6 +2894,8 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
28892894
if (!conn->le.keys) {
28902895
conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst);
28912896
if (!conn->le.keys) {
2897+
BT_DBG("Unable to get keys for %s",
2898+
bt_addr_le_str(&conn->le.dst));
28922899
return BT_SMP_ERR_UNSPECIFIED;
28932900
}
28942901
}
@@ -2941,6 +2948,7 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
29412948
atomic_set_bit(smp->flags, SMP_FLAG_BOND);
29422949
} else if (IS_ENABLED(CONFIG_BT_BONDING_REQUIRED)) {
29432950
/* Reject pairing req if not both intend to bond */
2951+
BT_DBG("Bonding required");
29442952
return BT_SMP_ERR_UNSPECIFIED;
29452953
}
29462954

@@ -3144,6 +3152,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
31443152
atomic_set_bit(smp->flags, SMP_FLAG_BOND);
31453153
} else if (IS_ENABLED(CONFIG_BT_BONDING_REQUIRED)) {
31463154
/* Reject pairing req if not both intend to bond */
3155+
BT_DBG("Bonding required");
31473156
return BT_SMP_ERR_UNSPECIFIED;
31483157
}
31493158

@@ -3261,6 +3270,7 @@ static uint8_t smp_pairing_confirm(struct bt_smp *smp, struct net_buf *buf)
32613270
case JUST_WORKS:
32623271
case PASSKEY_CONFIRM:
32633272
default:
3273+
BT_ERR("Unknown pairing method (%u)", smp->method);
32643274
return BT_SMP_ERR_UNSPECIFIED;
32653275
}
32663276
}
@@ -3306,6 +3316,7 @@ static uint8_t compute_and_send_master_dhcheck(struct bt_smp *smp)
33063316
}
33073317
break;
33083318
default:
3319+
BT_ERR("Unknown pairing method (%u)", smp->method);
33093320
return BT_SMP_ERR_UNSPECIFIED;
33103321
}
33113322

@@ -3314,12 +3325,14 @@ static uint8_t compute_and_send_master_dhcheck(struct bt_smp *smp)
33143325
&smp->chan.chan.conn->le.init_addr,
33153326
&smp->chan.chan.conn->le.resp_addr, smp->mackey,
33163327
smp->tk)) {
3328+
BT_ERR("Calculate LTK failed");
33173329
return BT_SMP_ERR_UNSPECIFIED;
33183330
}
33193331
/* calculate local DHKey check */
33203332
if (smp_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->preq[1],
33213333
&smp->chan.chan.conn->le.init_addr,
33223334
&smp->chan.chan.conn->le.resp_addr, e)) {
3335+
BT_ERR("Calculate local DHKey check failed");
33233336
return BT_SMP_ERR_UNSPECIFIED;
33243337
}
33253338

@@ -3350,6 +3363,7 @@ static uint8_t compute_and_check_and_send_slave_dhcheck(struct bt_smp *smp)
33503363
}
33513364
break;
33523365
default:
3366+
BT_ERR("Unknown pairing method (%u)", smp->method);
33533367
return BT_SMP_ERR_UNSPECIFIED;
33543368
}
33553369

@@ -3358,13 +3372,15 @@ static uint8_t compute_and_check_and_send_slave_dhcheck(struct bt_smp *smp)
33583372
&smp->chan.chan.conn->le.init_addr,
33593373
&smp->chan.chan.conn->le.resp_addr, smp->mackey,
33603374
smp->tk)) {
3375+
BT_ERR("Calculate LTK failed");
33613376
return BT_SMP_ERR_UNSPECIFIED;
33623377
}
33633378

33643379
/* calculate local DHKey check */
33653380
if (smp_f6(smp->mackey, smp->prnd, smp->rrnd, r, &smp->prsp[1],
33663381
&smp->chan.chan.conn->le.resp_addr,
33673382
&smp->chan.chan.conn->le.init_addr, e)) {
3383+
BT_ERR("Calculate local DHKey check failed");
33683384
return BT_SMP_ERR_UNSPECIFIED;
33693385
}
33703386

@@ -3380,6 +3396,7 @@ static uint8_t compute_and_check_and_send_slave_dhcheck(struct bt_smp *smp)
33803396
if (smp_f6(smp->mackey, smp->rrnd, smp->prnd, r, &smp->preq[1],
33813397
&smp->chan.chan.conn->le.init_addr,
33823398
&smp->chan.chan.conn->le.resp_addr, re)) {
3399+
BT_ERR("Calculate remote DHKey check failed");
33833400
return BT_SMP_ERR_UNSPECIFIED;
33843401
}
33853402

@@ -3515,10 +3532,12 @@ static uint8_t sc_smp_check_confirm(struct bt_smp *smp)
35153532
r |= 0x80;
35163533
break;
35173534
default:
3535+
BT_ERR("Unknown pairing method (%u)", smp->method);
35183536
return BT_SMP_ERR_UNSPECIFIED;
35193537
}
35203538

35213539
if (smp_f4(smp->pkey, sc_public_key, smp->rrnd, r, cfm)) {
3540+
BT_ERR("Calculate confirm failed");
35223541
return BT_SMP_ERR_UNSPECIFIED;
35233542
}
35243543

@@ -3631,6 +3650,7 @@ static uint8_t smp_pairing_random(struct bt_smp *smp, struct net_buf *buf)
36313650
BT_SMP_CMD_PAIRING_CONFIRM);
36323651
return smp_send_pairing_confirm(smp);
36333652
default:
3653+
BT_ERR("Unknown pairing method (%u)", smp->method);
36343654
return BT_SMP_ERR_UNSPECIFIED;
36353655
}
36363656

@@ -3708,6 +3728,7 @@ static uint8_t smp_pairing_random(struct bt_smp *smp, struct net_buf *buf)
37083728
return BT_SMP_ERR_OOB_NOT_AVAIL;
37093729
}
37103730
default:
3731+
BT_ERR("Unknown pairing method (%u)", smp->method);
37113732
return BT_SMP_ERR_UNSPECIFIED;
37123733
}
37133734

@@ -3924,6 +3945,7 @@ static uint8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf)
39243945
if (IS_ENABLED(CONFIG_BT_BONDING_REQUIRED) &&
39253946
!(bondable && (auth & BT_SMP_AUTH_BONDING))) {
39263947
/* Reject security req if not both intend to bond */
3948+
BT_DBG("Bonding required");
39273949
return BT_SMP_ERR_UNSPECIFIED;
39283950
}
39293951

@@ -3970,6 +3992,7 @@ static uint8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf)
39703992
conn->le.keys->ltk.ediv,
39713993
conn->le.keys->ltk.val,
39723994
conn->le.keys->enc_size) < 0) {
3995+
BT_ERR("Failed to start encryption");
39733996
return BT_SMP_ERR_UNSPECIFIED;
39743997
}
39753998

@@ -4068,6 +4091,7 @@ static uint8_t smp_public_key_slave(struct bt_smp *smp)
40684091
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_PAIRING_RANDOM);
40694092
break;
40704093
default:
4094+
BT_ERR("Unknown pairing method (%u)", smp->method);
40714095
return BT_SMP_ERR_UNSPECIFIED;
40724096
}
40734097

@@ -4157,6 +4181,7 @@ static uint8_t smp_public_key(struct bt_smp *smp, struct net_buf *buf)
41574181
}
41584182
break;
41594183
default:
4184+
BT_ERR("Unknown pairing method (%u)", smp->method);
41604185
return BT_SMP_ERR_UNSPECIFIED;
41614186
}
41624187

@@ -4205,6 +4230,7 @@ static uint8_t smp_dhkey_check(struct bt_smp *smp, struct net_buf *buf)
42054230
}
42064231
break;
42074232
default:
4233+
BT_ERR("Unknown pairing method (%u)", smp->method);
42084234
return BT_SMP_ERR_UNSPECIFIED;
42094235
}
42104236

@@ -4226,6 +4252,7 @@ static uint8_t smp_dhkey_check(struct bt_smp *smp, struct net_buf *buf)
42264252
(void)memset(rand, 0, sizeof(rand));
42274253
if (bt_conn_le_start_encryption(smp->chan.chan.conn, rand, ediv,
42284254
smp->tk, enc_size) < 0) {
4255+
BT_ERR("Failed to start encryption");
42294256
return BT_SMP_ERR_UNSPECIFIED;
42304257
}
42314258

@@ -5357,6 +5384,8 @@ int bt_smp_auth_cancel(struct bt_conn *conn)
53575384
return -EINVAL;
53585385
}
53595386

5387+
BT_DBG("");
5388+
53605389
switch (smp->method) {
53615390
case PASSKEY_INPUT:
53625391
case PASSKEY_DISPLAY:
@@ -5369,6 +5398,7 @@ int bt_smp_auth_cancel(struct bt_conn *conn)
53695398
case JUST_WORKS:
53705399
return smp_error(smp, BT_SMP_ERR_UNSPECIFIED);
53715400
default:
5401+
BT_ERR("Unknown pairing method (%u)", smp->method);
53725402
return 0;
53735403
}
53745404
}

0 commit comments

Comments
 (0)