From 79a529a46b0b9606763755b75d1af068c959bf25 Mon Sep 17 00:00:00 2001 From: Jiwan Kim Date: Mon, 29 May 2017 18:55:18 +0900 Subject: [PATCH] Fix for API concept changes - Rename some APIs and dbus interface also - Remove some unnecessary APIs --- include/mesh.h | 103 ++++++-------------- include/mesh_dbus.h | 10 +- src/mesh.c | 31 ++---- src/mesh_dbus.c | 82 ++-------------- test/main.c | 4 - test/mesh_network.c | 228 +++++++++++--------------------------------- 6 files changed, 107 insertions(+), 351 deletions(-) diff --git a/include/mesh.h b/include/mesh.h index f1184fd..d3a9c05 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_found_mesh_netwrok() + * @brief Called after mesh_foreach_scanned_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_found_mesh_netwrok() + * @pre The callback must be registered with mesh_foreach_scanned_mesh_network() * - * @see mesh_foreach_found_mesh_netwrok() + * @see mesh_foreach_scanned_mesh_network() */ -typedef void (*mesh_found_mesh_netwrok_cb)(mesh_network_h network, void* user_data); +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_netwrok_cb. + * @details This function returns network information scanned through mesh_found_mesh_network_cb. * * @since_tizen 4.0 * @@ -639,11 +639,11 @@ typedef void (*mesh_found_mesh_netwrok_cb)(mesh_network_h network, void* user_da * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * * @see mesh_scan() - * @see mesh_found_mesh_netwrok_cb() + * @see mesh_found_mesh_network_cb() * */ int mesh_foreach_scanned_mesh_network(mesh_h handle, - mesh_found_mesh_netwrok_cb cb, void *user_data); + mesh_found_mesh_network_cb cb, void *user_data); /** * @brief Enables the mesh network. @@ -830,52 +830,13 @@ int mesh_enable_softap(mesh_h handle); int mesh_disable_softap(mesh_h handle); /** - * @brief Adds new mesh network configuration - * @details This function adds new network configuration to connect. - * - * @since_tizen 4.0 - * - * @param[in] handle The mesh handle - * @param[in] network callback function pointer to know saved network information - * - * - * @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_foreach_saved_mesh_network() - * @see mesh_saved_mesh_netwrok_cb() - * @see mesh_select_mesh_network() - * @see mesh_remove_mesh_network() - * - */ -int mesh_add_mesh_network(mesh_h handle, mesh_network_h network); - -/** - * @brief Called after mesh_foreach_saved_mesh_network() - * @details This function can receive saved mesh network configuration. - * - * @since_tizen 4.0 - * - * @param[out] network saved network configuration handle - * @param[out] user_data user data pointer - * - * @pre The callback must be registered with mesh_foreach_saved_mesh_netwrok() - * - * @see mesh_foreach_saved_mesh_netwrok() - */ -typedef void (*mesh_saved_mesh_netwrok_cb)(mesh_network_h network, void* user_data); - -/** - * @brief Gets saved mesh network information - * @details This function returns saved network information through mesh_saved_mesh_netwrok_cb. + * @brief Creates new mesh network configuration + * @details This function creates new mesh network. * * @since_tizen 4.0 * * @param[in] handle The mesh handle - * @param[in] cb callback function pointer to know saved network information - * @param[in] user_data user data pointer + * @param[in] network Mesh bss information handle * * * @return 0 on success, otherwise a negative error value. @@ -883,21 +844,20 @@ typedef void (*mesh_saved_mesh_netwrok_cb)(mesh_network_h network, void* user_da * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * - * @see mesh_saved_mesh_netwrok_cb() + * @see mesh_connect_mesh_network() + * @see mesh_forget_mesh_network() * */ -int mesh_foreach_saved_mesh_network(mesh_h handle, - mesh_saved_mesh_netwrok_cb cb, void *user_data); +int mesh_create_mesh_network(mesh_h handle, mesh_network_h network); /** - * @brief Selects existing mesh network configuration - * @details This function selects existing network configuration to connect. + * @brief Connects existing mesh network + * @details This function makes a connection to existing mesh network. * * @since_tizen 4.0 * * @param[in] handle The mesh handle - * @param[in] network callback function pointer to know saved network information - * @param[in] user_data user data pointer + * @param[in] network Mesh bss information handle * * * @return 0 on success, otherwise a negative error value. @@ -905,23 +865,20 @@ int mesh_foreach_saved_mesh_network(mesh_h handle, * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * - * @see mesh_foreach_saved_mesh_network() - * @see mesh_saved_mesh_netwrok_cb() - * @see mesh_select_mesh_network() - * @see mesh_add_mesh_network() + * @see mesh_create_mesh_network() + * @see mesh_forget_mesh_network() * */ -int mesh_select_mesh_network(mesh_h handle, mesh_network_h network); +int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network); /** - * @brief Removes existing mesh network configuration - * @details This function removes new network configuration. + * @brief Forgets existing mesh network + * @details This function removes the information of connected network. * * @since_tizen 4.0 * * @param[in] handle The mesh handle - * @param[in] network callback function pointer to know saved network information - * @param[in] user_data user data pointer + * @param[in] network Mesh bss information handle * * * @return 0 on success, otherwise a negative error value. @@ -929,13 +886,11 @@ int mesh_select_mesh_network(mesh_h handle, mesh_network_h network); * @retval #MESH_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MESH_ERROR_IO_ERROR Unexpected d-bus error * - * @see mesh_foreach_saved_mesh_network() - * @see mesh_saved_mesh_netwrok_cb() - * @see mesh_select_mesh_network() - * @see mesh_add_mesh_network() + * @see mesh_create_mesh_network() + * @see mesh_connect_mesh_network() * */ -int mesh_remove_mesh_network(mesh_h handle, mesh_network_h network); +int mesh_forget_mesh_network(mesh_h handle, mesh_network_h network); /** * @brief Called after mesh_get_stations_info() @@ -946,9 +901,9 @@ int mesh_remove_mesh_network(mesh_h handle, mesh_network_h network); * @param[out] station mesh station information handle * @param[out] user_data user data pointer * - * @pre The callback must be registered with mesh_foreach_found_mesh_netwrok() + * @pre The callback must be registered with mesh_foreach_found_mesh_network() * - * @see mesh_foreach_found_mesh_netwrok() + * @see mesh_foreach_found_mesh_network() */ typedef void (*mesh_found_station_cb)(mesh_station_info_h station, void* user_data); @@ -982,9 +937,9 @@ int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_d * @param[out] path mesh path information handle * @param[out] user_data user data pointer * - * @pre The callback must be registered with mesh_foreach_found_mesh_netwrok() + * @pre The callback must be registered with mesh_foreach_found_mesh_network() * - * @see mesh_foreach_found_mesh_netwrok() + * @see mesh_foreach_found_mesh_network() */ typedef void (*mesh_found_mpath_cb)(mesh_mpath_info_h path, void* user_data); diff --git a/include/mesh_dbus.h b/include/mesh_dbus.h index b6078dd..ba982a3 100644 --- a/include/mesh_dbus.h +++ b/include/mesh_dbus.h @@ -42,7 +42,7 @@ 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_foreach_found_mesh_network(mesh_h handle, - mesh_found_mesh_netwrok_cb cb, void *user_data); + mesh_found_mesh_network_cb cb, void *user_data); int _mesh_enable_mesh(mesh_h handle); int _mesh_disable_mesh(mesh_h handle); int _mesh_is_joined(mesh_h handle, int* is_joined); @@ -53,11 +53,9 @@ int _mesh_set_softap(mesh_h handle, const char* ssid, const char* key, const cha int channel, int visibility, int max_stations, int security); int _mesh_enable_softap(mesh_h handle); int _mesh_disable_softap(mesh_h handle); -int _mesh_add_network(mesh_h handle, mesh_network_h _network); -int _mesh_foreach_saved_mesh_netwrok(mesh_h handle, - mesh_saved_mesh_netwrok_cb cb, void *user_data); -int _mesh_select_network(mesh_h handle, mesh_network_h _network); -int _mesh_remove_network(mesh_h handle, mesh_network_h _network); +int _mesh_create_network(mesh_h handle, mesh_network_h _network); +int _mesh_connect_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); int _mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data); diff --git a/src/mesh.c b/src/mesh.c index 939e570..d80100d 100644 --- a/src/mesh.c +++ b/src/mesh.c @@ -396,7 +396,7 @@ EXPORT_API int mesh_specific_scan(mesh_h handle, const char* ssid, int channel) } EXPORT_API int mesh_foreach_scanned_mesh_network(mesh_h handle, - mesh_found_mesh_netwrok_cb cb, void *user_data) + mesh_found_mesh_network_cb cb, void *user_data) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); @@ -558,7 +558,7 @@ EXPORT_API int mesh_disable_softap(mesh_h handle) return MESH_ERROR_NONE; } -EXPORT_API int mesh_add_mesh_network(mesh_h handle, mesh_network_h network) +EXPORT_API int mesh_create_mesh_network(mesh_h handle, mesh_network_h network) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); @@ -566,7 +566,7 @@ EXPORT_API int mesh_add_mesh_network(mesh_h handle, mesh_network_h network) RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_add_network(handle, network); + rv = _mesh_create_network(handle, network); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } @@ -574,24 +574,7 @@ EXPORT_API int mesh_add_mesh_network(mesh_h handle, mesh_network_h network) return MESH_ERROR_NONE; } -EXPORT_API int mesh_foreach_saved_mesh_network(mesh_h handle, - mesh_found_mesh_netwrok_cb cb, void *user_data) -{ - int rv = 0; - CHECK_FEATURE_SUPPORTED(MESH_FEATURE); - - RETV_IF(NULL == cb, MESH_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - - rv = _mesh_foreach_saved_mesh_netwrok(handle, cb, user_data); - if (rv == MESH_ITNL_ERR_IO_ERROR) { - return MESH_ERROR_IO_ERROR; - } - - return MESH_ERROR_NONE; -} - -EXPORT_API int mesh_select_mesh_network(mesh_h handle, mesh_network_h network) +EXPORT_API int mesh_connect_mesh_network(mesh_h handle, mesh_network_h network) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); @@ -599,7 +582,7 @@ EXPORT_API int mesh_select_mesh_network(mesh_h handle, mesh_network_h network) RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_select_network(handle, network); + rv = _mesh_connect_network(handle, network); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } @@ -607,7 +590,7 @@ EXPORT_API int mesh_select_mesh_network(mesh_h handle, mesh_network_h network) return MESH_ERROR_NONE; } -EXPORT_API int mesh_remove_mesh_network(mesh_h handle, mesh_network_h network) +EXPORT_API int mesh_forget_mesh_network(mesh_h handle, mesh_network_h network) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); @@ -615,7 +598,7 @@ EXPORT_API int mesh_remove_mesh_network(mesh_h handle, mesh_network_h network) RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); RETV_IF(NULL == network, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_remove_network(handle, network); + rv = _mesh_forget_network(handle, network); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } diff --git a/src/mesh_dbus.c b/src/mesh_dbus.c index bfadc60..1d26322 100644 --- a/src/mesh_dbus.c +++ b/src/mesh_dbus.c @@ -540,7 +540,7 @@ int _mesh_cancel_scan(mesh_h handle) } int _mesh_foreach_found_mesh_network(mesh_h handle, - mesh_found_mesh_netwrok_cb cb, void *user_data) + mesh_found_mesh_network_cb cb, void *user_data) { int i; GList *iter = NULL; @@ -848,7 +848,7 @@ int _mesh_disable_softap(mesh_h handle) return MESH_ITNL_ERR_NONE; } -int _mesh_add_network(mesh_h handle, mesh_network_h _network) +int _mesh_create_network(mesh_h handle, mesh_network_h _network) { GVariant *variant = NULL; unsigned int result; @@ -859,14 +859,14 @@ int _mesh_add_network(mesh_h handle, mesh_network_h _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, "add_mesh_network", + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "create_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("add_network status 0x%x", result); + LOGD("create_network status 0x%x", result); } else if (error) { LOGE("Failed DBus call [%s]", error->message); g_error_free(error); @@ -876,69 +876,7 @@ int _mesh_add_network(mesh_h handle, mesh_network_h _network) return MESH_ITNL_ERR_NONE; } -int _mesh_foreach_saved_mesh_netwrok(mesh_h handle, - mesh_saved_mesh_netwrok_cb cb, void *user_data) -{ - GVariant *variant = NULL; - unsigned int result; - GError *error = NULL; - struct mesh_handle *h = handle; - - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - - gchar *key; - GVariant *val; - gsize len = 0; - - struct mesh_network_s network_info; - - 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, "get_saved_mesh_network", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, &error); - if (variant) { - /* handle station list here */ - g_variant_get(variant, "(aa{sv}u)", &iter, &result); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - memset(&network_info, 0, sizeof(struct mesh_network_s)); - while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - if (strcasecmp(key, "mesh_id") == 0) { - const char *buf = g_variant_get_string(val, &len); - memcpy(network_info.meshid, buf, len); - //network_info->meshid = g_variant_dup_string(val, &len); - LOGE("meshid=%s", network_info.meshid); - } - else if (strcasecmp(key, "channel") == 0) { - network_info.channel = g_variant_get_uint32(val); - LOGE("channel = %d", network_info.channel); - } - else if (strcasecmp(key, "security") == 0) { - network_info.security = g_variant_get_uint32(val); - LOGE("security = %d", network_info.security); - - if (cb) cb(&network_info, user_data); - } - } - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - LOGD("get_saved_mesh_networks 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_select_network(mesh_h handle, mesh_network_h _network) +int _mesh_connect_network(mesh_h handle, mesh_network_h _network) { GVariant *variant = NULL; unsigned int result; @@ -949,14 +887,14 @@ int _mesh_select_network(mesh_h handle, mesh_network_h _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, "select_saved_mesh_network", + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "connect_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("select_network status 0x%x", result); + LOGD("connect network status 0x%x", result); } else if (error) { LOGE("Failed DBus call [%s]", error->message); g_error_free(error); @@ -966,7 +904,7 @@ int _mesh_select_network(mesh_h handle, mesh_network_h _network) return MESH_ITNL_ERR_NONE; } -int _mesh_remove_network(mesh_h handle, mesh_network_h _network) +int _mesh_forget_network(mesh_h handle, mesh_network_h _network) { GVariant *variant = NULL; unsigned int result; @@ -979,14 +917,14 @@ int _mesh_remove_network(mesh_h handle, mesh_network_h _network) LOGD("mesid=%s channel=%d security=%d", n->meshid, n->channel, n->security); - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "forget_saved_mesh_network", + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "forget_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("remove_network status 0x%x", result); + LOGD("forget_network status 0x%x", result); } else if (error) { LOGE("Failed DBus call [%s]", error->message); g_error_free(error); diff --git a/test/main.c b/test/main.c index 1a841df..f2543ee 100644 --- a/test/main.c +++ b/test/main.c @@ -36,8 +36,6 @@ extern struct menu_data menu_mesh_network[]; /* Scanned Mesh Network */ extern GList *g_scanned_network_list; -/* Mesh Network Configuration */ -extern GList *g_saved_network_list; const char* mesh_error_to_string(mesh_error_e err) { @@ -163,8 +161,6 @@ int main(int arg, char **argv) OUT: if (g_scanned_network_list) g_list_free(g_scanned_network_list); - if (g_saved_network_list) - g_list_free(g_saved_network_list); if (mesh) { mesh_disable(mesh); diff --git a/test/mesh_network.c b/test/mesh_network.c index 3571271..50e55ce 100644 --- a/test/mesh_network.c +++ b/test/mesh_network.c @@ -49,10 +49,6 @@ static char network_idx[MENU_DATA_SIZE + 1] = "1"; static int g_scan_net_idx = 0; GList *g_scanned_network_list = NULL; -/* Mesh Network Configuration */ -static int g_saved_net_idx = 0; -GList *g_saved_network_list = NULL; - void found_mesh_network_cb(mesh_network_h network, void* user_data) { int ret; @@ -77,27 +73,6 @@ void found_mesh_network_cb(mesh_network_h network, void* user_data) g_scan_net_idx++; } -void saved_mesh_network_cb(mesh_network_h network, void* user_data) -{ - mesh_network_h net = NULL; - int ret = mesh_network_clone(&net, network); - - char *meshid = NULL; - int channel; - - if (0 != ret) { - msg("Failed to clone configured network: [%s(0x%X)]", mesh_error_to_string(ret), ret); - return; - } - - g_saved_network_list = g_list_append(g_saved_network_list, net); - mesh_network_get_meshid(net, &meshid); - mesh_network_get_channel(net, &channel); - msg(" [%02d] Mesh ID[%-10s] Channel[%d]", g_saved_net_idx, meshid, channel); - - g_saved_net_idx++; -} - static void found_station_cb(mesh_station_info_h station, void* user_data) { msg("Station Information Received: %p", station); @@ -108,36 +83,6 @@ static void found_mpath_cb(mesh_mpath_info_h mpath, void* user_data) msg("Station Information Received: %p", mpath); } -static int run_show_saved_network(MManager *mm, struct menu_data *menu) -{ - int i = 1; /* Displays from 1 */ - char *_meshid = NULL; - int _channel = 1; - - GList *iter = NULL; - -// if (NULL == g_saved_network_list) { -// return RET_FAILURE; -// } - if (NULL == g_scanned_network_list) { - msgp("There is not any scan result.. do scan first"); - return RET_FAILURE; - } - - msg("Saved Mesh Network Configurations : "); - //iter = g_saved_network_list; - iter = g_scanned_network_list; - while (iter != NULL) { - mesh_network_h _net = iter->data; - mesh_network_get_meshid(_net, &_meshid); - mesh_network_get_channel(_net, &_channel); - msgb(" [%02d] Mesh ID[%-10s] Channel[%d]", i++, _meshid, _channel); - iter = g_list_next(iter); - } - - return RET_SUCCESS; -} - static int run_show_scanned_network(MManager *mm, struct menu_data *menu) { int i = 1; /* Displays from 1 */ @@ -386,77 +331,22 @@ static int run_disable_softap(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_get_saved_network(MManager *mm, struct menu_data *menu) -{ - int ret; - msg("Get Saved Mesh Network Configuration"); - - /* Clear previous saved network configurations */ - g_saved_net_idx = 1; - if (g_saved_network_list) { - g_list_free_full(g_saved_network_list, mesh_network_destroy); - } - g_saved_network_list = NULL; - - ret = mesh_foreach_saved_mesh_network(mesh, saved_mesh_network_cb, NULL); - if (ret != 0) { - msg("Failed to mesh_foreach_saved_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - - return RET_SUCCESS; -} - -static int run_add_network(MManager *mm, struct menu_data *menu) -{ - int ret; - int idx = 1; - mesh_network_h net = NULL; - msg("Add a Network Configuration among scan results"); - - 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_scanned_network_list) { - net = g_list_nth_data(g_scanned_network_list, idx - 1); - if (NULL == net) { - msg("Failed to find candidate network"); - return RET_FAILURE; - } - } - - ret = mesh_add_mesh_network(mesh, net); - if (ret != 0) { - msg("Failed to mesh_add_mesh_network: [%s(0x%X)]", - mesh_error_to_string(ret), ret); - return RET_FAILURE; - } - - return RET_SUCCESS; -} - -static int run_add_new_network(MManager *mm, struct menu_data *menu) +static int run_create_network(MManager *mm, struct menu_data *menu) { int ret; int _mesh_channel = 1; mesh_network_h net = NULL; - msg("Add New Network Configuration"); + msg("Create a new Mesh Network"); if (strlen(mesh_channel)) _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10); mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0, 0); - ret = mesh_add_mesh_network(mesh, net); + ret = mesh_create_mesh_network(mesh, net); mesh_network_destroy(net); if (ret != 0) { - msg("Failed to mesh_add_mesh_network: [%s(0x%X)]", + msg("Failed to mesh_create_mesh_network: [%s(0x%X)]", mesh_error_to_string(ret), ret); return RET_FAILURE; } @@ -464,12 +354,12 @@ static int run_add_new_network(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_select_network(MManager *mm, struct menu_data *menu) +static int run_connect_network(MManager *mm, struct menu_data *menu) { int ret; int idx = 1; mesh_network_h net = NULL; - msg("Select Saved Network Configuration"); + msg("Connect to Mesh Network"); if (strlen(network_idx)) { idx = (unsigned short)strtol(network_idx, NULL, 10); @@ -479,17 +369,17 @@ static int run_select_network(MManager *mm, struct menu_data *menu) } } - if (g_saved_network_list) { - net = g_list_nth_data(g_saved_network_list, idx - 1); + if (g_scanned_network_list) { + net = g_list_nth_data(g_scanned_network_list, idx - 1); if (NULL == net) { msg("Failed to g_hash_table_find"); return RET_FAILURE; } } - ret = mesh_select_mesh_network(mesh, net); + ret = mesh_connect_mesh_network(mesh, net); if (ret != 0) { - msg("Failed to mesh_select_mesh_network: [%s(0x%X)]", + msg("Failed to mesh_connect_mesh_network: [%s(0x%X)]", mesh_error_to_string(ret), ret); return RET_FAILURE; } @@ -497,27 +387,32 @@ static int run_select_network(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_remove_network(MManager *mm, struct menu_data *menu) +static int run_forget_network(MManager *mm, struct menu_data *menu) { int ret; int idx = 1; mesh_network_h net = NULL; - msg("Remove Saved Network Configuration"); + msg("Forget Mesh Network"); - if (strlen(network_idx)) + 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_saved_network_list) { - net = g_list_nth_data(g_saved_network_list, idx); + if (g_scanned_network_list) { + net = g_list_nth_data(g_scanned_network_list, idx - 1); if (NULL == net) { msg("Failed to g_hash_table_find"); return RET_FAILURE; } } - ret = mesh_remove_mesh_network(mesh, net); + ret = mesh_forget_mesh_network(mesh, net); if (ret != 0) { - msg("Failed to mesh_remove_mesh_network: [%s(0x%X)]", + msg("Failed to mesh_forget_mesh_network: [%s(0x%X)]", mesh_error_to_string(ret), ret); return RET_FAILURE; } @@ -555,79 +450,70 @@ static int run_get_mpath_information(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } static struct menu_data menu_specific_scan[] = { - { "1", "meshid", NULL, NULL, meshid }, - { "2", "channel", NULL, NULL, mesh_channel }, - { "3", "run", NULL, run_mesh_specific_scan, NULL }, + { "1", "Mesh ID", NULL, NULL, meshid }, + { "2", "Channel", NULL, NULL, mesh_channel }, + { "3", "Run", NULL, run_mesh_specific_scan, NULL }, { NULL, NULL, }, }; static struct menu_data menu_gate_option[] = { - { "1", "stp", NULL, NULL, stp }, - { "2", "gate_announce", NULL, NULL, gate_announce }, - { "3", "run", NULL, run_set_gate, NULL }, + { "1", "STP", NULL, NULL, stp }, + { "2", "Gate Announcement", NULL, NULL, gate_announce }, + { "3", "Run", NULL, run_set_gate, NULL }, { NULL, NULL, }, }; static struct menu_data menu_softap_option[] = { - { "1", "ssid", NULL, NULL, ssid }, + { "1", "SSID", NULL, NULL, ssid }, { "2", "passphrase", NULL, NULL, passphrase }, { "3", "802.11 mode", NULL, NULL, mode }, { "4", "channel", NULL, NULL, softap_channel }, - { "5", "ssid broadcast=1, hidden=0", NULL, NULL, visibility }, + { "5", "SSID broadcast=1, hidden=0", NULL, NULL, visibility }, { "6", "max. client num", NULL, NULL, max_stations }, { "6", "security (wpa1=1, wpa2=2)", NULL, NULL, security }, { "7", "run", NULL, run_set_softap, NULL }, { NULL, NULL, }, }; -static struct menu_data menu_add_network[] = { - { "0", "show scanned networks", NULL, run_show_scanned_network, NULL }, - { "1", "index", NULL, NULL, network_idx }, - { "2", "run", NULL, run_add_network, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_add_new_network[] = { - { "1", "meshid", NULL, NULL, meshid }, - { "2", "channel", NULL, NULL, mesh_channel }, - { "3", "run", NULL, run_add_new_network, NULL }, +static struct menu_data menu_create_network[] = { + { "1", "Mesh ID", NULL, NULL, meshid }, + { "2", "Channel", NULL, NULL, mesh_channel }, + { "3", "Run", NULL, run_create_network, NULL }, { NULL, NULL, }, }; -static struct menu_data menu_select_network[] = { - { "0", "show scanned(!saved) networks", NULL, run_show_saved_network, NULL }, - { "1", "index", NULL, NULL, network_idx }, - { "2", "run", NULL, run_select_network, NULL }, +static struct menu_data menu_connect_network[] = { + { "0", "Show scanned networks", NULL, run_show_scanned_network, NULL }, + { "1", "Index", NULL, NULL, network_idx }, + { "2", "Run", NULL, run_connect_network, NULL }, { NULL, NULL, }, }; -static struct menu_data menu_remove_network[] = { - { "0", "show saved networks", NULL, run_show_saved_network, NULL }, - { "1", "index", NULL, NULL, network_idx }, - { "2", "run", NULL, run_remove_network, NULL }, +static struct menu_data menu_forget_network[] = { + { "0", "Show scanned networks", NULL, run_show_scanned_network, NULL }, + { "1", "Index", NULL, NULL, network_idx }, + { "2", "Run", NULL, run_forget_network, NULL }, { NULL, NULL, }, }; 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 scanned mesh network", NULL, run_get_scanned_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 }, - { "6", "disable mesh", NULL, run_mesh_disable, NULL }, - { "7", "get joined mesh network", NULL, run_get_joined_mesh_network, NULL }, - { "8", "set gate", menu_gate_option, NULL, NULL }, - { "9", "unset gate", NULL, run_unset_gate, NULL }, - { "10", "set softap", menu_softap_option, NULL, NULL }, - { "11", "enable softap", NULL, run_enable_softap, NULL }, - { "12", "disable softap", NULL, run_disable_softap, NULL }, - { "13", "Get Saved Mesh Network", NULL, run_get_saved_network, NULL }, - { "14", "add network", menu_add_network, NULL, NULL }, - { "15", "add new network", menu_add_new_network, NULL, NULL }, - { "16", "select network", menu_select_network, NULL, NULL }, - { "17", "remove network", menu_remove_network, NULL, NULL }, - { "18", "get mesh station information", NULL, run_get_station_information, NULL }, - { "19", "get mesh path information", NULL, run_get_mpath_information, NULL }, + { "4", "Cancel scan", NULL, run_mesh_cancel_scan, NULL }, + { "5", "Enable mesh", NULL, run_mesh_enable, NULL }, + { "6", "Disable mesh", NULL, run_mesh_disable, NULL }, + { "7", "Get joined mesh network", NULL, run_get_joined_mesh_network, NULL }, + { "8", "Set gate", menu_gate_option, NULL, NULL }, + { "9", "Unset gate", NULL, run_unset_gate, NULL }, + { "10", "Set softap", menu_softap_option, NULL, NULL }, + { "11", "Enable softap", NULL, run_enable_softap, NULL }, + { "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 }, { NULL, NULL, }, }; -- 2.34.1