1 From 31fafe0dd2265cd181734ee909554f24fd3c3c20 Mon Sep 17 00:00:00 2001
2 From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
3 Date: Fri, 26 Jun 2015 14:52:22 +0300
4 Subject: [PATCH] core/advertising: Fix using wrong instance id
6 The instance id shall be limited to the number of instance the kernel
7 support, and since this will probably be quite small the ids should be
8 reused once the client unregistered.
10 src/advertising.c | 12 +++++++-----
11 1 file changed, 7 insertions(+), 5 deletions(-)
13 diff --git a/src/advertising.c b/src/advertising.c
14 index d6ab084..3763d85 100644
15 --- a/src/advertising.c
16 +++ b/src/advertising.c
17 @@ -48,7 +48,7 @@ struct btd_advertising {
21 - unsigned int next_instance_id;
22 + unsigned int instance_bitmap;
25 #define AD_TYPE_BROADCAST 0
26 @@ -155,6 +155,8 @@ static void advertisement_remove(void *data)
28 queue_remove(ad->manager->ads, ad);
30 + util_clear_uid(&ad->manager->instance_bitmap, ad->instance);
32 g_idle_add(advertisement_free_idle_cb, ad);
35 @@ -633,6 +635,7 @@ static DBusMessage *register_advertisement(DBusConnection *conn,
37 struct advertisement *ad;
38 struct dbus_obj_match match;
41 DBG("RegisterAdvertisement");
43 @@ -649,7 +652,8 @@ static DBusMessage *register_advertisement(DBusConnection *conn,
44 if (queue_find(manager->ads, match_advertisement, &match))
45 return btd_error_already_exists(msg);
47 - if (queue_length(manager->ads) >= manager->max_ads)
48 + instance = util_get_uid(&manager->instance_bitmap, manager->max_ads);
50 return btd_error_failed(msg, "Maximum advertisements reached");
52 dbus_message_iter_next(&args);
53 @@ -664,7 +668,7 @@ static DBusMessage *register_advertisement(DBusConnection *conn,
55 DBG("Registered advertisement at path %s", match.path);
57 - ad->instance = manager->next_instance_id++;
58 + ad->instance = instance;
59 ad->manager = manager;
61 queue_push_tail(manager->ads, ad);
62 @@ -787,8 +791,6 @@ advertising_manager_create(struct btd_adapter *adapter)
64 manager->ads = queue_new();
66 - manager->next_instance_id = 1;