[PATCH BlueZ v4 5/8] device: Better error when no BR/EDR profiles can be connected to

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a more precise error when there are no BR/EDR profiles to connect
to. This is useful when trying to connect to a particular device, and
there are no relevant profiles to connect to on the bearer.
---
 doc/org.bluez.Device.rst |  2 ++
 src/device.c             |  3 +--
 src/error.c              | 19 +++++++++++++++----
 src/error.h              |  3 +--
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/doc/org.bluez.Device.rst b/doc/org.bluez.Device.rst
index 646e2c77ec2d..b36a49eabdd5 100644
--- a/doc/org.bluez.Device.rst
+++ b/doc/org.bluez.Device.rst
@@ -49,6 +49,7 @@ Possible errors:
 :org.bluez.Error.Failed:
 :org.bluez.Error.InProgress:
 :org.bluez.Error.AlreadyConnected:
+:org.bluez.Error.ProfileUnavailable:
 
 void Disconnect()
 `````````````````
@@ -80,6 +81,7 @@ Possible errors:
 :org.bluez.Error.InProgress:
 :org.bluez.Error.InvalidArguments:
 :org.bluez.Error.NotAvailable:
+:org.bluez.Error.ProfileUnavailable:
 :org.bluez.Error.NotReady:
 
 void DisconnectProfile(string uuid)
diff --git a/src/device.c b/src/device.c
index 5c80fedd7dc6..99c0aa67ec0c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2685,8 +2685,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type
 						BTD_SERVICE_STATE_CONNECTED)) {
 				return dbus_message_new_method_return(msg);
 			} else {
-				return btd_error_not_available_str(msg,
-					ERR_BREDR_CONN_PROFILE_UNAVAILABLE);
+				return btd_error_profile_unavailable(msg);
 			}
 		}
 
diff --git a/src/error.c b/src/error.c
index 74b8f80e63c5..8070bc6107ae 100644
--- a/src/error.c
+++ b/src/error.c
@@ -128,6 +128,14 @@ DBusMessage *btd_error_not_ready_str(DBusMessage *msg, const char *str)
 					"%s", str);
 }
 
+DBusMessage *btd_error_profile_unavailable(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE
+					".ProfileUnavailable",
+					"Exhausted the list of BR/EDR "
+					"profiles to connect to");
+}
+
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE
@@ -142,8 +150,6 @@ static const char *btd_error_str_bredr_conn_from_errno(int errno_code)
 		return ERR_BREDR_CONN_ALREADY_CONNECTED;
 	case EHOSTDOWN:
 		return ERR_BREDR_CONN_PAGE_TIMEOUT;
-	case ENOPROTOOPT:
-		return ERR_BREDR_CONN_PROFILE_UNAVAILABLE;
 	case EIO:
 		return ERR_BREDR_CONN_CREATE_SOCKET;
 	case EINVAL:
@@ -220,8 +226,13 @@ static const char *btd_error_str_le_conn_from_errno(int errno_code)
 
 DBusMessage *btd_error_bredr_conn_from_errno(DBusMessage *msg, int errno_code)
 {
-	return btd_error_failed(msg,
-				btd_error_str_bredr_conn_from_errno(errno_code));
+	switch (-errno_code) {
+	case ENOPROTOOPT:
+		return btd_error_profile_unavailable(msg);
+	default:
+		return btd_error_failed(msg,
+					btd_error_str_bredr_conn_from_errno(errno_code));
+	}
 }
 
 DBusMessage *btd_error_le_conn_from_errno(DBusMessage *msg, int errno_code)
diff --git a/src/error.h b/src/error.h
index 0fa3975cff7c..f4ad81e5daa5 100644
--- a/src/error.h
+++ b/src/error.h
@@ -19,8 +19,6 @@
 #define ERR_BREDR_CONN_ALREADY_CONNECTED	"br-connection-already-"\
 						"connected"
 #define ERR_BREDR_CONN_PAGE_TIMEOUT		"br-connection-page-timeout"
-#define ERR_BREDR_CONN_PROFILE_UNAVAILABLE	"br-connection-profile-"\
-						"unavailable"
 #define ERR_BREDR_CONN_SDP_SEARCH		"br-connection-sdp-search"
 #define ERR_BREDR_CONN_CREATE_SOCKET		"br-connection-create-socket"
 #define ERR_BREDR_CONN_INVALID_ARGUMENTS	"br-connection-invalid-"\
@@ -85,6 +83,7 @@ DBusMessage *btd_error_no_such_adapter(DBusMessage *msg);
 DBusMessage *btd_error_agent_not_available(DBusMessage *msg);
 DBusMessage *btd_error_not_ready(DBusMessage *msg);
 DBusMessage *btd_error_not_ready_str(DBusMessage *msg, const char *str);
+DBusMessage *btd_error_profile_unavailable(DBusMessage *msg);
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str);
 DBusMessage *btd_error_bredr_conn_from_errno(DBusMessage *msg, int errno_code);
 DBusMessage *btd_error_le_conn_from_errno(DBusMessage *msg, int errno_code);
-- 
2.50.0





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux