Add plugin reset method for ese open fail 16/207416/1 accepted/tizen/unified/20190605.215602 submit/tizen/20190605.020213
authorJihoon Jung <jh8801.jung@samsung.com>
Tue, 4 Jun 2019 10:06:01 +0000 (19:06 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Tue, 4 Jun 2019 10:19:21 +0000 (19:19 +0900)
Change-Id: I55660e300730b423afd7d9eec277f9784c835e45

src/manager/include/net_nfc_server_common.h [changed mode: 0644->0755]
src/manager/net_nfc_server_common.c [changed mode: 0644->0755]
src/manager/net_nfc_server_se.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 0bebf91..b9d6be6
@@ -31,6 +31,9 @@ void net_nfc_server_controller_init(void);
 #ifndef ESE_ALWAYS_ON
 void net_nfc_server_controller_deinit(void);
 #endif
+void net_nfc_server_controller_deinit_without_quit(void);
+
+void net_nfc_server_controller_reset(void);
 
 gboolean net_nfc_server_controller_is_blocked();
 
old mode 100644 (file)
new mode 100755 (executable)
index b7974bd..1d7cb02
@@ -72,6 +72,9 @@ static gint controller_block;
 static gboolean deinit_is_running = FALSE;
 static gboolean check_nfc_disable = FALSE;
 
+static pthread_mutex_t reset_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t reset_cond = PTHREAD_COND_INITIALIZER;
+
 static void controller_async_queue_free_func(gpointer user_data)
 {
        ControllerFuncData *func_data = (ControllerFuncData *) user_data;
@@ -347,6 +350,7 @@ static void controller_init_thread_func(gpointer user_data)
                abort();
        }
 
+       pthread_cond_signal(&reset_cond);
        DEBUG_SERVER_MSG("net_nfc_server_llcp_set_config success");
 }
 /* LCOV_EXCL_STOP */
@@ -370,6 +374,18 @@ static void controller_deinit_thread_func(gpointer user_data)
 }
 #endif
 
+static void controller_deinit_without_quit_thread_func(gpointer user_data)
+{
+       net_nfc_server_free_target_info();
+
+       if (net_nfc_controller_deinit() == false) {
+               DEBUG_ERR_MSG("net_nfc_controller_deinit failed");
+               return;
+       }
+
+       DEBUG_SERVER_MSG("net_nfc_controller_deinit success");
+}
+
 /* LCOV_EXCL_START */
 static void restart_polling_loop_thread_func(gpointer user_data)
 {
@@ -535,6 +551,36 @@ void net_nfc_server_controller_deinit(void)
        }
 }
 #endif
+void net_nfc_server_controller_deinit_without_quit()
+{
+       if (controller_async_queue == NULL) {
+               DEBUG_ERR_MSG("controller_async_queue is not initialized");     //LCOV_EXCL_LINE
+
+               return;
+       }
+
+       _push_to_queue(0, false, controller_deinit_without_quit_thread_func, NULL);
+}
+
+void net_nfc_server_controller_reset(void)
+{
+       DEBUG_ERR_MSG("[%s] START", __func__);
+
+       struct timeval now;
+       struct timespec ts;
+
+       gettimeofday(&now, NULL);
+       ts.tv_sec = now.tv_sec + 5;
+       ts.tv_nsec = now.tv_usec * 1000;
+
+       pthread_mutex_lock(&reset_mutex);
+       net_nfc_server_controller_deinit_without_quit();
+       net_nfc_server_controller_init();
+       pthread_cond_timedwait(&reset_cond, &reset_mutex, &ts);
+       pthread_mutex_unlock(&reset_mutex);
+
+       DEBUG_ERR_MSG("[%s] END", __func__);
+}
 
 gboolean net_nfc_server_controller_is_blocked()
 {
old mode 100644 (file)
new mode 100755 (executable)
index fd35b2c..cfffc73
@@ -583,7 +583,20 @@ static net_nfc_target_handle_s *net_nfc_server_se_open_ese()
 
                        SECURE_MSG("handle [%p]", handle);
                } else {
-                       DEBUG_ERR_MSG("net_nfc_controller_secure_element_open failed [%d]", result);
+                       DEBUG_ERR_MSG("First net_nfc_controller_secure_element_open failed [%d]", result);
+
+                       /* Restore state */
+                       if (result == NET_NFC_OPERATION_FAIL) {
+                               net_nfc_server_controller_reset();
+
+                               if (net_nfc_controller_secure_element_open(NET_NFC_SE_TYPE_ESE, &handle, &result) == true) {
+                                       net_nfc_server_se_set_current_ese_handle(handle);
+
+                                       SECURE_MSG("handle [%p]", handle);
+                               } else {
+                                       DEBUG_ERR_MSG("Second net_nfc_controller_secure_element_open failed [%d]", result);
+                               }
+                       }
                }
        }