Update network API's 08/272008/3
authorRavinder <ravinder.01@samsung.com>
Fri, 4 Mar 2022 11:39:15 +0000 (17:09 +0530)
committerRavinder <ravinder.01@samsung.com>
Mon, 7 Mar 2022 06:23:12 +0000 (11:53 +0530)
Change-Id: I57e218960a6f0d5a0350de1cfc242ba18b25cfdb

src/thread-network.c
tests/thread-network.c

index 2f3caa9..b2be07d 100644 (file)
@@ -333,15 +333,48 @@ done:
        return ret;
 }
 
+static int __thread_detach_active_network()
+{
+       FUNC_ENTRY;
+       int ret = THREAD_ERROR_NONE;
+
+       THREAD_DBG("Detach current active network dataset");
+       ret = _thread_dbus_sync_method_call(THREAD_DBUS_DETACH_METHOD,
+                                               g_variant_new("()"));
+       if (ret != THREAD_ERROR_NONE)
+               THREAD_ERR("Thread Detach failed");
+       else
+               THREAD_DBG("Thread Detach successful");
+
+       FUNC_EXIT;
+       return ret;
+}
+
 int thread_network_detach(thread_instance_h instance)
 {
        FUNC_ENTRY;
        THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
        THREAD_CHECK_INIT_STATUS();
        THREAD_VALIDATE_INPUT_PARAMETER(instance);
-       int ret = THREAD_ERROR_NOT_SUPPORTED;
+       int ret = THREAD_ERROR_NONE;
+
+       thread_instance_s *current_instance = instance;
+       thread_network_s *network = current_instance->network;
+
+       if (!network)
+               return THREAD_ERROR_INVALID_PARAMETER;
 
+       if (network->is_network_active == TRUE)
+               ret = __thread_detach_active_network();
 
+       if (ret != THREAD_ERROR_NONE) {
+               THREAD_ERR("Thread Detach failed");
+               goto done;
+       }
+       network->is_network_active = FALSE;
+       THREAD_DBG("Thread Detach successful");
+
+done:
        FUNC_EXIT;
        return ret;
 }
index d2002e6..1f4cc81 100644 (file)
@@ -174,6 +174,23 @@ OUT:
        return RET_SUCCESS;
 }
 
+static int run_thread_network_detach(MManager *mm, struct menu_data *menu)
+{
+       FUNC_ENTRY;
+       thread_instance_h g_instance = mm->t_instance;
+       if (g_instance == NULL)
+               goto OUT;
+
+       int ret = thread_network_detach(g_instance);
+       if (ret == THREAD_ERROR_NONE)
+               msg("thread_network_detach success");
+       else
+               msg("thread_network_detach failed");
+OUT:
+       FUNC_EXIT;
+       return RET_SUCCESS;
+}
+
 static void __get_ipaddr_callback(int index, char* ipaddr,
                        thread_ipaddr_type_e ipaddr_type, void *user_data) {
        FUNC_ENTRY;
@@ -309,11 +326,13 @@ struct menu_data menu_thread_network[] = {
                NULL, run_thread_network_get_active_dataset_tlvs, NULL },
        { "5", "thread_network_attach",
                NULL, run_thread_network_attach, NULL},
-       { "6", "thread_get_ipaddr",
+       { "6", "thread_network_detach",
+               NULL, run_thread_network_detach, NULL},
+       { "7", "thread_get_ipaddr",
                menu_thread_get_ipaddr, NULL, NULL},
-       { "7", "thread_add_ipaddr",
+       { "8", "thread_add_ipaddr",
                menu_thread_add_ipaddr, NULL, NULL},
-       { "8", "thread_remove_ipaddr",
+       { "9", "thread_remove_ipaddr",
                menu_thread_remove_ipaddr, NULL, NULL},
        { NULL, NULL, },
 };