[connection] Added Tizen Wi-Fi Mesh 77/186777/1 submit/tizen/20180824.072908
authorNishant Chaprana <n.chaprana@samsung.com>
Tue, 14 Aug 2018 07:35:05 +0000 (13:05 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Tue, 14 Aug 2018 07:35:05 +0000 (13:05 +0530)
Change-Id: I0d4d9c44abc60609a1104b877b31f3b7fe912451
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/connection_extension.h
packaging/capi-network-connection.spec
src/connection.c
src/connection_profile.c
src/libnetwork.c
test/connection_test.c

index 3f0457f..5aa1b2b 100755 (executable)
@@ -29,6 +29,22 @@ extern "C" {
  */
 
 /**
+ * @brief Enumeration for extended network connection type.
+ * @since_tizen 5.0
+ */
+typedef enum {
+       CONNECTION_PROFILE_TYPE_MESH = CONNECTION_PROFILE_TYPE_BT + 1,  /**< Wi-Fi Mesh type */
+} connection_profile_type_extended_e;
+
+/**
+ * @brief Enumeration for extended security type of Wi-Fi.
+ * @since_tizen 5.0
+ */
+typedef enum {
+       CONNECTION_WIFI_SECURITY_TYPE_SAE = CONNECTION_WIFI_SECURITY_TYPE_EAP + 1,  /**< SAE */
+} connection_wifi_security_type_extended_e;
+
+/**
  * @brief Start TCP Dump.
  *
  * @param[in] connection        The connection handle
index dee1b74..fcfe520 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-connection
 Summary:       Network Connection library in TIZEN C API
-Version:       1.0.111
+Version:       1.0.112
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 51261f8..64ccf56 100755 (executable)
@@ -969,6 +969,7 @@ EXPORT_API int connection_remove_profile(connection_h connection, connection_pro
        }
 
        if (profile_info->profile_type != NET_DEVICE_CELLULAR &&
+               profile_info->profile_type != NET_DEVICE_MESH &&
            profile_info->profile_type != NET_DEVICE_WIFI) {
                CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
                return CONNECTION_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
index d5e3bd8..6cbb3a2 100755 (executable)
@@ -22,6 +22,7 @@
 #include <vconf/vconf.h>
 
 #include "net_connection_private.h"
+#include "connection_extension.h"
 
 #define HTTP_PROXY "http_proxy"
 #define MAX_PREFIX_LENGTH 6
@@ -37,6 +38,8 @@ static net_dev_info_t* __profile_get_net_info(net_profile_info_t *profile_info)
                return &profile_info->ProfileInfo.Ethernet.net_info; //LCOV_EXCL_LINE
        case NET_DEVICE_BLUETOOTH:
                return &profile_info->ProfileInfo.Bluetooth.net_info;
+       case NET_DEVICE_MESH:
+               return &profile_info->ProfileInfo.Mesh.net_info;
        case NET_DEVICE_DEFAULT:
        case NET_DEVICE_USB:
        case NET_DEVICE_UNKNOWN:
@@ -372,6 +375,9 @@ EXPORT_API int connection_profile_get_name(connection_profile_h profile, char**
                bt_name++;
                *profile_name = g_strdup(bt_name);
        } break;
+       case NET_DEVICE_MESH:
+               *profile_name = g_strdup(profile_info->ProfileInfo.Mesh.essid);
+               break;
        default:
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
@@ -406,6 +412,9 @@ EXPORT_API int connection_profile_get_type(connection_profile_h profile, connect
        case NET_DEVICE_BLUETOOTH:
                *type = CONNECTION_PROFILE_TYPE_BT;
                break;
+       case NET_DEVICE_MESH:
+               *type = CONNECTION_PROFILE_TYPE_MESH;
+               break;
        default:
                CONNECTION_LOG(CONNECTION_ERROR, "Invalid profile type");
                return CONNECTION_ERROR_OPERATION_FAILED;
@@ -1161,10 +1170,15 @@ EXPORT_API int connection_profile_get_wifi_essid(connection_profile_h profile, c
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       *essid = g_strdup(profile_info->ProfileInfo.Wlan.essid);
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               *essid = g_strdup(profile_info->ProfileInfo.Wlan.essid);
+       else
+               *essid = g_strdup(profile_info->ProfileInfo.Mesh.essid);
+
        if (*essid == NULL)
                return CONNECTION_ERROR_OUT_OF_MEMORY;
 
@@ -1182,10 +1196,15 @@ EXPORT_API int connection_profile_get_wifi_bssid(connection_profile_h profile, c
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       *bssid = g_strdup(profile_info->ProfileInfo.Wlan.bssid);
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               *bssid = g_strdup(profile_info->ProfileInfo.Wlan.bssid);
+       else
+               *bssid = g_strdup(profile_info->ProfileInfo.Mesh.bssid);
+
        if (*bssid == NULL)
                return CONNECTION_ERROR_OUT_OF_MEMORY;
 
@@ -1203,10 +1222,15 @@ EXPORT_API int connection_profile_get_wifi_rssi(connection_profile_h profile, in
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       *rssi = (int)profile_info->ProfileInfo.Wlan.Strength;
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               *rssi = (int)profile_info->ProfileInfo.Wlan.Strength;
+       else
+               *rssi = (int)profile_info->ProfileInfo.Mesh.Strength;
+
 
        return CONNECTION_ERROR_NONE;
 }
@@ -1222,10 +1246,15 @@ EXPORT_API int connection_profile_get_wifi_frequency(connection_profile_h profil
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       *frequency = (int)profile_info->ProfileInfo.Wlan.frequency;
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               *frequency = (int)profile_info->ProfileInfo.Wlan.frequency;
+       else
+               *frequency = (int)profile_info->ProfileInfo.Mesh.frequency;
+
 
        return CONNECTION_ERROR_NONE;
 }
@@ -1260,10 +1289,17 @@ EXPORT_API int connection_profile_get_wifi_security_type(connection_profile_h pr
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       wlan_security_mode_type_t sec_mode;
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       switch (profile_info->ProfileInfo.Wlan.security_info.sec_mode) {
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               sec_mode = profile_info->ProfileInfo.Wlan.security_info.sec_mode;
+       else
+               sec_mode = profile_info->ProfileInfo.Mesh.security_info.sec_mode;
+
+       switch (sec_mode) {
        //LCOV_EXCL_START
        case WLAN_SEC_MODE_NONE:
                *type = CONNECTION_WIFI_SECURITY_TYPE_NONE;
@@ -1280,6 +1316,9 @@ EXPORT_API int connection_profile_get_wifi_security_type(connection_profile_h pr
        case WLAN_SEC_MODE_WPA2_PSK:
                *type = CONNECTION_WIFI_SECURITY_TYPE_WPA2_PSK;
                break;
+       case WLAN_SEC_MODE_SAE:
+               *type = CONNECTION_WIFI_SECURITY_TYPE_SAE;
+               break;
        default:
                return CONNECTION_ERROR_OPERATION_FAILED;
        //LCOV_EXCL_STOP
@@ -1338,7 +1377,9 @@ EXPORT_API int connection_profile_is_wifi_passphrase_required(connection_profile
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       wlan_security_mode_type_t sec_mode;
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
        if (profile_info->Favourite) {
@@ -1346,7 +1387,12 @@ EXPORT_API int connection_profile_is_wifi_passphrase_required(connection_profile
                return CONNECTION_ERROR_NONE;
        }
 
-       switch (profile_info->ProfileInfo.Wlan.security_info.sec_mode) {
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               sec_mode = profile_info->ProfileInfo.Wlan.security_info.sec_mode;
+       else
+               sec_mode = profile_info->ProfileInfo.Mesh.security_info.sec_mode;
+
+       switch (sec_mode) {
        //LCOV_EXCL_START
        case WLAN_SEC_MODE_NONE:
                *required = false;
@@ -1355,6 +1401,7 @@ EXPORT_API int connection_profile_is_wifi_passphrase_required(connection_profile
        case WLAN_SEC_MODE_IEEE8021X:
        case WLAN_SEC_MODE_WPA_PSK:
        case WLAN_SEC_MODE_WPA2_PSK:
+       case WLAN_SEC_MODE_SAE:
                *required = true;
                break;
        default:
@@ -1376,11 +1423,16 @@ EXPORT_API int connection_profile_set_wifi_passphrase(connection_profile_h profi
 
        net_profile_info_t *profile_info = profile;
 
-       if (profile_info->profile_type != NET_DEVICE_WIFI)
+       if (profile_info->profile_type != NET_DEVICE_WIFI &&
+                               profile_info->profile_type != NET_DEVICE_MESH)
                return CONNECTION_ERROR_INVALID_PARAMETER;
 
-       g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.psk.pskKey,
-                                               passphrase, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN);
+       if (profile_info->profile_type == NET_DEVICE_WIFI)
+               g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.psk.pskKey,
+                                 passphrase, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN);
+       else
+               g_strlcpy(profile_info->ProfileInfo.Mesh.security_info.authentication.sae.saeKey,
+                                 passphrase, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN);
 
        return CONNECTION_ERROR_NONE;
 }
index 878d423..1b43bea 100755 (executable)
@@ -848,13 +848,14 @@ done:
 int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h)
 {
        int count = 0;
-       int rv1, rv2, rv3, rv4;
+       int rv1, rv2, rv3, rv4, rv5;
        net_profile_info_t *profiles = NULL;
 
        struct _profile_list_s wifi_profiles = {0, 0, NULL};
        struct _profile_list_s cellular_profiles = {0, 0, NULL};
        struct _profile_list_s ethernet_profiles = {0, 0, NULL};
        struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
+       struct _profile_list_s mesh_profiles = {0, 0, NULL};
 
        __libnet_clear_profile_list(&profile_iterator);
 
@@ -906,11 +907,22 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
        }
        CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d", bluetooth_profiles.count);
 
+       rv5 = net_get_profile_list(NET_DEVICE_MESH, &mesh_profiles.profiles, &mesh_profiles.count);
+       if (rv5 == NET_ERR_ACCESS_DENIED) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
+               __libnet_clear_profile_list(&wifi_profiles);
+               return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+       } else if (rv5 != NET_ERR_NO_SERVICE && rv5 != NET_ERR_NONE) {
+               __libnet_clear_profile_list(&wifi_profiles);
+               return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+       }
+
+       CONNECTION_LOG(CONNECTION_INFO, "Mesh profile count: %d", mesh_profiles.count);
        *profile_iter_h = &profile_iterator;
 
        switch (type) {
        case CONNECTION_ITERATOR_TYPE_REGISTERED:
-               count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count;
+               count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count + bluetooth_profiles.count + mesh_profiles.count;
                CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d", count);
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
@@ -921,6 +933,7 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                        __libnet_clear_profile_list(&cellular_profiles);
                        __libnet_clear_profile_list(&ethernet_profiles);
                        __libnet_clear_profile_list(&bluetooth_profiles);
+                       __libnet_clear_profile_list(&mesh_profiles);
                        return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
@@ -944,6 +957,12 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                        profiles += ethernet_profiles.count;
                }
 
+               if (mesh_profiles.count > 0) {
+                       memcpy(profiles, mesh_profiles.profiles,
+                                       sizeof(net_profile_info_t) * mesh_profiles.count);
+                       profiles += mesh_profiles.count;
+               }
+
                if (bluetooth_profiles.count > 0)
                        memcpy(profiles, bluetooth_profiles.profiles,
                                        sizeof(net_profile_info_t) * bluetooth_profiles.count);
@@ -954,6 +973,7 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                count += __libnet_get_connected_count(&cellular_profiles);
                count += __libnet_get_connected_count(&ethernet_profiles);
                count += __libnet_get_connected_count(&bluetooth_profiles);
+               count += __libnet_get_connected_count(&mesh_profiles);
                CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d", count);
                if (count == 0)
                        return CONNECTION_ERROR_NONE;
@@ -964,6 +984,7 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                        __libnet_clear_profile_list(&cellular_profiles);
                        __libnet_clear_profile_list(&ethernet_profiles);
                        __libnet_clear_profile_list(&bluetooth_profiles);
+                       __libnet_clear_profile_list(&mesh_profiles);
                        return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
@@ -981,6 +1002,9 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                if (bluetooth_profiles.count > 0)
                        __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
 
+               if (mesh_profiles.count > 0)
+                       __libnet_copy_connected_profile(&profiles, &mesh_profiles);
+
                break;
        case CONNECTION_ITERATOR_TYPE_DEFAULT:
                count = __libnet_get_default_count(&cellular_profiles);
@@ -994,6 +1018,7 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
                        __libnet_clear_profile_list(&cellular_profiles);
                        __libnet_clear_profile_list(&ethernet_profiles);
                        __libnet_clear_profile_list(&bluetooth_profiles);
+                       __libnet_clear_profile_list(&mesh_profiles);
                        return CONNECTION_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
                }
 
@@ -1008,6 +1033,7 @@ int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, con
        __libnet_clear_profile_list(&cellular_profiles);
        __libnet_clear_profile_list(&ethernet_profiles);
        __libnet_clear_profile_list(&bluetooth_profiles);
+       __libnet_clear_profile_list(&mesh_profiles);
 
        profile_iterator.count = count;
 
@@ -1104,7 +1130,11 @@ int _connection_libnet_open_profile(connection_profile_h profile,
 
        net_profile_info_t *profile_info = profile;
 
-       rv = net_open_connection_with_profile(profile_info->ProfileName);
+       if (profile_info->profile_type == NET_DEVICE_MESH)
+               rv = net_open_mesh_connection_with_profile(profile_info->ProfileName);
+       else
+               rv = net_open_connection_with_profile(profile_info->ProfileName);
+
        if (rv == NET_ERR_ACCESS_DENIED) {
                CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
                return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
@@ -1269,7 +1299,11 @@ int _connection_libnet_close_profile(connection_profile_h profile, connection_cl
 
        net_profile_info_t *profile_info = profile;
 
-       rv = net_close_connection(profile_info->ProfileName);
+       if (profile_info->profile_type == NET_DEVICE_MESH)
+               rv = net_close_mesh_connection(profile_info->ProfileName);
+       else
+               rv = net_close_connection(profile_info->ProfileName);
+
        if (rv == NET_ERR_ACCESS_DENIED) {
                CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
                return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
index 4a63bac..80d4c96 100755 (executable)
@@ -858,6 +858,50 @@ static void test_print_wifi_info(connection_profile_h profile)
                printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
 }
 
+static void test_print_mesh_info(connection_profile_h profile)
+{
+       char *essid = NULL;
+       char *bssid = NULL;
+       int rssi = 0;
+       int frequency = 0;
+       connection_wifi_security_type_e security_type;
+       bool pass_required = false;
+
+       if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh essid!\n");
+       else {
+               printf("Mesh essid : %s\n", essid);
+               g_free(essid);
+       }
+
+       if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh bssid!\n");
+       else {
+               printf("Mesh bssid : %s\n", bssid);
+               g_free(bssid);
+       }
+
+       if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh rssi!\n");
+       else
+               printf("Mesh rssi : %d\n", rssi);
+
+       if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh frequency!\n");
+       else
+               printf("Mesh frequency : %d\n", frequency);
+
+       if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh security type!\n");
+       else
+               printf("Mesh security type : %d\n", security_type);
+
+       if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
+               printf("Fail to get Mesh passphrase required!\n");
+       else
+               printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
+}
+
 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
 {
        char *interface_name = NULL;
@@ -1555,12 +1599,20 @@ int test_update_profile(void)
        case CONNECTION_PROFILE_TYPE_ETHERNET:
                if (test_update_network_info(profile) == -1)
                        return -1;
-               break;
 
+               break;
        case CONNECTION_PROFILE_TYPE_BT:
                printf("Not supported!\n");
                /* fall through */
        default:
+               {
+                       int profile_type = prof_type;
+                       if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
+                               if (test_update_wifi_info(profile) == -1)
+                                       return -1;
+                               break;
+                       }
+               }
                return -1;
        }
 
@@ -1626,6 +1678,14 @@ int test_get_profile_info(void)
                printf("Profile Type : Bluetooth\n");
                break;
        default:
+               {
+                       int profile_type = prof_type;
+                       if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
+                               printf("Profile Type : Mesh\n");
+                               test_print_mesh_info(profile);
+                               break;
+                       }
+               }
                return -1;
        }
 
@@ -1685,6 +1745,14 @@ int test_refresh_profile_info(void)
                printf("Profile Type : Bluetooth\n");
                break;
        default:
+               {
+                       int profile_type = prof_type;
+                       if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
+                               printf("Profile Type : Mesh\n");
+                               test_print_mesh_info(profile);
+                               break;
+                       }
+               }
                return -1;
        }