From: Youngjae Shin Date: Fri, 30 Aug 2013 02:23:11 +0000 (+0900) Subject: New api was added for card emulation on/off X-Git-Tag: submit/tizen/20130830.071135~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F97%2F8997%2F1;p=platform%2Fcore%2Fconnectivity%2Fnfc-manager.git New api was added for card emulation on/off Additionally, revise daemon functions and code cleanup Change-Id: Ia8b359e73e58c6f1db9d0296a10e5872a9232ff9 --- diff --git a/client/include/net_nfc_client_se.h b/client/include/net_nfc_client_se.h index 4ea3115..9b4592d 100644 --- a/client/include/net_nfc_client_se.h +++ b/client/include/net_nfc_client_se.h @@ -21,41 +21,33 @@ /*************Secure Element Callbacks*********/ typedef void (*net_nfc_se_set_se_cb)( - net_nfc_error_e result, - void *user_data); + net_nfc_error_e result, + void *user_data); -typedef void (*net_nfc_se_open_se_cb)( - net_nfc_error_e result, - net_nfc_target_handle_h handle, - void *user_data); +typedef void (*net_nfc_se_set_card_emulation_cb)(net_nfc_error_e result, + void *user_data); -typedef void (*net_nfc_se_close_se_cb)( - net_nfc_error_e result, - void *user_data); +typedef void (*net_nfc_se_open_se_cb)(net_nfc_error_e result, + net_nfc_target_handle_h handle, void *user_data); -typedef void (*net_nfc_se_get_atr_cb)( - net_nfc_error_e result, - data_h data, - void *user_data); +typedef void (*net_nfc_se_close_se_cb)(net_nfc_error_e result, void *user_data); -typedef void (*net_nfc_se_send_apdu_cb)( - net_nfc_error_e result, - data_h data, - void *user_data); +typedef void (*net_nfc_se_get_atr_cb)(net_nfc_error_e result, data_h data, + void *user_data); -typedef void (*net_nfc_client_se_event)( - net_nfc_message_e event, - void *user_data); +typedef void (*net_nfc_se_send_apdu_cb)(net_nfc_error_e result, data_h data, + void *user_data); -typedef void (*net_nfc_client_se_transaction_event)(data_h aid, - data_h param, - void *user_data); +typedef void (*net_nfc_client_se_event)(net_nfc_message_e event, void *user_data); + +typedef void (*net_nfc_client_se_transaction_event)(data_h aid, data_h param, + void *user_data); typedef void (*net_nfc_client_se_ese_detected_event)( - net_nfc_target_handle_h handle, - int dev_type, - data_h data, - void *user_data); + net_nfc_target_handle_h handle, + int dev_type, + data_h data, + void *user_data); /************* Secure Element API's*************/ @@ -73,48 +65,44 @@ net_nfc_error_e net_nfc_client_se_get_secure_element_type(void *user_data); net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync( gint *se_type); +net_nfc_error_e net_nfc_set_card_emulation_mode( + net_nfc_card_emulation_mode_t mode, + net_nfc_se_set_card_emulation_cb callback, + void *user_data); + +net_nfc_error_e net_nfc_set_card_emulation_mode_sync( + net_nfc_card_emulation_mode_t mode); net_nfc_error_e net_nfc_client_se_open_internal_secure_element( net_nfc_se_type_e se_type, net_nfc_se_open_se_cb callback, void *user_data); net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync( - net_nfc_se_type_e se_type, - net_nfc_target_handle_h *handle); + net_nfc_se_type_e se_type, net_nfc_target_handle_h *handle); net_nfc_error_e net_nfc_client_se_close_internal_secure_element( - net_nfc_target_handle_h handle, - net_nfc_se_close_se_cb callback, - void *user_data); + net_nfc_target_handle_h handle, net_nfc_se_close_se_cb callback, void *user_data); net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync( - net_nfc_target_handle_h handle); + net_nfc_target_handle_h handle); -net_nfc_error_e net_nfc_client_se_get_atr( - net_nfc_target_handle_h handle, - net_nfc_se_get_atr_cb callback, - void *user_data); +net_nfc_error_e net_nfc_client_se_get_atr(net_nfc_target_handle_h handle, + net_nfc_se_get_atr_cb callback, void *user_data); -net_nfc_error_e net_nfc_client_se_get_atr_sync( - net_nfc_target_handle_h handle, - data_h *atr); +net_nfc_error_e net_nfc_client_se_get_atr_sync(net_nfc_target_handle_h handle, + data_h *atr); -net_nfc_error_e net_nfc_client_se_send_apdu( - net_nfc_target_handle_h handle, - data_h apdu_data, - net_nfc_se_send_apdu_cb callback, - void *user_data); +net_nfc_error_e net_nfc_client_se_send_apdu(net_nfc_target_handle_h handle, + data_h apdu_data, net_nfc_se_send_apdu_cb callback, void *user_data); net_nfc_error_e net_nfc_client_se_send_apdu_sync( - net_nfc_target_handle_h handle, - data_h apdu_data, - data_h *response); + net_nfc_target_handle_h handle, data_h apdu_data, data_h *response); /************* Secure Element CallBack Register/Deregister functions*************/ diff --git a/client/net_nfc_client_data.c b/client/net_nfc_client_data.c index 7ea9693..5771883 100644 --- a/client/net_nfc_client_data.c +++ b/client/net_nfc_client_data.c @@ -32,15 +32,13 @@ API net_nfc_error_e net_nfc_create_data(data_h* data, data_s *tmp_data = NULL; if (data == NULL) - { return NET_NFC_NULL_PARAMETER; - } _net_nfc_util_alloc_mem(tmp_data, sizeof(data_s)); if (tmp_data == NULL) return NET_NFC_ALLOC_FAIL; - if (length > 0) + if (0 < length) { _net_nfc_util_alloc_mem(tmp_data->buffer, length); if (tmp_data->buffer == NULL) @@ -65,9 +63,8 @@ API net_nfc_error_e net_nfc_create_data(data_h* data, API net_nfc_error_e net_nfc_get_data(const data_h data, uint8_t** bytes, uint32_t * length) { if (data == NULL) - { return NET_NFC_NULL_PARAMETER; - } + data_s * tmp_data = (data_s *)data; *bytes = tmp_data->buffer; @@ -79,20 +76,15 @@ API net_nfc_error_e net_nfc_get_data(const data_h data, uint8_t** bytes, uint32_ API net_nfc_error_e net_nfc_set_data(const data_h data, const uint8_t* bytes, const uint32_t length) { if (data == NULL) - { return NET_NFC_NULL_PARAMETER; - } + data_s * tmp_data = (data_s *)data; if (tmp_data->buffer == bytes && tmp_data->length == length) - { return NET_NFC_OK; - } if (tmp_data->buffer != NULL) - { _net_nfc_util_free_mem(tmp_data->buffer); - } if (length <= 0) { @@ -102,14 +94,10 @@ API net_nfc_error_e net_nfc_set_data(const data_h data, const uint8_t* bytes, co } if (length > 0) - { _net_nfc_util_alloc_mem((tmp_data)->buffer, length); - } if (bytes != NULL) - { memcpy(tmp_data->buffer, bytes, length); - } tmp_data->length = length; diff --git a/client/net_nfc_client_manager.c b/client/net_nfc_client_manager.c index a0cccc0..1a7b6a0 100644 --- a/client/net_nfc_client_manager.c +++ b/client/net_nfc_client_manager.c @@ -21,19 +21,20 @@ #include "net_nfc_client_context.h" #include "net_nfc_client_manager.h" +#define DEACTIVATE_DELAY 500 /* ms */ + typedef struct _ManagerFuncData ManagerFuncData; struct _ManagerFuncData { gpointer callback; gpointer user_data; + net_nfc_error_e result; }; static NetNfcGDbusManager *manager_proxy = NULL; static gboolean activation_is_running = FALSE; - -static ManagerFuncData *activated_func_data = NULL; - +static ManagerFuncData activated_func_data; static int is_activated = -1; static void manager_call_set_active_callback(GObject *source_object, @@ -50,162 +51,155 @@ static void manager_activated(NetNfcGDbusManager *manager, gpointer user_data); +static gboolean _set_activate_time_elapsed_callback(gpointer user_data) +{ + ManagerFuncData *func_data = (ManagerFuncData *)user_data; + + g_assert(func_data != NULL); + + if (func_data != NULL) { + net_nfc_client_manager_set_active_completed callback = + (net_nfc_client_manager_set_active_completed)func_data->callback; + + callback(func_data->result, func_data->user_data); + } + + g_free(func_data); + + return false; +} + static void manager_call_set_active_callback(GObject *source_object, GAsyncResult *res, gpointer user_data) { - ManagerFuncData *func_data; - + ManagerFuncData *func_data = (ManagerFuncData *)user_data; net_nfc_error_e result = NET_NFC_OK; GError *error = NULL; - net_nfc_client_manager_set_active_completed callback; - gpointer data; + g_assert(user_data != NULL); activation_is_running = FALSE; - if (net_nfc_gdbus_manager_call_set_active_finish( - NET_NFC_GDBUS_MANAGER(source_object), - res, - &error) == FALSE) + if (net_nfc_gdbus_manager_call_set_active_finish(NET_NFC_GDBUS_MANAGER(source_object), + &result, res, &error) == FALSE) { - result = NET_NFC_UNKNOWN_ERROR; - - DEBUG_ERR_MSG("Can not finish call_set_active: %s", - error->message); + DEBUG_ERR_MSG("Can not finish call_set_active: %s", error->message); g_error_free(error); + + result = NET_NFC_IPC_FAIL; } - func_data = user_data; - if (func_data == NULL) - return; + func_data->result = result; - if (func_data->callback == NULL) + if (is_activated == false) { - g_free(func_data); - return; + //TODO : wait several times + g_timeout_add(DEACTIVATE_DELAY, + _set_activate_time_elapsed_callback, + func_data); + } + else + { + g_main_context_invoke(NULL, + _set_activate_time_elapsed_callback, + func_data); } - - - callback = (net_nfc_client_manager_set_active_completed) - func_data->callback; - data = func_data->user_data; - - callback(result, data); - - g_free(func_data); } static void manager_call_get_server_state_callback(GObject *source_object, GAsyncResult *res, gpointer user_data) { - ManagerFuncData *func_data; - + NetNfcCallback *func_data = (NetNfcCallback *)user_data; net_nfc_error_e result = NET_NFC_OK; - guint out_state; + guint out_state = 0; GError *error = NULL; - net_nfc_client_manager_get_server_state_completed callback; - gpointer data; + g_assert(user_data != NULL); if (net_nfc_gdbus_manager_call_get_server_state_finish( NET_NFC_GDBUS_MANAGER(source_object), + &result, &out_state, res, &error) == FALSE) { - - result = NET_NFC_UNKNOWN_ERROR; - DEBUG_ERR_MSG("Can not finish get_server_state: %s", error->message); g_error_free(error); - } - - func_data = user_data; - if (func_data == NULL) - return; - if (func_data->callback == NULL) - { - g_free(func_data); - return; + result = NET_NFC_IPC_FAIL; } - callback = (net_nfc_client_manager_get_server_state_completed) - func_data->callback; - data = func_data->user_data; + if (func_data->callback != NULL) + { + net_nfc_client_manager_get_server_state_completed callback = + (net_nfc_client_manager_get_server_state_completed)func_data->callback; - callback(result, out_state, data); + callback(result, out_state, func_data->user_data); + } g_free(func_data); } - -static void manager_activated(NetNfcGDbusManager *manager, - gboolean activated, - gpointer user_data) +static gboolean _activated_time_elapsed_callback(gpointer user_data) { - bool state = false; + net_nfc_client_manager_activated callback = + (net_nfc_client_manager_activated)activated_func_data.callback; + + callback(is_activated, activated_func_data.user_data); + return false; +} + +static void manager_activated(NetNfcGDbusManager *manager, gboolean activated, + gpointer user_data) +{ INFO_MSG(">>> SIGNAL arrived"); DEBUG_CLIENT_MSG("activated %d", activated); /* update current state */ is_activated = (int)activated; - if (activated_func_data == NULL) - return; - - if (activated == TRUE) - state = true; - - if (activated_func_data->callback) + if (activated_func_data.callback != NULL) { - net_nfc_client_manager_activated callback; - gpointer user_data; - - callback = (net_nfc_client_manager_activated) - (activated_func_data->callback); - user_data = activated_func_data->user_data; - - callback(state, user_data); + if (is_activated == false) + { + /* FIXME : wait several times */ + g_timeout_add(DEACTIVATE_DELAY, _activated_time_elapsed_callback, NULL); + } + else + { + g_main_context_invoke(NULL, _activated_time_elapsed_callback, NULL); + } } } API void net_nfc_client_manager_set_activated( - net_nfc_client_manager_activated callback, - void *user_data) + net_nfc_client_manager_activated callback, void *user_data) { - if (activated_func_data == NULL) - activated_func_data = g_new0(ManagerFuncData, 1); + if (callback == NULL) + return; - activated_func_data->callback = (gpointer)callback; - activated_func_data->user_data = user_data; + activated_func_data.callback = callback; + activated_func_data.user_data = user_data; } API void net_nfc_client_manager_unset_activated(void) { - if (activated_func_data == NULL) - { - DEBUG_ERR_MSG("manager_func_data is not initialized"); - return; - } - - g_free(activated_func_data); - activated_func_data = NULL; + activated_func_data.callback = NULL; + activated_func_data.user_data = NULL; } API net_nfc_error_e net_nfc_client_manager_set_active(int state, - net_nfc_client_manager_set_active_completed callback, - void *user_data) + net_nfc_client_manager_set_active_completed callback, void *user_data) { gboolean active = FALSE; ManagerFuncData *func_data; if (manager_proxy == NULL) - return NET_NFC_UNKNOWN_ERROR; + return NET_NFC_NOT_INITIALIZED; /* allow this function even nfc is off */ @@ -214,9 +208,9 @@ API net_nfc_error_e net_nfc_client_manager_set_active(int state, activation_is_running = TRUE; - func_data = g_new0(ManagerFuncData, 1); + func_data = g_try_new0(ManagerFuncData, 1); if (func_data == NULL) - return NET_NFC_UNKNOWN_ERROR; + return NET_NFC_ALLOC_FAIL; func_data->callback = (gpointer)callback; func_data->user_data = user_data; @@ -236,45 +230,47 @@ API net_nfc_error_e net_nfc_client_manager_set_active(int state, API net_nfc_error_e net_nfc_client_manager_set_active_sync(int state) { + net_nfc_error_e out_result = NET_NFC_OK; GError *error = NULL; if (manager_proxy == NULL) - return NET_NFC_UNKNOWN_ERROR; + return NET_NFC_NOT_INITIALIZED; /* allow this function even nfc is off */ if (net_nfc_gdbus_manager_call_set_active_sync(manager_proxy, (gboolean)state, net_nfc_client_gdbus_get_privilege(), + &out_result, NULL, &error) == FALSE) { DEBUG_CLIENT_MSG("can not call SetActive: %s", error->message); g_error_free(error); - return NET_NFC_UNKNOWN_ERROR; + + out_result = NET_NFC_IPC_FAIL; } - return NET_NFC_OK; + return out_result; } API net_nfc_error_e net_nfc_client_manager_get_server_state( - net_nfc_client_manager_get_server_state_completed callback, - void *user_data) + net_nfc_client_manager_get_server_state_completed callback, void *user_data) { - ManagerFuncData *func_data; + NetNfcCallback *func_data; if (manager_proxy == NULL) - return NET_NFC_UNKNOWN_ERROR; + return NET_NFC_NOT_INITIALIZED; /* prevent executing daemon when nfc is off */ if (net_nfc_client_manager_is_activated() == false) { return NET_NFC_INVALID_STATE; } - func_data = g_new0(ManagerFuncData, 1); + func_data = g_try_new0(NetNfcCallback, 1); if (func_data == NULL) - return NET_NFC_UNKNOWN_ERROR; + return NET_NFC_ALLOC_FAIL; func_data->callback = (gpointer) callback; func_data->user_data = user_data; @@ -291,11 +287,17 @@ API net_nfc_error_e net_nfc_client_manager_get_server_state( API net_nfc_error_e net_nfc_client_manager_get_server_state_sync( unsigned int *state) { + net_nfc_error_e out_result = NET_NFC_OK; + guint out_state = 0; GError *error = NULL; - guint out_state; + + if (state == NULL) + return NET_NFC_NULL_PARAMETER; + + *state = 0; if (manager_proxy == NULL) - return NET_NFC_UNKNOWN_ERROR; + return NET_NFC_NOT_INITIALIZED; /* prevent executing daemon when nfc is off */ if (net_nfc_client_manager_is_activated() == false) { @@ -304,20 +306,23 @@ API net_nfc_error_e net_nfc_client_manager_get_server_state_sync( if (net_nfc_gdbus_manager_call_get_server_state_sync(manager_proxy, net_nfc_client_gdbus_get_privilege(), + &out_result, &out_state, NULL, - &error) == FALSE) + &error) == TRUE) + { + *state = out_state; + } + else { DEBUG_CLIENT_MSG("can not call GetServerState: %s", error->message); g_error_free(error); - return NET_NFC_UNKNOWN_ERROR; + out_result = NET_NFC_IPC_FAIL; } - *state = out_state; - return NET_NFC_OK; - + return out_result; } net_nfc_error_e net_nfc_client_manager_init(void) @@ -327,6 +332,7 @@ net_nfc_error_e net_nfc_client_manager_init(void) if (manager_proxy) { DEBUG_CLIENT_MSG("Already initialized"); + return NET_NFC_OK; } @@ -342,6 +348,7 @@ net_nfc_error_e net_nfc_client_manager_init(void) { DEBUG_ERR_MSG("Can not create proxy : %s", error->message); g_error_free(error); + return NET_NFC_UNKNOWN_ERROR; } @@ -358,12 +365,6 @@ void net_nfc_client_manager_deinit(void) g_object_unref(manager_proxy); manager_proxy = NULL; } - - if (activated_func_data) - { - g_free(activated_func_data); - activated_func_data = NULL; - } } /* internal function */ diff --git a/client/net_nfc_client_ndef.c b/client/net_nfc_client_ndef.c index 832abc7..767d405 100644 --- a/client/net_nfc_client_ndef.c +++ b/client/net_nfc_client_ndef.c @@ -596,9 +596,7 @@ API net_nfc_error_e net_nfc_client_ndef_make_read_only_sync( } API net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle, - data_h key, - net_nfc_client_ndef_format_completed callback, - void *user_data) + data_h key, net_nfc_client_ndef_format_completed callback, void *user_data) { NdefFuncData *func_data; GVariant *arg_data = NULL; @@ -621,12 +619,7 @@ API net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle, if (key == NULL) arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0); else - { - data_s *key_s; - - key_s = (data_s *)key; - arg_data = net_nfc_util_gdbus_data_to_variant(key_s); - } + arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)key); if (arg_data == NULL) return NET_NFC_INVALID_PARAM; @@ -636,7 +629,7 @@ API net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle, func_data->callback = (gpointer)callback; func_data->user_data = user_data; - net_nfc_gdbus_ndef_call_format(ndef_proxy , + net_nfc_gdbus_ndef_call_format(ndef_proxy, GPOINTER_TO_UINT(handle), arg_data, net_nfc_client_gdbus_get_privilege(), @@ -648,8 +641,7 @@ API net_nfc_error_e net_nfc_client_ndef_format(net_nfc_target_handle_h handle, } API net_nfc_error_e net_nfc_client_ndef_format_sync( - net_nfc_target_handle_h handle, - data_h key) + net_nfc_target_handle_h handle, data_h key) { GVariant *arg_data = NULL; GError *error = NULL; @@ -673,12 +665,7 @@ API net_nfc_error_e net_nfc_client_ndef_format_sync( if (key == NULL) arg_data = net_nfc_util_gdbus_buffer_to_variant(NULL, 0); else - { - data_s *key_s; - - key_s = (data_s *)key; - arg_data = net_nfc_util_gdbus_data_to_variant(key_s); - } + arg_data = net_nfc_util_gdbus_data_to_variant((data_s *)key); if (arg_data == NULL) return NET_NFC_INVALID_PARAM; diff --git a/client/net_nfc_client_ndef_message.c b/client/net_nfc_client_ndef_message.c index 5d29581..10b29fd 100644 --- a/client/net_nfc_client_ndef_message.c +++ b/client/net_nfc_client_ndef_message.c @@ -27,15 +27,15 @@ API net_nfc_error_e net_nfc_create_ndef_message(ndef_message_h *ndef_message) return net_nfc_util_create_ndef_message((ndef_message_s **)ndef_message); } -API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef_message, data_h *rawdata) +API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message( + ndef_message_h ndef_message, data_h *rawdata) { uint32_t count; net_nfc_error_e result; data_h data; - if (ndef_message == NULL || rawdata == NULL) { + if (ndef_message == NULL || rawdata == NULL) return NET_NFC_NULL_PARAMETER; - } *rawdata = NULL; @@ -51,83 +51,78 @@ API net_nfc_error_e net_nfc_create_rawdata_from_ndef_message(ndef_message_h ndef result = net_nfc_util_convert_ndef_message_to_rawdata( (ndef_message_s *)ndef_message, (data_s *)data); - if (result == NET_NFC_OK) { + if (result == NET_NFC_OK) *rawdata = data; - } else { + else net_nfc_free_data(data); - } return result; } -API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata(ndef_message_h *ndef_message, data_h rawdata) +API net_nfc_error_e net_nfc_create_ndef_message_from_rawdata( + ndef_message_h *ndef_message, data_h rawdata) { net_nfc_error_e result; ndef_message_h msg; - if (ndef_message == NULL || rawdata == NULL) { + if (ndef_message == NULL || rawdata == NULL) return NET_NFC_NULL_PARAMETER; - } *ndef_message = NULL; result = net_nfc_create_ndef_message(&msg); - if (result != NET_NFC_OK) { + if (result != NET_NFC_OK) return result; - } result = net_nfc_util_convert_rawdata_to_ndef_message( (data_s *)rawdata, (ndef_message_s *)msg); - if (result == NET_NFC_OK) { + if (result == NET_NFC_OK) *ndef_message = msg; - } else { + else net_nfc_free_ndef_message(msg); - } return result; } -API net_nfc_error_e net_nfc_get_ndef_message_byte_length(ndef_message_h ndef_message, uint32_t *length) +API net_nfc_error_e net_nfc_get_ndef_message_byte_length( + ndef_message_h ndef_message, uint32_t *length) { net_nfc_error_e result; - if (ndef_message == NULL || length == NULL){ + if (ndef_message == NULL || length == NULL) return NET_NFC_NULL_PARAMETER; - } *length = net_nfc_util_get_ndef_message_length((ndef_message_s *)ndef_message); - if (*length > 0) { + if (*length > 0) result = NET_NFC_OK; - } else { + else result = NET_NFC_INVALID_PARAM; - } return result; } -API net_nfc_error_e net_nfc_append_record_to_ndef_message(ndef_message_h ndef_message, ndef_record_h record) +API net_nfc_error_e net_nfc_append_record_to_ndef_message( + ndef_message_h ndef_message, ndef_record_h record) { - if (ndef_message == NULL || record == NULL){ + if (ndef_message == NULL || record == NULL) return NET_NFC_NULL_PARAMETER; - } return net_nfc_util_append_record((ndef_message_s*)ndef_message, (ndef_record_s *)record); } API net_nfc_error_e net_nfc_free_ndef_message(ndef_message_h ndef_message) { - if (ndef_message == NULL) { + if (ndef_message == NULL) return NET_NFC_NULL_PARAMETER; - } return net_nfc_util_free_ndef_message((ndef_message_s *)ndef_message); } -API net_nfc_error_e net_nfc_get_ndef_message_record_count(ndef_message_h ndef_message, int *count) +API net_nfc_error_e net_nfc_get_ndef_message_record_count( + ndef_message_h ndef_message, int *count) { - if (ndef_message == NULL || count == NULL) { + if (ndef_message == NULL || count == NULL) return NET_NFC_NULL_PARAMETER; - } ndef_message_s *msg = (ndef_message_s *)ndef_message; @@ -138,42 +133,46 @@ API net_nfc_error_e net_nfc_get_ndef_message_record_count(ndef_message_h ndef_me API void net_nfc_ndef_print_message (ndef_message_h ndef_message ) { - net_nfc_util_print_ndef_message ((ndef_message_s *)(ndef_message) ); + net_nfc_util_print_ndef_message((ndef_message_s *)(ndef_message)); } -API net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, net_nfc_record_tnf_e tnf, data_h type, ndef_record_h* record) +API net_nfc_error_e net_nfc_search_record_by_type (ndef_message_h ndef_message, + net_nfc_record_tnf_e tnf, data_h type, ndef_record_h* record) { return net_nfc_util_search_record_by_type ((ndef_message_s*)ndef_message, tnf, (data_s *)type, (ndef_record_s**)record); } -API net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h record) +API net_nfc_error_e net_nfc_append_record_by_index (ndef_message_h ndef_message, + int index, ndef_record_h record) { return net_nfc_util_append_record_by_index ((ndef_message_s *) ndef_message, index, (ndef_record_s *) record); } -API net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, int index, ndef_record_h* record) +API net_nfc_error_e net_nfc_get_record_by_index (ndef_message_h ndef_message, + int index, ndef_record_h* record) { return net_nfc_util_get_record_by_index ((ndef_message_s*) ndef_message, index, (ndef_record_s**) record); } -API net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, int index) +API net_nfc_error_e net_nfc_remove_record_by_index (ndef_message_h ndef_message, + int index) { return net_nfc_util_remove_record_by_index ((ndef_message_s*)ndef_message, index); } -API net_nfc_error_e net_nfc_retrieve_current_ndef_message(ndef_message_h* ndef_message) +API net_nfc_error_e net_nfc_retrieve_current_ndef_message( + ndef_message_h* ndef_message) { net_nfc_error_e result = NET_NFC_UNKNOWN_ERROR; - char file_path[1024] = { 0, }; + char file_path[1024] = {0}; FILE *fp = NULL; if (ndef_message == NULL) - { return NET_NFC_NULL_PARAMETER; - } - snprintf(file_path, sizeof(file_path), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME); + snprintf(file_path, sizeof(file_path), "%s/%s/%s", NET_NFC_MANAGER_DATA_PATH, + NET_NFC_MANAGER_DATA_PATH_MESSAGE, NET_NFC_MANAGER_NDEF_FILE_NAME); if ((fp = fopen(file_path, "r")) != NULL) { diff --git a/client/net_nfc_client_ndef_message_handover.c b/client/net_nfc_client_ndef_message_handover.c index 3caad21..39eccc9 100644 --- a/client/net_nfc_client_ndef_message_handover.c +++ b/client/net_nfc_client_ndef_message_handover.c @@ -21,135 +21,158 @@ #include "net_nfc_util_internal.h" #include "net_nfc_util_handover.h" -API net_nfc_error_e net_nfc_create_carrier_config (net_nfc_carrier_config_h * config, net_nfc_conn_handover_carrier_type_e type) +API net_nfc_error_e net_nfc_create_carrier_config( + net_nfc_carrier_config_h *config, net_nfc_conn_handover_carrier_type_e type) { - return net_nfc_util_create_carrier_config ((net_nfc_carrier_config_s **) config, type); + return net_nfc_util_create_carrier_config ((net_nfc_carrier_config_s **)config, type); } -API net_nfc_error_e net_nfc_add_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t * data) +API net_nfc_error_e net_nfc_add_carrier_config_property( + net_nfc_carrier_config_h config, uint16_t attribute, uint16_t size, uint8_t *data) { - return net_nfc_util_add_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data); + return net_nfc_util_add_carrier_config_property((net_nfc_carrier_config_s *) config, attribute, size, data); } -API net_nfc_error_e net_nfc_remove_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute) +API net_nfc_error_e net_nfc_remove_carrier_config_property( + net_nfc_carrier_config_h config, uint16_t attribute) { - return net_nfc_util_remove_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute); + return net_nfc_util_remove_carrier_config_property((net_nfc_carrier_config_s *) config, attribute); } -API net_nfc_error_e net_nfc_get_carrier_config_property (net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data) +API net_nfc_error_e net_nfc_get_carrier_config_property( + net_nfc_carrier_config_h config, uint16_t attribute, uint16_t * size, uint8_t ** data) { - return net_nfc_util_get_carrier_config_property ((net_nfc_carrier_config_s *) config, attribute, size, data); + return net_nfc_util_get_carrier_config_property((net_nfc_carrier_config_s *) config, attribute, size, data); } -API net_nfc_error_e net_nfc_append_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group) +API net_nfc_error_e net_nfc_append_carrier_config_group( + net_nfc_carrier_config_h config, net_nfc_property_group_h group) { - return net_nfc_util_append_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group); + return net_nfc_util_append_carrier_config_group((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group); } -API net_nfc_error_e net_nfc_remove_carrier_config_group (net_nfc_carrier_config_h config, net_nfc_property_group_h group) +API net_nfc_error_e net_nfc_remove_carrier_config_group( + net_nfc_carrier_config_h config, net_nfc_property_group_h group) { - return net_nfc_util_remove_carrier_config_group ((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group); + return net_nfc_util_remove_carrier_config_group((net_nfc_carrier_config_s *) config, (net_nfc_carrier_property_s *) group); } -API net_nfc_error_e net_nfc_get_carrier_config_group (net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group) +API net_nfc_error_e net_nfc_get_carrier_config_group( + net_nfc_carrier_config_h config, int index, net_nfc_property_group_h * group) { - return net_nfc_util_get_carrier_config_group ((net_nfc_carrier_config_s *) config, index, (net_nfc_carrier_property_s **) group); + return net_nfc_util_get_carrier_config_group((net_nfc_carrier_config_s *) config, index, (net_nfc_carrier_property_s **) group); } -API net_nfc_error_e net_nfc_free_carrier_config (net_nfc_carrier_config_h config) +API net_nfc_error_e net_nfc_free_carrier_config(net_nfc_carrier_config_h config) { - return net_nfc_util_free_carrier_config ((net_nfc_carrier_config_s *) config); + return net_nfc_util_free_carrier_config((net_nfc_carrier_config_s *) config); } -API net_nfc_error_e net_nfc_create_carrier_config_group (net_nfc_property_group_h * group, uint16_t attribute) +API net_nfc_error_e net_nfc_create_carrier_config_group( + net_nfc_property_group_h * group, uint16_t attribute) { - return net_nfc_util_create_carrier_config_group ((net_nfc_carrier_property_s **) group, attribute); + return net_nfc_util_create_carrier_config_group((net_nfc_carrier_property_s **) group, attribute); } -API net_nfc_error_e net_nfc_add_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data) +API net_nfc_error_e net_nfc_add_carrier_config_group_property( + net_nfc_property_group_h group, uint16_t attribute, uint16_t size, uint8_t * data) { - return net_nfc_util_add_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data); + return net_nfc_util_add_carrier_config_group_property((net_nfc_carrier_property_s*) group, attribute, size, data); } -API net_nfc_error_e net_nfc_get_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data) +API net_nfc_error_e net_nfc_get_carrier_config_group_property( + net_nfc_property_group_h group, uint16_t attribute, uint16_t *size, uint8_t ** data) { - return net_nfc_util_get_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute, size, data); + return net_nfc_util_get_carrier_config_group_property((net_nfc_carrier_property_s*) group, attribute, size, data); } -API net_nfc_error_e net_nfc_remove_carrier_config_group_property (net_nfc_property_group_h group, uint16_t attribute) +API net_nfc_error_e net_nfc_remove_carrier_config_group_property( + net_nfc_property_group_h group, uint16_t attribute) { - return net_nfc_util_remove_carrier_config_group_property ((net_nfc_carrier_property_s*) group, attribute); + return net_nfc_util_remove_carrier_config_group_property((net_nfc_carrier_property_s*) group, attribute); } -API net_nfc_error_e net_nfc_free_carrier_group (net_nfc_property_group_h group) +API net_nfc_error_e net_nfc_free_carrier_group(net_nfc_property_group_h group) { - return net_nfc_util_free_carrier_group ((net_nfc_carrier_property_s*) group); + return net_nfc_util_free_carrier_group((net_nfc_carrier_property_s*) group); } -API net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config (ndef_record_h * record, net_nfc_carrier_config_h config) +API net_nfc_error_e net_nfc_create_ndef_record_with_carrier_config( + ndef_record_h * record, net_nfc_carrier_config_h config) { - return net_nfc_util_create_ndef_record_with_carrier_config ((ndef_record_s**) record, (net_nfc_carrier_config_s *) config); + return net_nfc_util_create_ndef_record_with_carrier_config((ndef_record_s**) record, (net_nfc_carrier_config_s *) config); } -API net_nfc_error_e net_nfc_create_carrier_config_from_config_record (net_nfc_carrier_config_h * config, ndef_record_h record) +API net_nfc_error_e net_nfc_create_carrier_config_from_config_record( + net_nfc_carrier_config_h * config, ndef_record_h record) { return net_nfc_util_create_carrier_config_from_config_record ((net_nfc_carrier_config_s **) config, (ndef_record_s *) record); - } -API net_nfc_error_e net_nfc_append_carrier_config_record (ndef_message_h message, ndef_record_h record, net_nfc_conn_handover_carrier_state_e power_status) +API net_nfc_error_e net_nfc_append_carrier_config_record( + ndef_message_h message, + ndef_record_h record, + net_nfc_conn_handover_carrier_state_e power_status) { - return net_nfc_util_append_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record, power_status); + return net_nfc_util_append_carrier_config_record((ndef_message_s *) message, (ndef_record_s *) record, power_status); } -API net_nfc_error_e net_nfc_remove_carrier_config_record (ndef_message_h message, ndef_record_h record) +API net_nfc_error_e net_nfc_remove_carrier_config_record( + ndef_message_h message, ndef_record_h record) { return net_nfc_util_remove_carrier_config_record ((ndef_message_s *) message, (ndef_record_s *) record); } -API net_nfc_error_e net_nfc_get_carrier_config_record (ndef_message_h message, int index, ndef_record_h * record) +API net_nfc_error_e net_nfc_get_carrier_config_record(ndef_message_h message, + int index, ndef_record_h * record) { - return net_nfc_util_get_carrier_config_record ((ndef_message_s *) message, index, (ndef_record_s **) record); + return net_nfc_util_get_carrier_config_record((ndef_message_s *) message, index, (ndef_record_s **) record); } -API net_nfc_error_e net_nfc_get_handover_random_number(ndef_message_h message, unsigned short* random_number) +API net_nfc_error_e net_nfc_get_handover_random_number( + ndef_message_h message, unsigned short* random_number) { return net_nfc_util_get_handover_random_number((ndef_message_s *) message, random_number); } -API net_nfc_error_e net_nfc_get_alternative_carrier_record_count (ndef_message_h message, unsigned int * count) +API net_nfc_error_e net_nfc_get_alternative_carrier_record_count( + ndef_message_h message, unsigned int * count) { - return net_nfc_util_get_alternative_carrier_record_count ((ndef_message_s *) message, count); + return net_nfc_util_get_alternative_carrier_record_count((ndef_message_s *) message, count); } -API net_nfc_error_e net_nfc_get_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state) +API net_nfc_error_e net_nfc_get_alternative_carrier_power_status( + ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e * power_state) { - return net_nfc_util_get_alternative_carrier_power_status ((ndef_message_s *) message, index, power_state); + return net_nfc_util_get_alternative_carrier_power_status((ndef_message_s *) message, index, power_state); } -API net_nfc_error_e net_nfc_set_alternative_carrier_power_status (ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status) +API net_nfc_error_e net_nfc_set_alternative_carrier_power_status( + ndef_message_h message, int index, net_nfc_conn_handover_carrier_state_e power_status) { - return net_nfc_util_set_alternative_carrier_power_status ((ndef_message_s *) message, index, power_status); + return net_nfc_util_set_alternative_carrier_power_status((ndef_message_s *) message, index, power_status); } -API net_nfc_error_e net_nfc_get_alternative_carrier_type (ndef_message_h message, int index, net_nfc_conn_handover_carrier_type_e * type) +API net_nfc_error_e net_nfc_get_alternative_carrier_type(ndef_message_h message, + int index, net_nfc_conn_handover_carrier_type_e * type) { - return net_nfc_util_get_alternative_carrier_type ((ndef_message_s *) message, index, type); + return net_nfc_util_get_alternative_carrier_type((ndef_message_s *) message, index, type); } -API net_nfc_error_e net_nfc_create_handover_request_message (ndef_message_h * message) +API net_nfc_error_e net_nfc_create_handover_request_message( + ndef_message_h * message) { - return net_nfc_util_create_handover_request_message ((ndef_message_s **) message); + return net_nfc_util_create_handover_request_message((ndef_message_s **) message); } -API net_nfc_error_e net_nfc_create_handover_select_message (ndef_message_h * message) +API net_nfc_error_e net_nfc_create_handover_select_message( + ndef_message_h * message) { return net_nfc_util_create_handover_select_message((ndef_message_s **) message); } -API net_nfc_error_e net_nfc_create_handover_error_record (ndef_record_h * record, uint8_t reason, uint32_t data) +API net_nfc_error_e net_nfc_create_handover_error_record( + ndef_record_h * record, uint8_t reason, uint32_t data) { return net_nfc_util_create_handover_error_record ((ndef_record_s**) record, reason, data); -} - - +} \ No newline at end of file diff --git a/client/net_nfc_client_ndef_record.c b/client/net_nfc_client_ndef_record.c index c0d701a..97b7acf 100644 --- a/client/net_nfc_client_ndef_record.c +++ b/client/net_nfc_client_ndef_record.c @@ -157,12 +157,11 @@ API uint8_t net_nfc_get_record_il(uint8_t flag) return ((flag >> 3) & 0x01); } -API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h record, char** buffer) +API net_nfc_error_e net_nfc_create_text_string_from_text_record( + ndef_record_h record, char** buffer) { if (record == NULL || buffer == NULL) - { return NET_NFC_ALLOC_FAIL; - } data_h payload; data_h rec_type; @@ -200,12 +199,11 @@ API net_nfc_error_e net_nfc_create_text_string_from_text_record(ndef_record_h re return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record(ndef_record_h record, char** lang_code_str) +API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record( + ndef_record_h record, char** lang_code_str) { if (record == NULL || lang_code_str == NULL) - { return NET_NFC_ALLOC_FAIL; - } data_h payload; data_h rec_type; @@ -244,12 +242,11 @@ API net_nfc_error_e net_nfc_get_languange_code_string_from_text_record(ndef_reco return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h record, net_nfc_encode_type_e * encoding) +API net_nfc_error_e net_nfc_get_encoding_type_from_text_record( + ndef_record_h record, net_nfc_encode_type_e * encoding) { if (record == NULL || encoding == NULL) - { return NET_NFC_NULL_PARAMETER; - } data_h payload; data_h rec_type; @@ -270,19 +267,16 @@ API net_nfc_error_e net_nfc_get_encoding_type_from_text_record(ndef_record_h rec int controllbyte = buffer_temp[0]; if ((controllbyte & 0x80) == 0x80) - { *encoding = NET_NFC_ENCODE_UTF_16; - } else - { *encoding = NET_NFC_ENCODE_UTF_8; - } } return NET_NFC_OK; } -API net_nfc_error_e net_nfc_create_uri_string_from_uri_record(ndef_record_h record, char **uri) +API net_nfc_error_e net_nfc_create_uri_string_from_uri_record( + ndef_record_h record, char **uri) { return net_nfc_util_create_uri_string_from_uri_record((ndef_record_s *)record, uri); } diff --git a/client/net_nfc_client_se.c b/client/net_nfc_client_se.c index 9459a89..987cbd3 100644 --- a/client/net_nfc_client_se.c +++ b/client/net_nfc_client_se.c @@ -106,8 +106,7 @@ static void se_ese_detected(GObject *source_object, net_nfc_util_gdbus_variant_to_data_s(arg_data, &buffer_data); - callback((net_nfc_target_handle_h)arg_handle, - arg_se_type, &buffer_data, + callback((net_nfc_target_handle_h)arg_handle, arg_se_type, &buffer_data, se_esedetecthandler.se_ese_detected_data); net_nfc_util_free_data(&buffer_data); @@ -191,14 +190,50 @@ static void set_secure_element(GObject *source_object, } +static void _set_card_emulation_cb(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_secure_element_call_set_card_emulation_finish( + se_proxy, + &result, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Could not set card emulation: %s", + error->message); + + g_error_free(error); + + result = NET_NFC_IPC_FAIL; + } + + if (func_data->callback != NULL) + { + net_nfc_se_set_se_cb se_callback = + (net_nfc_se_set_se_cb)func_data->callback; + + se_callback(result, func_data->user_data); + } + + g_free(func_data); +} + + static void open_secure_element(GObject *source_object, GAsyncResult *res, gpointer user_data) { SeFuncData *func_data = (SeFuncData *)user_data; - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; + guint out_handle = 0; GError *error = NULL; - guint out_handle; g_assert(user_data != NULL); @@ -222,9 +257,7 @@ static void open_secure_element(GObject *source_object, net_nfc_se_open_se_cb se_callback = (net_nfc_se_open_se_cb)func_data->se_callback; - se_callback(result, - (net_nfc_target_handle_h)out_handle, - func_data->se_data); + se_callback(result, (net_nfc_target_handle_h)out_handle, func_data->se_data); } g_free(func_data); @@ -236,7 +269,7 @@ static void close_secure_element(GObject *source_object, gpointer user_data) { SeFuncData *func_data = (SeFuncData *)user_data; - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; GError *error = NULL; g_assert(user_data != NULL); @@ -271,8 +304,8 @@ static void send_apdu_secure_element(GObject *source_object, gpointer user_data) { SeFuncData *func_data = (SeFuncData *)user_data; - net_nfc_error_e result; - GVariant *out_response; + net_nfc_error_e result = NET_NFC_OK; + GVariant *out_response = NULL; GError *error = NULL; g_assert(user_data != NULL); @@ -313,8 +346,8 @@ static void get_atr_secure_element(GObject *source_object, gpointer user_data) { SeFuncData *func_data = (SeFuncData *)user_data; - net_nfc_error_e result; - GVariant *out_atr; + net_nfc_error_e result = NET_NFC_OK; + GVariant *out_atr = NULL; GError *error = NULL; g_assert(user_data != NULL); @@ -369,7 +402,7 @@ API net_nfc_error_e net_nfc_client_se_set_secure_element_type( return NET_NFC_INVALID_STATE; } - func_data = g_new0(SeFuncData, 1); + func_data = g_try_new0(SeFuncData, 1); if (func_data == NULL) return NET_NFC_ALLOC_FAIL; @@ -391,7 +424,7 @@ API net_nfc_error_e net_nfc_client_se_set_secure_element_type( API net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync( net_nfc_se_type_e se_type) { - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; GError *error = NULL; if (se_proxy == NULL) @@ -424,6 +457,79 @@ API net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync( return result; } +API net_nfc_error_e net_nfc_set_card_emulation_mode( + net_nfc_card_emulation_mode_t mode, + net_nfc_se_set_card_emulation_cb callback, + void *user_data) +{ + NetNfcCallback *func_data; + + if (se_proxy == NULL) { + DEBUG_ERR_MSG("Can not get se_proxy"); + + return NET_NFC_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_INVALID_STATE; + } + + func_data = g_try_new0(NetNfcCallback, 1); + if (func_data == NULL) + return NET_NFC_ALLOC_FAIL; + + func_data->callback = (gpointer)callback; + func_data->user_data = user_data; + + net_nfc_gdbus_secure_element_call_set_card_emulation( + se_proxy, + (gint)mode, + net_nfc_client_gdbus_get_privilege(), + NULL, + _set_card_emulation_cb, + func_data); + + return NET_NFC_OK; +} + + +API net_nfc_error_e net_nfc_set_card_emulation_mode_sync( + net_nfc_card_emulation_mode_t mode) +{ + net_nfc_error_e result = NET_NFC_OK; + GError *error = NULL; + + if (se_proxy == NULL) + { + DEBUG_ERR_MSG("Can not get se_proxy"); + + return NET_NFC_NOT_INITIALIZED; + } + + /* prevent executing daemon when nfc is off */ + if (net_nfc_client_manager_is_activated() == false) { + return NET_NFC_INVALID_STATE; + } + + if (net_nfc_gdbus_secure_element_call_set_card_emulation_sync( + se_proxy, + (gint)mode, + net_nfc_client_gdbus_get_privilege(), + &result, + NULL, + &error) == FALSE) + { + DEBUG_ERR_MSG("Set card emulation failed: %s", error->message); + + g_error_free(error); + + result = NET_NFC_IPC_FAIL; + } + + return result; +} + API net_nfc_error_e net_nfc_client_se_open_internal_secure_element( net_nfc_se_type_e se_type, @@ -441,7 +547,7 @@ API net_nfc_error_e net_nfc_client_se_open_internal_secure_element( /* allow this function even nfc is off */ - func_data = g_new0(SeFuncData, 1); + func_data = g_try_new0(SeFuncData, 1); if (func_data == NULL) return NET_NFC_ALLOC_FAIL; @@ -454,18 +560,17 @@ API net_nfc_error_e net_nfc_client_se_open_internal_secure_element( net_nfc_client_gdbus_get_privilege(), NULL, open_secure_element, - user_data); + func_data); return NET_NFC_OK; } API net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync( - net_nfc_se_type_e se_type, - net_nfc_target_handle_h *handle) + net_nfc_se_type_e se_type, net_nfc_target_handle_h *handle) { - net_nfc_error_e result; - guint out_handle; + net_nfc_error_e result = NET_NFC_OK; + guint out_handle = 0; GError *error = NULL; if (handle == NULL) { @@ -491,8 +596,7 @@ API net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync( &error) == true) { *handle = GUINT_TO_POINTER(out_handle); } else { - DEBUG_ERR_MSG("Open internal secure element failed: %s", - error->message); + DEBUG_ERR_MSG("Open internal secure element failed: %s", error->message); g_error_free(error); result = NET_NFC_IPC_FAIL; @@ -503,9 +607,7 @@ API net_nfc_error_e net_nfc_client_se_open_internal_secure_element_sync( API net_nfc_error_e net_nfc_client_se_close_internal_secure_element( - net_nfc_target_handle_h handle, - net_nfc_se_close_se_cb callback, - void *user_data) + net_nfc_target_handle_h handle, net_nfc_se_close_se_cb callback, void *user_data) { SeFuncData *func_data; @@ -518,7 +620,7 @@ API net_nfc_error_e net_nfc_client_se_close_internal_secure_element( /* allow this function even nfc is off */ - func_data = g_new0(SeFuncData, 1); + func_data = g_try_new0(SeFuncData, 1); if (func_data == NULL) return NET_NFC_ALLOC_FAIL; @@ -531,7 +633,7 @@ API net_nfc_error_e net_nfc_client_se_close_internal_secure_element( net_nfc_client_gdbus_get_privilege(), NULL, close_secure_element, - user_data); + func_data); return NET_NFC_OK; } @@ -540,7 +642,7 @@ API net_nfc_error_e net_nfc_client_se_close_internal_secure_element( API net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync( net_nfc_target_handle_h handle) { - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; GError *error = NULL; if (se_proxy == NULL) @@ -571,10 +673,8 @@ API net_nfc_error_e net_nfc_client_se_close_internal_secure_element_sync( } -API net_nfc_error_e net_nfc_client_se_get_atr( - net_nfc_target_handle_h handle, - net_nfc_se_get_atr_cb callback, - void *user_data) +API net_nfc_error_e net_nfc_client_se_get_atr(net_nfc_target_handle_h handle, + net_nfc_se_get_atr_cb callback, void *user_data) { SeFuncData *func_data; @@ -587,7 +687,7 @@ API net_nfc_error_e net_nfc_client_se_get_atr( /* allow this function even nfc is off */ - func_data = g_new0(SeFuncData, 1); + func_data = g_try_new0(SeFuncData, 1); if (func_data == NULL) return NET_NFC_ALLOC_FAIL; @@ -607,23 +707,20 @@ API net_nfc_error_e net_nfc_client_se_get_atr( API net_nfc_error_e net_nfc_client_se_get_atr_sync( - net_nfc_target_handle_h handle, - data_h *atr) + net_nfc_target_handle_h handle, data_h *atr) { - net_nfc_error_e result; - GVariant *out_atr; + net_nfc_error_e result = NET_NFC_OK; + GVariant *out_atr = NULL; GError *error = NULL; - if (atr == NULL) { + if (atr == NULL) return NET_NFC_NULL_PARAMETER; - } *atr = NULL; if (se_proxy == NULL) { DEBUG_ERR_MSG("Can not get se_proxy"); - return NET_NFC_NOT_INITIALIZED; } @@ -649,11 +746,8 @@ API net_nfc_error_e net_nfc_client_se_get_atr_sync( } -API net_nfc_error_e net_nfc_client_se_send_apdu( - net_nfc_target_handle_h handle, - data_h apdu_data, - net_nfc_se_send_apdu_cb callback, - void *user_data) +API net_nfc_error_e net_nfc_client_se_send_apdu(net_nfc_target_handle_h handle, + data_h apdu_data, net_nfc_se_send_apdu_cb callback, void *user_data) { SeFuncData *func_data; GVariant *arg_data; @@ -671,7 +765,7 @@ API net_nfc_error_e net_nfc_client_se_send_apdu( if (arg_data == NULL) return NET_NFC_INVALID_PARAM; - func_data = g_new0(SeFuncData, 1); + func_data = g_try_new0(SeFuncData, 1); if (func_data == NULL) { g_variant_unref(arg_data); @@ -695,18 +789,15 @@ API net_nfc_error_e net_nfc_client_se_send_apdu( API net_nfc_error_e net_nfc_client_se_send_apdu_sync( - net_nfc_target_handle_h handle, - data_h apdu_data, - data_h *response) + net_nfc_target_handle_h handle, data_h apdu_data, data_h *response) { - net_nfc_error_e result; - GVariant *out_data; - GVariant *arg_data; + net_nfc_error_e result = NET_NFC_OK; + GVariant *out_data = NULL; GError *error = NULL; + GVariant *arg_data; - if (response == NULL) { + if (response == NULL) return NET_NFC_NULL_PARAMETER; - } *response = NULL; diff --git a/client/net_nfc_client_sign_record.c b/client/net_nfc_client_sign_record.c index 4f3fb90..05e3795 100644 --- a/client/net_nfc_client_sign_record.c +++ b/client/net_nfc_client_sign_record.c @@ -16,12 +16,14 @@ #include "net_nfc_debug_internal.h" #include "net_nfc_util_sign_record.h" -API net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, int end_index, char *cert_file, char *password) +API net_nfc_error_e net_nfc_sign_records(ndef_message_h msg, int begin_index, + int end_index, char *cert_file, char *password) { return net_nfc_util_sign_records((ndef_message_s *)msg, begin_index, end_index, cert_file, password); } -API net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, char *cert_file, char *password) +API net_nfc_error_e net_nfc_sign_ndef_message(ndef_message_h msg, + char *cert_file, char *password) { return net_nfc_util_sign_ndef_message((ndef_message_s *)msg, cert_file, password); } @@ -31,7 +33,8 @@ API net_nfc_error_e net_nfc_verify_signature_ndef_message(ndef_message_h msg) return net_nfc_util_verify_signature_ndef_message((ndef_message_s *)msg); } -API net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, ndef_record_h sign_record) +API net_nfc_error_e net_nfc_verify_signature_records(ndef_record_h begin_record, + ndef_record_h sign_record) { return net_nfc_util_verify_signature_records((ndef_record_s *)begin_record, (ndef_record_s *)sign_record); } diff --git a/client/net_nfc_client_snep.c b/client/net_nfc_client_snep.c index b920e49..232a6b0 100644 --- a/client/net_nfc_client_snep.c +++ b/client/net_nfc_client_snep.c @@ -344,8 +344,7 @@ API net_nfc_error_e net_nfc_client_snep_send_client_request_sync( } #endif API net_nfc_error_e net_nfc_client_snep_stop_service_sync( - net_nfc_target_handle_h target, - net_nfc_snep_handle_h service) + net_nfc_target_handle_h target, net_nfc_snep_handle_h service) { net_nfc_error_e result = NET_NFC_OK; GError *error = NULL; diff --git a/client/net_nfc_client_system_handler.c b/client/net_nfc_client_system_handler.c index 4de1a65..15d90e8 100644 --- a/client/net_nfc_client_system_handler.c +++ b/client/net_nfc_client_system_handler.c @@ -35,12 +35,10 @@ struct _PopupFuncData static NetNfcGDbusPopup *popup_proxy = NULL; static int popup_state = 0; -static void popup_set_active_callback(GObject *source_object, - GAsyncResult *res, +static void popup_set_active_callback(GObject *source_object, GAsyncResult *res, gpointer user_data); -static void popup_set_active_callback(GObject *source_object, - GAsyncResult *res, +static void popup_set_active_callback(GObject *source_object, GAsyncResult *res, gpointer user_data) { PopupFuncData *func_data; @@ -84,8 +82,7 @@ static void popup_set_active_callback(GObject *source_object, } API net_nfc_error_e net_nfc_client_sys_handler_set_state(int state, - net_nfc_client_popup_set_state_callback callback, - void *user_data) + net_nfc_client_popup_set_state_callback callback, void *user_data) { gboolean active = FALSE; PopupFuncData *func_data; diff --git a/client/net_nfc_client_tag_felica.c b/client/net_nfc_client_tag_felica.c index 9cb0780..c0c34bc 100644 --- a/client/net_nfc_client_tag_felica.c +++ b/client/net_nfc_client_tag_felica.c @@ -222,9 +222,7 @@ API net_nfc_error_e net_nfc_client_felica_request_response( send_buffer[0] = 0xA; send_buffer[1] = FELICA_CMD_REQ_RESPONSE; - memcpy(send_buffer + 2, - ((data_s*)IDm)->buffer, - ((data_s*)IDm)->length); + memcpy(send_buffer + 2, ((data_s*)IDm)->buffer, ((data_s*)IDm)->length); DEBUG_MSG_PRINT_BUFFER(send_buffer, 10); @@ -494,7 +492,6 @@ API net_nfc_error_e net_nfc_client_felica_request_system_code( if (((data_s*)IDm)->length != 8) return NET_NFC_OUT_OF_BOUND; - send_buffer[0] = 0xA; send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE; diff --git a/client/net_nfc_client_tag_internal.h b/client/net_nfc_client_tag_internal.h index 11220d9..18ba50d 100644 --- a/client/net_nfc_client_tag_internal.h +++ b/client/net_nfc_client_tag_internal.h @@ -20,16 +20,8 @@ #include "net_nfc_typedef_internal.h" -#ifdef __cplusplus -extern "C" { -#endif - gboolean net_nfc_client_tag_is_connected(void); -net_nfc_target_info_s *net_nfc_client_tag_get_client_target_info(void); - -#ifdef __cplusplus -} -#endif +net_nfc_target_info_s* net_nfc_client_tag_get_client_target_info(void); #endif //__NET_NFC_CLIENT_TAG_INTERNAL_H__ diff --git a/client/net_nfc_client_tag_jewel.c b/client/net_nfc_client_tag_jewel.c index 07220dc..0af7fdb 100644 --- a/client/net_nfc_client_tag_jewel.c +++ b/client/net_nfc_client_tag_jewel.c @@ -36,10 +36,9 @@ #define JEWEL_TAG_KEY "UID" API net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle, - nfc_transceive_data_callback callback, - void *user_data) + nfc_transceive_data_callback callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; + net_nfc_target_info_s *target_info = NULL; data_s rawdata; @@ -77,12 +76,9 @@ API net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle, } API net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle, - uint8_t block, - uint8_t byte, - nfc_transceive_data_callback callback, - void *user_data) + uint8_t block, uint8_t byte, nfc_transceive_data_callback callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; + net_nfc_target_info_s *target_info = NULL; data_s rawdata; @@ -148,10 +144,9 @@ API net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handl } API net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle, - nfc_transceive_data_callback callback, - void *user_data) + nfc_transceive_data_callback callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; + net_nfc_target_info_s *target_info = NULL; data_s rawdata; @@ -220,12 +215,9 @@ API net_nfc_error_e net_nfc_client_jewel_write_with_erase( nfc_transceive_callback callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; data_s rawdata; - data_h UID = NULL; - uint8_t send_buffer[9] = {0x00, }; if(handle == NULL) @@ -288,7 +280,7 @@ API net_nfc_error_e net_nfc_client_jewel_write_with_no_erase( nfc_transceive_callback callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; + net_nfc_target_info_s *target_info = NULL; data_s rawdata; diff --git a/client/net_nfc_client_tag_mifare.c b/client/net_nfc_client_tag_mifare.c index c81ed94..2afffae 100644 --- a/client/net_nfc_client_tag_mifare.c +++ b/client/net_nfc_client_tag_mifare.c @@ -63,17 +63,12 @@ API net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyA( void *user_data) { net_nfc_target_info_s* target_info = NULL; - data_s *key; data_s rawdata; - data_h UID = NULL; - uint8_t* send_buffer = NULL; uint8_t* temp = NULL; - int send_buffer_length = 0; - uint8_t sector_to_block = 0; @@ -193,20 +188,15 @@ API net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB( void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; data_s *key; data_s rawdata; - data_h UID = NULL; - uint8_t* send_buffer = NULL; uint8_t* temp = NULL; - int send_buffer_length = 0; - uint8_t sector_to_block = 0; - + net_nfc_error_e result; if (handle == NULL || auth_key == NULL) return NET_NFC_NULL_PARAMETER; @@ -303,10 +293,7 @@ API net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB( rawdata.buffer = send_buffer; rawdata.length = send_buffer_length; - net_nfc_error_e result = net_nfc_client_transceive(handle, - (data_h)&rawdata, - callback, - user_data); + result = net_nfc_client_transceive(handle, (data_h)&rawdata, callback, user_data); if (send_buffer != NULL) _net_nfc_util_free_mem(send_buffer); @@ -315,16 +302,11 @@ API net_nfc_error_e net_nfc_client_mifare_authenticate_with_keyB( } API net_nfc_error_e net_nfc_client_mifare_read(net_nfc_target_handle_h handle, - uint8_t addr, - void *callback, - void *user_data) + uint8_t addr, void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; data_s rawdata; - - uint8_t send_buffer[4] = { 0 }; - + uint8_t send_buffer[4] = {0}; if (handle == NULL) return NET_NFC_NULL_PARAMETER; @@ -373,14 +355,11 @@ API net_nfc_error_e net_nfc_client_mifare_write_block( void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; data_s rawdata; - uint8_t* send_buffer = NULL; - uint32_t send_buffer_length = 0; - + net_nfc_error_e result; if (handle == NULL) return NET_NFC_NULL_PARAMETER; @@ -430,9 +409,7 @@ API net_nfc_error_e net_nfc_client_mifare_write_block( *temp = addr; temp++; - memcpy(temp, - ((data_s*)data)->buffer, - MIFARE_PAGE_SIZE); + memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE); } else @@ -521,10 +498,7 @@ API net_nfc_error_e net_nfc_client_mifare_write_block( rawdata.buffer = send_buffer; rawdata.length = send_buffer_length; - net_nfc_error_e result = net_nfc_client_transceive(handle, - (data_h)&rawdata, - callback, - user_data); + result = net_nfc_client_transceive(handle, (data_h)&rawdata, callback, user_data); if (send_buffer != NULL) _net_nfc_util_free_mem(send_buffer); @@ -539,11 +513,11 @@ API net_nfc_error_e net_nfc_client_mifare_write_page( void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; uint8_t* send_buffer = NULL; - uint32_t send_buffer_length = 0; + net_nfc_error_e result; + data_s rawdata; if (handle == NULL) return NET_NFC_NULL_PARAMETER; @@ -680,15 +654,10 @@ API net_nfc_error_e net_nfc_client_mifare_write_page( net_nfc_util_compute_CRC(CRC_A, send_buffer, send_buffer_length); - data_s rawdata; - rawdata.buffer = send_buffer; rawdata.length = send_buffer_length; - net_nfc_error_e result = net_nfc_client_transceive(handle, - (data_h)&rawdata, - callback, - user_data); + result = net_nfc_client_transceive(handle, (data_h)&rawdata, callback, user_data); if (send_buffer != NULL) _net_nfc_util_free_mem(send_buffer); @@ -696,13 +665,14 @@ API net_nfc_error_e net_nfc_client_mifare_write_page( return result; } -API net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h handle, +API net_nfc_error_e net_nfc_client_mifare_increment( + net_nfc_target_handle_h handle, uint8_t addr, int value, void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; + net_nfc_target_info_s *target_info = NULL; data_s rawdata; @@ -749,13 +719,14 @@ API net_nfc_error_e net_nfc_client_mifare_increment(net_nfc_target_handle_h hand user_data); } -API net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h handle, +API net_nfc_error_e net_nfc_client_mifare_decrement( + net_nfc_target_handle_h handle, uint8_t addr, int value, void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; + net_nfc_target_info_s *target_info = NULL; data_s rawdata; @@ -803,14 +774,10 @@ API net_nfc_error_e net_nfc_client_mifare_decrement(net_nfc_target_handle_h hand } API net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handle, - uint8_t addr, - void *callback, - void *user_data) + uint8_t addr, void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; data_s rawdata; - uint8_t send_buffer[4] = { 0 }; if (handle == NULL) @@ -845,14 +812,10 @@ API net_nfc_error_e net_nfc_client_mifare_transfer(net_nfc_target_handle_h handl } API net_nfc_error_e net_nfc_client_mifare_restore(net_nfc_target_handle_h handle, - uint8_t addr, - void *callback, - void *user_data) + uint8_t addr, void *callback, void *user_data) { - net_nfc_target_info_s* target_info = NULL; - + net_nfc_target_info_s *target_info = NULL; data_s rawdata; - uint8_t send_buffer[4] = { 0 }; if (handle == NULL) diff --git a/client/net_nfc_client_target_info.c b/client/net_nfc_client_target_info.c index 1884af2..eef253e 100644 --- a/client/net_nfc_client_target_info.c +++ b/client/net_nfc_client_target_info.c @@ -22,84 +22,79 @@ #include "net_nfc_target_info.h" #include "net_nfc_util_internal.h" -API net_nfc_error_e net_nfc_get_tag_type(net_nfc_target_info_h target_info, net_nfc_target_type_e * type) +API net_nfc_error_e net_nfc_get_tag_type(net_nfc_target_info_h target_info, + net_nfc_target_type_e * type) { if (target_info == NULL || type == NULL) - { return NET_NFC_NULL_PARAMETER; - } + net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info; *type = tmp_target_info->devType; return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, net_nfc_target_handle_h * handle) +API net_nfc_error_e net_nfc_get_tag_handle(net_nfc_target_info_h target_info, + net_nfc_target_handle_h * handle) { if (target_info == NULL || handle == NULL) - { return NET_NFC_NULL_PARAMETER; - } + net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info; *handle = (net_nfc_target_handle_h)tmp_target_info->handle; return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_tag_ndef_support(net_nfc_target_info_h target_info, bool * is_support) +API net_nfc_error_e net_nfc_get_tag_ndef_support( + net_nfc_target_info_h target_info, bool * is_support) { if (target_info == NULL || is_support == NULL) - { return NET_NFC_NULL_PARAMETER; - } + net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info; *is_support = (bool)tmp_target_info->is_ndef_supported; return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_tag_max_data_size(net_nfc_target_info_h target_info, uint32_t * max_size) +API net_nfc_error_e net_nfc_get_tag_max_data_size( + net_nfc_target_info_h target_info, uint32_t * max_size) { if (target_info == NULL || max_size == NULL) - { return NET_NFC_NULL_PARAMETER; - } + net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info; *max_size = tmp_target_info->maxDataSize; return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_tag_actual_data_size(net_nfc_target_info_h target_info, uint32_t * actual_data) +API net_nfc_error_e net_nfc_get_tag_actual_data_size( + net_nfc_target_info_h target_info, uint32_t * actual_data) { if (target_info == NULL || actual_data == NULL) - { return NET_NFC_NULL_PARAMETER; - } + net_nfc_target_info_s * tmp_target_info = (net_nfc_target_info_s*)target_info; *actual_data = tmp_target_info->actualDataSize; return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, char ***keys, int* number_of_keys) +API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, + char ***keys, int *number_of_keys) { if (keys == NULL || number_of_keys == NULL || target_info == NULL) - { return NET_NFC_NULL_PARAMETER; - } net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info; if (handle->tag_info_list == NULL) - { return NET_NFC_NO_DATA_FOUND; - } if (handle->number_of_keys <= 0) - { return NET_NFC_NO_DATA_FOUND; - } int i = 0; @@ -129,19 +124,16 @@ API net_nfc_error_e net_nfc_get_tag_info_keys(net_nfc_target_info_h target_info, return NET_NFC_OK; } -API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, const char* key, data_h* value) +API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info, + const char* key, data_h* value) { if (target_info == NULL || key == NULL || value == NULL) - { return NET_NFC_NULL_PARAMETER; - } net_nfc_target_info_s* handle = (net_nfc_target_info_s*)target_info; if (handle->tag_info_list == NULL) - { return NET_NFC_NO_DATA_FOUND; - } int i = 0; @@ -169,21 +161,18 @@ API net_nfc_error_e net_nfc_get_tag_info_value(net_nfc_target_info_h target_info return NET_NFC_OK; } -API net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, net_nfc_target_info_h *result) +API net_nfc_error_e net_nfc_duplicate_target_info(net_nfc_target_info_h origin, + net_nfc_target_info_h *result) { net_nfc_target_info_s *handle = (net_nfc_target_info_s *)origin; net_nfc_target_info_s *temp = NULL; if (handle == NULL || result == NULL) - { return NET_NFC_NULL_PARAMETER; - } _net_nfc_util_alloc_mem(temp, sizeof(net_nfc_target_info_s)); if (temp == NULL) - { return NET_NFC_ALLOC_FAIL; - } temp->ndefCardState = handle->ndefCardState; temp->actualDataSize = handle->actualDataSize; @@ -265,7 +254,6 @@ static net_nfc_error_e net_nfc_util_release_tag_info(net_nfc_target_info_s *info API net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info) { - net_nfc_error_e result = NET_NFC_OK; net_nfc_target_info_s *info = (net_nfc_target_info_s *)target_info; if (info == NULL) @@ -275,5 +263,5 @@ API net_nfc_error_e net_nfc_release_tag_info(net_nfc_target_info_h target_info) _net_nfc_util_free_mem(info); - return result; + return NET_NFC_OK; } diff --git a/client/net_nfc_client_transceive.c b/client/net_nfc_client_transceive.c index 71579e3..74585c2 100644 --- a/client/net_nfc_client_transceive.c +++ b/client/net_nfc_client_transceive.c @@ -212,9 +212,7 @@ static void transceive_call(GObject *source_object, } API net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle, - data_h rawdata, - nfc_transceive_callback callback, - void *user_data) + data_h rawdata, nfc_transceive_callback callback, void *user_data) { net_nfc_target_info_s *target_info = NULL; data_s *data = (data_s *)rawdata; @@ -247,8 +245,7 @@ API net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle, if (target_info == NULL) return NET_NFC_OPERATION_FAIL; - arg_data = transceive_data_to_transceive_variant(target_info->devType, - data); + arg_data = transceive_data_to_transceive_variant(target_info->devType, data); if (arg_data == NULL) return NET_NFC_OPERATION_FAIL; @@ -270,9 +267,7 @@ API net_nfc_error_e net_nfc_client_transceive(net_nfc_target_handle_h handle, } API net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handle, - data_h rawdata, - nfc_transceive_data_callback callback, - void *user_data) + data_h rawdata, nfc_transceive_data_callback callback, void *user_data) { net_nfc_target_info_s *target_info = NULL; data_s *data = (data_s *)rawdata; @@ -305,8 +300,7 @@ API net_nfc_error_e net_nfc_client_transceive_data(net_nfc_target_handle_h handl if (target_info == NULL) return NET_NFC_OPERATION_FAIL; - arg_data = transceive_data_to_transceive_variant(target_info->devType, - data); + arg_data = transceive_data_to_transceive_variant(target_info->devType, data); if (arg_data == NULL) return NET_NFC_OPERATION_FAIL; @@ -363,8 +357,7 @@ API net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handl if (target_info == NULL) return NET_NFC_OPERATION_FAIL; - arg_data = transceive_data_to_transceive_variant(target_info->devType, - data); + arg_data = transceive_data_to_transceive_variant(target_info->devType, data); if (arg_data == NULL) return NET_NFC_OPERATION_FAIL; @@ -388,9 +381,7 @@ API net_nfc_error_e net_nfc_client_transceive_sync(net_nfc_target_handle_h handl } API net_nfc_error_e net_nfc_client_transceive_data_sync( - net_nfc_target_handle_h handle, - data_h rawdata, - data_h *response) + net_nfc_target_handle_h handle, data_h rawdata, data_h *response) { net_nfc_target_info_s *target_info = NULL; data_s *data = (data_s *)rawdata; @@ -426,8 +417,7 @@ API net_nfc_error_e net_nfc_client_transceive_data_sync( if (target_info == NULL) return NET_NFC_OPERATION_FAIL; - arg_data = transceive_data_to_transceive_variant(target_info->devType, - data); + arg_data = transceive_data_to_transceive_variant(target_info->devType, data); if (arg_data == NULL) return NET_NFC_OPERATION_FAIL; diff --git a/common/include/net_nfc_typedef.h b/common/include/net_nfc_typedef.h index e0384e7..8bfa913 100644 --- a/common/include/net_nfc_typedef.h +++ b/common/include/net_nfc_typedef.h @@ -226,33 +226,6 @@ typedef enum NET_NFC_MESSAGE_SET_CARD_EMULATION, } net_nfc_message_e; -typedef enum -{ - NET_NFC_UNKNOWN_TARGET = 0x00U, - - /* Specific PICC Devices */ - - NET_NFC_GENERIC_PICC, - NET_NFC_ISO14443_A_PICC, - NET_NFC_ISO14443_4A_PICC, - NET_NFC_ISO14443_3A_PICC, - NET_NFC_MIFARE_MINI_PICC, - NET_NFC_MIFARE_1K_PICC, - NET_NFC_MIFARE_4K_PICC, - NET_NFC_MIFARE_ULTRA_PICC, - NET_NFC_MIFARE_DESFIRE_PICC, - NET_NFC_ISO14443_B_PICC, - NET_NFC_ISO14443_4B_PICC, - NET_NFC_ISO14443_BPRIME_PICC, - NET_NFC_FELICA_PICC, - NET_NFC_JEWEL_PICC, - NET_NFC_ISO15693_PICC, - - /* NFC-IP1 Device Types */ - NET_NFC_NFCIP1_TARGET, - NET_NFC_NFCIP1_INITIATOR, - -} net_nfc_target_type_e; /** Card states for nfc tag @@ -368,6 +341,33 @@ typedef enum typedef enum { + NET_NFC_UNKNOWN_TARGET = 0x00U, + + /* Specific PICC Devices */ + + NET_NFC_GENERIC_PICC, + NET_NFC_ISO14443_A_PICC, + NET_NFC_ISO14443_4A_PICC, + NET_NFC_ISO14443_3A_PICC, + NET_NFC_MIFARE_MINI_PICC, + NET_NFC_MIFARE_1K_PICC, + NET_NFC_MIFARE_4K_PICC, + NET_NFC_MIFARE_ULTRA_PICC, + NET_NFC_MIFARE_DESFIRE_PICC, + NET_NFC_ISO14443_B_PICC, + NET_NFC_ISO14443_4B_PICC, + NET_NFC_ISO14443_BPRIME_PICC, + NET_NFC_FELICA_PICC, + NET_NFC_JEWEL_PICC, + NET_NFC_ISO15693_PICC, + + /* NFC-IP1 Device Types */ + NET_NFC_NFCIP1_TARGET, + NET_NFC_NFCIP1_INITIATOR, +} net_nfc_target_type_e; + +typedef enum +{ NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED, NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS, } net_nfc_socket_type_e; @@ -414,23 +414,7 @@ typedef void (*net_nfc_internal_se_response_cb)(net_nfc_message_e message, typedef void (* net_nfc_set_activation_completed_cb)(net_nfc_error_e error, void *user_data); -// for data exchanger - -typedef enum -{ - NET_NFC_EXCHANGER_DATA_REQUESTED = 0x00, - NET_NFC_EXCHANGER_TRANSFER_COMPLETED, - NET_NFC_EXCHANGER_TRANSFER_FAILED, -} net_nfc_exchanger_event_e; - -typedef enum -{ - NET_NFC_EXCHANGER_RAW, -} net_nfc_exchanger_data_type_e; - -typedef struct _net_nfc_exchanger_data_s *net_nfc_exchanger_data_h; - -typedef net_nfc_exchanger_data_h (*net_nfc_exchanger_cb)(net_nfc_exchanger_event_e event, void *user_param); +// handover typedef enum { diff --git a/common/include/net_nfc_typedef_internal.h b/common/include/net_nfc_typedef_internal.h index 9a99dd4..b7d7090 100644 --- a/common/include/net_nfc_typedef_internal.h +++ b/common/include/net_nfc_typedef_internal.h @@ -471,13 +471,6 @@ typedef struct _net_nfc_request_receive_from_socket_t net_nfc_data_s data; } net_nfc_request_receive_from_socket_t; -// data exchanger -typedef struct _net_nfc_exchanger_data_s -{ - net_nfc_exchanger_data_type_e type; - data_s binary_data; /* this can be binary data */ -} net_nfc_exchanger_data_s; - // these are messages for response typedef void (*target_detection_listener_cb)(void *data, void *user_param); diff --git a/common/include/net_nfc_util_ndef_record.h b/common/include/net_nfc_util_ndef_record.h index 97b5044..c02ee07 100644 --- a/common/include/net_nfc_util_ndef_record.h +++ b/common/include/net_nfc_util_ndef_record.h @@ -21,7 +21,9 @@ /* create record structure with basic info */ -net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record); +net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, + const data_s *typeName, const data_s *id, const data_s *payload, + ndef_record_s **record); /* create text type record diff --git a/common/net_nfc.xml b/common/net_nfc.xml index 92bf069..752e876 100644 --- a/common/net_nfc.xml +++ b/common/net_nfc.xml @@ -11,6 +11,7 @@ + + - @@ -334,6 +335,15 @@ + + + + + + + @@ -431,7 +441,7 @@ - + diff --git a/common/net_nfc_util_ndef_record.c b/common/net_nfc_util_ndef_record.c index 9fe253e..0fe395a 100644 --- a/common/net_nfc_util_ndef_record.c +++ b/common/net_nfc_util_ndef_record.c @@ -37,32 +37,32 @@ net_nfc_error_e net_nfc_util_free_record(ndef_record_s *record) return NET_NFC_OK; } -net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, data_s *typeName, data_s *id, data_s *payload, ndef_record_s **record) +net_nfc_error_e net_nfc_util_create_record(net_nfc_record_tnf_e recordType, + const data_s *typeName, const data_s *id, const data_s *payload, + ndef_record_s **record) { ndef_record_s *record_temp = NULL; if (typeName == NULL || payload == NULL || record == NULL) - { return NET_NFC_NULL_PARAMETER; - } if (recordType < NET_NFC_RECORD_EMPTY || recordType > NET_NFC_RECORD_UNCHAGNED) - { return NET_NFC_OUT_OF_BOUND; - } /* empty_tag */ if (recordType == NET_NFC_RECORD_EMPTY) { - if ((typeName->buffer != NULL) || (payload->buffer != NULL) || (id->buffer != NULL) || (typeName->length != 0) || (payload->length != 0) || (id->length != 0)) + if ((typeName->buffer != NULL) || (payload->buffer != NULL) + || (id->buffer != NULL) || (typeName->length != 0) || (payload->length != 0) + || (id->length != 0)) + { return NET_NFC_NULL_PARAMETER; + } } _net_nfc_util_alloc_mem(record_temp, sizeof(ndef_record_s)); if (record_temp == NULL) - { return NET_NFC_ALLOC_FAIL; - } // set type name and length and TNF field record_temp->TNF = recordType; diff --git a/daemon/net_nfc_server_common.c b/daemon/net_nfc_server_common.c index 051a287..8ee4244 100644 --- a/daemon/net_nfc_server_common.c +++ b/daemon/net_nfc_server_common.c @@ -137,7 +137,6 @@ static void controller_target_detected_cb(void *info, _net_nfc_util_free_mem(info); } -/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */ static void controller_se_transaction_cb(void *info, void *user_context) { @@ -162,7 +161,6 @@ static void controller_se_transaction_cb(void *info, } } -/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */ static void controller_llcp_event_cb(void *info, void *user_context) { @@ -382,9 +380,13 @@ void net_nfc_server_controller_init(void) #ifndef ESE_ALWAYS_ON void net_nfc_server_controller_deinit(void) { - net_nfc_server_controller_async_queue_push( - controller_deinit_thread_func, - NULL); + int ret; + + ret = net_nfc_server_controller_async_queue_push(controller_deinit_thread_func, NULL); + if (FALSE == ret) + { + DEBUG_ERR_MSG("Failed to push onto the queue"); + } } #endif diff --git a/daemon/net_nfc_server_manager.c b/daemon/net_nfc_server_manager.c index 1582119..8c97620 100644 --- a/daemon/net_nfc_server_manager.c +++ b/daemon/net_nfc_server_manager.c @@ -16,31 +16,20 @@ #include -#include "net_nfc_typedef.h" +#include "net_nfc_debug_internal.h" +#include "net_nfc_typedef_internal.h" #include "net_nfc_gdbus.h" #include "net_nfc_server_common.h" #include "net_nfc_server_manager.h" -#include "net_nfc_server_tag.h" - -#include "net_nfc_typedef_internal.h" -#include "net_nfc_debug_internal.h" -#include "net_nfc_server_controller.h" -#include "net_nfc_server.h" #include "net_nfc_server_se.h" #include "net_nfc_server_llcp.h" +#include "net_nfc_server_context.h" +#include "net_nfc_server_controller.h" #include "net_nfc_server_process_snep.h" #include "net_nfc_server_process_npp.h" #include "net_nfc_server_process_handover.h" -#include "net_nfc_server_context.h" -typedef struct _ManagerData ManagerData; - -struct _ManagerData -{ - NetNfcGDbusManager *manager; - GDBusMethodInvocation *invocation; -}; typedef struct _ManagerActivationData ManagerActivationData; @@ -51,24 +40,6 @@ struct _ManagerActivationData gboolean is_active; }; -typedef struct _ManagerPrbsData ManagerPrbsData; - -struct _ManagerPrbsData -{ - NetNfcGDbusManager *manager; - GDBusMethodInvocation *invocation; - guint32 tech; - guint32 rate; -}; - -typedef struct _ServerManagerActivationData ServerManagerActivationData; - -struct _ServerManagerActivationData -{ - NetNfcGDbusManager *manager; - gboolean is_active; -}; - static NetNfcGDbusManager *manager_skeleton = NULL; @@ -177,78 +148,45 @@ static gboolean manager_deactive(void) static void manager_handle_active_thread_func(gpointer user_data) { + ManagerActivationData *data = (ManagerActivationData *)user_data; gboolean ret; + net_nfc_error_e result; - ManagerActivationData *data; - - data = (ManagerActivationData *)user_data; - - if (data == NULL) - { - DEBUG_ERR_MSG("can not get ManagerActivationData"); - return; - } + g_assert(data != NULL); + g_assert(data->manager != NULL); + g_assert(data->invocation != NULL); if (data->is_active) ret = manager_active(); else ret = manager_deactive(); - - if (data->manager == NULL) + if (ret == TRUE) { - DEBUG_ERR_MSG("can not get manager"); - - if(data->invocation) - { - g_dbus_method_invocation_return_dbus_error( - data->invocation, - "org.tizen.NetNfcService.SetActiveError", - "Can not get manager"); + result = NET_NFC_OK; + INFO_MSG("nfc %s", data->is_active ? "activated" : "deactivated"); - g_object_unref(data->invocation); - } - - g_free(data); - return; + net_nfc_gdbus_manager_emit_activated(data->manager, + data->is_active); } - - if (ret == FALSE) + else { - if (data->invocation) - { - g_dbus_method_invocation_return_dbus_error( - data->invocation, - "org.tizen.NetNfcService.SetActiveError", - "Can not set activation"); - - g_object_unref(data->invocation); - } - - g_object_unref(data->manager); - g_free(data); - - return; + result = NET_NFC_OPERATION_FAIL; } - net_nfc_gdbus_manager_emit_activated(data->manager, - data->is_active); - - if (data->invocation) - { - net_nfc_gdbus_manager_complete_set_active(data->manager, - data->invocation); - - g_object_unref(data->invocation); - } + net_nfc_gdbus_manager_complete_set_active(data->manager, + data->invocation, + result); + g_object_unref(data->invocation); g_object_unref(data->manager); + g_free(data); /* shutdown process if it doesn't need */ if (data->is_active == false && - net_nfc_server_gdbus_is_server_busy() == false) { + net_nfc_server_gdbus_is_server_busy() == false) { - net_nfc_manager_quit(); + net_nfc_server_controller_deinit(); } } @@ -260,6 +198,7 @@ static gboolean manager_handle_set_active(NetNfcGDbusManager *manager, gpointer user_data) { ManagerActivationData *data; + gboolean result; INFO_MSG(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation)); @@ -271,13 +210,13 @@ static gboolean manager_handle_set_active(NetNfcGDbusManager *manager, "rw") == false) { DEBUG_ERR_MSG("permission denied, and finished request"); - return TRUE; + return FALSE; } DEBUG_SERVER_MSG("is_active %d", arg_is_active); - data = g_new0(ManagerActivationData, 1); - if(data == NULL) + data = g_try_new0(ManagerActivationData, 1); + if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); g_dbus_method_invocation_return_dbus_error(invocation, @@ -290,24 +229,21 @@ static gboolean manager_handle_set_active(NetNfcGDbusManager *manager, data->invocation = g_object_ref(invocation); data->is_active = arg_is_active; - if (net_nfc_server_controller_async_queue_push( - manager_handle_active_thread_func, - data) == FALSE) + result = net_nfc_server_controller_async_queue_push( + manager_handle_active_thread_func, data); + if (result == FALSE) { g_dbus_method_invocation_return_dbus_error(invocation, "org.tizen.NetNfcService.ThreadError", "can not push to controller thread"); - if (data) - { - g_object_unref(data->manager); - g_object_unref(data->invocation); - g_free(data); - } - return FALSE; + g_object_unref(data->invocation); + g_object_unref(data->manager); + + g_free(data); } - return TRUE; + return result; } static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager, @@ -327,13 +263,14 @@ static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager, "r") == false) { DEBUG_ERR_MSG("permission denied, and finished request"); - return TRUE; + return FALSE; } state = net_nfc_server_get_state(); net_nfc_gdbus_manager_complete_get_server_state(manager, invocation, + NET_NFC_OK, state); return TRUE; } @@ -341,33 +278,28 @@ static gboolean manager_handle_get_server_state(NetNfcGDbusManager *manager, /* server side */ static void manager_active_thread_func(gpointer user_data) { - ServerManagerActivationData *data; - - gboolean ret = FALSE; - - data = (ServerManagerActivationData *)user_data; + ManagerActivationData *data = + (ManagerActivationData *)user_data; + gboolean ret; - if (data == NULL) - { - DEBUG_ERR_MSG("can not get ServerManagerActivationData"); - return; - } + g_assert(data != NULL); if (data->is_active) ret = manager_active(); else ret = manager_deactive(); + if (ret == TRUE) + { + INFO_MSG("nfc %s", + data->is_active ? "activated" : "deactivated"); - if (ret == FALSE) + net_nfc_gdbus_manager_emit_activated(data->manager, data->is_active); + } + else { DEBUG_ERR_MSG("can not set activation"); - g_free(data); - return; } - net_nfc_gdbus_manager_emit_activated(data->manager, - data->is_active); - g_free(data); } @@ -399,9 +331,8 @@ gboolean net_nfc_server_manager_init(GDBusConnection *connection) DEBUG_ERR_MSG("Can not skeleton_export %s", error->message); g_error_free(error); - g_object_unref(manager_skeleton); - manager_skeleton = NULL; + net_nfc_server_manager_deinit(); return FALSE; } @@ -420,22 +351,22 @@ void net_nfc_server_manager_deinit(void) void net_nfc_server_manager_set_active(gboolean is_active) { - ServerManagerActivationData *data; + ManagerActivationData *data; if (manager_skeleton == NULL) { - DEBUG_ERR_MSG("%s is not initialized", - "net_nfc_server_manager"); + DEBUG_ERR_MSG("net_nfc_server_manager is not initialized"); + return; } DEBUG_SERVER_MSG("is_active %d", is_active); - data = g_new0(ServerManagerActivationData, 1); - - if(data == NULL) + data = g_try_new0(ManagerActivationData, 1); + if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); + return; } @@ -448,15 +379,9 @@ void net_nfc_server_manager_set_active(gboolean is_active) { DEBUG_ERR_MSG("can not push to controller thread"); - if (data) - { - g_object_unref(data->manager); - - g_free(data); - } + g_object_unref(data->manager); + g_free(data); } - - return; } bool net_nfc_server_manager_get_active() diff --git a/daemon/net_nfc_server_se.c b/daemon/net_nfc_server_se.c index 98765e7..caf8c5e 100644 --- a/daemon/net_nfc_server_se.c +++ b/daemon/net_nfc_server_se.c @@ -22,7 +22,6 @@ #include "net_nfc_util_internal.h" #include "net_nfc_util_gdbus_internal.h" #include "net_nfc_gdbus.h" -#include "net_nfc_server.h" #include "net_nfc_server_common.h" #include "net_nfc_server_context.h" #include "net_nfc_server_manager.h" @@ -61,6 +60,15 @@ struct _ServerSeData guint event; }; +typedef struct _SeSetCardEmul SeSetCardEmul; + +struct _SeSetCardEmul +{ + NetNfcGDbusSecureElement *object; + GDBusMethodInvocation *invocation; + gint mode; +}; + typedef struct _SeDataSeType SeDataSeType; struct _SeDataSeType @@ -77,7 +85,7 @@ struct _SeDataHandle { NetNfcGDbusSecureElement *object; GDBusMethodInvocation *invocation; - net_nfc_target_handle_s* handle; + net_nfc_target_handle_s *handle; }; typedef struct _SeDataApdu SeDataApdu; @@ -86,7 +94,7 @@ struct _SeDataApdu { NetNfcGDbusSecureElement *object; GDBusMethodInvocation *invocation; - net_nfc_target_handle_s* handle; + net_nfc_target_handle_s *handle; GVariant *data; }; @@ -158,8 +166,7 @@ static void net_nfc_server_se_set_se_mode(uint8_t mode) /* eSE functions */ static bool net_nfc_server_se_is_ese_handle(net_nfc_target_handle_s *handle) { - return (gdbus_ese_handle != NULL && - gdbus_ese_handle == handle); + return (gdbus_ese_handle != NULL && gdbus_ese_handle == handle); } static void net_nfc_server_se_set_current_ese_handle( @@ -171,8 +178,8 @@ static void net_nfc_server_se_set_current_ese_handle( static net_nfc_target_handle_s *net_nfc_server_se_open_ese() { if (gdbus_ese_handle == NULL) { - net_nfc_error_e result; - net_nfc_target_handle_s *handle; + net_nfc_error_e result = NET_NFC_OK; + net_nfc_target_handle_s *handle = NULL; if (net_nfc_controller_secure_element_open( SECURE_ELEMENT_TYPE_ESE, @@ -244,7 +251,7 @@ static void _se_uicc_status_noti_cb(TapiHandle *handle, case TAPI_SIM_STATUS_SIM_INIT_COMPLETED : if (gdbus_se_setting.busy == true) { - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; DEBUG_SERVER_MSG("TAPI_SIM_STATUS_SIM_INIT_COMPLETED"); @@ -517,7 +524,7 @@ static void se_close_secure_element_thread_func(gpointer user_data) /* shutdown process if it doesn't need */ if (net_nfc_server_manager_get_active() == false && net_nfc_server_gdbus_is_server_busy() == false) { - net_nfc_manager_quit(); + net_nfc_server_controller_deinit(); } } @@ -543,7 +550,7 @@ static gboolean se_handle_close_secure_element( return FALSE; } - data = g_new0(SeDataHandle, 1); + data = g_try_new0(SeDataHandle, 1); if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); @@ -556,7 +563,7 @@ static gboolean se_handle_close_secure_element( data->object = g_object_ref(object); data->invocation = g_object_ref(invocation); - data->handle = (net_nfc_target_handle_s *)arg_handle; + data->handle = GUINT_TO_POINTER(arg_handle); result = net_nfc_server_controller_async_queue_push( se_close_secure_element_thread_func, data); @@ -578,9 +585,9 @@ static gboolean se_handle_close_secure_element( static void se_get_atr_thread_func(gpointer user_data) { SeDataHandle *detail = (SeDataHandle *)user_data; + net_nfc_error_e result = NET_NFC_OK; data_s *atr = NULL; GVariant *data; - net_nfc_error_e result; g_assert(detail != NULL); g_assert(detail->object != NULL); @@ -643,7 +650,7 @@ static gboolean se_handle_get_atr( return FALSE; } - data = g_new0(SeDataHandle, 1); + data = g_try_new0(SeDataHandle, 1); if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); @@ -656,7 +663,7 @@ static gboolean se_handle_get_atr( data->object = g_object_ref(object); data->invocation = g_object_ref(invocation); - data->handle = (net_nfc_target_handle_s *)arg_handle; + data->handle = GUINT_TO_POINTER(arg_handle); result = net_nfc_server_controller_async_queue_push( se_get_atr_thread_func, data); @@ -706,7 +713,7 @@ static void se_open_secure_element_thread_func(gpointer user_data) net_nfc_server_se_set_se_type(SECURE_ELEMENT_TYPE_UICC); net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); #endif - handle = (net_nfc_target_handle_s *)_se_uicc_open(); + handle = _se_uicc_open(); if (handle != NULL) { result = NET_NFC_OK; @@ -788,7 +795,7 @@ static gboolean se_handle_open_secure_element( return FALSE; } - data = g_new0(SeDataSeType, 1); + data = g_try_new0(SeDataSeType, 1); if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); @@ -825,9 +832,8 @@ static void se_send_apdu_thread_func(gpointer user_data) SeDataApdu *detail = (SeDataApdu *)user_data; data_s apdu_data = { NULL, 0 }; data_s *response = NULL; - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; GVariant *rspdata = NULL; - bool ret; g_assert(detail != NULL); g_assert(detail->object != NULL); @@ -841,13 +847,8 @@ static void se_send_apdu_thread_func(gpointer user_data) } else if (net_nfc_server_se_is_ese_handle(detail->handle) == true) { - ret = net_nfc_controller_secure_element_send_apdu(detail->handle, - &apdu_data, &response, &result); - if (false == ret) - { - DEBUG_ERR_MSG("net_nfc_controller_secure_element_send_apdu() Failed"); - return; - } + net_nfc_controller_secure_element_send_apdu(detail->handle, + &apdu_data, &response, &result); } else { @@ -901,7 +902,7 @@ static gboolean se_handle_send_apdu( return FALSE; } - data = g_new0(SeDataApdu, 1); + data = g_try_new0(SeDataApdu, 1); if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); @@ -914,7 +915,7 @@ static gboolean se_handle_send_apdu( data->object = g_object_ref(object); data->invocation = g_object_ref(invocation); - data->handle = (net_nfc_target_handle_s *)arg_handle; + data->handle = GUINT_TO_POINTER(arg_handle); data->data = g_variant_ref(apdudata); result = net_nfc_server_controller_async_queue_push( @@ -936,6 +937,118 @@ static gboolean se_handle_send_apdu( return result; } +static void _se_set_card_emulation_thread_func(gpointer user_data) +{ + SeSetCardEmul *data = (SeSetCardEmul *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + if (data->mode == NET_NFC_CARD_EMELATION_ENABLE) + { + net_nfc_controller_set_secure_element_mode( + net_nfc_server_se_get_se_mode(), + SECURE_ELEMENT_VIRTUAL_MODE, + &result); + if (result == NET_NFC_OK) + { + DEBUG_SERVER_MSG("changed to CARD EMULATION ON"); + + net_nfc_server_se_set_se_mode( + SECURE_ELEMENT_VIRTUAL_MODE); + } + else + { + DEBUG_ERR_MSG("CARD EMULATION ON fail [%d]", result); + } + } + else if (data->mode == NET_NFC_CARD_EMULATION_DISABLE) + { + net_nfc_controller_set_secure_element_mode( + net_nfc_server_se_get_se_mode(), + SECURE_ELEMENT_OFF_MODE, + &result); + if (result == NET_NFC_OK) + { + DEBUG_SERVER_MSG("changed to CARD EMULATION OFF"); + + net_nfc_server_se_set_se_mode(SECURE_ELEMENT_OFF_MODE); + } + else + { + DEBUG_ERR_MSG("CARD EMULATION OFF fail [%d]", result); + } + } + else + { + result = NET_NFC_INVALID_PARAM; + } + + net_nfc_gdbus_secure_element_complete_set_card_emulation(data->object, + data->invocation, result); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean _se_handle_set_card_emulation( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + gint arg_mode, + GVariant *smack_privilege) +{ + SeSetCardEmul *data; + gboolean result; + + INFO_MSG(">>> REQUEST from [%s]", + g_dbus_method_invocation_get_sender(invocation)); + + /* check privilege and update client context */ + if (net_nfc_server_gdbus_check_privilege(invocation, + smack_privilege, + "nfc-manager", + "w") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + + return FALSE; + } + + data = g_try_new0(SeSetCardEmul, 1); + if (data == NULL) + { + DEBUG_ERR_MSG("Memory allocation failed"); + g_dbus_method_invocation_return_dbus_error(invocation, + "org.tizen.NetNfcService.AllocationError", + "Can not allocate memory"); + + return FALSE; + } + + data->object = g_object_ref(object); + data->invocation = g_object_ref(invocation); + data->mode = arg_mode; + + result = net_nfc_server_controller_async_queue_push( + _se_set_card_emulation_thread_func, data); + if (result == FALSE) + { + g_dbus_method_invocation_return_dbus_error(invocation, + "org.tizen.NetNfcService.Se.ThreadError", + "can not push to controller thread"); + + g_object_unref(data->object); + g_object_unref(data->invocation); + + g_free(data); + } + + return result; +} + static void se_set_data_thread_func(gpointer user_data) { SeDataSeType *data = (SeDataSeType *)user_data; @@ -987,7 +1100,7 @@ static gboolean se_handle_set( return FALSE; } - data = g_new0(SeDataSeType, 1); + data = g_try_new0(SeDataSeType, 1); if (data == NULL) { DEBUG_ERR_MSG("Memory allocation failed"); @@ -1037,6 +1150,11 @@ gboolean net_nfc_server_se_init(GDBusConnection *connection) G_CALLBACK(se_handle_set), NULL); g_signal_connect(se_skeleton, + "handle-set-card-emulation", + G_CALLBACK(_se_handle_set_card_emulation), + NULL); + + g_signal_connect(se_skeleton, "handle-open-secure-element", G_CALLBACK(se_handle_open_secure_element), NULL); @@ -1087,10 +1205,10 @@ void net_nfc_server_se_deinit(void) static void se_detected_thread_func(gpointer user_data) { - net_nfc_target_handle_s *handle; - uint32_t devType; - GVariant *data; - net_nfc_error_e result; + net_nfc_target_handle_s *handle = NULL; + uint32_t devType = 0; + GVariant *data = NULL; + net_nfc_error_e result = NET_NFC_OK; g_assert(user_data != NULL); @@ -1189,7 +1307,7 @@ void net_nfc_server_se_transaction_received(void *info) (net_nfc_request_se_event_t *)info; ServerSeData *detail; - detail = g_new0(ServerSeData, 1); + detail = g_try_new0(ServerSeData, 1); if (detail != NULL) { detail->event = se_event->request_type; diff --git a/daemon/net_nfc_server_transceive.c b/daemon/net_nfc_server_transceive.c index 64a0d3d..b5314cd 100644 --- a/daemon/net_nfc_server_transceive.c +++ b/daemon/net_nfc_server_transceive.c @@ -61,9 +61,8 @@ struct _TransceiveSendData static void transceive_data_thread_func(gpointer user_data) { - TransceiveSendData *transceive_data = (TransceiveSendData*)user_data; - net_nfc_target_handle_s *handle = - (net_nfc_target_handle_s *)transceive_data->transceive_handle; + TransceiveSendData *transceive_data = user_data; + net_nfc_target_handle_s *handle = GUINT_TO_POINTER(transceive_data->transceive_handle); net_nfc_error_e result; data_s *data = NULL; GVariant *resp_data = NULL; @@ -181,9 +180,8 @@ static gboolean transceive_data_handle(NetNfcGDbusTransceive *transceive, static void transceive_thread_func(gpointer user_data) { - TransceiveSendData *transceive_data = (TransceiveSendData *)user_data; - net_nfc_target_handle_s *handle = - (net_nfc_target_handle_s *)transceive_data->transceive_handle; + TransceiveSendData *transceive_data = user_data; + net_nfc_target_handle_s *handle = GUINT_TO_POINTER(transceive_data->transceive_handle); net_nfc_error_e result = NET_NFC_OK; data_s *data = NULL; diff --git a/tools/ndef-tool/ndef-tool-display.c b/tools/ndef-tool/ndef-tool-display.c index f76693e..b5c9ecb 100644 --- a/tools/ndef-tool/ndef-tool-display.c +++ b/tools/ndef-tool/ndef-tool-display.c @@ -934,9 +934,7 @@ void ndef_tool_display_discovered_tag(net_nfc_target_info_h target) void ndef_tool_display_discovered_target(net_nfc_target_handle_h handle) { if (handle == NULL) - { return; - } fprintf(stdout, "\n************* Target discovered *************\n"); fprintf(stdout, "Target Type : P2P Target (NFCIP1) (%d)\n", NET_NFC_NFCIP1_TARGET); diff --git a/tools/ndef-tool/ndef-tool-tag.c b/tools/ndef-tool/ndef-tool-tag.c index 6da378f..5016125 100644 --- a/tools/ndef-tool/ndef-tool-tag.c +++ b/tools/ndef-tool/ndef-tool-tag.c @@ -114,15 +114,11 @@ static void _p2p_send_cb(net_nfc_target_handle_h handle, void *user_data) fprintf(stdout, "\nsending...\n\n"); - net_nfc_exchanger_data_h data_handle; - data_h rawdata; + data_s *rawdata; net_nfc_create_rawdata_from_ndef_message((ndef_message_h)context->user_param, &rawdata); - net_nfc_create_exchanger_data(&data_handle, rawdata); + /* FIXME */ net_nfc_free_data(rawdata); - - net_nfc_send_exchanger_data(data_handle, handle, user_data); - net_nfc_free_exchanger_data(data_handle); } static void _handover_completed_cb(net_nfc_error_e result, @@ -293,7 +289,7 @@ static void _initialize_tag_context(response_context_t *context) { int ret = 0; - ret = net_nfc_initialize(); + ret = net_nfc_client_initialize(); if (ret == NET_NFC_OK) { net_nfc_set_response_callback(_nfc_response_cb, (void *)context); @@ -310,7 +306,7 @@ static void _release_tag_context(void) { net_nfc_unset_response_callback(); - net_nfc_deinitialize(); + net_nfc_client_deinitialize(); } int ndef_tool_read_ndef_from_tag(const char *file) @@ -515,7 +511,7 @@ int ndef_tool_send_apdu(const char *apdu) if (buffer != NULL) { length = _convert_string_to_hex(apdu, buffer, length); - if (length > 0) + if (0 < length) { response_context.type = length; response_context.user_param = (void *)buffer; diff --git a/tools/ndef-tool/ndef-tool.c b/tools/ndef-tool/ndef-tool.c index a29636e..45e74b4 100644 --- a/tools/ndef-tool/ndef-tool.c +++ b/tools/ndef-tool/ndef-tool.c @@ -40,7 +40,7 @@ void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result, fprintf(stdout, "failed to power on (%d)\n\n", result); net_nfc_unset_response_callback(); - net_nfc_deinitialize(); + net_nfc_client_deinitialize(); g_main_loop_quit(main_loop); break; @@ -51,7 +51,7 @@ void _activation_complete_cb(net_nfc_message_e message, net_nfc_error_e result, fprintf(stdout, "failed to power off (%d)\n\n", result); net_nfc_unset_response_callback(); - net_nfc_deinitialize(); + net_nfc_client_deinitialize(); g_main_loop_quit(main_loop); break; @@ -652,7 +652,7 @@ int main(int argc, char *argv[]) main_loop = g_main_new(true); - net_nfc_initialize(); + net_nfc_client_initialize(); net_nfc_set_response_callback(_activation_complete_cb, NULL); net_nfc_set_state(true, NULL); @@ -682,7 +682,7 @@ int main(int argc, char *argv[]) main_loop = g_main_new(true); - net_nfc_initialize(); + net_nfc_client_initialize(); net_nfc_set_response_callback(_activation_complete_cb, NULL); net_nfc_set_state(false, NULL); @@ -700,7 +700,7 @@ int main(int argc, char *argv[]) break; case OPERATION_SET_SE : - net_nfc_initialize(); + net_nfc_client_initialize(); if (strcmp(file_name, "SIM1") == 0) { net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL); diff --git a/tools/nfc-client/main.c b/tools/nfc-client/main.c index d51aa86..c12723b 100644 --- a/tools/nfc-client/main.c +++ b/tools/nfc-client/main.c @@ -202,7 +202,7 @@ static void net_nfc_test_client_cb(net_nfc_message_e message, net_nfc_error_e re int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2) { net_nfc_error_e result; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); @@ -212,74 +212,16 @@ int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize(); CHECK_RESULT(result); return NET_NFC_TEST_OK; } -net_nfc_exchanger_data_h net_nfc_exchanger_callback(net_nfc_exchanger_event_e event, void * user_param) -{ - PRINT_INFO(" event = [%d] \n", event); - test_case_result = NET_NFC_TEST_OK; - - switch(event) - { - case NET_NFC_EXCHANGER_DATA_REQUESTED: - { - PRINT_INFO("exchange is requested"); - net_nfc_exchanger_data_h ex_data = NULL; - net_nfc_error_e error = NET_NFC_OK; - data_h payload = NULL; - - /* - uint8_t buffer[1024] = {0}; - - int i = 0; - for(; i< 1024; i++){ - buffer[i] = 'a'; - } - - net_nfc_create_data(&payload, buffer, 1024); - */ - - if((error = net_nfc_create_exchanger_data(&ex_data, payload/*(uint8_t *)"http://www.samsung.com"*/)) == NET_NFC_OK) - //if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK) - //if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK) - { - return ex_data; - } - else - { - PRINT_INFO("create exchanger data is failed = [%d]", error); - //pthread_cond_signal (&pcond); - return NULL; - } - } - case NET_NFC_EXCHANGER_TRANSFER_FAILED: - case NET_NFC_EXCHANGER_TRANSFER_COMPLETED: - default: - { - //pthread_cond_signal (&pcond); - - if(event == NET_NFC_EXCHANGER_TRANSFER_COMPLETED) - { - PRINT_INFO("transfer exchanger msg is completed"); - } - else - { - PRINT_INFO("transfer exchanger msg is failed"); - } - - return NULL; - } - } - -} - /*=================================================================================*/ -static void net_nfc_test_reader_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) +static void net_nfc_test_reader_cb(net_nfc_message_e message, + net_nfc_error_e result, void *data, void *user_param, void *trans_data) { //int user_context; @@ -519,7 +461,7 @@ int nfcConnHandover(uint8_t testNumber,void* arg_ptr2) #if 1 test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); net_nfc_state_activate(); @@ -536,7 +478,7 @@ int nfcConnHandover(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ #else @@ -694,7 +636,7 @@ int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); net_nfc_state_activate(); @@ -712,7 +654,7 @@ int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ @@ -728,7 +670,7 @@ int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); net_nfc_state_activate(); @@ -753,7 +695,7 @@ int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); net_nfc_state_activate(); @@ -771,7 +713,7 @@ int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ @@ -809,7 +751,7 @@ static void net_nfc_test_write_cb(net_nfc_message_e message, net_nfc_error_e res ndef_message_h msg = NULL; ndef_record_h record = NULL; - if( (error = net_nfc_create_uri_type_record(&record, "http://www.naver.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK) + if( (error = net_nfc_create_uri_type_record(&record, "http://www.samsung.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK) { if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK) { @@ -957,7 +899,7 @@ int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate(); @@ -974,7 +916,7 @@ int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2) /* result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ return test_case_result; @@ -991,7 +933,7 @@ int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2) read_count = 0; write_count = 0; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate(); @@ -1006,7 +948,7 @@ int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2) /* result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ @@ -1930,7 +1872,7 @@ int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate(); @@ -1945,7 +1887,7 @@ int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ return test_case_result; @@ -1983,7 +1925,7 @@ int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2) } */ - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate(); @@ -2009,7 +1951,7 @@ int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); sleep(1000); @@ -2025,7 +1967,7 @@ int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate(); @@ -2044,7 +1986,7 @@ int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ return test_case_result; @@ -2224,7 +2166,7 @@ int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2) net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate(); @@ -2238,7 +2180,7 @@ int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2) /* result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ @@ -2265,7 +2207,7 @@ int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2) result = net_nfc_create_ndef_message (&uriMsg); CHECK_RESULT(result); - result = net_nfc_create_uri_type_record (&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI); + result = net_nfc_create_uri_type_record (&record ,"http://www.samsung.com", NET_NFC_SCHEMA_FULL_URI); CHECK_RESULT(result); result = net_nfc_append_record_to_ndef_message (uriMsg, record); @@ -2490,7 +2432,6 @@ static void net_nfc_server_socket_cb (net_nfc_llcp_message_e message, net_nfc_er } net_nfc_target_handle_h snep_handle; -net_nfc_exchanger_data_h snep_ex_data = NULL; int temp_count; static void net_nfc_test_snep_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data) @@ -2600,7 +2541,7 @@ int nfcTestSnep(uint8_t testNumber,void* arg_ptr) { net_nfc_error_e result; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate (); result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL); @@ -2613,7 +2554,7 @@ int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2) { net_nfc_error_e result; net_nfc_llcp_config_info_h config; - result = net_nfc_initialize(); + result = net_nfc_client_initialize(); CHECK_RESULT(result); net_nfc_state_activate (); result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL); @@ -2629,7 +2570,7 @@ int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2) result = net_nfc_unset_response_callback (); CHECK_RESULT(result); - result = net_nfc_deinitialize (); + result = net_nfc_client_deinitialize (); CHECK_RESULT(result); */ net_nfc_free_llcp_configure(config); @@ -2863,22 +2804,22 @@ int nfcTestAPIException (uint8_t testNumber,void* arg_ptr) //net_nfc_error_e result; test_case_result = NET_NFC_TEST_FAIL; - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_ALREADY_INITIALIZED); - CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_ALREADY_INITIALIZED); + CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_OK); int count_try = 0; for (count_try = 0; count_try < 20; count_try ++) { - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); - CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_OK); } - CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED); - CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED); + CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_NOT_INITIALIZED); + CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_NOT_INITIALIZED); - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL)); CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL)); @@ -2937,7 +2878,7 @@ int nfcTestAPIException (uint8_t testNumber,void* arg_ptr) sleep (2); net_nfc_state_activate (); - CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_deinitialize () == NET_NFC_OK); PRINT_INSTRUCT("Please close a tag to device!! in 10 sec"); @@ -2952,7 +2893,7 @@ int nfcTestAPIException (uint8_t testNumber,void* arg_ptr) PRINT_INSTRUCT("Please remove the tag from device!!"); sleep (2); - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL)); net_nfc_state_activate (); @@ -2993,7 +2934,7 @@ static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc PRINT_INFO("target id: %X\n", (unsigned int)id); PRINT_INFO("Is NDEF supoort: %d\n", is_ndef); - net_nfc_deinitialize (); // Before calling transceive + net_nfc_client_deinitialize (); // Before calling transceive } break; @@ -3002,7 +2943,7 @@ static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc net_nfc_target_info_h target_info = (net_nfc_target_info_h)data; net_nfc_target_handle_h id; net_nfc_get_tag_handle (target_info, &id); - net_nfc_deinitialize(); + net_nfc_client_deinitialize(); if (NET_NFC_OK == net_nfc_read_tag (id ,NULL)){ test_case_result = NET_NFC_TEST_FAIL; } @@ -3016,7 +2957,7 @@ static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc ndef_record_h record = NULL; net_nfc_get_tag_handle (target_info, &id); - net_nfc_deinitialize(); + net_nfc_client_deinitialize(); net_nfc_create_ndef_message (&message); net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8); @@ -3036,7 +2977,7 @@ static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc char data [] = {0xff,0xff,0xff,0xff,0xff,0xff}; net_nfc_create_data (&key, (const uint8_t*)data, 6); net_nfc_get_tag_handle (target_info, &id); - net_nfc_deinitialize(); + net_nfc_client_deinitialize(); if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){ test_case_result = NET_NFC_TEST_FAIL; } @@ -3074,7 +3015,11 @@ int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr) } CHECK_ASSULT (NET_NFC_OK != result); result = net_nfc_format_ndef(NULL, key, NULL); - if((NET_NFC_NULL_PARAMETER != result)||(NET_NFC_OK == net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL))||(NET_NFC_OK == net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL))||(NET_NFC_NULL_PARAMETER != net_nfc_read_tag (NULL ,NULL))){ + if((NET_NFC_NULL_PARAMETER != result) + ||(NET_NFC_OK == net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL)) + ||(NET_NFC_OK == net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL)) + ||(NET_NFC_NULL_PARAMETER != net_nfc_read_tag (NULL ,NULL))) + { net_nfc_free_data(key); } CHECK_ASSULT (NET_NFC_NULL_PARAMETER == result); @@ -3104,7 +3049,7 @@ int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr) for (test_case = 0 ; test_case < 4; test_case++){ - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); net_nfc_state_activate (); PRINT_INSTRUCT("Please close a tag to device!!"); CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case)); @@ -3114,7 +3059,7 @@ int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr) sleep(2); } - CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_deinitialize () != NET_NFC_OK); return NET_NFC_TEST_OK; } @@ -3200,14 +3145,14 @@ int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr) CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, NULL, &value)); CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value)); - CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_initialize() == NET_NFC_OK); net_nfc_state_activate (); CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL)); PRINT_INSTRUCT("Please close a tag to device!!"); pthread_cond_wait (&pcond,&plock ); - CHECK_ASSULT(net_nfc_deinitialize() == NET_NFC_OK); + CHECK_ASSULT(net_nfc_client_deinitialize() == NET_NFC_OK); return NET_NFC_TEST_OK; }