linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] device: Add device type property
@ 2017-02-09  1:05 mcchou
  2017-02-09  7:37 ` Marcel Holtmann
  0 siblings, 1 reply; 13+ messages in thread
From: mcchou @ 2017-02-09  1:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.von.dentz, josephsih, ortuno, Eric Caruso

From: Eric Caruso <ejcaruso@chromium.org>

This allows us to gather information about whether a device
supports BR/EDR, BLE, or both. It appears as DBus Property
"Type" on the org.bluez.Device1 interface.

This is tested with the following steps:
Scan for devices and request the type property of a specific remote device,
using:
  # dbus-send --print-reply --system --dest=org.bluez <obj path> \
    org.freedesktop.DBus.Properties.Get \
      string:org.bluez.Device1 string:Type
or request the type of all remote devices, using:
  # dbus-send --print-reply --system --dest=org.bluez / \
    org.freedesktop.DBus.ObjectManager.GetManagedObjects | \
      grep -B1 -A2 Type
and check for "BR/EDR", "LE", and "DUAL"
---
 doc/device-api.txt |  5 +++++
 src/device.c       | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/doc/device-api.txt b/doc/device-api.txt
index 13b28818e..2f3100cd5 100644
--- a/doc/device-api.txt
+++ b/doc/device-api.txt
@@ -141,6 +141,11 @@ Properties	string Address [readonly]

 			The Bluetooth class of device of the remote device.

+		string Type [readonly, optional]
+
+			The carriers supported by this remote device. If it
+			exists, it can be one of "BR/EDR", "LE", or "DUAL".
+
 		uint16 Appearance [readonly, optional]

 			External appearance of device, as found on GAP service.
diff --git a/src/device.c b/src/device.c
index 8693eb826..14c62e127 100644
--- a/src/device.c
+++ b/src/device.c
@@ -788,6 +788,35 @@ static gboolean dev_property_get_class(const GDBusPropertyTable *property,
 	return TRUE;
 }

+static gboolean dev_property_exists_type(const GDBusPropertyTable *property,
+								void *data)
+{
+	struct btd_device *device = data;
+
+	return device->bredr || device->le;
+}
+
+static gboolean dev_property_get_type(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct btd_device *device = data;
+	const char *type;
+
+	if (!device->bredr && !device->le)
+		return FALSE;
+
+	if (!device->bredr)
+		type = "LE";
+	else if (!device->le)
+		type = "BR/EDR";
+	else
+		type = "DUAL";
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &type);
+
+	return TRUE;
+}
+
 static gboolean get_appearance(const GDBusPropertyTable *property, void *data,
 							uint16_t *appearance)
 {
@@ -2541,6 +2570,8 @@ static const GDBusPropertyTable device_properties[] = {
 	{ "Alias", "s", dev_property_get_alias, dev_property_set_alias },
 	{ "Class", "u", dev_property_get_class, NULL,
 					dev_property_exists_class },
+	{ "Type", "s", dev_property_get_type, NULL,
+					dev_property_exists_type },
 	{ "Appearance", "q", dev_property_get_appearance, NULL,
 					dev_property_exists_appearance },
 	{ "Icon", "s", dev_property_get_icon, NULL,
--
2.11.0.483.g087da7b7c-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread
* [PATCH] device: Add device type property
@ 2020-04-01 22:13 Sonny Sasaka
  2020-04-09 18:11 ` Marcel Holtmann
  0 siblings, 1 reply; 13+ messages in thread
From: Sonny Sasaka @ 2020-04-01 22:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Eric Caruso

From: Eric Caruso <ejcaruso@chromium.org>

This allows us to gather information about whether a device
supports BR/EDR, BLE, or both. It appears as DBus Property
"Type" on the org.bluez.Device1 interface.
---
 doc/device-api.txt |  5 +++++
 src/device.c       | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/doc/device-api.txt b/doc/device-api.txt
index 65d8fee37..ceb68d2f6 100644
--- a/doc/device-api.txt
+++ b/doc/device-api.txt
@@ -158,6 +158,11 @@ Properties	string Address [readonly]
 
 			The Bluetooth class of device of the remote device.
 
+		string Type [readonly, optional]
+
+			The carriers supported by this remote device. If it
+			exists, it can be one of "BR/EDR", "LE", or "DUAL".
+
 		uint16 Appearance [readonly, optional]
 
 			External appearance of device, as found on GAP service.
diff --git a/src/device.c b/src/device.c
index 5f9ad227d..ace9c348c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -849,6 +849,35 @@ static gboolean dev_property_get_class(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean dev_property_exists_type(const GDBusPropertyTable *property,
+								void *data)
+{
+	struct btd_device *device = data;
+
+	return device->bredr || device->le;
+}
+
+static gboolean dev_property_get_type(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct btd_device *device = data;
+	const char *type;
+
+	if (!device->bredr && !device->le)
+		return FALSE;
+
+	if (!device->bredr)
+		type = "LE";
+	else if (!device->le)
+		type = "BR/EDR";
+	else
+		type = "DUAL";
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &type);
+
+	return TRUE;
+}
+
 static gboolean get_appearance(const GDBusPropertyTable *property, void *data,
 							uint16_t *appearance)
 {
@@ -2752,6 +2781,8 @@ static const GDBusPropertyTable device_properties[] = {
 	{ "Alias", "s", dev_property_get_alias, dev_property_set_alias },
 	{ "Class", "u", dev_property_get_class, NULL,
 					dev_property_exists_class },
+	{ "Type", "s", dev_property_get_type, NULL,
+					dev_property_exists_type },
 	{ "Appearance", "q", dev_property_get_appearance, NULL,
 					dev_property_exists_appearance },
 	{ "Icon", "s", dev_property_get_icon, NULL,
-- 
2.24.1


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

end of thread, other threads:[~2020-05-21 16:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-09  1:05 [PATCH] device: Add device type property mcchou
2017-02-09  7:37 ` Marcel Holtmann
2017-02-09  8:07   ` Szymon Janc
2017-02-09  9:40     ` Luiz Augusto von Dentz
2020-04-01 22:13 Sonny Sasaka
2020-04-09 18:11 ` Marcel Holtmann
2020-04-09 21:05   ` Sonny Sasaka
2020-04-10  6:51     ` Marcel Holtmann
2020-05-19 23:12       ` Sonny Sasaka
2020-05-20  6:49         ` Marcel Holtmann
2020-05-21  1:07           ` Sonny Sasaka
2020-05-21  7:01             ` Marcel Holtmann
2020-05-21 16:24               ` Sonny Sasaka

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