Skip to contentSkip to conversation

Some thoughts on the current D-BUS interface

Bluez-devel Johan Hedberg 5 participants 14 messages Oct 31, 2005 – Nov 2, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi,

We discussed on IRC with Claudio about the current D-BUS interface state and decided that it would be good to have yet another thread about it. The discussion actually started with me wondering about why there are now two different DeviceList methods (one in the Device path and another in the Manager path). It then evolved to the access control policies and the differences between the Manager and Device paths.

It seems I hadn't really understood how the current design was meant to to function, what internal assumptions there are, etc. I finally ended up going through the HAL and NetworkManager[1] D-BUS interfaces and comparing them with our current interface. As a result, here are some ideas on how I think we should change the D-BUS interface.

[1] http://people.redhat.com/dcbw/NetworkManager/

We have borrowed the names "Manager" and "Device" from the HAL D-BUS interface. However, they are currently used in a very different way than in HAL (I'll explain this difference in the next paragraphs). This will surely be quite confusing to someone trying to understand our interface by relating to the HAL spec. In my opinion our options are to either not use those names or to change the behaviour of our interface to be more similar to HAL. I would suggest the latter.

As I mentioned, HAL has also a Manager and Device path. The Manager path is used to discover available (local) devices, and not much else. It provides methods for getting available device lists as well as signals for removed or added devices. The actual device identifiers used by these signals and methods are strings refering to D-BUS object paths in the Device object path hierarchy. The objects in the Device object path hierachy in turn represent the actual devices and provide interfaces to perform different operations with them.

Our current interface design mixes these two functions: we have both device discovery as well as device operations in both paths. To simplify it (at least in my mind ;-), and to make it more similar to the HAL one, I would suggest that we implement the following type of structure for our interface:

Well-known path: /org/bluez/Manager
Interface: org.bluez.Manager
Methods: DeviceList, DefaultDevice
Signals: DeviceAdded, DeviceRemoved

The device identifiers used by the manager interface methods and signals would be D-BUS object paths such as "/org/bluez/Device/hci0". To allow discovering device sub-paths (e.g. "PAN" or "RFCOMM"), the Manager interface could also provide an additional method which would return the sub-paths as a string list.

I've also mentioned a new method, DefaultDevice, which would return a string representing some real device path (or an error e.g. "org.bluez.NoDevices"). Having a DefaultDevice method should simplify the implementation since there's no need to handle the special case of a default device path.

The toplevel device paths (e.g. "/org/bluez/Device/hci0", would implement an interface "org.bluez.Device" which would provide a set of methods that are common for all devices (if needed this could be split up to several interfaces also, e.g. in a hcitool vs. hciconfig fashion).

The proposed changes wouldn't really change the current implemented methods in any way - it would only change their place in the object hierarchy. Well, actually that's not quite true: the DeviceList and Device(Added|Removed) signals would start using object paths as device identifiers instead of device names. One benefit of this is that we can later shuffle around the structure of the Device path hierarchy without introducing API incompatibilities.

Any comments?

Johan

-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course Free Certification Exam for All Training Attendees Through End of 2005 Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#1 lore raw

Hi Johan,

Quoted 15 lines

We discussed on IRC with Claudio about the current D-BUS interface state and decided that it would be good to have yet another thread about it. The discussion actually started with me wondering about why there are now two different DeviceList methods (one in the Device path and another in the Manager path). It then evolved to the access control policies and the differences between the Manager and Device paths.

It seems I hadn't really understood how the current design was meant to to function, what internal assumptions there are, etc. I finally ended up going through the HAL and NetworkManager[1] D-BUS interfaces and comparing them with our current interface. As a result, here are some ideas on how I think we should change the D-BUS interface.

[1] http://people.redhat.com/dcbw/NetworkManager/

Quoted 7 lines

We have borrowed the names "Manager" and "Device" from the HAL D-BUS interface. However, they are currently used in a very different way than in HAL (I'll explain this difference in the next paragraphs). This will surely be quite confusing to someone trying to understand our interface by relating to the HAL spec. In my opinion our options are to either not use those names or to change the behaviour of our interface to be more similar to HAL. I would suggest the latter.

I think this is my fault, because I started proposing the names "Device" and "Manager" and not taking care of that they are used in the same way HAL is using them. I prefer to go with the HAL design. These guys have the most experiences in using D-Bus (because it was written to support the HAL idea in the first place) and their interface has been proofed in real applications.

Quoted 15 lines

As I mentioned, HAL has also a Manager and Device path. The Manager path is used to discover available (local) devices, and not much else. It provides methods for getting available device lists as well as signals for removed or added devices. The actual device identifiers used by these signals and methods are strings refering to D-BUS object paths in the Device object path hierarchy. The objects in the Device object path hierachy in turn represent the actual devices and provide interfaces to perform different operations with them.

Our current interface design mixes these two functions: we have both device discovery as well as device operations in both paths. To simplify it (at least in my mind ;-), and to make it more similar to the HAL one, I would suggest that we implement the following type of structure for our interface:

Quoted 4 lines

Well-known path: /org/bluez/Manager
Interface: org.bluez.Manager
Methods: DeviceList, DefaultDevice
Signals: DeviceAdded, DeviceRemoved

Sound perfectly fine to me. Do you have a patch for this change?

Quoted 11 lines

The device identifiers used by the manager interface methods and signals would be D-BUS object paths such as "/org/bluez/Device/hci0". To allow discovering device sub-paths (e.g. "PAN" or "RFCOMM"), the Manager interface could also provide an additional method which would return the sub-paths as a string list.

I've also mentioned a new method, DefaultDevice, which would return a string representing some real device path (or an error e.g. "org.bluez.NoDevices"). Having a DefaultDevice method should simplify the implementation since there's no need to handle the special case of a default device path.

I also agree on this one.

Quoted 4 lines

The toplevel device paths (e.g. "/org/bluez/Device/hci0", would implement an interface "org.bluez.Device" which would provide a set of methods that are common for all devices (if needed this could be split up to several interfaces also, e.g. in a hcitool vs. hciconfig fashion).

We need one interface to do the local device configuration and one for the actual interaction with remote devices. This was the basic idea behind the split into hcitool and hciconfig back then. And I think such approach is still valid and useful.

Quoted 7 lines

The proposed changes wouldn't really change the current implemented methods in any way - it would only change their place in the object hierarchy. Well, actually that's not quite true: the DeviceList and Device(Added|Removed) signals would start using object paths as device identifiers instead of device names. One benefit of this is that we can later shuffle around the structure of the Device path hierarchy without introducing API incompatibilities.

Feel free to send in a patch. For me these proposed changes are sounding perfectly sane and I am happy to try them out. However it would be great if you can include some small test applications written in Python like Eduardo did.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course Free Certification Exam for All Training Attendees Through End of 2005 Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw

Hi Marcel,

Quoted 4 lines · Marcel Holtmann

Feel free to send in a patch. For me these proposed changes are sounding perfectly sane and I am happy to try them out. However it would be great if you can include some small test applications written in Python like Eduardo did.

Thanks for your encouraging reply! I don't yet have a patch for the changes, but I'll try to produce one during tommorow (Tuesday). I'll also try to provide some small python test apps as well as update the pygtk app I have been working on.

Johan

-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course Free Certification Exam for All Training Attendees Through End of 2005 Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#3 lore raw

Hi,

These changes are very nice! The effort to change the paths will be small.

Now, /org/bluez/Device should be registered using a fallback approach and this "root" path should reply for messages sent to a invalid/unregistered device path. The Manager path, can be registered as a normal path without care about child paths.

Considering that local and remote configuration tasks will be available under the same path, we need change the child path register/unregister action. When a device is turned DOWN the path can't be unregistered anymore. We can use the attribute "status" of the struct "profile_obj_path_data" to control this. I think this attribute was initially added with this purpose :)
Any comment? Does someone has another suggestion?

Remove the default device path good, a default path was inserting confusion when sending signals and replies.

Regards,
Claudio.

Quoted 4 lines · Johan Hedberg

Hi Marcel,

Quoted 1 line · Marcel Holtmann

Feel free to send in a patch. For me these proposed changes are soundin=

g

Quoted 1 line
Quoted 1 line

perfectly sane and I am happy to try them out. However it would be grea=

t

Quoted 11 lines
Quoted 2 lines

if you can include some small test applications written in Python like Eduardo did.

Thanks for your encouraging reply! I don't yet have a patch for the changes, but I'll try to produce one during tommorow (Tuesday). I'll also try to provide some small python test apps as well as update the pygtk app I have been working on.

Johan

Quoted 10 lines

-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course Free Certification Exam for All Training Attendees Through End of 2005 Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course Free Certification Exam for All Training Attendees Through End of 2005 Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw

Hi,

Here's the patch which implements the interface redesign. The change ended up being a little bigger than I originally thought, but I think the code and interface become more understandable this way. Attached is also a simple python app which tests the DeviceList and DefaultDevice methods. I've also updated the pygtk test app to work with the new interface:
http://www.iki.fi/~jhedberg/bluez-python/

Quoted 7 lines · Claudio Takahasi

Considering that local and remote configuration tasks will be available under the same path, we need change the child path register/unregister action. When a device is turned DOWN the path can't be unregistered anymore. We can use the attribute "status" of the struct "profile_obj_path_data" to control this. I think this attribute was initially added with this purpose :)
Any comment? Does someone has another suggestion?

My idea is that we would use paths such as "/org/bluez/Device/hci0" for the Up/Down stuff as well as other device configuration. The "/org/bluez/Device/hci0/Controller" path in turn is used for the other things and it us unregistered/registered during Down/Up events.

Johan

Index: hcid/dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.39

dbus.c +260 -457
diff -u -r1.39 dbus.c
@@ -45,15 +45,16 @@
 #include "dbus.h"
 
 static DBusConnection *connection;
+static int default_dev = -1;
 static int up_adapters = 0;
 
-#define TIMEOUT (30 * 1000)		/* 30 seconds */
-#define BLUETOOTH_DEVICE_NAME_LEN    (18)
-#define BLUETOOTH_DEVICE_ADDR_LEN    (18)
-#define MAX_PATH_LENGTH   (64)
-#define READ_REMOTE_NAME_TIMEOUT	(25000)
-#define MAX_CONN_NUMBER			(10)
-#define DEVICE_FLAG_NAME		(16)
+#define TIMEOUT				(30 * 1000)	/* 30 seconds */
+#define BLUETOOTH_DEVICE_NAME_LEN	18
+#define BLUETOOTH_DEVICE_ADDR_LEN	18
+#define MAX_PATH_LENGTH			64
+#define READ_REMOTE_NAME_TIMEOUT	25000
+#define MAX_CONN_NUMBER			10
+#define DEVICE_FLAG_NAME		16
 
 #define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
 #define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -77,13 +78,13 @@
 	uint16_t id;
 };
 
-typedef int register_function_t(DBusConnection *conn, int dft_reg, uint16_t id);
-typedef int unregister_function_t(DBusConnection *conn, int unreg_dft, uint16_t id);
+typedef int register_function_t(DBusConnection *conn, uint16_t id);
+typedef int unregister_function_t(DBusConnection *conn, uint16_t id);
 
 const struct service_data *get_hci_table(void);
 
-static int hci_dbus_reg_obj_path(DBusConnection *conn, int dft_reg, uint16_t id);
-static int hci_dbus_unreg_obj_path(DBusConnection *conn, int unreg_dft, uint16_t id);
+static int hci_dbus_reg_obj_path(DBusConnection *conn, uint16_t id);
+static int hci_dbus_unreg_obj_path(DBusConnection *conn, uint16_t id);
 
 typedef const struct service_data *get_svc_table_func_t(void);
 
@@ -257,8 +258,8 @@
 static DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data);
 static DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data);
 
-static DBusMessage* handle_get_devices_req_device(DBusMessage *msg, void *data);
-static DBusMessage* handle_get_devices_req_manager(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_default_device_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
 
 static const DBusObjectPathVTable obj_dev_vtable = {
@@ -271,16 +272,7 @@
 	.unregister_function = NULL
 };
 
-/*
- * Service provided under the path DEVICE_PATH
- * TODO add the handlers
- */
-static const struct service_data dev_root_services[] = {
-	{ DEV_GET_DEV,		handle_get_devices_req_device,	DEV_GET_DEV_SIGNATURE		},
-	{ NULL, NULL, NULL}
-};
-
-static const struct service_data dev_services[] = {
+static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_not_implemented_req,	DEV_UP_SIGNATURE		},
 	{ DEV_DOWN,		handle_not_implemented_req,	DEV_DOWN_SIGNATURE		},
 	{ DEV_RESET,		handle_not_implemented_req,	DEV_RESET_SIGNATURE		},
@@ -293,11 +285,12 @@
  * Manager Message handler functions object table declaration
  *
  */
-static const struct service_data mgr_services[] = {
-	{ MGR_GET_DEV,		handle_get_devices_req_manager,	MGR_GET_DEV_SIGNATURE	},
-	{ MGR_INIT,		handle_not_implemented_req,	NULL			},
-	{ MGR_ENABLE,		handle_not_implemented_req,	NULL			},
-	{ MGR_DISABLE,		handle_not_implemented_req,	NULL			},
+static const struct service_data manager_services[] = {
+	{ MGR_DEVICE_LIST,	handle_device_list_req,		MGR_GET_DEV_SIGNATURE		},
+	{ MGR_DEFAULT_DEVICE,	handle_default_device_req,	MGR_DEFAULT_DEV_SIGNATURE	},
+	{ MGR_INIT,		handle_not_implemented_req,	NULL				},
+	{ MGR_ENABLE,		handle_not_implemented_req,	NULL				},
+	{ MGR_DISABLE,		handle_not_implemented_req,	NULL				},
 	{ NULL, NULL, NULL }
 };
 
@@ -316,7 +309,7 @@
 static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_auth_req(DBusMessage *msg, void *data);
 
-static const struct service_data hci_services[] = {
+static const struct service_data device_hci_services[] = {
 	{ HCI_PERIODIC_INQ,		handle_periodic_inq_req,	HCI_PERIODIC_INQ_SIGNATURE		},
 	{ HCI_CANCEL_PERIODIC_INQ,	handle_cancel_periodic_inq_req,	HCI_CANCEL_PERIODIC_INQ_SIGNATURE	},
 	{ HCI_ROLE_SWITCH,		handle_role_switch_req,		HCI_ROLE_SWITCH_SIGNATURE		},
@@ -384,7 +377,7 @@
 	free(req);
 }
 
-static gboolean register_dbus_path(char *path, uint16_t id, const DBusObjectPathVTable *pvtable)
+static gboolean register_dbus_path(const char *path, uint16_t id, const DBusObjectPathVTable *pvtable)
 {
 	struct hci_dbus_data *data;
 	syslog(LOG_INFO,"Registering DBUS Path: %s", path);
@@ -403,7 +396,7 @@
 	return TRUE;
 }
 
-static gboolean unregister_dbus_path(char *path)
+static gboolean unregister_dbus_path(const char *path)
 {
 	void *data;
 	syslog(LOG_INFO,"Unregistering DBUS Path: %s", path);
@@ -477,10 +470,9 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
 
-	message = dbus_message_new_signal(path,
-				BLUEZ_HCI_INTERFACE, BLUEZ_HCI_INQ_START);
+	message = dbus_message_new_signal(path, DEV_HCI_INTERFACE, BLUEZ_HCI_INQ_START);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS inquiry start message");
 		goto failed;
@@ -517,10 +509,10 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
 
 	message = dbus_message_new_signal(path,
-				BLUEZ_HCI_INTERFACE, BLUEZ_HCI_INQ_COMPLETE);
+				DEV_HCI_INTERFACE, BLUEZ_HCI_INQ_COMPLETE);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
 		goto failed;
@@ -560,10 +552,10 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
 
 	message = dbus_message_new_signal(path,
-				BLUEZ_HCI_INTERFACE, BLUEZ_HCI_INQ_RESULT);
+				DEV_HCI_INTERFACE, BLUEZ_HCI_INQ_RESULT);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS inquiry result message");
 		goto failed;
@@ -608,10 +600,10 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
 
 	message = dbus_message_new_signal(path,
-				BLUEZ_HCI_INTERFACE, BLUEZ_HCI_REMOTE_NAME);
+				DEV_HCI_INTERFACE, BLUEZ_HCI_REMOTE_NAME);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
@@ -655,10 +647,10 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
 
 	message = dbus_message_new_signal(path,
-				BLUEZ_HCI_INTERFACE, BLUEZ_HCI_REMOTE_NAME_FAILED);
+				DEV_HCI_INTERFACE, BLUEZ_HCI_REMOTE_NAME_FAILED);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
@@ -710,9 +702,9 @@
 		goto failed;
 	}
 
-	snprintf(path, sizeof(path), "%s/hci%d/%s", MANAGER_PATH, id, BLUEZ_HCI);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
 
-	message = dbus_message_new_signal(path, BLUEZ_HCI_INTERFACE, BLUEZ_HCI_AUTH_COMPLETE);
+	message = dbus_message_new_signal(path, DEV_HCI_INTERFACE, BLUEZ_HCI_AUTH_COMPLETE);
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
@@ -810,6 +802,26 @@
 		remove_watch(watch, data);
 }
 
+static gboolean unregister_device_path(const char *path)
+{
+	char **children = NULL;
+
+	if (dbus_connection_list_registered(connection, path, &children)) {
+		for (; *children; children++) {
+			char child_path[MAX_PATH_LENGTH];
+
+			snprintf(child_path, sizeof(child_path), "%s/%s", path, *children);
+
+			unregister_dbus_path(child_path);
+		}
+
+		if (*children)
+			dbus_free_string_array(children);
+	}
+
+	return unregister_dbus_path(path);
+}
+
 gboolean hcid_dbus_init(void)
 {
 	struct hci_dbus_data *data;
@@ -854,7 +866,7 @@
 
 	data->id = MANAGER_PATH_ID;
 
-	if (!dbus_connection_register_fallback(connection, MANAGER_PATH,
+	if (!dbus_connection_register_object_path(connection, MANAGER_PATH,
 						&obj_mgr_vtable, data)) {
 		syslog(LOG_ERR, "Can't register %s object", MANAGER_PATH);
 		return FALSE;
@@ -873,149 +885,137 @@
 
 void hcid_dbus_exit(void)
 {
-	char path[MAX_PATH_LENGTH];
-	char fst_parent[] = MANAGER_PATH;
-	char snd_parent[MAX_PATH_LENGTH];
-	char **fst_level = NULL;
-	char **snd_level = NULL;
-	char *ptr1;
-	char *ptr2;
-	void *data = NULL;
+	char **children = NULL;
 
 	if (!connection)
 		return;
 
-	if (dbus_connection_get_object_path_data(connection,
-				DEVICE_PATH, &data)) {
-		if (data) {
-			free(data);
-			data = NULL;
-		}
-	}
+	/* Unregister all paths in Device path hierarchy */
+	if (dbus_connection_list_registered(connection, DEVICE_PATH, &children)) {
+
+		for (; *children; children++) {
+			char dev_path[MAX_PATH_LENGTH];
 
-	if (!dbus_connection_unregister_object_path(connection, DEVICE_PATH))
-		syslog(LOG_ERR, "Can't unregister %s object", DEVICE_PATH);
+			snprintf(dev_path, sizeof(dev_path), "%s/%s", DEVICE_PATH, *children);
 
-	if (dbus_connection_get_object_path_data(connection,
-				MANAGER_PATH, &data)) {
-		if (data) {
-			free(data);
-			data = NULL;
+			unregister_device_path(dev_path);
 		}
+
+		if (*children)
+			dbus_free_string_array(children);
 	}
 
-	if (!dbus_connection_unregister_object_path(connection, MANAGER_PATH))
-		syslog(LOG_ERR, "Can't unregister %s object", MANAGER_PATH);
+	unregister_dbus_path(DEVICE_PATH);
+	unregister_dbus_path(MANAGER_PATH);
 
-	if (dbus_connection_list_registered(connection, fst_parent, &fst_level)) {
+}
 
-		for (; *fst_level; fst_level++) {
-			ptr1 = *fst_level;
-			snprintf(snd_parent, sizeof(snd_parent), "%s/%s", fst_parent, ptr1);
+gboolean hcid_dbus_register_device(uint16_t id) 
+{
+	char path[MAX_PATH_LENGTH];
+	char *pptr = path;
+	gboolean ret;
+	DBusMessage *message = NULL;
 
-			if (dbus_connection_list_registered(connection, snd_parent, &snd_level)) {
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
 
-				if (!(*snd_level)) {
-					snprintf(path, sizeof(path), "%s/%s", MANAGER_PATH, ptr1);
+	message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE,
+					BLUEZ_MGR_DEV_ADDED);
 
-					if (dbus_connection_get_object_path_data(connection,
-								path, &data)) {
-						if (data) {
-							free(data);
-							data = NULL;
-						}
-					}
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
+		goto out;
+	}
 
-					if (!dbus_connection_unregister_object_path(connection, path))
-						syslog(LOG_ERR, "Can't unregister %s object", path);
+	dbus_message_append_args(message,
+			DBUS_TYPE_STRING, &pptr,
+			DBUS_TYPE_INVALID);
 
-					continue;
-				}
+	if (!dbus_connection_send(connection, message, NULL)) {
+		syslog(LOG_ERR, "Can't send D-BUS added device message");
+		goto out;
+	}
 
-				for (; *snd_level; snd_level++) {
-					ptr2 = *snd_level;
-					snprintf(path, sizeof(path), "%s/%s/%s", MANAGER_PATH, ptr1, ptr2);
-
-					if (dbus_connection_get_object_path_data(connection,
-								path, &data)) {
-						if (data) {
-							free(data);
-							data = NULL;
-						}
-					}
+	dbus_connection_flush(connection);
 
-					if (!dbus_connection_unregister_object_path(connection, path))
-						syslog(LOG_ERR, "Can't unregister %s object", path);
-				}
+out:
+	if (message)
+		dbus_message_unref(message);
 
-				if (*snd_level)
-					dbus_free_string_array(snd_level);
-			}
-		}
+	ret = register_dbus_path(path, id, &obj_dev_vtable);
 
-		if (*fst_level)
-			dbus_free_string_array(fst_level);
-	}
+	if (ret && default_dev < 0)
+		default_dev = id;
+
+	return ret;
 }
 
-gboolean hcid_dbus_register_device(uint16_t id) 
+gboolean hcid_dbus_unregister_device(uint16_t id)
 {
+	gboolean ret;
+	DBusMessage *message = NULL;
 	char path[MAX_PATH_LENGTH];
-	char dev[BLUETOOTH_DEVICE_NAME_LEN];
-	const char *pdev = dev;
+	char *pptr = path;
 
-	snprintf(dev, sizeof(dev), HCI_DEVICE_NAME "%d", id);
-	snprintf(path, sizeof(path), "%s/%s", DEVICE_PATH, pdev);
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
 
-	/* register the default path*/
-	return register_dbus_path(path, id, &obj_dev_vtable);
-}
+	message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE,
+					BLUEZ_MGR_DEV_REMOVED);
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
+		goto out;
+	}
 
-gboolean hcid_dbus_unregister_device(uint16_t id)
-{
-	char dev[BLUETOOTH_DEVICE_NAME_LEN];
-	char path[MAX_PATH_LENGTH];
-	const char *pdev = dev;
+	dbus_message_append_args(message,
+			DBUS_TYPE_STRING, &pptr,
+			DBUS_TYPE_INVALID);
 
-	snprintf(dev, sizeof(dev), HCI_DEVICE_NAME "%d", id);
-	snprintf(path, sizeof(path), "%s/%s", DEVICE_PATH, pdev);
+	if (!dbus_connection_send(connection, message, NULL)) {
+		syslog(LOG_ERR, "Can't send D-BUS added device message");
+		goto out;
+	}
 
-	return unregister_dbus_path(path);
+	dbus_connection_flush(connection);
+
+out:
+	if (message)
+		dbus_message_unref(message);
+
+	ret = unregister_device_path(path);
+
+	/* FIXME: If there are any devices left after this removal the default
+	 * device should be changed to one of them */
+	if (ret && default_dev == id)
+		default_dev = -1;
+
+	return ret;
 }
 
-gboolean hcid_dbus_register_manager(uint16_t id)
+gboolean hcid_dbus_dev_up(uint16_t id)
 {
-	char dev[BLUETOOTH_DEVICE_NAME_LEN];
+	char path[MAX_PATH_LENGTH];
 	struct profile_obj_path_data *ptr = obj_path_table;
 	DBusMessage *message = NULL;
-	const char *pdev = dev;
-	DBusMessageIter iter;
-	int ret = -1; 
 
 	if (!connection)
 		return FALSE;
 
 	for (; ptr->name; ptr++) {
-		ret = ptr->reg_func(connection, ptr->dft_reg, id);
-		ptr->dft_reg = 1;
+		if (ptr->reg_func(connection, id) < 0)
+			goto failed;
 	}
 
-	if (!ret)
-		up_adapters++;
+	up_adapters++;
+
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
 
-	message = dbus_message_new_signal(BLUEZ_HCI_PATH,
-			BLUEZ_HCI_INTERFACE, BLUEZ_HCI_DEV_ADDED);
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_UP);
 
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
 		goto failed;
 	}
 
-	snprintf(dev, sizeof(dev), HCI_DEVICE_NAME "%d", id);
-
-	dbus_message_iter_init_append(message, &iter);
-	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING ,&pdev);
-
 	if (dbus_connection_send(connection, message, NULL) == FALSE) {
 		syslog(LOG_ERR, "Can't send D-BUS added device message");
 		goto failed;
@@ -1032,40 +1032,30 @@
 	return TRUE;
 }
 
-gboolean hcid_dbus_unregister_manager(uint16_t id)
+gboolean hcid_dbus_dev_down(uint16_t id)
 {
-	char dev[BLUETOOTH_DEVICE_NAME_LEN];
+	char path[MAX_PATH_LENGTH];
 	struct profile_obj_path_data *ptr = obj_path_table;
 	DBusMessage *message = NULL;
-	const char *pdev = dev;
-	DBusMessageIter iter;
-	int dft_unreg = 0;
 
 	if (!connection)
 		return FALSE;
 
 	for (; ptr->name; ptr++) {
-		dft_unreg = (up_adapters > 1) ? 0 : 1;
-		up_adapters--;
-		ptr->unreg_func(connection, dft_unreg, id);
-
-		if (dft_unreg )
-			ptr->dft_reg = 0;
+		if (ptr->unreg_func(connection, id) < 0)
+			goto failed;	
 	}
 
-	message = dbus_message_new_signal(BLUEZ_HCI_PATH,
-			BLUEZ_HCI_INTERFACE, BLUEZ_HCI_DEV_REMOVED);
+	up_adapters--;
 
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, id);
+
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE, DEV_DOWN); 
 	if (message == NULL) {
 		syslog(LOG_ERR, "Can't allocate D-BUS device removed  message");
 		goto failed;
 	}
 
-	snprintf(dev, sizeof(dev), HCI_DEVICE_NAME "%d", id);
-
-	dbus_message_iter_init_append(message, &iter);
-	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING ,&pdev);
-
 	if (dbus_connection_send(connection, message, NULL) == FALSE) {
 		syslog(LOG_ERR, "Can't send D-BUS removed device message");
 		goto failed;
@@ -1087,23 +1077,17 @@
  * Detailed description: function responsible for register a new hci 
  * D-Bus path. If necessary the default path must be registered too.
  * @param conn D-Bus connection
- * @param dft_reg register the default path(0 or !0)
  * @param id hci device identification
  * @return (0-Success/-1 failure)
  */
-static int hci_dbus_reg_obj_path(DBusConnection *conn, int dft_reg, uint16_t id)
+static int hci_dbus_reg_obj_path(DBusConnection *conn, uint16_t id)
 {
 	char path[MAX_PATH_LENGTH];
 
 	/* register the default path*/
-	if (!dft_reg) {
-		snprintf(path, sizeof(path), "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
-		register_dbus_path(path, DEFAULT_DEVICE_PATH_ID, &obj_mgr_vtable);
-	}
-
-	/* register the default path*/
-	snprintf(path, sizeof(path), "%s/%s%d/%s", MANAGER_PATH, HCI_DEVICE_NAME, id, BLUEZ_HCI);
-	register_dbus_path(path, id, &obj_mgr_vtable);
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
+	if (!register_dbus_path(path, id, &obj_dev_vtable))
+		return -1;
 
 	return 0;
 }
@@ -1118,25 +1102,20 @@
  * @param id hci device identification
  * @return (0-Success/-1 failure)
  */
-static int hci_dbus_unreg_obj_path(DBusConnection *conn, int unreg_dft, uint16_t id) 
+static int hci_dbus_unreg_obj_path(DBusConnection *conn, uint16_t id) 
 {
-	int ret = 0;
 	char path[MAX_PATH_LENGTH];
 
-	if (unreg_dft) {
-		snprintf(path, sizeof(path), "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
-		unregister_dbus_path(path);
-	}
+	snprintf(path, sizeof(path), "%s/hci%d/%s", DEVICE_PATH, id, BLUEZ_HCI);
+	if (!unregister_dbus_path(path))
+		return -1;
 
-	snprintf(path, sizeof(path), "%s/%s%d/%s", MANAGER_PATH, HCI_DEVICE_NAME, id, BLUEZ_HCI);
-	unregister_dbus_path(path);
-
-	return ret;
+	return 0;
 }
 
 const struct service_data *get_hci_table(void)
 {
-	return hci_services;
+	return device_hci_services;
 }
 
 /*****************************************************************
@@ -1173,24 +1152,20 @@
 
 	return ret;
 }
-/*
- * There is only one message handler function for all object paths
- *
- */
 
 static DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data)
 {
-	const struct service_data *ptr_handlers = NULL;
+	const struct service_data *handlers = NULL;
 	DBusMessage *reply = NULL;
+	struct hci_dbus_data *dbus_data = data;
 	int type;
+	const char *child;
 	const char *iface;
 	const char *method;
 	const char *signature;
 	const char *path;
-	struct hci_dbus_data *dbus_data = data;
-	uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
 	DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	uint8_t found = 0;
 
 	path = dbus_message_get_path(msg);
 	type = dbus_message_get_type(msg);
@@ -1198,50 +1173,48 @@
 	method = dbus_message_get_member(msg);
 	signature = dbus_message_get_signature(msg);
 
-	if (strcmp(iface, DEVICE_INTERFACE))
-		return ret;
+	syslog(LOG_INFO, "%s - path:%s, id:%04X", __PRETTY_FUNCTION__, path, dbus_data->id);
 
-	if (strcmp(path, DEVICE_PATH) > 0) {
-		if (dbus_data->id == DEVICE_PATH_ID) {
-			/* fallback handling. The child path IS NOT registered */
-			reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_UNKNOWN_PATH);
-			ret = DBUS_HANDLER_RESULT_HANDLED;
-		} else {
-			/* hciX code */
-		}
-	} else {
-		/* it's the device path */
-		ptr_handlers = dev_root_services;
-		found = 1;
-	}
-
-	if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) && (method != NULL)) {
-
-		for (; ptr_handlers->name; ptr_handlers++) {
-			if (strcmp(method, ptr_handlers->name) == 0) {
-				/* resetting unknown method. It's possible handle method overload */
-				result = BLUEZ_EDBUS_WRONG_SIGNATURE; 
-				if (strcmp(ptr_handlers->signature, signature) == 0) {
-					if (ptr_handlers->handler_func) {
-						reply = (ptr_handlers->handler_func) (msg, data);
-						result = 0; /* resetting wrong signature*/
-					} else
-						syslog(LOG_INFO, "Service not implemented");
+	if (dbus_data->id == DEVICE_PATH_ID)
+		return ret;
 
+	if (strcmp(path, DEVICE_PATH) == 0)
+		handlers = device_services;
+	else {
+		child = strrchr(path,'/');
+		if (child && *child) {
+			struct profile_obj_path_data *profile;
+			child++;
+
+			for (profile = obj_path_table ;profile->name != NULL; profile++) {
+				if (strcmp(profile->name, child) == 0) {
+					handlers = profile->get_svc_table();
 					break;
 				}
-				
 			}
-		}
 
-		if (result) {
-			reply = bluez_new_failure_msg(msg, result);
 		}
+	}
+
+	if (handlers) {
+		for (; handlers->name != NULL; handlers++) {
+			if (strcmp(handlers->name, method) == 0) {
+				if (strcmp(handlers->signature, signature) != 0)
+					error = BLUEZ_EDBUS_WRONG_SIGNATURE;
+				else {
+					reply = handlers->handler_func(msg, data);
+					error = 0;
+				}
 
-		ret = DBUS_HANDLER_RESULT_HANDLED;
+				ret = DBUS_HANDLER_RESULT_HANDLED;
+			}
+		}
 	}
 
-	/* send an error or the success reply*/
+	if (error)
+		reply = bluez_new_failure_msg(msg, error);
+
+
 	if (reply) {
 		if (!dbus_connection_send (conn, reply, NULL)) {
 			syslog(LOG_ERR, "Can't send reply message!");
@@ -1254,88 +1227,45 @@
 
 static DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data)
 {
-	const struct service_data *ptr_handlers = NULL;
+	const struct service_data *handlers;
 	DBusMessage *reply = NULL;
-	int type;
 	const char *iface;
 	const char *method;
 	const char *signature;
 	const char *path;
-	const char *rel_path;
-	struct hci_dbus_data *dbus_data = data;
-	uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+	uint32_t error = BLUEZ_EDBUS_UNKNOWN_METHOD;
 	DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	uint8_t found = 0;
 
 	path = dbus_message_get_path(msg);
-	type = dbus_message_get_type(msg);
 	iface = dbus_message_get_interface(msg);
 	method = dbus_message_get_member (msg);
 	signature = dbus_message_get_signature(msg);
 
-	syslog (LOG_INFO, "%s - path:%s, id:0x%X", __PRETTY_FUNCTION__, path, dbus_data->id);
+	syslog (LOG_INFO, "%s - path:%s", __PRETTY_FUNCTION__, path);
 
-	if (strcmp(iface, MANAGER_INTERFACE))
+	if (strcmp(iface, MANAGER_INTERFACE) != 0)
 		return ret;
 
-	if (strcmp(path, MANAGER_PATH) > 0) {
-		/* it is device specific path */
-		if (dbus_data->id == MANAGER_PATH_ID) {
-			/* fallback handling. The child path IS NOT registered */
-			reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_UNKNOWN_PATH);
-			ret = DBUS_HANDLER_RESULT_HANDLED;
-		} else {
-			const struct profile_obj_path_data *mgr_child = obj_path_table;
-			rel_path = strrchr(path,'/');
-			rel_path++;
-
-			if (rel_path) {
-				for ( ;mgr_child->name; mgr_child++) {
-					if (strcmp(mgr_child->name, rel_path) == 0) {
-						ptr_handlers = mgr_child->get_svc_table();
-						found = 1;
-						break;
-					}
-				}
-
+	for (handlers = manager_services; handlers->name != NULL; handlers++) {
+		if (strcmp(handlers->name, method) == 0) {
+			if (strcmp(handlers->signature, signature) != 0)
+				error = BLUEZ_EDBUS_WRONG_SIGNATURE;
+			else {
+				reply = handlers->handler_func(msg, data);
+				error = 0;
 			}
-		}
-	} else {
-		/* it's the manager! path */
-		ptr_handlers = mgr_services;
-		found = 1;
-	}
-
-	if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) && (method != NULL)) {
-
-		for (; ptr_handlers->name; ptr_handlers++) {
-			if (strcmp(method, ptr_handlers->name) == 0) {
-				/* resetting unknown method. It's possible handle method overload */
-				result = BLUEZ_EDBUS_WRONG_SIGNATURE; 
-				if (strcmp(ptr_handlers->signature, signature) == 0) {
-					if (ptr_handlers->handler_func) {
-						reply = (ptr_handlers->handler_func)(msg, data);
-						result = 0; /* resetting wrong signature*/
-					} else 
-						syslog(LOG_INFO, "Service not implemented");
 
-					break;
-				} 
-				
-			}
+			ret = DBUS_HANDLER_RESULT_HANDLED;
 		}
+	}
 
-		if (result) {
-			reply = bluez_new_failure_msg(msg, result);
-		}
+	if (error)
+		reply = bluez_new_failure_msg(msg, error);
 
-		ret = DBUS_HANDLER_RESULT_HANDLED;
-	}
 
-	/* send an error or the success reply*/
 	if (reply) {
 		if (!dbus_connection_send (conn, reply, NULL)) {
-			syslog(LOG_ERR, "Can't send reply message!") ;
+			syslog(LOG_ERR, "Can't send reply message!");
 		}
 		dbus_message_unref (reply);
 	}
@@ -1354,20 +1284,8 @@
 	uint8_t max_period;
 	uint8_t min_period;
 	int dd = -1;
-	int dev_id = -1;
 
-	if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
-		dev_id = hci_get_route(NULL);
-		if (dev_id < 0) {
-			syslog(LOG_ERR, "Bluetooth device is not available");
-			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
-			goto failed;
-		
-		}
-	} else
-		dev_id =  dbus_data->id;
-
-	dd = hci_open_dev(dev_id);
+	dd = hci_open_dev(dbus_data->id);
 	if (dd < 0) {
 		syslog(LOG_ERR, "HCI device open failed");
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
@@ -1427,19 +1345,8 @@
 	DBusMessage *reply = NULL;
 	struct hci_dbus_data *dbus_data = data;
 	int dd = -1;
-	int dev_id = -1;
 
-	if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
-		dev_id = hci_get_route(NULL);
-		if (dev_id < 0) {
-			syslog(LOG_ERR, "Bluetooth device is not available");
-			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
-			goto failed;
-		}
-	} else
-		dev_id = dbus_data->id;
-
-	dd = hci_open_dev(dev_id);
+	dd = hci_open_dev(dbus_data->id);
 	if (dd < 0) {
 		syslog(LOG_ERR, "HCI device open failed");
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
@@ -1469,19 +1376,10 @@
 	evt_cmd_status rp;
 	struct hci_request rq;
 	struct hci_dbus_data *dbus_data = data;
-	int dev_id = -1, dd = -1;
+	int dd = -1;
 	int8_t length;
 	int8_t num_rsp;
 
-	if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
-		if ((dev_id = hci_get_route(NULL)) < 0) {
-			syslog(LOG_ERR, "Bluetooth device is not available");
-			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
-			goto failed;
-		}
-	} else
-		dev_id = dbus_data->id;
-
 	dbus_message_iter_init(msg, &iter);
 	dbus_message_iter_get_basic(&iter, &length);
 	dbus_message_iter_next(&iter);
@@ -1492,9 +1390,9 @@
 		goto failed;
 	}
 
-	dd = hci_open_dev(dev_id);
+	dd = hci_open_dev(dbus_data->id);
 	if (dd < 0) {
-		syslog(LOG_ERR, "Unable to open device %d: %s", dev_id, strerror(errno));
+		syslog(LOG_ERR, "Unable to open device %d: %s", dbus_data->id, strerror(errno));
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
 		goto failed;
 	}
@@ -1535,20 +1433,11 @@
 	DBusMessage *reply = NULL;
 	struct hci_request rq;
 	struct hci_dbus_data *dbus_data = data;
-	int dev_id = -1, dd = -1;
-
-	if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
-		if ((dev_id = hci_get_route(NULL)) < 0) {
-			syslog(LOG_ERR, "Bluetooth device is not available");
-			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
-			goto failed;
-		}
-	} else
-		dev_id = dbus_data->id;
+	int dd = -1;
 
-	dd = hci_open_dev(dev_id);
+	dd = hci_open_dev(dbus_data->id);
 	if (dd < 0) {
-		syslog(LOG_ERR, "Unable to open device %d: %s", dev_id, strerror(errno));
+		syslog(LOG_ERR, "Unable to open device %d: %s", dbus_data->id, strerror(errno));
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
 		goto failed;
 	}
@@ -1580,8 +1469,7 @@
 	struct hci_dbus_data *dbus_data = data;
 	bdaddr_t bdaddr;
 	uint8_t role;
-	int dev_id = -1;
-	int dd = -1;
+	int dev_id = -1, dd = -1;
 
 	dbus_message_iter_init(msg, &iter);
 	dbus_message_iter_get_basic(&iter, &str_bdaddr);
@@ -1598,7 +1486,7 @@
 		goto failed;
 	}
 
-	if (dbus_data->id != DEFAULT_DEVICE_PATH_ID && dbus_data->id != dev_id) {
+	if (dbus_data->id != dev_id) {
 		syslog(LOG_ERR, "Connection not found\n");
 		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
 		goto failed;
@@ -1631,7 +1519,6 @@
 	DBusMessageIter iter;
 	DBusMessage *reply = NULL;
 	struct hci_dbus_data *dbus_data = data;
-	int dev_id = -1;
 	int dd = -1;
 	const char *str_bdaddr;
 	bdaddr_t bdaddr;
@@ -1644,19 +1531,9 @@
 
 	str2ba(str_bdaddr, &bdaddr);
 
-	if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
-		dev_id = hci_get_route(&bdaddr);
-		if (dev_id  < 0) {
-			syslog(LOG_ERR, "Bluetooth device is not available");
-			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
-			goto failed;
-		}
-	} else
-		dev_id = dbus_data->id;
-
-	dd = hci_open_dev(dev_id);
+	dd = hci_open_dev(dbus_data->id);
 	if (dd < 0) {
-		syslog(LOG_ERR, "Unable to open device %d: %s", dev_id, strerror(errno));
+		syslog(LOG_ERR, "Unable to open device %d: %s", dbus_data->id, strerror(errno));
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
 		goto failed;
 	}
@@ -1701,21 +1578,9 @@
 	const char array_sig[] = HCI_CONN_INFO_STRUCT_SIGNATURE;
 	const char *paddr = addr;
 	struct hci_dbus_data *dbus_data = data;
-	int dev_id = -1;
 	int sk = -1;
 	int i;
 
-	if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
-		dev_id = hci_get_route(NULL);
-		if (dev_id < 0) {
-			syslog(LOG_ERR, "Bluetooth device is not available");
-			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
-			goto failed;
-		}
-	} else {
-		dev_id = dbus_data->id;
-	}
-
 	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
 	if (sk < 0) {
 		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
@@ -1728,7 +1593,7 @@
 		goto failed;
 	}
 
-	cl->dev_id = dev_id;
+	cl->dev_id = dbus_data->id;
 	cl->conn_num = MAX_CONN_NUMBER;
 	ci = cl->conn_info;
 
@@ -1791,7 +1656,7 @@
 		goto failed;
 	}
 
-	if (dbus_data->id != DEFAULT_DEVICE_PATH_ID && dbus_data->id != dev_id) {
+	if (dbus_data->id != dev_id) {
 		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
 		goto failed;
 	}
@@ -1849,27 +1714,16 @@
  *  Section reserved to Manager D-Bus message handlers
  *  
  *****************************************************************/
-static DBusMessage* handle_get_devices_req_device(DBusMessage *msg, void *data)
+static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;
 	DBusMessageIter array_iter;
-	DBusMessageIter flag_array_iter;
-	DBusMessageIter  struct_iter;
 	DBusMessage *reply = NULL;
 	struct hci_dev_list_req *dl = NULL;
 	struct hci_dev_req *dr      = NULL;
-	struct hci_dev_info di;
 	int sk = -1;
 	int i;
-	char aname[BLUETOOTH_DEVICE_NAME_LEN+1];
-	char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
-	char aflag[DEVICE_FLAG_NAME];
-	char *paddr = aaddr;
-	char *pname = aname;
-	char *pflag = aflag;
-	char *ptype;
-	const char array_sig[] = DEV_GET_DEV_REPLY_STRUCT_SIGNATURE;
-	hci_map *mp;
+	const char array_sig[] = MGR_GET_DEV_REPLY_STRUCT_SIGNATURE;
 
 	/* Create and bind HCI socket */
 	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
@@ -1901,6 +1755,16 @@
 	dr = dl->dev_req;
 
 	for (i = 0; i < dl->dev_num; i++, dr++) {
+		char apath[MAX_PATH_LENGTH];
+		char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
+		char *paddr = aaddr;
+		char *ppath = apath;
+		char *ptype;
+		const char *flag;
+		DBusMessageIter flag_array_iter, struct_iter;
+		struct hci_dev_info di;
+		hci_map *mp;
+
 		mp = dev_flags_map;
 		memset(&di, 0 , sizeof(struct hci_dev_info));
 		di.dev_id = dr->dev_id;
@@ -1908,8 +1772,7 @@
 		if (ioctl(sk, HCIGETDEVINFO, &di) < 0)
 			continue;
 
-		strncpy(aname, di.name, BLUETOOTH_DEVICE_NAME_LEN);
-		aname[BLUETOOTH_DEVICE_NAME_LEN] = '\0';
+		snprintf(apath, sizeof(apath), "%s/%s", DEVICE_PATH, di.name);
 
 		ba2str(&di.bdaddr, aaddr);
 		ptype = hci_dtypetostr(di.type);
@@ -1917,25 +1780,23 @@
 		dbus_message_iter_open_container(&array_iter,
 				DBUS_TYPE_STRUCT, NULL, &struct_iter);
 
-		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &pname);
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ppath);
 		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &paddr);
 		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ptype);
 
-		if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
-			sprintf(pflag, "%s", "UP");
-		} else {
-			sprintf(pflag, "%s", "DOWN");
-		}
-		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &pflag);
+		if (hci_test_bit(HCI_UP, &dr->dev_opt))
+			flag = "UP";
+		else
+			flag = "DOWN";
+
+		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &flag);
 
 		dbus_message_iter_open_container(&struct_iter,
 					DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &flag_array_iter);
 
 		while (mp->str) {
-			if (hci_test_bit(mp->val, &dr->dev_opt)) {
-				sprintf(pflag, "%s", mp->str);
-				dbus_message_iter_append_basic(&flag_array_iter, DBUS_TYPE_STRING, &pflag);
-			}
+			if (hci_test_bit(mp->val, &dr->dev_opt))
+				dbus_message_iter_append_basic(&flag_array_iter, DBUS_TYPE_STRING, &mp->str);
 			mp++;
 		}
 		dbus_message_iter_close_container(&struct_iter, &flag_array_iter);
@@ -1952,86 +1813,28 @@
 	return reply;
 }
 
-
-static DBusMessage* handle_get_devices_req_manager(DBusMessage *msg, void *data)
-{
-	DBusMessageIter iter;
-	DBusMessageIter array_iter;
-	DBusMessageIter  struct_iter;
+static DBusMessage* handle_default_device_req(DBusMessage *msg, void *data) {
+	char path[MAX_PATH_LENGTH];
+	char *pptr = path;
 	DBusMessage *reply = NULL;
 
-	struct hci_dev_list_req *dl = NULL;
-	struct hci_dev_req *dr      = NULL;
-	struct hci_dev_info di;
-	int sk = -1;
-	int i;
-
-	char aname[BLUETOOTH_DEVICE_NAME_LEN];
-	char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
-	char *paddr = aaddr;
-	char *pname = aname;
-	const char array_sig[] = HCI_DEVICE_STRUCT_SIGNATURE;
-
-	/* Create and bind HCI socket */
-	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
-	if (sk < 0) {
-		syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
-		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
-		goto failed;
-	}
-
-	dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
-	if (!dl) {
-		syslog(LOG_ERR, "Can't allocate memory");
-		reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
-		goto failed;
-	}
-
-	dl->dev_num = HCI_MAX_DEV;
-	dr = dl->dev_req;
-
-	if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
-		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
-		goto failed;
+	if (default_dev < 0) {
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto out;
 	}
 
-	/* active bluetooth adapter found */
 	reply = dbus_message_new_method_return(msg);
-	dbus_message_iter_init_append(reply, &iter);
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
-	dr = dl->dev_req;
-
-	for (i = 0; i < dl->dev_num; i++, dr++) {
-		if (!hci_test_bit(HCI_UP, &dr->dev_opt))
-			continue;
-
-		memset(&di, 0 , sizeof(struct hci_dev_info));
-		di.dev_id = dr->dev_id;
-
-		if (ioctl(sk, HCIGETDEVINFO, &di) < 0)
-			continue;
-
-		strcpy(aname, di.name);
-		ba2str(&di.bdaddr, aaddr);
-
-		dbus_message_iter_open_container(&array_iter,
-					DBUS_TYPE_STRUCT, NULL, &struct_iter);
-
-		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &pname);
-		dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &paddr);
-
-		dbus_message_iter_close_container(&array_iter, &struct_iter);
+	if (reply == NULL) {
+		syslog(LOG_ERR, "Out of memory while calling new_method_return");
+		goto out;
 	}
 
-	dbus_message_iter_close_container(&iter, &array_iter);
-
-failed:
-	if (sk >= 0)
-		close(sk);
-
-	if (dl)
-		free(dl);
+	snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, default_dev);
+	dbus_message_append_args(reply,
+				 DBUS_TYPE_STRING, &pptr,
+				 DBUS_TYPE_INVALID);
 
+out:
 	return reply;
 }
 

Index: hcid/dbus.h
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.h,v
retrieving revision 1.11

dbus.h +43 -51

131 lines not on this page · raw message

Index: hcid/hcid.h
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/hcid.h,v
retrieving revision 1.29

hcid.h +2 -2
diff -u -r1.29 hcid.h
@@ -121,9 +121,9 @@
 gboolean hcid_dbus_init(void);
 void hcid_dbus_exit(void);
 gboolean hcid_dbus_register_device(uint16_t id);
-gboolean hcid_dbus_register_manager(uint16_t id);
+gboolean hcid_dbus_dev_up(uint16_t id);
 gboolean hcid_dbus_unregister_device(uint16_t id);
-gboolean hcid_dbus_unregister_manager(uint16_t id);
+gboolean hcid_dbus_dev_down(uint16_t id);
 void hcid_dbus_request_pin(int dev, struct hci_conn_info *ci);
 void hcid_dbus_inquiry_start(bdaddr_t *local);
 void hcid_dbus_inquiry_complete(bdaddr_t *local);

Index: hcid/main.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/main.c,v
retrieving revision 1.30

main.c +5 -5
diff -u -r1.30 main.c
@@ -401,10 +401,10 @@
 			start_security_manager(dr->dev_id);
 
 #ifdef ENABLE_DBUS
-		if (hci_test_bit(HCI_UP, &dr->dev_opt))
-			hcid_dbus_register_manager(dr->dev_id);
-
 		hcid_dbus_register_device(dr->dev_id);
+
+		if (hci_test_bit(HCI_UP, &dr->dev_opt))
+			hcid_dbus_dev_up(dr->dev_id);
 #endif
 	}
 
@@ -476,7 +476,7 @@
 		if (hcid.security)
 			start_security_manager(sd->dev_id);
 #ifdef ENABLE_DBUS
-		hcid_dbus_register_manager(sd->dev_id);
+		hcid_dbus_dev_up(sd->dev_id);
 #endif
 		break;
 
@@ -485,7 +485,7 @@
 		if (hcid.security)
 			stop_security_manager(sd->dev_id);
 #ifdef ENABLE_DBUS
-		hcid_dbus_unregister_manager(sd->dev_id);
+		hcid_dbus_dev_down(sd->dev_id);
 #endif
 		break;
 	}

#!/usr/bin/env python

import dbus

bus = dbus.SystemBus()
manager_object = bus.get_object('org.bluez', '/org/bluez/Manager') manager_if = dbus.Interface(manager_object, 'org.bluez.Manager')

devices = manager_if.DeviceList ()
print 'Found %d devices:' % len(devices)
print devices

try:
default = manager_if.DefaultDevice()
print 'Default device is %s' % default
except dbus.DBusException, e:
print 'Failed to get default device: %s' % e

maintainer
#5 lore raw

Hi Johan,

Quoted 5 lines

Here's the patch which implements the interface redesign. The change ended up being a little bigger than I originally thought, but I think the code and interface become more understandable this way. Attached is also a simple python app which tests the DeviceList and DefaultDevice methods.

let's test this new interface. The patch is in the CVS now and we will see how it works out.

I also like to add a test script that can utilize the complete API. I don't wanna replace hciconfig or hcitool, but an easy script for testing is really needed.

Regards

Marcel

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#6 lore raw

Hi Marcel,

here is the device Up and Down dbus methods.

br,
Eduardo.

Quoted 22 lines · Marcel Holtmann

Hi Johan,

Quoted 5 lines

Here's the patch which implements the interface redesign. The change ended up being a little bigger than I originally thought, but I think the code and interface become more understandable this way. Attached is also a simple python app which tests the DeviceList and DefaultDevice methods.

let's test this new interface. The patch is in the CVS now and we will see how it works out.

I also like to add a test script that can utilize the complete API. I don't wanna replace hciconfig or hcitool, but an easy script for testing is really needed.

Regards

Marcel

Quoted 10 lines

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

hcid/dbus.c +84 -8
@@ -258,6 +258,8 @@
 static DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data);
 static DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data);
 
+static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_default_device_req(DBusMessage *msg, void *data);
 static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
@@ -273,8 +275,8 @@
 };
 
 static const struct service_data device_services[] = {
-	{ DEV_UP,		handle_not_implemented_req,	DEV_UP_SIGNATURE		},
-	{ DEV_DOWN,		handle_not_implemented_req,	DEV_DOWN_SIGNATURE		},
+	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
+	{ DEV_DOWN,		handle_device_down_req,		DEV_DOWN_SIGNATURE		},
 	{ DEV_RESET,		handle_not_implemented_req,	DEV_RESET_SIGNATURE		},
 	{ DEV_SET_PROPERTY,	handle_not_implemented_req,	DEV_SET_PROPERTY_SIGNATURE	},
 	{ DEV_GET_PROPERTY,	handle_not_implemented_req,	DEV_GET_PROPERTY_SIGNATURE	},
@@ -1187,14 +1189,16 @@
 		if (child && *child) {
 			struct profile_obj_path_data *profile;
 			child++;
-
-			for (profile = obj_path_table ;profile->name != NULL; profile++) {
-				if (strcmp(profile->name, child) == 0) {
-					handlers = profile->get_svc_table();
-					break;
+			if (!strncmp(child, "hci", 3)) {
+				handlers = device_services;
+			} else {
+				for (profile = obj_path_table ;profile->name != NULL; profile++) {
+					if (strcmp(profile->name, child) == 0) {
+						handlers = profile->get_svc_table();
+						break;
+					}
 				}
 			}
-
 		}
 	}
 
@@ -1716,6 +1720,78 @@
  *  Section reserved to Manager D-Bus message handlers
  *  
  *****************************************************************/
+static DBusMessage* handle_device_up_req(DBusMessage *msg, void *data)
+{
+	DBusMessage *reply = NULL;
+	struct hci_dbus_data *dbus_data = data;
+	struct hci_dev_info di;
+	struct hci_dev_req dr;
+	int sk = -1;
+
+	/* Create and bind HCI socket */
+	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+	if (sk < 0) {
+		syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if ((ioctl(sk, HCIDEVUP, dbus_data->id) < 0) && (errno != EALREADY)) {
+		syslog(LOG_ERR, "Can't init device hci%d: %s (%d)\n",
+			dbus_data->id, strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (ioctl(sk, HCIGETDEVINFO, (void *) &di) >= 0 && 
+	    !hci_test_bit(HCI_RAW, &di.flags)) {
+		dr.dev_id  = dbus_data->id;
+		dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY; /* piscan */
+		if (ioctl(sk, HCISETSCAN, (unsigned long) &dr) < 0) {
+			syslog(LOG_ERR, "Can't set scan mode on hci%d: %s (%d)\n",
+					dbus_data->id, strerror(errno), errno);
+			reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+			goto failed;
+		}
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (sk >= 0)
+		close(sk);
+	return reply;
+}
+
+static DBusMessage* handle_device_down_req(DBusMessage *msg, void *data)
+{
+	DBusMessage *reply = NULL;
+	struct hci_dbus_data *dbus_data = data;
+	int sk = -1;
+
+	/* Create and bind HCI socket */
+	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+	if (sk < 0) {
+		syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if ((ioctl(sk, HCIDEVDOWN, dbus_data->id) < 0) ) {
+		syslog(LOG_ERR, "Can't down device hci%d: %s (%d)\n",
+			dbus_data->id, strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (sk >= 0)
+		close(sk);
+	return reply;
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;

import dbus
import sys

print '/org/bluez/Device/' + str(sys.argv[1])
bus = dbus.SystemBus()
proxy_obj = bus.get_object('org.bluez', '/org/bluez/Device/' + str(sys.argv[1])) dbus_iface = dbus.Interface(proxy_obj, 'org.bluez.Device')

print dbus_iface.Down()

import dbus
import sys

print '/org/bluez/Device/' + str(sys.argv[1])
bus = dbus.SystemBus()
proxy_obj = bus.get_object('org.bluez', '/org/bluez/Device/' + str(sys.argv[1])) dbus_iface = dbus.Interface(proxy_obj, 'org.bluez.Device')

print dbus_iface.Up()

maintainer
#7 lore raw

Hi Eduardo,

Quoted 1 line

here is the device Up and Down dbus methods.

the patch is in the CVS now. However I am not sure about the future of any of these two methods. Do we really want the possibility to up and down a Bluetooth adapter?

For the test scripts, make sure that you include "#!/usr/bin/python" on the first line and I basically like one or two bigger test scripts. An extra script for every method is overkill.

Regards

Marcel

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#8 lore raw
Quoted 3 lines · Marcel Holtmann

For the test scripts, make sure that you include "#!/usr/bin/python" on the first line and I basically like one or two bigger test scripts. An extra script for every method is overkill.

I think I'll do just one big script. However, I think that "#!/usr/bin/env python" is better because it will also work if python is installed e.g. in /usr/local/bin.

Johan

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#9 lore raw
In reply to Marcel Holtmann

Hi Marcel,

Quoted 10 lines · ext Marcel Holtmann

Hi Eduardo,

Quoted 1 line

here is the device Up and Down dbus methods.

the patch is in the CVS now. However I am not sure about the future of any of these two methods. Do we really want the possibility to up and down a Bluetooth adapter?

Yes. At least in embedded devices it's useful for example when you need offline mode.

Signature · 12 lines
Ville


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#10 lore raw
In reply to Marcel Holtmann
Quoted 3 lines · Marcel Holtmann

I also like to add a test script that can utilize the complete API. I don't wanna replace hciconfig or hcitool, but an easy script for testing is really needed.

I'll try to produce something. Hopefully I'll be able to send a first version to the list some time tomorrow.

Johan

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#11 lore raw
Quoted 7 lines · Johan Hedberg
Quoted 3 lines · Marcel Holtmann

I also like to add a test script that can utilize the complete API. I don't wanna replace hciconfig or hcitool, but an easy script for testing is really needed.

I'll try to produce something. Hopefully I'll be able to send a first version to the list some time tomorrow.

I've now uploaded the first version of the script here:
http://www.iki.fi/~jhedberg/bluez-python/pybt.py

Here are some usage examples:
./pybt.py DeviceList
./pybt.py Inquiry
./pybt.py -i hci0 Inquiry 5 30
./pybt.py CancelInquiry
./pybt.py -i hci1 RemoteName 11:22:33:44:55:66
./pybt.py -i /org/bluez/Device/hci0 Up
./pybt.py -l

Johan

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#12 lore raw
Quoted 2 lines · Johan Hedberg

I've now uploaded the first version of the script here:
http://www.iki.fi/~jhedberg/bluez-python/pybt.py

I just uploaded a new version which fixes listening for AuthenticationComplete events. However the attached patch is also required for hcid because othervice it doesn't send a proper method return to the Authenticate method call.

Johan

Index: dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.41

dbus.c +2 -0
diff -u -r1.41 dbus.c
@@ -1712,6 +1712,8 @@
 		goto failed;
 	}
 
+	reply = dbus_message_new_method_return(msg);
+
 failed:
 	if (dd >= 0)
 		close(dd);
maintainer
#13 lore raw

Hi Johan,

Quoted 4 lines

I just uploaded a new version which fixes listening for AuthenticationComplete events. However the attached patch is also required for hcid because othervice it doesn't send a proper method return to the Authenticate method call.

the patch is in the CVS now.

Regards

Marcel

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel