summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArron Wang <arron.wang@intel.com>2013-07-01 09:11:03 +0800
committerArron Wang <arron.wang@intel.com>2013-07-02 14:56:35 +0800
commit27535c95325503cb5cca98bac040084b3178ceea (patch)
treea21fdde23afb4b8f94f65645ac518b431f23afca
parente513987d4b81ba1d5df296b80d3a0759f2c9920b (diff)
downloadnfc-manager-neard-27535c95325503cb5cca98bac040084b3178ceea.tar.gz
nfc-manager-neard-27535c95325503cb5cca98bac040084b3178ceea.tar.bz2
nfc-manager-neard-27535c95325503cb5cca98bac040084b3178ceea.zip
Add P2P send support
Change-Id: Ibad62629b7631f2ab315580fc713e902d75b47e1
-rw-r--r--src/clientlib/include/net_nfc_neard.h1
-rwxr-xr-xsrc/clientlib/net_nfc_client_exchanger.c30
-rw-r--r--src/clientlib/net_nfc_neard.c55
3 files changed, 68 insertions, 18 deletions
diff --git a/src/clientlib/include/net_nfc_neard.h b/src/clientlib/include/net_nfc_neard.h
index c4cb6c4..747285e 100644
--- a/src/clientlib/include/net_nfc_neard.h
+++ b/src/clientlib/include/net_nfc_neard.h
@@ -6,6 +6,7 @@
net_nfc_error_e net_nfc_neard_read_tag(net_nfc_target_handle_s *handle, void *trans_param);
net_nfc_error_e net_nfc_neard_write_ndef(net_nfc_target_handle_s *handle, data_s *data, void *trans_param);
+net_nfc_error_e net_nfc_neard_send_p2p(net_nfc_target_handle_s *handle, data_s *data, void *trans_param);
net_nfc_error_e net_nfc_neard_register_cb(net_nfc_response_cb cb);
net_nfc_error_e net_nfc_neard_unregister_cb(void);
net_nfc_error_e net_nfc_neard_is_tag_connected(int *dev_type);
diff --git a/src/clientlib/net_nfc_client_exchanger.c b/src/clientlib/net_nfc_client_exchanger.c
index 2ea0faa..63fe304 100755
--- a/src/clientlib/net_nfc_client_exchanger.c
+++ b/src/clientlib/net_nfc_client_exchanger.c
@@ -25,6 +25,7 @@
#include "net_nfc_debug_private.h"
#include "net_nfc_client_ipc_private.h"
#include "net_nfc_client_nfc_private.h"
+#include "net_nfc_neard.h"
static net_nfc_exchanger_cb exchanger_cb = NULL;
@@ -112,32 +113,25 @@ NET_NFC_EXPORT_API net_nfc_error_e net_nfc_unset_exchanger_cb()
NET_NFC_EXPORT_API net_nfc_error_e net_nfc_send_exchanger_data(net_nfc_exchanger_data_h ex_handle, net_nfc_target_handle_h target_handle, void* trans_param)
{
net_nfc_error_e ret;
- net_nfc_request_p2p_send_t *request = NULL;
- uint32_t length = 0;
- net_nfc_exchanger_data_s *ex_data = (net_nfc_exchanger_data_s *)ex_handle;
+ data_s exchanger_data = {NULL, 0};
DEBUG_CLIENT_MSG("send reqeust :: exchanger data = [%p] target_handle = [%p]", ex_handle, target_handle);
- length = sizeof(net_nfc_request_p2p_send_t) + ex_data->binary_data.length;
-
- _net_nfc_util_alloc_mem(request, length);
- if (request == NULL)
- {
+ _net_nfc_util_alloc_mem(exchanger_data.buffer,
+ ex_handle->binary_data.length);
+ if (exchanger_data.buffer == NULL)
return NET_NFC_ALLOC_FAIL;
- }
- request->length = length;
- request->request_type = NET_NFC_MESSAGE_P2P_SEND;
- request->handle = (net_nfc_target_handle_s *)target_handle;
- request->data_type = ex_data->type;
- request->data.length = ex_data->binary_data.length;
- request->user_param = (uint32_t)trans_param;
+ exchanger_data.length = ex_handle->binary_data.length;
- memcpy(&request->data.buffer, ex_data->binary_data.buffer, request->data.length);
+ memcpy(exchanger_data.buffer, ex_handle->binary_data.buffer,
+ exchanger_data.length);
- ret = net_nfc_client_send_request((net_nfc_request_msg_t *)request, NULL);
+ ret = net_nfc_neard_send_p2p(target_handle, &exchanger_data,
+ trans_param);
- _net_nfc_util_free_mem(request);
+ DEBUG_CLIENT_MSG("send result = [%d]", ret);
+ _net_nfc_util_free_mem(exchanger_data.buffer);
return ret;
}
diff --git a/src/clientlib/net_nfc_neard.c b/src/clientlib/net_nfc_neard.c
index 40b0438..366d953 100644
--- a/src/clientlib/net_nfc_neard.c
+++ b/src/clientlib/net_nfc_neard.c
@@ -500,6 +500,19 @@ exit:
client_context->register_user_param, NULL);
}
+static void _p2p_send_completed_cb(errorCode_t error_code, void *user_data)
+{
+ net_nfc_error_e result;
+
+ DEBUG_CLIENT_MSG("p2p send completed cb error code %d", error_code);
+
+ result = _convert_error_code(error_code);
+
+ if (client_cb != NULL)
+ client_cb(NET_NFC_MESSAGE_P2P_SEND, result, NULL,
+ client_context->register_user_param, NULL);
+}
+
net_nfc_error_e net_nfc_neard_read_tag(net_nfc_target_handle_s *handle,
void *trans_param)
{
@@ -560,6 +573,46 @@ net_nfc_error_e net_nfc_neard_write_ndef(net_nfc_target_handle_s *handle,
return NET_NFC_OK;
}
+net_nfc_error_e net_nfc_neard_send_p2p(net_nfc_target_handle_s *handle, data_s *data, void *trans_param)
+{
+ neardal_record *record;
+
+ DEBUG_CLIENT_MSG("neard send p2p");
+
+ if (target_handle == NULL || handle != target_handle)
+ return NET_NFC_TARGET_IS_MOVED_AWAY;
+
+ if ((data->buffer == NULL && data->length != 0) ||
+ (data->buffer != NULL && data->length == 0))
+ return NET_NFC_NULL_PARAMETER;
+
+ record = g_try_malloc0(sizeof(neardal_record));
+ if (record == NULL)
+ return NET_NFC_ALLOC_FAIL;
+
+ record->name = g_strdup(dev->name);
+ record->type = g_strdup("Raw");
+ record->rawNDEF = g_try_malloc0(data->length);
+ if (record->rawNDEF == NULL) {
+ neardal_free_record(record);
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ memcpy(record->rawNDEF, data->buffer, data->length);
+ record->rawNDEFSize = data->length;
+
+ if (neardal_dev_push(record) != NEARDAL_SUCCESS) {
+ neardal_free_record(record);
+ return NET_NFC_TAG_WRITE_FAILED;
+ }
+
+ neardal_free_record(record);
+
+ DEBUG_CLIENT_MSG("neard send p2p successfully");
+ callback_data = trans_param;
+ return NET_NFC_OK;
+}
+
net_nfc_error_e net_nfc_neard_is_tag_connected(int *dev_type)
{
if (tag == NULL)
@@ -609,6 +662,8 @@ net_nfc_error_e net_nfc_neard_cb_init(void)
neardal_set_cb_dev_found(_device_found_cb, NULL)
!= NEARDAL_SUCCESS ||
neardal_set_cb_dev_lost(_device_lost_cb, NULL)
+ != NEARDAL_SUCCESS ||
+ neardal_set_cb_push_completed(_p2p_send_completed_cb, NULL)
!= NEARDAL_SUCCESS) {
DEBUG_CLIENT_MSG("failed to register the callback");