diff options
author | Michael Janssen <jamuraa@chromium.org> | 2015-04-14 15:06:59 -0700 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-04-16 17:59:30 +0300 |
commit | 13e2a65eee65f32911016173f43ce76246d29861 (patch) | |
tree | 273618612b4ab89ecded0ba4583732a095a38bc6 /src | |
parent | 3182329ba514ca84eb5820bd6795fad84c55f32e (diff) | |
download | bluez-13e2a65eee65f32911016173f43ce76246d29861.tar.gz |
core/advertising: Support more than one advertisement.
Use the Read Advertising Features response to determine the maximum
number of advertisements, and limit the number of advertisements based
on this.
Diffstat (limited to 'src')
-rw-r--r-- | src/advertising.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/advertising.c b/src/advertising.c index 8e803cb41..46de9b48d 100644 --- a/src/advertising.c +++ b/src/advertising.c @@ -47,6 +47,8 @@ struct btd_advertising { struct mgmt *mgmt; uint16_t mgmt_index; uint8_t max_adv_len; + uint8_t max_ads; + unsigned int next_instance_id; }; #define AD_TYPE_BROADCAST 0 @@ -570,8 +572,6 @@ static struct advertisement *advertisement_create(DBusConnection *conn, if (!ad) return NULL; - ad->instance = 1; - ad->client = g_dbus_client_new_full(conn, sender, path, path); if (!ad->client) goto fail; @@ -629,9 +629,8 @@ static DBusMessage *register_advertisement(DBusConnection *conn, if (queue_find(manager->ads, match_advertisement, &match)) return btd_error_already_exists(msg); - /* TODO: support more than one advertisement */ - if (!queue_isempty(manager->ads)) - return btd_error_failed(msg, "Already advertising"); + if (queue_length(manager->ads) >= manager->max_ads) + return btd_error_failed(msg, "Maximum advertisements reached"); dbus_message_iter_next(&args); @@ -645,7 +644,9 @@ static DBusMessage *register_advertisement(DBusConnection *conn, DBG("Registered advertisement at path %s", match.path); + ad->instance = manager->next_instance_id++; ad->manager = manager; + queue_push_tail(manager->ads, ad); return NULL; @@ -722,6 +723,7 @@ static void read_adv_features_callback(uint8_t status, uint16_t length, } manager->max_adv_len = feat->max_adv_data_len; + manager->max_ads = feat->max_instances; } static struct btd_advertising * @@ -765,6 +767,8 @@ advertising_manager_create(struct btd_adapter *adapter) manager->ads = queue_new(); + manager->next_instance_id = 1; + return manager; } |