doc/advertising-api: Add Duration and Timeout
Luiz Augusto von Dentz
maintainerPATCH v2 1/7 doc/advertising-api: Add Duration and Timeout
From: Luiz Augusto von Dentz <[email protected]>
This adds duration and timeout so application can control the periods which the advertisement stays active.
--- doc/advertising-api.txt | 11 +++++++++++ 1 file changed, 11 insertions(+)
doc/advertising-api.txt +11 -0
@@ -84,6 +84,17 @@ Properties string Type Possible values: as found on GAP Service. + uint16_t Duration + + Duration of the advertisement in seconds. If there are + other applications advertising no duration is set the + default is 2 seconds. + + uint16_t Timeout + + Timeout of the advertisement in seconds. This defines + the lifetime of the advertisement. + LE Advertising Manager hierarchy ================================
Signature · 1 line
2.13.6
Luiz Augusto von Dentz
maintainerPATCH v2 2/7 advertising: Add implementation of Duration and Timeout
From: Luiz Augusto von Dentz <[email protected]>
This adds implementation of Duration and Timeout property and properly set them in Add Advertising:
@ MGMT Command: Add Advertising (0x003e) plen 11
Instance: 1
Flags: 0x00000003
Switch into Connectable mode
Advertise as Discoverable
Duration: 4
Timeout: 0
Advertising data length: 0
Scan response length: 0
--- src/advertising.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
src/advertising.c +51 -0
@@ -64,6 +64,9 @@ struct btd_adv_client {char *path;char *name;uint16_t appearance; +uint16_t duration; +uint16_t timeout; +unsigned int to_id;GDBusClient *client;GDBusProxy *proxy;DBusMessage *reg;
@@ -97,6 +100,9 @@ static void client_free(void *data) {struct btd_adv_client *client = data; +if (client->to_id >0 ) +g_source_remove (client->to_id); +if (client->client) {g_dbus_client_set_disconnect_watch (client->client,NULL ,NULL );g_dbus_client_unref (client->client);
@@ -491,6 +497,48 @@ static bool parse_appearance(DBusMessageIter *iter,return true; } +static bool parse_duration (DBusMessageIter *iter, +struct btd_adv_client *client) +{ +if (dbus_message_iter_get_arg_type (iter) !=DBUS_TYPE_UINT16 ) +return false; + +dbus_message_iter_get_basic (iter, &client->duration); + +return true; +} + +static gboolean client_timeout (void *user_data) +{ +struct btd_adv_client *client = user_data; + +DBG ("" ); + + client->to_id =0 ; + +client_release (client); +client_remove (client); + +return FALSE; +} + +static bool parse_timeout (DBusMessageIter *iter, +struct btd_adv_client *client) +{ +if (dbus_message_iter_get_arg_type (iter) !=DBUS_TYPE_UINT16 ) +return false; + +dbus_message_iter_get_basic (iter, &client->timeout); + +if (client->to_id) +g_source_remove (client->to_id); + + client->to_id =g_timeout_add_seconds (client->timeout, client_timeout, + client); + +return true; +} + static struct adv_parser { const char *name; bool (*func)(DBusMessageIter *iter, struct btd_adv_client *client);
@@ -503,6 +551,8 @@ static struct adv_parser { { "Includes", parse_includes }, { "LocalName", parse_local_name }, { "Appearance", parse_appearance }, + { "Duration", parse_duration }, + { "Timeout", parse_timeout }, { }, };
@@ -611,6 +661,7 @@ static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func) cp->flags =htobl (flags); cp->instance = client->instance; + cp->duration = client->duration; cp->adv_data_len = adv_data_len; cp->scan_rsp_len = scan_rsp_len;memcpy (cp->data, adv_data, adv_data_len);
Signature · 1 line
2.13.6
Luiz Augusto von Dentz
maintainerPATCH v2 3/7 client: Add set-advertise-{duration, timeout}
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds the following command which can be used to control the advertisement intervals:
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances: 0x04 [CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances: 0x01 Advertising object registered
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances: 0x05 [CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances: 0x00
--- client/advertising.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ client/advertising.h | 2 ++ client/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+)
client/advertising.c +50 -0
@@ -59,6 +59,8 @@ static struct ad {char *type;char *local_name;uint16_t local_appearance; +uint16_t duration; +uint16_t timeout;char **uuids;size_t uuids_len;struct service_data service;
@@ -323,6 +325,32 @@ static gboolean get_appearance(const GDBusPropertyTable *property,return TRUE; } +static gboolean duration_exits (const GDBusPropertyTable *property,void *data) +{ +return ad.duration; +} + +static gboolean get_duration (const GDBusPropertyTable *property, +DBusMessageIter *iter,void *user_data) +{ +dbus_message_iter_append_basic (iter,DBUS_TYPE_UINT16 , &ad.duration); + +return TRUE; +} + +static gboolean timeout_exits (const GDBusPropertyTable *property,void *data) +{ +return ad.timeout; +} + +static gboolean get_timeout (const GDBusPropertyTable *property, +DBusMessageIter *iter,void *user_data) +{ +dbus_message_iter_append_basic (iter,DBUS_TYPE_UINT16 , &ad.timeout); + +return TRUE; +} +static const GDBusPropertyTable ad_props[] = { {"Type" ,"s" , get_type }, {"ServiceUUIDs" ,"as" , get_uuids,NULL , uuids_exists },
@@ -332,6 +360,8 @@ static const GDBusPropertyTable ad_props[] = { { "Includes", "as", get_includes, NULL, includes_exists }, { "LocalName", "s", get_local_name, NULL, local_name_exits }, { "Appearance", "q", get_appearance, NULL, appearance_exits }, + { "Duration", "q", get_duration, NULL, duration_exits }, + { "Timeout", "q", get_timeout, NULL, timeout_exits }, { } };
@@ -592,3 +622,23 @@ void ad_advertise_local_appearance(DBusConnection *conn, uint16_t value)g_dbus_emit_property_changed (conn,AD_PATH ,AD_IFACE ,"Appearance" ); } + +void ad_advertise_duration (DBusConnection *conn,uint16_t value) +{ +if (ad.duration == value) +return ; + + ad.duration = value; + +g_dbus_emit_property_changed (conn,AD_PATH ,AD_IFACE ,"Duration" ); +} + +void ad_advertise_timeout (DBusConnection *conn,uint16_t value) +{ +if (ad.timeout == value) +return ; + + ad.timeout = value; + +g_dbus_emit_property_changed (conn,AD_PATH ,AD_IFACE ,"Timeout" ); +}
client/advertising.h +2 -0
@@ -32,3 +32,5 @@ void ad_advertise_name(DBusConnection *conn, bool value);void ad_advertise_appearance (DBusConnection *conn,bool value);void ad_advertise_local_name (DBusConnection *conn,const char *name);void ad_advertise_local_appearance (DBusConnection *conn,uint16_t value); +void ad_advertise_duration (DBusConnection *conn,uint16_t value); +void ad_advertise_timeout (DBusConnection *conn,uint16_t value);
client/main.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.13.6
Re: [PATCH v2 3/7] client: Add set-advertise-{duration, timeout}
Hi Luiz,
With the latest bluez master branch, when sets a advertise timeout and times out, bluetoothctl fails to run "advertise off" as below:
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller 00:09:DD:40:CA:12 SupportedInstances: 0x04 [CHG] Controller 00:09:DD:40:CA:12 ActiveInstances: 0x01 Advertising object registered
[CHG] Controller 00:09:DD:40:CA:12 SupportedInstances: 0x05 [CHG] Controller 00:09:DD:40:CA:12 ActiveInstances: 0x00 [bluetooth]# advertise off
Failed to unregister advertisement: org.bluez.Error.DoesNotExist
Regards,
Eramoto
Quoted 18 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the following command which can be used to control the advertisement intervals:
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances:0x04[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances:0x01Advertising object registered
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances:0x05[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances:0x00--- client/advertising.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ client/advertising.h | 2 ++ client/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+)
Luiz Augusto von Dentz
maintainerRe: [PATCH v2 3/7] client: Add set-advertise-{duration, timeout}
Hi Eramoto,
Quoted 5 lines · ERAMOTO Masaya
Hi Luiz,
With the latest bluez master branch, when sets a advertise timeout and times out, bluetoothctl fails to run "advertise off" as below:
Quoted 10 lines
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller 00:09:DD:40:CA:12 SupportedInstances:0x04[CHG] Controller 00:09:DD:40:CA:12 ActiveInstances:0x01Advertising object registered
[CHG] Controller 00:09:DD:40:CA:12 SupportedInstances:0x05[CHG] Controller 00:09:DD:40:CA:12 ActiveInstances:0x00[bluetooth]# advertise off
Failed to unregister advertisement: org.bluez.Error.DoesNotExist
In order for bluetoothd to call Release method you will need to update the bluetooth.conf D-Bus policy, without that the client has no idea when the its instance is removed due to timeout causing the problem above.
Quoted 24 lines
Regards,
EramotoQuoted 18 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the following command which can be used to control the advertisement intervals:
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances:0x04[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances:0x01Advertising object registered
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances:0x05[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances:0x00--- client/advertising.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ client/advertising.h | 2 ++ client/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+)
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH v2 3/7] client: Add set-advertise-{duration, timeout}
Hi Luiz,
Thank you for your help.
I hit this problem because my bluetooth.conf was old.
Regards,
Eramoto
Quoted 52 lines · Luiz Augusto von Dentz
Hi Eramoto,
Quoted 5 lines · ERAMOTO Masaya
Hi Luiz,
With the latest bluez master branch, when sets a advertise timeout and times out, bluetoothctl fails to run "advertise off" as below:
Quoted 10 lines
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller 00:09:DD:40:CA:12 SupportedInstances:0x04[CHG] Controller 00:09:DD:40:CA:12 ActiveInstances:0x01Advertising object registered
[CHG] Controller 00:09:DD:40:CA:12 SupportedInstances:0x05[CHG] Controller 00:09:DD:40:CA:12 ActiveInstances:0x00[bluetooth]# advertise off
Failed to unregister advertisement: org.bluez.Error.DoesNotExistIn order for bluetoothd to call Release method you will need to update the bluetooth.conf D-Bus policy, without that the client has no idea when the its instance is removed due to timeout causing the problem above.
Quoted 24 lines
Regards,
EramotoQuoted 18 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds the following command which can be used to control the advertisement intervals:
[bluetooth]# set-advertise-duration 4
[bluetooth]# set-advertise-timeout 4
[bluetooth]# advertise on
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances:0x04[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances:0x01Advertising object registered
[CHG] Controller B8:8A:60:D8:17:D7 SupportedInstances:0x05[CHG] Controller B8:8A:60:D8:17:D7 ActiveInstances:0x00--- client/advertising.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ client/advertising.h | 2 ++ client/main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+)
Luiz Augusto von Dentz
maintainerPATCH v2 4/7 advertising: Use client proxy to release
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This uses g_dbus_proxy_method_call instead of build the message manually.
--- src/advertising.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
src/advertising.c +2 -11
@@ -137,20 +137,11 @@ static gboolean client_free_idle_cb(void *data)static void client_release (void *data) {struct btd_adv_client *client = data; -DBusMessage *message;DBG ("Releasing advertisement %s, %s" , client->owner, client->path); - message =dbus_message_new_method_call (client->owner, client->path, -LE_ADVERTISEMENT_IFACE , -"Release" ); - -if (!message) { -error ("Couldn't allocate D-Bus message" ); -return ; - } - -g_dbus_send_message (btd_get_dbus_connection (), message); +g_dbus_proxy_method_call (client->proxy,"Release" ,NULL ,NULL ,NULL , +NULL ); }static void client_destroy (void *data)
Signature · 1 line
2.13.6
Luiz Augusto von Dentz
maintainerPATCH v2 5/7 core: Add LEAdvertisement1 to bluetooth.conf
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
LEAdvertisement1 must be included in order to be able to call Release.
--- src/bluetooth.conf | 1 + 1 file changed, 1 insertion(+)
src/bluetooth.conf +1 -0
@@ -20,6 +20,7 @@ <allow send_interface="org.bluez.CyclingSpeedWatcher1"/> <allow send_interface="org.bluez.GattCharacteristic1"/> <allow send_interface="org.bluez.GattDescriptor1"/> + <allow send_interface="org.bluez.LEAdvertisement1"/> <allow send_interface="org.freedesktop.DBus.ObjectManager"/> <allow send_interface="org.freedesktop.DBus.Properties"/> </policy>
Signature · 1 line
2.13.6
Luiz Augusto von Dentz
maintainerPATCH v2 6/7 core: Cleanup bluetooth.conf
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This removes interfaces that no longer exists.
--- src/bluetooth.conf | 4 ---- 1 file changed, 4 deletions(-)
src/bluetooth.conf +0 -4
@@ -13,11 +13,7 @@ <allow send_interface="org.bluez.Agent1"/> <allow send_interface="org.bluez.MediaEndpoint1"/> <allow send_interface="org.bluez.MediaPlayer1"/> - <allow send_interface="org.bluez.ThermometerWatcher1"/> - <allow send_interface="org.bluez.AlertAgent1"/> <allow send_interface="org.bluez.Profile1"/> - <allow send_interface="org.bluez.HeartRateWatcher1"/> - <allow send_interface="org.bluez.CyclingSpeedWatcher1"/> <allow send_interface="org.bluez.GattCharacteristic1"/> <allow send_interface="org.bluez.GattDescriptor1"/> <allow send_interface="org.bluez.LEAdvertisement1"/>
Signature · 1 line
2.13.6
Luiz Augusto von Dentz
maintainerPATCH v2 7/7 tests: Remove test-thermometer
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Thermomether interfaces no longer exists.
--- test/test-thermometer | 99 --------------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100755 test/test-thermometer
test/test-thermometer deleted +0 -99
@@ -1,99 +0,0 @@ -#!/usr/bin/python - -from __future__ import absolute_import, print_function, unicode_literals - -''' -Thermometer test script -''' - -from optparse import OptionParser, make_option -import sys -import dbus -import dbus.service -import dbus.mainloop.glib -try: - from gi.repository import GObject -except ImportError: - import gobject as GObject -import bluezutils - -BUS_NAME = 'org.bluez' -THERMOMETER_MANAGER_INTERFACE = 'org.bluez.ThermometerManager1' -THERMOMETER_WATCHER_INTERFACE = 'org.bluez.ThermometerWatcher1' -THERMOMETER_INTERFACE = 'org.bluez.Thermometer1' - -class Watcher(dbus.service.Object): - @dbus.service.method(THERMOMETER_WATCHER_INTERFACE, - in_signature="oa{sv}", out_signature="") - def MeasurementReceived(self, device, measure): - print("%s measurement received from %s" % (measure["Measurement"], device)) - print("Exponent: ", measure["Exponent"]) - print("Mantissa: ", measure["Mantissa"]) - print("Unit: ", measure["Unit"]) - - if "Time" in measure: - print("Time: ", measure["Time"]) - - if "Type" in measure: - print("Type: ", measure["Type"]) - -def properties_changed(interface, changed, invalidated): - if interface != THERMOMETER_INTERFACE: - return - for name, value in changed.iteritems(): - print("Property %s changed: %s" % (name, str(value))) - -if __name__ == "__main__": - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - - bus = dbus.SystemBus() - - option_list = [ - make_option("-i", "--adapter", action="store", - type="string", dest="adapter"), - make_option("-b", "--device", action="store", - type="string", dest="address"), - ] - - parser = OptionParser(option_list=option_list) - - (options, args) = parser.parse_args() - - if not options.address: - print("Usage: %s [-i <adapter>] -b <bdaddr> [command]" % (sys.argv[0])) - print("Possible commands:") - print("\tEnableIntermediateMeasurement") - sys.exit(1) - - managed_objects = bluezutils.get_managed_objects() - adapter = bluezutils.find_adapter_in_objects(managed_objects, - options.adapter) - adapter_path = adapter.object_path - - thermometer_manager = dbus.Interface(bus.get_object(BUS_NAME, - adapter_path), THERMOMETER_MANAGER_INTERFACE) - - device = bluezutils.find_device_in_objects(managed_objects, - options.address, - options.adapter) - device_path = device.object_path - - bus.add_signal_receiver(properties_changed, bus_name=BUS_NAME, - path=device_path, - dbus_interface="org.freedesktop.DBus.Properties", - signal_name="PropertiesChanged") - - path = "/test/watcher" - watcher = Watcher(bus, path) - - thermometer_manager.RegisterWatcher(path) - - if len(args) > 0: - if args[0] == "EnableIntermediateMeasurement": - thermometer_manager.EnableIntermediateMeasurement(path) - else: - print("unknown command") - sys.exit(1) - - mainloop = GObject.MainLoop() - mainloop.run()
Signature · 1 line
2.13.6
Hi,
Quoted 31 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds duration and timeout so application can control the periods which the advertisement stays active.
--- doc/advertising-api.txt | 11 +++++++++++ 1 file changed, 11 insertions(+)doc/advertising-api.txt +11
-1@@ -84,6 +84,17 @@ Properties string Type Possible values: as found on GAP Service. + uint16_t Duration + + Duration of the advertisement in seconds. If there are + other applications advertising no duration is set the + default is 2 seconds. + + uint16_t Timeout + + Timeout of the advertisement in seconds. This defines + the lifetime of the advertisement. + LE Advertising Manager hierarchy ================================ --
Quoted 1 line
2.13.6
Applied.
Signature · 1 line
Luiz Augusto von Dentz