diff options
-rw-r--r-- | common/error.c | 157 | ||||
-rw-r--r-- | common/error.h | 30 | ||||
-rw-r--r-- | hcid/dbus-database.c | 1 | ||||
-rw-r--r-- | hcid/dbus-error.c | 12 | ||||
-rw-r--r-- | hcid/dbus-error.h | 1 | ||||
-rw-r--r-- | hcid/dbus-security.c | 236 | ||||
-rw-r--r-- | hcid/dbus-service.c | 1 |
7 files changed, 0 insertions, 438 deletions
diff --git a/common/error.c b/common/error.c index 096b8651..adf2aa4f 100644 --- a/common/error.c +++ b/common/error.c @@ -42,17 +42,6 @@ DBusMessage *create_errno_message(DBusMessage *msg, int err) } /** - org.bluez.Error.DeviceUnreachable: - - The remote device is either powered down or out of range. -*/ -DBusHandlerResult error_device_unreachable(DBusConnection *conn, DBusMessage *msg) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".DeviceUnreachable", - "Device Unreachable"); -} - -/** org.bluez.Error.ConnectionAttemptFailed: An unexpected error (other than DeviceUnreachable) error has occured while @@ -66,74 +55,6 @@ DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMess } /** - org.bluez.Error.AlreadyConnected: - - A connection request has been received on an already connected device. -*/ -DBusHandlerResult error_already_connected(DBusConnection *conn, DBusMessage *msg) -{ - return error_common_reply(conn, msg, - ERROR_INTERFACE ".AlreadyConnected", - "Already connected to a device"); -} - -/** - org.bluez.Error.InProgress: - - Error returned if an operation is in progress. Since - this is a generic error that can be used in various - situations, the error message should be more clear - about what is in progress. For example "Bonding in - progress". - */ -DBusHandlerResult error_in_progress(DBusConnection *conn, DBusMessage *msg, - const char *str) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".InProgress", str); -} - -/** - org.bluez.Error.InvalidArguments: - - The DBUS request does not contain the right number of - arguments with the right type, or the arguments are there but - their value is wrong, or does not makes sense in the current context. -*/ -DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg, - const char *descr) -{ - return error_common_reply(conn, msg, - ERROR_INTERFACE ".InvalidArguments", - descr ? descr : "Invalid arguments in method call"); -} - -/** - org.bluez.Error.OutOfMemory: - - Not enough memory to execute the request. - Error returned when a memory allocation via malloc() - fails. This error is similar to ENOMEM. -*/ -DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".OutOfMemory", - "Out of memory"); -} - -/** - org.bluez.Error.NotAvailable: - - The requested information is not there. - Examples of use: Adapter object when remote info is not available, or Database - object record is not found -*/ -DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".NotAvailable", - "Not available"); -} - -/** org.bluez.Error.NotSupported: The remote device does not support the expected feature. @@ -147,56 +68,6 @@ DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg) } /** - org.bluez.Error.NotConnected: - - The remote device is not connected, while the method call - would expect it to be, or is not in the expected state to - perform the action -*/ -DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".NotConnected", - "Not connected"); -} - -/** - org.bluez.Error.AlreadyExists: - - One of the requested elements already exists - Examples of use: Bonding, record, passkey agent, auth agent, - hid device ... already exists -*/ -DBusHandlerResult error_already_exists(DBusConnection *conn, DBusMessage *msg, - const char *str) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".AlreadyExists", str); -} - -/** - org.bluez.Error.DoesNotExist: - - One of the requested elements does not exist - Examples of use: Bonding, record, passkey agent, auth agent, bluetooth device - ... does not exist. -*/ -DBusHandlerResult error_does_not_exist(DBusConnection *conn, DBusMessage *msg, - const char *str) -{ - return error_common_reply(conn, msg, ERROR_INTERFACE ".DoesNotExist", str); -} - -/** - org.bluez.Error.DoesNotExist: - - Same as error_does_not_exist, but with device error message -*/ -DBusHandlerResult error_device_does_not_exist(DBusConnection *conn, - DBusMessage *msg) -{ - return error_does_not_exist(conn, msg, "Device does not exist"); -} - -/** org.bluez.Error.Canceled: The operation was canceled. @@ -252,31 +123,3 @@ DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg, return DBUS_HANDLER_RESULT_HANDLED; } - -/** - org.bluez.Error.UnknownMethod: - - Used in experimental code. -*/ -DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg) -{ - DBusMessage *derr; - 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); - - derr = dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownMethod", - error); - if (!derr) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - dbus_connection_send(conn, derr, NULL); - - dbus_message_unref(derr); - - return DBUS_HANDLER_RESULT_HANDLED; -} diff --git a/common/error.h b/common/error.h index a2492601..68ce105a 100644 --- a/common/error.h +++ b/common/error.h @@ -29,41 +29,13 @@ DBusMessage *create_errno_message(DBusMessage *msg, int err); -DBusHandlerResult error_device_unreachable(DBusConnection *conn, - DBusMessage *msg); - DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err); -DBusHandlerResult error_already_connected(DBusConnection *conn, - DBusMessage *msg); - -DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg); - -DBusHandlerResult error_in_progress(DBusConnection *conn, DBusMessage *msg, - const char *str); - -DBusHandlerResult error_invalid_arguments(DBusConnection *conn, - DBusMessage *msg, - const char *str); - -DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg); - -DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg); - DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_already_exists(DBusConnection *conn, DBusMessage *msg, - const char *str); - -DBusHandlerResult error_does_not_exist(DBusConnection *conn, DBusMessage *msg, - const char *str); - -DBusHandlerResult error_device_does_not_exist(DBusConnection *conn, - DBusMessage *msg); - DBusHandlerResult error_canceled(DBusConnection *conn, DBusMessage *msg, const char *str); @@ -75,5 +47,3 @@ DBusHandlerResult error_failed_errno(DBusConnection *conn, DBusMessage *msg, DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg, const char *name, const char *descr); - -DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg); diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index c1ac2b97..5924beb6 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -45,7 +45,6 @@ #include "adapter.h" #include "dbus-hci.h" #include "dbus-common.h" -#include "dbus-error.h" #include "error.h" #include "dbus-service.h" #include "dbus-security.h" diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index c1d1506a..76d9f095 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -50,13 +50,6 @@ static inline DBusHandlerResult send_message_and_unref(DBusConnection *conn, return DBUS_HANDLER_RESULT_HANDLED; } -DBusHandlerResult error_rejected(DBusConnection *conn, DBusMessage *msg) -{ - return send_message_and_unref(conn, - dbus_message_new_error(msg, ERROR_INTERFACE ".Rejected", - "Rejected")); -} - DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg) { return send_message_and_unref(conn, @@ -71,11 +64,6 @@ DBusHandlerResult error_authentication_canceled(DBusConnection *conn, DBusMessag "Authentication Canceled")); } -DBusHandlerResult error_auth_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg) -{ - return error_does_not_exist(conn, msg, "Authorization agent does not exist"); -} - static const char *strsdperror(int err) { switch (err) { diff --git a/hcid/dbus-error.h b/hcid/dbus-error.h index c2435501..6b3a22c4 100644 --- a/hcid/dbus-error.h +++ b/hcid/dbus-error.h @@ -26,7 +26,6 @@ Please update dbus-api.txt in hcid folder when changes are made to this file. */ -DBusHandlerResult error_rejected(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg); /* Used only for hcid device audit feature */ DBusHandlerResult error_authentication_canceled(DBusConnection *conn, DBusMessage *msg); diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 840efca6..f0b0d4fc 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -47,7 +47,6 @@ #include "hcid.h" #include "dbus-common.h" #include "dbus-service.h" -#include "dbus-error.h" #include "error.h" #include "dbus-security.h" #include "dbus-hci.h" @@ -405,27 +404,6 @@ static DBusMessage *unregister_default_passkey_agent(DBusConnection *conn, return dbus_message_new_method_return(msg); } -static struct auth_agent_req *auth_agent_req_new(DBusMessage *msg, - struct authorization_agent *agent, - const char *adapter_path, - const char *address, - const char *service_path, - const char *uuid) -{ - struct auth_agent_req *req; - - req = g_new0(struct auth_agent_req, 1); - - req->agent = agent; - req->msg = dbus_message_ref(msg); - req->adapter_path = g_strdup(adapter_path); - req->address = g_strdup(address); - req->service_path = g_strdup(service_path); - req->uuid = g_strdup(uuid); - - return req; -} - static void auth_agent_req_free(struct auth_agent_req *req) { dbus_message_unref(req->msg); @@ -456,32 +434,6 @@ static void auth_agent_cancel_requests(struct authorization_agent *agent) } } -static void auth_agent_call_cancel(struct auth_agent_req *req) -{ - struct authorization_agent *agent = req->agent; - DBusMessage *message; - - message = dbus_message_new_method_call(agent->name, agent->path, - "org.bluez.AuthorizationAgent", "Cancel"); - if (!message) { - error("Couldn't allocate D-Bus message"); - return; - } - - dbus_message_append_args(message, - DBUS_TYPE_STRING, &req->adapter_path, - DBUS_TYPE_STRING, &req->address, - DBUS_TYPE_STRING, &req->service_path, - DBUS_TYPE_STRING, &req->uuid, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(message, TRUE); - - dbus_connection_send(agent->conn, message, NULL); - - dbus_message_unref(message); -} - static void auth_agent_free(struct authorization_agent *agent) { g_free(agent->name); @@ -616,194 +568,6 @@ static DBusMessage *unregister_default_auth_agent(DBusConnection *conn, return dbus_message_new_method_return(msg); } -static void auth_agent_req_reply(DBusPendingCall *call, void *data) -{ - struct auth_agent_req *req = data; - struct authorization_agent *agent = req->agent; - DBusMessage *reply = dbus_pending_call_steal_reply(call); - DBusMessage *message; - DBusError err; - - debug("authorize reply"); - - dbus_error_init(&err); - if (dbus_set_error_from_message(&err, reply)) { - if (dbus_error_has_name(&err, DBUS_ERROR_NO_REPLY)) - auth_agent_call_cancel(req); - error("Authorization agent replied with an error: %s, %s", - err.name, err.message); - dbus_error_free(&err); - goto reject; - } - - dbus_error_init(&err); - if (!dbus_message_get_args(reply, &err, DBUS_TYPE_INVALID)) { - error("Wrong authorization agent reply signature: %s", - err.message); - dbus_error_free(&err); - goto reject; - } - - message = dbus_message_new_method_return(req->msg); - if (!message) - goto reject; - - dbus_connection_send(agent->conn, message, NULL); - - dbus_message_unref(message); - - debug("successfull reply was sent"); - - goto done; - -reject: - error_rejected(agent->conn, req->msg); - -done: - dbus_message_unref(reply); - - agent->pending_requests = g_slist_remove(agent->pending_requests, req); - - auth_agent_req_free(req); - - debug("auth_agent_reply: returning"); -} - -static DBusPendingCall *auth_agent_call_authorize(struct authorization_agent *agent, - const char *adapter_path, - const char *service_path, - const char *address, - const char *uuid) -{ - DBusMessage *message; - DBusPendingCall *call; - - message = dbus_message_new_method_call(agent->name, agent->path, - "org.bluez.AuthorizationAgent", "Authorize"); - if (!message) { - error("Couldn't allocate D-Bus message"); - return NULL; - } - - dbus_message_append_args(message, - DBUS_TYPE_STRING, &adapter_path, - DBUS_TYPE_STRING, &address, - DBUS_TYPE_STRING, &service_path, - DBUS_TYPE_STRING, &uuid, - DBUS_TYPE_INVALID); - - if (dbus_connection_send_with_reply(agent->conn, message, - &call, REQUEST_TIMEOUT) == FALSE) { - error("D-Bus send failed"); - dbus_message_unref(message); - return NULL; - } - - dbus_message_unref(message); - return call; -} - -DBusHandlerResult handle_authorize_request_old(DBusConnection *conn, - DBusMessage *msg, - struct service *service, - const char *path, - const char *address, - const char *uuid) -{ - struct auth_agent_req *req; - - debug("handle_authorize_request"); - - if (!default_auth_agent) { - debug("no default agent"); - return error_auth_agent_does_not_exist(conn, msg); - } - - req = auth_agent_req_new(msg, default_auth_agent, path, - address, service->object_path, uuid); - - req->call = auth_agent_call_authorize(default_auth_agent, path, - service->object_path, address, uuid); - if (!req->call) { - auth_agent_req_free(req); - return DBUS_HANDLER_RESULT_NEED_MEMORY; - } - - dbus_pending_call_set_notify(req->call, auth_agent_req_reply, req, - NULL); - default_auth_agent->pending_requests = - g_slist_append(default_auth_agent->pending_requests, req); - - debug("authorize request was forwarded"); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult auth_agent_send_cancel(DBusMessage *msg, - struct authorization_agent *agent, - const char *adapter_path, - struct service *service, - const char *address, - const char *uuid) -{ - struct auth_agent_req *req = NULL; - DBusMessage *message; - GSList *l; - - for (l = agent->pending_requests; l != NULL; l = l->next) { - req = l->data; - if (!strcmp(adapter_path, req->adapter_path) && - !strcmp(address, req->address) && - !strcmp(service->object_path, req->service_path) && - !strcmp(uuid, req->uuid)) - break; - } - - if (!req) - return error_does_not_exist(agent->conn, msg, - "No such authorization process"); - - message = dbus_message_new_method_return(msg); - if (!message) - return DBUS_HANDLER_RESULT_NEED_MEMORY; - - auth_agent_call_cancel(req); - auth_agent_req_cancel(req); - agent->pending_requests = g_slist_remove(agent->pending_requests, req); - auth_agent_req_free(req); - - dbus_connection_send(agent->conn, message, NULL); - - dbus_message_unref(message); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -DBusHandlerResult cancel_authorize_request_old(DBusConnection *conn, - DBusMessage *msg, - struct service *service, - const char *address, - const char *uuid) -{ - char adapter_path[PATH_MAX]; - int adapter_id; - bdaddr_t bdaddr; - - if (!default_auth_agent) - return error_auth_agent_does_not_exist(conn, msg); - - str2ba(address, &bdaddr); - - adapter_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr); - if (adapter_id < 0) - return error_not_connected(conn, msg); - - snprintf(adapter_path, sizeof(adapter_path), "/org/bluez/hci%d", - adapter_id); - - return auth_agent_send_cancel(msg, default_auth_agent, adapter_path, - service, address, uuid); -} static GDBusMethodTable security_methods[] = { { "RegisterDefaultPasskeyAgent", "s", "", diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index b615970a..43b11c51 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -48,7 +48,6 @@ #include "hcid.h" #include "server.h" #include "dbus-common.h" -#include "dbus-error.h" #include "error.h" #include "manager.h" #include "adapter.h" |