diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2012-10-09 19:38:07 +0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-10-09 19:38:10 +0200 |
commit | 7dae3e94c9e0349a2d4508a0013655d6cbb78f36 (patch) | |
tree | b052e63371274b33dd819e9abf5595ec46d48d82 /src | |
parent | e90b16a04d6f23742fcad105cb29cf75218d617d (diff) |
core: Add initial Device.Pair() implementation
This will ultimately replace Adapter.CreatePairedDevice()
Diffstat (limited to 'src')
-rw-r--r-- | src/device.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c index 71bfea56..d85d41cd 100644 --- a/src/device.c +++ b/src/device.c @@ -66,6 +66,13 @@ #include "attrib-server.h" #include "attrib/client.h" +#define IO_CAPABILITY_DISPLAYONLY 0x00 +#define IO_CAPABILITY_DISPLAYYESNO 0x01 +#define IO_CAPABILITY_KEYBOARDONLY 0x02 +#define IO_CAPABILITY_NOINPUTNOOUTPUT 0x03 +#define IO_CAPABILITY_KEYBOARDDISPLAY 0x04 +#define IO_CAPABILITY_INVALID 0xFF + #define DISCONNECT_TIMER 2 #define DISCOVERY_TIMER 2 @@ -1187,6 +1194,43 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg, return NULL; } +static uint8_t parse_io_capability(const char *capability) +{ + if (g_str_equal(capability, "")) + return IO_CAPABILITY_DISPLAYYESNO; + if (g_str_equal(capability, "DisplayOnly")) + return IO_CAPABILITY_DISPLAYONLY; + if (g_str_equal(capability, "DisplayYesNo")) + return IO_CAPABILITY_DISPLAYYESNO; + if (g_str_equal(capability, "KeyboardOnly")) + return IO_CAPABILITY_KEYBOARDONLY; + if (g_str_equal(capability, "NoInputNoOutput")) + return IO_CAPABILITY_NOINPUTNOOUTPUT; + if (g_str_equal(capability, "KeyboardDisplay")) + return IO_CAPABILITY_KEYBOARDDISPLAY; + return IO_CAPABILITY_INVALID; +} + +static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg, + void *data) +{ + struct btd_device *device = data; + const char *agent_path, *capability; + uint8_t io_cap; + + if (!dbus_message_get_args(msg, NULL, + DBUS_TYPE_OBJECT_PATH, &agent_path, + DBUS_TYPE_STRING, &capability, + DBUS_TYPE_INVALID)) + return btd_error_invalid_args(msg); + + io_cap = parse_io_capability(capability); + if (io_cap == IO_CAPABILITY_INVALID) + return btd_error_invalid_args(msg); + + return device_create_bonding(device, msg, agent_path, io_cap); +} + static const GDBusMethodTable device_methods[] = { { GDBUS_ASYNC_METHOD("DiscoverServices", GDBUS_ARGS({ "pattern", "s" }), @@ -1195,6 +1239,9 @@ static const GDBusMethodTable device_methods[] = { { GDBUS_METHOD("CancelDiscovery", NULL, NULL, cancel_discover) }, { GDBUS_ASYNC_METHOD("Disconnect", NULL, NULL, disconnect) }, { GDBUS_ASYNC_METHOD("Connect", NULL, NULL, dev_connect) }, + { GDBUS_ASYNC_METHOD("Pair", + GDBUS_ARGS({ "agent", "o" }, { "capability", "s" }), + NULL, pair_device) }, { } }; |