2015-06-26 12:00:03

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ] core/advertising: Fix using wrong instance id

From: Luiz Augusto von Dentz <[email protected]>

The instance id shall be limited to the number of instance the kernel
support, and since this will probably be quite small the ids should be
reused once the client unregistered.
---
src/advertising.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/advertising.c b/src/advertising.c
index ab5c6fc..d56b7a2 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -48,7 +48,7 @@ struct btd_advertising {
uint16_t mgmt_index;
uint8_t max_adv_len;
uint8_t max_ads;
- unsigned int next_instance_id;
+ unsigned int instance_bitmap;
};

#define AD_TYPE_BROADCAST 0
@@ -155,6 +155,8 @@ static void advertisement_remove(void *data)

queue_remove(ad->manager->ads, ad);

+ util_clear_uid(&ad->manager->instance_bitmap, ad->instance);
+
g_idle_add(advertisement_free_idle_cb, ad);
}

@@ -633,6 +635,7 @@ static DBusMessage *register_advertisement(DBusConnection *conn,
DBusMessageIter args;
struct advertisement *ad;
struct dbus_obj_match match;
+ uint8_t instance;

DBG("RegisterAdvertisement");

@@ -649,7 +652,8 @@ static DBusMessage *register_advertisement(DBusConnection *conn,
if (queue_find(manager->ads, match_advertisement, &match))
return btd_error_already_exists(msg);

- if (queue_length(manager->ads) >= manager->max_ads)
+ instance = util_get_uid(&manager->instance_bitmap, manager->max_ads);
+ if (!instance)
return btd_error_failed(msg, "Maximum advertisements reached");

dbus_message_iter_next(&args);
@@ -664,7 +668,7 @@ static DBusMessage *register_advertisement(DBusConnection *conn,

DBG("Registered advertisement at path %s", match.path);

- ad->instance = manager->next_instance_id++;
+ ad->instance = instance;
ad->manager = manager;

queue_push_tail(manager->ads, ad);
@@ -786,8 +790,6 @@ advertising_manager_create(struct btd_adapter *adapter)

manager->ads = queue_new();

- manager->next_instance_id = 1;
-
return manager;
}

--
2.1.0



2015-06-29 07:59:59

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core/advertising: Fix using wrong instance id

Hi,

On Fri, Jun 26, 2015 at 10:33 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Ossama,
>
> On Fri, Jun 26, 2015 at 9:08 PM, Othman, Ossama <[email protected]> wrote:
>> Hi Luiz,
>>
>> On Fri, Jun 26, 2015 at 5:00 AM, Luiz Augusto von Dentz
>> <[email protected]> wrote:
>>> From: Luiz Augusto von Dentz <[email protected]>
>>>
>>> The instance id shall be limited to the number of instance the kernel
>>> support, and since this will probably be quite small the ids should be
>>> reused once the client unregistered.
>>> ---
>>> src/advertising.c | 12 +++++++-----
>>> 1 file changed, 7 insertions(+), 5 deletions(-)
>>> ...
>>
>> This patch appears to address the problem I was seeing with the failed
>> advertisement registration. With it in place I'm able to repeatedly
>> register/unregister my advertisement without problem.
>
> I will probably apply it tomorrow to give people some time to try it,
> but Im quite sure this will be the final version.
>
>
> --
> Luiz Augusto von Dentz

Applied.

--
Luiz Augusto von Dentz

2015-06-26 19:33:33

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core/advertising: Fix using wrong instance id

Hi Ossama,

On Fri, Jun 26, 2015 at 9:08 PM, Othman, Ossama <[email protected]> wrote:
> Hi Luiz,
>
> On Fri, Jun 26, 2015 at 5:00 AM, Luiz Augusto von Dentz
> <[email protected]> wrote:
>> From: Luiz Augusto von Dentz <[email protected]>
>>
>> The instance id shall be limited to the number of instance the kernel
>> support, and since this will probably be quite small the ids should be
>> reused once the client unregistered.
>> ---
>> src/advertising.c | 12 +++++++-----
>> 1 file changed, 7 insertions(+), 5 deletions(-)
>> ...
>
> This patch appears to address the problem I was seeing with the failed
> advertisement registration. With it in place I'm able to repeatedly
> register/unregister my advertisement without problem.

I will probably apply it tomorrow to give people some time to try it,
but Im quite sure this will be the final version.


--
Luiz Augusto von Dentz

2015-06-26 18:08:12

by Othman, Ossama

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core/advertising: Fix using wrong instance id

Hi Luiz,

On Fri, Jun 26, 2015 at 5:00 AM, Luiz Augusto von Dentz
<[email protected]> wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> The instance id shall be limited to the number of instance the kernel
> support, and since this will probably be quite small the ids should be
> reused once the client unregistered.
> ---
> src/advertising.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
> ...

This patch appears to address the problem I was seeing with the failed
advertisement registration. With it in place I'm able to repeatedly
register/unregister my advertisement without problem.

Thanks!
-Ossama