* [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing
@ 2012-01-17 16:18 Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 2/3] Fix g_strndup() call for EIR name Anderson Lizardo
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Anderson Lizardo @ 2012-01-17 16:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
When looking for NUL byte terminators on EIR names, the first two bytes
of the EIR field should be skipped, which correspond to field length and
EIR type.
---
src/eir.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index 1b68949..ff50cf8 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -159,7 +159,8 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
* the name */
name_len = field_len - 1;
- while (name_len > 0 && eir_data[name_len - 1] == '\0')
+ while (name_len > 0 &&
+ eir_data[2 + name_len - 1] == '\0')
name_len--;
if (!g_utf8_validate((char *) &eir_data[2],
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH BlueZ 2/3] Fix g_strndup() call for EIR name
2012-01-17 16:18 [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Anderson Lizardo
@ 2012-01-17 16:18 ` Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info Anderson Lizardo
2012-01-17 19:35 ` [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Johan Hedberg
2 siblings, 0 replies; 6+ messages in thread
From: Anderson Lizardo @ 2012-01-17 16:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
Use the actual string length (without the trailing NUL terminator) for
g_strndup(), because it allocates and inserts a trailing NUL byte.
---
src/eir.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index ff50cf8..96aa763 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -169,8 +169,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
g_free(eir->name);
- eir->name = g_strndup((char *) &eir_data[2],
- field_len - 1);
+ eir->name = g_strndup((char *) &eir_data[2], name_len);
eir->name_complete = eir_data[1] == EIR_NAME_COMPLETE;
break;
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info
2012-01-17 16:18 [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 2/3] Fix g_strndup() call for EIR name Anderson Lizardo
@ 2012-01-17 16:18 ` Anderson Lizardo
2012-01-17 19:43 ` Johan Hedberg
2012-01-17 19:35 ` [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Johan Hedberg
2 siblings, 1 reply; 6+ messages in thread
From: Anderson Lizardo @ 2012-01-17 16:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
Some devices may not advertise their name right on the first EIR data
sent (e.g. LE devices where name is set on either advertises or scan
responses, but not both). Given that the "found devices" cache does not
refresh the name on each EIR received, the UI may never show the name
during a discovery session.
This fix improves the Discovery UI by showing names immediately as they
are received. This works by emitting DeviceFound signals when the name
is received, even if RSSI stays the same.
Further discovery sessions will use the stored complete name, as usual.
---
src/adapter.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 7e4bbb6..2984d80 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2806,6 +2806,15 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
if (dev) {
adapter->oor_devices = g_slist_remove(adapter->oor_devices,
dev);
+
+ /* If an existing device had no name but the newly received EIR
+ * data has (complete or not), we want to present it to the
+ * user. */
+ if (dev->name == NULL && eir_data.name != NULL) {
+ dev->name = g_strdup(eir_data.name);
+ goto done;
+ }
+
if (dev->rssi != rssi)
goto done;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing
2012-01-17 16:18 [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 2/3] Fix g_strndup() call for EIR name Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info Anderson Lizardo
@ 2012-01-17 19:35 ` Johan Hedberg
2 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2012-01-17 19:35 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: linux-bluetooth
Hi Lizardo,
On Tue, Jan 17, 2012, Anderson Lizardo wrote:
> When looking for NUL byte terminators on EIR names, the first two bytes
> of the EIR field should be skipped, which correspond to field length and
> EIR type.
> ---
> src/eir.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
Actually I already noticed the issues in the first two patches and have
fixes in my local tree which I'll push in minute. I also ended up adding
a data pointer (to &eir_data[2]) and a generic data_len (field_len - 1)
to make the code more readable. Once I've pushed those I'll apply your
patch 3/3.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info
2012-01-17 16:18 ` [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info Anderson Lizardo
@ 2012-01-17 19:43 ` Johan Hedberg
2012-01-17 19:58 ` Anderson Lizardo
0 siblings, 1 reply; 6+ messages in thread
From: Johan Hedberg @ 2012-01-17 19:43 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: linux-bluetooth
Hi Lizardo,
On Tue, Jan 17, 2012, Anderson Lizardo wrote:
> Some devices may not advertise their name right on the first EIR data
> sent (e.g. LE devices where name is set on either advertises or scan
> responses, but not both). Given that the "found devices" cache does not
> refresh the name on each EIR received, the UI may never show the name
> during a discovery session.
>
> This fix improves the Discovery UI by showing names immediately as they
> are received. This works by emitting DeviceFound signals when the name
> is received, even if RSSI stays the same.
>
> Further discovery sessions will use the stored complete name, as usual.
> ---
> src/adapter.c | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)
Applied. Please do a git pull and check that the eir_parse function is
now both readable and correct.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info
2012-01-17 19:43 ` Johan Hedberg
@ 2012-01-17 19:58 ` Anderson Lizardo
0 siblings, 0 replies; 6+ messages in thread
From: Anderson Lizardo @ 2012-01-17 19:58 UTC (permalink / raw)
To: Anderson Lizardo, linux-bluetooth
Hi Johan,
On Tue, Jan 17, 2012 at 3:43 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Applied. Please do a git pull and check that the eir_parse function is
> now both readable and correct.
After a quick review, it looks correct and more readable. I still need
to test it, but I will have to skip the last mgmt API changes given I
can't update the kernel at the moment.
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-01-17 19:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-17 16:18 [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 2/3] Fix g_strndup() call for EIR name Anderson Lizardo
2012-01-17 16:18 ` [PATCH BlueZ 3/3] Fix not showing name if first EIR has no name info Anderson Lizardo
2012-01-17 19:43 ` Johan Hedberg
2012-01-17 19:58 ` Anderson Lizardo
2012-01-17 19:35 ` [PATCH BlueZ 1/3] Fix wrong offset in EIR name parsing Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).