All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Store LE device address type with primary list
@ 2012-04-25 13:27 Hemant Gupta
  2012-04-26  9:32 ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Hemant Gupta @ 2012-04-25 13:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Hemant Gupta

This patch stores the address type while storing the primary services
of LE Device which is later used for re-creating device from primary
service database.
---
 src/adapter.c |   10 ++++++++--
 src/device.c  |    9 +++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 12b6aeb..5df49e3 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1920,13 +1920,19 @@ 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;
+	/* Assume address type to be public by default */
+	addr_type_t addr_type = ADDR_TYPE_LE_PUBLIC;
 
 	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);
+	/* Check if address type can be parsed properly */
+	if (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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Store LE device address type with primary list
  2012-04-25 13:27 [PATCH v2] Store LE device address type with primary list Hemant Gupta
@ 2012-04-26  9:32 ` Johan Hedberg
  2012-04-26 21:02   ` Claudio Takahasi
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hedberg @ 2012-04-26  9:32 UTC (permalink / raw)
  To: Hemant Gupta; +Cc: linux-bluetooth

Hi Hemant,

On Wed, Apr 25, 2012, Hemant Gupta wrote:
> This patch stores the address type while storing the primary services
> of LE Device which is later used for re-creating device from primary
> service database.
> ---
>  src/adapter.c |   10 ++++++++--
>  src/device.c  |    9 +++++++--
>  2 files changed, 15 insertions(+), 4 deletions(-)

Would it make more sense (and I'm not asking just you but also the
INdTers) to have the address type as part of the key instead of the
value. After all it's basically an extension to the address and that way
tightly bound to it. Maybe something like the following:

11:22:33:44:55:66|1 <value1>
aa:bb:cc:dd:ee:ff|0 <value2>

The same should then also be considered for the longtermkeys file.

Johan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Store LE device address type with primary list
  2012-04-26  9:32 ` Johan Hedberg
@ 2012-04-26 21:02   ` Claudio Takahasi
  2012-04-27 12:15     ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Claudio Takahasi @ 2012-04-26 21:02 UTC (permalink / raw)
  To: Hemant Gupta, linux-bluetooth

Hi Hemant/Johan:

On Thu, Apr 26, 2012 at 6:32 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Hemant,
>
> On Wed, Apr 25, 2012, Hemant Gupta wrote:
>> This patch stores the address type while storing the primary services
>> of LE Device which is later used for re-creating device from primary
>> service database.
>> ---
>>  src/adapter.c |   10 ++++++++--
>>  src/device.c  |    9 +++++++--
>>  2 files changed, 15 insertions(+), 4 deletions(-)
>
> Would it make more sense (and I'm not asking just you but also the
> INdTers) to have the address type as part of the key instead of the
> value. After all it's basically an extension to the address and that way
> tightly bound to it. Maybe something like the following:
>
> 11:22:33:44:55:66|1 <value1>
> aa:bb:cc:dd:ee:ff|0 <value2>
>
> The same should then also be considered for the longtermkeys file.
>
> Johan

I agree if we append the address type for all LE/GATT storage
files(not only for primary and longtermkeys).
Probably we will have minor problems between BlueZ releases, but IMO
it is acceptable since LE it is not officially supported.
btw: the separator commonly used in the storage files is "#" instead of "|".

BR,
Claudio

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Store LE device address type with primary list
  2012-04-26 21:02   ` Claudio Takahasi
@ 2012-04-27 12:15     ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2012-04-27 12:15 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: Hemant Gupta, linux-bluetooth

Hi Claudio,

On Thu, Apr 26, 2012, Claudio Takahasi wrote:
> On Thu, Apr 26, 2012 at 6:32 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> > Hi Hemant,
> >
> > On Wed, Apr 25, 2012, Hemant Gupta wrote:
> >> This patch stores the address type while storing the primary services
> >> of LE Device which is later used for re-creating device from primary
> >> service database.
> >> ---
> >>  src/adapter.c |   10 ++++++++--
> >>  src/device.c  |    9 +++++++--
> >>  2 files changed, 15 insertions(+), 4 deletions(-)
> >
> > Would it make more sense (and I'm not asking just you but also the
> > INdTers) to have the address type as part of the key instead of the
> > value. After all it's basically an extension to the address and that way
> > tightly bound to it. Maybe something like the following:
> >
> > 11:22:33:44:55:66|1 <value1>
> > aa:bb:cc:dd:ee:ff|0 <value2>
> >
> > The same should then also be considered for the longtermkeys file.
> >
> > Johan
> 
> I agree if we append the address type for all LE/GATT storage
> files(not only for primary and longtermkeys).
> Probably we will have minor problems between BlueZ releases, but IMO
> it is acceptable since LE it is not officially supported.
> btw: the separator commonly used in the storage files is "#" instead of "|".

I'm fine with using # and yes all LE related files should use this
convention. And if possible these changes should go in before the next
BlueZ release.

Johan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-27 12:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25 13:27 [PATCH v2] Store LE device address type with primary list Hemant Gupta
2012-04-26  9:32 ` Johan Hedberg
2012-04-26 21:02   ` Claudio Takahasi
2012-04-27 12:15     ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.