Add multi interfaces function 87/242487/5
authorhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 27 Aug 2020 07:48:34 +0000 (16:48 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 31 Aug 2020 02:47:37 +0000 (11:47 +0900)
Change-Id: I57f3d5b46361a9383c1e25cd2c11b8ffaa6660f9
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
packaging/capi-network-connection.spec
src/connection.c
src/connection_profile.c

index fd19d28..3578120 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-connection
 Summary:       Network Connection library in TIZEN C API
-Version:       1.0.118
+Version:       1.0.119
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 8b9f3a7..ec38d92 100755 (executable)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <vconf/vconf.h>
 #include <system_info.h>
 
 #include "net_connection_private.h"
 
 static GSList *conn_handle_list = NULL;
-static int tv_profile = -1; // Unknown
 
 //LCOV_EXCL_START
 static int __connection_convert_net_state(int status)
@@ -169,16 +169,14 @@ EXPORT_API int connection_create(connection_h *connection)
        rv = _connection_libnet_init(*connection);
        if (rv == NET_ERR_ACCESS_DENIED) {
                CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
-               g_free(*connection);
-               *connection = NULL;
-
+               g_free(*connection); //LCOV_EXCL_LINE
+               *connection = NULL; //LCOV_EXCL_LINE
                CONN_UNLOCK; //LCOV_EXCL_LINE
                return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
        } else if (rv != NET_ERR_NONE) {
                CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv); //LCOV_EXCL_LINE
-               g_free(*connection);
-               *connection = NULL;
-
+               g_free(*connection); //LCOV_EXCL_LINE
+               *connection = NULL; //LCOV_EXCL_LINE
                CONN_UNLOCK; //LCOV_EXCL_LINE
                return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
@@ -350,7 +348,7 @@ EXPORT_API int connection_get_proxy(connection_h connection,
 
 EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr)
 {
-       FILE *fp;
+       FILE *fp = NULL;
        char buf[CONNECTION_MAC_INFO_LENGTH + 1];
 
        CONN_LOCK;
@@ -370,24 +368,10 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
 
        switch (type) {
        case CONNECTION_TYPE_WIFI:
-               if (__builtin_expect(tv_profile == -1, 0)) {
-                       char *profileName;
-                       system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
-                       if (*profileName == 't' || *profileName == 'T')
-                               tv_profile = 1; //LCOV_EXCL_LINE
-                       else
-                               tv_profile = 0;
-                       free(profileName);
-               }
-               if (tv_profile == 1) {
-                       //LCOV_EXCL_START
+               if (access(WIFI_MAC_INFO_FILE, F_OK) == 0)
                        fp = fopen(WIFI_MAC_INFO_FILE, "r");
-                       if (fp == NULL) {
-                               CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE);
-                               CONN_UNLOCK;
-                               return CONNECTION_ERROR_OUT_OF_MEMORY;
-                       }
 
+               if (fp) {
                        if (fgets(buf, sizeof(buf), fp) == NULL) {
                                CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE);
                                fclose(fp);
@@ -397,16 +381,8 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
 
                        CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf);
 
-                       *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
-                       if (*mac_addr == NULL) {
-                               CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
-                               fclose(fp);
-                               CONN_UNLOCK;
-                               return CONNECTION_ERROR_OUT_OF_MEMORY;
-                       }
-                       g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
+                       *mac_addr = g_strdup(buf);
                        fclose(fp);
-                       //LCOV_EXCL_STOP
                } else {
                        *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
 
@@ -415,6 +391,15 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
                                CONN_UNLOCK; //LCOV_EXCL_LINE
                                return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
                        }
+
+                       if (strlen(*mac_addr) == 0) {
+                               CONNECTION_LOG(CONNECTION_ERROR, "Mac address is invalid"
+                                       " from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
+                               g_free(*mac_addr); //LCOV_EXCL_LINE
+                               *mac_addr = NULL; //LCOV_EXCL_LINE
+                               CONN_UNLOCK; //LCOV_EXCL_LINE
+                               return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+                       }
                }
                break;
        //LCOV_EXCL_START
@@ -435,17 +420,8 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
 
                CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf);
 
-               *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1);
-               if (*mac_addr == NULL) {
-                       CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed");
-                       fclose(fp);
-                       CONN_UNLOCK;
-                       return CONNECTION_ERROR_OUT_OF_MEMORY;
-               }
-
-               g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1);
+               *mac_addr = g_strdup(buf);
                fclose(fp);
-
                break;
        //LCOV_EXCL_STOP
        default:
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;