[connection] Added Tizen Wi-Fi Mesh
[platform/core/api/connection.git] / src / libnetwork.c
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