Add test mode on/off interface 21/287721/1 accepted/tizen_8.0_unified tizen_8.0 accepted/tizen/8.0/unified/20231005.093233 accepted/tizen/unified/20230213.170712 tizen_8.0_m2_release
authorJihoon Jung <jh8801.jung@samsung.com>
Fri, 3 Feb 2023 03:41:48 +0000 (12:41 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Fri, 3 Feb 2023 03:41:48 +0000 (12:41 +0900)
Change-Id: I8f628e5ccb00edb4b89f6ab43901332e25cb7ab3
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/commonlib/net_nfc.xml
src/manager/net_nfc_server_test.c

index 2ffc09e..a17423b 100644 (file)
 
   <interface name="org.tizen.NetNfcService.Test">
     <!--
+      TestModeOn
+    -->
+    <method name="TestModeOn">
+      <arg type="i" name="result" direction="out" />
+    </method>
+
+    <!--
+      TestOff
+    -->
+    <method name="TestModeOff">
+      <arg type="i" name="result" direction="out" />
+    </method>
+
+    <!--
       SimTest
     -->
     <method name="SimTest">
index bcb81a3..a85411b 100644 (file)
@@ -60,6 +60,10 @@ struct _TestSetListenTechData {
        guint32 mode;
 };
 
+static void test_handle_test_mode_on_thread_func(gpointer user_data);
+
+static void test_handle_test_mode_off_thread_func(gpointer user_data);
+
 static void test_handle_sim_test_thread_func(gpointer user_data);
 
 static void test_handle_prbs_test_thread_func(gpointer user_data);
@@ -68,6 +72,10 @@ static void test_handle_get_firmware_version_thread_func(gpointer user_data);
 
 static void test_handle_set_ee_data_thread_func(gpointer user_data);
 
+static gboolean test_handle_test_mode_on(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, GVariant * smack_privilege, gpointer user_data);
+
+static gboolean test_handle_test_mode_off(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, GVariant * smack_privilege, gpointer user_data);
+
 static gboolean test_handle_sim_test(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, GVariant * smack_privilege, gpointer user_data);
 
 static gboolean test_handle_prbs_test(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, guint32 arg_tech, guint32 arg_rate, GVariant * smack_privilege, gpointer user_data);
@@ -79,6 +87,44 @@ static gboolean test_handle_set_ee_data(NetNfcGDbusTest * test, GDBusMethodInvoc
 static NetNfcGDbusTest *test_skeleton = NULL;
 
 /* LCOV_EXCL_START */
+static void test_handle_test_mode_on_thread_func(gpointer user_data)
+{
+       TestData *data = (TestData *) user_data;
+       net_nfc_error_e result = NET_NFC_OK;
+
+       g_assert(data != NULL);
+       g_assert(data->test != NULL);
+       g_assert(data->invocation != NULL);
+
+       net_nfc_controller_test_mode_on(&result);
+
+       net_nfc_gdbus_test_complete_test_mode_on(data->test, data->invocation, (gint) result);
+
+       g_object_unref(data->invocation);
+       g_object_unref(data->test);
+
+       g_free(data);
+}
+
+static void test_handle_test_mode_off_thread_func(gpointer user_data)
+{
+       TestData *data = (TestData *) user_data;
+       net_nfc_error_e result = NET_NFC_OK;
+
+       g_assert(data != NULL);
+       g_assert(data->test != NULL);
+       g_assert(data->invocation != NULL);
+
+       net_nfc_controller_test_mode_off(&result);
+
+       net_nfc_gdbus_test_complete_test_mode_off(data->test, data->invocation, (gint) result);
+
+       g_object_unref(data->invocation);
+       g_object_unref(data->test);
+
+       g_free(data);
+}
+
 static void test_handle_sim_test_thread_func(gpointer user_data)
 {
        TestData *data = (TestData *) user_data;
@@ -191,6 +237,108 @@ static void test_handle_ese_test_thread_func(gpointer user_data)
        g_free(data);
 }
 
+static gboolean test_handle_test_mode_on(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, GVariant * smack_privilege, gpointer user_data)
+{
+    TestData *data = NULL;
+    gint 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, NET_NFC_PRIVILEGE_NFC) == false) {
+        DEBUG_ERR_MSG("permission denied, and finished request");
+        result = NET_NFC_PERMISSION_DENIED;
+
+        goto ERROR;
+    }
+
+    DEBUG_SERVER_MSG("test_mode_on");
+
+    data = g_try_new0(TestData, 1);
+    if (data == NULL) {
+        DEBUG_ERR_MSG("Memory allocation failed");
+        result = NET_NFC_ALLOC_FAIL;
+
+        goto ERROR;
+    }
+
+    data->test = g_object_ref(test);
+    data->invocation = g_object_ref(invocation);
+
+    if (net_nfc_server_controller_async_queue_push(test_handle_test_mode_on_thread_func, data) == FALSE) {
+        /* return error if queue was blocked */
+        DEBUG_SERVER_MSG("controller is processing important message..");
+        result = NET_NFC_BUSY;
+
+        goto ERROR;
+    }
+
+    return TRUE;
+
+ ERROR:
+    if (data != NULL) {
+        g_object_unref(data->invocation);
+        g_object_unref(data->test);
+
+        g_free(data);
+    }
+
+    net_nfc_gdbus_test_complete_test_mode_on(test, invocation, result);
+
+    return TRUE;
+}
+
+static gboolean test_handle_test_mode_off(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, GVariant * smack_privilege, gpointer user_data)
+{
+    TestData *data = NULL;
+    gint 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, NET_NFC_PRIVILEGE_NFC) == false) {
+        DEBUG_ERR_MSG("permission denied, and finished request");
+        result = NET_NFC_PERMISSION_DENIED;
+
+        goto ERROR;
+    }
+
+    DEBUG_SERVER_MSG("test_mode_off");
+
+    data = g_try_new0(TestData, 1);
+    if (data == NULL) {
+        DEBUG_ERR_MSG("Memory allocation failed");
+        result = NET_NFC_ALLOC_FAIL;
+
+        goto ERROR;
+    }
+
+    data->test = g_object_ref(test);
+    data->invocation = g_object_ref(invocation);
+
+    if (net_nfc_server_controller_async_queue_push(test_handle_test_mode_off_thread_func, data) == FALSE) {
+        /* return error if queue was blocked */
+        DEBUG_SERVER_MSG("controller is processing important message..");
+        result = NET_NFC_BUSY;
+
+        goto ERROR;
+    }
+
+    return TRUE;
+
+ ERROR:
+    if (data != NULL) {
+        g_object_unref(data->invocation);
+        g_object_unref(data->test);
+
+        g_free(data);
+    }
+
+    net_nfc_gdbus_test_complete_test_mode_off(test, invocation, result);
+
+    return TRUE;
+}
+
 static gboolean test_handle_sim_test(NetNfcGDbusTest * test, GDBusMethodInvocation * invocation, GVariant * smack_privilege, gpointer user_data)
 {
        TestData *data = NULL;
@@ -600,6 +748,10 @@ gboolean net_nfc_server_test_init(GDBusConnection * connection)
 
        test_skeleton = net_nfc_gdbus_test_skeleton_new();
 
+       g_signal_connect(test_skeleton, "handle-test-mode-on", G_CALLBACK(test_handle_test_mode_on), NULL);
+
+       g_signal_connect(test_skeleton, "handle-test-mode-off", G_CALLBACK(test_handle_test_mode_off), NULL);
+
        g_signal_connect(test_skeleton, "handle-sim-test", G_CALLBACK(test_handle_sim_test), NULL);
 
        g_signal_connect(test_skeleton, "handle-prbs-test", G_CALLBACK(test_handle_prbs_test), NULL);