Add multi interfaces function
[platform/core/api/connection.git] / src / connection_profile.c
index f9d4dea..cc38394 100755 (executable)
@@ -227,8 +227,30 @@ static void __profile_init_cellular_profile(net_profile_info_t *profile_info, co
        _connection_libnet_set_cellular_subscriber_id(profile, default_subscriber_id);
 }
 
-static void __profile_init_wifi_profile(net_profile_info_t *profile_info)
+static int __profile_init_wifi_profile(net_profile_info_t *profile_info)
 {
+       GSList *list = NULL;
+       GSList *interface_list = NULL;
+
+       if (net_get_wifi_interface_list(NULL, &interface_list) != NET_ERR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Fail to get interface list");
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       }
+
+       for (list = interface_list; list; list = list->next) {
+               const char *interface_name = list->data;
+               g_strlcpy(profile_info->ProfileName, interface_name, NET_PROFILE_NAME_LEN_MAX);
+               g_strlcpy(profile_info->ProfileInfo.Wlan.net_info.ProfileName,
+                               interface_name, NET_PROFILE_NAME_LEN_MAX);
+               break;
+       }
+
+       if (list == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Fail to get interface name");
+               g_slist_free_full(interface_list, g_free);
+               return CONNECTION_ERROR_INVALID_OPERATION;
+       }
+
        profile_info->profile_type = NET_DEVICE_WIFI;
        profile_info->ProfileState = NET_STATE_TYPE_IDLE;
        profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF;
@@ -236,10 +258,13 @@ static void __profile_init_wifi_profile(net_profile_info_t *profile_info)
        profile_info->ProfileInfo.Wlan.wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
        profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_NONE;
        profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_NONE;
+
+       g_slist_free_full(interface_list, g_free);
+       return CONNECTION_ERROR_NONE;
 }
 
 //LCOV_EXCL_START
-static char__profile_get_ethernet_proxy(void)
+static char *__profile_get_ethernet_proxy(void)
 {
        char *proxy;
 
@@ -419,7 +444,12 @@ EXPORT_API int connection_profile_create(connection_profile_type_e type, const c
                }
                __profile_init_cellular_profile(profile_info, keyword);
        } else if (type ==  CONNECTION_PROFILE_TYPE_WIFI) {
-               __profile_init_wifi_profile(profile_info);
+               rv = __profile_init_wifi_profile(profile_info);
+               if (rv != CONNECTION_ERROR_NONE) {
+                       g_free(profile_info);
+                       CONN_UNLOCK;
+                       return rv;
+               }
        }
 
        *profile = (connection_profile_h)profile_info;