From 863fb87511804c1df41c51ebf3eb3da19a7d394d Mon Sep 17 00:00:00 2001 From: Jiwan Kim Date: Tue, 30 May 2017 16:23:25 +0900 Subject: [PATCH] Change APIs - Add 'mesh_disconnect_mesh_network' - Revert API name (scanned->found) --- include/mesh.h | 38 +++++++++++++++---- include/mesh_dbus.h | 2 + src/mesh.c | 23 +++++++++++- src/mesh_dbus.c | 37 ++++++++++++++---- test/main.c | 6 +-- test/mesh_network.c | 91 ++++++++++++++++++++++++++++++++------------- 6 files changed, 153 insertions(+), 44 deletions(-) diff --git a/include/mesh.h b/include/mesh.h index d3a9c05..9645330 100644 --- a/include/mesh.h +++ b/include/mesh.h @@ -608,7 +608,7 @@ int mesh_specific_scan(mesh_h handle, const char* ssid, int channel); int mesh_cancel_scan(mesh_h handle); /** - * @brief Called after mesh_foreach_scanned_mesh_network() + * @brief Called after mesh_foreach_found_mesh_network() * @details This function can receive scan results from mesh network. * * @since_tizen 4.0 @@ -616,15 +616,15 @@ int mesh_cancel_scan(mesh_h handle); * @param[out] network mesh bss information handle * @param[out] user_data user data pointer * - * @pre The callback must be registered with mesh_foreach_scanned_mesh_network() + * @pre The callback must be registered with mesh_foreach_found_mesh_network() * - * @see mesh_foreach_scanned_mesh_network() + * @see mesh_foreach_found_mesh_network() */ typedef void (*mesh_found_mesh_network_cb)(mesh_network_h network, void* user_data); /** - * @brief Gets scanned mesh network bss information - * @details This function returns network information scanned through mesh_found_mesh_network_cb. + * @brief Gets found mesh network bss information + * @details This function returns network information found through mesh_found_mesh_network_cb. * * @since_tizen 4.0 * @@ -642,7 +642,7 @@ typedef void (*mesh_found_mesh_network_cb)(mesh_network_h network, void* user_da * @see mesh_found_mesh_network_cb() * */ -int mesh_foreach_scanned_mesh_network(mesh_h handle, +int mesh_foreach_found_mesh_network(mesh_h handle, mesh_found_mesh_network_cb cb, void *user_data); /** @@ -697,7 +697,7 @@ int mesh_disable_mesh(mesh_h handle); * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * * @see mesh_enable_mesh() - * @see mesh_found_mesh_netwrok_cb() + * @see mesh_found_mesh_network_cb() * */ int mesh_is_joined(mesh_h handle, int* is_joined); @@ -845,6 +845,7 @@ int mesh_disable_softap(mesh_h handle); * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * * @see mesh_connect_mesh_network() + * @see mesh_disconnect_mesh_network() * @see mesh_forget_mesh_network() * */ @@ -866,11 +867,33 @@ int mesh_create_mesh_network(mesh_h handle, mesh_network_h network); * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * * @see mesh_create_mesh_network() + * @see mesh_disconnect_mesh_network() * @see mesh_forget_mesh_network() * */ int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network); +/** + * @brief Disconnects existing mesh network + * @details This function disconnects with existing mesh network. + * + * @since_tizen 4.0 + * + * @param[in] handle The mesh handle + * @param[in] network Mesh bss information handle + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #MESH_ERROR_NONE Successful + * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see mesh_create_mesh_network() + * @see mesh_forget_mesh_network() + * + */ +int mesh_disconnect_mesh_network(mesh_h handle, mesh_network_h network); + /** * @brief Forgets existing mesh network * @details This function removes the information of connected network. @@ -888,6 +911,7 @@ int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network); * * @see mesh_create_mesh_network() * @see mesh_connect_mesh_network() + * @see mesh_disconnect_mesh_network() * */ int mesh_forget_mesh_network(mesh_h handle, mesh_network_h network); diff --git a/include/mesh_dbus.h b/include/mesh_dbus.h index ba982a3..113df62 100644 --- a/include/mesh_dbus.h +++ b/include/mesh_dbus.h @@ -41,6 +41,7 @@ int _mesh_disable(mesh_h handle); int _mesh_scan(mesh_h handle); int _mesh_specific_scan(mesh_h handle, const char* ssid, int channel); int _mesh_cancel_scan(mesh_h handle); +int _mesh_get_scan_result(mesh_h handle); int _mesh_foreach_found_mesh_network(mesh_h handle, mesh_found_mesh_network_cb cb, void *user_data); int _mesh_enable_mesh(mesh_h handle); @@ -55,6 +56,7 @@ int _mesh_enable_softap(mesh_h handle); int _mesh_disable_softap(mesh_h handle); int _mesh_create_network(mesh_h handle, mesh_network_h _network); int _mesh_connect_network(mesh_h handle, mesh_network_h _network); +int _mesh_disconnect_network(mesh_h handle, mesh_network_h _network); int _mesh_forget_network(mesh_h handle, mesh_network_h _network); int _mesh_set_interface(mesh_h handle, const char *mesh, const char *gate, const char *softap); int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data); diff --git a/src/mesh.c b/src/mesh.c index d80100d..02da840 100644 --- a/src/mesh.c +++ b/src/mesh.c @@ -395,7 +395,7 @@ EXPORT_API int mesh_specific_scan(mesh_h handle, const char* ssid, int channel) return MESH_ERROR_NONE; } -EXPORT_API int mesh_foreach_scanned_mesh_network(mesh_h handle, +EXPORT_API int mesh_foreach_found_mesh_network(mesh_h handle, mesh_found_mesh_network_cb cb, void *user_data) { int rv = 0; @@ -404,6 +404,11 @@ EXPORT_API int mesh_foreach_scanned_mesh_network(mesh_h handle, RETV_IF(NULL == cb, MESH_ERROR_INVALID_PARAMETER); RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); + rv = _mesh_get_scan_result(handle); + if (rv == MESH_ITNL_ERR_IO_ERROR) { + return MESH_ERROR_IO_ERROR; + } + rv = _mesh_foreach_found_mesh_network(handle, cb, user_data); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; @@ -590,6 +595,22 @@ EXPORT_API int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network) return MESH_ERROR_NONE; } +EXPORT_API int mesh_disconnect_mesh_network(mesh_h handle, mesh_network_h network) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); + + rv = _mesh_disconnect_network(handle, network); + if (rv == MESH_ITNL_ERR_IO_ERROR) { + return MESH_ERROR_IO_ERROR; + } + + return MESH_ERROR_NONE; +} + EXPORT_API int mesh_forget_mesh_network(mesh_h handle, mesh_network_h network) { int rv = 0; diff --git a/src/mesh_dbus.c b/src/mesh_dbus.c index 1d26322..1e1048f 100644 --- a/src/mesh_dbus.c +++ b/src/mesh_dbus.c @@ -127,7 +127,7 @@ static void _mesh_remove_networks() g_networks.count = 0; } -static int _mesh_get_scan_result(mesh_h handle) +int _mesh_get_scan_result(mesh_h handle) { GVariant *variant = NULL; unsigned int result; @@ -214,9 +214,6 @@ static void _mesh_signal_handler(GDBusConnection *connection, h->event_handler(MESH_MESH_ENABLED_EVENT, &ev); g_free(ev.data.mesh_enable); } else if (0 == g_strcmp0(signal_name, "scan_done")) { - /* Read scan results first */ - _mesh_get_scan_result(h); - /* Then, notify of scan_done event */ h->event_handler(MESH_SCAN_DONE_EVENT, NULL); } else if (0 == g_strcmp0(signal_name, "joined_network")) { h->event_handler(MESH_JOIN_NETWORK_EVENT, NULL); @@ -472,10 +469,6 @@ int _mesh_scan(mesh_h handle) if (variant) { g_variant_get(variant, "(u)", &result); LOGD("scan status 0x%x", result); - - /* Read again */ - if (MESH_ITNL_ERR_NONE != result) - _mesh_get_scan_result(h); } else if (error) { LOGE("Failed DBus call [%s]", error->message); g_error_free(error); @@ -904,6 +897,34 @@ int _mesh_connect_network(mesh_h handle, mesh_network_h _network) return MESH_ITNL_ERR_NONE; } +int _mesh_disconnect_network(mesh_h handle, mesh_network_h _network) +{ + GVariant *variant = NULL; + unsigned int result; + GError *error = NULL; + struct mesh_handle *h = handle; + struct mesh_network_s *n = _network; + + RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); + RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "disconnect_mesh_network", + g_variant_new("(sii)", n->meshid, n->channel, n->security), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(u)", &result); + LOGD("disconnect network status 0x%x", result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return MESH_ITNL_ERR_IO_ERROR; + } + + return MESH_ITNL_ERR_NONE; +} + int _mesh_forget_network(mesh_h handle, mesh_network_h _network) { GVariant *variant = NULL; diff --git a/test/main.c b/test/main.c index f2543ee..6838cee 100644 --- a/test/main.c +++ b/test/main.c @@ -35,7 +35,7 @@ extern struct menu_data menu_mesh_device[]; extern struct menu_data menu_mesh_network[]; /* Scanned Mesh Network */ -extern GList *g_scanned_network_list; +extern GList *g_found_network_list; const char* mesh_error_to_string(mesh_error_e err) { @@ -159,8 +159,8 @@ int main(int arg, char **argv) g_main_loop_run(mainloop); OUT: - if (g_scanned_network_list) - g_list_free(g_scanned_network_list); + if (g_found_network_list) + g_list_free(g_found_network_list); if (mesh) { mesh_disable(mesh); diff --git a/test/mesh_network.c b/test/mesh_network.c index 50e55ce..273b160 100644 --- a/test/mesh_network.c +++ b/test/mesh_network.c @@ -45,9 +45,9 @@ static char mesh_channel[MENU_DATA_SIZE + 1] = "161"; static char network_idx[MENU_DATA_SIZE + 1] = "1"; -/* Scanned Mesh Network */ +/* Found Mesh Network */ static int g_scan_net_idx = 0; -GList *g_scanned_network_list = NULL; +GList *g_found_network_list = NULL; void found_mesh_network_cb(mesh_network_h network, void* user_data) { @@ -59,11 +59,11 @@ void found_mesh_network_cb(mesh_network_h network, void* user_data) ret = mesh_network_clone(&net, network); if (0 != ret) { - msg("Failed to clone scanned network: [%s(0x%X)]", mesh_error_to_string(ret), ret); + msg("Failed to clone found network: [%s(0x%X)]", mesh_error_to_string(ret), ret); return; } - g_scanned_network_list = g_list_append(g_scanned_network_list, net); + g_found_network_list = g_list_append(g_found_network_list, net); mesh_network_get_meshid(net, &meshid); mesh_network_get_bssid(net, &bssid); @@ -83,7 +83,7 @@ static void found_mpath_cb(mesh_mpath_info_h mpath, void* user_data) msg("Station Information Received: %p", mpath); } -static int run_show_scanned_network(MManager *mm, struct menu_data *menu) +static int run_show_found_network(MManager *mm, struct menu_data *menu) { int i = 1; /* Displays from 1 */ char *_meshid = NULL; @@ -91,13 +91,13 @@ static int run_show_scanned_network(MManager *mm, struct menu_data *menu) GList *iter = NULL; - if (NULL == g_scanned_network_list) { + if (NULL == g_found_network_list) { msgp("There is not any scan result.. do scan first"); return RET_FAILURE; } msg("Scan Results : "); - iter = g_scanned_network_list; + iter = g_found_network_list; while (iter != NULL) { mesh_network_h _net = iter->data; mesh_network_get_meshid(_net, &_meshid); @@ -123,21 +123,21 @@ static int run_mesh_scan(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_get_scanned_mesh_network(MManager *mm, struct menu_data *menu) +static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu) { int ret; - msg("Get Scanned Mesh Network"); + msg("Get Found Mesh Network"); - /* Clear previous scanned network list */ + /* Clear previous found network list */ g_scan_net_idx = 1; - if (g_scanned_network_list) { - g_list_free_full(g_scanned_network_list, mesh_network_destroy); + if (g_found_network_list) { + g_list_free_full(g_found_network_list, mesh_network_destroy); } - g_scanned_network_list = NULL; + g_found_network_list = NULL; - ret = mesh_foreach_scanned_mesh_network(mesh, found_mesh_network_cb, NULL); + ret = mesh_foreach_found_mesh_network(mesh, found_mesh_network_cb, NULL); if (ret != 0) { - msg("Failed to mesh_foreach_scanned_mesh_network: [%s(0x%X)]", + msg("Failed to mesh_foreach_found_mesh_network: [%s(0x%X)]", mesh_error_to_string(ret), ret); return RET_FAILURE; } @@ -369,8 +369,8 @@ static int run_connect_network(MManager *mm, struct menu_data *menu) } } - if (g_scanned_network_list) { - net = g_list_nth_data(g_scanned_network_list, idx - 1); + if (g_found_network_list) { + net = g_list_nth_data(g_found_network_list, idx - 1); if (NULL == net) { msg("Failed to g_hash_table_find"); return RET_FAILURE; @@ -387,6 +387,39 @@ static int run_connect_network(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +static int run_disconnect_network(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx = 1; + mesh_network_h net = NULL; + msg("Disconnect with Mesh Network"); + + if (strlen(network_idx)) { + idx = (unsigned short)strtol(network_idx, NULL, 10); + if (0 >= idx) { + msg("Invalid index. set to 1"); + idx = 1; + } + } + + if (g_found_network_list) { + net = g_list_nth_data(g_found_network_list, idx - 1); + if (NULL == net) { + msg("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = mesh_disconnect_mesh_network(mesh, net); + if (ret != 0) { + msg("Failed to mesh_disconnect_mesh_network: [%s(0x%X)]", + mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + + return RET_SUCCESS; +} + static int run_forget_network(MManager *mm, struct menu_data *menu) { int ret; @@ -402,8 +435,8 @@ static int run_forget_network(MManager *mm, struct menu_data *menu) } } - if (g_scanned_network_list) { - net = g_list_nth_data(g_scanned_network_list, idx - 1); + if (g_found_network_list) { + net = g_list_nth_data(g_found_network_list, idx - 1); if (NULL == net) { msg("Failed to g_hash_table_find"); return RET_FAILURE; @@ -483,14 +516,21 @@ static struct menu_data menu_create_network[] = { }; static struct menu_data menu_connect_network[] = { - { "0", "Show scanned networks", NULL, run_show_scanned_network, NULL }, + { "0", "Show found networks", NULL, run_show_found_network, NULL }, { "1", "Index", NULL, NULL, network_idx }, { "2", "Run", NULL, run_connect_network, NULL }, { NULL, NULL, }, }; +static struct menu_data menu_disconnect_network[] = { + { "0", "Show found networks", NULL, run_show_found_network, NULL }, + { "1", "Index", NULL, NULL, network_idx }, + { "2", "Run", NULL, run_disconnect_network, NULL }, + { NULL, NULL, }, +}; + static struct menu_data menu_forget_network[] = { - { "0", "Show scanned networks", NULL, run_show_scanned_network, NULL }, + { "0", "Show found networks", NULL, run_show_found_network, NULL }, { "1", "Index", NULL, NULL, network_idx }, { "2", "Run", NULL, run_forget_network, NULL }, { NULL, NULL, }, @@ -499,7 +539,7 @@ static struct menu_data menu_forget_network[] = { struct menu_data menu_mesh_network[] = { { "1", "Scan", NULL, run_mesh_scan, NULL }, - { "2", "Get scanned mesh network", NULL, run_get_scanned_mesh_network, NULL }, + { "2", "Get found mesh network", NULL, run_get_found_mesh_network, NULL }, { "3", "Specific scan", menu_specific_scan, NULL, NULL }, { "4", "Cancel scan", NULL, run_mesh_cancel_scan, NULL }, { "5", "Enable mesh", NULL, run_mesh_enable, NULL }, @@ -512,8 +552,9 @@ struct menu_data menu_mesh_network[] = { { "12", "Disable softap", NULL, run_disable_softap, NULL }, { "13", "Create network", menu_create_network, NULL, NULL }, { "14", "Connect network", menu_connect_network, NULL, NULL }, - { "15", "Forget network", menu_forget_network, NULL, NULL }, - { "16", "Get mesh station information", NULL, run_get_station_information, NULL }, - { "17", "Get mesh path information", NULL, run_get_mpath_information, NULL }, + { "15", "Disconnect network", menu_disconnect_network, NULL, NULL }, + { "16", "Forget network", menu_forget_network, NULL, NULL }, + { "17", "Get mesh station information", NULL, run_get_station_information, NULL }, + { "18", "Get mesh path information", NULL, run_get_mpath_information, NULL }, { NULL, NULL, }, }; -- 2.34.1