From c5e2ec50b4a578feef011b557a91f9a5320846f1 Mon Sep 17 00:00:00 2001 From: Ravinder Date: Fri, 4 Mar 2022 17:09:15 +0530 Subject: [PATCH] Update network API's Change-Id: I57e218960a6f0d5a0350de1cfc242ba18b25cfdb --- src/thread-network.c | 35 ++++++++++++++++++++++++++++++++++- tests/thread-network.c | 25 ++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/thread-network.c b/src/thread-network.c index 2f3caa9..b2be07d 100644 --- a/src/thread-network.c +++ b/src/thread-network.c @@ -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; } diff --git a/tests/thread-network.c b/tests/thread-network.c index d2002e6..1f4cc81 100644 --- a/tests/thread-network.c +++ b/tests/thread-network.c @@ -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, }, }; -- 2.7.4