diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-10-20 14:19:17 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-10-20 14:19:17 +0000 |
commit | db048bd6bb5a4f71c3362430a29b963e0b25247c (patch) | |
tree | 49904e2b935d10e521a5b43c83baa08365d20b37 /hcid | |
parent | 8f0584a2042946f1bbe41b48a57c3a824ffd443b (diff) |
Update D-Bus API and example passkey agent
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-api.txt | 20 | ||||
-rw-r--r-- | hcid/passkey-agent.c | 55 |
2 files changed, 62 insertions, 13 deletions
diff --git a/hcid/dbus-api.txt b/hcid/dbus-api.txt index 2656a838..96d43ef9 100644 --- a/hcid/dbus-api.txt +++ b/hcid/dbus-api.txt @@ -954,21 +954,35 @@ Service unique name Interface org.bluez.PasskeyAgent Object path freely definable -Methods string Request(string path, string address) +Methods string Request(string path, string address, boolean numeric) This method gets called when the service daemon needs to get the passkey for an authentication. The return value is actual passkey. The first argument contains the path of the local - adapter and the second one the remote address. + adapter and the second one the remote address. The + third argument signals if a numeric PIN code is + expected or not. The default is a 1 to 16 byte PIN + code in UTF-8 format. + + Possible errors: org.bluez.Error.Rejected + org.bluez.Error.Canceled + + boolean Confirm(string path, string address, string value) + + This method gets called when the service daemon + needs to verify a passkey. The verification is + done by showing the value to the passkey agent + and returnin true means a successful confirmation + while false means that the values don't match. Possible errors: org.bluez.Error.Rejected org.bluez.Error.Canceled void Cancel(string path, string address) - This method is called to indicate that the + This method gets called to indicate that the authentication request failed before a reply was returned by the Request method. diff --git a/hcid/passkey-agent.c b/hcid/passkey-agent.c index e47afe6b..79147ee2 100644 --- a/hcid/passkey-agent.c +++ b/hcid/passkey-agent.c @@ -76,12 +76,14 @@ static DBusHandlerResult request_message(DBusConnection *conn, { DBusMessage *reply; const char *path, *address; + dbus_bool_t numeric; 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)) { + 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"); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -104,29 +106,56 @@ static DBusHandlerResult request_message(DBusConnection *conn, return DBUS_HANDLER_RESULT_HANDLED; } -static DBusHandlerResult release_message(DBusConnection *conn, +static DBusHandlerResult confirm_message(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; + const char *path, *address, *value; + dbus_bool_t result; - if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) { - fprintf(stderr, "Invalid arguments for passkey Release method"); + 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_STRING, &value, DBUS_TYPE_INVALID)) { + fprintf(stderr, "Invalid arguments for passkey Confirm method"); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } + result = strcmp(value, passkey) == 0 ? TRUE : FALSE; + reply = dbus_message_new_method_return(msg); if (!reply) { fprintf(stderr, "Can't create reply message\n"); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - dbus_message_append_args(reply, DBUS_TYPE_INVALID); + dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &result, + DBUS_TYPE_INVALID); 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) +{ + return DBUS_HANDLER_RESULT_HANDLED; +} + +static DBusHandlerResult release_message(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID)) { + fprintf(stderr, "Invalid arguments for passkey Release method"); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } if (!__io_canceled) fprintf(stderr, "Passkey service has been released\n"); @@ -142,6 +171,12 @@ static DBusHandlerResult agent_message(DBusConnection *conn, if (dbus_message_is_method_call(msg, "org.bluez.PasskeyAgent", "Request")) return request_message(conn, msg, data); + if (dbus_message_is_method_call(msg, "org.bluez.PasskeyAgent", "Confirm")) + return confirm_message(conn, msg, data); + + if (dbus_message_is_method_call(msg, "org.bluez.PasskeyAgent", "Cancel")) + return cancel_message(conn, msg, data); + if (dbus_message_is_method_call(msg, "org.bluez.PasskeyAgent", "Release")) return release_message(conn, msg, data); @@ -226,7 +261,7 @@ static int unregister_agent(DBusConnection *conn, const char *agent_path, msg = dbus_message_new_method_call("org.bluez", path, INTERFACE, method); if (!msg) { fprintf(stderr, "Can't allocate new method call\n"); - dbus_connection_close(conn); + dbus_connection_unref(conn); exit(1); } @@ -334,7 +369,7 @@ int main(int argc, char *argv[]) } if (register_agent(conn, agent_path, address, use_default) < 0) { - dbus_connection_close(conn); + dbus_connection_unref(conn); exit(1); } @@ -354,7 +389,7 @@ int main(int argc, char *argv[]) sigaction(SIGINT, &sa, NULL); while (!__io_canceled && !__io_terminated) { - if (dbus_connection_read_write_dispatch(conn, 100) != TRUE) + if (dbus_connection_read_write_dispatch(conn, 500) != TRUE) break; } @@ -364,7 +399,7 @@ int main(int argc, char *argv[]) if (passkey) free(passkey); - dbus_connection_close(conn); + dbus_connection_unref(conn); return 0; } |