Get Mac Policy parameters from Connman instead of wifi_handle 56/259556/2
authorNishant Chaprana <n.chaprana@samsung.com>
Wed, 9 Jun 2021 12:46:50 +0000 (18:16 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Wed, 9 Jun 2021 14:03:31 +0000 (19:33 +0530)
Change-Id: Ib883b766ada55290fc5d50e86d4d00dfd43ad246
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/network_dbus.h
include/network_interface.h
packaging/capi-network-wifi-manager.spec
src/network_dbus.c
src/network_interface.c
src/wifi_internal.c
tests/mocks/mock_gdbus.c

index 66f3208..7ff7012 100755 (executable)
@@ -221,8 +221,11 @@ int _net_dbus_dpp_stop(network_info_s *network_info,
                guint32 peer_id, guint32 own_id, gboolean is_initiator);
 
 int _net_dbus_set_mac_policy(network_info_s *network_info, unsigned int policy);
+int _net_dbus_get_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_get_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_get_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);
 int _net_dbus_get_country_code(network_info_s *network_info, char **country);
index 769d9fd..1823b77 100755 (executable)
@@ -381,8 +381,11 @@ int net_dpp_stop(network_info_s *network_info,
                guint32 peer_id, guint32 own_id, gboolean is_initiator);
 
 int net_wifi_set_mac_policy(network_info_s *network_info, unsigned int policy);
+int net_wifi_get_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_get_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_get_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);
 int net_wifi_get_country_code(network_info_s *network_info, char **country);
index 6501632..8df83b8 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-wifi-manager
 Summary:       Network Wi-Fi library in TIZEN C API
-Version:       1.3.8
+Version:       1.3.9
 Release:       5
 Group:         System/Network
 License:       Apache-2.0
index c41c997..82a4079 100755 (executable)
@@ -4066,6 +4066,48 @@ int _net_dbus_set_mac_policy(network_info_s *network_info, unsigned int policy)
        return Error;
 }
 
+int _net_dbus_get_mac_policy(network_info_s *network_info, unsigned int *policy)
+{
+       __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(network_info,
+                       CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+                       CONNMAN_TECHNOLOGY_INTERFACE, "GetProperties",
+                       NULL, &Error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get 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, "MacPolicy") == 0) {
+                       *policy = g_variant_get_uint32(value);
+                       WIFI_LOG(WIFI_INFO, "Successfully get mac policy: %u", *policy);
+
+                       g_variant_unref(value);
+                       g_free(key);
+                       break;
+               }
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int _net_dbus_set_preassoc_mac_policy(network_info_s *network_info, unsigned int policy)
 {
        __NETWORK_FUNC_ENTER__;
@@ -4098,6 +4140,48 @@ int _net_dbus_set_preassoc_mac_policy(network_info_s *network_info, unsigned int
        return Error;
 }
 
+int _net_dbus_get_preassoc_mac_policy(network_info_s *network_info, unsigned int *policy)
+{
+       __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(network_info,
+                       CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+                       CONNMAN_TECHNOLOGY_INTERFACE, "GetProperties",
+                       NULL, &Error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get 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, "PreassocMacPolicy") == 0) {
+                       *policy = g_variant_get_uint32(value);
+                       WIFI_LOG(WIFI_INFO, "Successfully get preassoc mac policy: %u", *policy);
+
+                       g_variant_unref(value);
+                       g_free(key);
+                       break;
+               }
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int _net_dbus_set_random_mac_lifetime(network_info_s *network_info, unsigned int lifetime)
 {
        __NETWORK_FUNC_ENTER__;
@@ -4130,6 +4214,48 @@ int _net_dbus_set_random_mac_lifetime(network_info_s *network_info, unsigned int
        return Error;
 }
 
+int _net_dbus_get_random_mac_lifetime(network_info_s *network_info, unsigned int *lifetime)
+{
+       __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(network_info,
+                       CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+                       CONNMAN_TECHNOLOGY_INTERFACE, "GetProperties",
+                       NULL, &Error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get 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, "RandomMacLifetime") == 0) {
+                       *lifetime = g_variant_get_uint32(value);
+                       WIFI_LOG(WIFI_INFO, "Successfully get random mac lifetime: %u", *lifetime);
+
+                       g_variant_unref(value);
+                       g_free(key);
+                       break;
+               }
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int _net_dbus_set_country_code(network_info_s *network_info, const char *country)
 {
        __NETWORK_FUNC_ENTER__;
index 6d8cb8e..05662d7 100755 (executable)
@@ -4023,6 +4023,18 @@ int net_wifi_set_mac_policy(network_info_s *network_info, unsigned int policy)
        return Error;
 }
 
+int net_wifi_get_mac_policy(network_info_s *network_info, unsigned int *policy)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       Error =  _net_dbus_get_mac_policy(network_info, policy);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int net_wifi_set_preassoc_mac_policy(network_info_s *network_info, unsigned int policy)
 {
        __NETWORK_FUNC_ENTER__;
@@ -4035,6 +4047,18 @@ int net_wifi_set_preassoc_mac_policy(network_info_s *network_info, unsigned int
        return Error;
 }
 
+int net_wifi_get_preassoc_mac_policy(network_info_s *network_info, unsigned int *policy)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       Error = _net_dbus_get_preassoc_mac_policy(network_info, policy);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int net_wifi_set_random_mac_lifetime(network_info_s *network_info, unsigned int lifetime)
 {
        __NETWORK_FUNC_ENTER__;
@@ -4047,6 +4071,18 @@ int net_wifi_set_random_mac_lifetime(network_info_s *network_info, unsigned int
        return Error;
 }
 
+int net_wifi_get_random_mac_lifetime(network_info_s *network_info, unsigned int *lifetime)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       Error = _net_dbus_get_random_mac_lifetime(network_info, lifetime);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int net_wifi_set_country_code(network_info_s *network_info, const char *country)
 {
        __NETWORK_FUNC_ENTER__;
index 17c7e97..e4f3439 100755 (executable)
@@ -3998,9 +3998,15 @@ int _wifi_set_mac_policy(wifi_manager_h wifi, unsigned int policy)
 
 int _wifi_get_mac_policy(wifi_manager_h wifi, unsigned int *policy)
 {
+       int rv;
        wifi_manager_handle_s *wifi_handle = wifi;
 
-       *policy = wifi_handle->mac_policy;
+       rv = net_wifi_get_mac_policy(wifi_handle->network_info, policy);
+       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
 
        return WIFI_MANAGER_ERROR_NONE;
 }
@@ -4024,9 +4030,15 @@ int _wifi_set_preassoc_mac_policy(wifi_manager_h wifi, unsigned int policy)
 
 int _wifi_get_preassoc_mac_policy(wifi_manager_h wifi, unsigned int *policy)
 {
+       int rv;
        wifi_manager_handle_s *wifi_handle = wifi;
 
-       *policy = wifi_handle->preassoc_mac_policy;
+       rv = net_wifi_get_preassoc_mac_policy(wifi_handle->network_info, policy);
+       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
 
        return WIFI_MANAGER_ERROR_NONE;
 }
@@ -4050,9 +4062,15 @@ 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 rv;
        wifi_manager_handle_s *wifi_handle = wifi;
 
-       *lifetime = wifi_handle->random_mac_lifetime;
+       rv = net_wifi_get_random_mac_lifetime(wifi_handle->network_info, lifetime);
+       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
 
        return WIFI_MANAGER_ERROR_NONE;
 }
index 629b327..3a8d738 100644 (file)
@@ -211,7 +211,18 @@ static GVariant * __get_mock_variant_get_services(void)
 
 static GVariant * __get_mock_variant_get_properties(void)
 {
-       return NULL;
+       GVariant *return_parameter;
+       GVariantBuilder *builder_properties = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       g_variant_builder_add(builder_properties, "{sv}", "MacPolicy", g_variant_new_uint32(1));
+       g_variant_builder_add(builder_properties, "{sv}", "PreassocMacPolicy", g_variant_new_uint32(2));
+       g_variant_builder_add(builder_properties, "{sv}", "RandomMacAddrLifetime", g_variant_new_uint32(20));
+
+       return_parameter = g_variant_new("(a{sv})", builder_properties);
+
+       g_variant_builder_unref(builder_properties);
+
+       return return_parameter;
 }
 
 static GVariant * __get_mock_variant_get_interfaces(void)