Skip to contentSkip to conversation

Added config conversion tool

PATCH In review Christian Zimmermann 3 participants 7 messages Jan 27, 2019 – Jan 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Added config conversion tool

Added a config conversion tool for Bluez4 config, instead of doing the conversion in adapter.c

Christian Zimmermann (2):
Renamed Bluez4 config read functions
Added config converter for Bluez4 config conversion

 .gitignore                |   2 +
 Makefile.am               |  12 ++++
 Makefile.tools            |   9 +++
 src/adapter.c             |   8 +--
 src/storage.c             |  36 +++--------
 src/storage.h             |  10 +--
 tools/config-conversion.c | 129 +++++++++++++++++++++++++++++++++++++
 tools/config-conversion.h |  23 +++++++
 tools/config-converter.c  |  69 ++++++++++++++++++++
 unit/test-conversions.c   | 158 ++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 420 insertions(+), 36 deletions(-)
 create mode 100644 tools/config-conversion.c
 create mode 100644 tools/config-conversion.h
 create mode 100644 tools/config-converter.c
 create mode 100644 unit/test-conversions.c
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/2 Renamed Bluez4 config read functions

---
 src/adapter.c |  8 ++++----
 src/storage.c | 36 ++++++++----------------------------
 src/storage.h | 10 ++++++----
 3 files changed, 18 insertions(+), 36 deletions(-)
src/adapter.c +4 -4
index b8a6bb6e2..f7c24fe62 100644
@@ -5654,21 +5654,21 @@ static void convert_config(struct btd_adapter *adapter, const char *filename,
 	ba2str(&adapter->bdaddr, address);
 	snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address);
 
-	if (read_pairable_timeout(address, &timeout) == 0)
+	if (bluez4_read_pairable_timeout(config_path, &timeout) == 0)
 		g_key_file_set_integer(key_file, "General",
 						"PairableTimeout", timeout);
 
-	if (read_discoverable_timeout(address, &timeout) == 0)
+	if (bluez4_read_discoverable_timeout(config_path, &timeout) == 0)
 		g_key_file_set_integer(key_file, "General",
 						"DiscoverableTimeout", timeout);
 
-	if (read_on_mode(address, str, sizeof(str)) == 0) {
+	if (bluez4_read_on_mode(config_path, str, sizeof(str)) == 0) {
 		mode = get_mode(str);
 		g_key_file_set_boolean(key_file, "General", "Discoverable",
 					mode == MODE_DISCOVERABLE);
 	}
 
-	if (read_local_name(&adapter->bdaddr, str) == 0)
+	if (bluez4_read_local_name(config_path, str) == 0)
 		g_key_file_set_string(key_file, "General", "Alias", str);
 
 	create_file(filename, S_IRUSR | S_IWUSR);
src/storage.c +8 -28
index 8cbb5b270..779ca2bc8 100644
@@ -56,22 +56,9 @@ struct match {
 	char *pattern;
 };
 
-static inline int create_filename(char *buf, size_t size,
-				const bdaddr_t *bdaddr, const char *name)
+int bluez4_read_discoverable_timeout(const char *filename, int *timeout)
 {
-	char addr[18];
-
-	ba2str(bdaddr, addr);
-
-	return create_name(buf, size, STORAGEDIR, addr, name);
-}
-
-int read_discoverable_timeout(const char *src, int *timeout)
-{
-	char filename[PATH_MAX], *str;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "config");
-
+	char *str;
 	str = textfile_get(filename, "discovto");
 	if (!str)
 		return -ENOENT;
@@ -86,12 +73,9 @@ int read_discoverable_timeout(const char *src, int *timeout)
 	return 0;
 }
 
-int read_pairable_timeout(const char *src, int *timeout)
+int bluez4_read_pairable_timeout(const char *filename, int *timeout)
 {
-	char filename[PATH_MAX], *str;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "config");
-
+	char *str;
 	str = textfile_get(filename, "pairto");
 	if (!str)
 		return -ENOENT;
@@ -106,11 +90,9 @@ int read_pairable_timeout(const char *src, int *timeout)
 	return 0;
 }
 
-int read_on_mode(const char *src, char *mode, int length)
+int bluez4_read_on_mode(const char *filename, char *mode, int length)
 {
-	char filename[PATH_MAX], *str;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, src, "config");
+	char *str;
 
 	str = textfile_get(filename, "onmode");
 	if (!str)
@@ -124,13 +106,11 @@ int read_on_mode(const char *src, char *mode, int length)
 	return 0;
 }
 
-int read_local_name(const bdaddr_t *bdaddr, char *name)
+int bluez4_read_local_name(const char *filename, char *name)
 {
-	char filename[PATH_MAX], *str;
+	char *str;
 	int len;
 
-	create_filename(filename, PATH_MAX, bdaddr, "config");
-
 	str = textfile_get(filename, "name");
 	if (!str)
 		return -ENOENT;
src/storage.h +6 -4
index 1c0ad57ec..d84cc86db 100644
@@ -21,9 +21,11 @@
  *
  */
 
-int read_discoverable_timeout(const char *src, int *timeout);
-int read_pairable_timeout(const char *src, int *timeout);
-int read_on_mode(const char *src, char *mode, int length);
-int read_local_name(const bdaddr_t *bdaddr, char *name);
+#include "lib/sdp.h"
+
+int bluez4_read_discoverable_timeout(const char *filename, int *timeout);
+int bluez4_read_pairable_timeout(const char *filename, int *timeout);
+int bluez4_read_on_mode(const char *filename, char *mode, int length);
+int bluez4_read_local_name(const char *filename, char *name);
 sdp_record_t *record_from_string(const char *str);
 sdp_record_t *find_record_in_list(sdp_list_t *recs, const char *uuid);
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/2 Added config converter for Bluez4 config conversion

In reply to Christian Zimmermann
---
 .gitignore                |   2 +
 Makefile.am               |  12 ++++
 Makefile.tools            |   9 +++
 tools/config-conversion.c | 129 +++++++++++++++++++++++++++++++++++++
 tools/config-conversion.h |  23 +++++++
 tools/config-converter.c  |  69 ++++++++++++++++++++
 unit/test-conversions.c   | 158 ++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 402 insertions(+)
 create mode 100644 tools/config-conversion.c
 create mode 100644 tools/config-conversion.h
 create mode 100644 tools/config-converter.c
 create mode 100644 unit/test-conversions.c
.gitignore +2 -0
index d145ccdcd..b75e49bd6 100644
@@ -122,6 +122,7 @@ tools/btsnoop
 tools/btpclient
 tools/btmon-logger
 tools/bluetooth-logger.service
+tools/config-converter
 peripheral/btsensor
 monitor/btmon
 emulator/btvirt
@@ -150,6 +151,7 @@ unit/test-avrcp
 unit/test-gatt
 unit/test-midi
 unit/test-gattrib
+unit/test-conversions
 unit/test-*.log
 unit/test-*.trs
 
Makefile.am +12 -0
index f84a1faba..4a157d714 100644
@@ -499,6 +499,15 @@ unit_test_gattrib_LDADD = lib/libbluetooth-internal.la \
 			src/libshared-glib.la \
 			$(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt
 
+unit_tests += unit/test-conversions
+unit_test_conversions_SOURCES = unit/test-conversions.c \
+			tools/config-conversion.h tools/config-conversion.c \
+			src/storage.h src/storage.c \
+			src/textfile.h src/textfile.c \
+			src/uuid-helper.h src/uuid-helper.c
+unit_test_conversions_LDADD = src/libshared-glib.la \
+				lib/libbluetooth-internal.la $(GLIB_LIBS)
+
 if MIDI
 unit_tests += unit/test-midi
 unit_test_midi_CPPFLAGS = $(AM_CPPFLAGS) $(ALSA_CFLAGS) -DMIDI_TEST
@@ -617,3 +626,6 @@ clean-local:
 	-find $(top_builddir) -name "*.gcda" -delete
 	$(RM) -r lib/bluetooth
 endif
+
+install-exec-hook:
+	tools/config-converter
Makefile.tools +9 -0
index 1f8271542..3221e2634 100644
@@ -473,3 +473,12 @@ tools_btpclient_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-ell.la $(ell_ldadd)
 tools_btpclient_DEPENDENCIES = $(ell_dependencies)
 endif
+
+noinst_PROGRAMS += tools/config-converter
+tools_config_converter_SOURCES = tools/config-converter.c \
+			tools/config-conversion.h tools/config-conversion.c \
+			src/storage.h src/storage.c \
+			src/textfile.h src/textfile.c \
+			src/uuid-helper.h src/uuid-helper.c
+tools_config_converter_LDADD = src/libshared-glib.la lib/libbluetooth-internal.la \
+				$(GLIB_LIBS)
\ No newline at end of file
tools/config-conversion.c new file +129 -0

129 lines not on this page · raw message

tools/config-conversion.h new file +23 -0
new file mode 100644
index 000000000..eac789cec
@@ -0,0 +1,23 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2019  Christian Zimmermann <[email protected]>
+ *
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ */
+
+#include <glib.h>
+
+void convert_bluez4_config(const char *cfg_path);
+void convert_config(const char *adapter_cfg_path, gboolean force);
tools/config-converter.c new file +69 -0

69 lines not on this page · raw message

unit/test-conversions.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#3 lore raw
In reply to Christian Zimmermann

Hi Christian,

Quoted 5 lines

Added a config conversion tool for Bluez4 config, instead of doing the conversion in adapter.c

Christian Zimmermann (2):
Renamed Bluez4 config read functions
Added config converter for Bluez4 config conversion

so what is the intention here. I was going to just remove any 4.x support and more to BlueZ 6.0 soon. Actually BlueZ 5.x has been release over 6 years ago. I have pretty much zero interest in carrying / maintaining anything for BlueZ 4.x support.

Regards

Marcel

#4 lore raw

Hi Marcel,

i reviewed the TODO file of Bluez in Nov. 2018 in order to find an issue where i could support the project.
So i found the issue to remove the config conversion in adapter.c shortly after Bluez5 release. Therefore i made a patch to remove those conversions, but i got a hint of Luiz that there are still some platforms dealing with Bluez4 which must be considered.
As a consequence of this i first did an shell script approach for the config conversion, but had some issues with that, e.g. unit test for the script. So i started writing this config converter in order to remove the conversion parts in adapter.c in favour of an external conversion part, which could handle those conversions during install. Moreover it would be possible to handle other conversions due to config API changes with such an external application.

Best regards,
Christian

Quoted 10 lines

Am 28.01.2019 um 13:22 schrieb Marcel Holtmann <[email protected]>:

Hi Christian,

Quoted 5 lines

Added a config conversion tool for Bluez4 config, instead of doing the conversion in adapter.c

Christian Zimmermann (2):
Renamed Bluez4 config read functions
Added config converter for Bluez4 config conversion

Quoted 6 lines

so what is the intention here. I was going to just remove any 4.x support and more to BlueZ 6.0 soon. Actually BlueZ 5.x has been release over 6 years ago. I have pretty much zero interest in carrying / maintaining anything for BlueZ 4.x support.

Regards

Marcel

Hi Christian,

Quoted 5 lines · Christian Zimmermann

Hi Luiz,

thank you for your response.
How about having a shell or python script which does the necessary conversion during bluez install? Would this be sufficient?

Yep, that way the distro can actually run those in case of updating an old installation.

Quoted 915 lines

Regards,
Christian

Quoted 912 lines

Am 07.11.2018 um 12:37 schrieb Luiz Augusto von Dentz <[email protected]>:

Hi Christian,

Quoted 4 lines · Christian Zimmermann

According to TODO file:
Removal of conversion functions for persistant settings
since they're obsolete with Bluez5 after certain time of it's first release

We probably need to consider if there are still platforms using BlueZ 4 then removing this code would make the transition, perhaps we could have a tool to do that so we can remove this from the daemon.

Quoted 885 lines

---
TODO | 6 -
src/adapter.c | 832 ----------------------------------------------------------

2 files changed, 838 deletions(-)
TODO +0 -7
index d88349e06..ae2d69dfa 100644
@@ -37,12 +37,6 @@ General
  Priority: Medium
  Complexity: C2
 
-- Function in src/adapter.c to convert old storage files to new ini-file format
-  should be removed 6-8 months after first BlueZ 5 release.
-
-  Priority: Low
-  Complexity: C1
-
- Remove usage of symlinks for drivers, such as profiles/input/suspend.c and
  profiles/sap/sap.c. Instead, select drivers at runtime by using config
  options or probing for running D-Bus services (using e.g.
src/adapter.c +0 -831
index c24432125..5709ee956 100644
@@ -423,18 +423,6 @@ void btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major,
       set_dev_class(adapter);
 }
 
-static uint8_t get_mode(const char *mode)
-{
-       if (strcasecmp("off", mode) == 0)
-               return MODE_OFF;
-       else if (strcasecmp("connectable", mode) == 0)
-               return MODE_CONNECTABLE;
-       else if (strcasecmp("discoverable", mode) == 0)
-               return MODE_DISCOVERABLE;
-       else
-               return MODE_UNKNOWN;
-}
-
 const char *btd_adapter_get_storage_dir(struct btd_adapter *adapter)
 {
       static char dir[25];
@@ -4927,824 +4915,10 @@ void btd_adapter_unref(struct btd_adapter *adapter)
                                               ADAPTER_INTERFACE);
 }
 
-static void convert_names_entry(char *key, char *value, void *user_data)
-{
-       char *address = user_data;
-       char *str = key;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       char *data;
-       gsize length = 0;
-
-       if (strchr(key, '#'))
-               str[17] = '\0';
-
-       if (bachk(str) != 0)
-               return;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", address, str);
-       create_file(filename, S_IRUSR | S_IWUSR);
-
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-       g_key_file_set_string(key_file, "General", "Name", value);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, data, length, NULL);
-       g_free(data);
-
-       g_key_file_free(key_file);
-}
-
-struct device_converter {
-       char *address;
-       void (*cb)(GKeyFile *key_file, void *value);
-       gboolean force;
-};
-
-static void set_device_type(GKeyFile *key_file, char type)
-{
-       char *techno;
-       char *addr_type = NULL;
-       char *str;
-
-       switch (type) {
-       case BDADDR_BREDR:
-               techno = "BR/EDR";
-               break;
-       case BDADDR_LE_PUBLIC:
-               techno = "LE";
-               addr_type = "public";
-               break;
-       case BDADDR_LE_RANDOM:
-               techno = "LE";
-               addr_type = "static";
-               break;
-       default:
-               return;
-       }
-
-       str = g_key_file_get_string(key_file, "General",
-                                       "SupportedTechnologies", NULL);
-       if (!str)
-               g_key_file_set_string(key_file, "General",
-                                       "SupportedTechnologies", techno);
-       else if (!strstr(str, techno))
-               g_key_file_set_string(key_file, "General",
-                                       "SupportedTechnologies", "BR/EDR;LE");
-
-       g_free(str);
-
-       if (addr_type)
-               g_key_file_set_string(key_file, "General", "AddressType",
-                                       addr_type);
-}
-
-static void convert_aliases_entry(GKeyFile *key_file, void *value)
-{
-       g_key_file_set_string(key_file, "General", "Alias", value);
-}
-
-static void convert_trusts_entry(GKeyFile *key_file, void *value)
-{
-       g_key_file_set_boolean(key_file, "General", "Trusted", TRUE);
-}
-
-static void convert_classes_entry(GKeyFile *key_file, void *value)
-{
-       g_key_file_set_string(key_file, "General", "Class", value);
-}
-
-static void convert_blocked_entry(GKeyFile *key_file, void *value)
-{
-       g_key_file_set_boolean(key_file, "General", "Blocked", TRUE);
-}
-
-static void convert_did_entry(GKeyFile *key_file, void *value)
-{
-       char *vendor_str, *product_str, *version_str;
-       uint16_t val;
-
-       vendor_str = strchr(value, ' ');
-       if (!vendor_str)
-               return;
-
-       *(vendor_str++) = 0;
-
-       if (g_str_equal(value, "FFFF"))
-               return;
-
-       product_str = strchr(vendor_str, ' ');
-       if (!product_str)
-               return;
-
-       *(product_str++) = 0;
-
-       version_str = strchr(product_str, ' ');
-       if (!version_str)
-               return;
-
-       *(version_str++) = 0;
-
-       val = (uint16_t) strtol(value, NULL, 16);
-       g_key_file_set_integer(key_file, "DeviceID", "Source", val);
-
-       val = (uint16_t) strtol(vendor_str, NULL, 16);
-       g_key_file_set_integer(key_file, "DeviceID", "Vendor", val);
-
-       val = (uint16_t) strtol(product_str, NULL, 16);
-       g_key_file_set_integer(key_file, "DeviceID", "Product", val);
-
-       val = (uint16_t) strtol(version_str, NULL, 16);
-       g_key_file_set_integer(key_file, "DeviceID", "Version", val);
-}
-
-static void convert_linkkey_entry(GKeyFile *key_file, void *value)
-{
-       char *type_str, *length_str, *str;
-       int val;
-
-       type_str = strchr(value, ' ');
-       if (!type_str)
-               return;
-
-       *(type_str++) = 0;
-
-       length_str = strchr(type_str, ' ');
-       if (!length_str)
-               return;
-
-       *(length_str++) = 0;
-
-       str = g_strconcat("0x", value, NULL);
-       g_key_file_set_string(key_file, "LinkKey", "Key", str);
-       g_free(str);
-
-       val = strtol(type_str, NULL, 16);
-       g_key_file_set_integer(key_file, "LinkKey", "Type", val);
-
-       val = strtol(length_str, NULL, 16);
-       g_key_file_set_integer(key_file, "LinkKey", "PINLength", val);
-}
-
-static void convert_ltk_entry(GKeyFile *key_file, void *value)
-{
-       char *auth_str, *rand_str, *str;
-       int i, ret;
-       unsigned char auth, master, enc_size;
-       unsigned short ediv;
-
-       auth_str = strchr(value, ' ');
-       if (!auth_str)
-               return;
-
-       *(auth_str++) = 0;
-
-       for (i = 0, rand_str = auth_str; i < 4; i++) {
-               rand_str = strchr(rand_str, ' ');
-               if (!rand_str || rand_str[1] == '\0')
-                       return;
-
-               rand_str++;
-       }
-
-       ret = sscanf(auth_str, " %hhd %hhd %hhd %hd", &auth, &master,
-                                                       &enc_size, &ediv);
-       if (ret < 4)
-               return;
-
-       str = g_strconcat("0x", value, NULL);
-       g_key_file_set_string(key_file, "LongTermKey", "Key", str);
-       g_free(str);
-
-       g_key_file_set_integer(key_file, "LongTermKey", "Authenticated", auth);
-       g_key_file_set_integer(key_file, "LongTermKey", "Master", master);
-       g_key_file_set_integer(key_file, "LongTermKey", "EncSize", enc_size);
-       g_key_file_set_integer(key_file, "LongTermKey", "EDiv", ediv);
-
-       str = g_strconcat("0x", rand_str, NULL);
-       g_key_file_set_string(key_file, "LongTermKey", "Rand", str);
-       g_free(str);
-}
-
-static void convert_profiles_entry(GKeyFile *key_file, void *value)
-{
-       g_strdelimit(value, " ", ';');
-       g_key_file_set_string(key_file, "General", "Services", value);
-}
-
-static void convert_appearances_entry(GKeyFile *key_file, void *value)
-{
-       g_key_file_set_string(key_file, "General", "Appearance", value);
-}
-
-static void convert_entry(char *key, char *value, void *user_data)
-{
-       struct device_converter *converter = user_data;
-       char type = BDADDR_BREDR;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       char *data;
-       gsize length = 0;
-
-       if (strchr(key, '#')) {
-               key[17] = '\0';
-               type = key[18] - '0';
-       }
-
-       if (bachk(key) != 0)
-               return;
-
-       if (converter->force == FALSE) {
-               struct stat st;
-               int err;
-
-               snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s",
-                               converter->address, key);
-
-               err = stat(filename, &st);
-               if (err || !S_ISDIR(st.st_mode))
-                       return;
-       }
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
-                       converter->address, key);
-
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       set_device_type(key_file, type);
-
-       converter->cb(key_file, value);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-       g_free(data);
-
-       g_key_file_free(key_file);
-}
-
-static void convert_file(char *file, char *address,
-                               void (*cb)(GKeyFile *key_file, void *value),
-                               gboolean force)
-{
-       char filename[PATH_MAX];
-       struct device_converter converter;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", address, file);
-
-       converter.address = address;
-       converter.cb = cb;
-       converter.force = force;
-
-       textfile_foreach(filename, convert_entry, &converter);
-}
-
-static gboolean record_has_uuid(const sdp_record_t *rec,
-                               const char *profile_uuid)
-{
-       sdp_list_t *pat;
-
-       for (pat = rec->pattern; pat != NULL; pat = pat->next) {
-               char *uuid;
-               int ret;
-
-               uuid = bt_uuid2string(pat->data);
-               if (!uuid)
-                       continue;
-
-               ret = strcasecmp(uuid, profile_uuid);
-
-               free(uuid);
-
-               if (ret == 0)
-                       return TRUE;
-       }
-
-       return FALSE;
-}
-
-static void store_attribute_uuid(GKeyFile *key_file, uint16_t start,
-                                       uint16_t end, char *att_uuid,
-                                       uuid_t uuid)
-{
-       char handle[6], uuid_str[33];
-       int i;
-
-       switch (uuid.type) {
-       case SDP_UUID16:
-               sprintf(uuid_str, "%4.4X", uuid.value.uuid16);
-               break;
-       case SDP_UUID32:
-               sprintf(uuid_str, "%8.8X", uuid.value.uuid32);
-               break;
-       case SDP_UUID128:
-               for (i = 0; i < 16; i++)
-                       sprintf(uuid_str + (i * 2), "%2.2X",
-                                       uuid.value.uuid128.data[i]);
-               break;
-       default:
-               uuid_str[0] = '\0';
-       }
-
-       sprintf(handle, "%hu", start);
-       g_key_file_set_string(key_file, handle, "UUID", att_uuid);
-       g_key_file_set_string(key_file, handle, "Value", uuid_str);
-       g_key_file_set_integer(key_file, handle, "EndGroupHandle", end);
-}
-
-static void store_sdp_record(char *local, char *peer, int handle, char *value)
-{
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       char handle_str[11];
-       char *data;
-       gsize length = 0;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
-
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       sprintf(handle_str, "0x%8.8X", handle);
-       g_key_file_set_string(key_file, "ServiceRecords", handle_str, value);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-       g_free(data);
-
-       g_key_file_free(key_file);
-}
-
-static void convert_sdp_entry(char *key, char *value, void *user_data)
-{
-       char *src_addr = user_data;
-       char dst_addr[18];
-       char type = BDADDR_BREDR;
-       int handle, ret;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       struct stat st;
-       sdp_record_t *rec;
-       uuid_t uuid;
-       char *att_uuid, *prim_uuid;
-       uint16_t start = 0, end = 0, psm = 0;
-       int err;
-       char *data;
-       gsize length = 0;
-
-       ret = sscanf(key, "%17s#%hhu#%08X", dst_addr, &type, &handle);
-       if (ret < 3) {
-               ret = sscanf(key, "%17s#%08X", dst_addr, &handle);
-               if (ret < 2)
-                       return;
-       }
-
-       if (bachk(dst_addr) != 0)
-               return;
-
-       /* Check if the device directory has been created as records should
-        * only be converted for known devices */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, dst_addr);
-
-       err = stat(filename, &st);
-       if (err || !S_ISDIR(st.st_mode))
-               return;
-
-       /* store device records in cache */
-       store_sdp_record(src_addr, dst_addr, handle, value);
-
-       /* Retrieve device record and check if there is an
-        * attribute entry in it */
-       sdp_uuid16_create(&uuid, ATT_UUID);
-       att_uuid = bt_uuid2string(&uuid);
-
-       sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
-       prim_uuid = bt_uuid2string(&uuid);
-
-       rec = record_from_string(value);
-
-       if (record_has_uuid(rec, att_uuid))
-               goto failed;
-
-       /* TODO: Do this through btd_gatt_database */
-       if (!gatt_parse_record(rec, &uuid, &psm, &start, &end))
-               goto failed;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", src_addr,
-                                                               dst_addr);
-
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       store_attribute_uuid(key_file, start, end, prim_uuid, uuid);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-       g_free(data);
-       g_key_file_free(key_file);
-
-failed:
-       sdp_record_free(rec);
-       free(prim_uuid);
-       free(att_uuid);
-}
-
-static void convert_primaries_entry(char *key, char *value, void *user_data)
-{
-       char *address = user_data;
-       int device_type = -1;
-       uuid_t uuid;
-       char **services, **service, *prim_uuid;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       int ret;
-       uint16_t start, end;
-       char uuid_str[MAX_LEN_UUID_STR + 1];
-       char *data;
-       gsize length = 0;
-
-       if (strchr(key, '#')) {
-               key[17] = '\0';
-               device_type = key[18] - '0';
-       }
-
-       if (bachk(key) != 0)
-               return;
-
-       services = g_strsplit(value, " ", 0);
-       if (services == NULL)
-               return;
-
-       sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
-       prim_uuid = bt_uuid2string(&uuid);
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", address,
-                                                                       key);
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       for (service = services; *service; service++) {
-               ret = sscanf(*service, "%04hX#%04hX#%s", &start, &end,
-                                                               uuid_str);
-               if (ret < 3)
-                       continue;
-
-               bt_string2uuid(&uuid, uuid_str);
-               sdp_uuid128_to_uuid(&uuid);
-
-               store_attribute_uuid(key_file, start, end, prim_uuid, uuid);
-       }
-
-       g_strfreev(services);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length == 0)
-               goto end;
-
-       create_file(filename, S_IRUSR | S_IWUSR);
-       g_file_set_contents(filename, data, length, NULL);
-
-       if (device_type < 0)
-               goto end;
-
-       g_free(data);
-       g_key_file_free(key_file);
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", address, key);
-
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-       set_device_type(key_file, device_type);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-end:
-       g_free(data);
-       free(prim_uuid);
-       g_key_file_free(key_file);
-}
-
-static void convert_ccc_entry(char *key, char *value, void *user_data)
-{
-       char *src_addr = user_data;
-       char dst_addr[18];
-       char type = BDADDR_BREDR;
-       uint16_t handle;
-       int ret, err;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       struct stat st;
-       char group[6];
-       char *data;
-       gsize length = 0;
-
-       ret = sscanf(key, "%17s#%hhu#%04hX", dst_addr, &type, &handle);
-       if (ret < 3)
-               return;
-
-       if (bachk(dst_addr) != 0)
-               return;
-
-       /* Check if the device directory has been created as records should
-        * only be converted for known devices */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, dst_addr);
-
-       err = stat(filename, &st);
-       if (err || !S_ISDIR(st.st_mode))
-               return;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/ccc", src_addr,
-                                                               dst_addr);
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       sprintf(group, "%hu", handle);
-       g_key_file_set_string(key_file, group, "Value", value);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-       g_free(data);
-       g_key_file_free(key_file);
-}
-
-static void convert_gatt_entry(char *key, char *value, void *user_data)
-{
-       char *src_addr = user_data;
-       char dst_addr[18];
-       char type = BDADDR_BREDR;
-       uint16_t handle;
-       int ret, err;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       struct stat st;
-       char group[6];
-       char *data;
-       gsize length = 0;
-
-       ret = sscanf(key, "%17s#%hhu#%04hX", dst_addr, &type, &handle);
-       if (ret < 3)
-               return;
-
-       if (bachk(dst_addr) != 0)
-               return;
-
-       /* Check if the device directory has been created as records should
-        * only be converted for known devices */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, dst_addr);
-
-       err = stat(filename, &st);
-       if (err || !S_ISDIR(st.st_mode))
-               return;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/gatt", src_addr,
-                                                               dst_addr);
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       sprintf(group, "%hu", handle);
-       g_key_file_set_string(key_file, group, "Value", value);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-       g_free(data);
-       g_key_file_free(key_file);
-}
-
-static void convert_proximity_entry(char *key, char *value, void *user_data)
-{
-       char *src_addr = user_data;
-       char *alert;
-       char filename[PATH_MAX];
-       GKeyFile *key_file;
-       struct stat st;
-       int err;
-       char *data;
-       gsize length = 0;
-
-       if (!strchr(key, '#'))
-               return;
-
-       key[17] = '\0';
-       alert = &key[18];
-
-       if (bachk(key) != 0)
-               return;
-
-       /* Check if the device directory has been created as records should
-        * only be converted for known devices */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", src_addr, key);
-
-       err = stat(filename, &st);
-       if (err || !S_ISDIR(st.st_mode))
-               return;
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/proximity", src_addr,
-                                                                       key);
-       key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
-
-       g_key_file_set_string(key_file, alert, "Level", value);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       if (length > 0) {
-               create_file(filename, S_IRUSR | S_IWUSR);
-               g_file_set_contents(filename, data, length, NULL);
-       }
-
-       g_free(data);
-       g_key_file_free(key_file);
-}
-
-static void convert_device_storage(struct btd_adapter *adapter)
-{
-       char filename[PATH_MAX];
-       char address[18];
-
-       ba2str(&adapter->bdaddr, address);
-
-       /* Convert device's name cache */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/names", address);
-       textfile_foreach(filename, convert_names_entry, address);
-
-       /* Convert aliases */
-       convert_file("aliases", address, convert_aliases_entry, TRUE);
-
-       /* Convert trusts */
-       convert_file("trusts", address, convert_trusts_entry, TRUE);
-
-       /* Convert blocked */
-       convert_file("blocked", address, convert_blocked_entry, TRUE);
-
-       /* Convert profiles */
-       convert_file("profiles", address, convert_profiles_entry, TRUE);
-
-       /* Convert primaries */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/primaries", address);
-       textfile_foreach(filename, convert_primaries_entry, address);
-
-       /* Convert linkkeys */
-       convert_file("linkkeys", address, convert_linkkey_entry, TRUE);
-
-       /* Convert longtermkeys */
-       convert_file("longtermkeys", address, convert_ltk_entry, TRUE);
-
-       /* Convert classes */
-       convert_file("classes", address, convert_classes_entry, FALSE);
-
-       /* Convert device ids */
-       convert_file("did", address, convert_did_entry, FALSE);
-
-       /* Convert sdp */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/sdp", address);
-       textfile_foreach(filename, convert_sdp_entry, address);
-
-       /* Convert ccc */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/ccc", address);
-       textfile_foreach(filename, convert_ccc_entry, address);
-
-       /* Convert appearances */
-       convert_file("appearances", address, convert_appearances_entry, FALSE);
-
-       /* Convert gatt */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/gatt", address);
-       textfile_foreach(filename, convert_gatt_entry, address);
-
-       /* Convert proximity */
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/proximity", address);
-       textfile_foreach(filename, convert_proximity_entry, address);
-}
-
-static void convert_config(struct btd_adapter *adapter, const char *filename,
-                                                       GKeyFile *key_file)
-{
-       char address[18];
-       char str[MAX_NAME_LENGTH + 1];
-       char config_path[PATH_MAX];
-       int timeout;
-       uint8_t mode;
-       char *data;
-       gsize length = 0;
-
-       ba2str(&adapter->bdaddr, address);
-       snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address);
-
-       if (read_pairable_timeout(address, &timeout) == 0)
-               g_key_file_set_integer(key_file, "General",
-                                               "PairableTimeout", timeout);
-
-       if (read_discoverable_timeout(address, &timeout) == 0)
-               g_key_file_set_integer(key_file, "General",
-                                               "DiscoverableTimeout", timeout);
-
-       if (read_on_mode(address, str, sizeof(str)) == 0) {
-               mode = get_mode(str);
-               g_key_file_set_boolean(key_file, "General", "Discoverable",
-                                       mode == MODE_DISCOVERABLE);
-       }
-
-       if (read_local_name(&adapter->bdaddr, str) == 0)
-               g_key_file_set_string(key_file, "General", "Alias", str);
-
-       create_file(filename, S_IRUSR | S_IWUSR);
-
-       data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, data, length, NULL);
-       g_free(data);
-}
-
-static void fix_storage(struct btd_adapter *adapter)
-{
-       char filename[PATH_MAX];
-       char address[18];
-       char *converted;
-
-       ba2str(&adapter->bdaddr, address);
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/config", address);
-       converted = textfile_get(filename, "converted");
-       if (!converted)
-               return;
-
-       free(converted);
-
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/names", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/aliases", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/trusts", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/blocked", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/profiles", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/primaries", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/linkkeys", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/longtermkeys", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/classes", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/did", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/sdp", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/ccc", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/appearances", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/gatt", address);
-       textfile_del(filename, "converted");
-
-       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/proximity", address);
-       textfile_del(filename, "converted");
-}
-
 static void load_config(struct btd_adapter *adapter)
 {
       GKeyFile *key_file;
       char filename[PATH_MAX];
-       struct stat st;
       GError *gerr = NULL;
 
       key_file = g_key_file_new();
@@ -5752,11 +4926,6 @@ static void load_config(struct btd_adapter *adapter)
       snprintf(filename, PATH_MAX, STORAGEDIR "/%s/settings",
                                       btd_adapter_get_storage_dir(adapter));
 
-       if (stat(filename, &st) < 0) {
-               convert_config(adapter, filename, key_file);
-               convert_device_storage(adapter);
-       }
-
       g_key_file_load_from_file(key_file, filename, 0, NULL);
 
       /* Get alias */
@@ -8124,7 +7293,6 @@ static int adapter_register(struct btd_adapter *adapter)
 

load:

Quoted 8 lines
       load_config(adapter);
-       fix_storage(adapter);
       load_drivers(adapter);
       btd_profile_foreach(probe_profile, adapter);
       clear_blocked(adapter);

--
2.11.0

--
Luiz Augusto von Dentz

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw
In reply to Marcel Holtmann

Hi Marcel,

Quoted 10 lines · Marcel Holtmann

Hi Christian,

Quoted 5 lines

Added a config conversion tool for Bluez4 config, instead of doing the conversion in adapter.c

Christian Zimmermann (2):
Renamed Bluez4 config read functions
Added config converter for Bluez4 config conversion

so what is the intention here. I was going to just remove any 4.x support and more to BlueZ 6.0 soon. Actually BlueZ 5.x has been release over 6 years ago. I have pretty much zero interest in carrying / maintaining anything for BlueZ 4.x support.

These are just tools for converting the config options, I guess it is nice to keep them somewhere even if have long stop support 4.x APIs so that if there is anyone switching from 4.x it has some means to update the storage.

Signature · 1 line
Luiz Augusto von Dentz
maintainer
#6 lore raw

Hi Luiz,

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Added a config conversion tool for Bluez4 config, instead of doing the conversion in adapter.c

Christian Zimmermann (2):
Renamed Bluez4 config read functions
Added config converter for Bluez4 config conversion

Quoted 6 lines
Quoted 1 line

so what is the intention here. I was going to just remove any 4.x support and more to BlueZ 6.0 soon. Actually BlueZ 5.x has been release over 6 years ago. I have pretty much zero interest in carrying / maintaining anything for BlueZ 4.x support.

These are just tools for converting the config options, I guess it is nice to keep them somewhere even if have long stop support 4.x APIs so that if there is anyone switching from 4.x it has some means to update the storage.

that is all good and golden, but I was actually planning to go on a diet and remove really old stuff. There are so many tools and plugins in the repository that are really not used anymore and most likely will not be used any time soon. As I said, BlueZ 5 has been released over 6 years ago.

Regards

Marcel