From 2c2eea910ae0f4a3ef9f10c2b610a13dcb64eb4e Mon Sep 17 00:00:00 2001 From: Gu Chaojie Date: Tue, 1 Jul 2014 10:51:59 +0800 Subject: [PATCH] Add param fd into authorize service Change-Id: I138b1a9f1e8fca2530d443d461d961a13727bafa Signed-off-by: Gu Chaojie --- profiles/audio/avctp.c | 4 ++-- profiles/audio/avdtp.c | 4 ++-- profiles/input/server.c | 2 +- profiles/network/server.c | 2 +- profiles/sap/server.c | 2 +- src/adapter.c | 14 +++++++++----- src/adapter.h | 2 +- src/agent.c | 22 ++++++++++++++-------- src/agent.h | 4 ++-- src/profile.c | 4 +++- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c index 74d3512..1879ae2 100644 --- a/profiles/audio/avctp.c +++ b/profiles/audio/avctp.c @@ -1339,8 +1339,8 @@ static void avctp_control_confirm(struct avctp *session, GIOChannel *chan, dst = device_get_address(dev); session->auth_id = btd_request_authorization(src, dst, - AVRCP_REMOTE_UUID, - auth_cb, session); + AVRCP_REMOTE_UUID, + auth_cb, session, 0); if (session->auth_id == 0) goto drop; diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c index 8a7d1c0..8bd7f5a 100644 --- a/profiles/audio/avdtp.c +++ b/profiles/audio/avdtp.c @@ -2507,8 +2507,8 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data) (GIOFunc) session_cb, session); session->auth_id = btd_request_authorization(&src, &dst, - ADVANCED_AUDIO_UUID, - auth_cb, session); + ADVANCED_AUDIO_UUID, + auth_cb, session, 0); if (session->auth_id == 0) { avdtp_set_state(session, AVDTP_SESSION_STATE_DISCONNECTED); goto drop; diff --git a/profiles/input/server.c b/profiles/input/server.c index 772a605..8c64f87 100644 --- a/profiles/input/server.c +++ b/profiles/input/server.c @@ -266,7 +266,7 @@ static void confirm_event_cb(GIOChannel *chan, gpointer user_data) server->confirm = g_io_channel_ref(chan); ret = btd_request_authorization(&src, &dst, HID_UUID, - auth_callback, server); + auth_callback, server, 0); if (ret != 0) return; diff --git a/profiles/network/server.c b/profiles/network/server.c index a1c5646..4834ce8 100644 --- a/profiles/network/server.c +++ b/profiles/network/server.c @@ -537,7 +537,7 @@ static void confirm_event(GIOChannel *chan, gpointer user_data) na->setup->io = g_io_channel_ref(chan); ret = btd_request_authorization(&src, &dst, BNEP_SVC_UUID, - auth_cb, na); + auth_cb, na, 0); if (ret == 0) { error("Refusing connect from %s", address); setup_destroy(na); diff --git a/profiles/sap/server.c b/profiles/sap/server.c index 20c6cab..20af81f 100644 --- a/profiles/sap/server.c +++ b/profiles/sap/server.c @@ -1253,7 +1253,7 @@ static void connect_confirm_cb(GIOChannel *io, gpointer data) ba2str(&dst, dstaddr); ret = btd_request_authorization(&src, &dst, SAP_UUID, connect_auth_cb, - server); + server, 0); if (ret == 0) { error("Authorization failure"); sap_server_remove_conn(server); diff --git a/src/adapter.c b/src/adapter.c index ac42b7d..a3722e2 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -139,6 +139,7 @@ struct service_auth { struct btd_device *device; struct btd_adapter *adapter; struct agent *agent; /* NULL for queued auths */ + int fd; }; struct btd_adapter_pin_cb_iter { @@ -4647,7 +4648,7 @@ static gboolean process_auth_queue(gpointer user_data) dev_path = btd_device_get_path(device); if (agent_authorize_service(auth->agent, dev_path, auth->uuid, - agent_auth_cb, adapter, NULL) < 0) { + agent_auth_cb, adapter, NULL, auth->fd) < 0) { auth->cb(&err, auth->user_data); goto next; } @@ -4686,7 +4687,7 @@ static void svc_complete(struct btd_device *dev, int err, void *user_data) static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst, const char *uuid, service_auth_cb cb, - void *user_data) + void *user_data, int fd) { struct service_auth *auth; struct btd_device *device; @@ -4710,6 +4711,7 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst, auth->device = device; auth->adapter = adapter; auth->id = ++id; + auth->fd = fd; auth->svc_id = device_wait_for_svc_complete(device, svc_complete, auth); g_queue_push_tail(adapter->auths, auth); @@ -4719,7 +4721,7 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst, guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, const char *uuid, service_auth_cb cb, - void *user_data) + void *user_data, int fd) { struct btd_adapter *adapter; GSList *l; @@ -4729,7 +4731,8 @@ guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, if (!adapter) return 0; - return adapter_authorize(adapter, dst, uuid, cb, user_data); + return adapter_authorize(adapter, dst, uuid, cb, + user_data, fd); } for (l = adapters; l != NULL; l = g_slist_next(l)) { @@ -4737,7 +4740,8 @@ guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, adapter = l->data; - id = adapter_authorize(adapter, dst, uuid, cb, user_data); + id = adapter_authorize(adapter, dst, uuid, cb, + user_data, fd); if (id != 0) return id; } diff --git a/src/adapter.h b/src/adapter.h index f88c339..a5c0801 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -120,7 +120,7 @@ void adapter_remove_profile(struct btd_adapter *adapter, gpointer p); int btd_register_adapter_driver(struct btd_adapter_driver *driver); void btd_unregister_adapter_driver(struct btd_adapter_driver *driver); guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, - const char *uuid, service_auth_cb cb, void *user_data); + const char *uuid, service_auth_cb cb, void *user_data, int fd); int btd_cancel_authorization(guint id); int btd_adapter_restore_powered(struct btd_adapter *adapter); diff --git a/src/agent.c b/src/agent.c index ded59a3..d23550f 100644 --- a/src/agent.c +++ b/src/agent.c @@ -377,8 +377,10 @@ done: static int agent_call_authorize_service(struct agent_request *req, const char *device_path, - const char *uuid) + const char *uuid, + const int fd) { + DBusMessageIter iter, dict; struct agent *agent = req->agent; req->msg = dbus_message_new_method_call(agent->owner, agent->path, @@ -388,10 +390,14 @@ static int agent_call_authorize_service(struct agent_request *req, return -ENOMEM; } - dbus_message_append_args(req->msg, - DBUS_TYPE_OBJECT_PATH, &device_path, - DBUS_TYPE_STRING, &uuid, - DBUS_TYPE_INVALID); + dbus_message_iter_init_append(req->msg, &iter); + + dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, + &device_path); + + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &uuid); + + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd); if (g_dbus_send_message_with_reply(btd_get_dbus_connection(), req->msg, &req->call, @@ -405,8 +411,8 @@ static int agent_call_authorize_service(struct agent_request *req, } int agent_authorize_service(struct agent *agent, const char *path, - const char *uuid, agent_cb cb, - void *user_data, GDestroyNotify destroy) + const char *uuid, agent_cb cb, + void *user_data, GDestroyNotify destroy, int fd) { struct agent_request *req; int err; @@ -417,7 +423,7 @@ int agent_authorize_service(struct agent *agent, const char *path, req = agent_request_new(agent, AGENT_REQUEST_AUTHORIZE_SERVICE, cb, user_data, destroy); - err = agent_call_authorize_service(req, path, uuid); + err = agent_call_authorize_service(req, path, uuid, fd); if (err < 0) { agent_request_free(req, FALSE); return -ENOMEM; diff --git a/src/agent.h b/src/agent.h index 1e46920..bab6db0 100644 --- a/src/agent.h +++ b/src/agent.h @@ -39,8 +39,8 @@ void agent_unref(struct agent *agent); struct agent *agent_get(const char *owner); int agent_authorize_service(struct agent *agent, const char *path, - const char *uuid, agent_cb cb, - void *user_data, GDestroyNotify destroy); + const char *uuid, agent_cb cb, + void *user_data, GDestroyNotify destroy, int fd); int agent_request_pincode(struct agent *agent, struct btd_device *device, agent_pincode_cb cb, gboolean secure, diff --git a/src/profile.c b/src/profile.c index 91167bc..90713ae 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1100,6 +1100,7 @@ static void ext_confirm(GIOChannel *io, gpointer user_data) GError *gerr = NULL; bdaddr_t src, dst; char addr[18]; + int fd; bt_io_get(io, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src, @@ -1119,8 +1120,9 @@ static void ext_confirm(GIOChannel *io, gpointer user_data) if (conn == NULL) return; + fd = g_io_channel_unix_get_fd(conn->io); conn->auth_id = btd_request_authorization(&src, &dst, uuid, ext_auth, - conn); + conn, fd); if (conn->auth_id == 0) { error("%s authorization failure", ext->name); ext_io_destroy(conn); -- 2.7.4