[PATCH BlueZ] client/player: Add support to Max Transports in endpoint.register

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

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

[bluetooth]# endpoint.register 00002bc9-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): 1
[/local/endpoint/ep0] CIG (auto/value): a
[/local/endpoint/ep0] CIS (auto/value): a
---
 client/player.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/client/player.c b/client/player.c
index 2880c5ffe140..f055ff941569 100644
--- a/client/player.c
+++ b/client/player.c
@@ -73,6 +73,7 @@ struct endpoint {
 	struct iovec *meta;
 	bool auto_accept;
 	bool acquiring;
+	uint8_t max_transports;
 	uint8_t cig;
 	uint8_t cis;
 	char *transport;
@@ -1056,6 +1057,16 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn,
 	print_iter("\t", "Properties", &props);
 
 	free(ep->transport);
+
+	if (!ep->max_transports) {
+		bt_shell_printf("Maximum transports reached: rejecting\n");
+		return g_dbus_create_error(msg,
+					 "org.bluez.Error.Rejected",
+					 "Maximum transports reached");
+	}
+
+	ep->max_transports--;
+
 	ep->transport = strdup(path);
 
 	if (ep->auto_accept) {
@@ -1672,6 +1683,13 @@ static DBusMessage *endpoint_select_configuration(DBusConnection *conn,
 	bt_shell_printf("Endpoint: SelectConfiguration\n");
 	print_iter("\t", "Capabilities", &args);
 
+	if (!ep->max_transports) {
+		bt_shell_printf("Maximum transports reached: rejecting\n");
+		return g_dbus_create_error(msg,
+					 "org.bluez.Error.Rejected",
+					 "Maximum transports reached");
+	}
+
 	if (!ep->auto_accept) {
 		ep->msg = dbus_message_ref(msg);
 		bt_shell_prompt_input("Endpoint", "Enter preset/configuration:",
@@ -1688,8 +1706,11 @@ static DBusMessage *endpoint_select_configuration(DBusConnection *conn,
 
 	reply = endpoint_select_config_reply(msg, p->data.iov_base,
 						p->data.iov_len);
-	if (!reply)
-		return NULL;
+	if (!reply) {
+		reply = g_dbus_create_error(msg, "org.bluez.Error.Rejected",
+								NULL);
+		return reply;
+	}
 
 	bt_shell_printf("Auto Accepting using %s...\n", p->name);
 
@@ -1878,6 +1899,13 @@ static DBusMessage *endpoint_select_properties(DBusConnection *conn,
 	bt_shell_printf("Endpoint: SelectProperties\n");
 	print_iter("\t", "Properties", &args);
 
+	if (!ep->max_transports) {
+		bt_shell_printf("Maximum transports reached: rejecting\n");
+		return g_dbus_create_error(msg,
+					 "org.bluez.Error.Rejected",
+					 "Maximum transports reached");
+	}
+
 	if (!ep->auto_accept) {
 		ep->msg = dbus_message_ref(msg);
 		bt_shell_prompt_input("Endpoint", "Enter preset/configuration:",
@@ -1903,6 +1931,9 @@ static DBusMessage *endpoint_clear_configuration(DBusConnection *conn,
 {
 	struct endpoint *ep = user_data;
 
+	if (ep->max_transports != UINT8_MAX)
+		ep->max_transports++;
+
 	free(ep->transport);
 	ep->transport = NULL;
 
@@ -2234,12 +2265,37 @@ static void endpoint_cig(const char *input, void *user_data)
 	bt_shell_prompt_input(ep->path, "CIS (auto/value):", endpoint_cis, ep);
 }
 
+static void endpoint_max_transports(const char *input, void *user_data)
+{
+	struct endpoint *ep = user_data;
+	char *endptr = NULL;
+	int value;
+
+	if (!strcasecmp(input, "a") || !strcasecmp(input, "auto")) {
+		ep->max_transports = UINT8_MAX;
+	} else {
+		value = strtol(input, &endptr, 0);
+
+		if (!endptr || *endptr != '\0' || value > UINT8_MAX) {
+			bt_shell_printf("Invalid argument: %s\n", input);
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+		}
+
+		ep->max_transports = value;
+	}
+
+	bt_shell_prompt_input(ep->path, "CIG (auto/value):", endpoint_cig, ep);
+}
+
 static void endpoint_auto_accept(const char *input, void *user_data)
 {
 	struct endpoint *ep = user_data;
 
 	if (!strcasecmp(input, "y") || !strcasecmp(input, "yes")) {
 		ep->auto_accept = true;
+		bt_shell_prompt_input(ep->path, "Max Transports (auto/value):",
+						endpoint_max_transports, ep);
+		return;
 	} else if (!strcasecmp(input, "n") || !strcasecmp(input, "no")) {
 		ep->auto_accept = false;
 	} else {
@@ -2977,6 +3033,7 @@ static void register_endpoints(GDBusProxy *proxy)
 				continue;
 
 			ep = endpoint_new(cap);
+			ep->max_transports = UINT8_MAX;
 			ep->auto_accept = true;
 			ep->cig = BT_ISO_QOS_CIG_UNSET;
 			ep->cis = BT_ISO_QOS_CIS_UNSET;
-- 
2.40.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