Add multi interfaces function 08/242508/8 accepted/tizen/unified/20200903.151725 submit/tizen/20200901.053326 submit/tizen/20200902.111409 submit/tizen/20200903.044940
authorhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 27 Aug 2020 08:31:46 +0000 (17:31 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Tue, 1 Sep 2020 03:21:51 +0000 (12:21 +0900)
Change-Id: I5ae1059626ba6cde1c58eee1564904eaa7542af0
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/internal/network-internal.h
include/wifi/network-wifi-intf.h
src/network-profile-intf.c
src/network-wifi-intf.c

index 7c95476..d3b9c68 100755 (executable)
@@ -60,6 +60,7 @@ extern "C" {
 #define CONNMAN_MANAGER_PATH                   "/"
 #define CONNMAN_PATH                                   "/net/connman"
 #define CONNMAN_TECHNOLOGY_PATH                        "/net/connman/technology"
+#define CONNMAN_WIFI_TECHNOLOGY_PATH   "/net/connman/technology/wifi"
 
 #define NETCONFIG_SERVICE                              "net.netconfig"
 #define NETCONFIG_NETWORK_INTERFACE            NETCONFIG_SERVICE ".network"
index f0c4418..8584f3c 100755 (executable)
@@ -151,6 +151,10 @@ struct ssid_scan_bss_info_t {
  */
 
 int net_get_wifi_state(void *handle, net_wifi_state_t *current_state);
+
+int net_get_wifi_interface_list(void *handle, GSList **interface_list);
+
+
 /*****************************************************************************
  *     ConnMan Wi-Fi Client Interface Asynchronous Function Declaration
  *****************************************************************************/
index b892555..d264272 100755 (executable)
@@ -562,6 +562,8 @@ static int __net_extract_all_services(network_info_t *network_info,
        net_profile_info_t ProfInfo = { 0, };
        net_err_t Error = NET_ERR_NONE;
        gchar *obj;
+       gchar *service_name = NULL;
+       GHashTable *service_hash = NULL;
        GVariantIter *next = NULL;
 
        __NETWORK_FUNC_ENTER__;
@@ -573,6 +575,8 @@ static int __net_extract_all_services(network_info_t *network_info,
                return NET_ERR_INVALID_PARAM;
        }
 
+       service_hash = g_hash_table_new(g_str_hash, g_str_equal);
+
        /* LCOV_EXCL_START */
        while (g_variant_iter_loop(array, "(oa{sv})", &obj, &next)) {
                if (obj == NULL)
@@ -590,9 +594,16 @@ static int __net_extract_all_services(network_info_t *network_info,
                                goto error;
                        }
 
-                       if (device_type == NET_DEVICE_WIFI &&
-                                       g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
-                               ProfInfo.ProfileInfo.Wlan.is_hidden = TRUE;
+                       if (device_type == NET_DEVICE_WIFI) {
+                               service_name = &obj[strlen(service_prefix) + 13];
+                               if (g_hash_table_lookup(service_hash, service_name))
+                                       continue;
+
+                               g_hash_table_insert(service_hash, service_name, service_name);
+
+                               if (g_strrstr(obj + strlen(service_prefix), "hidden") != NULL)
+                                       ProfInfo.ProfileInfo.Wlan.is_hidden = TRUE;
+                       }
 
                        ProfInfo.profile_type = device_type;
                        g_strlcpy(ProfInfo.ProfileName, obj, NET_PROFILE_NAME_LEN_MAX);
@@ -662,11 +673,15 @@ static int __net_extract_all_services(network_info_t *network_info,
 
        *prof_count = count;
 
+       g_hash_table_destroy(service_hash);
+
        __NETWORK_FUNC_EXIT__;
        return NET_ERR_NONE;
 
 error:
        /* LCOV_EXCL_START */
+       g_hash_table_destroy(service_hash);
+
        if (next)
                g_variant_iter_free(next);
        if (obj)
@@ -2753,105 +2768,95 @@ static gboolean __net_is_cellular_default_candidate(const char *profile)
 }
 
 static int __net_extract_default_profile(network_info_t *network_info,
-               GVariantIter *array, net_profile_info_t *ProfilePtr)
+               GVariant *message, net_profile_info_t *ProfilePtr)
 {
        net_err_t Error = NET_ERR_NONE;
        net_device_t device_type;
-       gchar *key = NULL;
-       GVariantIter *value = NULL;
+       gchar *obj_path = NULL;
+       GVariantIter *iter = NULL;
 
        __NETWORK_FUNC_ENTER__;
 
-       if (array == NULL || ProfilePtr == NULL) {
+       if (message == NULL || ProfilePtr == NULL) {
                NETWORK_LOG(NETWORK_ERROR, "Invalid parameter");
                __NETWORK_FUNC_EXIT__;
                return NET_ERR_INVALID_PARAM;
        }
 
-       while (g_variant_iter_loop(array, "(oa{sv})", &key, &value)) {
-               if (g_str_has_prefix(key, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
-                       device_type = NET_DEVICE_CELLULAR;
-               else if (g_str_has_prefix(key, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
-                       device_type = NET_DEVICE_WIFI;
-               else if (g_str_has_prefix(key, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
-                       device_type = NET_DEVICE_ETHERNET;
-               else if (g_str_has_prefix(key, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
-                       device_type = NET_DEVICE_BLUETOOTH;
-               else if (g_str_has_prefix(key, CONNMAN_MESH_PROFILE_PREFIX) == TRUE)
-                       device_type = NET_DEVICE_MESH;
-               else {
-                       Error = NET_ERR_NO_SERVICE;
-                       goto error;
-               }
+       if (!g_variant_is_of_type(message, G_VARIANT_TYPE("(oa{sv})"))) {
+               NETWORK_LOG(NETWORK_ERROR, "There is no default service");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_NO_SERVICE;
+       }
 
-               Error = __net_pm_init_profile_info(device_type, ProfilePtr);
-               if (Error != NET_ERR_NONE) {
-                       NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
-                       goto error;
-               }
+       g_variant_get(message, "(oa{sv})", &obj_path, &iter);
+
+       if (g_str_has_prefix(obj_path, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE)
+               device_type = NET_DEVICE_CELLULAR;
+       else if (g_str_has_prefix(obj_path, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE)
+               device_type = NET_DEVICE_WIFI;
+       else if (g_str_has_prefix(obj_path, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX) == TRUE)
+               device_type = NET_DEVICE_ETHERNET;
+       else if (g_str_has_prefix(obj_path, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX) == TRUE)
+               device_type = NET_DEVICE_BLUETOOTH;
+       else if (g_str_has_prefix(obj_path, CONNMAN_MESH_PROFILE_PREFIX) == TRUE)
+               device_type = NET_DEVICE_MESH;
+       else {
+               Error = NET_ERR_NO_SERVICE;
+               g_variant_iter_free(iter);
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
 
-               ProfilePtr->profile_type = device_type;
-               g_strlcpy(ProfilePtr->ProfileName, key, NET_PROFILE_NAME_LEN_MAX);
+       Error = __net_pm_init_profile_info(device_type, ProfilePtr);
+       if (Error != NET_ERR_NONE) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to init profile");
+               g_variant_iter_free(iter);
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
 
-               if (device_type == NET_DEVICE_CELLULAR &&
-                               __net_is_cellular_default_candidate(key) == TRUE) {
-                       g_strlcpy(ProfilePtr->ProfileInfo.Pdp.net_info.ProfileName,
-                                       key, NET_PROFILE_NAME_LEN_MAX);
+       ProfilePtr->profile_type = device_type;
+       g_strlcpy(ProfilePtr->ProfileName, obj_path, NET_PROFILE_NAME_LEN_MAX);
 
-                       Error = __net_extract_mobile_info(network_info, value, ProfilePtr);
-                       break;
-               } else if (device_type == NET_DEVICE_WIFI) {
-                       g_strlcpy(ProfilePtr->ProfileInfo.Wlan.net_info.ProfileName,
-                                       key, NET_PROFILE_NAME_LEN_MAX);
+       if (device_type == NET_DEVICE_CELLULAR &&
+                       __net_is_cellular_default_candidate(obj_path) == TRUE) {
+               g_strlcpy(ProfilePtr->ProfileInfo.Pdp.net_info.ProfileName,
+                               obj_path, NET_PROFILE_NAME_LEN_MAX);
 
-                       Error = __net_extract_wifi_info(value, ProfilePtr);
-                       break;
-               } else if (device_type == NET_DEVICE_ETHERNET) {
-                       g_strlcpy(ProfilePtr->ProfileInfo.Ethernet.net_info.ProfileName,
-                                       key, NET_PROFILE_NAME_LEN_MAX);
+               Error = __net_extract_mobile_info(network_info, iter, ProfilePtr);
+       } else if (device_type == NET_DEVICE_WIFI) {
+               g_strlcpy(ProfilePtr->ProfileInfo.Wlan.net_info.ProfileName,
+                               obj_path, NET_PROFILE_NAME_LEN_MAX);
 
-                       Error = __net_extract_ethernet_info(value, ProfilePtr);
-                       break;
-               } else if (device_type == NET_DEVICE_BLUETOOTH) {
-                       g_strlcpy(ProfilePtr->ProfileInfo.Bluetooth.net_info.ProfileName,
-                                       key, NET_PROFILE_NAME_LEN_MAX);
+               Error = __net_extract_wifi_info(iter, ProfilePtr);
+       } else if (device_type == NET_DEVICE_ETHERNET) {
+               g_strlcpy(ProfilePtr->ProfileInfo.Ethernet.net_info.ProfileName,
+                               obj_path, NET_PROFILE_NAME_LEN_MAX);
 
-                       Error = __net_extract_bluetooth_info(value, ProfilePtr);
-                       break;
-               } else if (device_type == NET_DEVICE_MESH) {
-                       g_strlcpy(ProfilePtr->ProfileInfo.Mesh.net_info.ProfileName,
-                                       key, NET_PROFILE_NAME_LEN_MAX);
+               Error = __net_extract_ethernet_info(iter, ProfilePtr);
+       } else if (device_type == NET_DEVICE_BLUETOOTH) {
+               g_strlcpy(ProfilePtr->ProfileInfo.Bluetooth.net_info.ProfileName,
+                               obj_path, NET_PROFILE_NAME_LEN_MAX);
 
-                       Error = __net_extract_mesh_info(value, ProfilePtr);
-                       if (ProfilePtr->ProfileState == NET_STATE_TYPE_READY)
-                               break;
-               }
-       }
+               Error = __net_extract_bluetooth_info(iter, ProfilePtr);
+       } else if (device_type == NET_DEVICE_MESH) {
+               g_strlcpy(ProfilePtr->ProfileInfo.Mesh.net_info.ProfileName,
+                               obj_path, NET_PROFILE_NAME_LEN_MAX);
 
-       if (Error == NET_ERR_NONE &&
-                       (ProfilePtr->ProfileState == NET_STATE_TYPE_READY ||
-                                       ProfilePtr->ProfileState == NET_STATE_TYPE_ONLINE))
-               goto found;
-
-       NETWORK_LOG(NETWORK_ERROR, "Fail to find default service");
-       Error = NET_ERR_NO_SERVICE;
-
-error:
-       if (value)
-               g_variant_iter_free(value);
-       if (key)
-               g_free(key);
+               Error = __net_extract_mesh_info(iter, ProfilePtr);
+       }
 
-       __NETWORK_FUNC_EXIT__;
-       return Error;
+       if (Error != NET_ERR_NONE) {
+               g_variant_iter_free(iter);
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
 
-found:
        NETWORK_LOG(NETWORK_HIGH, "Default: %s", ProfilePtr->ProfileName);
 
-       if (value)
-               g_variant_iter_free(value);
-       if (key)
-               g_free(key);
+       g_variant_iter_free(iter);
+       g_free(obj_path);
 
        __NETWORK_FUNC_EXIT__;
        return Error;
@@ -3137,43 +3142,22 @@ int _net_get_default_profile_info(network_info_t *network_info,
 {
        net_err_t Error = NET_ERR_NONE;
        GVariant *message = NULL;
-       GVariantIter *iter = NULL;
 
        __NETWORK_FUNC_ENTER__;
 
        message = _net_invoke_dbus_method(network_info,
                        CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
-                       CONNMAN_MANAGER_INTERFACE, "GetServices", NULL, &Error);
+                       CONNMAN_MANAGER_INTERFACE, "GetDefaultService", NULL, &Error);
        if (message == NULL) {
                NETWORK_LOG(NETWORK_ERROR, "Failed to get profile list");
                __NETWORK_FUNC_EXIT__;
                return Error;
        }
 
-       g_variant_get(message, "(a(oa{sv}))", &iter);
-       Error = __net_extract_default_profile(network_info, iter, profile_info);
+       Error = __net_extract_default_profile(network_info, message, profile_info);
 
-       g_variant_iter_free(iter);
        g_variant_unref(message);
 
-       if (Error == NET_ERR_NO_SERVICE) {
-               message = _net_invoke_dbus_method(network_info,
-                                       CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
-                                       CONNMAN_MANAGER_INTERFACE, "GetMeshPeers", NULL, &Error);
-               if (message == NULL) {
-                       NETWORK_LOG(NETWORK_ERROR, "Failed to get mesh peers");
-                       Error = NET_ERR_NO_SERVICE;
-                       __NETWORK_FUNC_EXIT__;
-                       return Error;
-               }
-
-               g_variant_get(message, "(a(oa{sv}))", &iter);
-               Error = __net_extract_default_profile(network_info, iter, profile_info);
-
-               g_variant_iter_free(iter);
-               g_variant_unref(message);
-       }
-
        __NETWORK_FUNC_EXIT__;
        return Error;
 }
index 1cbef03..147b5d8 100755 (executable)
@@ -77,7 +77,6 @@ static net_wifi_state_t __net_get_wifi_connection_state(network_info_t *network_
 {
        __NETWORK_FUNC_ENTER__;
 
-       net_state_type_t service_state = NET_STATE_TYPE_UNKNOWN;
        net_wifi_state_t connection_state = WIFI_UNKNOWN;
        net_tech_info_t status;
 
@@ -87,34 +86,13 @@ static net_wifi_state_t __net_get_wifi_connection_state(network_info_t *network_
                return WIFI_UNKNOWN;
        }
 
-       service_state = _net_get_wifi_service_state(network_info);
-
        /* LCOV_EXCL_START */
        if (status.powered == FALSE)
                connection_state = WIFI_OFF;
        else if (status.connected == TRUE)
                connection_state = WIFI_CONNECTED;
-       else {
-               switch (service_state) {
-               case NET_STATE_TYPE_ASSOCIATION:
-                       connection_state = WIFI_ASSOCIATION;
-                       break;
-               case NET_STATE_TYPE_CONFIGURATION:
-                       connection_state = WIFI_CONFIGURATION;
-                       break;
-               case NET_STATE_TYPE_READY:
-               case NET_STATE_TYPE_ONLINE:
-                       connection_state = WIFI_CONNECTED;
-                       break;
-               case NET_STATE_TYPE_UNKNOWN:
-                       connection_state = WIFI_UNKNOWN;
-                       break;
-               case NET_STATE_TYPE_FAILURE:
-               case NET_STATE_TYPE_IDLE:
-               default:
-                       connection_state = WIFI_ON;
-               }
-       }
+       else
+               connection_state = WIFI_ON;
        /* LCOV_EXCL_STOP */
 
        if (connection_state == WIFI_CONNECTED &&
@@ -146,6 +124,39 @@ EXPORT_API int net_get_wifi_state(void *handle, net_wifi_state_t *current_state)
        return Error;
 }
 
+EXPORT_API int net_get_wifi_interface_list(void *handle, GSList **interface_list)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_t Error = NET_ERR_NONE;
+       GVariant *message;
+       GVariantIter *iter;
+       gchar *interface_name = NULL;
+       network_info_t *network_info = (network_info_t *)handle;
+
+       message = _net_invoke_dbus_method(network_info,
+                       CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
+                       CONNMAN_MANAGER_INTERFACE, "GetInterfaces",
+                       NULL, &Error);
+       if (message == NULL) {
+               NETWORK_LOG(NETWORK_ERROR, "Failed to get interface list"); //LCOV_EXCL_LINE
+               __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return Error; //LCOV_EXCL_LINE
+       }
+
+       g_variant_get(message, "(as)", &iter);
+       while (g_variant_iter_loop(iter, "s", &interface_name)) {
+               NETWORK_LOG(NETWORK_LOW, "interface name [%s]", interface_name);
+               *interface_list = g_slist_append(*interface_list, g_strdup(interface_name));
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return NET_ERR_NONE;
+}
+
 EXPORT_API int net_check_get_privilege(void)
 {
        net_err_t Error = NET_ERR_NONE;