linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] Bluetooth: Set wakeable flag via add_device
@ 2020-03-20  1:49 Abhishek Pandit-Subedi
  2020-03-20  1:49 ` [RFC PATCH 1/1] Bluetooth: Update add_device to accept flags Abhishek Pandit-Subedi
  0 siblings, 1 reply; 3+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-03-20  1:49 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: linux-bluetooth, chromeos-bluetooth-upstreaming,
	Abhishek Pandit-Subedi, David S. Miller, Johan Hedberg, netdev,
	linux-kernel, Jakub Kicinski


Hi Marcel and Luiz,

As suggested, I've updated the add_device mgmt op to accept flags on the
device and added support for the wakeable flag. I've prototyped an
implementation in Bluez as well that will send the mask + value on any
add_device and then clear it on the add_device completion.

This seems to work fairly well and allows updating flags during runtime
as well (for example, via dbus property setting).

Please take a look. I will also send up the Bluez changes so you can
look at how userspace would use this.

Thanks
Abhishek



Abhishek Pandit-Subedi (1):
  Bluetooth: Update add_device to accept flags

 include/net/bluetooth/mgmt.h |  5 ++++-
 net/bluetooth/mgmt.c         | 42 +++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 2 deletions(-)

-- 
2.25.1.696.g5e7596f4ac-goog


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

* [RFC PATCH 1/1] Bluetooth: Update add_device to accept flags
  2020-03-20  1:49 [RFC PATCH 0/1] Bluetooth: Set wakeable flag via add_device Abhishek Pandit-Subedi
@ 2020-03-20  1:49 ` Abhishek Pandit-Subedi
  2020-03-25 21:27   ` Marcel Holtmann
  0 siblings, 1 reply; 3+ messages in thread
From: Abhishek Pandit-Subedi @ 2020-03-20  1:49 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: linux-bluetooth, chromeos-bluetooth-upstreaming,
	Abhishek Pandit-Subedi, David S. Miller, Johan Hedberg, netdev,
	linux-kernel, Jakub Kicinski

Add the capability to set flags on devices being added via add_device.
The first flag being used is the wakeable flag which allows the device
to wake the system from suspend.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
---

 include/net/bluetooth/mgmt.h |  5 ++++-
 net/bluetooth/mgmt.c         | 42 +++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index f41cd87550dc..e9db9b1a4436 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -445,8 +445,11 @@ struct mgmt_rp_get_clock_info {
 struct mgmt_cp_add_device {
 	struct mgmt_addr_info addr;
 	__u8	action;
+	__u8	flags_mask;
+	__u8	flags_value;
 } __packed;
-#define MGMT_ADD_DEVICE_SIZE		(MGMT_ADDR_INFO_SIZE + 1)
+#define MGMT_ADD_DEVICE_SIZE		(MGMT_ADDR_INFO_SIZE + 3)
+#define DEVICE_FLAG_WAKEABLE		(1 << 0)
 
 #define MGMT_OP_REMOVE_DEVICE		0x0034
 struct mgmt_cp_remove_device {
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 6552003a170e..ae241f541713 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5759,6 +5759,25 @@ static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr,
 	return 0;
 }
 
+static int hci_conn_params_set_flags(struct hci_dev *hdev, bdaddr_t *addr,
+				     u8 addr_type, u8 flags_mask,
+				     u8 flags_value)
+{
+	struct hci_conn_params *params =
+		hci_conn_params_add(hdev, addr, addr_type);
+
+	if (!params)
+		return -EIO;
+
+	if (flags_mask & DEVICE_FLAG_WAKEABLE)
+		params->wakeable = flags_mask & DEVICE_FLAG_WAKEABLE;
+
+	bt_dev_dbg(hdev, "addr %pMR (type %u) flag mask %u, values %u", addr,
+		   addr_type, flags_mask, flags_value);
+
+	return 0;
+}
+
 static void device_added(struct sock *sk, struct hci_dev *hdev,
 			 bdaddr_t *bdaddr, u8 type, u8 action)
 {
@@ -5805,11 +5824,23 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
 
 		err = hci_bdaddr_list_add(&hdev->whitelist, &cp->addr.bdaddr,
 					  cp->addr.type);
-		if (err)
+		if (err && err != -EEXIST)
 			goto unlock;
 
 		hci_req_update_scan(hdev);
 
+		/* Modify wake capable property if set. */
+		if (cp->flags_mask & DEVICE_FLAG_WAKEABLE) {
+			if (cp->flags_value & DEVICE_FLAG_WAKEABLE)
+				hci_bdaddr_list_add(&hdev->wakeable,
+						    &cp->addr.bdaddr,
+						    cp->addr.type);
+			else
+				hci_bdaddr_list_del(&hdev->wakeable,
+						    &cp->addr.bdaddr,
+						    cp->addr.type);
+		}
+
 		goto added;
 	}
 
@@ -5845,6 +5876,15 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
 		goto unlock;
 	}
 
+	/* Set or clear flags that were configured for this device */
+	if (hci_conn_params_set_flags(hdev, &cp->addr.bdaddr, addr_type,
+				      cp->flags_mask, cp->flags_value)) {
+		err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
+					MGMT_STATUS_FAILED, &cp->addr,
+					sizeof(cp->addr));
+		goto unlock;
+	}
+
 	hci_update_background_scan(hdev);
 
 added:
-- 
2.25.1.696.g5e7596f4ac-goog


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

* Re: [RFC PATCH 1/1] Bluetooth: Update add_device to accept flags
  2020-03-20  1:49 ` [RFC PATCH 1/1] Bluetooth: Update add_device to accept flags Abhishek Pandit-Subedi
@ 2020-03-25 21:27   ` Marcel Holtmann
  0 siblings, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2020-03-25 21:27 UTC (permalink / raw)
  To: Abhishek Pandit-Subedi
  Cc: Luiz Augusto von Dentz, linux-bluetooth,
	chromeos-bluetooth-upstreaming, David S. Miller, Johan Hedberg,
	netdev, linux-kernel, Jakub Kicinski

Hi Abhishek,

> Add the capability to set flags on devices being added via add_device.
> The first flag being used is the wakeable flag which allows the device
> to wake the system from suspend.
> 
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> ---
> 
> include/net/bluetooth/mgmt.h |  5 ++++-
> net/bluetooth/mgmt.c         | 42 +++++++++++++++++++++++++++++++++++-
> 2 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index f41cd87550dc..e9db9b1a4436 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -445,8 +445,11 @@ struct mgmt_rp_get_clock_info {
> struct mgmt_cp_add_device {
> 	struct mgmt_addr_info addr;
> 	__u8	action;
> +	__u8	flags_mask;
> +	__u8	flags_value;
> } __packed;
> -#define MGMT_ADD_DEVICE_SIZE		(MGMT_ADDR_INFO_SIZE + 1)
> +#define MGMT_ADD_DEVICE_SIZE		(MGMT_ADDR_INFO_SIZE + 3)

as I mentioned in the other review. This is not backwards compatible.

Regards

Marcel


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

end of thread, other threads:[~2020-03-25 21:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20  1:49 [RFC PATCH 0/1] Bluetooth: Set wakeable flag via add_device Abhishek Pandit-Subedi
2020-03-20  1:49 ` [RFC PATCH 1/1] Bluetooth: Update add_device to accept flags Abhishek Pandit-Subedi
2020-03-25 21:27   ` Marcel Holtmann

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).