From: taesub kim Date: Mon, 23 Oct 2017 07:27:58 +0000 (+0900) Subject: Added APIs to set/get enable or disable of Wi-Fi profile auto-connect in extension... X-Git-Tag: submit/tizen/20171030.235228~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=406a7da9759ad5be8a1c99ca734fa2e2fdb9671b;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Added APIs to set/get enable or disable of Wi-Fi profile auto-connect in extension.h file Change-Id: I0cc360ed78f26a85062b2af5d17b78af2798da81 Signed-off-by: Taesub Kim --- diff --git a/include/network_dbus.h b/include/network_dbus.h index 505858b..8d86a87 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -151,6 +151,8 @@ 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); +int _net_dbus_wifi_set_autoconnect(const char *profile_name, gboolean autoconnect); +int _net_dbus_wifi_get_autoconnect(const char *profile_name, gboolean *autoconnect); #ifdef __cplusplus } diff --git a/include/network_interface.h b/include/network_interface.h index 1a1f228..d2f7680 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -260,6 +260,8 @@ 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_set_ap_auto_connect(const char *profile_name, gboolean autoconnect); +int net_wifi_get_ap_auto_connect(const char *profile_name, gboolean *autoconnect); int net_wifi_cancel_wps(void); diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 8bf997f..e16bd81 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -294,6 +294,8 @@ 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); +int _wifi_set_ap_auto_connect(wifi_manager_ap_h ap_h, bool autoconnect); +int _wifi_get_ap_auto_connect(wifi_manager_ap_h ap_h, bool *autoconnect); /* WIFI Privilege Check */ int _wifi_check_get_privilege(); diff --git a/include/wifi_manager_extension.h b/include/wifi_manager_extension.h index 9c2b2e6..9a89cd8 100755 --- a/include/wifi_manager_extension.h +++ b/include/wifi_manager_extension.h @@ -94,11 +94,13 @@ typedef enum { /** * @brief Called when you get the vsie repeatedly. * @since_tizen 4.0 - * @param[in] vsie The vsie data - * @param[in] length The length of vsie data - * @param[in] user_data The user data passed from the request function + * + * @param[in] vsie The vsie data + * @param[in] length The length of vsie data + * @param[in] user_data The user data passed from the request function + * * @return @c true to continue with the next iteration of the loop, \n - *» otherwise @c false to break out of the loop + * otherwise @c false to break out of the loop * @see wifi_manager_get_vsie_list() */ typedef bool(*wifi_manager_vsie_list_cb)(char* vsie, int length, void* user_data); @@ -109,12 +111,9 @@ typedef bool(*wifi_manager_vsie_list_cb)(char* vsie, int length, void* user_data * By default, the auto-scanning is enabled automatically until disabling auto-scanning. * Don't forget to enable again when you finish your works with disabled auto-scanning. * @since_tizen 4.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/network.set \n - * %http://tizen.org/privilege/network.get - * @remarks This API needs both privileges. * - * @param[in] autoscan true to enable and false to disable + * @param[in] wifi The Wi-Fi handle + * @param[in] autoscan true to enable and false to disable * * @return 0 on success, otherwise negative error value * @retval #WIFI_ERROR_NONE Successful @@ -126,13 +125,28 @@ typedef bool(*wifi_manager_vsie_list_cb)(char* vsie, int length, void* user_data */ int wifi_manager_set_autoscan(wifi_manager_h wifi, bool autoscan); +/** + * @brief Gets the autoscan state. + * @since_tizen 4.0 + * + * @param[in] wifi The Wi-Fi handle + * @param[out] autoscan The autoscan state(enable or disable) + * + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied + * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported + */ +int wifi_manager_get_autoscan(wifi_manager_h wifi, bool *autoscan); + /** * @brief Sets the mode of autoscan. * @since_tizen 4.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/network.set * - * @param[in] mode The auto scan mode + * @param[in] wifi The Wi-Fi handle + * @param[in] mode The auto scan mode * * @return 0 on success, otherwise negative error value * @retval #WIFI_ERROR_NONE Successful @@ -141,32 +155,16 @@ int wifi_manager_set_autoscan(wifi_manager_h wifi, bool autoscan); * @retval #WIFI_ERROR_PERMISSION_DENIED Permission Denied * @pre This API needs wifi_initialize() before use. */ -int wifi_manager_set_autoscan_mode(wifi_manager_h wifi, wifi_manager_autoscan_mode_e mode); - -/** - * @brief Gets the autoscan state. - * @since_tizen 4.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/network.get - * @param[in] wifi The wifi handle - * @param[out] autoscan The autoscan state(enable or disable) - * @return 0 on success, otherwise negative error value - * @retval #WIFI_MANAGER_ERROR_NONE Successful - * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed - * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied - * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported - */ -int wifi_manager_get_autoscan(wifi_manager_h wifi, - bool *autoscan); +int wifi_manager_set_autoscan_mode(wifi_manager_h wifi, + wifi_manager_autoscan_mode_e mode); /** * @brief Gets the autoscan mode. * @since_tizen 4.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/network.get - * @param[in] wifi The wifi handle - * @param[out] mode The mode of autoscan + * + * @param[in] wifi The Wi-Fi handle + * @param[out] mode The mode of autoscan + * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter @@ -180,12 +178,12 @@ int wifi_manager_get_autoscan_mode(wifi_manager_h wifi, /** * @brief Adds the Wi-Fi Vendor Specific Information Element (VSIE) to specific frame type. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/network.set * @remarks @a vsie_str for @a frame_id will be in effect until Wi-Fi is deactivated. - * @param[in] wifi The wifi handle - * @param[in] frame_id frame ID for setting VSIE - * @param[in] vsie_str VSIE data + * + * @param[in] wifi The Wi-Fi handle + * @param[in] frame_id The frame ID for setting VSIE + * @param[in] vsie_str The VSIE data + * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter @@ -204,12 +202,12 @@ int wifi_manager_add_vsie(wifi_manager_h wifi, /** * @brief Gets the Wi-Fi Vendor Specific Information Elements (VSIE) from specific frame. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/network.get * @remarks @a vsie_str must be released with free(). - * @param[in] wifi The wifi handle - * @param[in] frame_id frame ID for setting VSIE - * @param[out] vsie_str VSIE data + * + * @param[in] wifi The Wi-Fi handle + * @param[in] frame_id The frame ID for setting VSIE + * @param[out] vsie_str The VSIE data + * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter @@ -229,12 +227,12 @@ int wifi_manager_get_vsie(wifi_manager_h wifi, /** * @brief Removes the Wi-Fi Vendor Specific Information Element (VSIE) from specific frame. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/network.set * @remarks @a vsie_str for @a frame_id will be in effect until Wi-Fi is deactivated. - * @param[in] wifi The wifi handle - * @param[in] frame_id frame ID for removing VSIE - * @param[in] vsie_str VSIE data + * + * @param[in] wifi The wifi handle + * @param[in] frame_id The frame ID for removing VSIE + * @param[in] vsie_str The VSIE data + * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter @@ -254,11 +252,11 @@ int wifi_manager_remove_vsie(wifi_manager_h wifi, /** * @brief Gets the vsie result of the scan. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/network.get - * @param[in] wifi The wifi handle - * @param[in] callback The callback to be called - * @param[in] user_data The user data passed to the callback function + * + * @param[in] wifi The Wi-Fi handle + * @param[in] callback The callback to be called + * @param[in] user_data The user data passed to the callback function + * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter @@ -273,34 +271,81 @@ int wifi_manager_get_vsie_list(wifi_manager_h wifi, /** * @brief Flush BSS * @since_tizen 4.0 + * + * @param[in] wifi The Wi-Fi handle + * * @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 + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation */ int wifi_manager_flush_bss(wifi_manager_h wifi); /** - * @brief Gets auto connect mode + * @brief Sets auto connection mode(enable or disable) for all Wi-Fi profile. * @since_tizen 4.0 - * @param[out] connect_mode pointer + * + * @param[in] wifi The Wi-Fi handle + * @param[in] connect_mode The mode of auto connection + * * @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 + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation */ -int wifi_manager_get_auto_connect(wifi_manager_h wifi, int *connect_mode); +int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mode); /** - * @brief Sets auto connect mode + * @brief Gets auto connection mode(enable or disable) for all Wi-Fi profile. * @since_tizen 4.0 - * @param[in] connect_mode + * + * @param[in] wifi The Wi-Fi handle + * @param[out] connect_mode The mode of auto connection + * * @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 + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation */ -int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mode); +int wifi_manager_get_auto_connect(wifi_manager_h wifi, int *connect_mode); + +/** + * @brief Sets enables or disables auto-connection of the AP. + * @details If an AP is connected, then connection information will be stored. + * By default, the stored AP can be connected automatically when it found, until disabling auto-connection. + * @since_tizen 5.0 + * + * @param[in] ap The access point handle + * @param[in] autoconnect true when enabled and false when disabled + * + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied + * @pre This API needs wifi_manager_initialize() and wifi_manager_activate() before use. + */ +int wifi_manager_ap_set_auto_connect(wifi_manager_ap_h ap, bool autoconnect); + +/** + * @brief Gets enables or disables auto-connection of the AP. + * @details If an AP is connected, then connection information will be stored. + * By default, the stored AP can be connected automatically when it found, until disabling auto-connection. + * @since_tizen 5.0 + * + * @param[in] ap The access point handle + * @param[out] autoconnect true when enabled and false when disabled + * + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied + * @pre This API needs wifi_manager_initialize() and wifi_manager_activate() before use. + */ +int wifi_manager_ap_get_auto_connect(wifi_manager_ap_h ap, bool *autoconnect); /** diff --git a/src/network_dbus.c b/src/network_dbus.c index 04b88af..520fd17 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -2201,6 +2201,72 @@ int _net_dbus_set_auto_connect_mode(int connect_mode) return Error; } +int _net_dbus_wifi_set_autoconnect(const char *profile_name, gboolean autoconnect) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + GVariant *message = NULL; + GVariant *params = NULL; + + WIFI_LOG(WIFI_INFO, "[%s] auto connect", autoconnect ? "enable" : "disable"); + + params = g_variant_new("(sv)", "AutoConnect", g_variant_new_boolean(autoconnect)); + + message = _net_invoke_dbus_method(CONNMAN_SERVICE, + profile_name, CONNMAN_SERVICE_INTERFACE, + "SetProperty", params, &Error); + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to Set AutoConnect"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_wifi_get_autoconnect(const char *profile_name, gboolean *autoconnect) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + GVariant *message = NULL; + GVariant *value = NULL; + GVariantIter *iter = NULL; + gchar *key = NULL; + + message = _net_invoke_dbus_method(CONNMAN_SERVICE, + profile_name, CONNMAN_SERVICE_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, "AutoConnect") == 0) { + *autoconnect = g_variant_get_boolean(value); + g_variant_unref(value); + g_free(key); + break; + } + } + + WIFI_LOG(WIFI_INFO, "Successfully get autoconnect: %d", *autoconnect); + + g_variant_iter_free(iter); + g_variant_unref(message); + + __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 7fa91e8..5765f3b 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1821,6 +1821,60 @@ EXPORT_API int net_wifi_get_auto_connect_mode(int *connect_mode) __NETWORK_CAPI_FUNC_EXIT__; return NET_ERR_NONE; } + +EXPORT_API int net_wifi_set_ap_auto_connect(const char *profile_name, gboolean autoconnect) +{ + __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 (_net_check_profile_name(profile_name) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Invalid profile name"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_PARAM; + } + + Error = _net_dbus_wifi_set_autoconnect(profile_name, autoconnect); + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to set autoconnect(%d), Error[%s]", + autoconnect, _net_print_error(Error)); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +EXPORT_API int net_wifi_get_ap_auto_connect(const char *profile_name, gboolean *autoconnect) +{ + __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 (_net_check_profile_name(profile_name) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Invalid profile name"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_PARAM; + } + + Error = _net_dbus_wifi_get_autoconnect(profile_name, autoconnect); + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to get autoconnect(%d), Error[%s]", + autoconnect, _net_print_error(Error)); + + __NETWORK_FUNC_EXIT__; + return Error; +} //LCOV_EXCL_STOP int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info) diff --git a/src/wifi_internal.c b/src/wifi_internal.c index feb49cb..a5d5b2b 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -1801,6 +1801,42 @@ int _wifi_get_auto_connect(int *connect_mode) return rv; } + +int _wifi_set_ap_auto_connect(wifi_manager_ap_h ap, bool autoconnect) +{ + int rv = 0; + net_profile_info_s *ap_info = ap; + + rv = net_wifi_set_ap_auto_connect(ap_info->ProfileName, autoconnect); + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to set auto connect [%d]", rv); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; + } + + return WIFI_MANAGER_ERROR_NONE; +} + +int _wifi_get_ap_auto_connect(wifi_manager_ap_h ap, bool *autoconnect) +{ + int rv = 0; + gboolean auto_connect = FALSE; + net_profile_info_s *ap_info = ap; + + rv = net_wifi_get_ap_auto_connect(ap_info->ProfileName, &auto_connect); + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to get auto connect [%d]", rv); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; + } + + *autoconnect = auto_connect; + return WIFI_MANAGER_ERROR_NONE; +} //LCOV_EXCL_STOP int _wifi_get_connected_profile(wifi_manager_ap_h *ap) @@ -2580,7 +2616,7 @@ int _wifi_set_background_scan_mode(wifi_manager_autoscan_mode_e mode) int _wifi_get_autoscan(bool *autoscan) { int rv; - gboolean auto_scan = 0;; + gboolean auto_scan = 0; rv = net_wifi_get_autoscan(&auto_scan); if (rv == NET_ERR_ACCESS_DENIED) { diff --git a/src/wifi_manager.c b/src/wifi_manager.c index e81c47b..442cfec 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -1290,6 +1290,32 @@ EXPORT_API int wifi_manager_set_auto_connect(wifi_manager_h wifi, int connect_mo __NETWORK_CAPI_FUNC_EXIT__; return rv; } + +EXPORT_API int wifi_manager_ap_set_auto_connect(wifi_manager_ap_h ap, bool autoconnect) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + if (_wifi_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + __NETWORK_CAPI_FUNC_EXIT__; + return _wifi_set_ap_auto_connect(ap, autoconnect); +} + +EXPORT_API int wifi_manager_ap_get_auto_connect(wifi_manager_ap_h ap, bool *autoconnect) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + if (_wifi_check_ap_validity(ap) == false || autoconnect == NULL) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + __NETWORK_CAPI_FUNC_EXIT__; + return _wifi_get_ap_auto_connect(ap, autoconnect); +} //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 6377743..4cf1f61 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -557,6 +557,73 @@ static bool __test_found_eap_ap_callback(wifi_manager_ap_h ap, void *user_data) return true; } +static bool __test_found_set_autoconnect_ap_callback(wifi_manager_ap_h ap, void *user_data) +{ + int rv = 0, enable; + char *ap_name = NULL; + bool autoconnect = false; + char *ap_name_part = (char *)user_data; + + rv = wifi_manager_ap_get_essid(ap, &ap_name); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("[Wi-Fi] Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (__test_compare_ap_name(ap_name, ap_name_part)) { + printf("[Wi-Fi] Input command number (enable[1], disable[0]) : "); + rv = scanf("%9d", &enable); + if (rv <= 0) { + g_free(ap_name); + return false; + } + + if (enable != 0) + autoconnect = true; + + rv = wifi_manager_ap_set_auto_connect(ap, autoconnect); + if (rv != WIFI_MANAGER_ERROR_NONE) + printf("Fail to set [%s] : %s\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to set [%s]\n", ap_name); + + g_free(ap_name); + return false; + } + + g_free(ap_name); + + return true; +} + +static bool __test_found_get_autoconnect_ap_callback(wifi_manager_ap_h ap, void *user_data) +{ + int rv = 0; + bool autoconnect = false; + char *ap_name = NULL; + char *ap_name_part = (char *)user_data; + + rv = wifi_manager_ap_get_essid(ap, &ap_name); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("[Wi-Fi] Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (__test_compare_ap_name(ap_name, ap_name_part)) { + rv = wifi_manager_ap_get_auto_connect(ap, &autoconnect); + if (rv != WIFI_MANAGER_ERROR_NONE) + printf("Fail to get [%s] : %s\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to get : [%s]\n", autoconnect ? "TRUE" : "FALSE"); + g_free(ap_name); + return false; + } + + g_free(ap_name); + + return true; +} + static bool test_get_user_int(const char *msg, int *num) { if (msg == NULL || num == NULL) @@ -2513,6 +2580,56 @@ int test_wifi_manager_get_auto_connect(void) return 1; } +int test_wifi_manager_set_ap_auto_connect(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_manager_is_activated(wifi, &state); + if (state == false) + return -1; + + printf("[Wi-Fi] Input a part of AP name to set : "); + rv = scanf("%32s", ap_name); + if (rv <= 0) + return -1; + + rv = wifi_manager_foreach_found_ap(wifi, __test_found_set_autoconnect_ap_callback, ap_name); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("[Wi-Fi] Fail to set up (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("[Wi-Fi] Set up finished\n"); + return 1; +} + +int test_wifi_manager_get_ap_auto_connect(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_manager_is_activated(wifi, &state); + if (state == false) + return -1; + + printf("[Wi-Fi] Input a part of AP name to get : "); + rv = scanf("%32s", ap_name); + if (rv <= 0) + return -1; + + rv = wifi_manager_foreach_found_ap(wifi, __test_found_get_autoconnect_ap_callback, ap_name); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("[Wi-Fi] Fail to get up (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("[Wi-Fi] Get up finished\n"); + return 1; +} + int main(int argc, char **argv) { GMainLoop *mainloop; @@ -2553,6 +2670,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) /* Public API */ printf("\n\n Network Connection API Test App\n\n"); printf("Options..\n"); + printf(LOG_BLUE "[Public APIs]\n" LOG_END); printf(LOG_GREEN "1 - Wi-Fi init and set callbacks\n" LOG_END); printf("2 - Wi-Fi deinit(unset callbacks automatically)\n"); printf(LOG_GREEN "3 - Activate Wi-Fi device\n" LOG_END); @@ -2584,23 +2702,26 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("t - Connect WPS PBC without SSID\n"); printf("u - Connect WPS PIN without SSID\n"); printf("v - Cancel WPS Request\n"); + printf("w - Get wifi scanning state\n"); + printf("x - Enable TDLS Channel Switch Request\n"); + printf("y - Disable TDLS Channel Switch Request\n"); + printf("z - Get Wi-Fi Module State\n"); + printf("A - BSSID Scan\n"); + printf("B - Start Multi Scan\n"); /* Extension API */ - printf("w - Set Auto Scan Enable-Disable\n"); - printf("x - Set Auto Scan Mode\n"); - printf("y - Get wifi scanning state\n"); - printf("z - Get Auto Scan Enable-Disable\n"); - printf("A - Get Auto Scan Mode\n"); - printf("B - Enable TDLS Channel Switch Request\n"); - printf("C - Disable TDLS Channel Switch Request\n"); - printf("D - Get Wi-Fi Module State\n"); - printf("E - BSSID Scan\n"); - printf("F - Add VSIE\n"); - printf("G - Get VSIE\n"); - printf("H - Remove VSIE\n"); - printf("I - Start Multi Scan\n"); + printf(LOG_BLUE "[Extension API]\n" LOG_END); + printf("C - Set Auto Scan Enable-Disable\n"); + printf("D - Set Auto Scan Mode\n"); + printf("E - Get Auto Scan Enable-Disable\n"); + printf("F - Get Auto Scan Mode\n"); + printf("G - Add VSIE\n"); + printf("H - Get VSIE\n"); + printf("I - Remove VSIE\n"); printf("J - Flush BSS\n"); printf("K - Set auto connect mode\n"); printf("L - Get auto connect mode\n"); + printf("M - Set enable or disable of Wi-Fi profile auto-connect \n"); + printf("N - Get enable or disable of Wi-Fi profile auto-connect \n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -2701,45 +2822,45 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'v': rv = test_wifi_manager_cancel_wps(); break; -/* Extension API */ case 'w': - rv = test_wifi_manager_set_autoscan_state(); + rv = test_wifi_manager_get_scan_state(); break; case 'x': - rv = test_wifi_manager_set_autoscan_mode(); + rv = test_wifi_manager_tdls_enable_channel_switch(); break; case 'y': - rv = test_wifi_manager_get_scan_state(); + rv = test_wifi_manager_tdls_disable_channel_switch(); break; case 'z': - rv = test_wifi_manager_get_autoscan_state(); + rv = test_wifi_manager_get_module_state(); break; case 'A': - rv = test_wifi_manager_get_autoscan_mode(); + rv = test_wifi_manager_bssid_scan(); break; case 'B': - rv = test_wifi_manager_tdls_enable_channel_switch(); + rv = test_wifi_manager_specific_ap_start_multi_scan(); break; +/* Extension API */ case 'C': - rv = test_wifi_manager_tdls_disable_channel_switch(); + rv = test_wifi_manager_set_autoscan_state(); break; case 'D': - rv = test_wifi_manager_get_module_state(); + rv = test_wifi_manager_set_autoscan_mode(); break; case 'E': - rv = test_wifi_manager_bssid_scan(); + rv = test_wifi_manager_get_autoscan_state(); break; case 'F': - rv = test_wifi_manager_add_vsie(); + rv = test_wifi_manager_get_autoscan_mode(); break; case 'G': - rv = test_wifi_manager_get_vsie(); + rv = test_wifi_manager_add_vsie(); break; case 'H': - rv = test_wifi_manager_remove_vsie(); + rv = test_wifi_manager_get_vsie(); break; case 'I': - rv = test_wifi_manager_specific_ap_start_multi_scan(); + rv = test_wifi_manager_remove_vsie(); break; case 'J': rv = test_wifi_manager_flush_bss(); @@ -2750,6 +2871,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'L': rv = test_wifi_manager_get_auto_connect(); break; + case 'M': + rv = test_wifi_manager_set_ap_auto_connect(); + break; + case 'N': + rv = test_wifi_manager_get_ap_auto_connect(); + break; default: break; }