* [PATCH BlueZ v2] core/device: Fix breakage of Bluetooth pairing
@ 2016-04-11 16:03 Luiz Augusto von Dentz
2016-04-11 19:06 ` Johan Hedberg
0 siblings, 1 reply; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-11 16:03 UTC (permalink / raw)
To: linux-bluetooth
From: Jakub Pawlowski <jpawlowski@chromium.org>
This patch converts old propertis containing list of services available
on remote devices. Without that previously paired devices, i.e.
keyboards, will not work properly.
---
v2: Convert the old entries to Services deleting the entries in the process
src/device.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 63 insertions(+), 11 deletions(-)
diff --git a/src/device.c b/src/device.c
index 0d46eba..b20d389 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2697,6 +2697,65 @@ fail:
return NULL;
}
+static bool device_add_uuid(struct btd_device *device, const char *uuid)
+{
+ if (g_slist_find_custom(device->uuids, uuid, bt_uuid_strcmp))
+ return false;
+
+ device->uuids = g_slist_insert_sorted(device->uuids, g_strdup(uuid),
+ bt_uuid_strcmp);
+
+ return true;
+}
+
+static void convert_info(struct btd_device *device, GKeyFile *key_file)
+{
+ char **uuids;
+
+ /* Load device profile list from legacy property */
+ uuids = g_key_file_get_string_list(key_file, "General", "SDPServices",
+ NULL, NULL);
+ if (uuids) {
+ char **uuid;
+
+ for (uuid = uuids; *uuid; uuid++)
+ device_add_uuid(device, *uuid);
+
+ /* Remove SDPServices so it is not loaded again */
+ g_key_file_remove_key(key_file, "General", "SDPServices", NULL);
+ g_strfreev(uuids);
+ }
+
+ /* Load device profile list from legacy property */
+ uuids = g_key_file_get_string_list(key_file, "General", "GATTServices",
+ NULL, NULL);
+ if (uuids) {
+ char **uuid;
+
+ for (uuid = uuids; *uuid; uuid++)
+ device_add_uuid(device, *uuid);
+
+ /* Remove GATTServices so it is not loaded again */
+ g_key_file_remove_key(key_file, "General", "GATTServices",
+ NULL);
+ g_strfreev(uuids);
+ }
+
+ if (device->uuids) {
+ GSList *l;
+ int i;
+
+ uuids = g_new0(char *, g_slist_length(device->uuids) + 1);
+ for (i = 0, l = device->uuids; l; l = g_slist_next(l), i++)
+ uuids[i] = l->data;
+
+ /* Store the list in the Services so it is properly loaded */
+ g_key_file_set_string_list(key_file, "General", "Services",
+ (const char **)uuids, i);
+ g_free(uuids);
+ }
+}
+
static void load_info(struct btd_device *device, const char *local,
const char *peer, GKeyFile *key_file)
{
@@ -2795,18 +2854,9 @@ next:
if (uuids) {
char **uuid;
- for (uuid = uuids; *uuid; uuid++) {
- GSList *match;
-
- match = g_slist_find_custom(device->uuids, *uuid,
- bt_uuid_strcmp);
- if (match)
- continue;
+ for (uuid = uuids; *uuid; uuid++)
+ device_add_uuid(device, *uuid);
- device->uuids = g_slist_insert_sorted(device->uuids,
- g_strdup(*uuid),
- bt_uuid_strcmp);
- }
g_strfreev(uuids);
/* Discovered services restored from storage */
@@ -3528,6 +3578,8 @@ struct btd_device *device_create_from_storage(struct btd_adapter *adapter,
src = btd_adapter_get_address(adapter);
ba2str(src, srcaddr);
+ convert_info(device, key_file);
+
load_info(device, srcaddr, address, key_file);
load_att_info(device, srcaddr, address);
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH BlueZ v2] core/device: Fix breakage of Bluetooth pairing
2016-04-11 16:03 [PATCH BlueZ v2] core/device: Fix breakage of Bluetooth pairing Luiz Augusto von Dentz
@ 2016-04-11 19:06 ` Johan Hedberg
2016-04-11 21:24 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2016-04-11 19:06 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
On Mon, Apr 11, 2016, Luiz Augusto von Dentz wrote:
> +static void convert_info(struct btd_device *device, GKeyFile *key_file)
> +{
> + char **uuids;
> +
> + /* Load device profile list from legacy property */
> + uuids = g_key_file_get_string_list(key_file, "General", "SDPServices",
> + NULL, NULL);
> + if (uuids) {
> + char **uuid;
> +
> + for (uuid = uuids; *uuid; uuid++)
> + device_add_uuid(device, *uuid);
> +
> + /* Remove SDPServices so it is not loaded again */
> + g_key_file_remove_key(key_file, "General", "SDPServices", NULL);
Note that this doesn't modify the file but just the GKeyFile object. For
places where we need to write back out the contents to the file we
usually use g_key_file_to_data + g_file_set_contents, but I didn't see
any such calls in this call path.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH BlueZ v2] core/device: Fix breakage of Bluetooth pairing
2016-04-11 19:06 ` Johan Hedberg
@ 2016-04-11 21:24 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-11 21:24 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
Hi Johan,
On Mon, Apr 11, 2016 at 10:06 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Luiz,
>
> On Mon, Apr 11, 2016, Luiz Augusto von Dentz wrote:
>> +static void convert_info(struct btd_device *device, GKeyFile *key_file)
>> +{
>> + char **uuids;
>> +
>> + /* Load device profile list from legacy property */
>> + uuids = g_key_file_get_string_list(key_file, "General", "SDPServices",
>> + NULL, NULL);
>> + if (uuids) {
>> + char **uuid;
>> +
>> + for (uuid = uuids; *uuid; uuid++)
>> + device_add_uuid(device, *uuid);
>> +
>> + /* Remove SDPServices so it is not loaded again */
>> + g_key_file_remove_key(key_file, "General", "SDPServices", NULL);
>
> Note that this doesn't modify the file but just the GKeyFile object. For
> places where we need to write back out the contents to the file we
> usually use g_key_file_to_data + g_file_set_contents, but I didn't see
> any such calls in this call path.
Good catch I forgot that is actually not saved automatically.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-11 21:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-11 16:03 [PATCH BlueZ v2] core/device: Fix breakage of Bluetooth pairing Luiz Augusto von Dentz
2016-04-11 19:06 ` Johan Hedberg
2016-04-11 21:24 ` Luiz Augusto von Dentz
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).