Implement method getting the secure element currently selected.
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Wed, 11 Sep 2013 09:15:06 +0000 (18:15 +0900)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 12 Sep 2013 05:14:34 +0000 (22:14 -0700)
Change-Id: Ia51d00c86483ebc14e7e68012c28008864665bb8

client/include/net_nfc_client_se.h
client/net_nfc_client_se.c
common/net_nfc.xml
daemon/net_nfc_server_se.c

index b6c5ab51a16b2dfd48124674163929e90c1f0705..bc8cb764c03ee00cc0a09304891eb69161121096 100644 (file)
@@ -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(
index 987cbd3e1d3b011ebd0ce62449b581aa25a4edf2..d0cc2b7d1e453d44a4c136948f9ed1b23ebd1c0e 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <vconf.h>
 
 #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,
index 293d7600577836219584193af5a5aec4c01ad336..9d3d027d275a1ad18aaaea5ebeea549de654c3bc 100644 (file)
       <arg type="i" name="result" direction="out" />
     </method>
 
+    <!--
+      Get
+    -->
+    <method name="Get">
+      <arg type="a(y)" name="privilege" direction="in" />
+      <arg type="i" name="result" direction="out" />
+      <arg type="i" name="type" direction="out" />
+    </method>
+
     <!--
       SetCardEmulation
     -->
index 08a3d61f5a8a9884b15f187d489851696653215e..cfe80c61427baacde19e999af2f5fc54a771dd5a 100644 (file)
@@ -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),