From: taesub kim Date: Thu, 14 Sep 2017 00:31:40 +0000 (+0900) Subject: Add APIs to set/get auto connection mode X-Git-Tag: submit/tizen/20170920.020838^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1def976473153254ebcfb0e9cfa23c064bacf0f;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Add APIs to set/get auto connection mode Change-Id: I81a3438278354b225f8d3b1fe55bac26e0ea8b14 Signed-off-by: Taesub Kim --- diff --git a/include/network_dbus.h b/include/network_dbus.h index bce8821..505858b 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -149,7 +149,8 @@ int _net_dbus_get_vsie(unsigned int frame_id, char **vsie_str); int _net_dbus_remove_vsie(unsigned int frame_id, const char *vsie_str); int _net_dbus_get_vsie_list(GSList **vsie_list); int _net_dbus_flush_bss(void); - +int _net_dbus_get_auto_connect_mode(int *connect_mode); +int _net_dbus_set_auto_connect_mode(int connect_mode); #ifdef __cplusplus } diff --git a/include/network_interface.h b/include/network_interface.h index 51f103b..1a1f228 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -258,6 +258,8 @@ int net_wifi_get_vsie(unsigned int frame_id, char **vsie_str); int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str); int net_wifi_get_vsie_list(GSList **vsie_list); int net_wifi_flush_bss(void); +int net_wifi_get_auto_connect_mode(int *connect_mode); +int net_wifi_set_auto_connect_mode(int connect_mode); int net_wifi_cancel_wps(void); diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 7771822..8bf997f 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -290,7 +290,10 @@ int _wifi_get_vsie(wifi_manager_h wifi, int _wifi_remove_vsie(wifi_manager_h wifi, wifi_manager_vsie_frames_e frame_id, const char *vsie_str); int _wifi_get_vsie_list(wifi_manager_vsie_list_cb callback, void *user_data); + int _wifi_flush_bss(void); +int _wifi_get_auto_connect(int *connect_mode); +int _wifi_set_auto_connect(int connect_mode); /* WIFI Privilege Check */ int _wifi_check_get_privilege(); diff --git a/include/wifi_manager_extension.h b/include/wifi_manager_extension.h index f103414..9c2b2e6 100755 --- a/include/wifi_manager_extension.h +++ b/include/wifi_manager_extension.h @@ -280,6 +280,29 @@ int wifi_manager_get_vsie_list(wifi_manager_h wifi, */ int wifi_manager_flush_bss(wifi_manager_h wifi); +/** + * @brief Gets auto connect mode + * @since_tizen 4.0 + * @param[out] connect_mode pointer + * @return 0 on success, otherwise negative error value. + * @retval #WIFI_ERROR_NONE Successful + * @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation + */ +int wifi_manager_get_auto_connect(wifi_manager_h wifi, int *connect_mode); + +/** + * @brief Sets auto connect mode + * @since_tizen 4.0 + * @param[in] connect_mode + * @return 0 on success, otherwise negative error value. + * @retval #WIFI_ERROR_NONE Successful + * @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation + */ +int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mode); + + /** * @} */ diff --git a/src/network_dbus.c b/src/network_dbus.c index 32339d3..6ed89e5 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -588,6 +588,33 @@ static void __net_set_passpoint_reply(GObject *source_object, GAsyncResult *res, __NETWORK_FUNC_EXIT__; } +static void __net_set_auto_connect_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + __NETWORK_FUNC_ENTER__; + + GDBusConnection *conn = NULL; + GError *error = NULL; + net_err_e Error = NET_ERR_NONE; + + WIFI_LOG(WIFI_INFO, "WiFi set auto connection reply"); + + conn = G_DBUS_CONNECTION(source_object); + g_dbus_connection_call_finish(conn, res, &error); + if (error != NULL) { + Error = __net_netconfig_error_string_to_enum(error->message); + g_error_free(error); + } + + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "set auto connect failed[%d]", Error); + else + WIFI_LOG(WIFI_INFO, "set auto connect succeeded"); + + _net_dbus_pending_call_unref(); + __NETWORK_FUNC_EXIT__; +} + + static char *__net_make_group_name(const char *ssid, const char *net_mode, const char *sec) { @@ -2094,9 +2121,85 @@ int _net_dbus_flush_bss(void) g_variant_unref(message); WIFI_LOG(WIFI_INFO, "Successfully flush bss\n"); + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_get_auto_connect_mode(int *connect_mode) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + GVariant *message = NULL; + GVariant *value = NULL; + GVariantIter *iter = NULL; + gchar *key = NULL; + gboolean status = TRUE; + + message = _net_invoke_dbus_method( + CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, + CONNMAN_MANAGER_INTERFACE, "GetProperties", NULL, &Error); + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to get service properties"); + + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_get(message, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "AutoConnectMode") == 0) { + status = g_variant_get_boolean(value); + g_variant_unref(value); + g_free(key); + break; + } + } + + *connect_mode = (int)status; + + WIFI_LOG(WIFI_INFO, "Successfully auto connect mode: %d", *connect_mode); + + g_variant_iter_free(iter); + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; return Error; } + +int _net_dbus_set_auto_connect_mode(int connect_mode) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *params = NULL; + GVariant *param0 = NULL; + net_err_e Error = NET_ERR_NONE; + char key[] = "AutoConnectMode"; + gboolean value_enable = TRUE; + gboolean value_disable = FALSE; + + WIFI_LOG(WIFI_INFO, "Request auto connect mode [%s]", + connect_mode == 1 ? "enable" : "disable"); + + if (connect_mode == 1) + param0 = g_variant_new_boolean(value_enable); + else + param0 = g_variant_new_boolean(value_disable); + + params = g_variant_new("(sv)", key, param0); + + Error = _net_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "SetProperty", params, 6 * DBUS_REPLY_TIMEOUT, + __net_set_auto_connect_reply); + + __NETWORK_FUNC_EXIT__; + return Error; +} + + static void __net_wps_cancel_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) { diff --git a/src/network_interface.c b/src/network_interface.c index ef1ac21..b65265a 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1744,7 +1744,6 @@ int net_wifi_get_vsie_list(GSList **vsie_list) __NETWORK_FUNC_EXIT__; return Error; } -//LCOV_EXCL_STOP EXPORT_API int net_wifi_flush_bss(void) { @@ -1770,6 +1769,57 @@ EXPORT_API int net_wifi_flush_bss(void) return NET_ERR_NONE; } +EXPORT_API int net_wifi_set_auto_connect_mode(int connect_mode) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + if (NetworkInfo.ref_count < 1) { + WIFI_LOG(WIFI_ERROR, "Application is not registered"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + if ((Error = _net_dbus_set_auto_connect_mode(connect_mode)) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "Failed to set auto connect mode. Error [%s]", + _net_print_error(Error)); + + __NETWORK_FUNC_EXIT__; + return Error; + } + + __NETWORK_FUNC_EXIT__; + return NET_ERR_NONE; +} + +EXPORT_API int net_wifi_get_auto_connect_mode(int *connect_mode) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + if (NetworkInfo.ref_count < 1) { + WIFI_LOG(WIFI_ERROR, "Application is not registered"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + if ((Error = _net_dbus_get_auto_connect_mode(connect_mode)) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "Failed to set auto connect mode. Error [%s]", + _net_print_error(Error)); + + __NETWORK_FUNC_EXIT__; + return Error; + } + + __NETWORK_FUNC_EXIT__; + return NET_ERR_NONE; +} +//LCOV_EXCL_STOP + int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info) { __NETWORK_FUNC_ENTER__; diff --git a/src/wifi_internal.c b/src/wifi_internal.c index b8dd277..0fe291e 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -1775,6 +1775,32 @@ int _wifi_flush_bss(void) return WIFI_MANAGER_ERROR_NONE; } +int _wifi_set_auto_connect(int connect_mode) +{ + int rv; + + rv = net_wifi_set_auto_connect_mode(connect_mode); + + if (rv != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to set auto connection mode"); + } + + return rv; +} + +int _wifi_get_auto_connect(int *connect_mode) +{ + int rv; + + rv = net_wifi_get_auto_connect_mode(connect_mode); + + if (rv != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to get auto connection mode"); + } + + return rv; +} + int _wifi_get_connected_profile(wifi_manager_ap_h *ap) { int rv; diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 19894b2..908133b 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -1032,6 +1032,35 @@ EXPORT_API int wifi_manager_flush_bss(wifi_manager_h wifi) return rv; } + +EXPORT_API int wifi_manager_get_auto_connect(wifi_manager_h wifi, int *connect_mode) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + WIFI_LOG(WIFI_INFO, "[App-->TizenMW] get auto connect mode"); + + int rv; + + if (!(__wifi_check_handle_validity(wifi))) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE + } + + rv = _wifi_get_auto_connect(connect_mode); + + return rv; +} + +EXPORT_API int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mode) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + WIFI_LOG(WIFI_INFO, "[App-->TizenMW] set auto connect mode"); + + int rv; + + rv = _wifi_set_auto_connect(connect_mode); + + return rv; +} //LCOV_EXCL_STOP EXPORT_API int wifi_manager_specific_scan_create(wifi_manager_h wifi, diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index 5a5d196..5a272fe 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -2475,6 +2475,42 @@ int test_wifi_manager_flush_bss(void) return 1; } +int test_wifi_manager_set_auto_connect(void) +{ + int rv; + int mode; + + printf("Auto connect mode (1:enable, 0:disable) : "); + rv = scanf("%d", &mode); + if (rv <= 0) + return -1; + + rv = wifi_manager_set_auto_connect(wifi, mode); + + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Fail to set auto connect mode, rv = %d\n", rv); + } + + printf("Request to set auto connect mode\n"); + return 1; +} + +int test_wifi_manager_get_auto_connect(void) +{ + int rv; + int mode; + + rv = wifi_manager_get_auto_connect(wifi, &mode); + + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Fail to get auto connect mode, rv = %d\n", rv); + return 1; + } + + printf("Request to get auto connect mode = %d (1:enable, 0:disable)\n", mode); + return 1; +} + int main(int argc, char **argv) { GMainLoop *mainloop; @@ -2561,6 +2597,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("H - Remove VSIE\n"); printf("I - Start Multi Scan\n"); printf("J - Flush BSS\n"); + printf("K - Set auto connect mode\n"); + printf("L - Get auto connect mode\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -2704,6 +2742,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'J': rv = test_wifi_manager_flush_bss(); break; + case 'K': + rv = test_wifi_manager_set_auto_connect(); + break; + case 'L': + rv = test_wifi_manager_get_auto_connect(); + break; default: break; }