Skip to contentSkip to conversation

add support for multiple serial proxies configuration

PATCH In review Forrest Zhao 2 participants 2 messages Jul 24, 2009 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add support for multiple serial proxies configuration

---
 serial/Makefile.am |    2 +
 serial/proxy.c     |  230 +++++++++++++++++++++++++++++++++++++++-------------
 serial/serial.conf |   10 +++
 3 files changed, 184 insertions(+), 58 deletions(-)
 create mode 100644 serial/serial.conf
serial/Makefile.am +2 -0
index 4fa455f..c88a980 100644
@@ -19,4 +19,6 @@ AM_CFLAGS = -fvisibility=hidden \
 
 INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/src
 
+EXTRA_DIST = serial.conf
+
 MAINTAINERCLEANFILES = Makefile.in
serial/proxy.c +172 -58

307 lines not on this page · raw message

serial/serial.conf new file +10 -0
new file mode 100644
index 0000000..982dcdd
@@ -0,0 +1,10 @@
+# Configuration file for serial
+
+# There could be multiple proxy sections, the format is [Proxy <user chosen name>]
+[Proxy DUN]
+
+# UUID for DUN proxy service
+#UUID=00001103-0000-1000-8000-00805F9B34FB
+
+# Address for device node
+#Address=/dev/ttyx
Signature · 1 line
1.5.4.5
#1 lore raw

Hi Forrest,

Quoted 6 lines · Forrest Zhao
---
 serial/Makefile.am |    2 +
 serial/proxy.c     |  230 +++++++++++++++++++++++++++++++++++++++-------------
 serial/serial.conf |   10 +++
 3 files changed, 184 insertions(+), 58 deletions(-)
 create mode 100644 serial/serial.conf

I finally pushed this upstream but still had to make quite a lot of changes.

serial/proxy.c static DBusMessage *proxy_enable(DBusConnection *conn, · line 580

Quoted 2 lines
serial/proxy.c +2 -0
+		return g_dbus_create_error(msg, ERROR_INTERFACE "Failed",
+				"Proxy enable failed (%s)",  strerror(-err));

Two spaces before strerror.

serial/proxy.c static int proxy_pathcmp(gconstpointer proxy, gconstpointer p) · line 1019

Quoted 6 lines
serial/proxy.c +1 -1
 	g_dbus_emit_signal(adapter->conn,
 			adapter_get_path(adapter->btd_adapter),
 			SERIAL_MANAGER_INTERFACE, "ProxyCreated",
-			DBUS_TYPE_STRING, &ppath,
+			DBUS_TYPE_STRING, &path,
 			DBUS_TYPE_INVALID);

These could be indented at least with one more tab.

serial/proxy.c static int proxy_pathcmp(gconstpointer proxy, gconstpointer p) · line 1031

Quoted 8 lines
serial/proxy.c +8 -0
+static DBusMessage *create_proxy(DBusConnection *conn,
+				DBusMessage *msg, void *data)
+{
+	struct serial_adapter *adapter = data;
+	char path[MAX_PATH_LENGTH + 1];
+	const char *pattern, *address;
+	char *uuid_str, *ppath = path;
+	uuid_t uuid;

The uuid variable is never used in this function except for getting set once by the following:

Quoted 14 lines
serial/proxy.c +13 -0
+	bt_string2uuid(&uuid, uuid_str);
 
+static void serial_proxy_init(struct serial_adapter *adapter)
+{
+	GKeyFile *config;
+	GError *gerr = NULL;
+	const char *file = CONFIGDIR "/serial.conf";
+	char **group_list;
+	int i;
+
+	config = g_key_file_new();
+
+	if (!g_key_file_load_from_file(config, file, 0, &gerr)) {
+		error("Parsing %s failed: %s", file, gerr->message);

serial/proxy.c static struct serial_adapter *find_adapter(GSList *list, · line 1264

Quoted 10 lines
serial/proxy.c +10 -0
+		g_error_free(gerr);
+		g_key_file_free(config);
+		return;
+	}
+
+	group_list = g_key_file_get_groups(config, NULL);
+
+	for (i = 0; group_list[i] != NULL; i++) {
+		char *group_str = group_list[i], *uuid_str, *address;
+		uuid_t uuid;

Same with this uuid variable.

serial/proxy.c static struct serial_adapter *find_adapter(GSList *list, · line 1273

Quoted 3 lines
serial/proxy.c +3 -0
+		/* string length of "Proxy" is 5 */
+		if (strlen(group_str) < 5 || strncmp(group_str, "Proxy", 5))
+			continue;

Hmm, I actually forgot to change this one, but isn't just the strncmp call enough here (i.e. no need for strlen)?

serial/proxy.c static struct serial_adapter *find_adapter(GSList *list, · line 1285

Quoted 11 lines
serial/proxy.c +11 -0
+		uuid_str = g_key_file_get_string(config, group_str, "UUID",
+							&gerr);
+		if (gerr) {
+			debug("%s: %s", file, gerr->message);
+			g_error_free(gerr);
+			g_key_file_free(config);
+			return;
+		}
+		address = g_key_file_get_string(config, group_str, "Address",
+							&gerr);
+		if (gerr) {

There should be an empty line before address = ...

serial/proxy.c static struct serial_adapter *find_adapter(GSList *list, · line 1313

Quoted 3 lines
serial/proxy.c +3 -0
+				if (err < 0)
+					error("Proxy enable failed (%s)",
+							 strerror(-err));

Mixing tabs and spaces for indentation.

serial/proxy.c static struct serial_adapter *find_adapter(GSList *list, · line 1324

Quoted 4 lines
serial/proxy.c +4 -0
+	g_strfreev(group_list);
+	g_key_file_free(config);
+	return;
+}

Redundant return statement at the end of void function.

Quoted 6 lines
serial/serial.conf new file +0 -0
new file mode 100644
index 0000000..982dcdd

serial/serial.conf line 10

Quoted 10 lines
serial/serial.conf new file +10 -0
@@ -0,0 +1,10 @@
+# Configuration file for serial
+
+# There could be multiple proxy sections, the format is [Proxy <user chosen name>]
+[Proxy DUN]
+
+# UUID for DUN proxy service
+#UUID=00001103-0000-1000-8000-00805F9B34FB
+
+# Address for device node
+#Address=/dev/ttyx

I think the [Proxy DUN] should also be commented out along with the other lines.

Even after these changes there are still the following issues that need fixing:

1. After creating a proxy through serial.conf the first time bluetoothd stores some info about it in /var/lib/bluetooth/.../proxy. The next time bluetoothd starts it fails to register (or at least I don't see the local service record anymore)

2. The UUID in the service record should be reduced to 16 or 32 bit format if it is derived from the Bluetooth base UUID.

3. The Name attribute for the records should (if we are going to keep them generic) "Serial Proxy" instead of the current (imho confusing) "Port Proxy Entity".

Johan