--- /dev/null
+/*
+ * Copyright (c) 2012, Intel Corportation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <time.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <syslog.h>
+#include <glib.h>
+
+#include "net_nfc_oem_controller.h"
+#include "net_nfc_typedef.h"
+#include "net_nfc_util_private.h"
+#include "net_nfc_util_ndef_message.h"
+#include "net_nfc_util_ndef_record.h"
+
+#include "neardal.h"
+
+#ifndef NET_NFC_EXPORT_API
+#define NET_NFC_EXPORT_API __attribute__((visibility("default")))
+#endif
+
+/* TODO get real data */
+#define NET_NFC_JEWEL_PICC_MAX_SIZE 116
+#define NET_NFC_MIFARE_ULTRA_PICC_MAX_SIZE 48
+#define NET_NFC_FELICA_PICC_MAX_SIZE 256
+#define NET_NFC_MIFARE_DESFIRE_PICC_MAX_SIZE 2048
+
+/*************************** INTERFACE CALLBACKS *****************************/
+static target_detection_listener_cb interface_target_detection_cb;
+static se_transaction_listener_cb interface_se_transaction_cb;
+static llcp_event_listener_cb interface_llcp_event_cb;
+
+/*************************** INTERFACE START *********************************/
+static bool neard_plugin_init(net_nfc_error_e* result);
+static bool neard_plugin_deinit(void);
+static bool neard_plugin_register_listener(
+ target_detection_listener_cb target_detection_listener,
+ se_transaction_listener_cb se_transaction_listener,
+ llcp_event_listener_cb llcp_event_listener,
+ net_nfc_error_e* result);
+static bool neard_plugin_unregister_listener();
+static bool neard_plugin_check_firmware_version(net_nfc_error_e* result);
+static bool neard_plugin_update_firmware(net_nfc_error_e* result);
+static bool neard_plugin_get_stack_information(
+ net_nfc_stack_information_s* stack_info,
+ net_nfc_error_e* result);
+static bool neard_plugin_configure_discovery(
+ net_nfc_discovery_mode_e mode,
+ net_nfc_event_filter_e config,
+ net_nfc_error_e* result);
+static bool neard_plugin_get_secure_element_list(
+ net_nfc_secure_element_info_s* list,
+ int* count, net_nfc_error_e* result);
+static bool neard_plugin_set_secure_element_mode(
+ net_nfc_secure_element_type_e element_type,
+ net_nfc_secure_element_mode_e mode,
+ net_nfc_error_e* result);
+static bool neard_plugin_connect(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result);
+static bool neard_plugin_disconnect(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result);
+static bool neard_plugin_check_ndef(net_nfc_target_handle_s* handle,
+ uint8_t *ndef_card_state,
+ int* max_data_size,
+ int* real_data_size,
+ net_nfc_error_e* result);
+static bool neard_plugin_check_target_presence(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result);
+static bool neard_plugin_read_ndef(net_nfc_target_handle_s* handle,
+ data_s** data,
+ net_nfc_error_e* result);
+static bool neard_plugin_write_ndef(net_nfc_target_handle_s* handle,
+ data_s* data, net_nfc_error_e* result);
+static bool neard_plugin_make_read_only_ndef(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result);
+static bool neard_plugin_transceive(net_nfc_target_handle_s* handle,
+ net_nfc_transceive_info_s* info,
+ data_s** data,
+ net_nfc_error_e* result);
+static bool neard_plugin_format_ndef(net_nfc_target_handle_s* handle,
+ data_s* secure_key,
+ net_nfc_error_e* result);
+static bool neard_plugin_exception_handler(void);
+static bool neard_plugin_is_ready(net_nfc_error_e* error);
+
+static bool neard_plugin_llcp_config(net_nfc_llcp_config_info_s *config,
+ net_nfc_error_e *result);
+static bool neard_plugin_llcp_check_llcp(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result);
+static bool neard_plugin_llcp_activate_llcp(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result);
+static bool neard_plugin_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_socket_type_e socketType,
+ uint16_t miu, uint8_t rw,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_bind(net_nfc_llcp_socket_t socket,
+ uint8_t service_access_point,
+ net_nfc_error_e* result);
+static bool neard_plugin_llcp_listen(net_nfc_target_handle_s* handle,
+ uint8_t* service_access_name,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_accept(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result);
+static bool neard_plugin_llcp_connect_by_url(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ uint8_t* service_access_name,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_connect(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ uint8_t service_access_point,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_reject(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result);
+static bool neard_plugin_llcp_disconnect(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_socket_close(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result);
+static bool neard_plugin_llcp_recv(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s* data, net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_send(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s* data, net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_recv_from(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s * data,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_send_to(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s* data,
+ uint8_t service_access_point,
+ net_nfc_error_e* result,
+ void * user_param);
+static bool neard_plugin_llcp_get_remote_config(
+ net_nfc_target_handle_s* handle,
+ net_nfc_llcp_config_info_s *config,
+ net_nfc_error_e* result);
+static bool neard_plugin_llcp_get_remote_socket_info(
+ net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_option_s * option,
+ net_nfc_error_e* result);
+
+/*************************** INTERFACE END ***********************************/
+
+static char *neard_adp_path = NULL;
+static bool neard_adp_powered = false;
+static bool neard_adp_polling = false;
+static net_nfc_target_handle_s *current_handle = NULL;
+static neardal_tag *tag = NULL;
+
+/* neard plugin logging functions */
+static void neard_plugin_log_open(const char *name)
+{
+ openlog(name, LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER);
+}
+
+static void neard_plugin_log_close(void)
+{
+ closelog();
+}
+
+static void neard_plugin_debug(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ vsyslog(LOG_DEBUG, format, ap);
+ va_end(ap);
+}
+
+#define DBG(fmt, arg...) neard_plugin_debug("%d:%s() " fmt, __LINE__, __FUNCTION__, ## arg)
+
+/* Target handle related functions */
+static bool __neard_plugin_is_valid_target_handle(
+ net_nfc_target_handle_s *handle)
+{
+ return (current_handle == handle);
+}
+
+static void __neard_plugin_make_valid_target_handle(
+ net_nfc_target_handle_s **handle)
+{
+ if (current_handle != NULL); /* already allocated */
+
+ *handle = g_try_malloc0(sizeof(net_nfc_target_handle_s));
+ if (*handle != NULL)
+ current_handle = *handle;
+}
+
+static void __neard_plugin_make_invalid_target_handle(
+ net_nfc_target_handle_s* handle)
+
+{
+ if (current_handle != NULL) {
+ g_free(current_handle);
+ current_handle = NULL;
+ }
+
+ handle = NULL;
+}
+
+/* neard plugin helper funtions */
+static int __neard_plugin_convert_target_type(const char *type)
+{
+ int t_type;
+
+ DBG("");
+
+ /* TODO tag sub types */
+
+ if (type == NULL)
+ return NET_NFC_UNKNOWN_TARGET;
+
+ if (!g_strcmp0(type, "Type 1"))
+ t_type = NET_NFC_JEWEL_PICC;
+ else if (!g_strcmp0(type, "Type 2"))
+ t_type = NET_NFC_MIFARE_ULTRA_PICC;
+ /*
+ NET_NFC_MIFARE_MINI_PICC
+ NET_NFC_MIFARE_1K_PICC
+ NET_NFC_MIFARE_4K_PICC
+ NET_NFC_MIFARE_ULTRA_PICC
+ */
+ else if (!g_strcmp0(type, "Type 3"))
+ t_type = NET_NFC_FELICA_PICC;
+ else if (!g_strcmp0(type, "Type 4"))
+ t_type = NET_NFC_MIFARE_DESFIRE_PICC;
+ else if (!g_strcmp0(type, "Target"))
+ t_type = NET_NFC_NFCIP1_TARGET;
+ else if (!g_strcmp0(type, "Initiator"))
+ t_type = NET_NFC_NFCIP1_INITIATOR;
+ else
+ t_type = NET_NFC_UNKNOWN_TARGET;
+
+ return t_type;
+}
+
+static uint32_t __neard_plugin_get_tag_id(const char *name)
+{
+ uint32_t id;
+ char **s;
+
+ s = g_strsplit(name, "tag", 2);
+ id = atoi(s[1]);
+ g_strfreev(s);
+
+ return id;
+}
+
+/* neardal callbaks */
+static void __neardal_adp_added_cb(const char *adpName, void *user_data)
+{
+ DBG("");
+
+ if (neard_adp_path) {
+ g_free(neard_adp_path);
+ neard_adp_path = NULL;
+ }
+
+ if (adpName != NULL)
+ neard_adp_path = g_strdup(adpName);
+}
+
+static void __neardal_adp_removed_cb(const char *adpName, void *user_data)
+{
+ DBG("");
+
+ if (neard_adp_path) {
+ g_free(neard_adp_path);
+ neard_adp_path = NULL;
+ }
+}
+
+static void __neardal_adp_prop_changed_cb(char *adpName, char *propName,
+ void *value, void *user_data)
+{
+ DBG(" %s", propName);
+
+ if (!g_strcmp0(propName, "Polling")) {
+ if ((int*) value == 0) {
+ neard_adp_polling = false;
+ DBG(" polling stopped ");
+ } else {
+ neard_adp_polling = true;
+ DBG(" polling started ");
+ }
+ }
+}
+
+static void __neardal_tag_found_cb(const char *tagName, void *user_data)
+{
+ DBG("");
+
+ net_nfc_target_handle_s *handle = NULL;
+ net_nfc_request_target_detected_t *tag_detected = NULL;
+
+ if (neardal_get_tag_properties(tagName, &tag) != NEARDAL_SUCCESS)
+ return;
+
+ __neard_plugin_make_valid_target_handle(&handle);
+ if (handle == NULL)
+ goto out_err;
+
+ handle->connection_id = __neard_plugin_get_tag_id(tagName);
+ handle->connection_type = NET_NFC_TAG_CONNECTION;
+
+ tag_detected = g_try_malloc0(sizeof(net_nfc_request_target_detected_t));
+ if (tag_detected == NULL)
+ goto out_err;
+
+ tag_detected->length = sizeof(net_nfc_request_target_detected_t);
+ tag_detected->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED;
+ tag_detected->devType = __neard_plugin_convert_target_type(tag->type);
+ tag_detected->number_of_keys = 0;
+ tag_detected->handle = handle;
+ tag_detected->target_info_values.length = 0;
+
+ if (interface_target_detection_cb != NULL)
+ interface_target_detection_cb(tag_detected, NULL);
+
+ return;
+
+out_err:
+ g_free(tag_detected);
+}
+
+static void __neardal_tag_lost_cb(const char *tagName, void *userdata)
+{
+ DBG("");
+
+ if (tag != NULL) {
+ neardal_free_tag(tag);
+ tag = NULL;
+ }
+
+ if (neard_adp_polling == true)
+ return;
+
+ if (neardal_start_poll_loop(neard_adp_path,
+ NEARD_ADP_MODE_DUAL) == NEARDAL_SUCCESS)
+ neard_adp_polling = true;
+
+}
+
+static void __neardal_record_found_cb(const char *rcdName, void *user_data)
+{
+
+}
+
+static errorCode_t __neardal_init(void)
+{
+ errorCode_t err;
+ neardal_adapter *neard_adp = NULL;
+ char **adapters = NULL;
+ int len, powered;
+
+ DBG("");
+
+ /* Get neard adapters */
+ err = neardal_get_adapters(&adapters, &len);
+ if (err != NEARDAL_SUCCESS)
+ goto out_err;
+
+ if (!(len > 0 && adapters != NULL))
+ goto out_err;
+
+ /* Cache the current/default adapter path */
+ neard_adp_path = g_strdup(adapters[0]);
+ neardal_free_array(&adapters);
+ adapters = NULL;
+
+ /* Get adapters properties */
+ err = neardal_get_adapter_properties(neard_adp_path, &neard_adp);
+ if (err != NEARDAL_SUCCESS)
+ goto out_err;
+
+ if (neard_adp == NULL) {
+ err = NEARDAL_ERROR_DBUS;
+ goto out_err;
+ }
+
+ neard_adp_powered = (neard_adp->powered) ? true : false;
+ neard_adp_polling = (neard_adp->polling) ? true : false;
+ neardal_free_adapter(neard_adp);
+ neard_adp = NULL;
+
+ /* If adpater is not powered on then power it on */
+ if (neard_adp_powered == false) {
+ powered = 1;
+ err = neardal_set_adapter_property(neard_adp_path,
+ NEARD_ADP_PROP_POWERED, (void*) powered);
+ if (err != NEARDAL_SUCCESS)
+ goto out_err;
+
+ neard_adp_powered = true;
+ }
+
+ if (neard_adp_polling == false) {
+ err = neardal_start_poll_loop(neard_adp_path,
+ NEARD_ADP_MODE_DUAL);
+ if (err != NEARDAL_SUCCESS)
+ goto out_err;
+
+ neard_adp_polling = true;
+ }
+
+ return NEARDAL_SUCCESS;
+
+out_err:
+
+ if (adapters)
+ neardal_free_array(&adapters);
+
+ if (neard_adp)
+ neardal_free_adapter(neard_adp);
+
+ return err;
+}
+
+static bool neard_plugin_init(net_nfc_error_e *result)
+{
+ neard_plugin_log_open("neard-plugin");
+
+ DBG("");
+
+ if (neardal_set_cb_adapter_added(
+ __neardal_adp_added_cb, NULL) != NEARDAL_SUCCESS ||
+ neardal_set_cb_adapter_removed(
+ __neardal_adp_removed_cb, NULL) != NEARDAL_SUCCESS ||
+ neardal_set_cb_adapter_property_changed(
+ __neardal_adp_prop_changed_cb, NULL) != NEARDAL_SUCCESS ||
+ neardal_set_cb_tag_found(
+ __neardal_tag_found_cb, NULL) != NEARDAL_SUCCESS ||
+ neardal_set_cb_tag_lost(
+ __neardal_tag_lost_cb, NULL) != NEARDAL_SUCCESS ||
+ neardal_set_cb_record_found(
+ __neardal_record_found_cb, NULL) != NEARDAL_SUCCESS) {
+
+ *result = NET_NFC_INVALID_HANDLE;
+
+ return false;
+ }
+
+ if (__neardal_init() != NEARDAL_SUCCESS) {
+ *result = NET_NFC_UNKNOWN_ERROR;
+
+ return false;
+ }
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_deinit(void)
+{
+ int powered = 0;
+
+ DBG("");
+
+ if (neard_adp_polling == true)
+ neardal_stop_poll(neard_adp_path);
+
+ if (neard_adp_powered == true)
+ neardal_set_adapter_property(neard_adp_path,
+ NEARD_ADP_PROP_POWERED, (void*) powered);
+
+ if (neard_adp_path) {
+ g_free(neard_adp_path);
+ neard_adp_path = NULL;
+ }
+
+ if (tag != NULL) {
+ neardal_free_tag(tag);
+ tag = NULL;
+ }
+
+ neardal_destroy();
+ neard_plugin_log_close();
+
+ return true;
+}
+
+static bool neard_plugin_register_listener(
+ target_detection_listener_cb target_detection_listener,
+ se_transaction_listener_cb se_transaction_listener,
+ llcp_event_listener_cb llcp_event_listener,
+ net_nfc_error_e* result)
+{
+ if (result == NULL)
+ return false;
+
+ DBG("");
+
+ interface_target_detection_cb = target_detection_listener;
+ interface_se_transaction_cb = se_transaction_listener;
+ interface_llcp_event_cb = llcp_event_listener;
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_unregister_listener()
+{
+ DBG("");
+
+ interface_target_detection_cb = NULL;
+ interface_se_transaction_cb = NULL;
+ interface_llcp_event_cb = NULL;
+
+ return true;
+}
+
+static bool neard_plugin_check_firmware_version(net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ *result = NET_NFC_NOT_SUPPORTED;
+
+ return false;
+}
+
+static bool neard_plugin_update_firmware(net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ *result = NET_NFC_NOT_SUPPORTED;
+
+ return false;
+}
+
+static bool neard_plugin_get_stack_information(
+ net_nfc_stack_information_s* stack_info,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_configure_discovery(
+ net_nfc_discovery_mode_e mode,
+ net_nfc_event_filter_e config,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_get_secure_element_list(
+ net_nfc_secure_element_info_s* list,
+ int* count, net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == FALSE)
+ return false;
+
+ *result = NET_NFC_NOT_SUPPORTED;
+
+ return false;
+}
+
+static bool neard_plugin_set_secure_element_mode(
+ net_nfc_secure_element_type_e element_type,
+ net_nfc_secure_element_mode_e mode,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == FALSE)
+ return false;
+
+ *result = NET_NFC_NOT_SUPPORTED;
+
+ return false;
+}
+
+static bool neard_plugin_connect(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_disconnect(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ __neard_plugin_make_invalid_target_handle(handle);
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+/* TODO */
+static bool neard_plugin_check_ndef(net_nfc_target_handle_s* handle,
+ uint8_t *ndef_card_state,
+ int* max_data_size,
+ int* real_data_size,
+ net_nfc_error_e* result)
+{
+ char *ndef = NULL;
+ int len = 0;
+
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL || ndef_card_state == NULL ||
+ max_data_size == NULL || real_data_size == NULL) {
+
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ if (tag == NULL) {
+ *result = NET_NFC_UNKNOWN_ERROR;
+ return false;
+ }
+
+ if (neardal_tag_get_rawNDEF(tag->name, &ndef, &len)
+ != NEARDAL_SUCCESS) {
+ *ndef_card_state = 0;
+ *max_data_size = -1;
+ *real_data_size = -1;
+ *result = NET_NFC_TAG_READ_FAILED;
+ }
+
+ if (tag->readOnly)
+ *ndef_card_state = NET_NFC_NDEF_CARD_READ_ONLY;
+ else
+ *ndef_card_state = NET_NFC_NDEF_CARD_READ_WRITE;
+
+ /* TODO get real data */
+ switch (__neard_plugin_convert_target_type(tag->type)) {
+ case NET_NFC_JEWEL_PICC:
+ *max_data_size = NET_NFC_JEWEL_PICC_MAX_SIZE;
+ break;
+
+ case NET_NFC_MIFARE_ULTRA_PICC:
+ *max_data_size = NET_NFC_MIFARE_ULTRA_PICC_MAX_SIZE;;
+ break;
+
+ case NET_NFC_FELICA_PICC:
+ *max_data_size = NET_NFC_FELICA_PICC_MAX_SIZE;
+ break;
+
+ case NET_NFC_MIFARE_DESFIRE_PICC:
+ *max_data_size = NET_NFC_MIFARE_DESFIRE_PICC_MAX_SIZE;
+ break;
+ }
+
+ g_free(ndef);
+ *real_data_size = len;
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_check_target_presence(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result)
+{
+// DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ if (tag == NULL) {
+ DBG("target lost");
+ *result = NET_NFC_NOT_CONNECTED;
+ return false;
+ }
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_read_ndef(net_nfc_target_handle_s* handle,
+ data_s** data,
+ net_nfc_error_e* result)
+{
+ char *buffer = NULL;
+ int len = 0;
+
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL || data == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ *data = g_try_malloc0(sizeof(data_s));
+ if (*data == NULL) {
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ if (neardal_tag_get_rawNDEF(tag->name, &buffer,
+ &len) != NEARDAL_SUCCESS) {
+ g_free(*data);
+ *data = NULL;
+ *result = NET_NFC_TAG_READ_FAILED;
+
+ return false;
+ }
+
+ (*data)->length = len;
+ (*data)->buffer = g_try_malloc0((*data)->length);
+ if ((*data)->buffer == NULL) {
+ g_free(buffer);
+ g_free(*data);
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ memcpy((*data)->buffer, buffer, (*data)->length);
+
+ g_free(buffer);
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_write_ndef(net_nfc_target_handle_s* handle,
+ data_s* data, net_nfc_error_e* result)
+{
+ neardal_record *record;
+
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL || data == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ if ((data->buffer == NULL && data->length != 0) ||
+ (data->buffer != NULL && data->length == 0)) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ record = g_try_malloc0(sizeof(neardal_record));
+ if (record == NULL) {
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ record->name = g_strdup(tag->records[0]);
+ record->type = g_strdup("Raw");
+ record->rawNDEF = g_try_malloc0(data->length);
+ if (record->rawNDEF == NULL) {
+ neardal_free_record(record);
+ *result = NET_NFC_ALLOC_FAIL;
+ return false;
+ }
+
+ memcpy(record->rawNDEF, data->buffer, data->length);
+ record->rawNDEFSize = data->length;
+
+ if (neardal_tag_write(record) != NEARDAL_SUCCESS) {
+ neardal_free_record(record);
+ *result = NET_NFC_TAG_WRITE_FAILED;
+ return false;
+ }
+
+ neardal_free_record(record);
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+static bool neard_plugin_make_read_only_ndef(net_nfc_target_handle_s* handle,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ *result = NET_NFC_NOT_SUPPORTED;
+
+ return false;
+}
+
+static bool neard_plugin_transceive(net_nfc_target_handle_s* handle,
+ net_nfc_transceive_info_s* info,
+ data_s** data,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_format_ndef(net_nfc_target_handle_s* handle,
+ data_s* secure_key,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (handle == NULL || secure_key == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ if (!__neard_plugin_is_valid_target_handle(handle)) {
+ *result = NET_NFC_INVALID_HANDLE;
+ return false;
+ }
+
+ *result = NET_NFC_NOT_SUPPORTED;
+
+ return false;
+}
+
+static bool neard_plugin_exception_handler(void)
+{
+ DBG("");
+
+ return true;
+}
+
+static bool neard_plugin_is_ready(net_nfc_error_e* result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ *result = NET_NFC_OK;
+
+ return true;
+}
+
+
+static bool neard_plugin_llcp_config(net_nfc_llcp_config_info_s *config,
+ net_nfc_error_e *result)
+{
+ DBG("");
+
+ if (result == NULL)
+ return false;
+
+ if (config == NULL) {
+ *result = NET_NFC_NULL_PARAMETER;
+ return false;
+ }
+
+ return false;
+}
+
+static bool neard_plugin_llcp_check_llcp(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_activate_llcp(net_nfc_target_handle_s *handle,
+ net_nfc_error_e *result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_create_socket(net_nfc_llcp_socket_t *socket,
+ net_nfc_socket_type_e socketType,
+ uint16_t miu, uint8_t rw,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_bind(net_nfc_llcp_socket_t socket,
+ uint8_t service_access_point,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_listen(net_nfc_target_handle_s* handle,
+ uint8_t* service_access_name,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_accept(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_connect_by_url(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ uint8_t* service_access_name,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_connect(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ uint8_t service_access_point,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_reject(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_disconnect(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_socket_close(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_recv(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s* data, net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_send(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s* data, net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_recv_from(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s * data,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_send_to(net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ data_s* data,
+ uint8_t service_access_point,
+ net_nfc_error_e* result,
+ void * user_param)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_get_remote_config(
+ net_nfc_target_handle_s* handle,
+ net_nfc_llcp_config_info_s *config,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+static bool neard_plugin_llcp_get_remote_socket_info(
+ net_nfc_target_handle_s* handle,
+ net_nfc_llcp_socket_t socket,
+ net_nfc_llcp_socket_option_s * option,
+ net_nfc_error_e* result)
+{
+ DBG("");
+
+ return false;
+}
+
+
+NET_NFC_EXPORT_API bool onload(net_nfc_oem_interface_s* iface)
+{
+ iface->init = neard_plugin_init;
+ iface->deinit = neard_plugin_deinit;
+ iface->register_listener = neard_plugin_register_listener;
+ iface->unregister_listener = neard_plugin_unregister_listener;
+ iface->check_firmware_version = neard_plugin_check_firmware_version;
+ iface->update_firmeware = neard_plugin_update_firmware;
+ iface->get_stack_information = neard_plugin_get_stack_information;
+ iface->configure_discovery = neard_plugin_configure_discovery;
+ iface->get_secure_element_list = neard_plugin_get_secure_element_list;
+ iface->set_secure_element_mode = neard_plugin_set_secure_element_mode;
+ iface->connect = neard_plugin_connect;
+ iface->disconnect = neard_plugin_disconnect;
+ iface->check_ndef = neard_plugin_check_ndef;
+ iface->check_presence = neard_plugin_check_target_presence;
+ iface->read_ndef = neard_plugin_read_ndef;
+ iface->write_ndef = neard_plugin_write_ndef;
+ iface->make_read_only_ndef = neard_plugin_make_read_only_ndef;
+ iface->transceive = neard_plugin_transceive;
+ iface->format_ndef = neard_plugin_format_ndef;
+ iface->exception_handler = neard_plugin_exception_handler;
+ iface->is_ready = neard_plugin_is_ready;
+
+ iface->config_llcp = neard_plugin_llcp_config;
+ iface->check_llcp_status = neard_plugin_llcp_check_llcp;
+ iface->activate_llcp = neard_plugin_llcp_activate_llcp;
+ iface->create_llcp_socket = neard_plugin_llcp_create_socket;
+ iface->bind_llcp_socket = neard_plugin_llcp_bind;
+ iface->listen_llcp_socket = neard_plugin_llcp_listen;
+ iface->accept_llcp_socket = neard_plugin_llcp_accept;
+ iface->connect_llcp_by_url = neard_plugin_llcp_connect_by_url;
+ iface->connect_llcp = neard_plugin_llcp_connect;
+ iface->disconnect_llcp = neard_plugin_llcp_disconnect;
+ iface->close_llcp_socket = neard_plugin_llcp_socket_close;
+ iface->recv_llcp = neard_plugin_llcp_recv;
+ iface->send_llcp = neard_plugin_llcp_send;
+ iface->recv_from_llcp = neard_plugin_llcp_recv_from;
+ iface->send_to_llcp = neard_plugin_llcp_send_to;
+ iface->reject_llcp = neard_plugin_llcp_reject;
+ iface->get_remote_config = neard_plugin_llcp_get_remote_config;
+ iface->get_remote_socket_info = neard_plugin_llcp_get_remote_socket_info;
+
+ return true;
+}
+