From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/3] client: Add 'auto' parameter to agent command
Date: Tue, 26 Nov 2013 17:05:08 +0200 [thread overview]
Message-ID: <1385478310-22520-1-git-send-email-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds 'auto' parameter to agent command which auto accepts requests
whenever possible.
---
client/agent.c | 14 +++++++++++++-
client/agent.h | 2 +-
client/main.c | 30 ++++++++++++++++++------------
3 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/client/agent.c b/client/agent.c
index 2d9dffd..81526a1 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <readline/readline.h>
#include <gdbus.h>
@@ -40,6 +41,7 @@
static gboolean agent_registered = FALSE;
static const char *agent_capability = NULL;
+static bool agent_auto_accept = false;
static DBusMessage *pending_message = NULL;
static char *agent_saved_prompt = NULL;
static int agent_saved_point = 0;
@@ -259,6 +261,9 @@ static DBusMessage *request_confirmation(DBusConnection *conn,
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
DBUS_TYPE_UINT32, &passkey, DBUS_TYPE_INVALID);
+ if (agent_auto_accept)
+ return dbus_message_new_method_return(msg);
+
str = g_strdup_printf("Confirm passkey %06u (yes/no): ", passkey);
agent_prompt(str);
g_free(str);
@@ -278,6 +283,9 @@ static DBusMessage *request_authorization(DBusConnection *conn,
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
DBUS_TYPE_INVALID);
+ if (agent_auto_accept)
+ return dbus_message_new_method_return(msg);
+
agent_prompt("Accept pairing (yes/no): ");
pending_message = dbus_message_ref(msg);
@@ -296,6 +304,9 @@ static DBusMessage *authorize_service(DBusConnection *conn,
dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID);
+ if (agent_auto_accept)
+ return dbus_message_new_method_return(msg);
+
str = g_strdup_printf("Authorize service %s (yes/no): ", uuid);
agent_prompt(str);
g_free(str);
@@ -375,7 +386,7 @@ static void register_agent_reply(DBusMessage *message, void *user_data)
}
void agent_register(DBusConnection *conn, GDBusProxy *manager,
- const char *capability)
+ const char *capability, bool auto_accept)
{
if (agent_registered == TRUE) {
@@ -401,6 +412,7 @@ void agent_register(DBusConnection *conn, GDBusProxy *manager,
}
agent_capability = NULL;
+ agent_auto_accept = auto_accept;
}
static void unregister_agent_setup(DBusMessageIter *iter, void *user_data)
diff --git a/client/agent.h b/client/agent.h
index 0fbe8e5..467afb0 100644
--- a/client/agent.h
+++ b/client/agent.h
@@ -22,7 +22,7 @@
*/
void agent_register(DBusConnection *conn, GDBusProxy *manager,
- const char *capability);
+ const char *capability, bool auto_accept);
void agent_unregister(DBusConnection *conn, GDBusProxy *manager);
void agent_default(DBusConnection *conn, GDBusProxy *manager);
diff --git a/client/main.c b/client/main.c
index ebc85c6..5639f0e 100644
--- a/client/main.c
+++ b/client/main.c
@@ -29,6 +29,7 @@
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <signal.h>
#include <sys/signalfd.h>
@@ -53,13 +54,15 @@ static GMainLoop *main_loop;
static DBusConnection *dbus_conn;
static GDBusProxy *agent_manager;
-static char *auto_register_agent = NULL;
+static char *agent_capability = NULL;
+static bool agent_auto_accept = false;
static GDBusProxy *default_ctrl;
static GList *ctrl_list;
static GList *dev_list;
static const char * const agent_arguments[] = {
+ "auto",
"on",
"off",
"DisplayOnly",
@@ -284,9 +287,10 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
if (!agent_manager) {
agent_manager = proxy;
- if (auto_register_agent)
+ if (agent_capability)
agent_register(dbus_conn, agent_manager,
- auto_register_agent);
+ agent_capability,
+ agent_auto_accept);
}
}
}
@@ -434,7 +438,8 @@ static gboolean parse_argument_agent(const char *arg, dbus_bool_t *value,
return FALSE;
}
- if (strcmp(arg, "on") == 0 || strcmp(arg, "yes") == 0) {
+ if (strcmp(arg, "on") == 0 || strcmp(arg, "yes") == 0 ||
+ strcmp(arg, "auto") == 0) {
*value = TRUE;
*capability = "";
return TRUE;
@@ -680,17 +685,18 @@ static void cmd_agent(const char *arg)
return;
if (enable == TRUE) {
- g_free(auto_register_agent);
- auto_register_agent = g_strdup(capability);
+ g_free(agent_capability);
+ agent_capability = g_strdup(capability);
+ agent_auto_accept = strcmp(arg, "auto") == 0 ? true : false;
if (agent_manager)
agent_register(dbus_conn, agent_manager,
- auto_register_agent);
+ agent_capability, agent_auto_accept);
else
rl_printf("Agent registration enabled\n");
} else {
- g_free(auto_register_agent);
- auto_register_agent = NULL;
+ g_free(agent_capability);
+ agent_capability = NULL;
if (agent_manager)
agent_unregister(dbus_conn, agent_manager);
@@ -1331,9 +1337,9 @@ static gboolean parse_agent(const char *key, const char *value,
gpointer user_data, GError **error)
{
if (value)
- auto_register_agent = g_strdup(value);
+ agent_capability = g_strdup(value);
else
- auto_register_agent = g_strdup("");
+ agent_capability = g_strdup("");
return TRUE;
}
@@ -1410,7 +1416,7 @@ int main(int argc, char *argv[])
g_list_free_full(ctrl_list, proxy_leak);
g_list_free_full(dev_list, proxy_leak);
- g_free(auto_register_agent);
+ g_free(agent_capability);
return 0;
}
--
1.8.3.1
next reply other threads:[~2013-11-26 15:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-26 15:05 Luiz Augusto von Dentz [this message]
2013-11-26 15:05 ` [PATCH BlueZ 2/3] client: Fix not releasing agent if bluetoothd exit without calling Release Luiz Augusto von Dentz
2013-11-26 15:05 ` [PATCH BlueZ 3/3] core/agent: Set first agent as default Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385478310-22520-1-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox