2009-06-28 18:27:36

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 1/4] test/agent.c: honour commandline --device

---
test/agent.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index b256f52..7cd4b6e 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -283,7 +283,7 @@ static char *get_device(const char *device)
{
char *path;

- path = strdup("/org/bluez/hci0");
+ path = strdup(device);

return path;
}
--
1.6.3.1



2009-06-30 15:48:28

by Filippo Giunchedi

[permalink] [raw]
Subject: Re: [PATCH 3/3] test/agent.c: pairing via CreatePairedDevice

[JFTR I'm subscribed to linux-bluetooth, no need to CC]

On Tue, Jun 30, 2009 at 06:39:10PM +0300, Johan Hedberg wrote:
> Thanks for the updated patches. There are still some issues however:
>
> $ test/agent 1234
> Can't register agent
> Method "RegisterAgent" with signature "os" on interface "org.bluez.Adapter" doesn't exist
>
> whereas running test/simple-agent (without arguments) works fine. Or am I
> giving the wrong arguments to test/agent in order to run it in passive
> mode?

You are right, I thought I had sent the patch for calling DefaultDevice and that
went unnoticed but it seems I didn't send it, sending now.

> Also, the RequestPasskey agent method is only used if we are a Bluetooth
> 2.1 keyboard, so it's not particularly useful for the typical environment
> that BlueZ gets run in. To get at least the most common Bluetooth 2.1
> Secure Simple Pairing cases covered at least the RequestConfirmation and
> DisplayPasskey callbacks should be supported. Also, once these do become
> supported the PIN code command line parameter should probably be set as
> optional since you won't be asked for a PIN code when doing SSP.

Indeed, I'll try to update agent.c to better match simple-agent behaviour in the
future

filippo
--
Filippo Giunchedi - http://esaurito.net - 0x6B79D401

UNIX is simple, but it just takes a genius to understand the simplicity.
-- Dennis Ritchie

2009-06-30 15:39:10

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 3/3] test/agent.c: pairing via CreatePairedDevice

Hi Filippo,

Thanks for the updated patches. There are still some issues however:

$ test/agent 1234
Can't register agent
Method "RegisterAgent" with signature "os" on interface "org.bluez.Adapter" doesn't exist

whereas running test/simple-agent (without arguments) works fine. Or am I
giving the wrong arguments to test/agent in order to run it in passive
mode?

Also, the RequestPasskey agent method is only used if we are a Bluetooth
2.1 keyboard, so it's not particularly useful for the typical environment
that BlueZ gets run in. To get at least the most common Bluetooth 2.1
Secure Simple Pairing cases covered at least the RequestConfirmation and
DisplayPasskey callbacks should be supported. Also, once these do become
supported the PIN code command line parameter should probably be set as
optional since you won't be asked for a PIN code when doing SSP.

I guess these patches do improve the current situation in anycase since
now calling CreatePairedDevice should at least be possible with test/agent
but I'm not sure if I should wait for another update or just apply the
current versions. Marcel?

Johan

2009-06-30 15:16:48

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 3/3] test/agent.c: pairing via CreatePairedDevice

introduce optional argument target for remote address, if passed pairing
will be called
---
test/agent.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 25e3d54..7c492b7 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -362,6 +362,39 @@ static int unregister_agent(DBusConnection *conn, const char *device_path,
return 0;
}

+static int create_paired_device(DBusConnection *conn, const char *device_path,
+ const char *agent_path,
+ const char *capabilities, const char *target)
+{
+ dbus_bool_t success;
+ DBusMessage *msg;
+
+ msg = dbus_message_new_method_call("org.bluez", device_path,
+ "org.bluez.Adapter", "CreatePairedDevice");
+ if (!msg) {
+ fprintf(stderr, "Can't allocate new method call\n");
+ return -1;
+ }
+
+ dbus_message_append_args(msg, DBUS_TYPE_STRING, &target,
+ DBUS_TYPE_OBJECT_PATH, &agent_path,
+ DBUS_TYPE_STRING, &capabilities,
+ DBUS_TYPE_INVALID);
+
+ success = dbus_connection_send(conn, msg, NULL);
+
+ dbus_message_unref(msg);
+
+ if (!success) {
+ fprintf(stderr, "Not enough memory for message send\n");
+ return -1;
+ }
+
+ dbus_connection_flush(conn);
+
+ return 0;
+}
+
static char *get_device(const char *device)
{
char *path = "/org/bluez/hci0";
@@ -377,7 +410,7 @@ static void usage(void)
printf("Bluetooth agent ver %s\n\n", VERSION);

printf("Usage:\n"
- "\tagent [--device interface] [--path agent-path] <passkey>\n"
+ "\tagent [--device interface] [--path agent-path] <passkey> [<target_device>]\n"
"\n");
}

@@ -396,7 +429,7 @@ int main(int argc, char *argv[])
struct sigaction sa;
DBusConnection *conn;
char match_string[128], default_path[128], *device_id = NULL;
- char *device_path = NULL, *agent_path = NULL;
+ char *device_path = NULL, *agent_path = NULL, *target = NULL;
int opt;

snprintf(default_path, sizeof(default_path),
@@ -439,6 +472,9 @@ int main(int argc, char *argv[])

passkey = strdup(argv[0]);

+ if (argc > 1)
+ target = strdup(argv[1]);
+
if (!agent_path)
agent_path = strdup(default_path);

@@ -451,9 +487,17 @@ int main(int argc, char *argv[])
if (!device_path)
device_path = get_device(device_id);

- if (register_agent(conn, device_path, agent_path, capabilities) < 0) {
- dbus_connection_unref(conn);
- exit(1);
+ if (!target) {
+ if (register_agent(conn, device_path, agent_path, capabilities) < 0) {
+ dbus_connection_unref(conn);
+ exit(1);
+ }
+ } else {
+ if (create_paired_device(conn, device_path, agent_path,
+ capabilities, target) < 0) {
+ dbus_connection_unref(conn);
+ exit(1);
+ }
}

if (!dbus_connection_add_filter(conn, agent_filter, NULL, NULL))
@@ -476,8 +520,10 @@ int main(int argc, char *argv[])
break;
}

- if (!__io_terminated)
- unregister_agent(conn, device_path, agent_path);
+ if (!__io_terminated) {
+ if (!target)
+ unregister_agent(conn, device_path, agent_path);
+ }

free(device_path);
free(agent_path);
--
1.6.3.3


2009-06-30 15:16:46

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 1/3] test/agent.c: honour commandline --device

---
test/agent.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index b256f52..334618e 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -281,9 +281,10 @@ static int unregister_agent(DBusConnection *conn, const char *device_path,

static char *get_device(const char *device)
{
- char *path;
+ char *path = "/org/bluez/hci0";

- path = strdup("/org/bluez/hci0");
+ if (device)
+ path = strdup(device);

return path;
}
--
1.6.3.3


2009-06-30 15:16:47

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 2/3] test/agent.c: update dbus API usage

This patch implements and updates some parts of dbus API missing from
test/agent.c, namely Authorize, RequestPinCode and RequestPasskey.
---
test/agent.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 97 insertions(+), 14 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 334618e..25e3d54 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -70,20 +70,18 @@ static DBusHandlerResult agent_filter(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

-static DBusHandlerResult request_message(DBusConnection *conn,
+static DBusHandlerResult request_pincode_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
- dbus_bool_t numeric;
+ const char *path;

if (!passkey)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_BOOLEAN, &numeric, DBUS_TYPE_INVALID)) {
- fprintf(stderr, "Invalid arguments for passkey Request method");
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPinCode method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

@@ -99,7 +97,7 @@ static DBusHandlerResult request_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}

- printf("Passkey request for device %s\n", address);
+ printf("Pincode request for device %s\n", path);

dbus_message_append_args(reply, DBUS_TYPE_STRING, &passkey,
DBUS_TYPE_INVALID);
@@ -114,20 +112,63 @@ send:
return DBUS_HANDLER_RESULT_HANDLED;
}

-static DBusHandlerResult cancel_message(DBusConnection *conn,
+static DBusHandlerResult request_passkey_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
+ const char *path;
+ unsigned int int_passkey;
+
+ if (!passkey)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPasskey method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Passkey request for device %s\n", path);
+
+ int_passkey = strtoul(passkey, NULL, 10);
+
+ dbus_message_append_args(reply, DBUS_TYPE_UINT32, &int_passkey,
+ DBUS_TYPE_INVALID);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult cancel_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) {
fprintf(stderr, "Invalid arguments for passkey Confirm method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

- printf("Request canceled for device %s\n", address);
+ printf("Request canceled\n");

reply = dbus_message_new_method_return(msg);
if (!reply) {
@@ -174,11 +215,50 @@ static DBusHandlerResult release_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}

+static DBusHandlerResult authorize_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char *path, *uuid;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for Authorize method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Authorizing request for %s\n", path);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult agent_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
- return request_message(conn, msg, data);
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode"))
+ return request_pincode_message(conn, msg, data);
+
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPasskey"))
+ return request_passkey_message(conn, msg, data);

if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Cancel"))
return cancel_message(conn, msg, data);
@@ -186,6 +266,9 @@ static DBusHandlerResult agent_message(DBusConnection *conn,
if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Release"))
return release_message(conn, msg, data);

+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Authorize"))
+ return authorize_message(conn, msg, data);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

--
1.6.3.3


2009-06-30 13:34:39

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 3/4] test/agent.c: register object path only

Hi,

On Sun, Jun 28, 2009, Filippo Giunchedi wrote:
> remove unused register_agent and unregister_agent, will be handled by
> CreatePairedDevice

I don't think we want to remove the RegisterAgent and UnregisterAgent
feature. It is needed when you want the agent to passively wait for
incoming pairing request. E.g. the simple-agent script supports it too
when you run it without arguments.

So could you please redo the patches so that the Register/UnregisterAgent
support remains. Thanks.

Johan

2009-06-28 18:27:38

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 3/4] test/agent.c: register object path only

remove unused register_agent and unregister_agent, will be handled by
CreatePairedDevice
---
test/agent.c | 96 ++-------------------------------------------------------
1 files changed, 4 insertions(+), 92 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 4796e90..30af926 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -276,92 +276,6 @@ static const DBusObjectPathVTable agent_table = {
.message_function = agent_message,
};

-static int register_agent(DBusConnection *conn, const char *device_path,
- const char *agent_path,
- const char *capabilities)
-{
- DBusMessage *msg, *reply;
- DBusError err;
-
- if (!dbus_connection_register_object_path(conn, agent_path,
- &agent_table, NULL)) {
- fprintf(stderr, "Can't register object path for agent\n");
- return -1;
- }
-
- msg = dbus_message_new_method_call("org.bluez", device_path,
- "org.bluez.Adapter", "RegisterAgent");
- if (!msg) {
- fprintf(stderr, "Can't allocate new method call\n");
- return -1;
- }
-
- dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &agent_path,
- DBUS_TYPE_STRING, &capabilities,
- DBUS_TYPE_INVALID);
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
-
- dbus_message_unref(msg);
-
- if (!reply) {
- fprintf(stderr, "Can't register agent\n");
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- }
- return -1;
- }
-
- dbus_message_unref(reply);
-
- dbus_connection_flush(conn);
-
- return 0;
-}
-
-static int unregister_agent(DBusConnection *conn, const char *device_path,
- const char *agent_path)
-{
- DBusMessage *msg, *reply;
- DBusError err;
-
- msg = dbus_message_new_method_call("org.bluez", device_path,
- "org.bluez.Adapter", "UnregisterAgent");
- if (!msg) {
- fprintf(stderr, "Can't allocate new method call\n");
- return -1;
- }
-
- dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &agent_path,
- DBUS_TYPE_INVALID);
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
-
- dbus_message_unref(msg);
-
- if (!reply) {
- fprintf(stderr, "Can't unregister agent\n");
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- }
- return -1;
- }
-
- dbus_message_unref(reply);
-
- dbus_connection_flush(conn);
-
- dbus_connection_unregister_object_path(conn, agent_path);
-
- return 0;
-}
-
static char *get_device(const char *device)
{
char *path;
@@ -450,9 +364,10 @@ int main(int argc, char *argv[])
if (!device_path)
device_path = get_device(device_id);

- if (register_agent(conn, device_path, agent_path, capabilities) < 0) {
- dbus_connection_unref(conn);
- exit(1);
+ if (!dbus_connection_register_object_path(conn, agent_path,
+ &agent_table, NULL)) {
+ fprintf(stderr, "Can't register object path for agent\n");
+ return -1;
}

if (!dbus_connection_add_filter(conn, agent_filter, NULL, NULL))
@@ -475,9 +390,6 @@ int main(int argc, char *argv[])
break;
}

- if (!__io_terminated)
- unregister_agent(conn, device_path, agent_path);
-
free(device_path);
free(agent_path);

--
1.6.3.1


2009-06-28 18:27:37

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 2/4] test/agent.c: update dbus API usage

This patch implements and updates some parts of dbus API missing from
test/agent.c, namely Authorize, RequestPinCode and RequestPasskey.
---
test/agent.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 97 insertions(+), 14 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 7cd4b6e..4796e90 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -70,20 +70,18 @@ static DBusHandlerResult agent_filter(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

-static DBusHandlerResult request_message(DBusConnection *conn,
+static DBusHandlerResult request_pincode_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
- dbus_bool_t numeric;
+ const char *path;

if (!passkey)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_BOOLEAN, &numeric, DBUS_TYPE_INVALID)) {
- fprintf(stderr, "Invalid arguments for passkey Request method");
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPinCode method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

@@ -99,7 +97,7 @@ static DBusHandlerResult request_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}

- printf("Passkey request for device %s\n", address);
+ printf("Pincode request for device %s\n", path);

dbus_message_append_args(reply, DBUS_TYPE_STRING, &passkey,
DBUS_TYPE_INVALID);
@@ -114,20 +112,63 @@ send:
return DBUS_HANDLER_RESULT_HANDLED;
}

-static DBusHandlerResult cancel_message(DBusConnection *conn,
+static DBusHandlerResult request_passkey_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
- const char *path, *address;
+ const char *path;
+ unsigned int int_passkey;
+
+ if (!passkey)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+

if (!dbus_message_get_args(msg, NULL,
- DBUS_TYPE_STRING, &path, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID)) {
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for RequestPasskey method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Passkey request for device %s\n", path);
+
+ int_passkey = strtoul(passkey, NULL, 10);
+
+ dbus_message_append_args(reply, DBUS_TYPE_UINT32, &int_passkey,
+ DBUS_TYPE_INVALID);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult cancel_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) {
fprintf(stderr, "Invalid arguments for passkey Confirm method");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

- printf("Request canceled for device %s\n", address);
+ printf("Request canceled\n");

reply = dbus_message_new_method_return(msg);
if (!reply) {
@@ -174,11 +215,50 @@ static DBusHandlerResult release_message(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}

+static DBusHandlerResult authorize_message(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ DBusMessage *reply;
+ const char *path, *uuid;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID)) {
+ fprintf(stderr, "Invalid arguments for Authorize method");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (do_reject) {
+ reply = dbus_message_new_error(msg,
+ "org.bluez.Error.Rejected", "");
+ goto send;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply) {
+ fprintf(stderr, "Can't create reply message\n");
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ }
+
+ printf("Authorizing request for %s\n", path);
+
+send:
+ dbus_connection_send(conn, reply, NULL);
+
+ dbus_connection_flush(conn);
+
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult agent_message(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Request"))
- return request_message(conn, msg, data);
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPinCode"))
+ return request_pincode_message(conn, msg, data);
+
+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "RequestPasskey"))
+ return request_passkey_message(conn, msg, data);

if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Cancel"))
return cancel_message(conn, msg, data);
@@ -186,6 +266,9 @@ static DBusHandlerResult agent_message(DBusConnection *conn,
if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Release"))
return release_message(conn, msg, data);

+ if (dbus_message_is_method_call(msg, "org.bluez.Agent", "Authorize"))
+ return authorize_message(conn, msg, data);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

--
1.6.3.1


2009-06-28 18:27:39

by Filippo Giunchedi

[permalink] [raw]
Subject: [PATCH 4/4] test/agent.c: pairing via CreatePairedDevice

Introduce mandatory target argument for remote address
---
test/agent.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/test/agent.c b/test/agent.c
index 30af926..7f7bfe4 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -276,6 +276,39 @@ static const DBusObjectPathVTable agent_table = {
.message_function = agent_message,
};

+static int create_paired_device(DBusConnection *conn, const char *device_path,
+ const char *agent_path,
+ const char *capabilities, const char *target)
+{
+ dbus_bool_t success;
+ DBusMessage *msg;
+
+ msg = dbus_message_new_method_call("org.bluez", device_path,
+ "org.bluez.Adapter", "CreatePairedDevice");
+ if (!msg) {
+ fprintf(stderr, "Can't allocate new method call\n");
+ return -1;
+ }
+
+ dbus_message_append_args(msg, DBUS_TYPE_STRING, &target,
+ DBUS_TYPE_OBJECT_PATH, &agent_path,
+ DBUS_TYPE_STRING, &capabilities,
+ DBUS_TYPE_INVALID);
+
+ success = dbus_connection_send(conn, msg, NULL);
+
+ dbus_message_unref(msg);
+
+ if (!success) {
+ fprintf(stderr, "Not enough memory for message send\n");
+ return -1;
+ }
+
+ dbus_connection_flush(conn);
+
+ return 0;
+}
+
static char *get_device(const char *device)
{
char *path;
@@ -290,7 +323,7 @@ static void usage(void)
printf("Bluetooth agent ver %s\n\n", VERSION);

printf("Usage:\n"
- "\tagent [--device interface] [--path agent-path] <passkey>\n"
+ "\tagent [--device interface] [--path agent-path] <passkey> <target_device>\n"
"\n");
}

@@ -309,7 +342,7 @@ int main(int argc, char *argv[])
struct sigaction sa;
DBusConnection *conn;
char match_string[128], default_path[128], *device_id = NULL;
- char *device_path = NULL, *agent_path = NULL;
+ char *device_path = NULL, *agent_path = NULL, *target = NULL;
int opt;

snprintf(default_path, sizeof(default_path),
@@ -345,13 +378,15 @@ int main(int argc, char *argv[])
argv += optind;
optind = 0;

- if (argc < 1) {
+ if (argc < 2) {
usage();
exit(1);
}

passkey = strdup(argv[0]);

+ target = strdup(argv[1]);
+
if (!agent_path)
agent_path = strdup(default_path);

@@ -370,6 +405,11 @@ int main(int argc, char *argv[])
return -1;
}

+ if (create_paired_device(conn, device_path, agent_path, capabilities, target) < 0) {
+ dbus_connection_unref(conn);
+ exit(1);
+ }
+
if (!dbus_connection_add_filter(conn, agent_filter, NULL, NULL))
fprintf(stderr, "Can't add signal filter");

--
1.6.3.1