/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
+* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+*
+* 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 <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
-#include <net_nfc.h>
-#include <net_nfc_typedef_private.h>
#include <dlog.h>
-#include <nfc.h>
-#include <nfc_private.h>
-#include <net_nfc_exchanger.h>
#include <vconf.h>
#include <Ecore_X.h>
-#include <glib.h>
-#include "net_nfc_internal_se.h"
+#include "net_nfc.h"
+#include "nfc_private.h"
+#include "nfc_internal.h"
/**
* @brief The default factory key.
*/
const unsigned char NFC_RECORD_HANDOVER_SELECT_TYPE[2] = { 'H','s' };
-typedef struct _init_context_t
-{
- nfc_initialize_completed_cb cb;
- int ret;
- void* user_data;
-}init_context_t;
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "CAPI_NETWORK_NFC"
-
-static int _init_callback(init_context_t *context)
-{
- if (context == NULL) {
- return 0;
- }
-
- if(context->cb != NULL)
- context->cb(context->ret, context->user_data);
-
- free(context);
+static _nfc_context_s gdbus_nfc_context;
- return 0;
-}
+/********************************Utility functions***********************/
static pid_t _get_focus_app_pid()
{
focus_app_pid = _get_focus_app_pid();
current_app_pid = getpgid(getpid());
- LOGE( "[check app permission] focus_app_pid [%d], current_app_pid [%d]", focus_app_pid, current_app_pid);
+ LOGD("[check app permission] focus_app_pid [%d], current_app_pid [%d]", focus_app_pid, current_app_pid);
return (focus_app_pid == current_app_pid) ? true : false;
}
static int _return_invalid_param(const char *func)
{
- LOGE( "INVALID_PARAMETER (0x%08x)", NFC_ERROR_INVALID_PARAMETER);
+ LOG_ERR("INVALID_PARAMETER : %s", func);
+
return NFC_ERROR_INVALID_PARAMETER;
}
static int _convert_error_code(const char *func, int native_error_code)
{
int error_code = NFC_ERROR_NONE;
- char * errorstr = NULL;
- switch(native_error_code){
- case 0 :
- error_code = NFC_ERROR_NONE;
- errorstr = "ERROR_NONE";
- break;
-
- case NET_NFC_ALLOC_FAIL:
- error_code = NFC_ERROR_OUT_OF_MEMORY;
- errorstr = "OUT_OF_MEMORY";
- break;
-
- case NET_NFC_UNKNOWN_ERROR:
- case NET_NFC_THREAD_CREATE_FAIL:
- case NET_NFC_INVALID_STATE:
- case NET_NFC_IPC_FAIL:
- case NET_NFC_BUFFER_TOO_SMALL:
- case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED:
- case NET_NFC_RF_ERROR:
- case NET_NFC_NOT_SUPPORTED:
- case NET_NFC_TAG_READ_FAILED:
- case NET_NFC_TAG_WRITE_FAILED:
- case NET_NFC_OPERATION_FAIL:
- case NET_NFC_SECURITY_FAIL:
- case NET_NFC_INSUFFICIENT_STORAGE:
- case NET_NFC_NOT_CONNECTED:
- case NET_NFC_NOT_INITIALIZED:
- case NET_NFC_NOT_REGISTERED:
- error_code = NFC_ERROR_OPERATION_FAILED;
- errorstr = "OPERATION_FAILED";
- break;
-
- case NET_NFC_OUT_OF_BOUND:
- case NET_NFC_NULL_PARAMETER:
- case NET_NFC_NOT_ALLOWED_OPERATION:
- case NET_NFC_LLCP_INVALID_SOCKET:
- case NET_NFC_NO_DATA_FOUND:
- error_code = NFC_ERROR_INVALID_PARAMETER;
- errorstr = "INVALID_PARAMETER";
- break;
- case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE:
- error_code = NFC_ERROR_INVALID_RECORD_TYPE;
- errorstr = "INVALID_RECORD_TYPE";
- break;
-
- case NET_NFC_ALREADY_INITIALIZED:
- case NET_NFC_ALREADY_REGISTERED:
- error_code = NFC_ERROR_NONE;
- errorstr = "ERROR_NONE";
- break;
-
- case NET_NFC_RF_TIMEOUT:
- error_code = NFC_ERROR_TIMED_OUT;
- errorstr = "TIMED_OUT";
- break;
- case NET_NFC_INVALID_FORMAT:
- case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK:
- case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK:
- case NET_NFC_NDEF_BUF_END_WITHOUT_ME:
- error_code = NFC_ERROR_INVALID_NDEF_MESSAGE;
- errorstr = "INVALID_NDEF_MESSAGE";
- break;
- case NET_NFC_NO_NDEF_MESSAGE:
- error_code = NFC_ERROR_NO_NDEF_MESSAGE;
- errorstr = "NO_NDEF_MESSAGE";
- break;
- case NET_NFC_BUSY :
- error_code = NFC_ERROR_DEVICE_BUSY;
- errorstr = "DEVICE_BUSY";
- break;
- case NET_NFC_NO_NDEF_SUPPORT:
- error_code = NFC_ERROR_NOT_NDEF_FORMAT;
- errorstr = "NOT_SUPPORTED";
- break;
- default :
- error_code = NFC_ERROR_OPERATION_FAILED;
- errorstr = "OPERATION_FAILED";
- }
-
- LOGE( "NFC %s(0x%08x)", errorstr, error_code);
+ char *errorstr = NULL;
- return error_code;
-
-}
-
-static _nfc_context_s g_nfc_context;
-
-static void _clear_context()
-{
- if (g_nfc_context.current_tag != NULL)
+ switch (native_error_code)
{
- net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
- }
-
- memset(&g_nfc_context, 0, sizeof(g_nfc_context));
-}
-
-static void nfc_manager_set_activation_completed_cb(nfc_activation_completed_cb callback , void *user_data)
-{
- g_nfc_context.on_activation_completed_cb = callback;
- g_nfc_context.on_activation_completed_user_data = user_data;
- g_nfc_context.on_activation_doing = true;
-}
-
-static void nfc_manager_unset_activation_completed_cb(void)
-{
- g_nfc_context.on_activation_completed_cb = NULL;
- g_nfc_context.on_activation_completed_user_data = NULL;
- g_nfc_context.on_activation_doing = false;
-}
-
-static bool nfc_manager_check_activation(void)
-{
- return g_nfc_context.on_activation_doing;
-}
-
-
-void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
-{
- LOGI("NFC message %d - start result[%d] ", message, result);
-
- int capi_result = _convert_error_code("EVENT", result);
-
- switch ( message ){
- case NET_NFC_MESSAGE_TRANSCEIVE:
- {
- if( trans_data != NULL ){
- _async_callback_data *user_cb = (_async_callback_data*)trans_data;
-
- if( user_cb->callback_type == _NFC_CALLBACK_TYPE_DATA ){
- unsigned char * buffer = NULL;
- int buffer_size = 0;
- if( result == 0 && data != NULL){
- data_s *arg = (data_s*) data;
- buffer = arg->buffer;
- buffer_size = arg->length;
- }
- void (* data_type_callback)(int result , unsigned char * buffer, int buffer_size, void * user_data);
- data_type_callback = user_cb->callback;
- data_type_callback(capi_result, buffer, buffer_size, user_cb->user_data);
- }else if ( user_cb->callback_type == _NFC_CALLBACK_TYPE_RESULT){
- void (* result_type_callback)(int result , void * user_data);
- result_type_callback = user_cb->callback;
- result_type_callback(capi_result, user_cb->user_data);
- }
- free(user_cb);
- }
+ case NET_NFC_OK:
+ error_code = NFC_ERROR_NONE;
+ errorstr = "ERROR_NONE";
break;
- }
- case NET_NFC_MESSAGE_READ_NDEF:
- {
- if( trans_data != NULL ) {
- ndef_message_h ndef_message = (ndef_message_h)data;
- _async_callback_data *user_cb = (_async_callback_data*)trans_data;
- ((nfc_tag_read_completed_cb)user_cb->callback)(capi_result, ndef_message, user_cb->user_data);
- free(user_cb);
- }
+
+ case NET_NFC_ALLOC_FAIL:
+ error_code = NFC_ERROR_OUT_OF_MEMORY;
+ errorstr = "OUT_OF_MEMORY";
break;
- }
- case NET_NFC_MESSAGE_WRITE_NDEF:
- {
- if( trans_data != NULL ){
- _async_callback_data *user_cb = (_async_callback_data*)trans_data;
- ((nfc_tag_write_completed_cb)user_cb->callback)(capi_result, user_cb->user_data);
- free(user_cb);
- }
+
+ case NET_NFC_NOT_CONNECTED:
+ error_code = NFC_ERROR_NO_DEVICE;
+ errorstr = "NO_DEVICE";
break;
- }
- case NET_NFC_MESSAGE_TAG_DISCOVERED:
- {
- net_nfc_target_info_s *target_info = (net_nfc_target_info_s *)data;
- if (g_nfc_context.current_tag != NULL)
- {
- net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
- g_nfc_context.current_tag = NULL;
- }
+ case NET_NFC_UNKNOWN_ERROR:
+ case NET_NFC_THREAD_CREATE_FAIL:
+ case NET_NFC_IPC_FAIL:
+ case NET_NFC_BUFFER_TOO_SMALL:
+ case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED:
+ case NET_NFC_RF_ERROR:
+ case NET_NFC_NOT_SUPPORTED:
+ case NET_NFC_TAG_READ_FAILED:
+ case NET_NFC_TAG_WRITE_FAILED:
+ case NET_NFC_OPERATION_FAIL:
+ case NET_NFC_INSUFFICIENT_STORAGE:
+ case NET_NFC_NOT_INITIALIZED:
+ case NET_NFC_NOT_REGISTERED:
+ error_code = NFC_ERROR_OPERATION_FAILED;
+ errorstr = "OPERATION_FAILED";
+ break;
- net_nfc_duplicate_target_info((net_nfc_target_info_h)target_info, (net_nfc_target_info_h *)&g_nfc_context.current_tag);
+ case NET_NFC_SECURITY_FAIL:
+ error_code = NFC_ERROR_SECURITY_RESTRICTED;
+ errorstr = "SECURITY_RESTRICTED";
+ break;
- if (g_nfc_context.on_tag_discovered_cb)
- {
- g_nfc_context.on_tag_discovered_cb(NFC_DISCOVERED_TYPE_ATTACHED, (nfc_tag_h)g_nfc_context.current_tag, g_nfc_context.on_tag_discovered_user_data);
- }
+ case NET_NFC_INVALID_STATE:
+ error_code = NFC_ERROR_ILLEGAL_STATE;
+ errorstr = "ILLEGAL_STATE";
+ break;
- //ndef discovered cb
- if (g_nfc_context.on_ndef_discovered_cb && target_info->raw_data.buffer != NULL)
- {
- ndef_message_h ndef_message;
- net_nfc_create_ndef_message_from_rawdata(&ndef_message, (data_h)&(target_info->raw_data));
- g_nfc_context.on_ndef_discovered_cb(ndef_message, g_nfc_context.on_ndef_discovered_user_data);
- net_nfc_free_ndef_message(ndef_message);
- }
+ case NET_NFC_OUT_OF_BOUND:
+ case NET_NFC_NULL_PARAMETER:
+ case NET_NFC_NOT_ALLOWED_OPERATION:
+ case NET_NFC_LLCP_INVALID_SOCKET:
+ case NET_NFC_NO_DATA_FOUND:
+ error_code = NFC_ERROR_INVALID_PARAMETER;
+ errorstr = "INVALID_PARAMETER";
break;
- }
- case NET_NFC_MESSAGE_NOTIFY:
- {
+ case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE:
+ error_code = NFC_ERROR_INVALID_RECORD_TYPE;
+ errorstr = "INVALID_RECORD_TYPE";
break;
- }
- case NET_NFC_MESSAGE_TAG_DETACHED:
- {
- if( g_nfc_context.on_tag_discovered_cb ){
- g_nfc_context.on_tag_discovered_cb( NFC_DISCOVERED_TYPE_DETACHED, (nfc_tag_h)g_nfc_context.current_tag , g_nfc_context.on_tag_discovered_user_data );
- }
- if (g_nfc_context.current_tag != NULL)
- {
- net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
- g_nfc_context.current_tag = NULL;
- }
+ case NET_NFC_ALREADY_INITIALIZED:
+ case NET_NFC_ALREADY_REGISTERED:
+ error_code = NFC_ERROR_NONE;
+ errorstr = "ERROR_NONE";
break;
- }
- case NET_NFC_MESSAGE_P2P_DISCOVERED:
- {
- g_nfc_context.current_target = (net_nfc_target_handle_h)data;
- g_nfc_context.on_p2p_recv_cb = NULL;
- g_nfc_context.on_p2p_recv_user_data = NULL;
- g_nfc_context.on_p2p_send_completed_cb = NULL;
- g_nfc_context.on_p2p_send_completed_user_data = NULL;
-
- if( g_nfc_context.on_p2p_discovered_cb ){
- g_nfc_context.on_p2p_discovered_cb(NFC_DISCOVERED_TYPE_ATTACHED , (nfc_p2p_target_h)g_nfc_context.current_target, g_nfc_context.on_p2p_discovered_user_data );
- }
+ case NET_NFC_RF_TIMEOUT:
+ error_code = NFC_ERROR_TIMED_OUT;
+ errorstr = "TIMED_OUT";
break;
- }
- case NET_NFC_MESSAGE_P2P_DETACHED:
- {
- if( g_nfc_context.on_p2p_discovered_cb ){
- g_nfc_context.on_p2p_discovered_cb( NFC_DISCOVERED_TYPE_DETACHED, (nfc_p2p_target_h)(g_nfc_context.current_target) , g_nfc_context.on_p2p_discovered_user_data );
- }
- memset(&g_nfc_context.current_target , 0 , sizeof( g_nfc_context.current_target ));
- g_nfc_context.on_p2p_recv_cb = NULL;
- g_nfc_context.on_p2p_recv_user_data = NULL;
- g_nfc_context.on_p2p_send_completed_cb = NULL;
- g_nfc_context.on_p2p_send_completed_user_data = NULL;
-
+ case NET_NFC_INVALID_FORMAT:
+ case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK:
+ case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK:
+ case NET_NFC_NDEF_BUF_END_WITHOUT_ME:
+ error_code = NFC_ERROR_INVALID_NDEF_MESSAGE;
+ errorstr = "INVALID_NDEF_MESSAGE";
break;
- }
- case NET_NFC_MESSAGE_P2P_SEND :
- {
- if( g_nfc_context.on_p2p_send_completed_cb != NULL ){
-
- nfc_p2p_send_completed_cb cb = g_nfc_context.on_p2p_send_completed_cb;
- void * user_data = g_nfc_context.on_p2p_send_completed_user_data;
- g_nfc_context.on_p2p_send_completed_cb = NULL;
- g_nfc_context.on_p2p_send_completed_user_data = NULL;
- cb(capi_result , user_data );
- }
+ case NET_NFC_NO_NDEF_MESSAGE:
+ error_code = NFC_ERROR_NO_NDEF_MESSAGE;
+ errorstr = "NO_NDEF_MESSAGE";
break;
- }
- case NET_NFC_MESSAGE_P2P_RECEIVE :
- {
- if( g_nfc_context.on_p2p_recv_cb != NULL ){
- ndef_message_h ndef_message ;
- net_nfc_create_ndef_message_from_rawdata (&ndef_message, (data_h)(data) );
- g_nfc_context.on_p2p_recv_cb( (nfc_p2p_target_h)(g_nfc_context.current_target) , ndef_message ,g_nfc_context.on_p2p_recv_user_data );
- net_nfc_free_ndef_message(ndef_message);
- }
-
+ case NET_NFC_BUSY :
+ error_code = NFC_ERROR_DEVICE_BUSY;
+ errorstr = "DEVICE_BUSY";
break;
- }
- case NET_NFC_MESSAGE_FORMAT_NDEF:
- {
- if( trans_data != NULL) {
- _async_callback_data *user_cb = (_async_callback_data*)trans_data;
- ((nfc_tag_format_completed_cb)user_cb->callback)(capi_result, user_cb->user_data);
- free(user_cb);
- }
+ case NET_NFC_NO_NDEF_SUPPORT:
+ error_code = NFC_ERROR_NOT_NDEF_FORMAT;
+ errorstr = "NOT_SUPPORTED";
break;
- }
-
- case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
- {
- if( g_nfc_context.on_p2p_connection_handover_completed_cb != NULL ){
-
- net_nfc_conn_handover_carrier_type_e type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
- nfc_ac_type_e carrior_type = NFC_AC_TYPE_UNKNOWN;
- char * ac_data = NULL;
- int ac_data_size = 0;
- char * temp = NULL;
- char buffer[50] = {0,};
- data_h ac_info = NULL;
-
-
- net_nfc_exchanger_get_alternative_carrier_type((net_nfc_connection_handover_info_h)data, &type);
- if (type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
- {
- carrior_type = NFC_AC_TYPE_BT;
- if(net_nfc_exchanger_get_alternative_carrier_data((net_nfc_connection_handover_info_h)data, &ac_info)== 0)
- {
- temp = (char *)net_nfc_get_data_buffer(ac_info);
- if( temp != NULL)
- {
-
- snprintf(buffer, 50, "%02x:%02x:%02x:%02x:%02x:%02x",temp[0], temp[1], temp[2], temp[3], temp[4], temp[5]);
-
- ac_data = (strdup(buffer));
- ac_data_size = strlen(ac_data ) +1;
- }
- net_nfc_free_data(ac_info);
- }
- }
-
- nfc_p2p_connection_handover_completed_cb cb = g_nfc_context.on_p2p_connection_handover_completed_cb;
- void * user_data = g_nfc_context.on_p2p_connection_handover_completed_user_data;
- g_nfc_context.on_p2p_connection_handover_completed_cb = NULL;
- g_nfc_context.on_p2p_connection_handover_completed_user_data = NULL;
- cb(capi_result , carrior_type, (void *)ac_data, ac_data_size, user_data );
-
- net_nfc_exchanger_free_alternative_carrier_data((net_nfc_connection_handover_info_h)data);
- free(ac_data);
- }
+ case NET_NFC_PERMISSION_DENIED:
+ error_code = NFC_ERROR_PERMISSION_DENIED;
+ errorstr = "PERMISSION_DENIED";
break;
- }
-
-
- case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
- {
- net_nfc_target_type_e devType = *(net_nfc_target_type_e *)data;
+ case NET_NFC_NOT_ACTIVATED:
+ error_code = NFC_ERROR_NOT_ACTIVATED;
+ errorstr = "NOT_ACTIVATED";
+ break;
+ default :
+ error_code = NFC_ERROR_OPERATION_FAILED;
+ errorstr = "OPERATION_FAILED";
+ }
- if( (devType == NET_NFC_NFCIP1_TARGET )||(devType == NET_NFC_NFCIP1_INITIATOR ))
- {
- net_nfc_get_current_target_handle(trans_data);
- }
- else if( (devType > NET_NFC_UNKNOWN_TARGET )&&(devType < NET_NFC_NFCIP1_TARGET ))
- {
- net_nfc_get_current_tag_info(trans_data);
- }
- else
- {
- if (result == NET_NFC_NOT_CONNECTED)
- {
- capi_result = NFC_ERROR_NONE;
- }
+ if ( error_code != NFC_ERROR_NONE )
+ LOGE("NFC func : %s, %s(0x%08x)", func, errorstr, error_code);
- if( g_nfc_context.on_initialize_completed_cb ){
- nfc_initialize_completed_cb cb = g_nfc_context.on_initialize_completed_cb;
- g_nfc_context.on_initialize_completed_cb = NULL;
- cb( capi_result,trans_data );
- }
- }
- break;
- }
+ return error_code;
+}
- case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
- {
- net_nfc_target_info_s *target_info = (net_nfc_target_info_s *)data;
+static bool _is_initialized()
+{
+ return gdbus_nfc_context.initialized;
+}
- if (target_info != NULL)
- {
- if (g_nfc_context.current_tag != NULL)
- {
- net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
- g_nfc_context.current_tag = NULL;
- }
+/**********************Activate/DeActivate*****************/
- net_nfc_duplicate_target_info((net_nfc_target_info_h)target_info, (net_nfc_target_info_h *)&g_nfc_context.current_tag);
- }
+bool nfc_manager_is_supported(void)
+{
+ int ret;
+ int nfc_supported = 0;
- nfc_initialize_completed_cb cb = g_nfc_context.on_initialize_completed_cb;
- g_nfc_context.on_initialize_completed_cb = NULL;
- if (cb)
- {
- cb(capi_result, trans_data);
- }
- break;
- }
+ LOG_BEGIN();
- case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
- {
- g_nfc_context.current_target = (net_nfc_target_handle_h)data;
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
- nfc_initialize_completed_cb cb = g_nfc_context.on_initialize_completed_cb;
- g_nfc_context.on_initialize_completed_cb = NULL;
- if( cb ){
- cb( capi_result, trans_data );
- }
+ if(ret != NET_NFC_OK || nfc_supported == false)
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ else
+ set_last_result(NFC_ERROR_NONE);
- break;
- }
+ return (!!nfc_supported);
+}
- case NET_NFC_MESSAGE_INIT :
- {
- bool activated = true;
+static void _activation_changed(net_nfc_error_e result, void *user_data)
+{
+ nfc_activation_completed_cb callback;
+ void *user_param;
- LOGE( "_nfc_response_handler NET_NFC_MESSAGE_INIT\n");
+ LOG_BEGIN();
- if (result == NET_NFC_OK){
- if( g_nfc_context.on_activation_changed_cb != NULL ){
- g_nfc_context.on_activation_changed_cb(activated , g_nfc_context.on_activation_changed_user_data);
- LOGE( "_nfc_response_handler changed call back NET_NFC_MESSAGE_INIT NET_NFC_OK\n");
- }
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
- if( g_nfc_context.on_activation_completed_cb != NULL ){
- g_nfc_context.on_activation_completed_cb(result , g_nfc_context.on_activation_completed_user_data);
- LOGE( "_nfc_response_handler completed call back NET_NFC_MESSAGE_INIT NET_NFC_OK\n");
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- nfc_manager_unset_activation_completed_cb();
- }
- else
- {
- g_nfc_context.on_activation_doing = false;
- LOGE( "g_nfc_context.on_activation_doing\n");
- }
- }
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
+ }
- break;
- }
+ g_variant_unref((GVariant *)user_data);
+}
- case NET_NFC_MESSAGE_DEINIT :
- {
- bool activated = false;
+int nfc_manager_set_activation(bool activation,
+ nfc_activation_completed_cb callback,
+ void *user_data)
+{
+ int ret;
+ int nfc_supported = 0;
- if (result == NET_NFC_OK){
- if( g_nfc_context.on_activation_changed_cb != NULL ){
- g_nfc_context.on_activation_changed_cb(activated , g_nfc_context.on_activation_changed_user_data);
- LOGE( "_nfc_response_handler NET_NFC_MESSAGE_DEINIT NET_NFC_OK\n");
- }
+ LOG_BEGIN();
- if( g_nfc_context.on_activation_completed_cb != NULL ){
- g_nfc_context.on_activation_completed_cb(result , g_nfc_context.on_activation_completed_user_data);
- LOGE( "_nfc_response_handler completed call back NET_NFC_MESSAGE_INIT NET_NFC_OK\n");
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
- nfc_manager_unset_activation_completed_cb();
- }
- else
- {
- g_nfc_context.on_activation_doing = false;
- LOGE( "g_nfc_context.on_activation_doing\n");
- }
- }
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- break;
+ if (nfc_manager_is_activated() == activation)
+ {
+ if (activation)
+ {
+ ret = NFC_ERROR_ALREADY_ACTIVATED;
}
-
- case NET_NFC_MESSAGE_SET_SE :
+ else
{
- if( trans_data != NULL ){
- _async_callback_data *user_cb = (_async_callback_data*)trans_data;
- ((nfc_set_card_emulation_completed_cb)user_cb->callback)(capi_result, user_cb->user_data);
- free(user_cb);
- }
- break;
+ ret = NFC_ERROR_ALREADY_DEACTIVATED;
}
+ }
+ else
+ {
+ GVariant *parameter;
- case NET_NFC_MESSAGE_SE_START_TRANSACTION :
- case NET_NFC_MESSAGE_SE_END_TRANSACTION :
- case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION:
- case NET_NFC_MESSAGE_SE_CONNECTIVITY :
- case NET_NFC_MESSAGE_SE_FIELD_ON :
- case NET_NFC_MESSAGE_SE_FIELD_OFF :
- case NET_NFC_MESSAGE_SE_TYPE_CHANGED :
- case NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED :
+ parameter = g_variant_new("(uu)",
+ callback,
+ user_data);
+ if (parameter != NULL)
{
- nfc_se_event_e event = NFC_SE_EVENT_START_TRANSACTION;
- switch( message ){
- case NET_NFC_MESSAGE_SE_START_TRANSACTION:
- event = NFC_SE_EVENT_START_TRANSACTION;
- break;
- case NET_NFC_MESSAGE_SE_END_TRANSACTION:
- event = NFC_SE_EVENT_END_TRANSACTION;
- break;
- case NET_NFC_MESSAGE_SE_CONNECTIVITY:
- event = NFC_SE_EVENT_CONNECTIVITY;
- break;
- case NET_NFC_MESSAGE_SE_FIELD_ON :
- event = NFC_SE_EVENT_FIELD_ON;
- break;
- case NET_NFC_MESSAGE_SE_FIELD_OFF :
- event = NFC_SE_EVENT_FIELD_OFF;
- break;
- case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION:
- event = NFC_SE_EVENT_TRANSACTION;
- break;
- case NET_NFC_MESSAGE_SE_TYPE_CHANGED:
- event = NFC_SE_EVENT_SE_TYPE_CHANGED;
- break;
- case NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED:
- event = NFC_SE_EVENT_SE_CARD_EMULATION_CHANGED;
- default:
- break;
- }
+ ret = net_nfc_client_manager_set_active(activation,
+ _activation_changed,
+ parameter);
+ if (ret != NET_NFC_OK)
+ {
+ LOG_ERR("net_nfc_client_manager_set_active fail");
- if( g_nfc_context.on_se_event_cb ){
- g_nfc_context.on_se_event_cb(event, g_nfc_context.on_se_event_user_data);
- }
- if( message == NET_NFC_MESSAGE_SE_TYPE_TRANSACTION){
- net_nfc_se_event_info_s* transaction_data = (net_nfc_se_event_info_s*)data;
-
- bool fg_dispatch = transaction_data->fg_dispatch;
- net_nfc_se_type_e se_type = transaction_data->se_type;
- pid_t focus_app_pid = transaction_data->focus_app_pid;
-
- if(g_nfc_context.on_se_type == se_type)
- {
- pid_t mypid = getpid();
-
- if(fg_dispatch == false ||
- (fg_dispatch == true && focus_app_pid == (getpgid(mypid))))
- {
- if( NET_NFC_SE_TYPE_ESE == g_nfc_context.on_se_type)
- {
- if( g_nfc_context.on_eSE_transaction_event_cb && transaction_data != NULL)
- {
- g_nfc_context.on_eSE_transaction_event_cb(
- se_type,
- transaction_data->aid.buffer,transaction_data->aid.length,
- transaction_data->param.buffer,transaction_data->param.length,
- g_nfc_context.on_eSE_transaction_event_user_data);
- }
- }
- else if( NET_NFC_SE_TYPE_UICC == g_nfc_context.on_se_type)
- {
- if( g_nfc_context.on_UICC_transaction_event_cb && transaction_data != NULL)
- {
- g_nfc_context.on_UICC_transaction_event_cb(
- se_type,
- transaction_data->aid.buffer,transaction_data->aid.length,
- transaction_data->param.buffer,transaction_data->param.length,
- g_nfc_context.on_UICC_transaction_event_user_data);
- }
- }
- }
- }
+ g_variant_unref(parameter);
}
}
+ else
+ {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
- default :
- break;
+ ret = _convert_error_code(__func__, ret);
}
+ return ret;
}
-
-bool nfc_manager_is_supported(void)
+bool nfc_manager_is_activated(void)
{
+ int ret;
+ int activated = 0;
int nfc_supported = 0;
- net_nfc_is_supported(&nfc_supported);
+ LOG_BEGIN();
- return nfc_supported;
-}
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return false;
+ }
+
+ ret = net_nfc_client_get_nfc_state(&activated);
+ set_last_result(_convert_error_code(__func__,ret));
+
+ return (!!activated);
+}
-int nfc_manager_set_activation(bool activation, nfc_activation_completed_cb callback, void *user_data)
+int nfc_manager_set_activation_changed_cb(nfc_activation_changed_cb callback,
+ void *user_data)
{
- int ret = 0;
+ int ret;
int nfc_supported = 0;
- bool nfc_check_activation = 0;
- nfc_check_activation = nfc_manager_check_activation();
+ LOG_BEGIN();
- if (nfc_check_activation == true)
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- LOGE( "nfc_manager_check_activation BUSY!!!!!");
- return NFC_ERROR_DEVICE_BUSY;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- net_nfc_is_supported(&nfc_supported);
-
- if (!nfc_supported)
+ if(_is_initialized() == false)
{
- ret = NFC_ERROR_NOT_SUPPORTED;
+ return NFC_ERROR_NOT_INITIALIZED;
}
- else
- {
- if (nfc_manager_is_activated() == activation)
- {
- if (activation)
- {
- ret = NFC_ERROR_ALREADY_ACTIVATED;
- }
- else
- {
- ret = NFC_ERROR_ALREADY_DEACTIVATED;
- }
- }
- else
- {
- nfc_manager_set_activation_completed_cb(callback, user_data);
-
- ret = net_nfc_set_state(activation, NULL);
- if (ret == NET_NFC_OK)
- {
- ret = NFC_ERROR_NONE;
- LOGE( "nfc_manager_set_activation net_nfc_set_state success\n");
- }
- else
- {
- nfc_manager_unset_activation_completed_cb();
- ret = NFC_ERROR_OPERATION_FAILED;
- LOGE( "nfc_manager_set_activation net_nfc_set_state fail\n");
- }
- }
+ if (callback == NULL)
+ {
+ LOG_ERR("callback is NULL");
+ return _return_invalid_param(__func__);
}
- return ret;
-
-}
-int nfc_manager_set_activation_changed_cb(nfc_activation_changed_cb callback , void *user_data)
-{
- if( callback == NULL)
- return _return_invalid_param(__func__);
+ net_nfc_client_manager_set_activated(callback, user_data);
- g_nfc_context.on_activation_changed_cb = callback;
- g_nfc_context.on_activation_changed_user_data = user_data;
- return 0;
+ return NFC_ERROR_NONE;
}
void nfc_manager_unset_activation_changed_cb(void)
{
- g_nfc_context.on_activation_changed_cb = NULL;
- g_nfc_context.on_activation_changed_user_data = NULL;
-}
-
-bool nfc_manager_is_activated(void)
-{
- int activated = 0;
+ int ret;
+ int nfc_supported = 0;
- net_nfc_get_state(&activated);
+ LOG_BEGIN();
- if(activated)
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return true;
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
}
- else
+
+ if(_is_initialized() == false)
{
- return false;
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
}
-}
-static bool _is_initialized()
-{
- return g_nfc_context.initialized;
+ net_nfc_client_manager_unset_activated();
+
+ set_last_result(NFC_ERROR_NONE);
}
-int nfc_manager_initialize (nfc_initialize_completed_cb callback, void *user_data)
+static void _nfc_manager_tag_discovered_cb(net_nfc_target_info_h info,
+ void *user_data)
{
- int ret;
- int nfc_supported = 0;
- init_context_t* context;
+ LOG_BEGIN();
- net_nfc_is_supported(&nfc_supported);
+ gdbus_nfc_context.current_tag = info;
- if(!nfc_supported)
- {
- LOGE( "nfc_manager_initialize NFC_ERROR_NOT_SUPPORTED \n");
- return NFC_ERROR_NOT_SUPPORTED;
+ if (gdbus_nfc_context.on_tag_discovered_cb != NULL) {
+ gdbus_nfc_context.on_tag_discovered_cb(
+ NFC_DISCOVERED_TYPE_ATTACHED,
+ (nfc_tag_h)gdbus_nfc_context.current_tag,
+ gdbus_nfc_context.on_tag_discovered_user_data);
}
- if (!_is_initialized())
+ /* ndef discovered cb */
+ if (gdbus_nfc_context.on_ndef_discovered_cb)
{
- int type;
-
- ret = net_nfc_initialize();
- if( ret != NET_NFC_OK )
- return _convert_error_code(__func__, ret);
+ ndef_message_h ndef_message = NULL;
- _clear_context();
- net_nfc_set_response_callback( _nfc_response_handler , &g_nfc_context);
+ if (net_nfc_get_tag_ndef_message((net_nfc_target_info_h)info,
+ &ndef_message) == NET_NFC_OK) {
+ gdbus_nfc_context.on_ndef_discovered_cb(ndef_message,
+ gdbus_nfc_context.on_ndef_discovered_user_data);
- if (net_nfc_is_tag_connected_sync(&type) == NET_NFC_OK)
- {
- if (type == NET_NFC_NFCIP1_INITIATOR ||
- type == NET_NFC_NFCIP1_TARGET)
- {
- net_nfc_get_current_target_handle_sync(&g_nfc_context.current_target);
- }
- else
- {
- net_nfc_get_current_tag_info_sync((net_nfc_target_info_h *)&g_nfc_context.current_tag);
- }
+ net_nfc_free_ndef_message(ndef_message);
}
+ }
+}
- g_nfc_context.initialized = true;
+static void _nfc_manager_tag_detached_cb(void *user_data)
+{
+ LOG_BEGIN();
- if (callback != NULL)
- {
- context = (init_context_t*)malloc( sizeof(init_context_t));
+ if (gdbus_nfc_context.on_tag_discovered_cb != NULL) {
+ gdbus_nfc_context.on_tag_discovered_cb(
+ NFC_DISCOVERED_TYPE_DETACHED,
+ (nfc_tag_h)gdbus_nfc_context.current_tag,
+ gdbus_nfc_context.on_tag_discovered_user_data);
+ }
- if(context == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
+ gdbus_nfc_context.current_tag = NULL;
+}
+static void _p2p_target_discovered_cb(
+ net_nfc_target_handle_h handle_info,
+ void *user_data)
+{
+ LOG_BEGIN();
- memset(context , 0 , sizeof(init_context_t));
- context->cb = callback;
- context->ret = ret;
- context->user_data = user_data;
- g_idle_add((GSourceFunc)_init_callback, (gpointer)context);
- }
+ gdbus_nfc_context.current_target = handle_info;
+ if (gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) {
+ gdbus_nfc_context.on_p2p_target_discovered_cb(
+ NFC_DISCOVERED_TYPE_ATTACHED,
+ (nfc_p2p_target_h)gdbus_nfc_context.current_target,
+ gdbus_nfc_context.on_p2p_target_discovered_user_data);
}
+}
- return NFC_ERROR_NONE;
+static void _p2p_device_detached(void *user_data)
+{
+ nfc_p2p_target_h handle =
+ (nfc_p2p_target_h)gdbus_nfc_context.current_target;
+
+ LOG_BEGIN();
+
+ if (gdbus_nfc_context.on_p2p_target_discovered_cb != NULL) {
+ gdbus_nfc_context.on_p2p_target_discovered_cb(
+ NFC_DISCOVERED_TYPE_DETACHED,
+ handle,
+ gdbus_nfc_context.on_p2p_target_discovered_user_data);
+ }
+
+ /* unset data_received callback */
+ nfc_p2p_unset_data_received_cb(handle);
+
+ gdbus_nfc_context.current_target = NULL;
}
-int nfc_manager_initialize_sync()
+static void _se_event_cb(net_nfc_message_e message, void *user_data)
+{
+ LOG_BEGIN();
+
+ if (gdbus_nfc_context.on_se_event_cb != NULL) {
+ if(message == NET_NFC_MESSAGE_SE_CARD_EMULATION_CHANGED)
+ gdbus_nfc_context.on_se_event_cb(
+ NFC_SE_EVENT_CARD_EMULATION_CHANGED,
+ gdbus_nfc_context.on_se_event_user_data);
+
+ else if(message == NET_NFC_MESSAGE_SE_TYPE_CHANGED)
+ gdbus_nfc_context.on_se_event_cb(
+ NFC_SE_EVENT_SE_TYPE_CHANGED,
+ gdbus_nfc_context.on_se_event_user_data);
+ }
+}
+
+int nfc_manager_initialize(void)
{
int ret;
int nfc_supported = 0;
- net_nfc_is_supported(&nfc_supported);
- if (!nfc_supported)
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || !nfc_supported)
{
- LOGE("nfc_manager_initialize NFC_ERROR_NOT_SUPPORTED \n");
+ LOG_ERR("NFC_ERROR_NOT_SUPPORTED");
+
return NFC_ERROR_NOT_SUPPORTED;
}
if (!_is_initialized())
{
- int type;
-
- ret = net_nfc_initialize();
+ ret = net_nfc_client_initialize();
if (ret != NET_NFC_OK)
return _convert_error_code(__func__, ret);
- _clear_context();
- net_nfc_set_response_callback(_nfc_response_handler, &g_nfc_context);
- if (net_nfc_is_tag_connected_sync(&type) == NET_NFC_OK)
- {
- if (type == NET_NFC_NFCIP1_INITIATOR ||
- type == NET_NFC_NFCIP1_TARGET)
- {
- net_nfc_get_current_target_handle_sync(&g_nfc_context.current_target);
- }
- else
- {
- net_nfc_get_current_tag_info_sync((net_nfc_target_info_h *)&g_nfc_context.current_tag);
- }
- }
-
- g_nfc_context.initialized = true;
+ memset(&gdbus_nfc_context, 0, sizeof(gdbus_nfc_context));
+ gdbus_nfc_context.initialized = true;
}
- return NFC_ERROR_NONE;
+ return _convert_error_code(__func__, ret);
}
int nfc_manager_deinitialize (void)
{
- int ret = NFC_ERROR_NONE;
+ int ret = NET_NFC_OK;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || !nfc_supported)
+ {
+ LOG_ERR("NFC_ERROR_NOT_SUPPORTED");
+
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
if (_is_initialized())
{
-#if 0
- net_nfc_state_deactivate();
-#endif
- if (ret == 0)
- net_nfc_unset_response_callback();
+ net_nfc_client_se_unset_event_cb();
+
+ net_nfc_client_p2p_unset_device_discovered();
+ net_nfc_client_p2p_unset_device_detached();
- ret = net_nfc_deinitialize();
+ net_nfc_client_tag_unset_tag_discovered();
+ net_nfc_client_tag_unset_tag_detached();
- net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
- memset(&g_nfc_context, 0, sizeof(g_nfc_context));
+ ret = net_nfc_client_deinitialize();
+
+ gdbus_nfc_context.initialized = false;
}
return _convert_error_code(__func__, ret);
}
-int nfc_manager_set_tag_discovered_cb( nfc_tag_discovered_cb callback , void * user_data)
-{
- if( callback == NULL)
- return _return_invalid_param(__func__);
+/*********************** NDEF Functions*********************/
- g_nfc_context.on_tag_discovered_cb = callback;
- g_nfc_context.on_tag_discovered_user_data = user_data;
- return 0;
-}
-void nfc_manager_unset_tag_discovered_cb( void )
+int nfc_manager_set_ndef_discovered_cb(
+ nfc_ndef_discovered_cb callback,
+ void *user_data)
{
- g_nfc_context.on_tag_discovered_cb = NULL;
- g_nfc_context.on_tag_discovered_user_data = NULL;
-}
+ int ret;
+ int nfc_supported = 0;
-int nfc_manager_set_ndef_discovered_cb( nfc_ndef_discovered_cb callback , void *user_data)
-{
- if( callback == NULL)
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
return _return_invalid_param(__func__);
- g_nfc_context.on_ndef_discovered_cb= callback;
- g_nfc_context.on_ndef_discovered_user_data= user_data;
- return 0;
+ net_nfc_client_tag_set_tag_discovered(_nfc_manager_tag_discovered_cb,
+ NULL);
+ net_nfc_client_tag_set_tag_detached(_nfc_manager_tag_detached_cb, NULL);
+
+ gdbus_nfc_context.on_ndef_discovered_cb = callback;
+ gdbus_nfc_context.on_ndef_discovered_user_data = user_data;
+
+ return NFC_ERROR_NONE;
}
void nfc_manager_unset_ndef_discovered_cb( void )
{
- g_nfc_context.on_ndef_discovered_cb = NULL;
- g_nfc_context.on_ndef_discovered_user_data = NULL;
-}
+ int ret;
+ int nfc_supported = 0;
-void nfc_manager_set_tag_filter(int filter )
-{
- net_nfc_set_tag_filter(filter);
-}
+ LOG_BEGIN();
-int nfc_manager_get_tag_filter(void)
-{
- return net_nfc_get_tag_filter();
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ if(_is_initialized() == false)
+ {
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
+ }
+
+ gdbus_nfc_context.on_ndef_discovered_cb = NULL;
+ gdbus_nfc_context.on_ndef_discovered_user_data = NULL;
+
+ set_last_result(NFC_ERROR_NONE);
}
-int nfc_manager_get_connected_tag(nfc_tag_h * tag)
+void nfc_manager_set_tag_filter(int filter)
{
int ret;
- if( tag == NULL )
- return _return_invalid_param(__func__);
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
- if(g_nfc_context.current_tag == NULL)
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NO_DEVICE;
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
}
- if(g_nfc_context.current_tag->handle == NULL)
+ if(_is_initialized() == false)
{
- ret = NFC_ERROR_NO_DEVICE;
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
}
- else
+
+ if(filter < NET_NFC_ALL_DISABLE)
{
- *tag = (nfc_tag_h)g_nfc_context.current_tag;
- ret = NFC_ERROR_NONE;
+ set_last_result(_return_invalid_param(__func__));
+ return;
}
- return ret;
+
+ net_nfc_client_tag_set_filter(filter);
+
+ set_last_result(NFC_ERROR_NONE);
}
-int nfc_manager_get_connected_target(nfc_p2p_target_h *target)
+int nfc_manager_get_tag_filter(void)
{
int ret;
+ int nfc_supported = 0;
- if( target == NULL )
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- if(g_nfc_context.current_target == NULL)
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- ret = NFC_ERROR_NO_DEVICE;
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return 0;
}
- else
+
+ if(_is_initialized() == false)
{
- *target = (nfc_p2p_target_h)g_nfc_context.current_target;
- ret = NFC_ERROR_NONE;
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return 0;
}
- return ret;
+ return net_nfc_client_tag_get_filter();
+
+ set_last_result(NFC_ERROR_NONE);
}
-int nfc_manager_set_system_handler_enable(bool enable)
+static void _net_nfc_manager_tag_format_ndef_cb(net_nfc_error_e result,
+ void *user_data)
{
- int ret = NFC_ERROR_NONE;
+ nfc_tag_format_completed_cb callback;
+ void *user_param;
- ret = net_nfc_set_launch_popup_state(enable);
+ LOG_BEGIN();
- if( ret != NET_NFC_OK )
- return _convert_error_code(__func__, ret);
- else
- return ret;
-}
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
-bool nfc_manager_is_system_handler_enabled(void)
-{
- int state = 0;
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- net_nfc_get_launch_popup_state(&state);
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result),
+ user_param);
+ }
- return state;
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_manager_set_card_emulation_se_type(nfc_se_type_e type, nfc_set_card_emulation_completed_cb callback, void* user_data)
+int nfc_tag_format_ndef(nfc_tag_h tag,
+ unsigned char *key,
+ int key_size,
+ nfc_tag_format_completed_cb callback,
+ void *user_data)
{
- if ((type < NFC_SE_TYPE_DISABLE) || (type > NFC_SE_TYPE_UICC))
+ int ret;
+ data_h key_data = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return _return_invalid_param(__func__);
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- if(!nfc_manager_is_activated())
+ if(_is_initialized() == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ return NFC_ERROR_NOT_INITIALIZED;
}
- _async_callback_data *trans_data = NULL;
- int ret=0;
- net_nfc_se_type_e se_type;
+ if (tag == NULL)
+ return _return_invalid_param(__func__);
- if( callback != NULL )
+ if (!nfc_manager_is_activated())
{
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
+ return NFC_ERROR_NOT_ACTIVATED;
}
- switch(type)
+ if (_check_app_permission() == false)
{
- case NFC_SE_TYPE_DISABLE:
- se_type = NET_NFC_SE_TYPE_NONE;
- break;
- case NFC_SE_TYPE_ESE:
- se_type = NET_NFC_SE_TYPE_ESE;
- break;
- case NFC_SE_TYPE_UICC:
- se_type = NET_NFC_SE_TYPE_UICC;
- break;
- default:
- break;
+ LOG_ERR("permission check fail");
+
+ return NFC_ERROR_SECURITY_RESTRICTED;
}
- ret = net_nfc_set_secure_element_type(se_type, (void *)trans_data);
+ ret = net_nfc_create_data(&key_data, key, key_size);
+ if (ret == NET_NFC_OK) {
+ net_nfc_target_handle_h handle = NULL;
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag,
+ &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_ndef_format(
+ handle,
+ key_data,
+ _net_nfc_manager_tag_format_ndef_cb,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
+
+ net_nfc_free_data(key_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
+ }
return _convert_error_code(__func__, ret);
}
-int nfc_manager_set_se_type(nfc_se_type_e type)
+static void _net_nfc_manager_tag_read_ndef_cb(net_nfc_error_e result,
+ ndef_message_h message,
+ void *user_data)
{
- int ret;
- net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE;
+ nfc_tag_read_completed_cb callback;
+ void *user_param;
- if ((type < NFC_SE_TYPE_DISABLE) || (type > NFC_SE_TYPE_UICC))
- {
- return _return_invalid_param(__func__);
- }
+ LOG_BEGIN();
- if (!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
}
- switch (type)
- {
- case NFC_SE_TYPE_DISABLE :
- se_type = NET_NFC_SE_TYPE_NONE;
- break;
- case NFC_SE_TYPE_ESE :
- se_type = NET_NFC_SE_TYPE_ESE;
- break;
- case NFC_SE_TYPE_UICC :
- se_type = NET_NFC_SE_TYPE_UICC;
- break;
- }
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- ret = net_nfc_set_secure_element_type_sync(se_type);
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result),
+ (nfc_ndef_message_h)message,
+ user_param);
+ }
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-
-int nfc_manager_get_card_emulation_se_type(nfc_se_type_e* type)
+int nfc_tag_read_ndef(nfc_tag_h tag,
+ nfc_tag_read_completed_cb callback,
+ void * user_data)
{
- int ret = NFC_ERROR_NONE;
- int se_type;
+ int ret;
+ net_nfc_target_handle_h handle = NULL;
+ int nfc_supported = 0;
- if (type == NULL)
- return _return_invalid_param(__func__);
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
- if ((ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type)) != 0)
+ if(_is_initialized() == false)
{
- ret = NFC_ERROR_OPERATION_FAILED;
- return ret;
+ return NFC_ERROR_NOT_INITIALIZED;
}
- else
+
+ if (tag == NULL)
+ return _return_invalid_param(__func__);
+
+ if (!nfc_manager_is_activated())
{
- if ((se_type >= NFC_SE_TYPE_DISABLE) && (se_type <= NFC_SE_TYPE_UICC))
- *type = se_type;
- else
- ret = NFC_ERROR_OPERATION_FAILED;
+ LOG_ERR("NFC_ERROR_NOT_ACTIVATED");
+ return NFC_ERROR_NOT_ACTIVATED;
}
- return ret;
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_ndef_read(
+ handle,
+ _net_nfc_manager_tag_read_ndef_cb,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
+
+ return _convert_error_code(__func__, ret);
}
-int nfc_manager_get_cached_message(nfc_ndef_message_h *ndef_message)
+int nfc_ndef_message_get_rawdata_size(nfc_ndef_message_h ndef_message,
+ unsigned int *byte_size)
{
int ret;
- if( ndef_message == NULL )
+ LOG_BEGIN();
+
+ if (ndef_message == NULL || byte_size == NULL)
return _return_invalid_param(__func__);
- ret = net_nfc_retrieve_current_ndef_message(ndef_message);
+ ret = net_nfc_get_ndef_message_byte_length(ndef_message,
+ (unsigned int *)byte_size);
+
return _convert_error_code(__func__, ret);
}
-int nfc_ndef_record_create(nfc_ndef_record_h* record, nfc_record_tnf_e tnf, const unsigned char* type, int type_size , const unsigned char * id , int id_size, const unsigned char * payload, int payload_size)
+static void _net_nfc_manager_tag_write_ndef_cb(net_nfc_error_e result,
+ void *user_data)
{
- if(record == NULL )
- return _return_invalid_param(__func__);
+ nfc_tag_write_completed_cb callback;
+ void *user_param;
- data_s type_data = { (unsigned char*)type, type_size };
- data_s id_data = { (unsigned char*)id , id_size };
- data_s payload_data = {(unsigned char*)payload , payload_size };
- int ret;
- ret = net_nfc_create_record((ndef_record_h*)record , tnf , (data_h)&type_data , (data_h)&id_data, (data_h)&payload_data);
+ LOG_BEGIN();
- return _convert_error_code(__func__, ret);
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
+ }
+
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_ndef_record_create_text(nfc_ndef_record_h* record, const char * text, const char * lang_code, nfc_encode_type_e encode )
+int nfc_tag_write_ndef(nfc_tag_h tag,
+ nfc_ndef_message_h msg,
+ nfc_tag_write_completed_cb callback,
+ void *user_data)
{
int ret;
+ net_nfc_target_handle_h handle = NULL;
+ unsigned int byte_size = 0;
+ uint32_t max_len = 0;
+ net_nfc_ndef_card_state_e state = NET_NFC_NDEF_CARD_INVALID;
+ int nfc_supported = 0;
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if(record == NULL || text == NULL || lang_code == NULL )
+ if (tag == NULL)
return _return_invalid_param(__func__);
- ret = net_nfc_create_text_type_record((ndef_record_h*)record, text, lang_code, encode);
+ if (!nfc_manager_is_activated())
+ {
+ return NFC_ERROR_NOT_ACTIVATED;
+ }
+
+ if (_check_app_permission() == false)
+ {
+ LOGE("permission check fail");
+ return NFC_ERROR_SECURITY_RESTRICTED;
+ }
+
+ ret = net_nfc_get_tag_ndef_state((net_nfc_target_info_h)tag, &state);
+ if (ret != NET_NFC_OK) {
+ LOG_ERR("net_nfc_get_tag_ndef_state failed, [%d]", ret);
+ return _convert_error_code(__func__, ret);;
+ }
+
+ if (state == NET_NFC_NDEF_CARD_READ_ONLY) {
+ return NFC_ERROR_READ_ONLY_NDEF;
+ }
+
+ ret = net_nfc_get_tag_max_data_size((net_nfc_target_info_h)tag, &max_len);
+ if (ret != NET_NFC_OK) {
+ LOG_ERR("net_nfc_get_tag_max_data_size failed, [%d]", ret);
+ return _convert_error_code(__func__, ret);;
+ }
+
+ ret = nfc_ndef_message_get_rawdata_size(msg, &byte_size);
+ if (ret != NFC_ERROR_NONE) {
+ LOG_ERR("nfc_ndef_message_get_rawdata_size failed, [%d]", ret);
+ return _convert_error_code(__func__, ret);;
+ }
+
+ if (max_len < byte_size) {
+ return NFC_ERROR_NO_SPACE_ON_NDEF;
+ }
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_ndef_write(
+ handle,
+ msg,
+ _net_nfc_manager_tag_write_ndef_cb,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
+
return _convert_error_code(__func__, ret);
}
-int nfc_ndef_record_create_uri(nfc_ndef_record_h* record, const char* uri)
+int nfc_manager_get_cached_message(nfc_ndef_message_h *ndef_message)
{
int ret;
+ int nfc_supported = 0;
- if(record == NULL || uri == NULL)
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL)
return _return_invalid_param(__func__);
- ret = net_nfc_create_uri_type_record((ndef_record_h*)record , uri , NET_NFC_SCHEMA_FULL_URI);
+ ret = net_nfc_retrieve_current_ndef_message(ndef_message);
+
return _convert_error_code(__func__, ret);
}
-int nfc_ndef_record_create_mime(nfc_ndef_record_h* record, const char * mime_type , const unsigned char * data , int data_size)
+int nfc_ndef_record_create(nfc_ndef_record_h *record,
+ nfc_record_tnf_e tnf,
+ const unsigned char *type,
+ int type_size,
+ const unsigned char *id,
+ int id_size,
+ const unsigned char *payload,
+ unsigned int payload_size)
{
- if(record == NULL || mime_type == NULL || data == NULL)
- return _return_invalid_param(__func__);
-
- return nfc_ndef_record_create(record , NFC_RECORD_TNF_MIME_MEDIA , (unsigned char *) mime_type, strlen(mime_type), NULL, 0, data, data_size );
-}
+ int ret;
+ data_h type_data = NULL;
+ data_h id_data = NULL;
+ data_h payload_data = NULL;
+ int nfc_supported = 0;
-int nfc_ndef_record_get_mime_type(nfc_ndef_record_h record , char **mime_type){
+ LOG_BEGIN();
- int ret;
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL)
+ return _return_invalid_param(__func__);
+
+ net_nfc_create_data(&type_data, type, type_size);
+
+ if (id != NULL && id_size > 0) {
+ net_nfc_create_data(&id_data, id, id_size);
+ }
+
+ if (payload != NULL && payload_size > 0) {
+ net_nfc_create_data(&payload_data, payload, payload_size);
+ }
+
+ ret = net_nfc_create_record(
+ (ndef_record_h *)record,
+ tnf,
+ type_data,
+ id_data,
+ payload_data);
+
+ if (payload_data != NULL) {
+ net_nfc_free_data(payload_data);
+ }
+
+ if (id_data != NULL) {
+ net_nfc_free_data(id_data);
+ }
+
+ net_nfc_free_data(type_data);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_create_text(nfc_ndef_record_h *record,
+ const char *text,
+ const char *lang_code,
+ nfc_encode_type_e encode)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || text == NULL || lang_code == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_create_text_type_record(
+ (ndef_record_h *)record,
+ text,
+ lang_code,
+ encode);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_create_uri(nfc_ndef_record_h *record,
+ const char *uri)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || uri == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_create_uri_type_record(
+ (ndef_record_h *)record,
+ uri,
+ NET_NFC_SCHEMA_FULL_URI);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_create_mime(nfc_ndef_record_h *record,
+ const char *mime_type,
+ const unsigned char *data,
+ unsigned int data_size)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || mime_type == NULL ||
+ data == NULL || data_size <= 0)
+ return _return_invalid_param(__func__);
+
+ ret = nfc_ndef_record_create(record,
+ NFC_RECORD_TNF_MIME_MEDIA,
+ (unsigned char *)mime_type,
+ strlen(mime_type),
+ NULL,
+ 0,
+ data,
+ data_size);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_mime_type(nfc_ndef_record_h record,
+ char **mime_type)
+{
+ int ret;
+ nfc_record_tnf_e tnf;
unsigned char *typename;
int length;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if(record == NULL || mime_type == NULL)
+ if (record == NULL || mime_type == NULL)
return _return_invalid_param(__func__);
- nfc_record_tnf_e tnf;
- if( nfc_ndef_record_get_tnf(record, &tnf ) != 0 || tnf != NFC_RECORD_TNF_MIME_MEDIA ){
+ if (nfc_ndef_record_get_tnf(record, &tnf) != NET_NFC_OK ||
+ tnf != NFC_RECORD_TNF_MIME_MEDIA)
+ {
return NFC_ERROR_INVALID_RECORD_TYPE;
}
- ret = nfc_ndef_record_get_type(record,&typename, &length);
- if( ret != 0 )
- return _convert_error_code(__func__, ret);
+ ret = nfc_ndef_record_get_type(record, &typename, &length);
+ if (ret == NET_NFC_OK) {
+ *mime_type = calloc(1, length + 1);
+ if (*mime_type != NULL) {
+ memcpy(*mime_type, typename, length);
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_destroy(nfc_ndef_record_h record)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_free_record(record);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_set_id(nfc_ndef_record_h record,
+ unsigned char *id,
+ int id_size)
+{
+ int ret;
+ data_h id_data = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || id == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_create_data(&id_data, id, id_size);
+ if (ret == NET_NFC_OK) {
+ ret = net_nfc_set_record_id(record, id_data);
+
+ net_nfc_free_data(id_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_payload(nfc_ndef_record_h record,
+ unsigned char **payload,
+ unsigned int *size)
+{
+ int ret;
+ data_h payload_data;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || payload == NULL || size == NULL)
+ return _return_invalid_param(__func__);
+
+ *payload = NULL;
+ *size = 0;
+
+ ret = net_nfc_get_record_payload(record, &payload_data);
+ if (ret == NET_NFC_OK) {
+ *payload = net_nfc_get_data_buffer(payload_data);
+ *size = net_nfc_get_data_length(payload_data);
+ } else {
+ *payload = NULL;
+ *size = 0;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_type(nfc_ndef_record_h record,
+ unsigned char **type,
+ int *size)
+{
+ int ret;
+ data_h type_data;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || type == NULL || size == NULL)
+ return _return_invalid_param(__func__);
+
+ *type = NULL;
+ *size = 0;
+
+ ret = net_nfc_get_record_type(record, &type_data);
+ if (ret == NET_NFC_OK) {
+ *type = net_nfc_get_data_buffer(type_data);
+ *size = net_nfc_get_data_length(type_data);
+ } else {
+ *type = NULL;
+ *size = 0;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_id(nfc_ndef_record_h record,
+ unsigned char **id,
+ int *size)
+{
+ int ret;
+ data_h id_data;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || id == NULL || size == NULL)
+ return _return_invalid_param(__func__);
+
+ *id = NULL;
+ *size = 0;
+
+ ret = net_nfc_get_record_id(record, &id_data);
+ if (ret == NET_NFC_OK) {
+ *id = net_nfc_get_data_buffer(id_data);
+ *size = net_nfc_get_data_length(id_data);
+ } else {
+ *id = NULL;
+ *size = 0;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_tnf(nfc_ndef_record_h record, nfc_record_tnf_e *tnf)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || tnf == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_record_tnf(record, (net_nfc_record_tnf_e *)tnf);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_text(nfc_ndef_record_h record, char **buffer)
+{
+ int ret;
+ int nfc_supported = 0;
+ unsigned char* record_type = NULL;
+ int type_size = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || buffer == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = nfc_ndef_record_get_type(record, &record_type, &type_size);
+
+ if (ret == NFC_ERROR_NONE && record_type != NULL && type_size != 0 &&
+ !strcmp((char*)record_type, "T"))
+ {
+ LOG_ERR("record type is T");
+ ret = net_nfc_create_text_string_from_text_record(record, buffer);
+ }
+ else
+ {
+ LOG_ERR("record type is not T");
+ return _return_invalid_param(__func__);
+ }
+
+ return _convert_error_code(__func__, ret);
+}
- *mime_type = malloc(length+1);
- if( *mime_type == NULL ){
- LOGE( "OUT_OF_MEMORY (0x%08x)", NFC_ERROR_OUT_OF_MEMORY);
- return NFC_ERROR_OUT_OF_MEMORY;
+int nfc_ndef_record_get_langcode(nfc_ndef_record_h record, char **lang_code)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || lang_code == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_languange_code_string_from_text_record(record,
+ lang_code);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_encode_type(
+ nfc_ndef_record_h record,
+ nfc_encode_type_e *encode)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || encode == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_encoding_type_from_text_record(
+ record,
+ (net_nfc_encode_type_e *)encode);
+
+ /* if( ret == NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE)
+ LOGE("%s reord type is not text type");*/
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_record_get_uri(nfc_ndef_record_h record, char **uri)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (record == NULL || uri == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_create_uri_string_from_uri_record(record, uri);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_create(nfc_ndef_message_h *ndef_message)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_create_ndef_message(ndef_message);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_create_from_rawdata(
+ nfc_ndef_message_h *ndef_message,
+ const unsigned char *rawdata,
+ unsigned int rawdata_size)
+{
+ int ret;
+ data_h rawdata_data = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL || rawdata == NULL || rawdata_size <= 0)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_create_data(&rawdata_data, rawdata, rawdata_size);
+ if (ret == NET_NFC_OK) {
+ ret = net_nfc_create_ndef_message_from_rawdata(
+ (ndef_message_h *)ndef_message,
+ rawdata_data);
+
+ net_nfc_free_data(rawdata_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_destroy(nfc_ndef_message_h ndef_message)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_free_ndef_message(ndef_message);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_get_record_count(nfc_ndef_message_h ndef_message,
+ int *count)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL || count == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_ndef_message_record_count(ndef_message, count);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_get_rawdata(nfc_ndef_message_h ndef_message,
+ unsigned char **rawdata,
+ unsigned int *rawdata_size)
+{
+ int ret;
+ data_h rawdata_data;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL || rawdata == NULL || rawdata_size == NULL)
+ return _return_invalid_param(__func__);
+
+ *rawdata = NULL;
+ *rawdata_size = 0;
+
+ ret = net_nfc_create_rawdata_from_ndef_message(ndef_message,
+ &rawdata_data);
+ if (ret == NET_NFC_OK) {
+ uint8_t *buffer;
+ uint32_t length;
+
+ buffer = net_nfc_get_data_buffer(rawdata_data);
+ length = net_nfc_get_data_length(rawdata_data);
+
+ *rawdata = calloc(1, length);
+ if (rawdata != NULL) {
+ memcpy(*rawdata, buffer, length);
+ *rawdata_size = length;
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+
+ net_nfc_free_data(rawdata_data);
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_append_record(nfc_ndef_message_h ndef_message,
+ nfc_ndef_record_h record)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL || record == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_append_record_to_ndef_message(ndef_message, record);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_insert_record(nfc_ndef_message_h ndef_message,
+ int index,
+ nfc_ndef_record_h record)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL || record == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_append_record_by_index(ndef_message, index, record);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_remove_record(nfc_ndef_message_h ndef_message,
+ int index)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (ndef_message == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_remove_record_by_index(ndef_message, index);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_ndef_message_get_record(nfc_ndef_message_h ndef_message,
+ int index,
+ nfc_ndef_record_h *record)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+
+ if (ndef_message == NULL || record == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_record_by_index(ndef_message,
+ index,
+ (ndef_record_h*)record);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_tag_get_type(nfc_tag_h tag, nfc_tag_type_e *type)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL || type == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_tag_type(tag, (net_nfc_target_type_e *)type);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_tag_is_support_ndef(nfc_tag_h tag, bool *is_support)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL || is_support == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_tag_ndef_support(tag, is_support);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_tag_get_maximum_ndef_size(nfc_tag_h tag, unsigned int *max_size)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL || max_size == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_tag_max_data_size(tag, max_size);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_tag_get_ndef_size(nfc_tag_h tag, unsigned int *actual_data_size)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL || actual_data_size == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_tag_actual_data_size(tag, actual_data_size);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_tag_foreach_information(nfc_tag_h tag,
+ nfc_tag_information_cb callback,
+ void *user_data)
+{
+ int ret;
+ int i, count = 0;
+ char **keys = NULL;
+ data_h value = NULL;
+
+ bool cont;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL || callback == NULL)
+ return _return_invalid_param(__func__);
+
+ ret = net_nfc_get_tag_info_keys((net_nfc_target_info_h)tag,
+ &keys, &count);
+
+ if(ret != NET_NFC_OK)
+ return _convert_error_code(__func__, ret);
+
+ for (i = 0; i < count; i++) {
+ net_nfc_get_tag_info_value((net_nfc_target_info_h)tag, keys[i],
+ &value);
+
+ cont = callback(keys[i],
+ net_nfc_get_data_buffer(value),
+ net_nfc_get_data_length(value),
+ user_data);
+
+ if (!cont)
+ break;
+ }
+
+ return NFC_ERROR_NONE;
+}
+
+/***************************************Tag Functions********************************************/
+
+int nfc_manager_get_connected_tag(nfc_tag_h *tag)
+{
+ int ret;
+ net_nfc_target_info_h result = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL)
+ return _return_invalid_param(__func__);
+
+ *tag = NULL;
+
+ net_nfc_client_tag_set_tag_discovered(_nfc_manager_tag_discovered_cb,
+ NULL);
+ net_nfc_client_tag_set_tag_detached(_nfc_manager_tag_detached_cb, NULL);
+
+
+ if (gdbus_nfc_context.current_tag == NULL) {
+ ret = net_nfc_client_tag_get_current_tag_info_sync(&result);
+ if (ret == NET_NFC_OK) {
+ *tag = (nfc_tag_h)result;
+ }
+ } else {
+ /* FIXME ??? */
+ *tag = gdbus_nfc_context.current_tag;
+
+ ret = NET_NFC_OK;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_manager_get_connected_target(nfc_p2p_target_h *target)
+{
+ int ret;
+ net_nfc_target_handle_h result = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (target == NULL)
+ return _return_invalid_param(__func__);
+
+ *target = NULL;
+
+ net_nfc_client_tag_set_tag_discovered(_nfc_manager_tag_discovered_cb,
+ NULL);
+ net_nfc_client_tag_set_tag_detached(_nfc_manager_tag_detached_cb, NULL);
+
+ if (gdbus_nfc_context.current_target == NULL) {
+ ret = net_nfc_client_tag_get_current_target_handle_sync(&result);
+ if (ret == NET_NFC_OK) {
+ gdbus_nfc_context.current_target = result;
+
+ *target = gdbus_nfc_context.current_target;
+ }
+ } else {
+ /* FIXME ??? */
+ *target = gdbus_nfc_context.current_target;
+
+ ret = NET_NFC_OK;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_manager_set_tag_discovered_cb(nfc_tag_discovered_cb callback,
+ void *user_data)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ return _return_invalid_param(__func__);
+
+ net_nfc_client_tag_set_tag_discovered(_nfc_manager_tag_discovered_cb,
+ NULL);
+ net_nfc_client_tag_set_tag_detached(_nfc_manager_tag_detached_cb, NULL);
+
+ gdbus_nfc_context.on_tag_discovered_cb = callback;
+ gdbus_nfc_context.on_tag_discovered_user_data = user_data;
+
+ return NFC_ERROR_NONE;
+}
+
+void nfc_manager_unset_tag_discovered_cb(void)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ if(_is_initialized() == false)
+ {
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
+ }
+
+ gdbus_nfc_context.on_tag_discovered_cb = NULL;
+ gdbus_nfc_context.on_tag_discovered_user_data = NULL;
+
+ set_last_result(NFC_ERROR_NONE);
+}
+
+/******************************Popup Notification*******************************/
+
+int nfc_manager_set_system_handler_enable(bool enable)
+{
+ int ret;
+ int state;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (enable == true) {
+ state = 0;
+ } else {
+ state = 1;
+ }
+
+ ret = net_nfc_client_sys_handler_set_launch_popup_state(state);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_manager_set_system_handler_enable_force(bool enable)
+{
+ int ret;
+ int state;
+
+ LOG_BEGIN();
+
+ if (enable == true) {
+ state = 0;
+ } else {
+ state = 1;
+ }
+
+ ret = net_nfc_client_sys_handler_set_launch_popup_state_force(state);
+
+ return _convert_error_code(__func__, ret);
+}
+
+bool nfc_manager_is_system_handler_enabled(void)
+{
+ int ret;
+ int state = 0;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return false;
+ }
+
+ if(_is_initialized() == false)
+ {
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return false;
+ }
+
+ ret = net_nfc_client_sys_handler_get_launch_popup_state(&state);
+
+ set_last_result(_convert_error_code(__func__,ret));
+
+ return (state == 0);
+}
+
+/******************************Handover*******************************/
+
+static char *__get_bt_address_string(data_h data)
+{
+ uint8_t *buffer;
+ uint32_t length;
+
+ if (data == NULL) {
+ return NULL;
+ }
+
+ buffer = net_nfc_get_data_buffer(data);
+ length = net_nfc_get_data_length(data);
+
+ if (buffer == NULL || length < 6) {
+ return NULL;
+ }
+
+ return g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
+ buffer[0],
+ buffer[1],
+ buffer[2],
+ buffer[3],
+ buffer[4],
+ buffer[5]);
+}
+
+static void _net_nfc_manager_p2p_handover_cb(net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e carrier,
+ data_h ac_data,
+ void *user_data)
+{
+ nfc_p2p_connection_handover_completed_cb callback;
+ void *user_param;
+
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ nfc_ac_type_e carrior_type;
+ char *buffer;
+ int len;
+
+ switch (carrier) {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ carrior_type = NFC_AC_TYPE_BT;
+ buffer = __get_bt_address_string(ac_data);
+ len = strlen(buffer);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS :
+ carrior_type = NFC_AC_TYPE_WIFI;
+ buffer = __get_bt_address_string(ac_data);
+ len = strlen(buffer);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P :
+ carrior_type = NFC_AC_TYPE_WIFI_DIRECT;
+ buffer = __get_bt_address_string(ac_data);
+ len = strlen(buffer);
+ break;
+
+ default :
+ carrior_type = NFC_AC_TYPE_UNKNOWN;
+ buffer = NULL;
+ len = 0;
+ break;
+ }
+
+ callback(_convert_error_code(__func__, result),
+ carrior_type, (void *)buffer,
+ len, user_param);
+
+ if (buffer != NULL) {
+ g_free(buffer);
+ }
+ }
+
+ g_variant_unref((GVariant *)user_data);
+}
+
+int nfc_p2p_connection_handover(nfc_p2p_target_h target,
+ nfc_ac_type_e type,
+ nfc_p2p_connection_handover_completed_cb callback,
+ void *user_data)
+{
+ int ret;
+ net_nfc_conn_handover_carrier_type_e net_ac_type =
+ NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+ GVariant *parameter;
+
+ LOG_BEGIN();
+
+ if (target == NULL)
+ return _return_invalid_param(__func__);
+
+ if (type > NFC_AC_TYPE_UNKNOWN)
+ return _return_invalid_param(__func__);
+
+ if (!nfc_manager_is_activated()) {
+ return NFC_ERROR_NOT_ACTIVATED;
+ }
+
+ switch (type)
+ {
+ case NFC_AC_TYPE_BT :
+ net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ break;
+
+ case NFC_AC_TYPE_WIFI :
+ net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS;
+ break;
+
+ case NFC_AC_TYPE_WIFI_DIRECT :
+ net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P;
+ break;
+
+ case NFC_AC_TYPE_UNKNOWN :
+ net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+ break;
+
+ default:
+ break;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_p2p_connection_handover(
+ (net_nfc_target_handle_h)target,
+ net_ac_type,
+ _net_nfc_manager_p2p_handover_cb,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+bool nfc_p2p_is_supported_ac_type(nfc_ac_type_e carrier)
+{
+ bool result = false;
+
+ LOG_BEGIN();
+
+ if (carrier == NFC_AC_TYPE_BT)
+ result = true;
+
+ return result;
+}
+
+static void _connection_handover_event_cb(
+ net_nfc_handover_event_e event,
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e carrier,
+ data_h ac_data,
+ data_h ndef_message,
+ void *user_data)
+{
+ LOG_BEGIN();
+
+ if (gdbus_nfc_context.on_handover_event_cb != NULL) {
+ nfc_ndef_message_h message;
+ nfc_ac_type_e type;
+ char *address;
+
+ net_nfc_create_ndef_message_from_rawdata(&message, ndef_message);
+
+ if (event == NET_NFC_HANDOVER_START) {
+ type = NFC_AC_TYPE_UNKNOWN;
+ address = NULL;
+ } else {
+ switch (carrier) {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ type = NFC_AC_TYPE_BT;
+ address = __get_bt_address_string(ac_data);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS :
+ type = NFC_AC_TYPE_WIFI;
+ address = __get_bt_address_string(ac_data);
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P :
+ type = NFC_AC_TYPE_WIFI_DIRECT;
+ address = __get_bt_address_string(ac_data);
+ break;
+
+ default :
+ type = NFC_AC_TYPE_UNKNOWN;
+ address = NULL;
+ break;
+ }
+ }
+
+ gdbus_nfc_context.on_handover_event_cb(
+ _convert_error_code(__func__, result),
+ event,
+ type,
+ address,
+ message,
+ gdbus_nfc_context.on_handover_event_user_data);
+
+ if (address != NULL) {
+ g_free(address);
+ }
+ net_nfc_free_ndef_message(message);
+ }
+
+ LOG_END();
+}
+
+
+int nfc_connection_handover_set_event_cb(nfc_connection_handover_event_cb callback, void *user_data)
+{
+ if (callback == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ gdbus_nfc_context.on_handover_event_cb = callback;
+ gdbus_nfc_context.on_handover_event_user_data = user_data;
+
+ net_nfc_client_handover_set_handover_event_cb(_connection_handover_event_cb, NULL);
+
+ return NFC_ERROR_NONE;
+}
+
+int nfc_connection_handover_unset_event_cb(void)
+{
+ net_nfc_client_handover_unset_handover_event_cb();
+
+ gdbus_nfc_context.on_handover_event_cb = NULL;
+ gdbus_nfc_context.on_handover_event_user_data = NULL;
+
+ return NFC_ERROR_NONE;
+}
+/**********************P2P functions************************************/
+
+static void _p2p_send_cb(net_nfc_error_e result,
+ void *user_data)
+{
+ nfc_p2p_send_completed_cb callback;
+ void *user_param;
+
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
+ }
+
+ g_variant_unref((GVariant *)user_data);
+}
+
+int nfc_p2p_send(nfc_p2p_target_h target,
+ nfc_ndef_message_h message,
+ nfc_p2p_send_completed_cb callback,
+ void *user_data)
+{
+ int ret;
+ data_h rawdata;
+ GVariant *parameter;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (target == NULL || message == NULL)
+ return _return_invalid_param(__func__);
+
+ if (!nfc_manager_is_activated())
+ return NFC_ERROR_NOT_ACTIVATED;
+
+ if (_check_app_permission() == false)
+ {
+ LOGE("permission check fail");
+
+ return NFC_ERROR_SECURITY_RESTRICTED;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ net_nfc_create_rawdata_from_ndef_message(message, &rawdata);
+ ret = net_nfc_client_p2p_send((net_nfc_target_handle_h)target,
+ rawdata,
+ _p2p_send_cb,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+
+ net_nfc_free_data(rawdata);
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_p2p_send_no_permission(
+ nfc_p2p_target_h target,
+ nfc_ndef_message_h message,
+ nfc_p2p_send_completed_cb callback,
+ void *user_data)
+{
+ int ret;
+ data_h rawdata;
+ GVariant *parameter;
+
+ LOG_BEGIN();
+
+ if (target == NULL || message == NULL)
+ return _return_invalid_param(__func__);
+
+ if (!nfc_manager_is_activated())
+ return NFC_ERROR_NOT_ACTIVATED;
+
+ /* skip check app permission */
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ net_nfc_create_rawdata_from_ndef_message(message, &rawdata);
+ ret = net_nfc_client_p2p_send((net_nfc_target_handle_h)target,
+ rawdata,
+ _p2p_send_cb,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+
+ net_nfc_free_data(rawdata);
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+static void _net_nfc_manager_p2p_set_data_received_cb(data_h data,
+ void *user_data)
+{
+ LOG_BEGIN();
+
+ if (gdbus_nfc_context.on_p2p_recv_cb != NULL)
+ {
+ ndef_message_h ndef_message;
+
+ net_nfc_create_ndef_message_from_rawdata(&ndef_message, data);
+
+ gdbus_nfc_context.on_p2p_recv_cb(
+ (nfc_p2p_target_h)(gdbus_nfc_context.current_target),
+ ndef_message,
+ gdbus_nfc_context.on_p2p_recv_user_data);
+
+ net_nfc_free_ndef_message(ndef_message);
+ }
+}
+
+int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target,
+ nfc_p2p_data_received_cb callback,
+ void *user_data)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (target == NULL || callback == NULL)
+ return _return_invalid_param(__func__);
+
+ if (gdbus_nfc_context.current_target != target)
+ return _return_invalid_param(__func__);
+
+ gdbus_nfc_context.on_p2p_recv_cb = callback;
+ gdbus_nfc_context.on_p2p_recv_user_data = user_data;
+
+ net_nfc_client_p2p_set_data_received(
+ _net_nfc_manager_p2p_set_data_received_cb,
+ NULL);
+
+ return NFC_ERROR_NONE;
+}
+
+int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (target == NULL)
+ return _return_invalid_param(__func__);
+
+ if (gdbus_nfc_context.current_target != target)
+ return _return_invalid_param(__func__);
+
+ net_nfc_client_p2p_unset_data_received();
+
+ gdbus_nfc_context.on_p2p_recv_cb = NULL;
+ gdbus_nfc_context.on_p2p_recv_user_data = NULL;
+
+ return NFC_ERROR_NONE;
+}
+
+int nfc_manager_set_p2p_target_discovered_cb(
+ nfc_p2p_target_discovered_cb callback,
+ void *user_data)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ return _return_invalid_param(__func__);
+
+ net_nfc_client_p2p_set_device_discovered(_p2p_target_discovered_cb,
+ NULL);
+ net_nfc_client_p2p_set_device_detached(_p2p_device_detached, NULL);
+
+ gdbus_nfc_context.on_p2p_target_discovered_cb = callback;
+ gdbus_nfc_context.on_p2p_target_discovered_user_data = user_data;
+
+ return NFC_ERROR_NONE;
+}
+
+void nfc_manager_unset_p2p_target_discovered_cb(void)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ if(_is_initialized() == false)
+ {
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
+ }
+
+ gdbus_nfc_context.on_p2p_target_discovered_cb = NULL;
+ gdbus_nfc_context.on_p2p_target_discovered_user_data = NULL;
+
+ set_last_result(NFC_ERROR_NONE);
+}
+
+/******************************SNEP***********************************/
+
+static void _net_nfc_manager_snep_start_server(
+ net_nfc_snep_handle_h arg_handle,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ nfc_ndef_message_h msg,
+ void *user_data)
+{
+ nfc_snep_event_cb callback;
+ void *user_param;
+
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ nfc_snep_event_e snep_event;
+
+ switch ((int)event) {
+ case NET_NFC_SNEP_GET :
+ snep_event = NFC_SNEP_EVENT_GET;
+ break;
+
+ case NET_NFC_SNEP_PUT :
+ snep_event = NFC_SNEP_EVENT_PUT;
+ break;
+
+ case NET_NFC_LLCP_REGISTERED :
+ snep_event = NFC_SNEP_EVENT_REGISTER;
+ break;
+
+ case NET_NFC_LLCP_UNREGISTERED :
+ snep_event = NFC_SNEP_EVENT_UNREGISTER;
+ break;
+
+ case NET_NFC_LLCP_START :
+ snep_event = NFC_SNEP_EVENT_START;
+ break;
+
+ case NET_NFC_LLCP_STOP :
+ default :
+ snep_event = NFC_SNEP_EVENT_STOP;
+ break;
+ }
+
+ callback(arg_handle, snep_event,
+ _convert_error_code(__func__, result),
+ msg, user_param);
+
+ if (snep_event == NFC_SNEP_EVENT_STOP) {
+ g_variant_unref(user_data);
+ }
+ }
+}
+
+int nfc_snep_start_server(nfc_p2p_target_h target,
+ const char *san,
+ int sap,
+ nfc_snep_event_cb callback,
+ void *user_data)
+{
+ int ret;
+ net_nfc_error_e result;
+ GVariant *parameter;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (target == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ result = net_nfc_client_snep_start_server(
+ (net_nfc_target_handle_h)target,
+ san,
+ (sap_t)sap,
+ _net_nfc_manager_snep_start_server,
+ parameter);
+ if (result != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+static void _net_nfc_manager_snep_start_client(
+ net_nfc_snep_handle_h arg_handle,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ nfc_ndef_message_h msg,
+ void *user_data)
+{
+ nfc_snep_event_cb callback;
+ void *user_param;
+
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ nfc_snep_event_e snep_event;
+
+ switch ((int)event) {
+ case NET_NFC_SNEP_GET :
+ snep_event = NFC_SNEP_EVENT_GET;
+ break;
+
+ case NET_NFC_SNEP_PUT :
+ snep_event = NFC_SNEP_EVENT_PUT;
+ break;
+
+ case NET_NFC_LLCP_REGISTERED :
+ snep_event = NFC_SNEP_EVENT_REGISTER;
+ break;
+
+ case NET_NFC_LLCP_UNREGISTERED :
+ snep_event = NFC_SNEP_EVENT_UNREGISTER;
+ break;
+
+ case NET_NFC_LLCP_START :
+ snep_event = NFC_SNEP_EVENT_START;
+ break;
+
+ case NET_NFC_LLCP_STOP :
+ default :
+ snep_event = NFC_SNEP_EVENT_STOP;
+ break;
+ }
+
+ callback(arg_handle, snep_event,
+ _convert_error_code(__func__, result),
+ msg, user_param);
+
+ if (snep_event == NFC_SNEP_EVENT_STOP) {
+ g_variant_unref(user_data);
+ }
+ }
+}
+
+int nfc_snep_start_client(nfc_p2p_target_h target,
+ const char *san,
+ int sap,
+ nfc_snep_event_cb callback,
+ void *user_data)
+{
+ int ret;
+ net_nfc_error_e result;
+ GVariant *parameter;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (target == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ result = net_nfc_client_snep_start_client(
+ (net_nfc_target_handle_h)target,
+ san,
+ (sap_t)sap,
+ _net_nfc_manager_snep_start_client,
+ parameter);
+ if (result != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+static void _net_nfc_manager_snep_send_request(
+ net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+{
+ nfc_snep_event_cb callback;
+ void *user_param;
+
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ callback((nfc_p2p_snep_h)target,
+ event,
+ _convert_error_code(__func__, result),
+ (nfc_ndef_message_h)msg,
+ user_param);
+ }
+
+ g_variant_unref((GVariant *)user_data);
+}
+
+int nfc_snep_send_client_request(nfc_p2p_snep_h handle,
+ nfc_snep_type_e type,
+ nfc_ndef_message_h msg,
+ nfc_snep_event_cb callback,
+ void *user_data)
+{
+ int ret;
+ net_nfc_error_e result;
+ GVariant *parameter;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (handle == NULL || msg == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ result = net_nfc_client_snep_send_client_request(
+ (net_nfc_target_handle_h)handle,
+ type,
+ msg,
+ _net_nfc_manager_snep_send_request,
+ parameter);
+ if (result != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+static void _snep_event_cb(net_nfc_snep_handle_h target,
+ net_nfc_snep_type_t event,
+ net_nfc_error_e result,
+ ndef_message_h msg,
+ void *user_data)
+{
+ nfc_snep_event_cb callback;
+ void *user_param;
+
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
+
+ if (callback != NULL) {
+ switch ((int)event) {
+ case NET_NFC_SNEP_GET :
+ event = NFC_SNEP_EVENT_GET;
+ break;
+
+ case NET_NFC_SNEP_PUT :
+ event = NFC_SNEP_EVENT_PUT;
+ break;
+
+ case NET_NFC_LLCP_REGISTERED :
+ event = NFC_SNEP_EVENT_REGISTER;
+ break;
+
+ case NET_NFC_LLCP_UNREGISTERED :
+ event = NFC_SNEP_EVENT_UNREGISTER;
+ break;
+
+ case NET_NFC_LLCP_START :
+ event = NFC_SNEP_EVENT_START;
+ break;
+
+ case NET_NFC_LLCP_STOP :
+ event = NFC_SNEP_EVENT_STOP;
+ break;
+ }
+
+ callback(target, event,
+ _convert_error_code(__func__, result),
+ (ndef_message_h)msg, user_param);
+ }
+}
+
+int nfc_snep_register_server(const char *san, int sap,
+ nfc_snep_event_cb callback, void *user_data)
+{
+ int ret;
+ net_nfc_error_e result;
+ GVariant *parameter;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (san == NULL || sap == 0) {
+ return _return_invalid_param(__func__);
+ }
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ result = net_nfc_client_snep_register_server(san, (sap_t)sap,
+ _snep_event_cb, parameter);
+ if (result != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_snep_unregister_server(const char *san, int sap)
+{
+ net_nfc_error_e result;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ result = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (result != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ result = net_nfc_client_snep_unregister_server(san, (sap_t)sap);
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_snep_stop_service(nfc_p2p_target_h target, nfc_p2p_snep_h clients)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ ret = net_nfc_client_snep_stop_service_sync(target, clients);
+
+ return _convert_error_code(__func__, ret);
+}
+
+/******************************Secure Element***********************************/
+
+/* nfc_manager_set_card_emulation_se_typewill be delete. use nfc_manager_set_se_type */
+int nfc_manager_set_card_emulation_se_type(
+ nfc_se_type_e type,
+ nfc_set_card_emulation_completed_cb callback,
+ void *user_data)
+{
+ int ret = NET_NFC_NOT_SUPPORTED;
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_manager_set_se_type(nfc_se_type_e type)
+{
+ int ret;
+ net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if ((type < NFC_SE_TYPE_DISABLE) || (type > NFC_SE_TYPE_UICC))
+ {
+ return _return_invalid_param(__func__);
+ }
+
+ switch (type)
+ {
+ case NFC_SE_TYPE_DISABLE :
+ se_type = NET_NFC_SE_TYPE_NONE;
+ break;
+ case NFC_SE_TYPE_ESE :
+ se_type = NET_NFC_SE_TYPE_ESE;
+ break;
+ case NFC_SE_TYPE_UICC :
+ se_type = NET_NFC_SE_TYPE_UICC;
+ break;
+ }
+
+ ret = net_nfc_client_se_set_secure_element_type_sync(se_type);
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_manager_get_se_type(nfc_se_type_e *type)
+{
+ int ret;
+ net_nfc_se_type_e se_type = NET_NFC_SE_TYPE_NONE;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (type == NULL)
+ {
+ return _return_invalid_param(__func__);
+ }
+
+ ret = net_nfc_client_se_get_secure_element_type_sync(&se_type);
+
+ switch (se_type)
+ {
+ case NET_NFC_SE_TYPE_ESE :
+ *type = NFC_SE_TYPE_ESE;
+ break;
+ case NET_NFC_SE_TYPE_UICC :
+ *type = NFC_SE_TYPE_UICC;
+ break;
+ default:
+ *type = NFC_SE_TYPE_DISABLE;
+ break;
+ }
+
+ return _convert_error_code(__func__, ret);
+}
+
+/* nfc_manager_get_card_emulation_se_type will be delete */
+int nfc_manager_get_card_emulation_se_type(nfc_se_type_e *type)
+{
+ int ret = NET_NFC_NOT_SUPPORTED;
+
+ return _convert_error_code(__func__, ret);
+}
+
+int nfc_se_open_secure_element_internal(
+ nfc_se_type_e se_type,
+ nfc_se_h *handle)
+{
+ net_nfc_error_e result;
+ net_nfc_se_type_e type;
+ net_nfc_target_handle_h temp = NULL;
+
+ LOG_BEGIN();
+
+ switch (se_type)
+ {
+ case NFC_SE_TYPE_ESE :
+ type = NET_NFC_SE_TYPE_ESE;
+ break;
+
+ case NFC_SE_TYPE_UICC :
+ type = NET_NFC_SE_TYPE_UICC;
+ break;
+
+ default:
+ return NFC_ERROR_INVALID_PARAMETER;
+ break;
+ }
+
+ result = net_nfc_client_se_open_internal_secure_element_sync(
+ type,
+ &temp);
+ if (result == NET_NFC_OK) {
+ *handle = (nfc_se_h)temp;
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_se_send_apdu_internal(nfc_se_h handle,
+ unsigned char *cmd,
+ unsigned int cmd_len,
+ unsigned char **resp,
+ unsigned int *resp_len)
+{
+ net_nfc_error_e result;
+ data_h command = NULL;
+
+ LOG_BEGIN();
+
+ if (handle == NULL || cmd == NULL || cmd_len == 0 ||
+ resp == NULL || resp_len == NULL ) {
+ return _return_invalid_param(__func__);
+ }
+
+ if (cmd_len == 3 && cmd[0] == 'A' && cmd[1] == 'T' && cmd[2] == 'R') {
+ LOG_DEBUG("cheat... invoke get atr");
+ return nfc_se_get_atr_internal(handle, resp, resp_len);
+ }
+
+ *resp = NULL;
+ *resp_len = 0;
+
+ result = net_nfc_create_data(&command, cmd, cmd_len);
+ if (result == NET_NFC_OK) {
+ data_h response = NULL;
+
+ result = net_nfc_client_se_send_apdu_sync(
+ (net_nfc_target_handle_h)handle,
+ command,
+ &response);
+ if (result == NET_NFC_OK && response != NULL) {
+ uint8_t *buffer;
+ uint32_t length;
+
+ buffer = net_nfc_get_data_buffer(response);
+ length = net_nfc_get_data_length(response);
+
+ if (buffer != NULL && length > 0) {
+ *resp = calloc(1, length);
+ if (*resp != NULL) {
+ memcpy(*resp, buffer, length);
+ *resp_len = length;
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ result = NET_NFC_NO_DATA_FOUND;
+ }
+
+ net_nfc_free_data(response);
+ }
+
+ net_nfc_free_data(command);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", result);
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_se_get_atr_internal(nfc_se_h handle, unsigned char **atr, unsigned int *atr_len)
+{
+ net_nfc_error_e result;
+ data_h response = NULL;
+
+ LOG_BEGIN();
+
+ if (handle == NULL || atr == NULL || atr_len == NULL) {
+ return _return_invalid_param(__func__);
+ }
+
+ *atr = NULL;
+ *atr_len = 0;
+
+ result = net_nfc_client_se_get_atr_sync(
+ (net_nfc_target_handle_h)handle,
+ &response);
+ if (result == NET_NFC_OK && response != NULL) {
+ uint8_t *buffer;
+ uint32_t length;
+
+ buffer = net_nfc_get_data_buffer(response);
+ length = net_nfc_get_data_length(response);
+
+ if (buffer != NULL && length > 0) {
+ *atr = calloc(1, length);
+ if (*atr != NULL) {
+ memcpy(*atr, buffer, length);
+ *atr_len = length;
+ } else {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ result = NET_NFC_NO_DATA_FOUND;
+ }
+
+ net_nfc_free_data(response);
+ }
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_se_close_secure_element_internal(nfc_se_h handle)
+{
+ net_nfc_error_e result;
+
+ LOG_BEGIN();
+
+ result = net_nfc_client_se_close_internal_secure_element_sync(
+ (net_nfc_target_handle_h)handle);
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_se_enable_card_emulation()
+{
+ net_nfc_error_e result;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ result = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (result != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMELATION_ENABLE);
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_se_disable_card_emulation()
+{
+ net_nfc_error_e result;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ result = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (result != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMULATION_DISABLE);
+
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_se_get_card_emulation_mode(nfc_se_card_emulation_mode_type_e *mode)
+{
+ net_nfc_error_e result;
+ net_nfc_card_emulation_mode_t se_mode;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ result = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (result != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (mode == NULL)
+ {
+ return _return_invalid_param(__func__);
+ }
+
+ result = net_nfc_get_card_emulation_mode_sync(&se_mode);
+
+ switch(se_mode)
+ {
+ case NET_NFC_CARD_EMELATION_ENABLE :
+ *mode = NFC_SE_CARD_EMULATION_MODE_ON;
+ break;
+
+ case NET_NFC_CARD_EMULATION_DISABLE :
+ *mode = NFC_SE_CARD_EMULATION_MODE_OFF;
+ break;
+ }
+
+ return _convert_error_code(__func__, result);;
+}
+
+int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ return _return_invalid_param(__func__);
+
+ net_nfc_client_se_set_event_cb(_se_event_cb, NULL);
+
+ gdbus_nfc_context.on_se_event_cb = callback;
+ gdbus_nfc_context.on_se_event_user_data = user_data;
+
+ return NFC_ERROR_NONE;
+}
+
+void nfc_manager_unset_se_event_cb(void)
+{
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ if(_is_initialized() == false)
+ {
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
+ }
+
+ gdbus_nfc_context.on_se_event_cb = NULL;
+ gdbus_nfc_context.on_se_event_user_data = NULL;
+
+ set_last_result(NFC_ERROR_NONE);
+}
+
+static void _se_transaction_event_cb(net_nfc_se_type_e se_type,
+ data_h aid,
+ data_h param,
+ void *user_data)
+{
+ LOG_BEGIN();
+
+ if (gdbus_nfc_context.on_se_transaction_event_cb != NULL) {
+ gdbus_nfc_context.on_se_transaction_event_cb(
+ se_type,
+ net_nfc_get_data_buffer(aid),
+ net_nfc_get_data_length(aid),
+ net_nfc_get_data_buffer(param),
+ net_nfc_get_data_length(param),
+ gdbus_nfc_context.on_se_transaction_event_user_data);
+ }
+}
+
+int nfc_manager_set_se_transaction_event_cb(
+ nfc_se_type_e se_type,
+ nfc_se_transaction_event_cb callback,
+ void *user_data)
+{
+ net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE;
+ int ret;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (callback == NULL)
+ return _return_invalid_param(__func__);
+
+ gdbus_nfc_context.on_se_transaction_event_cb = callback;
+ gdbus_nfc_context.on_se_transaction_event_user_data = user_data;
+
+ switch(se_type)
+ {
+ case NFC_SE_TYPE_ESE:
+ type = NET_NFC_SE_TYPE_ESE;
+ break;
+
+ case NFC_SE_TYPE_UICC:
+ type = NET_NFC_SE_TYPE_UICC;
+ break;
+ default:
+ return _return_invalid_param(__func__);
+ break;
+
+ }
+
+ net_nfc_client_se_set_transaction_event_cb(type, _se_transaction_event_cb, user_data);
+
+ return NFC_ERROR_NONE;
+}
+
+void nfc_manager_unset_se_transaction_event_cb(nfc_se_type_e se_type)
+{
+ int ret;
+ int nfc_supported = 0;
+ net_nfc_se_type_e type = NET_NFC_SE_TYPE_NONE;
+
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ set_last_result(NFC_ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ if(_is_initialized() == false)
+ {
+ set_last_result(NFC_ERROR_NOT_INITIALIZED);
+ return;
+ }
+
+ switch(se_type)
+ {
+ case NFC_SE_TYPE_ESE:
+ type = NET_NFC_SE_TYPE_ESE;
+ break;
+
+ case NFC_SE_TYPE_UICC:
+ type = NET_NFC_SE_TYPE_UICC;
+ break;
+ default:
+ type = NET_NFC_SE_TYPE_NONE;
+ break;
}
+ net_nfc_client_se_unset_transaction_event_cb(type);
- memset(*mime_type, 0 , length+1);
- memcpy(*mime_type, typename , length );
- return 0;
+ set_last_result(NFC_ERROR_NONE);
}
-int nfc_ndef_record_destroy(nfc_ndef_record_h record)
+int nfc_manager_enable_transaction_fg_dispatch()
{
- int ret;
+ net_nfc_error_e result;
+ int nfc_supported = 0;
- if(record == NULL )
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- ret = net_nfc_free_record(record);
- return _convert_error_code(__func__, ret);
-}
+ result = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (result != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
-int nfc_ndef_record_set_id (nfc_ndef_record_h record, unsigned char *id , int id_size)
-{
- int ret;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if (record == NULL || id == NULL || id_size <= 0)
- return _return_invalid_param(__func__);
+ result = net_nfc_client_se_set_transaction_fg_dispatch(true);
- data_s id_data = {id, id_size};
- ret = net_nfc_set_record_id(record, (data_h)&id_data);
- return _convert_error_code(__func__, ret);
+ return _convert_error_code(__func__, result);
}
-int nfc_ndef_record_get_payload (nfc_ndef_record_h record,
- unsigned char ** payload, unsigned int *size)
+int nfc_manager_disable_transaction_fg_dispatch()
{
- int ret ;
+ net_nfc_error_e result;
+ int nfc_supported = 0;
- if(record == NULL || payload == NULL || size == NULL )
- return _return_invalid_param(__func__);
+ result = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (result != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
- data_s *payload_data;
- ret = net_nfc_get_record_payload(record, (data_h*)&payload_data);
- if( ret == 0){
- *payload = payload_data->buffer;
- *size = payload_data->length;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
}
- return _convert_error_code(__func__, ret);
+
+ result = net_nfc_client_se_set_transaction_fg_dispatch(false);
+
+ return _convert_error_code(__func__, result);
}
-int nfc_ndef_record_get_type (nfc_ndef_record_h record, unsigned char ** type, int *size)
+/************************************Raw Data- Transceive*********************/
+
+static void _net_nfc_manager_tag_transceive_data(net_nfc_error_e result,
+ data_h arg_data,
+ void *user_data)
{
- int ret ;
- data_s *type_data;
+ nfc_tag_transceive_completed_cb callback;
+ void *user_param;
- if (record == NULL || type == NULL || size == NULL)
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- ret = net_nfc_get_record_type(record, (data_h*)&type_data);
- if( ret == 0){
- *type = type_data->buffer;
- *size = type_data->length;
+ if (user_data == NULL) {
+ return;
}
- return _convert_error_code(__func__, ret);
-}
-int nfc_ndef_record_get_id (nfc_ndef_record_h record, unsigned char **id , int *size)
-{
- int ret ;
- data_s *id_data;
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if(record == NULL || id == NULL || size == NULL )
- return _return_invalid_param(__func__);
+ if (callback != NULL) {
+ uint8_t *buffer = NULL;
+ uint32_t length = 0;
- ret = net_nfc_get_record_id(record, (data_h*)&id_data);
- if( ret == 0){
- *id = id_data->buffer;
- *size = id_data->length;
+ if (result == NET_NFC_OK && arg_data != NULL) {
+ buffer = net_nfc_get_data_buffer(arg_data);
+ length = net_nfc_get_data_length(arg_data);
+ }
+
+ callback(_convert_error_code(__func__, result),
+ buffer,
+ length,
+ user_param);
}
- return _convert_error_code(__func__, ret);
+
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_ndef_record_get_tnf(nfc_ndef_record_h record, nfc_record_tnf_e * tnf)
+int nfc_tag_transceive(nfc_tag_h tag,
+ unsigned char *buffer,
+ int buffer_size,
+ nfc_tag_transceive_completed_cb callback,
+ void *user_data)
{
int ret;
+ data_h rawdata = NULL;
+ int nfc_supported = 0;
- if(record == NULL || tnf == NULL )
- return _return_invalid_param(__func__);
-
- ret = net_nfc_get_record_tnf(record, (net_nfc_record_tnf_e*)tnf);
- return _convert_error_code(__func__, ret);
-}
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
-int nfc_ndef_record_get_text(nfc_ndef_record_h record, char** buffer)
-{
- int ret;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if(record == NULL || buffer == NULL)
+ if (tag == NULL || buffer == NULL || buffer_size <= 0)
return _return_invalid_param(__func__);
- ret = net_nfc_create_text_string_from_text_record(record, buffer);
- return _convert_error_code(__func__, ret);
-}
+ if (!nfc_manager_is_activated())
+ {
+ return NFC_ERROR_NOT_ACTIVATED;
+ }
-int nfc_ndef_record_get_langcode(nfc_ndef_record_h record, char **lang_code)
-{
- int ret;
+ if (_check_app_permission() == false)
+ {
+ LOGE("permission check fail");
- if(record == NULL || lang_code == NULL)
- return _return_invalid_param(__func__);
+ return NFC_ERROR_SECURITY_RESTRICTED;
+ }
- ret = net_nfc_get_languange_code_string_from_text_record(record, lang_code);
- return _convert_error_code(__func__, ret);
-}
-int nfc_ndef_record_get_encode_type(nfc_ndef_record_h record, nfc_encode_type_e *encode)
-{
- int ret=0;
+ ret = net_nfc_create_data(&rawdata, buffer, buffer_size);
+ if (ret == NET_NFC_OK) {
+ net_nfc_target_handle_h handle = NULL;
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_transceive_data(
+ handle,
+ rawdata,
+ _net_nfc_manager_tag_transceive_data,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
- if(record == NULL || encode == NULL )
- return _return_invalid_param(__func__);
+ net_nfc_free_data(rawdata);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
+ }
- ret = net_nfc_get_encoding_type_from_text_record(record, (net_nfc_encode_type_e*)encode);
- // if( ret == NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE)
- // LOGE("%s reord type is not text type");
return _convert_error_code(__func__, ret);
}
-int nfc_ndef_record_get_uri(nfc_ndef_record_h record , char **uri)
+
+/*********************************Mifare*********************************/
+/* FIXME */
+static void _net_nfc_manager_mifare_authenticate_with_keyA(
+ net_nfc_error_e result,
+ void *user_data)
{
- int ret=0;
+ nfc_mifare_authenticate_with_keyA_completed_cb callback;
+ void *user_param;
- if(record == NULL || uri == NULL )
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- ret = net_nfc_create_uri_string_from_uri_record(record, uri);
- return _convert_error_code(__func__, ret);
-}
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
-int nfc_ndef_message_create(nfc_ndef_message_h* ndef_message)
-{
- int ret = 0;
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if( ndef_message == NULL )
- return _return_invalid_param(__func__);
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
+ }
- ret = net_nfc_create_ndef_message(ndef_message);
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_ndef_message_create_from_rawdata(nfc_ndef_message_h* ndef_message,
- const unsigned char* rawdata, unsigned int rawdata_size)
+int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag,
+ int sector_index,
+ unsigned char *auth_key,
+ nfc_mifare_authenticate_with_keyA_completed_cb callback,
+ void *user_data)
{
- int ret = 0;
+ int ret;
+ data_h auth_key_data = NULL;
+ int nfc_supported = 0;
- if (ndef_message == NULL || rawdata == NULL || rawdata_size <= 0)
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
+
+ if (tag == NULL || auth_key == NULL)
return _return_invalid_param(__func__);
- data_s rawdata_data = {(unsigned char *)rawdata, rawdata_size};
+ if (!nfc_manager_is_activated())
+ {
+ return NFC_ERROR_NOT_ACTIVATED;
+ }
+
+ ret = net_nfc_create_data(&auth_key_data, auth_key, 6);
+ if (ret == NET_NFC_OK) {
+ net_nfc_target_handle_h handle = NULL;
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_authenticate_with_keyA(
+ handle,
+ sector_index,
+ auth_key_data,
+ _net_nfc_manager_mifare_authenticate_with_keyA,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
- ret = net_nfc_create_ndef_message_from_rawdata((ndef_message_h*)ndef_message , (data_h)&rawdata_data);
+ net_nfc_free_data(auth_key_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
+ }
return _convert_error_code(__func__, ret);
}
-int nfc_ndef_message_destroy(nfc_ndef_message_h ndef_message)
+static void _net_nfc_manager_mifare_authenticate_with_keyB(
+ net_nfc_error_e result,
+ void *user_data)
{
- int ret = 0;
+ nfc_mifare_authenticate_with_keyB_completed_cb callback;
+ void *user_param;
- if( ndef_message == NULL )
- return _return_invalid_param(__func__);
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
- ret = net_nfc_free_ndef_message(ndef_message);
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- return _convert_error_code(__func__, ret);
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
+ }
+
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_ndef_message_get_record_count(nfc_ndef_message_h ndef_message , int *count)
+int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag,
+ int sector_index,
+ unsigned char *auth_key,
+ nfc_mifare_authenticate_with_keyB_completed_cb callback,
+ void *user_data)
{
- int ret = 0;
-
- if( ndef_message == NULL || count == NULL)
- return _return_invalid_param(__func__);
+ int ret;
+ data_h auth_key_data = NULL;
+ int nfc_supported = 0;
- ret = net_nfc_get_ndef_message_record_count(ndef_message , count);
+ LOG_BEGIN();
- return _convert_error_code(__func__, ret);
-}
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
-int nfc_ndef_message_get_rawdata(nfc_ndef_message_h ndef_message ,
- unsigned char ** rawdata , unsigned int *rawdata_size)
-{
- int ret=0;
- data_s *rawdata_data = NULL;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if (ndef_message == NULL || rawdata == NULL || rawdata_size == NULL )
+ if (tag == NULL || auth_key == NULL)
return _return_invalid_param(__func__);
- *rawdata = NULL;
- *rawdata_size = 0;
+ if (!nfc_manager_is_activated())
+ {
+ return NFC_ERROR_NOT_ACTIVATED;
+ }
- ret = net_nfc_create_rawdata_from_ndef_message(ndef_message, (data_h *)&rawdata_data);
+ ret = net_nfc_create_data(&auth_key_data, auth_key, 6);
if (ret == NET_NFC_OK) {
- *rawdata = calloc(1, rawdata_data->length);
- if (*rawdata != NULL) {
- memcpy(*rawdata, rawdata_data->buffer, rawdata_data->length);
- *rawdata_size = rawdata_data->length;
+ net_nfc_target_handle_h handle = NULL;
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_authenticate_with_keyB(
+ handle,
+ sector_index,
+ auth_key_data,
+ _net_nfc_manager_mifare_authenticate_with_keyB,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
} else {
- ret = NET_NFC_ALLOC_FAIL;
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
}
- net_nfc_free_data((data_h)rawdata_data);
+
+ net_nfc_free_data(auth_key_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
}
return _convert_error_code(__func__, ret);
}
-int nfc_ndef_message_get_rawdata_size(nfc_ndef_message_h ndef_message,
- unsigned int *byte_size)
+/* FIXME */
+static void _net_nfc_manager_mifare_read_block(net_nfc_error_e result,
+ data_h data,
+ void *user_data)
{
- int ret = 0;
+ nfc_mifare_read_block_completed_cb callback;
+ void *user_param;
- if( ndef_message == NULL || byte_size == NULL)
- return _return_invalid_param(__func__);
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
- ret = net_nfc_get_ndef_message_byte_length(ndef_message, byte_size);
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- return _convert_error_code(__func__, ret);
-}
+ if (callback != NULL) {
+ uint8_t *buffer = NULL;
+ int length = 0;
-int nfc_ndef_message_append_record(nfc_ndef_message_h ndef_message , nfc_ndef_record_h record)
-{
- int ret=0;
+ if (result == NET_NFC_OK && data != NULL) {
+ buffer = net_nfc_get_data_buffer(data);
+ length = net_nfc_get_data_length(data);
+ }
- if( ndef_message == NULL || record == NULL)
- return _return_invalid_param(__func__);
+ callback(_convert_error_code(__func__, result),
+ buffer,
+ length,
+ user_param);
+ }
- ret = net_nfc_append_record_to_ndef_message(ndef_message , record );
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_ndef_message_insert_record(nfc_ndef_message_h ndef_message , int index, nfc_ndef_record_h record)
+int nfc_mifare_read_block(nfc_tag_h tag,
+ int block_index,
+ nfc_mifare_read_block_completed_cb callback,
+ void *user_data)
{
- int ret=0;
+ int ret;
+ net_nfc_target_handle_h handle = NULL;
+ int nfc_supported = 0;
- if( ndef_message == NULL || record == NULL )
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- ret = net_nfc_append_record_by_index(ndef_message , index , record);
- return _convert_error_code(__func__, ret);
-}
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
-int nfc_ndef_message_remove_record(nfc_ndef_message_h ndef_message , int index)
-{
- int ret=0;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if( ndef_message == NULL )
+ if (tag == NULL)
return _return_invalid_param(__func__);
- ret = net_nfc_remove_record_by_index(ndef_message , index);
- return _convert_error_code(__func__, ret);
-}
-
-int nfc_ndef_message_get_record(nfc_ndef_message_h ndef_message , int index , nfc_ndef_record_h *record)
-{
- int ret=0;
-
- if( ndef_message == NULL || record == NULL)
- return _return_invalid_param(__func__);
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_read(
+ handle,
+ block_index,
+ _net_nfc_manager_mifare_read_block,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
- ret = net_nfc_get_record_by_index(ndef_message , index , (ndef_record_h*)record);
return _convert_error_code(__func__, ret);
}
-int nfc_tag_get_type( nfc_tag_h tag , nfc_tag_type_e *type)
+int nfc_mifare_read_page(nfc_tag_h tag,
+ int page_index,
+ nfc_mifare_read_page_completed_cb callback,
+ void *user_data)
{
- int ret=0;
+ int ret;
+ GVariant *parameter;
+ int nfc_supported = 0;
- if( tag == NULL || type == NULL)
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- ret = net_nfc_get_tag_type( tag, (net_nfc_target_type_e*) type);
- return _convert_error_code(__func__, ret);
-}
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
-int nfc_tag_is_support_ndef(nfc_tag_h tag, bool * is_support)
-{
- int ret=0;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
- if( tag == NULL || is_support== NULL)
+ if (tag == NULL)
return _return_invalid_param(__func__);
- ret = net_nfc_get_tag_ndef_support(tag , is_support);
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ /* FIXME : not implemented */
+// ret = net_nfc_client_mifare_read_block(tag,
+// page_index,
+// _mifare_read_page,
+// parameter);
+// if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ ret = NET_NFC_OK;
+// }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+
return _convert_error_code(__func__, ret);
}
-int nfc_tag_get_maximum_ndef_size(nfc_tag_h tag , unsigned int * max_size)
+static void _net_nfc_manager_mifare_write_block(net_nfc_error_e result,
+ void *user_data)
{
- int ret=0;
+ nfc_mifare_write_block_completed_cb callback;
+ void *user_param;
- if( tag == NULL || max_size == NULL)
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- ret = net_nfc_get_tag_max_data_size(tag , max_size);
- return _convert_error_code(__func__, ret);
-}
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
-int nfc_tag_get_ndef_size(nfc_tag_h tag, unsigned int * actual_data_size)
-{
- int ret=0;
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if( tag == NULL || actual_data_size == NULL)
- return _return_invalid_param(__func__);
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
+ }
- ret = net_nfc_get_tag_actual_data_size(tag , actual_data_size);
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_tag_foreach_information(nfc_tag_h tag , nfc_tag_information_cb callback , void * user_data )
+int nfc_mifare_write_block(nfc_tag_h tag,
+ int block_index,
+ unsigned char *buffer,
+ int buffer_size,
+ nfc_mifare_write_block_completed_cb callback,
+ void *user_data)
{
- int i;
- net_nfc_tag_info_s *taglist = g_nfc_context.current_tag->tag_info_list;
+ int ret;
+ data_h block_data = NULL;
+ int nfc_supported = 0;
- if( tag == NULL || callback == NULL )
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- for(i=0; i<g_nfc_context.current_tag->number_of_keys; i++){
- bool cont;
- cont = callback(taglist[i].key, net_nfc_get_data_buffer(taglist[i].value), net_nfc_get_data_length(taglist[i].value), user_data);
- if( !cont )
- break;
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
+ {
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- return 0;
-}
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
-int nfc_tag_transceive( nfc_tag_h tag, unsigned char * buffer, int buffer_size, nfc_tag_transceive_completed_cb callback , void * user_data )
-{
if (tag == NULL || buffer == NULL || buffer_size <= 0)
return _return_invalid_param(__func__);
- if(!nfc_manager_is_activated())
+ if (!nfc_manager_is_activated())
{
return NFC_ERROR_NOT_ACTIVATED;
}
- if(_check_app_permission() == false)
- {
- LOGE("permission check fail");
- return NFC_ERROR_SECURITY_RESTRICTED;
- }
-
- int ret=0;
- data_s rawdata = { buffer, buffer_size };
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
+ ret = net_nfc_create_data(&block_data, buffer, buffer_size);
+ if (ret == NET_NFC_OK) {
+ net_nfc_target_handle_h handle = NULL;
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag,
+ &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_write_block(
+ handle,
+ block_index,
+ block_data,
+ _net_nfc_manager_mifare_write_block,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
- _async_callback_data * trans_data = NULL;
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_DATA;
+ net_nfc_free_data(block_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
}
- ret = net_nfc_transceive((net_nfc_target_handle_h)tag_info->handle , (data_h) &rawdata, trans_data );
-
return _convert_error_code(__func__, ret);
}
-int nfc_tag_read_ndef( nfc_tag_h tag, nfc_tag_read_completed_cb callback , void * user_data)
+static void _mifare_write_page(net_nfc_error_e result,
+ void *user_data)
{
- if( tag == NULL )
- return _return_invalid_param(__func__);
+ nfc_mifare_write_page_completed_cb callback;
+ void *user_param;
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
- }
+ LOG_BEGIN();
- int ret=0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
}
- ret = net_nfc_read_tag((net_nfc_target_handle_h)tag_info->handle , trans_data );
- return _convert_error_code(__func__, ret);
+
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_tag_write_ndef(nfc_tag_h tag, nfc_ndef_message_h msg , nfc_tag_write_completed_cb callback , void *user_data)
+int nfc_mifare_write_page(nfc_tag_h tag,
+ int page_index,
+ unsigned char *buffer,
+ int buffer_size,
+ nfc_mifare_write_page_completed_cb callback,
+ void *user_data)
{
+ int ret;
+ data_h block_data = NULL;
+ int nfc_supported = 0;
- int ret=0;
- unsigned int byte_size = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
- if (tag == NULL || msg == NULL)
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- if(!nfc_manager_is_activated())
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- if(_check_app_permission() == false)
+ if(_is_initialized() == false)
{
- LOGE("permission check fail");
- return NFC_ERROR_SECURITY_RESTRICTED;
+ return NFC_ERROR_NOT_INITIALIZED;
}
+ if (tag == NULL || buffer == NULL || buffer_size <= 0)
+ return _return_invalid_param(__func__);
- if (tag_info->ndefCardState == NET_NFC_NDEF_CARD_READ_ONLY )
+ if (!nfc_manager_is_activated())
{
- return NFC_ERROR_READ_ONLY_NDEF;
-
+ return NFC_ERROR_NOT_ACTIVATED;
}
- nfc_ndef_message_get_rawdata_size(msg , &byte_size);
+ ret = net_nfc_create_data(&block_data, buffer, buffer_size);
+ if (ret == NET_NFC_OK) {
+ net_nfc_target_handle_h handle = NULL;
+
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag,
+ &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_write_page(
+ handle,
+ page_index,
+ block_data,
+ _mifare_write_page,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
+ }
- if(tag_info->maxDataSize < byte_size)
- {
- return NFC_ERROR_NO_SPACE_ON_NDEF;
+ net_nfc_free_data(block_data);
+ } else {
+ LOG_ERR("net_nfc_create_data failed, [%d]", ret);
}
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- }
- ret = net_nfc_write_ndef( (net_nfc_target_handle_h)tag_info->handle , msg , trans_data );
return _convert_error_code(__func__, ret);
}
-int nfc_tag_format_ndef(nfc_tag_h tag , unsigned char * key, int key_size , nfc_tag_format_completed_cb callback, void * user_data )
+static void _net_nfc_manager_mifare_increment(net_nfc_error_e result,
+ void *user_data)
{
- if (tag == NULL || key == NULL || key_size <= 0)
- return _return_invalid_param(__func__);
+ nfc_mifare_increment_completed_cb callback;
+ void *user_param;
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
- }
+ LOG_BEGIN();
- if(_check_app_permission() == false)
- {
- LOGE("permission check fail");
- return NFC_ERROR_SECURITY_RESTRICTED;
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
}
- data_s key_data = { key, key_size };
- int ret=0;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- _async_callback_data * trans_data = NULL;
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
}
- ret = net_nfc_format_ndef( (net_nfc_target_handle_h)tag_info->handle, (data_h)&key_data, trans_data );
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag, int sector_index, unsigned char * auth_key, nfc_mifare_authenticate_with_keyA_completed_cb callback, void *user_data)
+int nfc_mifare_increment(nfc_tag_h tag,
+ int block_index,
+ int value,
+ nfc_mifare_increment_completed_cb callback,
+ void *user_data)
{
- if (tag == NULL || auth_key == NULL)
- return _return_invalid_param(__func__);
+ int ret;
+ net_nfc_target_handle_h handle = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
- if(!nfc_manager_is_activated())
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- data_s auth_key_data = { auth_key , 6};
- int ret = 0;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
- _async_callback_data * trans_data = NULL;
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
}
- ret = net_nfc_mifare_authenticate_with_keyA( (net_nfc_target_handle_h)tag_info->handle, sector_index, (data_h)&auth_key_data, trans_data);
- return _convert_error_code(__func__, ret);
-}
-
-int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag, int sector_index, unsigned char * auth_key, nfc_mifare_authenticate_with_keyB_completed_cb callback, void *user_data)
-{
- if (tag == NULL || auth_key == NULL)
+ if (tag == NULL )
return _return_invalid_param(__func__);
- if(!nfc_manager_is_activated())
+ if (!nfc_manager_is_activated())
{
return NFC_ERROR_NOT_ACTIVATED;
}
- data_s auth_key_data = { auth_key , 6};
- int ret = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_increment(
+ handle,
+ block_index,
+ value,
+ _net_nfc_manager_mifare_increment,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
}
- ret = net_nfc_mifare_authenticate_with_keyB( (net_nfc_target_handle_h)tag_info->handle, sector_index, (data_h)&auth_key_data, trans_data);
return _convert_error_code(__func__, ret);
}
-int nfc_mifare_read_block(nfc_tag_h tag, int block_index, nfc_mifare_read_block_completed_cb callback, void *user_data)
+static void _net_nfc_manager_mifare_decrement(net_nfc_error_e result,
+ void *user_data)
{
- if( tag == NULL )
- return _return_invalid_param(__func__);
+ nfc_mifare_decrement_completed_cb callback;
+ void *user_param;
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_BEGIN();
+
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
}
- int ret = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_DATA;
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
}
- ret = net_nfc_mifare_read( (net_nfc_target_handle_h)tag_info->handle, block_index, trans_data);
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_mifare_read_page(nfc_tag_h tag, int page_index, nfc_mifare_read_block_completed_cb callback, void *user_data)
+int nfc_mifare_decrement(nfc_tag_h tag,
+ int block_index,
+ int value,
+ nfc_mifare_decrement_completed_cb callback,
+ void *user_data)
{
- if (tag == NULL)
- return _return_invalid_param(__func__);
+ int ret;
+ net_nfc_target_handle_h handle = NULL;
+ int nfc_supported = 0;
+
+ LOG_BEGIN();
- if(!nfc_manager_is_activated())
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- return nfc_mifare_read_block(tag, page_index, callback, user_data);
-}
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
+ }
-int nfc_mifare_write_block (nfc_tag_h tag, int block_index, unsigned char* buffer, int buffer_size, nfc_mifare_write_block_completed_cb callback, void* user_data)
-{
- if (tag == NULL || buffer == NULL || buffer_size <= 0)
+ if (tag == NULL)
return _return_invalid_param(__func__);
- if(!nfc_manager_is_activated())
+ if (!nfc_manager_is_activated())
{
return NFC_ERROR_NOT_ACTIVATED;
}
- int ret = 0;
- data_s block_data = { buffer , buffer_size};
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_decrement(
+ handle,
+ block_index,
+ value,
+ _net_nfc_manager_mifare_decrement,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
}
- ret = net_nfc_mifare_write_block( (net_nfc_target_handle_h)tag_info->handle, block_index, (data_h)&block_data, trans_data);
return _convert_error_code(__func__, ret);
}
-int nfc_mifare_write_page(nfc_tag_h tag, int page_index, unsigned char* buffer, int buffer_size, nfc_mifare_write_block_completed_cb callback, void* user_data)
+static void _net_nfc_manager_mifare_transfer(net_nfc_error_e result,
+ void *user_data)
{
- if (tag == NULL || buffer == NULL || buffer_size <= 0)
- return _return_invalid_param(__func__);
-
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
- }
+ nfc_mifare_transfer_completed_cb callback;
+ void *user_param;
- int ret = 0;
- data_s block_data = { buffer , buffer_size};
- _async_callback_data * trans_data = NULL;
+ LOG_BEGIN();
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
}
- ret = net_nfc_mifare_write_page( (net_nfc_target_handle_h)tag_info->handle, page_index, (data_h)&block_data, trans_data);
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_mifare_increment(nfc_tag_h tag, int block_index, int value, nfc_mifare_increment_completed_cb callback, void *user_data)
+int nfc_mifare_transfer(nfc_tag_h tag,
+ int block_index,
+ nfc_mifare_transfer_completed_cb callback,
+ void *user_data)
{
- if( tag == NULL )
- return _return_invalid_param(__func__);
+ int ret;
+ net_nfc_target_handle_h handle = NULL;
+ int nfc_supported = 0;
- if(!nfc_manager_is_activated())
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- int ret = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
}
- ret = net_nfc_mifare_increment( (net_nfc_target_handle_h)tag_info->handle, block_index,value, trans_data);
- return _convert_error_code(__func__, ret);
-
-}
-
-int nfc_mifare_decrement(nfc_tag_h tag, int block_index, int value, nfc_mifare_decrement_completed_cb callback, void *user_data)
-{
- if( tag == NULL )
+ if (tag == NULL)
return _return_invalid_param(__func__);
- if(!nfc_manager_is_activated())
+ if (!nfc_manager_is_activated())
{
return NFC_ERROR_NOT_ACTIVATED;
}
- int ret = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
-
-
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_transfer(
+ handle,
+ block_index,
+ _net_nfc_manager_mifare_transfer,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
}
- ret = net_nfc_mifare_decrement( (net_nfc_target_handle_h)tag_info->handle, block_index,value, trans_data);
return _convert_error_code(__func__, ret);
}
-int nfc_mifare_transfer(nfc_tag_h tag, int block_index, nfc_mifare_transfer_completed_cb callback, void *user_data)
+static void _net_nfc_manager_mifare_restore(net_nfc_error_e result,
+ void *user_data)
{
- if( tag == NULL )
- return _return_invalid_param(__func__);
+ nfc_mifare_restore_completed_cb callback;
+ void *user_param;
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
- }
+ LOG_BEGIN();
- int ret = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
+ if (user_data == NULL) {
+ LOG_ERR("user_data is NULL");
+ return;
+ }
+ g_variant_get((GVariant *)user_data,
+ "(uu)",
+ (guint *)&callback,
+ (guint *)&user_param);
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ if (callback != NULL) {
+ callback(_convert_error_code(__func__, result), user_param);
}
- ret = net_nfc_mifare_transfer( (net_nfc_target_handle_h)tag_info->handle, block_index, trans_data);
- return _convert_error_code(__func__, ret);
+ g_variant_unref((GVariant *)user_data);
}
-int nfc_mifare_restore(nfc_tag_h tag, int block_index, nfc_mifare_restore_completed_cb callback, void *user_data)
+int nfc_mifare_restore(nfc_tag_h tag,
+ int block_index,
+ nfc_mifare_restore_completed_cb callback,
+ void *user_data)
{
- if( tag == NULL )
- return _return_invalid_param(__func__);
+ int ret;
+ net_nfc_target_handle_h handle = NULL;
+ int nfc_supported = 0;
- if(!nfc_manager_is_activated())
+ LOG_BEGIN();
+
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
+ }
+
+ if(_is_initialized() == false)
+ {
+ return NFC_ERROR_NOT_INITIALIZED;
}
+ if (tag == NULL)
+ return _return_invalid_param(__func__);
- int ret = 0;
- _async_callback_data * trans_data = NULL;
- net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
+ if (!nfc_manager_is_activated())
+ {
+ return NFC_ERROR_NOT_ACTIVATED;
+ }
- if( callback != NULL ){
- trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
- if(trans_data == NULL )
- return NFC_ERROR_OUT_OF_MEMORY;
- memset(trans_data , 0 , sizeof(_async_callback_data));
- trans_data->callback = callback;
- trans_data->user_data = user_data;
- trans_data->callback_type = _NFC_CALLBACK_TYPE_RESULT;
+ ret = net_nfc_get_tag_handle((net_nfc_target_info_h)tag, &handle);
+ if (ret == NET_NFC_OK) {
+ GVariant *parameter;
+
+ parameter = g_variant_new("(uu)",
+ GPOINTER_TO_UINT(callback),
+ GPOINTER_TO_UINT(user_data));
+ if (parameter != NULL) {
+ ret = net_nfc_client_mifare_restore(
+ handle,
+ block_index,
+ _net_nfc_manager_mifare_restore,
+ parameter);
+ if (ret != NET_NFC_OK) {
+ g_variant_unref(parameter);
+ }
+ } else {
+ ret = NET_NFC_ALLOC_FAIL;
+ }
+ } else {
+ LOG_ERR("net_nfc_get_tag_handle failed, [%d]", ret);
}
- ret = net_nfc_mifare_restore( (net_nfc_target_handle_h)tag_info->handle, block_index, trans_data);
return _convert_error_code(__func__, ret);
}
-int nfc_p2p_send(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_send_completed_cb callback, void *user_data)
+int nfc_barcode_get_barcode(unsigned char **barcode, int *barcode_len)
{
int ret;
+ int nfc_supported = 0;
- if( target == NULL || message == NULL )
- return _return_invalid_param(__func__);
+ LOG_BEGIN();
- if(!nfc_manager_is_activated())
+ ret = net_nfc_client_is_nfc_supported(&nfc_supported);
+ if (ret != NET_NFC_OK || nfc_supported == false)
{
- return NFC_ERROR_NOT_ACTIVATED;
+ LOG_ERR("NFC not supported");
+ return NFC_ERROR_NOT_SUPPORTED;
}
- if(_check_app_permission() == false)
+ if(_is_initialized() == false)
{
- LOGE("permission check fail");
- return NFC_ERROR_SECURITY_RESTRICTED;
+ return NFC_ERROR_NOT_INITIALIZED;
}
- net_nfc_exchanger_data_h data_handle;
- data_h rawdata;
- net_nfc_create_rawdata_from_ndef_message(message, &rawdata);
- ret = net_nfc_create_exchanger_data(&data_handle, rawdata);
- net_nfc_free_data(rawdata);
+ *barcode_len = 0;
+ ret = net_nfc_client_barcode_get_barcode_sync(barcode, barcode_len);
- if( ret != 0)
- return _convert_error_code(__func__, ret);
+ return _convert_error_code(__func__, ret);
+}
- ret = net_nfc_send_exchanger_data(data_handle ,(net_nfc_target_handle_h)target, NULL);
+/************************** handover ******************************************/
+int nfc_handover_message_import_from_ndef_message(nfc_handover_message_h *result, nfc_ndef_message_h msg)
+{
+ net_nfc_error_e ret;
- if( ret != 0 ){
- net_nfc_free_exchanger_data(data_handle);
- return _convert_error_code(__func__, ret);
+ if (msg == NULL || result == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- g_nfc_context.on_p2p_send_completed_cb = callback;
- g_nfc_context.on_p2p_send_completed_user_data = user_data;
-
- ret = net_nfc_free_exchanger_data(data_handle);
+ ret = net_nfc_import_handover_from_ndef_message(
+ (ndef_message_h)msg, (net_nfc_ch_message_h *)result);
- if( ret != 0 ){
- return _convert_error_code(__func__, ret);
- }
-
- return 0;
+ return _convert_error_code(__func__, ret);
}
-int nfc_p2p_send_no_permission(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_send_completed_cb callback, void *user_data)
+int nfc_handover_message_get_random_number(nfc_handover_message_h message, unsigned short *random_number)
{
- int ret;
-
- if( target == NULL || message == NULL )
- return _return_invalid_param(__func__);
+ net_nfc_error_e result;
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
+ if (message == NULL || random_number == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- net_nfc_exchanger_data_h data_handle;
- data_h rawdata;
- net_nfc_create_rawdata_from_ndef_message(message, &rawdata);
- ret = net_nfc_create_exchanger_data(&data_handle, rawdata);
- net_nfc_free_data(rawdata);
-
+ result = net_nfc_get_handover_random_number(
+ (net_nfc_ch_message_h)message,
+ random_number);
- if( ret != 0)
- return _convert_error_code(__func__, ret);
+ return _convert_error_code(__func__, result);
+}
- ret = net_nfc_send_exchanger_data(data_handle ,(net_nfc_target_handle_h)target, NULL);
+int nfc_handover_message_get_carrier_count(nfc_handover_message_h message, unsigned int *count)
+{
+ net_nfc_error_e result;
- if( ret != 0 ){
- net_nfc_free_exchanger_data(data_handle);
- return _convert_error_code(__func__, ret);
+ if (message == NULL || count == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- g_nfc_context.on_p2p_send_completed_cb = callback;
- g_nfc_context.on_p2p_send_completed_user_data = user_data;
+ result = net_nfc_get_handover_carrier_count(
+ (net_nfc_ch_message_h)message,
+ count);
+
+ return _convert_error_code(__func__, result);
+}
- ret = net_nfc_free_exchanger_data(data_handle);
+int nfc_handover_message_get_carrier(nfc_handover_message_h message, int index, nfc_handover_carrier_h *carrier)
+{
+ net_nfc_error_e result;
- if( ret != 0 ){
- return _convert_error_code(__func__, ret);
+ if (message == NULL || carrier == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- return 0;
-}
-
-int nfc_p2p_connection_handover(nfc_p2p_target_h target , nfc_ac_type_e type, nfc_p2p_connection_handover_completed_cb callback, void *user_data){
- int ret;
- net_nfc_conn_handover_carrier_type_e net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+ result = net_nfc_get_handover_carrier(
+ (net_nfc_ch_message_h)message,
+ index,
+ (net_nfc_ch_carrier_h *)carrier);
- if( target == NULL )
- return _return_invalid_param(__func__);
+ return _convert_error_code(__func__, result);
+}
- if( type > NFC_AC_TYPE_UNKNOWN )
- return _return_invalid_param(__func__);
+int nfc_handover_message_get_carrier_by_type(nfc_handover_message_h message, nfc_ac_type_e type, nfc_handover_carrier_h *carrier)
+{
+ net_nfc_error_e result;
+ net_nfc_conn_handover_carrier_type_e temp;
- if(!nfc_manager_is_activated())
- {
- return NFC_ERROR_NOT_ACTIVATED;
+ if (message == NULL || carrier == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- switch( type ){
- case NFC_AC_TYPE_BT:
- net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ switch (type) {
+ case NFC_AC_TYPE_BT :
+ temp = NET_NFC_CONN_HANDOVER_CARRIER_BT;
break;
- case NFC_AC_TYPE_WIFI:
- net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
- break;
- case NFC_AC_TYPE_WIFI_DIRECT:
- net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
+
+ case NFC_AC_TYPE_WIFI :
+ temp = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS;
break;
- case NFC_AC_TYPE_UNKNOWN :
- net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
+ case NFC_AC_TYPE_WIFI_DIRECT :
+ temp = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P;
break;
default:
+ temp = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
break;
}
- ret = net_nfc_exchanger_request_connection_handover((net_nfc_target_handle_h)target, net_ac_type);
+ result = net_nfc_get_handover_carrier_by_type(
+ (net_nfc_ch_message_h)message,
+ temp,
+ (net_nfc_ch_carrier_h *)carrier);
- if( ret != 0 ){
- return _convert_error_code(__func__, ret);
+ return _convert_error_code(__func__, result);
+}
+
+int nfc_handover_message_destroy(nfc_handover_message_h message)
+{
+ net_nfc_error_e result;
+
+ if (message == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- g_nfc_context.on_p2p_connection_handover_completed_cb = callback;
- g_nfc_context.on_p2p_connection_handover_completed_user_data = user_data;
+ result = net_nfc_free_handover_message((net_nfc_ch_message_h)message);
- return 0;
+ return _convert_error_code(__func__, result);
}
-bool nfc_p2p_is_supported_ac_type( nfc_ac_type_e carrior)
+
+int nfc_handover_carrier_get_cps(nfc_handover_carrier_h carrier, nfc_ac_state_e *cps)
{
- if( carrior > NFC_AC_TYPE_UNKNOWN )
- return false;
+ net_nfc_error_e result;
+ net_nfc_conn_handover_carrier_state_e temp;
- if( carrior == NFC_AC_TYPE_BT){
- return true;
+ if (carrier == NULL || cps == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- else{
- return false;
+
+ result = net_nfc_get_handover_carrier_cps(
+ (net_nfc_ch_carrier_h)carrier, &temp);
+ if (result == NET_NFC_OK) {
+ switch (temp) {
+ case NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE :
+ *cps = NFC_AC_STATE_INACTIVATE;
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE :
+ *cps = NFC_AC_STATE_ACTIVATE;
+ break;
+
+ case NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING :
+ *cps = NFC_AC_STATE_ACTIVATING;
+ break;
+
+ default :
+ *cps = NFC_AC_STATE_UNKNOWN;
+ break;
+ }
}
+
+ return _convert_error_code(__func__, result);
}
-int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target, nfc_p2p_data_recived_cb callback, void *user_data)
+int nfc_handover_carrier_get_type(nfc_handover_carrier_h carrier, nfc_ac_type_e *type)
{
- if( target == NULL || callback == NULL )
- return _return_invalid_param(__func__);
+ net_nfc_error_e result;
+ net_nfc_conn_handover_carrier_type_e temp;
- // if( g_nfc_context.current_target.connection_id != ((net_nfc_target_handle_s*)target)->connection_id )
- if(g_nfc_context.current_target != target )
- return _return_invalid_param(__func__);
+ if (carrier == NULL || type == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
- g_nfc_context.on_p2p_recv_cb = callback;
- g_nfc_context.on_p2p_recv_user_data = user_data;
- return 0;
-}
+ result = net_nfc_get_handover_carrier_type(
+ (net_nfc_ch_carrier_h)carrier, &temp);
+ if (result == NET_NFC_OK) {
+ switch (temp) {
+ case NET_NFC_CONN_HANDOVER_CARRIER_BT :
+ *type = NFC_AC_TYPE_BT;
+ break;
-int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target)
-{
- if( target == NULL )
- return _return_invalid_param(__func__);
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_WPS :
+ *type = NFC_AC_TYPE_WIFI;
+ break;
- // if( g_nfc_context.current_target.connection_id != ((net_nfc_target_handle_s*)target)->connection_id )
- if(g_nfc_context.current_target != target )
- return _return_invalid_param(__func__);
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_P2P :
+ *type = NFC_AC_TYPE_WIFI_DIRECT;
+ break;
- g_nfc_context.on_p2p_recv_cb = NULL;
- g_nfc_context.on_p2p_recv_user_data = NULL;
- return 0;
+ default :
+ *type = NFC_AC_TYPE_UNKNOWN;
+ break;
+ }
+ }
+
+ return _convert_error_code(__func__, result);
}
-int nfc_manager_set_p2p_target_discovered_cb( nfc_p2p_target_discovered_cb callback , void *user_data)
+int nfc_handover_carrier_get_carrier_record(nfc_handover_carrier_h carrier, nfc_ndef_record_h *record)
{
- if( callback == NULL )
- return _return_invalid_param(__func__);
+ net_nfc_error_e result;
- g_nfc_context.on_p2p_discovered_cb = callback;
- g_nfc_context.on_p2p_discovered_user_data = user_data;
- return 0;
-}
+ if (carrier == NULL || record == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ result = net_nfc_get_handover_carrier_record(
+ (net_nfc_ch_carrier_h)carrier, (ndef_record_h *)record);
-void nfc_manager_unset_p2p_target_discovered_cb( void ){
- g_nfc_context.on_p2p_discovered_cb = NULL;
- g_nfc_context.on_p2p_discovered_user_data = NULL;
+ return _convert_error_code(__func__, result);
}
-int nfc_se_enable_card_emulation()
+int nfc_handover_carrier_get_auxiliary_record_count(nfc_handover_carrier_h carrier, unsigned int *count)
{
net_nfc_error_e result;
- result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMELATION_ENABLE);
+ if (carrier == NULL || count == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ result = net_nfc_get_handover_auxiliary_record_count(
+ (net_nfc_ch_carrier_h)carrier, count);
return _convert_error_code(__func__, result);
}
-int nfc_se_disable_card_emulation()
+int nfc_handover_carrier_get_auxiliary_record(nfc_handover_carrier_h carrier, int index, nfc_ndef_record_h *record)
{
net_nfc_error_e result;
- result = net_nfc_set_card_emulation_mode_sync(NET_NFC_CARD_EMULATION_DISABLE);
+ if (carrier == NULL || record == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
+
+ result = net_nfc_get_handover_auxiliary_record(
+ (net_nfc_ch_carrier_h)carrier,
+ index, (ndef_record_h *)record);
return _convert_error_code(__func__, result);
}
-int nfc_se_get_card_emulation_mode(nfc_se_card_emulation_mode_type_e *type)
+int nfc_handover_carrier_get_handover_config(nfc_handover_carrier_h carrier, nfc_handover_config_h *config)
{
- int ret;
- int se_type;
-
- ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type);
- if (ret == 0)
- {
- if(se_type == NFC_SE_TYPE_DISABLE)
- {
- *type = NFC_SE_CARD_EMULATION_MODE_OFF;
- ret = NFC_ERROR_NONE;
+ net_nfc_error_e result;
- }
- else if(se_type >= NFC_SE_TYPE_ESE && se_type <= NFC_SE_TYPE_UICC)
- {
- *type = NFC_SE_CARD_EMULATION_MODE_ON;
- ret = NFC_ERROR_NONE;
- }
- else
- {
- ret = NFC_ERROR_OPERATION_FAILED;
- }
- }
- else
- {
- ret = NFC_ERROR_OPERATION_FAILED;
+ if (carrier == NULL || config == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- return ret;
-}
+ result = net_nfc_create_carrier_config_from_carrier(
+ (net_nfc_carrier_config_h *)config,
+ (net_nfc_ch_carrier_h)carrier);
+ return _convert_error_code(__func__, result);
+}
-int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data)
+int nfc_handover_carrier_destroy(nfc_handover_carrier_h carrier)
{
- if( callback == NULL )
- return _return_invalid_param(__func__);
+ net_nfc_error_e result;
- g_nfc_context.on_se_event_cb = callback;
- g_nfc_context.on_se_event_user_data = user_data;
- return 0;
-}
+ if (carrier == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
+ }
-void nfc_manager_unset_se_event_cb(void)
-{
- g_nfc_context.on_se_type = NET_NFC_SE_TYPE_NONE;
- g_nfc_context.on_se_event_cb = NULL;
- g_nfc_context.on_se_event_user_data = NULL;
+ result = net_nfc_free_handover_carrier((net_nfc_ch_carrier_h)carrier);
+
+ return _convert_error_code(__func__, result);
}
-int nfc_manager_set_se_transaction_event_cb(nfc_se_type_e se_type,
- nfc_se_transaction_event_cb callback, void *user_data)
-{
- if( callback == NULL )
- return _return_invalid_param(__func__);
- g_nfc_context.on_se_type = se_type;
+int nfc_handover_config_get_property(nfc_handover_config_h config, unsigned short attribute, unsigned short *size, unsigned char **data)
+{
+ net_nfc_error_e result;
- if(se_type == NFC_SE_TYPE_ESE)
- {
- g_nfc_context.on_eSE_transaction_event_cb = callback;
- g_nfc_context.on_eSE_transaction_event_user_data = user_data;
- }
- else if(se_type == NFC_SE_TYPE_UICC)
- {
- g_nfc_context.on_UICC_transaction_event_cb = callback;
- g_nfc_context.on_UICC_transaction_event_user_data = user_data;
+ if (config == NULL || size == NULL || data == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
- return 0;
+ result = net_nfc_get_carrier_config_property(
+ (net_nfc_carrier_config_h)config,
+ attribute, size, data);
+
+ return _convert_error_code(__func__, result);
}
-void nfc_manager_unset_se_transaction_event_cb(nfc_se_type_e se_type)
+int nfc_handover_config_destroy(nfc_handover_config_h config)
{
- if(se_type == NFC_SE_TYPE_ESE)
- {
- g_nfc_context.on_eSE_transaction_event_cb = NULL;
- g_nfc_context.on_eSE_transaction_event_user_data = NULL;
- }
- else if(se_type == NFC_SE_TYPE_UICC)
- {
- g_nfc_context.on_UICC_transaction_event_cb = NULL;
- g_nfc_context.on_UICC_transaction_event_user_data = NULL;
+ net_nfc_error_e result;
+
+ if (config == NULL) {
+ return NFC_ERROR_INVALID_PARAMETER;
}
+
+ result = net_nfc_free_carrier_config((net_nfc_carrier_config_h)config);
+
+ return _convert_error_code(__func__, result);
}