Usage of raw pointers in API of nfc-manager D-Bus service 07/236207/2
authorHimanshu Kumar <himanshu.kr@samsung.com>
Mon, 15 Jun 2020 12:41:38 +0000 (18:11 +0530)
committerJihoon Jung <jh8801.jung@samsung.com>
Tue, 16 Jun 2020 08:07:22 +0000 (17:07 +0900)
Change-Id: I232051cd095b100bfab5cfd4f22c0d4be80bada5
Signed-off-by: Himanshu Kumar <himanshu.kr@samsung.com>
packaging/nfc-manager.spec
src/manager/include/net_nfc_server_context_internal.h
src/manager/net_nfc_server_context.c
src/manager/net_nfc_server_hce.c
src/manager/net_nfc_server_se.c

index 3eaf4c32dc4562766b6ea13175de490c0c595407..34941a4dda060ae9dcddc8086253e880bd7745fb 100644 (file)
@@ -1,6 +1,6 @@
 Name:       nfc-manager
 Summary:    NFC framework manager
-Version:    0.1.179
+Version:    0.2.0
 Release:    0
 Group:      Network & Connectivity/NFC
 License:    Flora-1.1
index c15748bf7e145d17ec57747b32afca669de52829..a582d52dc20b98d94abbf9dd37047ae0240ab0f3 100644 (file)
@@ -84,4 +84,6 @@ bool net_nfc_server_gdbus_is_server_busy();
 
 net_nfc_error_e net_nfc_server_gdbus_set_transaction_fg_dispatch(const char *id, int fgDispatch);
 
+bool net_nfc_server_gdbus_check_client_context(const char *id);
+
 #endif                                                 //__NET_NFC_SERVER_CONTEXT_INTERNAL_H__
index 234ed1eedce3e1dd61b0a469f41cae8c92a2b534..827c3231f0e8358635ec0f50462aac9d43647785 100644 (file)
@@ -517,6 +517,23 @@ bool net_nfc_server_gdbus_get_client_transaction_fg_dispatch_state(pid_t pid)
        return state;
 }
 
+bool net_nfc_server_gdbus_check_client_context(const char *id)
+{
+       bool result = false;
+       net_nfc_client_context_info_t *info;
+
+       pthread_mutex_lock(&context_lock);
+
+       info = net_nfc_server_gdbus_get_client_context_no_lock(id);
+
+       if(info != NULL)
+               result = true;
+
+       pthread_mutex_unlock(&context_lock);
+
+       return result;
+}
+
 void net_nfc_server_gdbus_increase_se_count(const char *id)
 {
        net_nfc_client_context_info_t *info;
index 23898e076b2c65c3d7a203db54a46b660a0401ae..fd1f886f22dd8f982db79c397f43148b7928aba5 100644 (file)
@@ -61,6 +61,7 @@ struct _SeDataHandle {
        NetNfcGDbusHce *object;
        GDBusMethodInvocation *invocation;
        net_nfc_target_handle_s *handle;
+       guint se_type;
 };
 
 typedef struct _ServerHceData ServerHceData;
index cc14facecd4e5b2f9139e1d5b8ccfba3691afa79..bde1b081c79998874ee1d14b0c5d6f1ec42f0a33 100755 (executable)
@@ -104,6 +104,7 @@ struct _SeDataHandle {
        NetNfcGDbusSecureElement *object;
        GDBusMethodInvocation *invocation;
        net_nfc_target_handle_s *handle;
+       guint se_type;
 };
 
 typedef struct _SeDataApdu SeDataApdu;
@@ -113,6 +114,7 @@ struct _SeDataApdu {
        GDBusMethodInvocation *invocation;
        net_nfc_target_handle_s *handle;
        GVariant *data;
+       guint se_type;
 };
 
 typedef struct _SeSetPreferred SeSetPreferred;
@@ -721,10 +723,6 @@ static net_nfc_target_handle_s *_se_uicc_open(void)
        return result;
 }
 
-static bool _se_is_uicc_handle(net_nfc_target_handle_s * handle)
-{
-       return (gdbus_uicc_ready == SE_UICC_READY && gdbus_uicc_handle != NULL && (TapiHandle *) handle == gdbus_uicc_handle);
-}
 /* LCOV_EXCL_STOP */
 
 static void _se_uicc_close(net_nfc_target_handle_s * handle)
@@ -868,23 +866,25 @@ net_nfc_error_e net_nfc_server_se_change_wallet_mode(net_nfc_wallet_mode_e walle
 static void se_close_secure_element_thread_func(gpointer user_data)
 {
        SeDataHandle *detail = (SeDataHandle *) user_data;
-       net_nfc_error_e result;
+       net_nfc_error_e result = NET_NFC_INVALID_HANDLE;
 
        g_assert(detail != NULL);
        g_assert(detail->object != NULL);
        g_assert(detail->invocation != NULL);
 
-       if (_se_is_uicc_handle(detail->handle) == true) {
-               _se_uicc_close(detail->handle);
+       if(net_nfc_server_gdbus_check_client_context(g_dbus_method_invocation_get_sender(detail->invocation)) == true) {
+               if (detail->se_type == NET_NFC_SE_TYPE_UICC && gdbus_uicc_handle != NULL && gdbus_uicc_ready == SE_UICC_READY ) {
+               _se_uicc_close((net_nfc_target_handle_s *)gdbus_uicc_handle);
 
                result = NET_NFC_OK;
-       } else if (net_nfc_server_se_is_ese_handle(detail->handle) == true) {
+       } else if (detail->se_type == NET_NFC_SE_TYPE_ESE && gdbus_ese_handle != NULL ) {
                /* decrease client reference count */
                net_nfc_server_gdbus_decrease_se_count(g_dbus_method_invocation_get_sender(detail->invocation));
 
                result = net_nfc_server_se_close_ese();
        } else {
                result = NET_NFC_INVALID_HANDLE;
+               }
        }
 
        net_nfc_gdbus_secure_element_complete_close_secure_element(detail->object, detail->invocation, result);
@@ -926,7 +926,7 @@ static gboolean se_handle_close_secure_element(NetNfcGDbusSecureElement * object
 
        data->object = g_object_ref(object);
        data->invocation = g_object_ref(invocation);
-       data->handle = (net_nfc_target_handle_s *) (intptr_t)arg_handle;
+       data->se_type = arg_handle;
 
        if (net_nfc_server_controller_async_queue_push_force(se_close_secure_element_thread_func, data) == FALSE) {
                /* return error if queue was blocked */
@@ -954,7 +954,7 @@ static gboolean se_handle_close_secure_element(NetNfcGDbusSecureElement * object
 static void se_get_atr_thread_func(gpointer user_data)
 {
        SeDataHandle *detail = (SeDataHandle *) user_data;
-       net_nfc_error_e result = NET_NFC_OK;
+       net_nfc_error_e result = NET_NFC_INVALID_HANDLE;
        data_s *atr = NULL;
        GVariant *data;
 
@@ -962,19 +962,20 @@ static void se_get_atr_thread_func(gpointer user_data)
        g_assert(detail->object != NULL);
        g_assert(detail->invocation != NULL);
 
-       if (_se_is_uicc_handle(detail->handle) == true) {
-               if (_se_uicc_get_atr(detail->handle, &atr) == true)
+       if(net_nfc_server_gdbus_check_client_context(g_dbus_method_invocation_get_sender(detail->invocation)) == true) {
+               if (detail->se_type == NET_NFC_SE_TYPE_UICC && gdbus_uicc_handle != NULL && gdbus_uicc_ready == SE_UICC_READY ) {
+                       if (_se_uicc_get_atr((net_nfc_target_handle_s *)gdbus_uicc_handle, &atr) == true)
                        result = NET_NFC_OK;
                else
                        result = NET_NFC_OPERATION_FAIL;
-       } else if (net_nfc_server_se_is_ese_handle(detail->handle) == true) {
-               net_nfc_controller_secure_element_get_atr(detail->handle, &atr, &result);
+       } else if (detail->se_type == NET_NFC_SE_TYPE_ESE && gdbus_ese_handle != NULL) {
+               net_nfc_controller_secure_element_get_atr(gdbus_ese_handle, &atr, &result);
        } else {
                DEBUG_ERR_MSG("invalid se handle");
 
                result = NET_NFC_INVALID_HANDLE;
+               }
        }
-
        data = net_nfc_util_gdbus_data_to_variant(atr);
 
        net_nfc_gdbus_secure_element_complete_get_atr(detail->object, detail->invocation, result, data);
@@ -1013,7 +1014,7 @@ static gboolean se_handle_get_atr(NetNfcGDbusSecureElement * object, GDBusMethod
 
        data->object = g_object_ref(object);
        data->invocation = g_object_ref(invocation);
-       data->handle = (net_nfc_target_handle_s *) (intptr_t)arg_handle;
+       data->se_type = arg_handle;
 
        if (net_nfc_server_controller_async_queue_push_force(se_get_atr_thread_func, data) == FALSE) {
                /* return error if queue was blocked */
@@ -1041,6 +1042,9 @@ static gboolean se_handle_get_atr(NetNfcGDbusSecureElement * object, GDBusMethod
 static void se_open_secure_element_thread_func(gpointer user_data)
 {
        SeDataSeType *detail = (SeDataSeType *) user_data;
+       // as handle is not used by client except to check NULL
+       // instead handle, pass se_type for further ese-communication
+       // all operation will be done in ese through gdbus_ese_handle/gdbus_uicc_handle which is static
        net_nfc_target_handle_s *handle = NULL;
        net_nfc_error_e result = NET_NFC_OK;
 
@@ -1094,7 +1098,8 @@ static void se_open_secure_element_thread_func(gpointer user_data)
 #ifdef ACCESS_CONTROL
  END:
 #endif
-       net_nfc_gdbus_secure_element_complete_open_secure_element(detail->object, detail->invocation, result, (intptr_t) handle);
+       // As handle which is a pointer should not be exposed instead handle , passing se_type as handle is not required by ese-client app
+       net_nfc_gdbus_secure_element_complete_open_secure_element(detail->object, detail->invocation, result, detail->se_type);
 
        g_object_unref(detail->invocation);
        g_object_unref(detail->object);
@@ -1166,9 +1171,9 @@ static void se_send_apdu_thread_func(gpointer user_data)
        g_assert(detail->invocation != NULL);
 
        net_nfc_util_gdbus_variant_to_data_s(detail->data, &apdu_data);
-
-       if (_se_is_uicc_handle(detail->handle) == true) {
-               ret = _se_uicc_send_apdu(detail->handle, &apdu_data, &response);
+       if(net_nfc_server_gdbus_check_client_context(g_dbus_method_invocation_get_sender(detail->invocation)) == true) {
+               if (detail->se_type == NET_NFC_SE_TYPE_UICC && gdbus_uicc_handle != NULL && gdbus_uicc_ready == SE_UICC_READY ) {
+               ret = _se_uicc_send_apdu((net_nfc_target_handle_s *)gdbus_uicc_handle, &apdu_data, &response);
                if (ret == false) {
                        DEBUG_ERR_MSG("_se_uicc_send_apdu failed");
 
@@ -1176,10 +1181,11 @@ static void se_send_apdu_thread_func(gpointer user_data)
                } else {
                        result = NET_NFC_OK;
                }
-       } 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);
+       } else if (detail->se_type == NET_NFC_SE_TYPE_ESE && gdbus_ese_handle != NULL) {
+               ret = net_nfc_controller_secure_element_send_apdu(gdbus_ese_handle, &apdu_data, &response, &result);
        } else {
-               result = NET_NFC_INVALID_HANDLE;
+                       result = NET_NFC_INVALID_HANDLE;
+               }
        }
 
        rspdata = net_nfc_util_gdbus_data_to_variant(response);
@@ -1224,8 +1230,8 @@ static gboolean se_handle_send_apdu(NetNfcGDbusSecureElement * object, GDBusMeth
 
        data->object = g_object_ref(object);
        data->invocation = g_object_ref(invocation);
-       data->handle = (net_nfc_target_handle_s *) (intptr_t)arg_handle;
        data->data = g_variant_ref(apdudata);
+       data->se_type = arg_handle;
 
        if (net_nfc_server_controller_async_queue_push_force(se_send_apdu_thread_func, data) == FALSE) {
                /* return error if queue was blocked */