diff options
author | Szymon Janc <szymon.janc@tieto.com> | 2012-10-31 12:22:14 +0100 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-11-14 11:34:53 +0100 |
commit | 50118e6f2267e5926fdb28897ffc751d496ec5b4 (patch) | |
tree | f0f96976ad9cf48bc763ff28fdd504c5e9fbe7cf | |
parent | c76d6daf2af18253bf4955997c60267bb4349c43 (diff) | |
download | neard-50118e6f2267e5926fdb28897ffc751d496ec5b4.tar.gz neard-50118e6f2267e5926fdb28897ffc751d496ec5b4.tar.bz2 neard-50118e6f2267e5926fdb28897ffc751d496ec5b4.zip |
agent: Add __near_agent_handover_push_data function
-rw-r--r-- | include/dbus.h | 17 | ||||
-rw-r--r-- | src/agent.c | 68 | ||||
-rw-r--r-- | src/near.h | 8 |
3 files changed, 85 insertions, 8 deletions
diff --git a/include/dbus.h b/include/dbus.h index e5c74af..245152a 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -24,16 +24,17 @@ #define NFC_SERVICE "org.neard" #define NFC_PATH "/org/neard" -#define NFC_ERROR_INTERFACE NFC_SERVICE ".Error" -#define NFC_NDEF_AGENT_INTERFACE NFC_SERVICE ".NDEFAgent" +#define NFC_ERROR_INTERFACE NFC_SERVICE ".Error" +#define NFC_NDEF_AGENT_INTERFACE NFC_SERVICE ".NDEFAgent" +#define NFC_HANDOVER_AGENT_INTERFACE NFC_SERVICE ".HandoverAgent" -#define NFC_MANAGER_INTERFACE NFC_SERVICE ".Manager" -#define NFC_MANAGER_PATH "/" +#define NFC_MANAGER_INTERFACE NFC_SERVICE ".Manager" +#define NFC_MANAGER_PATH "/" -#define NFC_ADAPTER_INTERFACE NFC_SERVICE ".Adapter" -#define NFC_DEVICE_INTERFACE NFC_SERVICE ".Device" -#define NFC_TAG_INTERFACE NFC_SERVICE ".Tag" -#define NFC_RECORD_INTERFACE NFC_SERVICE ".Record" +#define NFC_ADAPTER_INTERFACE NFC_SERVICE ".Adapter" +#define NFC_DEVICE_INTERFACE NFC_SERVICE ".Device" +#define NFC_TAG_INTERFACE NFC_SERVICE ".Tag" +#define NFC_RECORD_INTERFACE NFC_SERVICE ".Record" typedef void (* near_dbus_append_cb_t) (DBusMessageIter *iter, void *user_data); diff --git a/src/agent.c b/src/agent.c index 0f99d1b..42acb93 100644 --- a/src/agent.c +++ b/src/agent.c @@ -222,6 +222,74 @@ static guint handover_agent_watch = 0; static gchar *handover_agent_path = NULL; static gchar *handover_agent_sender = NULL; +static void prepare_bt_data(DBusMessage *message, struct bt_data *data) +{ + DBusMessageIter iter; + DBusMessageIter dict; + char *name; + + DBG("data %p", data); + + dbus_message_iter_init_append(message, &iter); + + near_dbus_dict_open(&iter, &dict); + + if (data != NULL) { + void *pdata = data->data; + + if (data->type == BT_MIME_V2_1) + name = "EIR"; + else + name = "nokia.com:bt"; + + near_dbus_dict_append_fixed_array(&dict, name, DBUS_TYPE_BYTE, + &pdata, data->size); + } + + near_dbus_dict_close(&iter, &dict); +} + +int __near_agent_handover_push_data(struct bt_data *data) +{ + DBusMessage *message; + DBusMessage *reply; + DBusError error; + + DBG("agent %s", handover_agent_path ? : "not present"); + + if (handover_agent_path == NULL) + return -ESRCH; + + message = dbus_message_new_method_call(handover_agent_sender, + handover_agent_path, NFC_HANDOVER_AGENT_INTERFACE, + "PushOOB"); + if (message == NULL) + return -ENOMEM; + + prepare_bt_data(message, data); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + DBUS_TIMEOUT_USE_DEFAULT, &error); + + dbus_message_unref(message); + + if (reply != NULL) { + dbus_message_unref(reply); + return 0; + } + + if (dbus_error_is_set(&error) == TRUE) { + near_error("PushOOB failed: %s", error.message); + dbus_error_free(&error); + } else { + near_error("PushOOB failed"); + } + + return -EIO; +} + static void handover_agent_free(void) { if (handover_agent_watch > 0) { @@ -178,6 +178,12 @@ void __near_plugin_cleanup(void); #define OOB_PROPS_COD 0x08 #define OOB_PROPS_SP (OOB_PROPS_SP_HASH | OOB_PROPS_SP_RANDOM) +struct bt_data { + uint8_t type; + uint8_t size; + uint8_t data[UINT8_MAX]; +}; + int __near_bluetooth_init(void); void __near_bluetooth_cleanup(void); int __near_bluetooth_parse_oob_record(uint8_t version, uint8_t *bt_data, @@ -194,5 +200,7 @@ int __near_agent_ndef_unregister(const char *sender, const char *path, int __near_agent_handover_register(const char *sender, const char *path); int __near_agent_handover_unregister(const char *sender, const char *path); +int __near_agent_handover_push_data(struct bt_data *data); + int __near_agent_init(void); void __near_agent_cleanup(void); |