diff options
-rw-r--r-- | hcid/dbus-adapter.c | 10 | ||||
-rw-r--r-- | hcid/dbus-api.txt | 9 | ||||
-rw-r--r-- | hcid/dbus-error.c | 14 | ||||
-rw-r--r-- | hcid/dbus-manager.c | 12 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.c | 2 | ||||
-rw-r--r-- | hcid/dbus-sdp.c | 2 | ||||
-rw-r--r-- | hcid/dbus-security.c | 2 | ||||
-rwxr-xr-x | hcid/dbus-test | 16 | ||||
-rw-r--r-- | hcid/dbus.c | 49 | ||||
-rw-r--r-- | hcid/dbus.h | 18 |
10 files changed, 56 insertions, 78 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index 513d875c..49c8c526 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -2190,16 +2190,10 @@ static struct service_data dev_services[] = { DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data) { - struct hci_dbus_data *dbus_data = data; const char *iface; iface = dbus_message_get_interface(msg); - if (dbus_data->path_id == ADAPTER_ROOT_ID) { - /* Adapter is down (path unregistered) or the path is wrong */ - return error_no_such_adapter(conn, msg); - } - if (!strcmp(ADAPTER_INTERFACE, iface)) { service_handler_func_t handler; @@ -2208,7 +2202,7 @@ DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void * if (handler) return handler(conn, msg, data); else - return error_not_implemented(conn, msg); + return error_unknown_method(conn, msg); } else if (!strcmp(SECURITY_INTERFACE, iface)) return handle_security_method(conn, msg, data); @@ -2217,5 +2211,5 @@ DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void * else if (!strcmp(SDP_INTERFACE, iface)) return handle_sdp_method(conn, msg, data); else - return error_not_implemented(conn, msg); + return error_unknown_method(conn, msg); } diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt index d2733970..cf030b5d 100644 --- a/hcid/dbus-api.txt +++ b/hcid/dbus-api.txt @@ -44,11 +44,6 @@ Errors Failed Error returned when the argument list is invalid or out of specification for the method. - NotImplemented - - Error returned when the called method has not been - implemented. - NotAuthorized Error returned when the caller of a method is not @@ -121,7 +116,7 @@ Manager hierarchy Service org.bluez Interface org.bluez.Manager -Object path /org/bluez/Manager +Object path /org/bluez Methods uint32 InterfaceVersion() @@ -150,7 +145,7 @@ Adapter hierarchy Service org.bluez Interface org.bluez.Adapter -Object path /org/bluez/Adapter/{hci0,hci1,...} +Object path /org/bluez/{hci0,hci1,...} Methods string GetAddress() diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index bcd1b109..8b75efeb 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -48,11 +48,19 @@ DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg "Invalid arguments")); } -DBusHandlerResult error_not_implemented(DBusConnection *conn, DBusMessage *msg) +DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg) { + char error[128]; + const char *signature = dbus_message_get_signature(msg); + const char *method = dbus_message_get_member(msg); + const char *interface = dbus_message_get_interface(msg); + + snprintf(error, 128, "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist", + method, signature, interface); + return send_reply_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".NotImplemented", - "Not implemented")); + dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownMethod", + error)); } DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg) diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 1fc24e39..84d08361 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -106,7 +106,7 @@ static DBusHandlerResult handle_mgr_list_devices_req(DBusConnection *conn, DBusM if (ioctl(sk, HCIGETDEVINFO, &di) < 0) continue; - snprintf(path, sizeof(path), "%s/%s", ADAPTER_PATH, di.name); + snprintf(path, sizeof(path), "%s/%s", BASE_PATH, di.name); dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING, &path_ptr); @@ -134,7 +134,7 @@ static DBusHandlerResult handle_mgr_default_adapter_req(DBusConnection *conn, DB if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, default_dev); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, default_dev); dbus_message_append_args(reply, DBUS_TYPE_STRING, &path_ptr, DBUS_TYPE_INVALID); @@ -164,9 +164,13 @@ static DBusHandlerResult handle_manager_method(DBusConnection *conn, DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data) { - const char *iface; + const char *iface, *path; iface = dbus_message_get_interface(msg); + path = dbus_message_get_path(msg); + + if (strcmp(BASE_PATH, path)) + return error_no_such_adapter(conn, msg); if (!strcmp(iface, MANAGER_INTERFACE)) return handle_manager_method(conn, msg, data); @@ -174,5 +178,5 @@ DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void if (!strcmp(iface, SECURITY_INTERFACE)) return handle_security_method(conn, msg, data); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + return error_unknown_method(conn, msg); } diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c index c9f862e0..6b5912d8 100644 --- a/hcid/dbus-rfcomm.c +++ b/hcid/dbus-rfcomm.c @@ -719,5 +719,5 @@ DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, if (handler) return handler(conn, msg, data); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + return error_unknown_method(conn, msg); } diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index e2a46fb8..3a01b6b7 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -526,5 +526,5 @@ DBusHandlerResult handle_sdp_method(DBusConnection *conn, DBusMessage *msg, void if (handler) return handler(conn, msg, data); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + return error_unknown_method(conn, msg); } diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 432956f0..b69c9441 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -468,7 +468,7 @@ DBusHandlerResult handle_security_method(DBusConnection *conn, DBusMessage *msg, if (handler) return handler(conn, msg, data); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + return error_unknown_method(conn, msg); } int handle_passkey_request(int dev, const char *path, bdaddr_t *sba, bdaddr_t *dba) diff --git a/hcid/dbus-test b/hcid/dbus-test index 25373a00..2877043e 100755 --- a/hcid/dbus-test +++ b/hcid/dbus-test @@ -67,10 +67,10 @@ dev_signals = [ "ModeChanged", "BondingCreated", "BondingRemoved" ] -dev_signals_filter = [ "/org/bluez/Adapter/hci0", "/org/bluez/Adapter/hci1", - "/org/bluez/Adapter/hci2", "/org/bluez/Adapter/hci3", - "/org/bluez/Adapter/hci4", "/org/bluez/Adapter/hci5", - "/org/bluez/Adapter/hci6", "/org/bluez/Adapter/hci7" ] +dev_signals_filter = [ "/org/bluez/hci0", "/org/bluez/hci1", + "/org/bluez/hci2", "/org/bluez/hci3", + "/org/bluez/hci4", "/org/bluez/hci5", + "/org/bluez/hci6", "/org/bluez/hci7" ] class Tester: exit_events = [] @@ -107,7 +107,7 @@ class Tester: if a[0] == '/': self.dev_path = a else: - self.dev_path = '/org/bluez/Adapter/%s' % a + self.dev_path = '/org/bluez/%s' % a if not (args or self.listen): self.usage() @@ -148,13 +148,13 @@ class Tester: for signal in mgr_signals: self.bus.add_signal_receiver(self.mgr_signal_handler, signal,'org.bluez.Manager', - 'org.bluez', '/org/bluez/Manager') + 'org.bluez', '/org/bluez') except dbus.DBusException, e: print 'Failed to setup signal handler for manager path: %s' % e sys.exit(1) def dbus_mgr_setup(self): - self.manager_obj = self.bus.get_object('org.bluez', '/org/bluez/Manager') + self.manager_obj = self.bus.get_object('org.bluez', '/org/bluez') self.manager = dbus.Interface(self.manager_obj, 'org.bluez.Manager') def dbus_setup(self): @@ -162,7 +162,7 @@ class Tester: def usage(self): print 'Usage: %s [-i <dev>] [-l] [-h] <cmd> [arg1..]' % self.name - print ' -i <dev> Specify device (e.g. "hci0" or "/org/bluez/Adapter/hci0")' + print ' -i <dev> Specify device (e.g. "hci0" or "/org/bluez/hci0")' print ' -l Listen for events (no command required)' print ' -h Show this help' print 'Manager commands:' diff --git a/hcid/dbus.c b/hcid/dbus.c index 9ae09c72..2fb0f7e3 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -281,7 +281,7 @@ DBusMessage *dev_signal_factory(const int devid, const char *prop_name, const in DBusMessage *signal; char path[MAX_PATH_LENGTH]; - snprintf(path, sizeof(path)-1, "%s/hci%d", ADAPTER_PATH, devid); + snprintf(path, sizeof(path)-1, "%s/hci%d", BASE_PATH, devid); signal = dbus_message_new_signal(path, ADAPTER_INTERFACE, prop_name); if (!signal) { @@ -320,7 +320,7 @@ static const DBusObjectPathVTable obj_mgr_vtable = { */ static DBusHandlerResult hci_dbus_signal_filter(DBusConnection *conn, DBusMessage *msg, void *data); -static gboolean register_dbus_path(const char *path, uint16_t path_id, uint16_t dev_id, +static gboolean register_dbus_path(const char *path, uint16_t dev_id, const DBusObjectPathVTable *pvtable, gboolean fallback) { gboolean ret = FALSE; @@ -336,7 +336,6 @@ static gboolean register_dbus_path(const char *path, uint16_t path_id, uint16_t memset(data, 0, sizeof(struct hci_dbus_data)); - data->path_id = path_id; data->dev_id = dev_id; data->mode = SCAN_DISABLED; data->discoverable_timeout = get_discoverable_timeout(dev_id); @@ -420,8 +419,8 @@ gboolean hcid_dbus_register_device(uint16_t id) struct hci_conn_list_req *cl = NULL; struct hci_conn_info *ci = NULL; - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); - if (!register_dbus_path(path, ADAPTER_PATH_ID, id, &obj_dev_vtable, FALSE)) + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); + if (!register_dbus_path(path, id, &obj_dev_vtable, FALSE)) return FALSE; dd = hci_open_dev(id); @@ -463,7 +462,7 @@ gboolean hcid_dbus_register_device(uint16_t id) /* * Send the adapter added signal */ - message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE, + message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, "AdapterAdded"); if (message == NULL) { error("Can't allocate D-Bus message"); @@ -531,9 +530,9 @@ gboolean hcid_dbus_unregister_device(uint16_t id) char path[MAX_PATH_LENGTH]; char *pptr = path; - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - message = dbus_message_new_signal(MANAGER_PATH, MANAGER_INTERFACE, + message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, "AdapterRemoved"); if (message == NULL) { error("Can't allocate D-Bus message"); @@ -570,7 +569,7 @@ void hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci) ba2str(sba, addr); - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, hci_devid(addr)); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, hci_devid(addr)); handle_passkey_request(dev, path, sba, &ci->bdaddr); } @@ -594,7 +593,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, const u goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); /* create the authentication reply */ if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { @@ -681,7 +680,7 @@ void hcid_dbus_create_conn_cancel(bdaddr_t *local, void *ptr) goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { error("Getting %s path data failed!", path); goto failed; @@ -724,7 +723,7 @@ void hcid_dbus_inquiry_start(bdaddr_t *local) goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) pdata->discover_state = STATE_DISCOVER; @@ -860,7 +859,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { @@ -936,7 +935,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { error("Getting %s path data failed!", path); @@ -1034,7 +1033,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); /* remove from remote name request list */ if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) @@ -1102,7 +1101,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, b goto done; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { error("Getting %s path data failed!", path); @@ -1203,7 +1202,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, uint16_t handle goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { error("Getting %s path data failed!", path); @@ -1363,12 +1362,7 @@ gboolean hcid_dbus_init(void) return FALSE; } - if (!register_dbus_path(ADAPTER_PATH, ADAPTER_ROOT_ID, INVALID_DEV_ID, - &obj_dev_vtable, TRUE)) - return FALSE; - - if (!register_dbus_path(MANAGER_PATH, MANAGER_ROOT_ID, INVALID_DEV_ID, - &obj_mgr_vtable, FALSE)) + if (!register_dbus_path(BASE_PATH, INVALID_DEV_ID, &obj_mgr_vtable, TRUE)) return FALSE; if (!dbus_connection_add_filter(connection, hci_dbus_signal_filter, NULL, NULL)) { @@ -1391,13 +1385,13 @@ void hcid_dbus_exit(void) return; /* Unregister all paths in Adapter path hierarchy */ - if (!dbus_connection_list_registered(connection, ADAPTER_PATH, &children)) + if (!dbus_connection_list_registered(connection, BASE_PATH, &children)) goto done; for (; children[i]; i++) { char dev_path[MAX_PATH_LENGTH]; - snprintf(dev_path, sizeof(dev_path), "%s/%s", ADAPTER_PATH, children[i]); + snprintf(dev_path, sizeof(dev_path), "%s/%s", BASE_PATH, children[i]); unregister_dbus_path(dev_path); } @@ -1405,8 +1399,7 @@ void hcid_dbus_exit(void) dbus_free_string_array(children); done: - unregister_dbus_path(ADAPTER_PATH); - unregister_dbus_path(MANAGER_PATH); + unregister_dbus_path(BASE_PATH); dbus_connection_close(connection); } @@ -1634,7 +1627,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) goto failed; } - snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); dd = hci_open_dev(id); if (dd < 0) { diff --git a/hcid/dbus.h b/hcid/dbus.h index aab6f354..c56884f5 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -34,10 +34,8 @@ #define BASE_PATH "/org/bluez" #define BASE_INTERFACE "org.bluez" -#define ADAPTER_PATH BASE_PATH "/Adapter" #define ADAPTER_INTERFACE BASE_INTERFACE ".Adapter" -#define MANAGER_PATH BASE_PATH "/Manager" #define MANAGER_INTERFACE BASE_INTERFACE ".Manager" #define ERROR_INTERFACE BASE_INTERFACE ".Error" @@ -48,19 +46,6 @@ #define SDP_INTERFACE BASE_INTERFACE ".SDP" -#define MANAGER_PATH_MASK (1 << 15) -#define ADAPTER_PATH_MASK (1 << 14) - -/* /org/bluez/Manager */ -#define MANAGER_ROOT_ID MANAGER_PATH_MASK - -/* /org/bluez/Adapter */ -#define ADAPTER_ROOT_ID ADAPTER_PATH_MASK - -/* E.g. /org/bluez/Adapter/hci0 */ -#define ADAPTER_PATH_ID (ADAPTER_PATH_MASK | 0x0001) - -#define INVALID_PATH_ID 0xFFFF #define INVALID_DEV_ID 0xFFFF #define MAX_PATH_LENGTH 64 @@ -115,7 +100,6 @@ struct active_conn_info { struct hci_dbus_data { uint16_t dev_id; - uint16_t path_id; char address[18]; /* adapter Bluetooth Address */ uint32_t timeout_id; /* discoverable timeout id */ uint32_t discoverable_timeout; /* discoverable time(msec) */ @@ -157,7 +141,7 @@ int get_default_dev_id(void); DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err); DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_implemented(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg); |