2012-04-19 11:48:31

by Hemant Gupta

[permalink] [raw]
Subject: [PATCH BlueZ] Store LE device address type with primary list

This patch fixes the address type used for re-creating device from primary
service database.
---
src/adapter.c | 8 ++++++--
src/device.c | 9 +++++++--
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 12b6aeb..e51a5ab 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1920,13 +1920,17 @@ static void create_stored_device_from_primary(char *key, char *value,
struct btd_adapter *adapter = user_data;
struct btd_device *device;
GSList *services, *uuids, *l;
+ addr_type_t addr_type;

if (g_slist_find_custom(adapter->devices,
key, (GCompareFunc) device_address_cmp))
return;

- /* FIXME: Get the correct LE addr type (public/random) */
- device = device_create(connection, adapter, key, ADDR_TYPE_LE_PUBLIC);
+ sscanf(value, "%d ", &addr_type);
+ /* Increment by 2 (address type and space) */
+ value += 2;
+
+ device = device_create(connection, adapter, key, addr_type);
if (!device)
return;

diff --git a/src/device.c b/src/device.c
index ea6fec2..9c15d28 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1748,14 +1748,19 @@ static void store_services(struct btd_device *device)
{
struct btd_adapter *adapter = device->adapter;
bdaddr_t dba, sba;
- char *str = primary_list_to_string(device->primaries);
+ addr_type_t addr_type;
+ char *primary = primary_list_to_string(device->primaries);
+ /* Allocate extra space for address type, space and \0 */
+ char *str = g_malloc(strlen(primary) + 2 + 1);

adapter_get_address(adapter, &sba);
- device_get_address(device, &dba, NULL);
+ device_get_address(device, &dba, &addr_type);
+ sprintf(str, "%d %s", addr_type, primary);

write_device_services(&sba, &dba, str);

g_free(str);
+ g_free(primary);
}

static void attio_connected(gpointer data, gpointer user_data)
--
1.7.0.4



2012-04-21 08:17:06

by Hemant Gupta

[permalink] [raw]
Subject: Re: [PATCH BlueZ] Store LE device address type with primary list

Hi Anderson,

On Fri, Apr 20, 2012 at 11:09 PM, Anderson Lizardo
<[email protected]> wrote:
> Hi Hemant,
>
> On Thu, Apr 19, 2012 at 7:48 AM, Hemant Gupta
> <[email protected]> wrote:
>> @@ -1920,13 +1920,17 @@ static void create_stored_device_from_primary(char *key, char *value,
>> ? ? ? ?struct btd_adapter *adapter = user_data;
>> ? ? ? ?struct btd_device *device;
>> ? ? ? ?GSList *services, *uuids, *l;
>> + ? ? ? addr_type_t addr_type;
>>
>> ? ? ? ?if (g_slist_find_custom(adapter->devices,
>> ? ? ? ? ? ? ? ? ? ? ? ?key, (GCompareFunc) device_address_cmp))
>> ? ? ? ? ? ? ? ?return;
>>
>> - ? ? ? /* FIXME: Get the correct LE addr type (public/random) */
>> - ? ? ? device = device_create(connection, adapter, key, ADDR_TYPE_LE_PUBLIC);
>> + ? ? ? sscanf(value, "%d ", &addr_type);
>> + ? ? ? /* Increment by 2 (address type and space) */
>> + ? ? ? value += 2;
>
> I think it is a good idea to check for sscanf() return and if it
> fails, assume addr_type as ADDR_TYPE_LE_PUBLIC the value as primary
> data only. Remember that the system may have previously stored primary
> data in the old format.
>
Thanks, will update this in next patch.

>> +
>> + ? ? ? device = device_create(connection, adapter, key, addr_type);
>> ? ? ? ?if (!device)
>> ? ? ? ? ? ? ? ?return;
>>
>
>
> Are you planning to add support for other address types in BlueZ GATT
> server? It would be nice if you could share your plans on this topic.

For the moment no. I was testing with Nordic device which has random
device address
type, and found this issue when trying to connect to nordic device
again after rebooting
our device. Since BlueZ creates the stored device from primary and was
taking address
type as Public, reconnection was not possible.

>
> Best Regards,
> --
> Anderson Lizardo
> Instituto Nokia de Tecnologia - INdT
> Manaus - Brazil
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html



--
Best Regards
Hemant Gupta
ST-Ericsson India

2012-04-20 17:39:59

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [PATCH BlueZ] Store LE device address type with primary list

Hi Hemant,

On Thu, Apr 19, 2012 at 7:48 AM, Hemant Gupta
<[email protected]> wrote:
> @@ -1920,13 +1920,17 @@ static void create_stored_device_from_primary(char *key, char *value,
> ? ? ? ?struct btd_adapter *adapter = user_data;
> ? ? ? ?struct btd_device *device;
> ? ? ? ?GSList *services, *uuids, *l;
> + ? ? ? addr_type_t addr_type;
>
> ? ? ? ?if (g_slist_find_custom(adapter->devices,
> ? ? ? ? ? ? ? ? ? ? ? ?key, (GCompareFunc) device_address_cmp))
> ? ? ? ? ? ? ? ?return;
>
> - ? ? ? /* FIXME: Get the correct LE addr type (public/random) */
> - ? ? ? device = device_create(connection, adapter, key, ADDR_TYPE_LE_PUBLIC);
> + ? ? ? sscanf(value, "%d ", &addr_type);
> + ? ? ? /* Increment by 2 (address type and space) */
> + ? ? ? value += 2;

I think it is a good idea to check for sscanf() return and if it
fails, assume addr_type as ADDR_TYPE_LE_PUBLIC the value as primary
data only. Remember that the system may have previously stored primary
data in the old format.

> +
> + ? ? ? device = device_create(connection, adapter, key, addr_type);
> ? ? ? ?if (!device)
> ? ? ? ? ? ? ? ?return;
>


Are you planning to add support for other address types in BlueZ GATT
server? It would be nice if you could share your plans on this topic.


Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil