diff options
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/adapter.c | 229 | ||||
-rw-r--r-- | hcid/dbus-database.c | 49 | ||||
-rw-r--r-- | hcid/dbus-error.c | 110 | ||||
-rw-r--r-- | hcid/dbus-error.h | 21 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 3 | ||||
-rw-r--r-- | hcid/dbus-sdp.c | 43 | ||||
-rw-r--r-- | hcid/dbus-security.c | 15 | ||||
-rw-r--r-- | hcid/dbus-service.c | 21 | ||||
-rw-r--r-- | hcid/dbus-test.c | 17 | ||||
-rw-r--r-- | hcid/manager.c | 21 |
10 files changed, 208 insertions, 321 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 8085c0d6..c3fa8d1c 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -60,6 +60,7 @@ #include "dbus-hci.h" #include "dbus-sdp.h" #include "dbus-error.h" +#include "error.h" #define NUM_ELEMENTS(table) (sizeof(table)/sizeof(const char *)) @@ -365,7 +366,7 @@ static DBusHandlerResult adapter_get_address(DBusConnection *conn, DBusMessage *reply; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -386,11 +387,11 @@ static DBusHandlerResult adapter_get_version(DBusConnection *conn, int err; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); err = get_device_version(adapter->dev_id, str, sizeof(str)); if (err < 0) - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -411,11 +412,11 @@ static DBusHandlerResult adapter_get_revision(DBusConnection *conn, int err; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); err = get_device_revision(adapter->dev_id, str, sizeof(str)); if (err < 0) - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -436,11 +437,11 @@ static DBusHandlerResult adapter_get_manufacturer(DBusConnection *conn, int err; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); err = get_device_manufacturer(adapter->dev_id, str, sizeof(str)); if (err < 0) - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -461,11 +462,11 @@ static DBusHandlerResult adapter_get_company(DBusConnection *conn, int err; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); err = get_device_company(adapter->dev_id, str, sizeof(str)); if (err < 0) - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); reply = dbus_message_new_method_return(msg); if (!reply) @@ -487,7 +488,7 @@ static DBusHandlerResult adapter_list_modes(DBusConnection *conn, int i; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -513,7 +514,7 @@ static DBusHandlerResult adapter_get_mode(DBusConnection *conn, const char *mode; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -542,10 +543,10 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (!mode) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); new_mode = str2mode(adapter->address, mode); switch(new_mode) { @@ -560,7 +561,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, scan_enable = (SCAN_PAGE | SCAN_INQUIRY); break; default: - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } /* Do reverse resolution in case of "on" mode */ @@ -584,7 +585,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } } @@ -592,7 +593,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, hcid.offmode == HCID_OFFMODE_DEVDOWN) { if (ioctl(dd, HCIDEVDOWN, adapter->dev_id) < 0) { hci_close_dev(dd); - return error_failed(conn, msg, errno); + return error_failed_errno(conn, msg, errno); } goto done; @@ -602,7 +603,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, err = set_limited_discoverable(dd, adapter->class, limited); if (err < 0) { hci_close_dev(dd); - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); } if (current_scan != scan_enable) { @@ -623,14 +624,14 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, error("Sending write scan enable command failed: %s (%d)", strerror(errno), errno); hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } if (status) { error("Setting scan enable failed with status 0x%02x", status); hci_close_dev(dd); - return error_failed(conn, msg, bt_error(status)); + return error_failed_errno(conn, msg, bt_error(status)); } } else { /* discoverable or limited */ @@ -673,7 +674,7 @@ static DBusHandlerResult adapter_get_discoverable_to(DBusConnection *conn, DBusMessage *reply; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -700,7 +701,7 @@ static DBusHandlerResult adapter_set_discoverable_to(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &timeout, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -739,7 +740,7 @@ static DBusHandlerResult adapter_is_connectable(DBusConnection *conn, dbus_bool_t connectable = FALSE; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (scan_enable & SCAN_PAGE) connectable = TRUE; @@ -763,7 +764,7 @@ static DBusHandlerResult adapter_is_discoverable(DBusConnection *conn, dbus_bool_t discoverable = FALSE; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (scan_enable & SCAN_INQUIRY) discoverable = TRUE; @@ -793,10 +794,10 @@ static DBusHandlerResult adapter_is_connected(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(peer_addr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(peer_addr, &peer_bdaddr); @@ -824,7 +825,7 @@ static DBusHandlerResult adapter_list_connections(DBusConnection *conn, GSList *l = adapter->active_conn; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -860,7 +861,7 @@ static DBusHandlerResult adapter_get_major_class(DBusConnection *conn, const char *str_ptr = "computer"; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -888,7 +889,7 @@ static DBusHandlerResult adapter_list_minor_classes(DBusConnection *conn, int size, i; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); major_class = adapter->class[1] & 0x1F; @@ -930,7 +931,7 @@ static DBusHandlerResult adapter_get_minor_class(DBusConnection *conn, uint8_t minor_class; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* FIXME: Currently, only computer major class is supported */ if ((adapter->class[1] & 0x1f) != 1) @@ -970,10 +971,10 @@ static DBusHandlerResult adapter_set_minor_class(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &minor, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (!minor) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); dd = hci_open_dev(adapter->dev_id); if (dd < 0) @@ -994,7 +995,7 @@ static DBusHandlerResult adapter_set_minor_class(DBusConnection *conn, /* Check if it's a valid minor class */ if (dev_class == 0xFFFFFFFF) { hci_close_dev(dd); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } /* set the service class and major class */ @@ -1005,7 +1006,7 @@ static DBusHandlerResult adapter_set_minor_class(DBusConnection *conn, error("Can't write class of device on hci%d: %s(%d)", adapter->dev_id, strerror(errno), errno); hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } dbus_connection_emit_signal(conn, dbus_message_get_path(msg), @@ -1035,7 +1036,7 @@ static DBusHandlerResult adapter_get_service_classes(DBusConnection *conn, return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -1069,7 +1070,7 @@ static DBusHandlerResult adapter_get_name(DBusConnection *conn, bdaddr_t ba; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(adapter->address, &ba); @@ -1080,7 +1081,7 @@ static DBusHandlerResult adapter_get_name(DBusConnection *conn, err = get_device_name(adapter->dev_id, str, sizeof(str)); if (err < 0) - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); } reply = dbus_message_new_method_return(msg); @@ -1105,11 +1106,11 @@ static DBusHandlerResult adapter_set_name(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (!g_utf8_validate(str_ptr, -1, NULL)) { error("Name change failed: the supplied name isn't valid UTF-8"); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } str2ba(adapter->address, &bdaddr); @@ -1121,7 +1122,7 @@ static DBusHandlerResult adapter_set_name(DBusConnection *conn, ecode = set_device_name(adapter->dev_id, str_ptr); if (ecode < 0) - return error_failed(conn, msg, -ecode); + return error_failed_errno(conn, msg, -ecode); done: reply = dbus_message_new_method_return(msg); @@ -1151,10 +1152,10 @@ static DBusHandlerResult adapter_get_remote_info(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -1333,10 +1334,10 @@ static DBusHandlerResult adapter_get_remote_version(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "manufacturers"); @@ -1405,10 +1406,10 @@ static DBusHandlerResult adapter_get_remote_revision(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -1448,10 +1449,10 @@ static DBusHandlerResult adapter_get_remote_manufacturer(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "manufacturers"); @@ -1485,7 +1486,7 @@ static DBusHandlerResult adapter_get_remote_company(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str_bdaddr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(str_bdaddr, &bdaddr); ba2oui(&bdaddr, oui); @@ -1519,12 +1520,12 @@ static int get_remote_class(DBusConnection *conn, DBusMessage *msg, void *data, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_peer, DBUS_TYPE_INVALID)) { - error_invalid_arguments(conn, msg); + error_invalid_arguments(conn, msg, NULL); return -1; } if (check_address(addr_peer) < 0) { - error_invalid_arguments(conn, msg); + error_invalid_arguments(conn, msg, NULL); return -1; } @@ -1657,10 +1658,10 @@ static DBusHandlerResult adapter_get_remote_features(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "features"); @@ -1711,10 +1712,10 @@ static DBusHandlerResult adapter_get_remote_name(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(peer_addr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* check if it is in the cache */ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "names"); @@ -1762,10 +1763,10 @@ static DBusHandlerResult adapter_get_remote_alias(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(addr_ptr, &bdaddr); @@ -1796,18 +1797,18 @@ static DBusHandlerResult adapter_set_remote_alias(DBusConnection *conn, DBUS_TYPE_STRING, &addr, DBUS_TYPE_STRING, &alias, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if ((strlen(alias) == 0) || (check_address(addr) < 0)) { error("Alias change failed: Invalid parameter"); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } str2ba(addr, &bdaddr); ecode = set_device_alias(adapter->dev_id, &bdaddr, alias); if (ecode < 0) - return error_failed(conn, msg, -ecode); + return error_failed_errno(conn, msg, -ecode); reply = dbus_message_new_method_return(msg); if (!reply) @@ -1834,11 +1835,11 @@ static DBusHandlerResult adapter_clear_remote_alias(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) { error("Alias clear failed: Invalid parameter"); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } str2ba(addr_ptr, &bdaddr); @@ -1849,7 +1850,7 @@ static DBusHandlerResult adapter_clear_remote_alias(DBusConnection *conn, ecode = set_device_alias(adapter->dev_id, &bdaddr, NULL); if (ecode < 0) - return error_failed(conn, msg, -ecode); + return error_failed_errno(conn, msg, -ecode); reply = dbus_message_new_method_return(msg); if (!reply) @@ -1876,10 +1877,10 @@ static DBusHandlerResult adapter_last_seen(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen"); @@ -1913,10 +1914,10 @@ static DBusHandlerResult adapter_last_used(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused"); @@ -1962,7 +1963,7 @@ gboolean dc_pending_timeout_handler(void *data) 500) < 0) { int err = errno; error("Disconnect failed"); - error_failed(pending_dc->conn, pending_dc->msg, err); + error_failed_errno(pending_dc->conn, pending_dc->msg, err); } else { reply = dbus_message_new_method_return(pending_dc->msg); if (!reply) @@ -1999,10 +2000,10 @@ static DBusHandlerResult adapter_dc_remote_device(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(peer_addr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(peer_addr, &peer_bdaddr); @@ -2097,7 +2098,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &ret, &len) < 0) { error("Can't get socket error: %s (%d)", strerror(errno), errno); - error_failed(adapter->bonding->conn, adapter->bonding->rq, + error_failed_errno(adapter->bonding->conn, adapter->bonding->rq, errno); goto failed; } @@ -2116,7 +2117,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, if (getsockopt(sk, SOL_L2CAP, L2CAP_CONNINFO, &cinfo, &len) < 0) { error("Can't get connection info: %s (%d)", strerror(errno), errno); - error_failed(adapter->bonding->conn, adapter->bonding->rq, + error_failed_errno(adapter->bonding->conn, adapter->bonding->rq, errno); goto failed; } @@ -2145,7 +2146,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, if (hci_send_req(dd, &rq, 500) < 0) { error("Unable to send HCI request: %s (%d)", strerror(errno), errno); - error_failed(adapter->bonding->conn, adapter->bonding->rq, + error_failed_errno(adapter->bonding->conn, adapter->bonding->rq, errno); hci_close_dev(dd); goto failed; @@ -2154,7 +2155,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond, if (rp.status) { error("HCI_Authentication_Requested failed with status 0x%02x", rp.status); - error_failed(adapter->bonding->conn, adapter->bonding->rq, + error_failed_errno(adapter->bonding->conn, adapter->bonding->rq, bt_error(rp.status)); hci_close_dev(dd); goto failed; @@ -2200,10 +2201,10 @@ static DBusHandlerResult adapter_create_bonding(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(peer_addr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(peer_addr, &peer_bdaddr); @@ -2266,10 +2267,10 @@ static DBusHandlerResult adapter_cancel_bonding(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &peer_addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(peer_addr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(peer_addr, &peer_bdaddr); @@ -2337,10 +2338,10 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); dd = hci_open_dev(adapter->dev_id); if (dd < 0) @@ -2362,7 +2363,7 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn, if (textfile_casedel(filename, addr_ptr) < 0) { int err = errno; hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } str2ba(addr_ptr, &bdaddr); @@ -2381,7 +2382,7 @@ static DBusHandlerResult adapter_remove_bonding(DBusConnection *conn, int err = errno; error("Disconnect failed"); hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } } @@ -2409,10 +2410,10 @@ static DBusHandlerResult adapter_has_bonding(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); @@ -2448,7 +2449,7 @@ static DBusHandlerResult adapter_list_bondings(DBusConnection *conn, char filename[PATH_MAX + 1]; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); @@ -2481,10 +2482,10 @@ static DBusHandlerResult adapter_get_pin_code_length(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(adapter->address, &local); @@ -2518,16 +2519,16 @@ static DBusHandlerResult adapter_get_encryption_key_size(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr_ptr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(addr_ptr) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(addr_ptr, &bdaddr); val = get_encryption_key_size(adapter->dev_id, &bdaddr); if (val < 0) - return error_failed(conn, msg, -val); + return error_failed_errno(conn, msg, -val); reply = dbus_message_new_method_return(msg); @@ -2554,7 +2555,7 @@ static DBusHandlerResult adapter_start_periodic(DBusConnection *conn, return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (adapter->discov_active || adapter->pdiscov_active) return error_discover_in_progress(conn, msg); @@ -2586,14 +2587,14 @@ static DBusHandlerResult adapter_start_periodic(DBusConnection *conn, error("Unable to start periodic inquiry: %s (%d)", strerror(errno), errno); hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } if (status) { error("HCI_Periodic_Inquiry_Mode failed with status 0x%02x", status); hci_close_dev(dd); - return error_failed(conn, msg, bt_error(status)); + return error_failed_errno(conn, msg, bt_error(status)); } adapter->pdiscov_requestor = g_strdup(dbus_message_get_sender(msg)); @@ -2627,7 +2628,7 @@ static DBusHandlerResult adapter_stop_periodic(DBusConnection *conn, return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (!adapter->pdiscov_active) return error_not_authorized(conn, msg); @@ -2641,7 +2642,7 @@ static DBusHandlerResult adapter_stop_periodic(DBusConnection *conn, if (err == -ENODEV) return error_no_such_adapter(conn, msg); else - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); } reply = dbus_message_new_method_return(msg); @@ -2676,7 +2677,7 @@ static DBusHandlerResult adapter_set_pdiscov_resolve(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &resolve, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -2706,7 +2707,7 @@ static DBusHandlerResult adapter_get_pdiscov_resolve(DBusConnection *conn, dbus_bool_t resolve = adapter->pdiscov_resolve_names; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -2734,7 +2735,7 @@ static DBusHandlerResult adapter_discover_devices(DBusConnection *conn, return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (adapter->discov_active) return error_discover_in_progress(conn, msg); @@ -2767,14 +2768,14 @@ static DBusHandlerResult adapter_discover_devices(DBusConnection *conn, error("Unable to start inquiry: %s (%d)", strerror(errno), errno); hci_close_dev(dd); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } if (rp.status) { error("HCI_Inquiry command failed with status 0x%02x", rp.status); hci_close_dev(dd); - return error_failed(conn, msg, bt_error(rp.status)); + return error_failed_errno(conn, msg, bt_error(rp.status)); } method = dbus_message_get_member(msg); @@ -2807,7 +2808,7 @@ static DBusHandlerResult adapter_cancel_discovery(DBusConnection *conn, return error_not_ready(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* is there discover pending? or discovery cancel was requested * previously */ @@ -2828,7 +2829,7 @@ static DBusHandlerResult adapter_cancel_discovery(DBusConnection *conn, if (err == -ENODEV) return error_no_such_adapter(conn, msg); else - return error_failed(conn, msg, -err); + return error_failed_errno(conn, msg, -err); } /* Reply before send DiscoveryCompleted */ @@ -2881,7 +2882,7 @@ static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn, struct remote_device_list_t param = { NULL, 0 }; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* Add Bonded devices to the list */ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); @@ -2940,12 +2941,12 @@ static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* Date format is "YYYY-MM-DD HH:MM:SS GMT" */ len = strlen(string); if (len && (strptime(string, "%Y-%m-%d %H:%M:%S", &date) == NULL)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* Bonded and trusted: mandatory entries(no matter the date/time) */ create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys"); @@ -2997,10 +2998,10 @@ static DBusHandlerResult adapter_set_trusted(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -3031,10 +3032,10 @@ static DBusHandlerResult adapter_is_trusted(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(adapter->address, &local); @@ -3063,10 +3064,10 @@ static DBusHandlerResult adapter_remove_trust(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -3138,7 +3139,7 @@ static DBusHandlerResult list_devices(DBusConnection *conn, return error_unknown_method(conn, msg); if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -3168,10 +3169,10 @@ static DBusHandlerResult create_device(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -3198,7 +3199,7 @@ static DBusHandlerResult remove_device(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 7f2b2a99..8b4060b4 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -50,6 +50,7 @@ #include "dbus-hci.h" #include "dbus-common.h" #include "dbus-error.h" +#include "error.h" #include "dbus-service.h" #include "dbus-security.h" #include "dbus-database.h" @@ -109,7 +110,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, dbus_message_iter_get_fixed_array(&array, &record, &len); if (len <= 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = g_new0(struct record_data, 1); @@ -118,21 +119,21 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, if (!sdp_record) { error("Parsing of service record failed"); g_free(user_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } if (scanned != len) { error("Size mismatch of service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } if (add_record_to_server(sdp_record) < 0) { error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } user_record->handle = sdp_record->handle; @@ -143,7 +144,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, &user_record->handle) < 0) { error("Failed to register service record"); g_free(user_record); - return error_failed(conn, msg, errno); + return error_failed_errno(conn, msg, errno); } } @@ -175,7 +176,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = g_new0(struct record_data, 1); @@ -183,7 +184,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, if (!sdp_record) { error("Parsing of XML service record failed"); g_free(user_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } if (sdp_server_enable) { @@ -191,7 +192,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } user_record->handle = sdp_record->handle; @@ -200,7 +201,7 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, error("Failed to register service record"); g_free(user_record); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } user_record->handle = sdp_record->handle; @@ -243,7 +244,7 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, if (err < 0) { sdp_record_free(sdp_record); error("Failed to update the service record"); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } } else { sdp_data_t *d = sdp_data_alloc(SDP_UINT32, &handle); @@ -253,7 +254,7 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, sdp_record_free(sdp_record); if (err < 0) { error("Failed to update the service record"); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } } @@ -278,7 +279,7 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, dbus_message_iter_get_fixed_array(&array, &bin_record, &size); if (size <= 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) @@ -287,13 +288,13 @@ static DBusHandlerResult update_service_record(DBusConnection *conn, sdp_record = sdp_extract_pdu(bin_record, &scanned); if (!sdp_record) { error("Parsing of service record failed"); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } if (scanned != size) { error("Size mismatch of service record"); sdp_record_free(sdp_record); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } return update_record(conn, msg, handle, sdp_record); @@ -312,11 +313,11 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); len = (record ? strlen(record) : 0); if (len == 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); user_record = find_record(handle, dbus_message_get_sender(msg)); if (!user_record) @@ -326,7 +327,7 @@ static DBusHandlerResult update_service_record_from_xml(DBusConnection *conn, if (!sdp_record) { error("Parsing of XML service record failed"); sdp_record_free(sdp_record); - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); } return update_record(conn, msg, handle, sdp_record); @@ -342,7 +343,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -380,12 +381,12 @@ static DBusHandlerResult register_service(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &desc, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); if (service_register(conn, sender, ident, name, desc) < 0) - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); reply = dbus_message_new_method_return(msg); if (!reply) @@ -403,7 +404,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ident, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -415,7 +416,7 @@ static DBusHandlerResult unregister_service(DBusConnection *conn, return error_not_authorized(conn, msg); if (service_unregister(conn, service) < 0) - return error_failed(conn, msg, EIO); + return error_failed_errno(conn, msg, EIO); reply = dbus_message_new_method_return(msg); if (!reply) @@ -435,7 +436,7 @@ static DBusHandlerResult request_authorization(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); @@ -478,7 +479,7 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sender = dbus_message_get_sender(msg); diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index af67f831..26a0ffa6 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -37,14 +37,7 @@ #include "dbus.h" #include "dbus-common.h" #include "dbus-error.h" - -DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err) -{ - const char *str = strerror(err); - - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".Failed", str)); -} +#include "error.h" DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg) { @@ -52,13 +45,6 @@ DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg) dbus_message_new_error(msg, ERROR_INTERFACE ".NotReady", "Adapter is not ready")); } -DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".InvalidArguments", - "Invalid arguments")); -} - DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg) { char error[128]; @@ -88,13 +74,6 @@ DBusHandlerResult error_rejected(DBusConnection *conn, DBusMessage *msg) "Rejected")); } -DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".OutOfMemory", - "Out of memory")); -} - DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg) { return send_message_and_unref(conn, @@ -109,20 +88,6 @@ DBusHandlerResult error_no_such_service(DBusConnection *conn, DBusMessage *msg) "No such service")); } -DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".NotAvailable", - "Not available")); -} - -DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".NotSupported", - "Not supported")); -} - DBusHandlerResult error_request_deferred(DBusConnection *conn, DBusMessage *msg) { return send_message_and_unref(conn, @@ -130,13 +95,6 @@ DBusHandlerResult error_request_deferred(DBusConnection *conn, DBusMessage *msg) "Request Deferred")); } -DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".NotConnected", - "Not connected")); -} - DBusHandlerResult error_unsupported_major_class(DBusConnection *conn, DBusMessage *msg) { return send_message_and_unref(conn, @@ -144,48 +102,12 @@ DBusHandlerResult error_unsupported_major_class(DBusConnection *conn, DBusMessag "Unsupported Major Class")); } -DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".ConnectionAttemptFailed", - err ? strerror(err) : "Connection attempt failed")); -} - -static DBusHandlerResult error_already_exists(DBusConnection *conn, DBusMessage *msg, const char *str) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".AlreadyExists", str)); -} - -DBusHandlerResult error_does_not_exist(DBusConnection *conn, DBusMessage *msg, const char *str) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".DoesNotExist", str)); -} - -static DBusHandlerResult error_in_progress(DBusConnection *conn, DBusMessage *msg, const char *str) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".InProgress", str)); -} - -DBusHandlerResult error_canceled(DBusConnection *conn, DBusMessage *msg, const char *str) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".Canceled", str)); -} - DBusHandlerResult error_not_in_progress(DBusConnection *conn, DBusMessage *msg, const char *str) { return send_message_and_unref(conn, dbus_message_new_error(msg, ERROR_INTERFACE ".NotInProgress", str)); } -DBusHandlerResult error_connect_canceled(DBusConnection *conn, DBusMessage *msg) -{ - return error_canceled(conn, msg, "Connection creation was canceled"); -} - DBusHandlerResult error_bonding_already_exists(DBusConnection *conn, DBusMessage *msg) { return error_already_exists(conn, msg, "Bonding already exists"); @@ -218,16 +140,6 @@ DBusHandlerResult error_discover_in_progress(DBusConnection *conn, DBusMessage * return error_in_progress(conn, msg, "Discover in progress"); } -DBusHandlerResult error_connect_in_progress(DBusConnection *conn, DBusMessage *msg) -{ - return error_in_progress(conn, msg, "Connection creation in progress"); -} - -DBusHandlerResult error_connect_not_in_progress(DBusConnection *conn, DBusMessage *msg) -{ - return error_not_in_progress(conn, msg, "Connection creation not in progress"); -} - DBusHandlerResult error_record_does_not_exist(DBusConnection *conn, DBusMessage *msg) { return error_does_not_exist(conn, msg, "Record does not exist"); @@ -253,16 +165,6 @@ DBusHandlerResult error_auth_agent_does_not_exist(DBusConnection *conn, DBusMess return error_does_not_exist(conn, msg, "Authorization agent does not exist"); } -DBusHandlerResult error_binding_does_not_exist(DBusConnection *conn, DBusMessage *msg) -{ - return error_does_not_exist(conn, msg, "Binding does not exist"); -} - -DBusHandlerResult error_service_already_exists(DBusConnection *conn, DBusMessage *msg) -{ - return error_already_exists(conn, msg, "Service already exists"); -} - DBusHandlerResult error_service_does_not_exist(DBusConnection *conn, DBusMessage *msg) { return error_does_not_exist(conn, msg, "Service does not exist"); @@ -278,16 +180,6 @@ DBusHandlerResult error_audit_already_exists(DBusConnection *conn, DBusMessage * return error_already_exists(conn, msg, "Audit already performed"); } -DBusHandlerResult error_trusted_device_already_exists(DBusConnection *conn, DBusMessage *msg) -{ - return error_already_exists(conn, msg, "Trusted device already exists"); -} - -DBusHandlerResult error_trusted_device_does_not_exists(DBusConnection *conn, DBusMessage *msg) -{ - return error_does_not_exist(conn, msg, "Trusted device does not exist"); -} - DBusHandlerResult error_disconnect_in_progress(DBusConnection *conn, DBusMessage *msg) { return error_in_progress(conn, msg, "Disconnection in progress"); diff --git a/hcid/dbus-error.h b/hcid/dbus-error.h index a4a04c58..6a721eb5 100644 --- a/hcid/dbus-error.h +++ b/hcid/dbus-error.h @@ -22,47 +22,34 @@ * */ -#define ERROR_INTERFACE "org.bluez.Error" +/* + Please update dbus-api.txt in hcid folder when changes are made to this file. + */ -DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err); DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_rejected(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_no_such_service(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_request_deferred(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_does_not_exist(DBusConnection *conn, DBusMessage *msg, const char *str); -DBusHandlerResult error_canceled(DBusConnection *conn, DBusMessage *msg, const char *str); +/* Used only for hcid device audit feature */ DBusHandlerResult error_not_in_progress(DBusConnection *conn, DBusMessage *msg, const char *str); DBusHandlerResult error_unsupported_major_class(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err); DBusHandlerResult error_bonding_already_exists(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_bonding_does_not_exist(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_bonding_in_progress(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_bonding_not_in_progress(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_authentication_canceled(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_discover_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connect_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connect_not_in_progress(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_record_does_not_exist(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_passkey_agent_already_exists(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_passkey_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_auth_agent_already_exists(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_auth_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_binding_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_service_already_exists(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_service_does_not_exist(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_service_search_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connect_canceled(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_sdp_failed(DBusConnection *conn, DBusMessage *msg, int err); DBusHandlerResult error_audit_already_exists(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_trusted_device_already_exists(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_trusted_device_does_not_exists(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_disconnect_in_progress(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_service_start_in_progress(DBusConnection *conn, DBusMessage *msg); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index dcc550b7..1a21af4b 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -50,6 +50,7 @@ #include "textfile.h" #include "manager.h" #include "adapter.h" +#include "error.h" #include "dbus-helper.h" #include "dbus-common.h" #include "dbus-error.h" @@ -217,7 +218,7 @@ DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status) "Authentication Timeout"); case 0x17: /* too frequent pairing attempts */ return dbus_message_new_error(msg, - ERROR_INTERFACE ".RepeatedAttemps", + ERROR_INTERFACE ".RepeatedAttempts", "Repeated Attempts"); case 0x06: diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index 6d7e9b5b..4036f4fd 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -57,6 +57,7 @@ #include "dbus-hci.h" #include "dbus-common.h" #include "dbus-error.h" +#include "error.h" #include "dbus-sdp.h" #include "sdp-xml.h" @@ -436,7 +437,7 @@ static gboolean search_process_cb(GIOChannel *chan, failed: if (err) { - error_failed(ctxt->conn, ctxt->rq, err); + error_failed_errno(ctxt->conn, ctxt->rq, err); transaction_context_free(ctxt, FALSE); } @@ -461,12 +462,12 @@ static void remote_svc_rec_completed_cb(uint8_t type, uint16_t err, int sdp_err = sdp_get_error(ctxt->session); if (sdp_err < 0) { error("search failed: Invalid session!"); - error_failed(ctxt->conn, ctxt->rq, EINVAL); + error_failed_errno(ctxt->conn, ctxt->rq, EINVAL); goto failed; } error("search failed: %s (%d)", strerror(sdp_err), sdp_err); - error_failed(ctxt->conn, ctxt->rq, sdp_err); + error_failed_errno(ctxt->conn, ctxt->rq, sdp_err); goto failed; } @@ -478,7 +479,7 @@ static void remote_svc_rec_completed_cb(uint8_t type, uint16_t err, /* check response PDU ID */ if (type != SDP_SVC_ATTR_RSP) { error("SDP error: %s (%d)", strerror(EPROTO), EPROTO); - error_failed(ctxt->conn, ctxt->rq, EPROTO); + error_failed_errno(ctxt->conn, ctxt->rq, EPROTO); goto failed; } @@ -533,12 +534,12 @@ static void remote_svc_rec_completed_xml_cb(uint8_t type, uint16_t err, int sdp_err = sdp_get_error(ctxt->session); if (sdp_err < 0) { error("search failed: Invalid session!"); - error_failed(ctxt->conn, ctxt->rq, EINVAL); + error_failed_errno(ctxt->conn, ctxt->rq, EINVAL); goto failed; } error("search failed: %s (%d)", strerror(sdp_err), sdp_err); - error_failed(ctxt->conn, ctxt->rq, sdp_err); + error_failed_errno(ctxt->conn, ctxt->rq, sdp_err); goto failed; } @@ -550,7 +551,7 @@ static void remote_svc_rec_completed_xml_cb(uint8_t type, uint16_t err, /* check response PDU ID */ if (type != SDP_SVC_ATTR_RSP) { error("SDP error: %s (%d)", strerror(EPROTO), EPROTO); - error_failed(ctxt->conn, ctxt->rq, EPROTO); + error_failed_errno(ctxt->conn, ctxt->rq, EPROTO); goto failed; } @@ -607,12 +608,12 @@ static void remote_svc_handles_completed_cb(uint8_t type, uint16_t err, int sdp_err = sdp_get_error(ctxt->session); if (sdp_err < 0) { error("search failed: Invalid session!"); - error_failed(ctxt->conn, ctxt->rq, EINVAL); + error_failed_errno(ctxt->conn, ctxt->rq, EINVAL); goto failed; } error("search failed: %s (%d)", strerror(sdp_err), sdp_err); - error_failed(ctxt->conn, ctxt->rq, sdp_err); + error_failed_errno(ctxt->conn, ctxt->rq, sdp_err); goto failed; } @@ -624,7 +625,7 @@ static void remote_svc_handles_completed_cb(uint8_t type, uint16_t err, /* check response PDU ID */ if (type != SDP_SVC_SEARCH_RSP) { error("SDP error: %s (%d)", strerror(EPROTO), EPROTO); - error_failed(ctxt->conn, ctxt->rq, EPROTO); + error_failed_errno(ctxt->conn, ctxt->rq, EPROTO); goto failed; } @@ -739,12 +740,12 @@ static void remote_svc_identifiers_completed_cb(uint8_t type, uint16_t err, int sdp_err = sdp_get_error(ctxt->session); if (sdp_err < 0) { error("search failed: Invalid session!"); - error_failed(ctxt->conn, ctxt->rq, EINVAL); + error_failed_errno(ctxt->conn, ctxt->rq, EINVAL); goto failed; } error("search failed: %s (%d)", strerror(sdp_err), sdp_err); - error_failed(ctxt->conn, ctxt->rq, sdp_err); + error_failed_errno(ctxt->conn, ctxt->rq, sdp_err); goto failed; } @@ -756,7 +757,7 @@ static void remote_svc_identifiers_completed_cb(uint8_t type, uint16_t err, /* Check response PDU ID */ if (type != SDP_SVC_SEARCH_ATTR_RSP) { error("SDP error: %s (%d)", strerror(EPROTO), EPROTO); - error_failed(ctxt->conn, ctxt->rq, EPROTO); + error_failed_errno(ctxt->conn, ctxt->rq, EPROTO); goto failed; } @@ -1014,7 +1015,7 @@ DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_STRING, &dst, DBUS_TYPE_UINT32, &handle, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (find_pending_connect(dst)) return error_service_search_in_progress(conn, msg); @@ -1026,7 +1027,7 @@ DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, if (!connect_request(conn, msg, adapter->dev_id, dst, cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } return DBUS_HANDLER_RESULT_HANDLED; @@ -1087,13 +1088,13 @@ DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_STRING, &dst, DBUS_TYPE_STRING, &svc, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (strlen(svc) > 0) { /* Check if it is a service name string */ if (str2uuid(&uuid, svc) < 0) { error("Invalid service class name"); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } } @@ -1103,7 +1104,7 @@ DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg, if (!connect_request(conn, msg, adapter->dev_id, dst, remote_svc_handles_conn_cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } return DBUS_HANDLER_RESULT_HANDLED; @@ -1121,7 +1122,7 @@ DBusHandlerResult get_remote_svc_identifiers(DBusConnection *conn, DBusMessage * if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (find_pending_connect(dst)) return error_service_search_in_progress(conn, msg); @@ -1129,7 +1130,7 @@ DBusHandlerResult get_remote_svc_identifiers(DBusConnection *conn, DBusMessage * if (!connect_request(conn, msg, adapter->dev_id, dst, remote_svc_identifiers_conn_cb, &err)) { error("Search request failed: %s (%d)", strerror(err), err); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } return DBUS_HANDLER_RESULT_HANDLED; @@ -1147,7 +1148,7 @@ DBusHandlerResult finish_remote_svc_transact(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 1383a263..38e588be 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -50,6 +50,7 @@ #include "dbus-common.h" #include "dbus-service.h" #include "dbus-error.h" +#include "error.h" #include "dbus-security.h" #include "dbus-hci.h" @@ -259,10 +260,10 @@ static DBusHandlerResult register_passkey_agent(DBusConnection *conn, DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if ((check_address(addr) < 0) || (path[0] != '/')) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); memset(&ref, 0, sizeof(ref)); @@ -317,7 +318,7 @@ static DBusHandlerResult unregister_passkey_agent(DBusConnection *conn, DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); memset(&ref, 0, sizeof(ref)); @@ -357,7 +358,7 @@ static DBusHandlerResult register_default_passkey_agent(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); default_agent = passkey_agent_new(NULL, conn, dbus_message_get_sender(msg), path, NULL); @@ -398,7 +399,7 @@ static DBusHandlerResult unregister_default_passkey_agent(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); name = dbus_message_get_sender(msg); @@ -573,7 +574,7 @@ static DBusHandlerResult register_default_auth_agent(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); default_auth_agent = auth_agent_new(conn, dbus_message_get_sender(msg), path); @@ -614,7 +615,7 @@ static DBusHandlerResult unregister_default_auth_agent(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); name = dbus_message_get_sender(msg); diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index f66855b4..be9dccf5 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -49,6 +49,7 @@ #include "server.h" #include "dbus-common.h" #include "dbus-error.h" +#include "error.h" #include "manager.h" #include "adapter.h" #include "dbus-service.h" @@ -326,7 +327,7 @@ static void abort_startup(struct service *service, DBusConnection *conn, int eco if (service->action) { if (conn) - error_failed(conn, service->action, ecode); + error_failed_errno(conn, service->action, ecode); dbus_message_unref(service->action); service->action = NULL; } @@ -467,10 +468,10 @@ static DBusHandlerResult start(DBusConnection *conn, struct service *service = data; if (service->external || service->pid) - return error_failed(conn, msg, EALREADY); + return error_failed_errno(conn, msg, EALREADY); if (service_start(service, conn) < 0) - return error_failed(conn, msg, ENOEXEC); + return error_failed_errno(conn, msg, ENOEXEC); service->action = dbus_message_ref(msg); @@ -483,7 +484,7 @@ static DBusHandlerResult stop(DBusConnection *conn, struct service *service = data; if (service->external || !service->bus_name) - return error_failed(conn, msg, EPERM); + return error_failed_errno(conn, msg, EPERM); stop_service(service, FALSE); @@ -539,10 +540,10 @@ static DBusHandlerResult set_trusted(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -600,10 +601,10 @@ static DBusHandlerResult is_trusted(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); trusted = read_trust(BDADDR_ANY, address, service->ident); @@ -628,10 +629,10 @@ static DBusHandlerResult remove_trust(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c index 98303bc7..acd74ab4 100644 --- a/hcid/dbus-test.c +++ b/hcid/dbus-test.c @@ -45,6 +45,7 @@ #include "adapter.h" #include "dbus-hci.h" #include "dbus-error.h" +#include "error.h" #include "dbus-test.h" #define L2INFO_TIMEOUT (2 * 1000) @@ -424,11 +425,11 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, if (dbus_error_is_set(&err)) { error("Can't extract message arguments:%s", err.message); dbus_error_free(&err); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(address, &peer); str2ba(adapter->address, &local); @@ -507,11 +508,11 @@ static DBusHandlerResult cancel_audit_remote_device(DBusConnection *conn, if (dbus_error_is_set(&err)) { error("Can't extract message arguments:%s", err.message); dbus_error_free(&err); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(address, &peer); str2ba(adapter->address, &local); @@ -567,11 +568,11 @@ static DBusHandlerResult get_l2cap_feature_mask(DBusConnection *conn, if (dbus_error_is_set(&err)) { error("Can't extract message arguments:%s", err.message); dbus_error_free(&err); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(address, &peer); str2ba(adapter->address, &local); @@ -609,11 +610,11 @@ static DBusHandlerResult get_l2cap_mtu_size(DBusConnection *conn, if (dbus_error_is_set(&err)) { error("Can't extract message arguments:%s", err.message); dbus_error_free(&err); - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); } if (check_address(address) < 0) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); str2ba(address, &peer); str2ba(adapter->address, &local); diff --git a/hcid/manager.c b/hcid/manager.c index f7e4e29a..3b443f06 100644 --- a/hcid/manager.c +++ b/hcid/manager.c @@ -49,6 +49,7 @@ #include "dbus.h" #include "dbus-helper.h" #include "dbus-common.h" +#include "error.h" #include "dbus-error.h" #include "dbus-hci.h" #include "dbus-service.h" @@ -67,7 +68,7 @@ static DBusHandlerResult interface_version(DBusConnection *conn, dbus_uint32_t version = 0; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -86,7 +87,7 @@ static DBusHandlerResult default_adapter(DBusConnection *conn, char path[MAX_PATH_LENGTH], *path_ptr = path; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); if (default_adapter_id < 0) return error_no_such_adapter(conn, msg); @@ -159,7 +160,7 @@ static DBusHandlerResult find_adapter(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); /* hci_devid() would make sense to use here, except it is restricted to devices which are up */ @@ -200,11 +201,11 @@ static DBusHandlerResult list_adapters(DBusConnection *conn, int i, sk; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (sk < 0) - return error_failed(conn, msg, errno); + return error_failed_errno(conn, msg, errno); dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl)); @@ -215,7 +216,7 @@ static DBusHandlerResult list_adapters(DBusConnection *conn, int err = errno; close(sk); g_free(dl); - return error_failed(conn, msg, err); + return error_failed_errno(conn, msg, err); } dr = dl->dev_req; @@ -267,7 +268,7 @@ static DBusHandlerResult find_service(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); service = search_service(conn, pattern); if (!service) @@ -291,7 +292,7 @@ static DBusHandlerResult list_services(DBusConnection *conn, DBusMessageIter array_iter; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -317,7 +318,7 @@ static DBusHandlerResult activate_service(DBusConnection *conn, if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) - return error_invalid_arguments(conn, msg); + return error_invalid_arguments(conn, msg, NULL); service = search_service(conn, pattern); if (!service) @@ -341,7 +342,7 @@ static DBusHandlerResult activate_service(DBusConnection *conn, return error_service_start_in_progress(conn, msg); if (service_start(service, conn) < 0) - return error_failed(conn, msg, ENOEXEC); + return error_failed_errno(conn, msg, ENOEXEC); service->action = dbus_message_ref(msg); |