Skip to content

Linux + iPhone Continuity / iMessage / SMS

fix: more diagnostic logging for failures

Zack Bartela8e12b6af2d3
diff --git a/src/core/include/tether/bluetooth/pairing.hpp b/src/core/include/tether/bluetooth/pairing.hpp
index e26ffdf..342a991 100644
--- a/src/core/include/tether/bluetooth/pairing.hpp
+++ b/src/core/include/tether/bluetooth/pairing.hpp
@@ -31,6 +31,9 @@ namespace tether::bluetooth {
// at all. Device1.Pair() involves no profile.
bool should_fall_back(AuthStrategy tried, bool paired, bool confirmation_failed);
+ // Whether a D-Bus error names an authentication BlueZ already failed. No bond can appear afterwards.
+ bool is_authentication_failure(const std::string& err);
+
// Reports progress steps so the CLI and GTK app can show what is happening
// during a transaction that legitimately takes tens of seconds.
using ProgressFn = std::function<void(const std::string& step, const std::string& detail)>;
diff --git a/src/core/src/bluetooth/pairing.cpp b/src/core/src/bluetooth/pairing.cpp
index ea66ed0..6422004 100644
--- a/src/core/src/bluetooth/pairing.cpp
+++ b/src/core/src/bluetooth/pairing.cpp
@@ -482,6 +482,15 @@ namespace tether::bluetooth {
};
}
+ bool is_authentication_failure(const std::string& err) {
+ static const char* const NAMES[] = {
+ "AuthenticationFailed", "AuthenticationRejected", "AuthenticationCanceled", "AuthenticationTimeout"};
+ for (const char* name : NAMES)
+ if (err.find(name) != std::string::npos)
+ return true;
+ return false;
+ }
+
bool should_fall_back(AuthStrategy tried, bool paired, bool confirmation_failed) {
return tried == AuthStrategy::ConnectFirst && !paired && !confirmation_failed;
}
@@ -553,16 +562,22 @@ namespace tether::bluetooth {
bool unavailable = false;
bool accepted = confirm_with_dialog(display_name, code, unavailable);
+ std::string answered_by = "dialog";
if (unavailable && confirm) {
accepted = confirm(code);
unavailable = false;
+ answered_by = "client";
}
if (unavailable)
confirm_unavailable = true;
else if (!accepted)
user_rejected = true;
+
+ notify(progress,
+ unavailable ? "unanswered" : (accepted ? "confirmed" : "declined"),
+ unavailable ? "no dialog and no client answered" : answered_by);
return accepted;
});
@@ -598,8 +613,13 @@ namespace tether::bluetooth {
initiated = call_device(conn, device.path, "Pair", PAIR_TIMEOUT_SECONDS * 1000, err);
}
- // Connect() can report failure while authentication still completes so a refusal is waited out too
- const int seconds = (!initiated && !auth_seen) ? CONNECT_REFUSED_GRACE_SECONDS : PAIR_TIMEOUT_SECONDS;
+ if (!initiated)
+ notify(progress, "error", err);
+
+ // Connect() can report failure while authentication still completes so a refusal is waited out too.
+ const int seconds = (!initiated && (!auth_seen || is_authentication_failure(err)))
+ ? CONNECT_REFUSED_GRACE_SECONDS
+ : PAIR_TIMEOUT_SECONDS;
auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(seconds);
while (std::chrono::steady_clock::now() < deadline) {
if (device_is_paired(conn, device.path))
diff --git a/test/test_bluetooth_pairing.cpp b/test/test_bluetooth_pairing.cpp
index dd1b9a7..c9c8ba3 100644
--- a/test/test_bluetooth_pairing.cpp
+++ b/test/test_bluetooth_pairing.cpp
@@ -107,6 +107,23 @@ TEST(FallbackPolicy, DoesNotRetryAUserRejection) {
EXPECT_FALSE(should_fall_back(AuthStrategy::ConnectFirst, /*paired=*/false, /*user_rejected=*/true));
}
+// BlueZ reporting a failed authentication is terminal: polling for a bond after
+// it only buries when the transaction actually broke -- see issue #49.
+TEST(AuthenticationFailure, RecognizesBlueZErrorNames) {
+ EXPECT_TRUE(is_authentication_failure("GDBus.Error:org.bluez.Error.AuthenticationFailed: Authentication Failed"));
+ EXPECT_TRUE(is_authentication_failure("org.bluez.Error.AuthenticationRejected"));
+ EXPECT_TRUE(is_authentication_failure("org.bluez.Error.AuthenticationCanceled"));
+ EXPECT_TRUE(is_authentication_failure("org.bluez.Error.AuthenticationTimeout"));
+}
+
+// A refused profile connect can still be followed by a completed authentication,
+// so those errors must keep the full wait.
+TEST(AuthenticationFailure, IgnoresConnectAndTransportErrors) {
+ EXPECT_FALSE(is_authentication_failure("org.bluez.Error.Failed: br-connection-refused"));
+ EXPECT_FALSE(is_authentication_failure("org.bluez.Error.InProgress"));
+ EXPECT_FALSE(is_authentication_failure(""));
+}
+
// Explicit pair is the fallback; there is nothing further to fall back to.
TEST(FallbackPolicy, NeverRetriesExplicitPair) {
EXPECT_FALSE(should_fall_back(AuthStrategy::ExplicitPair, /*paired=*/false, /*user_rejected=*/false));