linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/2] Added config conversion tool
@ 2019-01-27 11:56 Christian Zimmermann
  2019-01-27 11:56 ` [PATCH BlueZ 1/2] Renamed Bluez4 config read functions Christian Zimmermann
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Christian Zimmermann @ 2019-01-27 11:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Christian Zimmermann

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

-- 
2.11.0


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

* [PATCH BlueZ 1/2] Renamed Bluez4 config read functions
  2019-01-27 11:56 [PATCH BlueZ 0/2] Added config conversion tool Christian Zimmermann
@ 2019-01-27 11:56 ` Christian Zimmermann
  2019-01-27 11:56 ` [PATCH BlueZ 2/2] Added config converter for Bluez4 config conversion Christian Zimmermann
  2019-01-28 12:22 ` [PATCH BlueZ 0/2] Added config conversion tool Marcel Holtmann
  2 siblings, 0 replies; 7+ messages in thread
From: Christian Zimmermann @ 2019-01-27 11:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Christian Zimmermann

---
 src/adapter.c |  8 ++++----
 src/storage.c | 36 ++++++++----------------------------
 src/storage.h | 10 ++++++----
 3 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index b8a6bb6e2..f7c24fe62 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -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);
diff --git a/src/storage.c b/src/storage.c
index 8cbb5b270..779ca2bc8 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -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;
diff --git a/src/storage.h b/src/storage.h
index 1c0ad57ec..d84cc86db 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -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);
-- 
2.11.0


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

* [PATCH BlueZ 2/2] Added config converter for Bluez4 config conversion
  2019-01-27 11:56 [PATCH BlueZ 0/2] Added config conversion tool Christian Zimmermann
  2019-01-27 11:56 ` [PATCH BlueZ 1/2] Renamed Bluez4 config read functions Christian Zimmermann
@ 2019-01-27 11:56 ` Christian Zimmermann
  2019-01-28 12:22 ` [PATCH BlueZ 0/2] Added config conversion tool Marcel Holtmann
  2 siblings, 0 replies; 7+ messages in thread
From: Christian Zimmermann @ 2019-01-27 11:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: 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

diff --git a/.gitignore b/.gitignore
index d145ccdcd..b75e49bd6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
 
diff --git a/Makefile.am b/Makefile.am
index f84a1faba..4a157d714 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
diff --git a/Makefile.tools b/Makefile.tools
index 1f8271542..3221e2634 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -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
diff --git a/tools/config-conversion.c b/tools/config-conversion.c
new file mode 100644
index 000000000..2f4f79708
--- /dev/null
+++ b/tools/config-conversion.c
@@ -0,0 +1,129 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2019  Christian Zimmermann <zimmermach@gmail.com>
+ *
+ *
+ *  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.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+
+#include <sys/stat.h>
+#include <dirent.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+#include "lib/bluetooth.h"
+#include "src/storage.h"
+#include "src/textfile.h"
+#include "tools/config-conversion.h"
+
+#define MAX_NAME_LENGTH		248
+
+#define MODE_OFF		0x00
+#define MODE_CONNECTABLE	0x01
+#define MODE_DISCOVERABLE	0x02
+#define MODE_UNKNOWN		0xff
+
+static uint8_t str_to_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;
+}
+
+static uint8_t has_file(const char *path, const char *file)
+{
+	struct stat st;
+	char filename[PATH_MAX];
+
+	snprintf(filename, PATH_MAX, "%s/%s", path, file);
+	if (stat(filename, &st) == 0)
+		return true;
+	else
+		return false;
+}
+
+static uint8_t has_bluez4_config(const char *adapter_cfg_path)
+{
+	return has_file(adapter_cfg_path, "config");
+}
+
+static uint8_t has_bluez5_config(const char *adapter_cfg_path)
+{
+	return has_file(adapter_cfg_path, "settings");
+}
+
+void convert_bluez4_config(const char *cfg_path)
+{
+	char filename[PATH_MAX];
+	char str[MAX_NAME_LENGTH + 1];
+	char *key_file_data;
+	int timeout;
+	uint8_t mode;
+	GKeyFile *key_file;
+	gsize length = 0;
+
+	key_file = g_key_file_new();
+
+	//Create config file string(old config)
+	snprintf(filename, PATH_MAX, "%s/config", cfg_path);
+
+	//Convert old config values
+	if (bluez4_read_pairable_timeout(filename, &timeout) == 0)
+		g_key_file_set_integer(key_file, "General",
+					"PairableTimeout", timeout);
+
+	if (bluez4_read_discoverable_timeout(filename, &timeout) == 0)
+		g_key_file_set_integer(key_file, "General",
+					"DiscoverableTimeout", timeout);
+
+	if (bluez4_read_on_mode(filename, str, sizeof(str)) == 0) {
+		mode = str_to_mode(str);
+		g_key_file_set_boolean(key_file, "General", "Discoverable",
+					mode == MODE_DISCOVERABLE);
+	}
+
+	if (bluez4_read_local_name(filename, str) == 0)
+		g_key_file_set_string(key_file, "General", "Alias", str);
+
+	//Create settings file string(new config)
+	snprintf(filename, PATH_MAX, "%s/settings", cfg_path);
+
+	create_file(filename, 0600);
+
+	key_file_data = g_key_file_to_data(key_file, &length, NULL);
+	g_file_set_contents(filename, key_file_data, length, NULL);
+	g_free(key_file_data);
+	g_key_file_free(key_file);
+}
+
+void convert_config(const char *adapter_cfg_path, gboolean force)
+{
+	if ((has_bluez4_config(adapter_cfg_path) &&
+			!has_bluez5_config(adapter_cfg_path)) || force) {
+		convert_bluez4_config(adapter_cfg_path);
+		//TODO will be done in 2nd step
+		//convert_bluez4_device_storage(cfg_path);
+	}
+}
diff --git a/tools/config-conversion.h b/tools/config-conversion.h
new file mode 100644
index 000000000..eac789cec
--- /dev/null
+++ b/tools/config-conversion.h
@@ -0,0 +1,23 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2019  Christian Zimmermann <zimmermach@gmail.com>
+ *
+ *
+ *  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);
diff --git a/tools/config-converter.c b/tools/config-converter.c
new file mode 100644
index 000000000..ab9cab9a0
--- /dev/null
+++ b/tools/config-converter.c
@@ -0,0 +1,69 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2019  Christian Zimmermann <zimmermach@gmail.com>
+ *
+ *
+ *  This program 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 program 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.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include "tools/config-conversion.h"
+#include "lib/bluetooth.h"
+
+int main(int argc, char *argv[])
+{
+	int user;
+
+	user = getuid();
+	if (user == 0) {
+		char adapter_cfg_path[PATH_MAX];
+		char *adapter_address;
+		struct dirent *dir_entry;
+		DIR *cfg_dir;
+
+		cfg_dir = opendir(STORAGEDIR);
+		if (cfg_dir) {
+			dir_entry = readdir(cfg_dir);
+			while (dir_entry != NULL) {
+				adapter_address = dir_entry->d_name;
+				if (bachk(adapter_address)) {
+					dir_entry = readdir(cfg_dir);
+					continue;
+				}
+				snprintf(adapter_cfg_path, PATH_MAX,
+					STORAGEDIR "/%s", adapter_address);
+				convert_config(adapter_cfg_path, FALSE);
+
+				dir_entry = readdir(cfg_dir);
+			};
+		} else {
+			printf("Storage Dir: %s was not found\n"
+				, STORAGEDIR);
+		}
+	} else {
+		printf("Root privileges needed for conversion, since it touches %s directory\n"
+			, STORAGEDIR);
+	}
+}
diff --git a/unit/test-conversions.c b/unit/test-conversions.c
new file mode 100644
index 000000000..542a5d15c
--- /dev/null
+++ b/unit/test-conversions.c
@@ -0,0 +1,158 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2019  Christian Zimmermann <zimmermach@gmail.com>
+ *
+ *
+ *  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.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+#include "src/shared/tester.h"
+#include "src/textfile.h"
+#include "tools/config-conversion.h"
+
+#define MAX_NAME_LENGTH		248
+#define TEST_CONFIG_DIR "/tmp/bluez/"
+#define TEST_CONTROLLER_MAC "00:11:22:33:44:55"
+
+const char bluez4_cfg_file[] =
+"name unit_test\n"
+"pairto 234\n"
+"discovto 123\n"
+"onmode discoverable\n"
+"pairable yes\n";
+
+static void setup_bluez4_cfg_conversion_test(const void *test_data)
+{
+	int fd;
+	ssize_t bytes_written;
+	char filename[PATH_MAX];
+
+	snprintf(filename, PATH_MAX, "%s/config", TEST_CONFIG_DIR);
+	create_file(filename, 0600);
+	fd = open(filename, O_WRONLY);
+	if (fd < 0) {
+		tester_debug("Couldn't open file: %s\n", strerror(errno));
+		tester_setup_failed();
+		return;
+	}
+	bytes_written = write(fd, bluez4_cfg_file, sizeof(bluez4_cfg_file));
+	if (bytes_written < (ssize_t) sizeof(bluez4_cfg_file)) {
+		if (bytes_written == -1)
+			tester_debug("Couldn't write all Bytes to Bluez4 config file, error: %s\n"
+				, strerror(errno));
+		else
+			tester_debug("Couldn't write all Bytes to Bluez4 config file, not enough disk space\n");
+		close(fd);
+		tester_setup_failed();
+		return;
+	}
+	close(fd);
+	tester_setup_complete();
+}
+
+static void teardown_bluez4_cfg_conversion_test(const void *test_data)
+{
+	char filename[PATH_MAX];
+
+	snprintf(filename, PATH_MAX, "%s/config", TEST_CONFIG_DIR);
+	remove(filename);
+	snprintf(filename, PATH_MAX, "%s/settings", TEST_CONFIG_DIR);
+	remove(filename);
+	snprintf(filename, PATH_MAX, "%s", TEST_CONFIG_DIR);
+	remove(filename);
+	tester_teardown_complete();
+}
+
+static void run_bluez4_cfg_conversion_test(const void *test_data)
+{
+	struct stat st;
+	char filename[PATH_MAX];
+	int timeout;
+	gchar *alias;
+	gboolean discoverable;
+	GKeyFile *key_file;
+
+	convert_bluez4_config(TEST_CONFIG_DIR);
+	snprintf(filename, PATH_MAX, "%s/settings", TEST_CONFIG_DIR);
+	if (stat(filename, &st) != 0) {
+		tester_debug("No new settings file created!\n");
+		goto failed;
+	}
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
+	timeout = g_key_file_get_integer(key_file,
+				"General", "DiscoverableTimeout", NULL);
+	if (timeout != 123) {
+		tester_debug("Conversion failed, Discoverable Timeout not correct: %d, should be 123\n"
+			, timeout);
+		g_key_file_free(key_file);
+		goto failed;
+	}
+	timeout = g_key_file_get_integer(key_file,
+				"General", "PairableTimeout", NULL);
+	if (timeout != 234) {
+		tester_debug("Conversion failed, Pairable Timeout not correct: %d, should be 234\n"
+			, timeout);
+		g_key_file_free(key_file);
+		goto failed;
+	}
+	alias = g_key_file_get_string(key_file,
+				"General", "Alias", NULL);
+	if (strncmp(alias, "unit_test", 9) != 0) {
+		tester_debug("Conversion failed, Alias not correct: %s, should be unit_test\n"
+			, alias);
+		g_key_file_free(key_file);
+		g_free(alias);
+		goto failed;
+	}
+	discoverable = g_key_file_get_boolean(key_file,
+					"General", "Discoverable", NULL);
+	if (!discoverable) {
+		tester_debug("Conversion failed, Discoverable not correct:	 %d, should be true\n"
+			, discoverable);
+		g_key_file_free(key_file);
+		g_free(alias);
+		goto failed;
+	}
+	g_key_file_free(key_file);
+	g_free(alias);
+	tester_test_passed();
+	return;
+
+failed:
+	tester_test_failed();
+}
+
+int main(int argc, char *argv[])
+{
+	tester_init(&argc, &argv);
+	tester_add("bluez4_config_conversion", NULL,
+		setup_bluez4_cfg_conversion_test,
+		run_bluez4_cfg_conversion_test,
+		teardown_bluez4_cfg_conversion_test);
+
+	return tester_run();
+}
-- 
2.11.0


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

* Re: [PATCH BlueZ 0/2] Added config conversion tool
  2019-01-27 11:56 [PATCH BlueZ 0/2] Added config conversion tool Christian Zimmermann
  2019-01-27 11:56 ` [PATCH BlueZ 1/2] Renamed Bluez4 config read functions Christian Zimmermann
  2019-01-27 11:56 ` [PATCH BlueZ 2/2] Added config converter for Bluez4 config conversion Christian Zimmermann
@ 2019-01-28 12:22 ` Marcel Holtmann
  2019-01-28 12:48   ` Christian Zimmermann
  2019-01-28 12:52   ` Luiz Augusto von Dentz
  2 siblings, 2 replies; 7+ messages in thread
From: Marcel Holtmann @ 2019-01-28 12:22 UTC (permalink / raw)
  To: Christian Zimmermann; +Cc: linux-bluetooth

Hi Christian,

> 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


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

* Re: [PATCH BlueZ 0/2] Added config conversion tool
  2019-01-28 12:22 ` [PATCH BlueZ 0/2] Added config conversion tool Marcel Holtmann
@ 2019-01-28 12:48   ` Christian Zimmermann
  2019-01-28 12:52   ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 7+ messages in thread
From: Christian Zimmermann @ 2019-01-28 12:48 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 1489 bytes --]

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

> Am 28.01.2019 um 13:22 schrieb Marcel Holtmann <marcel@holtmann.org>:
> 
> Hi Christian,
> 
>> 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
> 

[-- Attachment #2: Re: [PATCH BlueZ] src_adapter: Removed obsolete conversion functions for persistant settings.eml --]
[-- Type: message/rfc822, Size: 38533 bytes --]

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: zimmermach@gmail.com
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH BlueZ] src/adapter: Removed obsolete conversion functions for persistant settings
Date: Sat, 10 Nov 2018 19:58:03 +0200
Message-ID: <CABBYNZLs5Aw=+dkBuid_YbQvkyiHLiAvHG9muQJRnXXwve7qtQ@mail.gmail.com>

Hi Christian,
On Sat, Nov 10, 2018 at 4:34 PM Christian Zimmermann
<zimmermach@gmail.com> wrote:
>
> 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.

> Regards,
> Christian
>
> > Am 07.11.2018 um 12:37 schrieb Luiz Augusto von Dentz <luiz.dentz@gmail.com>:
> >
> > Hi Christian,
> >
> > On Mon, Nov 5, 2018 at 6:10 PM Christian Zimmermann
> > <zimmermach@gmail.com> wrote:
> >>
> >> 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.
> >
> >> ---
> >> TODO          |   6 -
> >> src/adapter.c | 832 ----------------------------------------------------------
> >> 2 files changed, 838 deletions(-)
> >>
> >> diff --git a/TODO b/TODO
> >> index d88349e06..ae2d69dfa 100644
> >> --- a/TODO
> >> +++ b/TODO
> >> @@ -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.
> >> diff --git a/src/adapter.c b/src/adapter.c
> >> index c24432125..5709ee956 100644
> >> --- a/src/adapter.c
> >> +++ b/src/adapter.c
> >> @@ -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:
> >>        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



-- 
Luiz Augusto von Dentz

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

* Re: [PATCH BlueZ 0/2] Added config conversion tool
  2019-01-28 12:22 ` [PATCH BlueZ 0/2] Added config conversion tool Marcel Holtmann
  2019-01-28 12:48   ` Christian Zimmermann
@ 2019-01-28 12:52   ` Luiz Augusto von Dentz
  2019-01-28 13:30     ` Marcel Holtmann
  1 sibling, 1 reply; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2019-01-28 12:52 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Christian Zimmermann, linux-bluetooth

Hi Marcel,
On Mon, Jan 28, 2019 at 2:24 PM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Christian,
>
> > 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.

-- 
Luiz Augusto von Dentz

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

* Re: [PATCH BlueZ 0/2] Added config conversion tool
  2019-01-28 12:52   ` Luiz Augusto von Dentz
@ 2019-01-28 13:30     ` Marcel Holtmann
  0 siblings, 0 replies; 7+ messages in thread
From: Marcel Holtmann @ 2019-01-28 13:30 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Christian Zimmermann, linux-bluetooth

Hi Luiz,

>>> 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.

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


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

end of thread, other threads:[~2019-01-28 13:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-27 11:56 [PATCH BlueZ 0/2] Added config conversion tool Christian Zimmermann
2019-01-27 11:56 ` [PATCH BlueZ 1/2] Renamed Bluez4 config read functions Christian Zimmermann
2019-01-27 11:56 ` [PATCH BlueZ 2/2] Added config converter for Bluez4 config conversion Christian Zimmermann
2019-01-28 12:22 ` [PATCH BlueZ 0/2] Added config conversion tool Marcel Holtmann
2019-01-28 12:48   ` Christian Zimmermann
2019-01-28 12:52   ` Luiz Augusto von Dentz
2019-01-28 13:30     ` Marcel Holtmann

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).