Added API to set device country-code. 38/258238/7
authorNiraj Kumar Goit <niraj.g@samsung.com>
Wed, 12 May 2021 14:30:11 +0000 (20:00 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 25 May 2021 09:43:12 +0000 (15:13 +0530)
Change-Id: I1549591ef478f6ae556a787683b234da259d9a42
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_dbus.h
include/network_interface.h
include/wifi-manager-extension.h
include/wifi_internal.h
packaging/capi-network-wifi-manager.spec
src/network_dbus.c
src/network_interface.c
src/wifi_internal.c
src/wifi_manager.c
tool/wifi_manager_test.c

index 38d80ba..f94b104 100755 (executable)
@@ -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
index beca6fd..22d3ba3 100755 (executable)
@@ -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);
+
 /**
  * \}
  */
index e8e810e..6618ca2 100755 (executable)
@@ -721,6 +721,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);
+
+/**
  * @}
  */
 
index 3666d51..bd62781 100755 (executable)
@@ -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 */
index eceae29..d7fd81b 100755 (executable)
@@ -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
index 99bdf5d..80f94c4 100755 (executable)
@@ -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;
+}
index a1deb5b..cdfef59 100755 (executable)
@@ -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;
+}
index 30cd2d5..64995ca 100755 (executable)
@@ -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;
+}
index e9ba33c..6381e6b 100755 (executable)
@@ -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;
+}
index 9ff85dd..565088e 100755 (executable)
@@ -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;
        }