From e4dae82fb742a3e568aaed2dfb65a123441d92ca Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 14 Jul 2017 17:06:22 +0300 Subject: [PATCH] core/advertisement: Add specifc error if max instance is reached Returning generic error may confuse the application using RegisterAdvertisement: https://bugs.chromium.org/p/chromium/issues/detail?id=741056#c4 --- doc/advertising-api.txt | 18 +++++++++++++----- src/advertising.c | 13 ++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/doc/advertising-api.txt b/doc/advertising-api.txt index 1c18ae31e..8207b5934 100644 --- a/doc/advertising-api.txt +++ b/doc/advertising-api.txt @@ -82,19 +82,27 @@ Methods RegisterAdvertisement(object advertisement, dict options) Registers an advertisement object to be sent over the LE Advertising channel. The service must be exported - under interface LEAdvertisement1. InvalidArguments - indicates that the object has invalid or conflicting - properties. InvalidLength indicates that the data + under interface LEAdvertisement1. + + InvalidArguments error indicates that the object has + invalid or conflicting properties. + + InvalidLength error indicates that the data provided generates a data packet which is too long. + The properties of this object are parser when it is registered, and any changes are ignored. - Currently only one advertisement at a time is supported, - attempting to register two advertisements will result in + + If the same object is registered twice it will result in an AlreadyExists error. + If the maximum number of advertisement instances is + reached it will result in NotPermitted error. + Possible errors: org.bluez.Error.InvalidArguments org.bluez.Error.AlreadyExists org.bluez.Error.InvalidLength + org.bluez.Error.NotPermitted UnregisterAdvertisement(object advertisement) diff --git a/src/advertising.c b/src/advertising.c index de07a98f9..1bea0d177 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -627,11 +627,6 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager, if (!client->data) goto fail; - client->instance = util_get_uid(&manager->instance_bitmap, - manager->max_ads); - if (!client->instance) - goto fail; - client->manager = manager; return client; @@ -675,6 +670,14 @@ static DBusMessage *register_advertisement(DBusConnection *conn, return btd_error_failed(msg, "Failed to register advertisement"); + client->instance = util_get_uid(&manager->instance_bitmap, + manager->max_ads); + if (!client->instance) { + client_free(client); + return btd_error_not_permitted(msg, + "Maximum advertisements reached"); + } + DBG("Registered advertisement at path %s", match.path); queue_push_tail(manager->clients, client); -- 2.47.3