All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC BlueZ 0/3] Add TX Power to LE Advertisement API
@ 2015-04-09 17:37 Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 1/3] doc: Add IncludeTXPower to LE Advertising API Michael Janssen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michael Janssen @ 2015-04-09 17:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michael Janssen

Adds a method to add the TX Power attribute to the advertisements that are sent
through the D-Bus interface.

Michael Janssen (3):
  doc: Add IncludeTXPower to LE Advertising API
  core/advertising: Parse IncludeTXPower
  test: add IncludeTXPower to example-advertisement

 doc/advertising-api.txt    |  5 +++++
 src/advertising.c          | 31 ++++++++++++++++++++++++++++++-
 test/example-advertisement |  4 ++++
 3 files changed, 39 insertions(+), 1 deletion(-)

-- 
2.2.0.rc0.207.ga3a616c


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

* [RFC BlueZ 1/3] doc: Add IncludeTXPower to LE Advertising API
  2015-04-09 17:37 [RFC BlueZ 0/3] Add TX Power to LE Advertisement API Michael Janssen
@ 2015-04-09 17:37 ` Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 2/3] core/advertising: Parse IncludeTXPower Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 3/3] test: add IncludeTXPower to example-advertisement Michael Janssen
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Janssen @ 2015-04-09 17:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michael Janssen

---
 doc/advertising-api.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/doc/advertising-api.txt b/doc/advertising-api.txt
index 7fb34ee..54ab106 100644
--- a/doc/advertising-api.txt
+++ b/doc/advertising-api.txt
@@ -61,6 +61,11 @@ Properties	string Type
 			Service Data elements to include. The keys are the
 			UUID to associate with the data.
 
+		bool IncludeTXPower
+
+			Includes the TX Power in the advertising packet.
+			If missing, the TX Power is not included.
+
 
 LE Advertising Manager hierarchy
 ================================
-- 
2.2.0.rc0.207.ga3a616c


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

* [RFC BlueZ 2/3] core/advertising: Parse IncludeTXPower
  2015-04-09 17:37 [RFC BlueZ 0/3] Add TX Power to LE Advertisement API Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 1/3] doc: Add IncludeTXPower to LE Advertising API Michael Janssen
@ 2015-04-09 17:37 ` Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 3/3] test: add IncludeTXPower to example-advertisement Michael Janssen
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Janssen @ 2015-04-09 17:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michael Janssen

Parse the IncludeTXPower property of the advertisement object, and
pass the appropriate flag to MGMT if it is set.
---
 src/advertising.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/advertising.c b/src/advertising.c
index 2f8e539..b8d92e8 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -51,6 +51,9 @@ struct btd_advertising {
 #define AD_TYPE_BROADCAST 0
 #define AD_TYPE_PERIPHERAL 1
 
+#define AD_MAX_LENGTH 31U
+#define AD_TX_POWER_LENGTH 2
+
 struct advertisement {
 	struct btd_advertising *manager;
 	char *owner;
@@ -59,6 +62,7 @@ struct advertisement {
 	GDBusProxy *proxy;
 	DBusMessage *reg;
 	uint8_t type; /* Advertising type */
+	bool include_tx_power;
 	struct bt_ad *data;
 	uint8_t instance;
 };
@@ -361,6 +365,22 @@ fail:
 	return false;
 }
 
+static bool parse_advertising_include_tx_power(GDBusProxy *proxy,
+							bool *included)
+{
+	DBusMessageIter iter;
+
+	if (!g_dbus_proxy_get_property(proxy, "IncludeTXPower", &iter))
+		return true;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
+		return false;
+
+	dbus_message_iter_get_basic(&iter, included);
+
+	return true;
+}
+
 static void add_advertising_callback(uint8_t status, uint16_t length,
 					  const void *param, void *user_data)
 {
@@ -381,12 +401,16 @@ static DBusMessage *refresh_advertisement(struct advertisement *ad)
 	uint8_t param_len;
 	uint8_t *adv_data;
 	size_t adv_data_len;
+	uint8_t ad_space_needed = 0;
 
 	DBG("Refreshing advertisement: %s", ad->path);
 
 	adv_data = bt_ad_generate(ad->data, &adv_data_len);
 
-	if (!adv_data) {
+	if (ad->include_tx_power)
+		ad_space_needed += AD_TX_POWER_LENGTH;
+
+	if (!adv_data || (adv_data_len > (AD_MAX_LENGTH - ad_space_needed))) {
 		error("Advertising data couldn't be generated.");
 
 		return g_dbus_create_error(ad->reg, ERROR_INTERFACE
@@ -409,6 +433,9 @@ static DBusMessage *refresh_advertisement(struct advertisement *ad)
 	if (ad->type == AD_TYPE_PERIPHERAL)
 		cp->flags = MGMT_ADV_FLAG_CONNECTABLE | MGMT_ADV_FLAG_DISCOV;
 
+	if (ad->include_tx_power)
+		cp->flags |= MGMT_ADV_FLAG_TX_POWER;
+
 	cp->instance = ad->instance;
 	cp->adv_data_len = adv_data_len;
 	memcpy(cp->data, adv_data, adv_data_len);
@@ -457,6 +484,8 @@ static DBusMessage *parse_advertisement(struct advertisement *ad)
 		goto fail;
 	}
 
+	parse_advertising_include_tx_power(ad->proxy, &ad->include_tx_power);
+
 	return refresh_advertisement(ad);
 
 fail:
-- 
2.2.0.rc0.207.ga3a616c


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

* [RFC BlueZ 3/3] test: add IncludeTXPower to example-advertisement
  2015-04-09 17:37 [RFC BlueZ 0/3] Add TX Power to LE Advertisement API Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 1/3] doc: Add IncludeTXPower to LE Advertising API Michael Janssen
  2015-04-09 17:37 ` [RFC BlueZ 2/3] core/advertising: Parse IncludeTXPower Michael Janssen
@ 2015-04-09 17:37 ` Michael Janssen
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Janssen @ 2015-04-09 17:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michael Janssen

---
 test/example-advertisement | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/test/example-advertisement b/test/example-advertisement
index 6e47391..1198f2e 100755
--- a/test/example-advertisement
+++ b/test/example-advertisement
@@ -51,6 +51,7 @@ class Advertisement(dbus.service.Object):
         self.manufacturer_data = None
         self.solicit_uuids = None
         self.service_data = None
+        self.include_tx_power = None
         dbus.service.Object.__init__(self, bus, self.path)
 
     def get_properties(self):
@@ -68,6 +69,8 @@ class Advertisement(dbus.service.Object):
         if self.service_data is not None:
             properties['ServiceData'] = dbus.Dictionary(self.service_data,
                                                         signature='say')
+        if self.include_tx_power is not None:
+            properties['IncludeTXPower'] = dbus.Boolean(self.include_tx_power)
         return {LE_ADVERTISEMENT_IFACE: properties}
 
     def get_path(self):
@@ -117,6 +120,7 @@ class TestAdvertisement(Advertisement):
         self.add_service_uuid('180F')
         self.add_manufacturer_data(0xffff, [0x00, 0x01, 0x02, 0x03, 0x04])
         self.add_service_data('9999', [0x00, 0x01, 0x02, 0x03, 0x04])
+        self.include_tx_power = True
 
 
 def register_ad_cb():
-- 
2.2.0.rc0.207.ga3a616c


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

end of thread, other threads:[~2015-04-09 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 17:37 [RFC BlueZ 0/3] Add TX Power to LE Advertisement API Michael Janssen
2015-04-09 17:37 ` [RFC BlueZ 1/3] doc: Add IncludeTXPower to LE Advertising API Michael Janssen
2015-04-09 17:37 ` [RFC BlueZ 2/3] core/advertising: Parse IncludeTXPower Michael Janssen
2015-04-09 17:37 ` [RFC BlueZ 3/3] test: add IncludeTXPower to example-advertisement Michael Janssen

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.