From c6a514f8e5bf6cc133e30eb44bec0f1ace2fa7c8 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Thu, 9 Jul 2015 18:25:07 +0900 Subject: [PATCH 1/1] Add supported features check Signed-off-by: hyunuktak Change-Id: Ibab74436fc633c19b792ae95badb300455dd6326 --- CMakeLists.txt | 2 +- include/net_connection.h | 2 +- include/net_connection_private.h | 21 ++++--- packaging/capi-network-connection.spec | 3 +- src/connection.c | 93 +++++++++++++++++++++++++++ src/connection_profile.c | 112 +++++++++++++++++++++++++++++++-- src/libnetwork.c | 55 ++++++++-------- test/connection_test.c | 8 +-- 8 files changed, 247 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f615b8..8364e95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog vconf capi-base-common glib-2.0 network") +SET(dependents "dlog vconf capi-base-common glib-2.0 network capi-system-info") SET(pc_dependents "capi-base-common") INCLUDE(FindPkgConfig) diff --git a/include/net_connection.h b/include/net_connection.h index 5e3cd7c..9573027 100644 --- a/include/net_connection.h +++ b/include/net_connection.h @@ -840,7 +840,7 @@ int connection_remove_route(connection_h connection, const char* interface_name, */ int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway); - + /** * @brief Removes a IPV6 route from the routing table. * @details You can get the @a interface_name from connection_profile_get_network_interface_name() of opened profile. diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 7fd3134..041b304 100644 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -38,12 +38,10 @@ extern "C" { #define ETHERNET_MAC_INFO_FILE "/sys/class/net/eth0/address" #define WIFI_MAC_INFO_FILE "/sys/class/net/wlan0/address" -typedef enum -{ - FEATURE_TYPE_TELEPHONY = 0, - FEATURE_TYPE_WIFI = 1, - FEATURE_TYPE_TETHERING_BLUETOOTH = 2 -} enable_feature_type_e; +#define TELEPHONY_FEATURE "http://tizen.org/feature/network.telephony" +#define WIFI_FEATURE "http://tizen.org/feature/network.wifi" +#define TETHERING_BLUETOOTH_FEATURE "http://tizen.org/feature/network.tethering.bluetooth" +#define ETHERNET_FEATURE "http://tizen.org/feature/network.ethernet" typedef enum { @@ -51,6 +49,13 @@ typedef enum CONNECTION_CELLULAR_SUBSCRIBER_2 = 0x01, } connection_cellular_subscriber_id_e; +#define CHECK_FEATURE_SUPPORTED(...) \ + do { \ + int rv = _connection_check_feature_supported(__VA_ARGS__, NULL); \ + if( rv != CONNECTION_ERROR_NONE ) \ + return rv; \ + } while(0) + #define CONNECTION_LOG(log_level, format, args...) \ do { \ switch (log_level) { \ @@ -138,9 +143,7 @@ int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, uns int _connection_libnet_check_get_privilege(); int _connection_libnet_check_profile_privilege(); -bool _connection_libnet_get_is_check_enable_feature(); -bool _connection_libnet_get_enable_feature_state(enable_feature_type_e feature_type); -int _connection_libnet_check_enable_feature(); +int _connection_check_feature_supported(const char *feature_name, ...); guint _connection_callback_add(GSourceFunc func, gpointer user_data); void _connection_callback_cleanup(void); diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 5b07ac0..b0842ed 100644 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 0.1.3_26 +Version: 0.1.3_27 Release: 1 Group: System/Network License: Apache-2.0 @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(network) %description diff --git a/src/connection.c b/src/connection.c index 1156dab..8dbe36a 100644 --- a/src/connection.c +++ b/src/connection.c @@ -293,6 +293,8 @@ static int __connection_get_handle_count(void) /* Connection Manager ********************************************************/ EXPORT_API int connection_create(connection_h* connection) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + CONNECTION_MUTEX_LOCK; int rv; if (connection == NULL || __connection_check_handle_validity(*connection)) { @@ -329,6 +331,8 @@ EXPORT_API int connection_create(connection_h* connection) EXPORT_API int connection_destroy(connection_h connection) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + CONNECTION_MUTEX_LOCK; if (connection == NULL || !(__connection_check_handle_validity(connection))) { @@ -359,6 +363,8 @@ EXPORT_API int connection_get_type(connection_h connection, connection_type_e* t { int status = 0; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (type == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -379,6 +385,8 @@ EXPORT_API int connection_get_type(connection_h connection, connection_type_e* t EXPORT_API int connection_get_ip_address(connection_h connection, connection_address_family_e address_family, char **ip_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (ip_address == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -406,6 +414,8 @@ EXPORT_API int connection_get_ip_address(connection_h connection, EXPORT_API int connection_get_proxy(connection_h connection, connection_address_family_e address_family, char **proxy) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (proxy == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -435,6 +445,13 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty FILE *fp; char buf[CONNECTION_MAC_INFO_LENGTH + 1]; + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE); + + if(type == CONNECTION_TYPE_WIFI) + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + else if(type == CONNECTION_TYPE_ETHERNET) + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -513,6 +530,8 @@ EXPORT_API int connection_get_cellular_state(connection_h connection, connection int status = 0; int cellular_state = 0; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (state == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -546,6 +565,8 @@ EXPORT_API int connection_get_cellular_state(connection_h connection, connection EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + int rv; if (state == NULL || !(__connection_check_handle_validity(connection))) { @@ -566,6 +587,8 @@ EXPORT_API int connection_get_wifi_state(connection_h connection, connection_wif EXPORT_API int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state) { + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + if (state == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -576,6 +599,8 @@ EXPORT_API int connection_get_ethernet_state(connection_h connection, connection EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state) { + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + if (state == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -587,6 +612,8 @@ EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, conn EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection, connection_ethernet_cable_state_chaged_cb callback, void *user_data) { + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + if (callback == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -598,6 +625,8 @@ EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connec EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection) { + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + if ( !(__connection_check_handle_validity(connection)) ) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -609,6 +638,8 @@ EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h conn EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state) { + CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE); + if (state == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -621,6 +652,8 @@ EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_st EXPORT_API int connection_set_type_changed_cb(connection_h connection, connection_type_changed_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (callback == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -631,6 +664,8 @@ EXPORT_API int connection_set_type_changed_cb(connection_h connection, EXPORT_API int connection_unset_type_changed_cb(connection_h connection) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -642,6 +677,8 @@ EXPORT_API int connection_unset_type_changed_cb(connection_h connection) EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (callback == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -652,6 +689,8 @@ EXPORT_API int connection_set_ip_address_changed_cb(connection_h connection, EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -663,6 +702,8 @@ EXPORT_API int connection_unset_ip_address_changed_cb(connection_h connection) EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (callback == NULL || !(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -673,6 +714,8 @@ EXPORT_API int connection_set_proxy_address_changed_cb(connection_h connection, EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -683,6 +726,8 @@ EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h connection EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(__connection_check_handle_validity(connection)) || !(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -712,6 +757,8 @@ EXPORT_API int connection_add_profile(connection_h connection, connection_profil EXPORT_API int connection_remove_profile(connection_h connection, connection_profile_h profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + if (!(__connection_check_handle_validity(connection)) || !(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -741,6 +788,8 @@ EXPORT_API int connection_remove_profile(connection_h connection, connection_pro EXPORT_API int connection_update_profile(connection_h connection, connection_profile_h profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || !(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -765,6 +814,8 @@ EXPORT_API int connection_update_profile(connection_h connection, connection_pro EXPORT_API int connection_get_profile_iterator(connection_h connection, connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || (type != CONNECTION_ITERATOR_TYPE_REGISTERED && type != CONNECTION_ITERATOR_TYPE_CONNECTED && @@ -779,21 +830,29 @@ EXPORT_API int connection_get_profile_iterator(connection_h connection, EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator, connection_profile_h* profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + return _connection_libnet_get_iterator_next(profile_iterator, profile); } EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + return _connection_libnet_iterator_has_next(profile_iterator); } EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + return _connection_libnet_destroy_iterator(profile_iterator); } EXPORT_API int connection_get_current_profile(connection_h connection, connection_profile_h* profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -805,6 +864,8 @@ EXPORT_API int connection_get_current_profile(connection_h connection, connectio EXPORT_API int connection_get_default_cellular_service_profile(connection_h connection, connection_cellular_service_type_e type, connection_profile_h* profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -816,6 +877,8 @@ EXPORT_API int connection_get_default_cellular_service_profile(connection_h conn EXPORT_API int connection_set_default_cellular_service_profile(connection_h connection, connection_cellular_service_type_e type, connection_profile_h profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -828,6 +891,8 @@ EXPORT_API int connection_set_default_cellular_service_profile_async(connection_ connection_cellular_service_type_e type, connection_profile_h profile, connection_set_default_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(__connection_check_handle_validity(connection)) || profile == NULL || callback == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -840,6 +905,8 @@ EXPORT_API int connection_set_default_cellular_service_profile_async(connection_ EXPORT_API int connection_open_profile(connection_h connection, connection_profile_h profile, connection_opened_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE); + if (!(__connection_check_handle_validity(connection)) || profile == NULL || callback == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -852,6 +919,8 @@ EXPORT_API int connection_open_profile(connection_h connection, connection_profi EXPORT_API int connection_close_profile(connection_h connection, connection_profile_h profile, connection_closed_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE); + if (!(__connection_check_handle_validity(connection)) || profile == NULL || callback == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -864,6 +933,8 @@ EXPORT_API int connection_close_profile(connection_h connection, connection_prof EXPORT_API int connection_reset_profile(connection_h connection, connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -879,6 +950,8 @@ EXPORT_API int connection_reset_profile(connection_h connection, EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || interface_name == NULL || host_address == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -890,6 +963,8 @@ EXPORT_API int connection_add_route(connection_h connection, const char* interfa EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || interface_name == NULL || host_address == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); @@ -901,6 +976,8 @@ EXPORT_API int connection_remove_route(connection_h connection, const char* inte EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || interface_name == NULL || host_address == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); @@ -912,6 +989,8 @@ EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *in EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE); + if (!(__connection_check_handle_validity(connection)) || interface_name == NULL || host_address == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); @@ -1042,6 +1121,13 @@ EXPORT_API int connection_get_statistics(connection_h connection, connection_type_e connection_type, connection_statistics_type_e statistics_type, long long* size) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + + if(connection_type == CONNECTION_TYPE_CELLULAR ) + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + else if(connection_type == CONNECTION_TYPE_WIFI) + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(__connection_check_handle_validity(connection)) || size == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1054,6 +1140,13 @@ EXPORT_API int connection_reset_statistics(connection_h connection, connection_type_e connection_type, connection_statistics_type_e statistics_type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + + if(connection_type == CONNECTION_TYPE_CELLULAR ) + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + else if(connection_type == CONNECTION_TYPE_WIFI) + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(__connection_check_handle_validity(connection))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed"); return CONNECTION_ERROR_INVALID_PARAMETER; diff --git a/src/connection_profile.c b/src/connection_profile.c index c1c49e9..cdd4be7 100644 --- a/src/connection_profile.c +++ b/src/connection_profile.c @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ #include @@ -207,6 +207,13 @@ net_state_type_t _connection_profile_convert_to_net_state(connection_profile_sta /* Connection profile ********************************************************/ EXPORT_API int connection_profile_create(connection_profile_type_e type, const char* keyword, connection_profile_h* profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + + if(type == CONNECTION_PROFILE_TYPE_CELLULAR) + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + else if(type == CONNECTION_PROFILE_TYPE_WIFI) + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if ((type != CONNECTION_PROFILE_TYPE_CELLULAR && type != CONNECTION_PROFILE_TYPE_WIFI) || profile == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -241,6 +248,8 @@ EXPORT_API int connection_profile_create(connection_profile_type_e type, const c EXPORT_API int connection_profile_destroy(connection_profile_h profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -253,6 +262,8 @@ EXPORT_API int connection_profile_destroy(connection_profile_h profile) EXPORT_API int connection_profile_clone(connection_profile_h* cloned_profile, connection_profile_h origin_profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(origin_profile)) || cloned_profile == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -270,6 +281,8 @@ EXPORT_API int connection_profile_clone(connection_profile_h* cloned_profile, co EXPORT_API int connection_profile_get_id(connection_profile_h profile, char** profile_id) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || profile_id == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -292,6 +305,8 @@ EXPORT_API int connection_profile_get_id(connection_profile_h profile, char** pr EXPORT_API int connection_profile_get_name(connection_profile_h profile, char** profile_name) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || profile_name == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -329,6 +344,8 @@ EXPORT_API int connection_profile_get_name(connection_profile_h profile, char** EXPORT_API int connection_profile_get_type(connection_profile_h profile, connection_profile_type_e* type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -359,6 +376,8 @@ EXPORT_API int connection_profile_get_type(connection_profile_h profile, connect EXPORT_API int connection_profile_get_network_interface_name(connection_profile_h profile, char** interface_name) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || interface_name == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -379,6 +398,9 @@ EXPORT_API int connection_profile_get_network_interface_name(connection_profile_ EXPORT_API int connection_profile_refresh(connection_profile_h profile) { int rv; + + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -403,6 +425,8 @@ EXPORT_API int connection_profile_refresh(connection_profile_h profile) EXPORT_API int connection_profile_get_state(connection_profile_h profile, connection_profile_state_e* state) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || state == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -421,6 +445,8 @@ EXPORT_API int connection_profile_get_ip_config_type(connection_profile_h profil { net_ip_config_type_t profile_type; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -489,6 +515,8 @@ EXPORT_API int connection_profile_get_ip_config_type(connection_profile_h profil EXPORT_API int connection_profile_get_ip_address(connection_profile_h profile, connection_address_family_e address_family, char** ip_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -519,7 +547,9 @@ EXPORT_API int connection_profile_get_subnet_mask(connection_profile_h profile, connection_address_family_e address_family, char** subnet_mask) { char* prefixlen; - + + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -549,7 +579,9 @@ EXPORT_API int connection_profile_get_subnet_mask(connection_profile_h profile, EXPORT_API int connection_profile_get_gateway_address(connection_profile_h profile, connection_address_family_e address_family, char** gateway_address) -{ +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -579,6 +611,8 @@ EXPORT_API int connection_profile_get_gateway_address(connection_profile_h profi EXPORT_API int connection_profile_get_dns_address(connection_profile_h profile, int order, connection_address_family_e address_family, char** dns_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -611,6 +645,8 @@ EXPORT_API int connection_profile_get_dns_address(connection_profile_h profile, EXPORT_API int connection_profile_get_proxy_type(connection_profile_h profile, connection_proxy_type_e* type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -653,6 +689,8 @@ EXPORT_API int connection_profile_get_proxy_type(connection_profile_h profile, c EXPORT_API int connection_profile_get_proxy_address(connection_profile_h profile, connection_address_family_e address_family, char** proxy_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -679,6 +717,8 @@ EXPORT_API int connection_profile_set_ip_config_type(connection_profile_h profil { net_ip_config_type_t *profile_type = NULL; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { @@ -752,7 +792,9 @@ EXPORT_API int connection_profile_set_ip_config_type(connection_profile_h profil EXPORT_API int connection_profile_set_ip_address(connection_profile_h profile, connection_address_family_e address_family, const char* ip_address) -{ +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { @@ -784,7 +826,9 @@ EXPORT_API int connection_profile_set_ip_address(connection_profile_h profile, EXPORT_API int connection_profile_set_subnet_mask(connection_profile_h profile, connection_address_family_e address_family, const char* subnet_mask) -{ +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { @@ -815,6 +859,8 @@ EXPORT_API int connection_profile_set_subnet_mask(connection_profile_h profile, EXPORT_API int connection_profile_set_gateway_address(connection_profile_h profile, connection_address_family_e address_family, const char* gateway_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { @@ -845,6 +891,8 @@ EXPORT_API int connection_profile_set_gateway_address(connection_profile_h profi EXPORT_API int connection_profile_set_dns_address(connection_profile_h profile, int order, connection_address_family_e address_family, const char* dns_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -882,6 +930,8 @@ EXPORT_API int connection_profile_set_dns_address(connection_profile_h profile, EXPORT_API int connection_profile_set_proxy_type(connection_profile_h profile, connection_proxy_type_e type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -912,6 +962,8 @@ EXPORT_API int connection_profile_set_proxy_type(connection_profile_h profile, c EXPORT_API int connection_profile_set_proxy_address(connection_profile_h profile, connection_address_family_e address_family, const char* proxy_address) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { @@ -935,6 +987,8 @@ EXPORT_API int connection_profile_set_proxy_address(connection_profile_h profile EXPORT_API int connection_profile_set_state_changed_cb(connection_profile_h profile, connection_profile_state_changed_cb callback, void* user_data) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || callback == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -948,6 +1002,8 @@ EXPORT_API int connection_profile_set_state_changed_cb(connection_profile_h prof EXPORT_API int connection_profile_unset_state_changed_cb(connection_profile_h profile) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_cb_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -963,6 +1019,8 @@ EXPORT_API int connection_profile_unset_state_changed_cb(connection_profile_h pr /* Wi-Fi profile *************************************************************/ EXPORT_API int connection_profile_get_wifi_essid(connection_profile_h profile, char** essid) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || essid == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -982,6 +1040,8 @@ EXPORT_API int connection_profile_get_wifi_essid(connection_profile_h profile, c EXPORT_API int connection_profile_get_wifi_bssid(connection_profile_h profile, char** bssid) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || bssid == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1001,6 +1061,8 @@ EXPORT_API int connection_profile_get_wifi_bssid(connection_profile_h profile, c EXPORT_API int connection_profile_get_wifi_rssi(connection_profile_h profile, int* rssi) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || rssi == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1018,6 +1080,8 @@ EXPORT_API int connection_profile_get_wifi_rssi(connection_profile_h profile, in EXPORT_API int connection_profile_get_wifi_frequency(connection_profile_h profile, int* frequency) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || frequency == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1035,6 +1099,8 @@ EXPORT_API int connection_profile_get_wifi_frequency(connection_profile_h profil EXPORT_API int connection_profile_get_wifi_max_speed(connection_profile_h profile, int* max_speed) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || max_speed == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1052,6 +1118,8 @@ EXPORT_API int connection_profile_get_wifi_max_speed(connection_profile_h profil EXPORT_API int connection_profile_get_wifi_security_type(connection_profile_h profile, connection_wifi_security_type_e* type) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1087,6 +1155,8 @@ EXPORT_API int connection_profile_get_wifi_security_type(connection_profile_h pr EXPORT_API int connection_profile_get_wifi_encryption_type(connection_profile_h profile, connection_wifi_encryption_type_e* type) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1122,6 +1192,8 @@ EXPORT_API int connection_profile_get_wifi_encryption_type(connection_profile_h EXPORT_API int connection_profile_is_wifi_passphrase_required(connection_profile_h profile, bool* required) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || required == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1156,6 +1228,8 @@ EXPORT_API int connection_profile_is_wifi_passphrase_required(connection_profile EXPORT_API int connection_profile_set_wifi_passphrase(connection_profile_h profile, const char* passphrase) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || passphrase == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1174,6 +1248,8 @@ EXPORT_API int connection_profile_set_wifi_passphrase(connection_profile_h profi EXPORT_API int connection_profile_is_wifi_wps_supported(connection_profile_h profile, bool* supported) { + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || supported == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1196,6 +1272,8 @@ EXPORT_API int connection_profile_is_wifi_wps_supported(connection_profile_h pro /* Cellular profile **********************************************************/ EXPORT_API int connection_profile_get_cellular_network_type(connection_profile_h profile, connection_cellular_network_type_e* type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1237,6 +1315,8 @@ EXPORT_API int connection_profile_get_cellular_network_type(connection_profile_h EXPORT_API int connection_profile_get_cellular_service_type(connection_profile_h profile, connection_cellular_service_type_e* type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1261,6 +1341,8 @@ EXPORT_API int connection_profile_get_cellular_service_type(connection_profile_h EXPORT_API int connection_profile_get_cellular_apn(connection_profile_h profile, char** apn) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || apn == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1281,6 +1363,8 @@ EXPORT_API int connection_profile_get_cellular_apn(connection_profile_h profile, EXPORT_API int connection_profile_get_cellular_auth_info(connection_profile_h profile, connection_cellular_auth_type_e* type, char** user_name, char** password) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL || user_name == NULL || password == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -1321,6 +1405,8 @@ EXPORT_API int connection_profile_get_cellular_auth_info(connection_profile_h pr EXPORT_API int connection_profile_get_cellular_home_url(connection_profile_h profile, char** home_url) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || home_url == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1340,6 +1426,8 @@ EXPORT_API int connection_profile_get_cellular_home_url(connection_profile_h pro EXPORT_API int connection_profile_is_cellular_roaming(connection_profile_h profile, bool* is_roaming) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || is_roaming == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1360,6 +1448,8 @@ EXPORT_API int connection_profile_is_cellular_roaming(connection_profile_h profi EXPORT_API int connection_profile_is_cellular_hidden(connection_profile_h profile, bool* is_hidden) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || is_hidden == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1382,6 +1472,8 @@ EXPORT_API int connection_profile_is_cellular_hidden(connection_profile_h profil EXPORT_API int connection_profile_is_cellular_editable(connection_profile_h profile, bool* is_editable) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || is_editable == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1404,6 +1496,8 @@ EXPORT_API int connection_profile_is_cellular_editable(connection_profile_h prof EXPORT_API int connection_profile_is_cellular_default(connection_profile_h profile, bool* is_default) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || is_default == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1427,6 +1521,8 @@ EXPORT_API int connection_profile_is_cellular_default(connection_profile_h profi EXPORT_API int connection_profile_set_cellular_service_type(connection_profile_h profile, connection_cellular_service_type_e service_type) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile))) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1466,6 +1562,8 @@ EXPORT_API int connection_profile_set_cellular_service_type(connection_profile_h EXPORT_API int connection_profile_set_cellular_apn(connection_profile_h profile, const char* apn) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || apn == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; @@ -1484,6 +1582,8 @@ EXPORT_API int connection_profile_set_cellular_apn(connection_profile_h profile, EXPORT_API int connection_profile_set_cellular_auth_info(connection_profile_h profile, connection_cellular_auth_type_e type, const char* user_name, const char* password) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || user_name == NULL || password == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); @@ -1517,6 +1617,8 @@ EXPORT_API int connection_profile_set_cellular_auth_info(connection_profile_h pr EXPORT_API int connection_profile_set_cellular_home_url(connection_profile_h profile, const char* home_url) { + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || home_url == NULL) { CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; diff --git a/src/libnetwork.c b/src/libnetwork.c index 2d61e3e..82c747d 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -11,13 +11,14 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ #include #include #include #include +#include #include #include "net_connection_private.h" @@ -57,17 +58,9 @@ struct managed_idle_data { guint id; }; -struct feature_type { - bool telephony; - bool wifi; - bool tethering_bluetooth; -}; - static struct _profile_list_s profile_iterator = {0, 0, NULL}; static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false}; static __thread GSList *managed_idler_list = NULL; -static __thread bool is_check_enable_feature = false; -static __thread struct feature_type enable_feature = {false, false, false}; bool _connection_is_created(void) { @@ -1281,26 +1274,32 @@ int _connection_libnet_check_profile_privilege() return CONNECTION_ERROR_NONE; } -bool _connection_libnet_get_is_check_enable_feature() -{ - return is_check_enable_feature; -} - -bool _connection_libnet_get_enable_feature_state(enable_feature_type_e feature_type) +int _connection_check_feature_supported(const char *feature_name, ...) { - if(is_check_enable_feature){ - switch(feature_type) { - case FEATURE_TYPE_TELEPHONY: - return enable_feature.telephony; - case FEATURE_TYPE_WIFI: - return enable_feature.wifi; - case FEATURE_TYPE_TETHERING_BLUETOOTH: - return enable_feature.tethering_bluetooth; - default: - CONNECTION_LOG(CONNECTION_ERROR, "Invalid feature type"); - return false; + va_list list; + const char *key; + bool value, feature_supported = false; + + va_start(list, feature_name); + key = feature_name; + while(1) { + if(system_info_get_platform_bool(key, &value) < 0) { + CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); + set_last_result(CONNECTION_ERROR_OPERATION_FAILED); + return CONNECTION_ERROR_OPERATION_FAILED; } + SECURE_CONNECTION_LOG(CONNECTION_INFO, "%s feature is %s", key, (value?"true":"false")); + feature_supported |= value; + key = va_arg(list, const char *); + if (!key) break; } - CONNECTION_LOG(CONNECTION_ERROR, "Not checked enable feature yet"); - return false; + if (!feature_supported) { + CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature is not supported"); + set_last_result(CONNECTION_ERROR_NOT_SUPPORTED); + return CONNECTION_ERROR_NOT_SUPPORTED; + } + va_end(list); + + set_last_result(CONNECTION_ERROR_NONE); + return CONNECTION_ERROR_NONE; } diff --git a/test/connection_test.c b/test/connection_test.c index f37c43f..dbe83c9 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ #include @@ -1704,12 +1704,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) { int rv = 0; char a[100]; - + memset(a, '\0', 100); printf("Event received from stdin\n"); - + rv = read(0, a, 100); - + if (rv < 0 || a[0] == '0') { if (connection != NULL) test_deregister_client(); -- 2.7.4