From: Wonkyu Kwon Date: Wed, 11 Sep 2013 09:15:06 +0000 (+0900) Subject: Implement method getting the secure element currently selected. X-Git-Tag: submit/tizen/20130913.110517~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=64640766db78b4bea7bb4a7756ba46c4ec6b51cd;p=platform%2Fcore%2Fconnectivity%2Fnfc-manager.git Implement method getting the secure element currently selected. Change-Id: Ia51d00c86483ebc14e7e68012c28008864665bb8 --- diff --git a/client/include/net_nfc_client_se.h b/client/include/net_nfc_client_se.h index b6c5ab5..bc8cb76 100644 --- a/client/include/net_nfc_client_se.h +++ b/client/include/net_nfc_client_se.h @@ -24,6 +24,11 @@ typedef void (*net_nfc_se_set_se_cb)( net_nfc_error_e result, void *user_data); +typedef void (*net_nfc_se_get_se_cb)( + net_nfc_error_e result, + net_nfc_se_type_e se_type, + void *user_data); + typedef void (*net_nfc_se_set_card_emulation_cb)(net_nfc_error_e result, void *user_data); @@ -59,8 +64,8 @@ net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync( net_nfc_se_type_e se_type); -net_nfc_error_e net_nfc_client_se_get_secure_element_type(void *user_data); - +net_nfc_error_e net_nfc_client_se_get_secure_element_type( + net_nfc_se_get_se_cb callback, void *user_data); net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync( net_nfc_se_type_e *se_type); @@ -74,37 +79,33 @@ 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_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_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_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_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); - /************* Secure Element CallBack Register/Deregister functions*************/ void net_nfc_client_se_set_ese_detection_cb( diff --git a/client/net_nfc_client_se.c b/client/net_nfc_client_se.c index 987cbd3..d0cc2b7 100644 --- a/client/net_nfc_client_se.c +++ b/client/net_nfc_client_se.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "net_nfc_typedef_internal.h" #include "net_nfc_debug_internal.h" @@ -160,7 +161,7 @@ static void set_secure_element(GObject *source_object, gpointer user_data) { SeFuncData *func_data = (SeFuncData *)user_data; - net_nfc_error_e result; + net_nfc_error_e result = NET_NFC_OK; GError *error = NULL; g_assert(user_data != NULL); @@ -189,6 +190,41 @@ static void set_secure_element(GObject *source_object, g_free(func_data); } +static void get_secure_element(GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + NetNfcCallback *func_data = (NetNfcCallback *)user_data; + net_nfc_error_e result = NET_NFC_OK; + gint type = 0; + GError *error = NULL; + + g_assert(user_data != NULL); + + if (net_nfc_gdbus_secure_element_call_get_finish(se_proxy, + &result, + &type, + res, + &error) == FALSE) + { + DEBUG_ERR_MSG("Could not set secure element: %s", + error->message); + + g_error_free(error); + + result = NET_NFC_IPC_FAIL; + } + + if (func_data->callback != NULL) + { + net_nfc_se_get_se_cb se_callback = + (net_nfc_se_get_se_cb)func_data->callback; + + se_callback(result, type, func_data->user_data); + } + + g_free(func_data); +} static void _set_card_emulation_cb(GObject *source_object, GAsyncResult *res, @@ -457,6 +493,86 @@ API net_nfc_error_e net_nfc_client_se_set_secure_element_type_sync( return result; } +API net_nfc_error_e net_nfc_client_se_get_secure_element_type( + net_nfc_se_get_se_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_get( + se_proxy, + net_nfc_client_gdbus_get_privilege(), + NULL, + get_secure_element, + func_data); + + return NET_NFC_OK; +} + +API net_nfc_error_e net_nfc_client_se_get_secure_element_type_sync( + net_nfc_se_type_e *se_type) +{ + net_nfc_error_e result = NET_NFC_OK; + gint type; +#if 0 + GError *error = NULL; +#endif + 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 1 + if (vconf_get_int(VCONFKEY_NFC_SE_TYPE, &type) == 0) { + *se_type = type; + } else { + result = NET_NFC_OPERATION_FAIL; + } +#else + if (net_nfc_gdbus_secure_element_call_get_sync( + se_proxy, + net_nfc_client_gdbus_get_privilege(), + &result, + (gint)&type, + NULL, + &error) == true) { + *se_type = type; + } else { + DEBUG_ERR_MSG("Set secure element failed: %s", error->message); + + g_error_free(error); + + result = NET_NFC_IPC_FAIL; + } +#endif + 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, diff --git a/common/net_nfc.xml b/common/net_nfc.xml index 293d760..9d3d027 100644 --- a/common/net_nfc.xml +++ b/common/net_nfc.xml @@ -362,6 +362,15 @@ + + + + + + + diff --git a/daemon/net_nfc_server_se.c b/daemon/net_nfc_server_se.c index 08a3d61..cfe80c6 100644 --- a/daemon/net_nfc_server_se.c +++ b/daemon/net_nfc_server_se.c @@ -57,6 +57,7 @@ static TapiHandle *gdbus_uicc_handle; static net_nfc_target_handle_s *gdbus_ese_handle; static int gdbus_uicc_ready; + /* server_side */ typedef struct _ServerSeData ServerSeData; @@ -1113,6 +1114,78 @@ static gboolean se_handle_set( return result; } +static void se_get_data_thread_func(gpointer user_data) +{ + SeDataSeType *data = (SeDataSeType *)user_data; + net_nfc_error_e result = NET_NFC_OK; + + g_assert(data != NULL); + g_assert(data->object != NULL); + g_assert(data->invocation != NULL); + + net_nfc_gdbus_secure_element_complete_get(data->object, + data->invocation, + net_nfc_server_se_get_se_type(), + result); + + g_object_unref(data->invocation); + g_object_unref(data->object); + + g_free(data); +} + +static gboolean se_handle_get( + NetNfcGDbusSecureElement *object, + GDBusMethodInvocation *invocation, + GVariant *smack_privilege) +{ + SeDataSeType *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", + "r") == false) { + DEBUG_ERR_MSG("permission denied, and finished request"); + + return FALSE; + } + + data = g_try_new0(SeDataSeType, 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); + + result = net_nfc_server_controller_async_queue_push( + se_get_data_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; +} + gboolean net_nfc_server_se_init(GDBusConnection *connection) { GError *error = NULL; @@ -1130,6 +1203,12 @@ gboolean net_nfc_server_se_init(GDBusConnection *connection) "handle-set", G_CALLBACK(se_handle_set), NULL); + + g_signal_connect(se_skeleton, + "handle-get", + G_CALLBACK(se_handle_get), + NULL); + g_signal_connect(se_skeleton, "handle-set-card-emulation", G_CALLBACK(_se_handle_set_card_emulation),