All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez PATCH v3] core: Add new policy for Just-Works repairing
@ 2020-02-14  3:45 Howard Chung
  2020-02-14  7:33 ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Howard Chung @ 2020-02-14  3:45 UTC (permalink / raw)
  To: linux-bluetooth, luiz.von.dentz
  Cc: chromeos-bluetooth-upstreaming, howardchung

From: "howardchung@google.com" <howardchung@google.com>

When kernel find out that the incoming Just-Works pairing is
initiated by a paired device, it is user space's responsibility to
decide the next action.

This patch includes the following:
- add JustWorksRepairing policy as an option in main.conf
- handle the confirmation request from kernel
---
The Just-Works repairing policy could be one of the following:
- never: default; reject the repairing immediately.
- confirm: prompt a confirmation dialog to user.
- always: always accept the repairing.

Changes in v3:
- move the check from src/agent.c to src/device.c
- fix the enum declaration in src/hcid.h

Changes in v2:
- let RequestAuthorization handle the situation
- remove the changes in client/

 src/device.c  | 16 ++++++++++++++++
 src/hcid.h    |  8 ++++++++
 src/main.c    | 27 +++++++++++++++++++++++++++
 src/main.conf |  5 +++++
 4 files changed, 56 insertions(+)

diff --git a/src/device.c b/src/device.c
index a4fe10980..a9cda47b3 100644
--- a/src/device.c
+++ b/src/device.c
@@ -6141,6 +6141,22 @@ int device_confirm_passkey(struct btd_device *device, uint8_t type,
 	struct authentication_req *auth;
 	int err;
 
+	/* Just-Works repairing policy */
+	if (confirm_hint && (device_is_paired(device, BDADDR_BREDR) ||
+				device_is_paired(device, BDADDR_LE_PUBLIC))) {
+		if (main_opts.jw_repairing == JW_REPAIRING_NEVER) {
+			btd_adapter_confirm_reply(device->adapter,
+						  &device->bdaddr,
+						  type, FALSE);
+			return 0;
+		} else if (main_opts.jw_repairing == JW_REPAIRING_ALWAYS) {
+			btd_adapter_confirm_reply(device->adapter,
+						  &device->bdaddr,
+						  type, TRUE);
+			return 0;
+		}
+	}
+
 	auth = new_auth(device, type, AUTH_TYPE_CONFIRM, FALSE);
 	if (!auth)
 		return -EPERM;
diff --git a/src/hcid.h b/src/hcid.h
index adea85ce2..ca405fde4 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -35,6 +35,12 @@ typedef enum {
 	BT_GATT_CACHE_NO,
 } bt_gatt_cache_t;
 
+enum jw_repairing_t {
+	JW_REPAIRING_NEVER,
+	JW_REPAIRING_CONFIRM,
+	JW_REPAIRING_ALWAYS,
+};
+
 struct main_opts {
 	char		*name;
 	uint32_t	class;
@@ -58,6 +64,8 @@ struct main_opts {
 	uint16_t	gatt_mtu;
 
 	uint8_t		key_size;
+
+	enum jw_repairing_t jw_repairing;
 };
 
 extern struct main_opts main_opts;
diff --git a/src/main.c b/src/main.c
index 1a6ab36a3..fc8c869fc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -93,6 +93,7 @@ static const char *supported_options[] = {
 	"MultiProfile",
 	"FastConnectable",
 	"Privacy",
+	"JustWorksRepairing",
 	NULL
 };
 
@@ -193,6 +194,20 @@ static bt_gatt_cache_t parse_gatt_cache(const char *cache)
 	}
 }
 
+static enum jw_repairing_t parse_jw_repairing(const char *jw_repairing)
+{
+	if (!strcmp(jw_repairing, "never")) {
+		return JW_REPAIRING_NEVER;
+	} else if (!strcmp(jw_repairing, "confirm")) {
+		return JW_REPAIRING_CONFIRM;
+	} else if (!strcmp(jw_repairing, "always")) {
+		return JW_REPAIRING_ALWAYS;
+	} else {
+		return JW_REPAIRING_NEVER;
+	}
+}
+
+
 static void check_options(GKeyFile *config, const char *group,
 						const char **options)
 {
@@ -331,6 +346,18 @@ static void parse_config(GKeyFile *config)
 		g_free(str);
 	}
 
+	str = g_key_file_get_string(config, "General",
+						"JustWorksRepairing", &err);
+	if (err) {
+		DBG("%s", err->message);
+		g_clear_error(&err);
+		main_opts.jw_repairing = JW_REPAIRING_NEVER;
+	} else {
+		DBG("just_works_repairing=%s", str);
+		main_opts.jw_repairing = parse_jw_repairing(str);
+		g_free(str);
+	}
+
 	str = g_key_file_get_string(config, "General", "Name", &err);
 	if (err) {
 		DBG("%s", err->message);
diff --git a/src/main.conf b/src/main.conf
index 40687a755..bb5ff5b15 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -72,6 +72,11 @@
 # Defaults to "off"
 # Privacy = off
 
+# Specify the policy to the JUST-WORKS repairing initiated by peer
+# Possible values: "never", "confirm", "always"
+# Defaults to "never"
+#JustWorksRepairing = never
+
 [GATT]
 # GATT attribute cache.
 # Possible values:
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Bluez PATCH v3] core: Add new policy for Just-Works repairing
  2020-02-14  3:45 [Bluez PATCH v3] core: Add new policy for Just-Works repairing Howard Chung
@ 2020-02-14  7:33 ` Johan Hedberg
  2020-02-14 18:26   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2020-02-14  7:33 UTC (permalink / raw)
  To: Howard Chung
  Cc: Bluez mailing list, Luiz Von Dentz, ChromeOS Bluetooth Upstreaming

Hi Howard,

On 14. Feb 2020, at 5.45, Howard Chung <howardchung@google.com> wrote:
> @@ -6141,6 +6141,22 @@ int device_confirm_passkey(struct btd_device *device, uint8_t type,
> 	struct authentication_req *auth;
> 	int err;
> 
> +	/* Just-Works repairing policy */
> +	if (confirm_hint && (device_is_paired(device, BDADDR_BREDR) ||
> +				device_is_paired(device, BDADDR_LE_PUBLIC))) {

Wouldn’t a single call to device_is_paired() using “type” (the address type that’s part of the mgmt event) be the right thing to do here?

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Bluez PATCH v3] core: Add new policy for Just-Works repairing
  2020-02-14  7:33 ` Johan Hedberg
@ 2020-02-14 18:26   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2020-02-14 18:26 UTC (permalink / raw)
  To: Johan Hedberg
  Cc: Howard Chung, Bluez mailing list, Luiz Von Dentz,
	ChromeOS Bluetooth Upstreaming

Hi Howard,

On Thu, Feb 13, 2020 at 11:35 PM Johan Hedberg <johan.hedberg@gmail.com> wrote:
>
> Hi Howard,
>
> On 14. Feb 2020, at 5.45, Howard Chung <howardchung@google.com> wrote:
> > @@ -6141,6 +6141,22 @@ int device_confirm_passkey(struct btd_device *device, uint8_t type,
> >       struct authentication_req *auth;
> >       int err;
> >
> > +     /* Just-Works repairing policy */
> > +     if (confirm_hint && (device_is_paired(device, BDADDR_BREDR) ||
> > +                             device_is_paired(device, BDADDR_LE_PUBLIC))) {
>
> Wouldn’t a single call to device_is_paired() using “type” (the address type that’s part of the mgmt event) be the right thing to do here?

+1, other than that it looks pretty good now so we should be able to
merge after this change.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-14 18:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14  3:45 [Bluez PATCH v3] core: Add new policy for Just-Works repairing Howard Chung
2020-02-14  7:33 ` Johan Hedberg
2020-02-14 18:26   ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.