/*************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*************/
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*************/
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)
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;
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)
{
}
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;
#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,
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 */
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;
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;
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) {
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)
if (manager_proxy)
{
DEBUG_CLIENT_MSG("Already initialized");
+
return NET_NFC_OK;
}
{
DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
g_error_free(error);
+
return NET_NFC_UNKNOWN_ERROR;
}
g_object_unref(manager_proxy);
manager_proxy = NULL;
}
-
- if (activated_func_data)
- {
- g_free(activated_func_data);
- activated_func_data = NULL;
- }
}
/* internal function */
}
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;
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;
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(),
}
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;
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;
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;
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;
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)
{
#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
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;
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;
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;
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);
}
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);
}
+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);
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);
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);
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);
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);
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;
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)
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,
/* 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;
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) {
&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;
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;
/* 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;
net_nfc_client_gdbus_get_privilege(),
NULL,
close_secure_element,
- user_data);
+ func_data);
return NET_NFC_OK;
}
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)
}
-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;
/* 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;
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;
}
}
-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;
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);
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;
#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);
}
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);
}
}
#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;
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;
}
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;
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);
if (((data_s*)IDm)->length != 8)
return NET_NFC_OUT_OF_BOUND;
-
send_buffer[0] = 0xA;
send_buffer[1] = FELICA_CMD_REQ_SYSTEM_CODE;
#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__
#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;
}
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;
}
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;
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)
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;
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;
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;
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);
}
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;
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;
*temp = addr;
temp++;
- memcpy(temp,
- ((data_s*)data)->buffer,
- MIFARE_PAGE_SIZE);
+ memcpy(temp, ((data_s*)data)->buffer, MIFARE_PAGE_SIZE);
}
else
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);
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;
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);
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;
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;
}
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)
}
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)
#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;
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;
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;
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)
_net_nfc_util_free_mem(info);
- return result;
+ return NET_NFC_OK;
}
}
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;
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;
}
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;
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;
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;
}
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;
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;
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
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;
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
{
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);
/*
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
<method name="SetActive">
<arg type="b" name="is_active" direction="in" />
<arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
</method>
<!--
-->
<method name="GetServerState">
<arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
<arg type="u" name="state" direction="out" />
</method>
-
<!--
Activated
-->
</method>
<!--
+ SetCardEmulation
+ -->
+ <method name="SetCardEmulation">
+ <arg type="i" name="mode" direction="in" />
+ <arg type="a(y)" name="privilege" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!--
OpenSecureElement
-->
<method name="OpenSecureElement">
<arg type="u" name="handle" direction="in" />
<arg type="i" name="type" direction="in" />
<arg type="a(y)" name="privilege" direction="in" />
- <arg type="i" name="event" direction="out" />
+ <arg type="i" name="result" direction="out" />
<arg type="i" name="carrier_type" direction="out" />
<arg type="a(y)" name="handover_data" direction="out" />
</method>
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;
_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)
{
}
}
-/* FIXME : net_nfc_dispatcher_queue_push() need to be removed */
static void controller_llcp_event_cb(void *info,
void *user_context)
{
#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
#include <vconf.h>
-#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;
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;
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();
}
}
gpointer user_data)
{
ManagerActivationData *data;
+ gboolean result;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"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,
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,
"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;
}
/* 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);
}
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;
}
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;
}
{
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()
#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"
guint event;
};
+typedef struct _SeSetCardEmul SeSetCardEmul;
+
+struct _SeSetCardEmul
+{
+ NetNfcGDbusSecureElement *object;
+ GDBusMethodInvocation *invocation;
+ gint mode;
+};
+
typedef struct _SeDataSeType SeDataSeType;
struct _SeDataSeType
{
NetNfcGDbusSecureElement *object;
GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s* handle;
+ net_nfc_target_handle_s *handle;
};
typedef struct _SeDataApdu SeDataApdu;
{
NetNfcGDbusSecureElement *object;
GDBusMethodInvocation *invocation;
- net_nfc_target_handle_s* handle;
+ net_nfc_target_handle_s *handle;
GVariant *data;
};
/* 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(
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,
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");
/* 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();
}
}
return FALSE;
}
- data = g_new0(SeDataHandle, 1);
+ data = g_try_new0(SeDataHandle, 1);
if (data == NULL)
{
DEBUG_ERR_MSG("Memory allocation failed");
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);
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);
return FALSE;
}
- data = g_new0(SeDataHandle, 1);
+ data = g_try_new0(SeDataHandle, 1);
if (data == NULL)
{
DEBUG_ERR_MSG("Memory allocation failed");
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);
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;
return FALSE;
}
- data = g_new0(SeDataSeType, 1);
+ data = g_try_new0(SeDataSeType, 1);
if (data == NULL)
{
DEBUG_ERR_MSG("Memory allocation failed");
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);
}
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
{
return FALSE;
}
- data = g_new0(SeDataApdu, 1);
+ data = g_try_new0(SeDataApdu, 1);
if (data == NULL)
{
DEBUG_ERR_MSG("Memory allocation failed");
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(
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;
return FALSE;
}
- data = g_new0(SeDataSeType, 1);
+ data = g_try_new0(SeDataSeType, 1);
if (data == NULL)
{
DEBUG_ERR_MSG("Memory allocation failed");
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);
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);
(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;
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;
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;
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);
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,
{
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);
{
net_nfc_unset_response_callback();
- net_nfc_deinitialize();
+ net_nfc_client_deinitialize();
}
int ndef_tool_read_ndef_from_tag(const char *file)
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;
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;
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;
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);
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);
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);
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);
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;
#if 1
test_case_result = NET_NFC_TEST_FAIL;
- result = net_nfc_initialize();
+ result = net_nfc_client_initialize();
net_nfc_state_activate();
result = net_nfc_unset_response_callback ();
CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
+ result = net_nfc_client_deinitialize ();
CHECK_RESULT(result);
*/
#else
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();
result = net_nfc_unset_response_callback ();
CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
+ result = net_nfc_client_deinitialize ();
CHECK_RESULT(result);
*/
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();
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();
result = net_nfc_unset_response_callback ();
CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
+ result = net_nfc_client_deinitialize ();
CHECK_RESULT(result);
*/
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)
{
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();
/*
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;
read_count = 0;
write_count = 0;
- result = net_nfc_initialize();
+ result = net_nfc_client_initialize();
CHECK_RESULT(result);
net_nfc_state_activate();
/*
result = net_nfc_unset_response_callback ();
CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
+ result = net_nfc_client_deinitialize ();
CHECK_RESULT(result);
*/
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();
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;
}
*/
- result = net_nfc_initialize();
+ result = net_nfc_client_initialize();
CHECK_RESULT(result);
net_nfc_state_activate();
result = net_nfc_unset_response_callback ();
CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
+ result = net_nfc_client_deinitialize ();
sleep(1000);
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();
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;
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();
/*
result = net_nfc_unset_response_callback ();
CHECK_RESULT(result);
- result = net_nfc_deinitialize ();
+ result = net_nfc_client_deinitialize ();
CHECK_RESULT(result);
*/
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);
}
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)
{
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);
{
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);
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);
//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));
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");
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 ();
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;
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;
}
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);
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;
}
}
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);
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));
sleep(2);
}
- CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK);
+ CHECK_ASSULT(net_nfc_client_deinitialize () != NET_NFC_OK);
return NET_NFC_TEST_OK;
}
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;
}