linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Cc: Bastien Nocera <hadess@hadess.net>
Subject: [PATCH v2 01/11] adapter: Add btd_request_authorization_cable_configured()
Date: Wed, 18 Oct 2017 03:58:05 +0200	[thread overview]
Message-ID: <20171018015815.10045-1-hadess@hadess.net> (raw)

Add btd_request_authorization_cable_configured() function to allow
cable configured devices to ask the user straight away about whether the
device should be allowed to connect to the computer.

This allows us to ask the user at the time of the USB connection and
initial setup, rather than when the first Bluetooth connection is made.

The fact that the device might not be connected to the adapter when
this event is triggered is mentioned in the Agent API docs.
---
 doc/agent-api.txt |  5 ++++-
 src/adapter.c     | 42 ++++++++++++++++++++++++++++++++++++------
 src/adapter.h     |  2 ++
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index 801ccb665..0d9347cab 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -163,7 +163,10 @@ Methods		void Release()
 			This method gets called to request the user to
 			authorize an incoming pairing attempt which
 			would in other circumstances trigger the just-works
-			model.
+			model, or when the user plugged in a device that
+			implements cable pairing. In the latter case, the
+			device would not be connected to the adapter via
+			Bluetooth yet.
 
 			Possible errors: org.bluez.Error.Rejected
 			                 org.bluez.Error.Canceled
diff --git a/src/adapter.c b/src/adapter.c
index 19205ed07..32a89d533 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -266,6 +266,11 @@ struct btd_adapter {
 	bool is_default;		/* true if adapter is default one */
 };
 
+typedef enum {
+	ADAPTER_AUTHORIZE_DISCONNECTED = 0,
+	ADAPTER_AUTHORIZE_CHECK_CONNECTED
+} adapter_authorize_type;
+
 static struct btd_adapter *btd_adapter_lookup(uint16_t index)
 {
 	GList *list;
@@ -6136,8 +6141,9 @@ static void svc_complete(struct btd_device *dev, int err, void *user_data)
 }
 
 static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst,
-					const char *uuid, service_auth_cb cb,
-					void *user_data)
+					const char *uuid,
+					adapter_authorize_type check_for_connection,
+					service_auth_cb cb, void *user_data)
 {
 	struct service_auth *auth;
 	struct btd_device *device;
@@ -6153,7 +6159,7 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst,
 	}
 
 	/* Device connected? */
-	if (!g_slist_find(adapter->connections, device))
+	if (check_for_connection && !g_slist_find(adapter->connections, device))
 		btd_error(adapter->dev_id,
 			"Authorization request for non-connected device!?");
 
@@ -6167,7 +6173,12 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst,
 	auth->device = device;
 	auth->adapter = adapter;
 	auth->id = ++id;
-	auth->svc_id = device_wait_for_svc_complete(device, svc_complete, auth);
+	if (check_for_connection)
+		auth->svc_id = device_wait_for_svc_complete(device, svc_complete, auth);
+	else {
+		if (adapter->auth_idle_id == 0)
+			adapter->auth_idle_id = g_idle_add(process_auth_queue, adapter);
+	}
 
 	g_queue_push_tail(adapter->auths, auth);
 
@@ -6186,7 +6197,8 @@ guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst,
 		if (!adapter)
 			return 0;
 
-		return adapter_authorize(adapter, dst, uuid, cb, user_data);
+		return adapter_authorize(adapter, dst, uuid,
+				ADAPTER_AUTHORIZE_CHECK_CONNECTED, cb, user_data);
 	}
 
 	for (l = adapters; l != NULL; l = g_slist_next(l)) {
@@ -6194,7 +6206,8 @@ guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst,
 
 		adapter = l->data;
 
-		id = adapter_authorize(adapter, dst, uuid, cb, user_data);
+		id = adapter_authorize(adapter, dst, uuid,
+				ADAPTER_AUTHORIZE_CHECK_CONNECTED, cb, user_data);
 		if (id != 0)
 			return id;
 	}
@@ -6202,6 +6215,23 @@ guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst,
 	return 0;
 }
 
+guint btd_request_authorization_cable_configured(const bdaddr_t *src, const bdaddr_t *dst,
+						const char *uuid, service_auth_cb cb,
+						void *user_data)
+{
+	struct btd_adapter *adapter;
+
+	if (bacmp(src, BDADDR_ANY) == 0)
+		return 0;
+
+	adapter = adapter_find(src);
+	if (!adapter)
+		return 0;
+
+	return adapter_authorize(adapter, dst, uuid,
+			ADAPTER_AUTHORIZE_DISCONNECTED, cb, user_data);
+}
+
 static struct service_auth *find_authorization(guint id)
 {
 	GSList *l;
diff --git a/src/adapter.h b/src/adapter.h
index f9178d59e..a85327cd1 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -120,6 +120,8 @@ int btd_register_adapter_driver(struct btd_adapter_driver *driver);
 void btd_unregister_adapter_driver(struct btd_adapter_driver *driver);
 guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst,
 		const char *uuid, service_auth_cb cb, void *user_data);
+guint btd_request_authorization_cable_configured(const bdaddr_t *src, const bdaddr_t *dst,
+		const char *uuid, service_auth_cb cb, void *user_data);
 int btd_cancel_authorization(guint id);
 
 int btd_adapter_restore_powered(struct btd_adapter *adapter);
-- 
2.14.2


             reply	other threads:[~2017-10-18  1:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18  1:58 Bastien Nocera [this message]
2017-10-18  1:58 ` [PATCH v2 02/11] sixaxis: Ask user whether cable configuration should be allowed Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 03/11] plugins/sixaxis: Move device discovery to shared header Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 04/11] profiles/input: Use sixaxis header to simplify device detection Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 05/11] profiles/input: Add DS4 devices to the shared header Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 06/11] plugins/sixaxis: Rename sixaxis specific functions Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 07/11] plugins/sixaxis: Add support for DualShock 4/PS4 cable pairing Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 08/11] plugins/sixaxis: Cancel cable pairing if unplugged Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 09/11] profiles/input: Add support for detecting PS3 Keypads Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 10/11] plugins/sixaxis: Add cable pairing for " Bastien Nocera
2017-10-18  1:58 ` [PATCH v2 11/11] plugins/autopair: Don't try to pair PS3 Keypad Bastien Nocera
2017-10-27  8:00 ` [PATCH v2 01/11] adapter: Add btd_request_authorization_cable_configured() Szymon Janc
2017-10-27 11:34   ` Bastien Nocera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171018015815.10045-1-hadess@hadess.net \
    --to=hadess@hadess.net \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).