Merge "Add new API to remove config" into tizen accepted/tizen/common/20160421.161757 accepted/tizen/ivi/20160422.065946 accepted/tizen/mobile/20160422.070019 accepted/tizen/tv/20160422.065911 accepted/tizen/wearable/20160422.065849 submit/tizen/20160421.064634
authorJaehyun Kim <jeik01.kim@samsung.com>
Thu, 21 Apr 2016 04:54:38 +0000 (21:54 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 21 Apr 2016 04:54:38 +0000 (21:54 -0700)
include/net_wifi_private.h
src/libnetwork.c
src/net_wifi_ap.c
test/wifi_test.c

index 210af6b..946f224 100755 (executable)
@@ -124,6 +124,9 @@ wifi_connection_state_e _wifi_convert_to_ap_state(net_state_type_t state);
 guint _wifi_callback_add(GSourceFunc func, gpointer user_data);
 void _wifi_callback_cleanup(void);
 
+int _wifi_libnet_check_get_privilege();
+int _wifi_libnet_check_profile_privilege();
+
 bool __libnet_check_feature_supported(const char *key, wifi_supported_feature_e feature);
 int _wifi_check_feature_supported(const char *feature_name, ...);
 
index a326b55..5070e2d 100755 (executable)
@@ -1347,6 +1347,32 @@ void _wifi_callback_cleanup(void)
        managed_idler_list = NULL;
 }
 
+int _wifi_libnet_check_get_privilege()
+{
+       int rv;
+
+       rv = net_check_get_privilege();
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+       } else if (rv != NET_ERR_NONE)
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+
+       return WIFI_ERROR_NONE;
+}
+
+int _wifi_libnet_check_profile_privilege()
+{
+       int rv = net_check_profile_privilege();
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+       } else if (rv != NET_ERR_NONE)
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+
+       return WIFI_ERROR_NONE;
+}
+
 bool __libnet_check_feature_supported(const char *key, wifi_supported_feature_e feature)
 {
        if (!wifi_is_feature_checked[feature]) {
index 52dfb38..dd78185 100755 (executable)
@@ -512,6 +512,22 @@ EXPORT_API int wifi_ap_set_ip_config_type(wifi_ap_h ap, wifi_address_family_e ad
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
 
        if (address_family == WIFI_ADDRESS_FAMILY_IPV4)
@@ -615,6 +631,22 @@ EXPORT_API int wifi_ap_set_ip_address(wifi_ap_h ap, wifi_address_family_e addres
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
 
        if (address_family == WIFI_ADDRESS_FAMILY_IPV4) {
@@ -687,6 +719,22 @@ EXPORT_API int wifi_ap_set_subnet_mask(wifi_ap_h ap, wifi_address_family_e addre
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
 
        /* Based on the family of address provided subnet mask should be set.
@@ -764,6 +812,22 @@ EXPORT_API int wifi_ap_set_gateway_address(wifi_ap_h ap, wifi_address_family_e a
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
        if (address_family == WIFI_ADDRESS_FAMILY_IPV6) {
                //LCOV_EXCL_START
@@ -819,6 +883,22 @@ EXPORT_API int wifi_ap_set_proxy_address(wifi_ap_h ap, wifi_address_family_e add
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
 
        if (proxy_address == NULL)
@@ -875,8 +955,23 @@ EXPORT_API int wifi_ap_set_proxy_type(wifi_ap_h ap, wifi_proxy_type_e proxy_type
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
-       int rv;
 
        switch (proxy_type) {
        //LCOV_EXCL_START
@@ -952,6 +1047,22 @@ EXPORT_API int wifi_ap_set_dns_address(wifi_ap_h ap, int order, wifi_address_fam
                return WIFI_ERROR_INVALID_PARAMETER;
        }
 
+       int rv = _wifi_libnet_check_get_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       rv = _wifi_libnet_check_profile_privilege();
+       if (rv == WIFI_ERROR_PERMISSION_DENIED)
+               return rv;
+       else if (rv != WIFI_ERROR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get statistics"); //LCOV_EXCL_LINE
+               return WIFI_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
        net_profile_info_t *profile_info = ap;
 
        if (address_family == WIFI_ADDRESS_FAMILY_IPV6) {
index b18d7f3..e83490f 100755 (executable)
@@ -191,6 +191,18 @@ static const char* __test_print_state(wifi_connection_state_e state)
        return "Unknown";
 }
 
+static bool __test_compare_ap_name(const char *ap_name, const char *ap_name_part)
+{
+       int ap_name_len = strlen(ap_name);
+       int ap_name_part_len = strlen(ap_name_part);
+
+       if (strncmp(ap_name, ap_name_part,
+                               ap_name_len > ap_name_part_len ? ap_name_len : ap_name_part_len) == 0)
+               return true;
+       else
+               return false;
+}
+
 static bool __test_found_ap_callback(wifi_ap_h ap, void *user_data)
 {
        int rv = 0;
@@ -228,7 +240,7 @@ static bool __test_found_connect_ap_callback(wifi_ap_h ap, void *user_data)
                return false;
        }
 
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                bool required = false;
 
                if (wifi_ap_is_passphrase_required(ap, &required) == WIFI_ERROR_NONE)
@@ -275,7 +287,7 @@ static bool __test_found_connect_wps_callback(wifi_ap_h ap, void *user_data)
                return false;
        }
 
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                int user_sel;
                char pin[32] = {0,};
 
@@ -322,7 +334,7 @@ static bool __test_found_disconnect_ap_callback(wifi_ap_h ap, void *user_data)
                return false;
        }
 
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                rv = wifi_disconnect(ap, __test_disconnected_callback, NULL);
                if (rv != WIFI_ERROR_NONE)
                        printf("Fail to disconnection reqeust %s : [%s]\n", ap_name, __test_convert_error_to_string(rv));
@@ -349,7 +361,7 @@ static bool __test_found_forget_ap_callback(wifi_ap_h ap, void *user_data)
                return false;
        }
 
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                rv = wifi_forget_ap(ap);
                if (rv != WIFI_ERROR_NONE)
                        printf("Fail to forget [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
@@ -376,7 +388,7 @@ static bool __test_found_eap_ap_callback(wifi_ap_h ap, void *user_data)
                return false;
        }
 
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                wifi_security_type_e type;
 
                if (wifi_ap_get_security_type(ap, &type) == WIFI_ERROR_NONE)
@@ -459,7 +471,7 @@ static bool __test_found_change_ip_method_callback(wifi_ap_h ap, void *user_data
                return false;
        }
 
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                wifi_ip_config_type_e type;
                int method;
                int address_type;
@@ -581,7 +593,7 @@ static bool __test_found_change_proxy_method_callback(wifi_ap_h ap, void *user_d
        }
 
        printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
-       if (strstr(ap_name, ap_name_part) != NULL) {
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                wifi_proxy_type_e type;
                char proxy_addr[65];
                int method;
@@ -671,8 +683,7 @@ static bool __test_found_print_ap_info_callback(wifi_ap_h ap, void *user_data)
        }
 
        printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
-       if (strstr(ap_name, ap_name_part) != NULL) {
-
+       if (__test_compare_ap_name(ap_name, ap_name_part)) {
                /* Basic info */
                printf("ESSID : %s\n", ap_name);
 
@@ -1627,7 +1638,9 @@ int test_wifi_tdls_get_connected_peer(void)
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
+#if !GLIB_CHECK_VERSION(2, 36, 0)
        g_type_init();
+#endif
        mainloop = g_main_loop_new(NULL, FALSE);
 
        GIOChannel *channel = g_io_channel_unix_new(0);