diff options
author | Jaehyun Kim <jeik01.kim@samsung.com> | 2024-09-05 14:51:22 +0900 |
---|---|---|
committer | Jaehyun Kim <jeik01.kim@samsung.com> | 2024-09-05 15:03:07 +0900 |
commit | 070228dce928541bb772e10860f83929b1da5b8f (patch) | |
tree | 0a56a05db51018afd96ded3bd6455ad480147537 | |
parent | 68d307f4ce8770d7914c8c44fba721f663157478 (diff) | |
download | wifi-manager-tizen_7.0.tar.gz wifi-manager-tizen_7.0.tar.bz2 wifi-manager-tizen_7.0.zip |
Add an API for getting VSIE from DHCP Ack packetaccepted/tizen/7.0/unified/20240909.160142tizen_7.0accepted/tizen_7.0_unified
Change-Id: I9b51c76f67f55206ad729c89d7c0ad69deaaa470
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
-rw-r--r-- | include/wifi-manager-extension.h | 20 | ||||
-rw-r--r-- | src/network_interface.c | 96 | ||||
-rw-r--r-- | src/network_internal.h | 2 | ||||
-rw-r--r-- | src/wifi_internal.c | 22 | ||||
-rw-r--r-- | src/wifi_internal.h | 1 | ||||
-rw-r--r-- | src/wifi_manager.c | 29 | ||||
-rw-r--r-- | tools/manager-test/wman_test_extension.c | 17 | ||||
-rw-r--r-- | tools/manager-test/wman_test_extension.h | 1 | ||||
-rw-r--r-- | tools/manager-test/wman_test_main.c | 4 |
9 files changed, 192 insertions, 0 deletions
diff --git a/include/wifi-manager-extension.h b/include/wifi-manager-extension.h index f03d572..ab58ff5 100644 --- a/include/wifi-manager-extension.h +++ b/include/wifi-manager-extension.h @@ -868,6 +868,26 @@ int wifi_manager_set_country_code(wifi_manager_h wifi, const char *country); int wifi_manager_get_country_code(wifi_manager_h wifi, char **country_code); /** + * @brief Gets the Wi-Fi Vendor Specific Information Elements (VSIE) from DHCP ack packet of the connected network. + * @since_tizen 9.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/network.get + * @remarks @a vsie_str must be released with free(). + * + * @param[in] wifi The Wi-Fi handle + * @param[out] vsie_str The DHCP VSIE data. If the connection is established but there is no VSIE data, this parameter will be set to NULL. + * + * @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_NOT_SUPPORTED Not supported + * @retval #WIFI_MANAGER_ERROR_NO_CONNECTION Not Connected + * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation Failed + * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied + */ +int wifi_manager_get_dhcp_vsie(wifi_manager_h wifi, char **vsie_str); + +/** * @brief Sets the Wi-Fi band to scan. * @since_tizen 9.0 * diff --git a/src/network_interface.c b/src/network_interface.c index 77690cf..a8ffffa 100644 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1070,6 +1070,41 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s *Prof return Error; } +static void _net_extract_dhcp_vsie_from_ipv4(GVariant *variant, char **vsie) +{ + GVariant *var = NULL; + GVariantIter *iter = NULL; + const gchar *value = NULL; + const gchar *subKey = NULL; + + g_variant_get(variant, "a{sv}", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) { + if (g_strcmp0(subKey, "DHCPVsie") == 0) { + value = g_variant_get_string(var, NULL); + *vsie = g_strdup(value); + } + } + + g_variant_iter_free(iter); +} + +static int __net_extract_dhcp_vsie(GVariantIter *array, char **vsie) +{ + GVariant *var = NULL; + const gchar *key = NULL; + + __NETWORK_FUNC_ENTER__; + + while (g_variant_iter_loop(array, "{sv}", &key, &var)) { + if (g_strcmp0(key, "IPv4") == 0) + _net_extract_dhcp_vsie_from_ipv4(var, vsie); + } + + __NETWORK_FUNC_EXIT__; + return NET_ERR_NONE; +} + int _net_extract_service_info(network_info_s *network_info, const char* ProfileName, GVariantIter *iter, net_profile_info_s* ProfInfo) @@ -1277,6 +1312,38 @@ static int __net_extract_connected_profile(network_info_s *network_info, return err; } +static int __net_extract_dhcp_vsie_from_connected_profile(network_info_s *network_info, + GVariant *message, char **vsie) +{ + int err = NET_ERR_NONE; + gchar *obj_path = NULL; + GVariantIter *iter = NULL; + + __NETWORK_FUNC_ENTER__; + + if (!g_variant_is_of_type(message, G_VARIANT_TYPE("(oa{sv})"))) { + WIFI_LOG(WIFI_ERROR, "There is no connected service"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_NO_PROFILE; + } + + g_variant_get(message, "(oa{sv})", &obj_path, &iter); + + if (g_str_has_prefix(obj_path, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) != TRUE) { + WIFI_LOG(WIFI_ERROR, "No wifi service"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_NO_PROFILE; + } + + err = __net_extract_dhcp_vsie(iter, vsie); + + g_variant_iter_free(iter); + g_free(obj_path); + + __NETWORK_FUNC_EXIT__; + return err; +} + static void _net_clear_cb_timers(void) { if (connection_cb_timer > 0) { @@ -1495,6 +1562,35 @@ int _net_get_connected_profile(network_info_s *network_info, return err; } +int _net_get_dhcp_vsie_from_connected_profile(network_info_s *network_info, + const char *ifname, char **vsie) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e err = NET_ERR_NO_PROFILE; + GVariant *message; + GVariant *params = NULL; + + params = g_variant_new("(s)", ifname); + + message = _net_invoke_dbus_method(network_info, + CONNMAN_SERVICE, CONNMAN_MANAGER_PATH, + CONNMAN_MANAGER_INTERFACE, "GetConnectedService", + params, &err); + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to get connected service(profile)"); //LCOV_EXCL_LINE + __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE + return err; //LCOV_EXCL_LINE + } + + err = __net_extract_dhcp_vsie_from_connected_profile(network_info, message, vsie); + + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; + return err; +} + int net_init_profile_info(network_info_s *network_info, net_profile_info_s *ProfInfo) { int i = 0; diff --git a/src/network_internal.h b/src/network_internal.h index 2da01f2..f1202a4 100644 --- a/src/network_internal.h +++ b/src/network_internal.h @@ -156,6 +156,8 @@ int _net_get_interface_list(network_info_s *network_info, GSList **interface_lis int _net_get_profile_list(network_info_s *network_info, GSList **profile_list); int _net_get_connected_profile(network_info_s *network_info, const char *ifname, net_profile_info_s *profile_info); +int _net_get_dhcp_vsie_from_connected_profile(network_info_s *network_info, + const char *ifname, char **vsie); net_err_e _net_get_wifi_state(network_info_s *network_info); void _net_clear_request_table(network_info_s *network_info); diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 2f959ac..635a79d 100644 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -4281,6 +4281,28 @@ int _wifi_get_country_code(wifi_manager_h wifi, char **country) } //LCOV_EXCL_START +int _wifi_get_dhcp_vsie(wifi_manager_h wifi, char **vsie) +{ + int rv; + wifi_manager_handle_s *wifi_handle = wifi; + const char *ifname = wifi_handle->interface_name; + + rv = _net_get_dhcp_vsie_from_connected_profile(wifi_handle->network_info, ifname, vsie); + if (rv != NET_ERR_NONE) { + if (rv == NET_ERR_NO_PROFILE) + return WIFI_MANAGER_ERROR_NO_CONNECTION; + else if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv == NET_ERR_INVALID_PARAM) + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + else + return WIFI_MANAGER_ERROR_OPERATION_FAILED; + } + + return WIFI_MANAGER_ERROR_NONE; +} + int _wifi_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band) { int rv; diff --git a/src/wifi_internal.h b/src/wifi_internal.h index d4bfab9..1925506 100644 --- a/src/wifi_internal.h +++ b/src/wifi_internal.h @@ -601,6 +601,7 @@ int _wifi_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime); int _wifi_set_country_code(wifi_manager_h wifi, const char *country); int _wifi_get_country_code(wifi_manager_h wifi, char **country); +int _wifi_get_dhcp_vsie(wifi_manager_h wifi, char **vsie); int _wifi_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band); int _wifi_get_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e *scan_band); diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 8b2ccb1..16b803f 100644 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -2245,6 +2245,35 @@ EXPORT_API int wifi_manager_get_country_code(wifi_manager_h wifi, char **country return rv; } +EXPORT_API int wifi_manager_get_dhcp_vsie(wifi_manager_h wifi, char **vsie_str) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + int rv = WIFI_MANAGER_ERROR_NONE; + char *vsie = NULL; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (vsie_str == NULL) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__); + + rv = _wifi_get_dhcp_vsie(wifi, &vsie); + if (vsie) { + *vsie_str = strdup(vsie); + g_free(vsie); + } else { + *vsie_str = NULL; + } + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + EXPORT_API int wifi_manager_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band) { int rv; diff --git a/tools/manager-test/wman_test_extension.c b/tools/manager-test/wman_test_extension.c index 10d706b..95f2f1c 100644 --- a/tools/manager-test/wman_test_extension.c +++ b/tools/manager-test/wman_test_extension.c @@ -1087,3 +1087,20 @@ int wman_test_set_scan_band(wifi_manager_h wifi) return 1; } + +int wman_test_get_dhcp_vsie(wifi_manager_h wifi) +{ + int rv; + char *vsie = NULL; + + rv = wifi_manager_get_dhcp_vsie(wifi, &vsie); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Fail to get DHCP VSIE[%s]\n", wman_test_strerror(rv)); + return -1; + } + printf("DHCP VSIE: %s\n", vsie); + free(vsie); + + return 1; +} + diff --git a/tools/manager-test/wman_test_extension.h b/tools/manager-test/wman_test_extension.h index 45661f4..0dfbf74 100644 --- a/tools/manager-test/wman_test_extension.h +++ b/tools/manager-test/wman_test_extension.h @@ -51,4 +51,5 @@ int wman_test_get_power_save_mode(wifi_manager_h wifi); int wman_test_set_power_save_mode(wifi_manager_h wifi); int wman_test_get_scan_band(wifi_manager_h wifi); int wman_test_set_scan_band(wifi_manager_h wifi); +int wman_test_get_dhcp_vsie(wifi_manager_h wifi); diff --git a/tools/manager-test/wman_test_main.c b/tools/manager-test/wman_test_main.c index dc308ac..cc3341f 100644 --- a/tools/manager-test/wman_test_main.c +++ b/tools/manager-test/wman_test_main.c @@ -333,6 +333,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf(", - Get Wi-Fi passphrase\n"); printf(". - Get Wi-Fi band for scanning\n"); printf("/ - Set Wi-Fi band for scanning\n"); + printf("_ - Gets the Wi-Fi VSIE from DHCP ack packet\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -576,6 +577,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case '/': rv = wman_test_set_scan_band(wifi); break; + case '_': + rv = wman_test_get_dhcp_vsie(wifi); + break; default: break; } |