From: Niraj Kumar Goit Date: Wed, 12 May 2021 14:30:11 +0000 (+0530) Subject: Added API to set device country-code. X-Git-Tag: submit/tizen/20210528.085525~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F258238%2F7;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Added API to set device country-code. Change-Id: I1549591ef478f6ae556a787683b234da259d9a42 Signed-off-by: Niraj Kumar Goit --- diff --git a/include/network_dbus.h b/include/network_dbus.h index 38d80ba..f94b104 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -224,6 +224,8 @@ int _net_dbus_set_mac_policy(network_info_s *network_info, unsigned int policy); int _net_dbus_set_preassoc_mac_policy(network_info_s *network_info, unsigned int policy); int _net_dbus_set_random_mac_lifetime(network_info_s *network_info, unsigned int lifetime); +int _net_dbus_set_country_code(network_info_s *network_info, const char *country); + #ifdef __cplusplus } #endif diff --git a/include/network_interface.h b/include/network_interface.h index beca6fd..22d3ba3 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -382,6 +382,8 @@ int net_wifi_set_mac_policy(network_info_s *network_info, unsigned int policy); int net_wifi_set_preassoc_mac_policy(network_info_s *network_info, unsigned int policy); int net_wifi_set_random_mac_lifetime(network_info_s *network_info, unsigned int lifetime); +int net_wifi_set_country_code(network_info_s *network_info, const char *country); + /** * \} */ diff --git a/include/wifi-manager-extension.h b/include/wifi-manager-extension.h index e8e810e..6618ca2 100755 --- a/include/wifi-manager-extension.h +++ b/include/wifi-manager-extension.h @@ -720,6 +720,23 @@ int wifi_manager_set_random_mac_lifetime(wifi_manager_h wifi, unsigned int lifet */ int wifi_manager_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime); +/** + * @brief Sets the raw country code. + * @since_tizen 6.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/network.set + * @param[in] wifi The Wi-Fi handle. + * @param[in] country The ISO/IEC alpha2 country code. + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation Failed + * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied + */ +int wifi_manager_set_country_code(wifi_manager_h wifi, const char *country); + /** * @} */ diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 3666d51..bd62781 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -279,6 +279,11 @@ typedef struct { unsigned int mac_policy; unsigned int preassoc_mac_policy; unsigned int random_mac_lifetime; + /** + * country - Country code + * The ISO/IEC alpha2 country code. + */ + char country[3]; } wifi_manager_handle_s; typedef struct { @@ -583,6 +588,8 @@ int _wifi_get_preassoc_mac_policy(wifi_manager_h wifi, unsigned int *policy); int _wifi_set_random_mac_lifetime(wifi_manager_h wifi, unsigned int lifetime); 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); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/packaging/capi-network-wifi-manager.spec b/packaging/capi-network-wifi-manager.spec index eceae29..d7fd81b 100755 --- a/packaging/capi-network-wifi-manager.spec +++ b/packaging/capi-network-wifi-manager.spec @@ -1,7 +1,7 @@ Name: capi-network-wifi-manager Summary: Network Wi-Fi library in TIZEN C API Version: 1.3.8 -Release: 3 +Release: 4 Group: System/Network License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/network_dbus.c b/src/network_dbus.c index 99bdf5d..80f94c4 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -4129,3 +4129,33 @@ int _net_dbus_set_random_mac_lifetime(network_info_s *network_info, unsigned int __NETWORK_FUNC_EXIT__; return Error; } + +int _net_dbus_set_country_code(network_info_s *network_info, const char *country) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + GVariant *message = NULL; + + const char *prop_key = "CountryCode"; + const char *method = "SetProperty"; + GVariant *params = NULL; + + params = g_variant_new("(sv)", prop_key, g_variant_new_string(country)); + + message = _net_invoke_dbus_method(network_info, + CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX, + CONNMAN_TECHNOLOGY_INTERFACE, + method, params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to set country code"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; + return Error; +} diff --git a/src/network_interface.c b/src/network_interface.c index a1deb5b..cdfef59 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -3968,3 +3968,15 @@ int net_wifi_set_random_mac_lifetime(network_info_s *network_info, unsigned int __NETWORK_FUNC_EXIT__; return Error; } + +int net_wifi_set_country_code(network_info_s *network_info, const char *country) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + Error = _net_dbus_set_country_code(network_info, country); + + __NETWORK_FUNC_EXIT__; + return Error; +} diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 30cd2d5..64995ca 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -4073,3 +4073,21 @@ int _wifi_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime) return WIFI_MANAGER_ERROR_NONE; } + +int _wifi_set_country_code(wifi_manager_h wifi, const char *country) +{ + int rv; + wifi_manager_handle_s *wifi_handle = wifi; + + rv = net_wifi_set_country_code(wifi_handle->network_info, country); + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE + } else if (rv != NET_ERR_NONE) + return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + + memset(wifi_handle->country, 0, sizeof(wifi_handle->country)); + g_strlcpy(wifi_handle->country, country, sizeof(wifi_handle->country)); + + return WIFI_MANAGER_ERROR_NONE; +} diff --git a/src/wifi_manager.c b/src/wifi_manager.c index e9ba33c..6381e6b 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -2129,3 +2129,26 @@ EXPORT_API int wifi_manager_get_random_mac_lifetime(wifi_manager_h wifi, unsigne __NETWORK_CAPI_FUNC_EXIT__; return rv; } + +EXPORT_API int wifi_manager_set_country_code(wifi_manager_h wifi, const char *country) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + int rv = WIFI_MANAGER_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (country == NULL || strlen(country) != 2) { + WIFI_LOG(WIFI_ERROR, "country code is invalid"); + __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__); + + WIFI_LOG(WIFI_INFO, "Country Code [%s]", country); + rv = _wifi_set_country_code(wifi, country); + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} diff --git a/tool/wifi_manager_test.c b/tool/wifi_manager_test.c index 9ff85dd..565088e 100755 --- a/tool/wifi_manager_test.c +++ b/tool/wifi_manager_test.c @@ -3566,6 +3566,23 @@ int test_wifi_manager_get_connection_mode(void) return 1; } +int test_wifi_manager_set_country_code(void) +{ + int rv; + char country[3]; + + printf("Enter alpha2 country code (e.g. IN, JP, KR, US)\n"); + rv = scanf("%2s", country); + + rv = wifi_manager_set_country_code(wifi, (const char *)country); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Fail to set country code[%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + return 1; +} + int main(int argc, char **argv) { GMainLoop *mainloop; @@ -3674,6 +3691,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("@ - Set preassoc mac policy\n"); printf("# - Set random mac lifetime\n"); printf("$ - Get mac policies\n"); + printf("^ - Set country code\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -3878,6 +3896,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case '$': rv = test_wifi_manager_get_mac_policies(); break; + case '^': + rv = test_wifi_manager_set_country_code(); + break; default: break; }