static bool __connection_check_handle_validity(connection_h connection)
{
- GSList *list;
+ bool ret = false;
+
+ if (connection == NULL)
+ return false;
- for (list = conn_handle_list; list; list = list->next)
- if (connection == list->data) return true;
+ if (g_slist_find(conn_handle_list, connection) != NULL)
+ ret = true;
- return false;
+ return ret;
}
static int __connection_get_handle_count(void)
EXPORT_API int connection_create(connection_h* connection)
{
CONNECTION_MUTEX_LOCK;
-
+ int rv;
if (connection == NULL || __connection_check_handle_validity(*connection)) {
CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
CONNECTION_MUTEX_UNLOCK;
return CONNECTION_ERROR_INVALID_PARAMETER;
}
- if (_connection_libnet_init() == false) {
- CONNECTION_LOG(CONNECTION_ERROR, "Creation failed!\n");
- CONNECTION_MUTEX_UNLOCK;
+ rv = _connection_libnet_init();
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ }
+ else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to create connection[%d]", rv);
return CONNECTION_ERROR_OPERATION_FAILED;
}
- CONNECTION_LOG(CONNECTION_ERROR, "Connection successfully created!\n");
-
*connection = g_try_malloc0(sizeof(connection_handle_s));
if (*connection != NULL) {
CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection);
}
rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile);
- if (rv != NET_ERR_NONE) {
- CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
return CONNECTION_ERROR_OPERATION_FAILED;
}
}
rv = net_delete_profile(profile_info->ProfileName);
- if (rv != NET_ERR_NONE) {
- CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to delete profile[%d]", rv);
return CONNECTION_ERROR_OPERATION_FAILED;
}
net_profile_info_t *profile_info = profile;
rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile);
- if (rv != NET_ERR_NONE) {
- CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to modify profile[%d]", rv);
return CONNECTION_ERROR_OPERATION_FAILED;
}
{
if (!(__connection_check_handle_validity(connection)) ||
(type != CONNECTION_ITERATOR_TYPE_REGISTERED &&
- type != CONNECTION_ITERATOR_TYPE_CONNECTED)) {
- CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
+ type != CONNECTION_ITERATOR_TYPE_CONNECTED &&
+ type != CONNECTION_ITERATOR_TYPE_DEFAULT)) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
return CONNECTION_ERROR_INVALID_PARAMETER;
}
return _connection_libnet_close_profile(profile, callback, user_data);
}
+EXPORT_API int connection_reset_profile(connection_h connection,
+ connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data)
+{
+ if (!(__connection_check_handle_validity(connection))) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if(id < 0 || id > 1) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return _connection_libnet_reset_profile(type, id, callback, user_data);
+}
+
EXPORT_API int connection_add_route(connection_h connection, const char* interface_name, const char* host_address)
{
if (!(__connection_check_handle_validity(connection)) ||
return _connection_libnet_add_route(interface_name, host_address);
}
+EXPORT_API int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address)
+{
+ if (!(__connection_check_handle_validity(connection)) ||
+ interface_name == NULL || host_address == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return _connection_libnet_remove_route(interface_name, host_address);
+}
/* Connection Statistics module ******************************************************************/
static int __get_statistic(connection_type_e connection_type,
connection_statistics_type_e statistics_type, long long* llsize)
{
- int size;
+ int rv, size;
unsigned long long ull_size;
int stat_type;
char *key = NULL;
return CONNECTION_ERROR_INVALID_PARAMETER;
}
- if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) {
- CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size);
+ rv = _connection_libnet_get_statistics(stat_type, &ull_size);
+ if (rv == CONNECTION_ERROR_PERMISSION_DENIED)
+ return rv;
+ else if (rv != CONNECTION_ERROR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi statistics");
*llsize = 0;
return CONNECTION_ERROR_OPERATION_FAILED;
}
connection_type_e connection_type,
connection_statistics_type_e statistics_type, long long* size)
{
+ if (!(__connection_check_handle_validity(connection)) || size == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
return __get_statistic(connection_type, statistics_type, size);
}
connection_type_e connection_type,
connection_statistics_type_e statistics_type)
{
+ if (!(__connection_check_handle_validity(connection))) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
return __reset_statistic(connection_type, statistics_type);
}
static void __profile_init_cellular_profile(net_profile_info_t *profile_info, const char *keyword)
{
+ int default_subscriber_id = 0;
+ connection_profile_h profile = NULL;
+
profile_info->profile_type = NET_DEVICE_CELLULAR;
profile_info->ProfileState = NET_STATE_TYPE_IDLE;
profile_info->ProfileInfo.Pdp.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF;
profile_info->ProfileInfo.Pdp.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT;
g_strlcpy(profile_info->ProfileInfo.Pdp.Keyword, keyword, NET_PDP_APN_LEN_MAX);
+
+ if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
+ &default_subscriber_id) != 0)
+ CONNECTION_LOG(CONNECTION_ERROR,
+ "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
+
+ profile = (connection_profile_h)profile_info;
+ _connection_libnet_set_cellular_subscriber_id(profile, default_subscriber_id);
}
static void __profile_init_wifi_profile(net_profile_info_t *profile_info)
EXPORT_API int connection_profile_refresh(connection_profile_h profile)
{
+ int rv;
if (!(_connection_libnet_check_profile_validity(profile))) {
CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
return CONNECTION_ERROR_INVALID_PARAMETER;
net_profile_info_t profile_info_local;
net_profile_info_t *profile_info = profile;
- if (net_get_profile_info(profile_info->ProfileName, &profile_info_local) != NET_ERR_NONE) {
- CONNECTION_LOG(CONNECTION_ERROR, "Error!!! net_get_profile_info() failed\n");
+ rv = net_get_profile_info(profile_info->ProfileName, &profile_info_local);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile information");
return CONNECTION_ERROR_OPERATION_FAILED;
}
return CONNECTION_ERROR_NONE;
}
+EXPORT_API int connection_profile_is_cellular_hidden(connection_profile_h profile, bool* is_hidden)
+{
+ if (!(_connection_libnet_check_profile_validity(profile)) || is_hidden == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ net_profile_info_t *profile_info = profile;
+
+ if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (profile_info->ProfileInfo.Pdp.Hidden)
+ *is_hidden = true;
+ else
+ *is_hidden = false;
+
+ return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_is_cellular_editable(connection_profile_h profile, bool* is_editable)
+{
+ if (!(_connection_libnet_check_profile_validity(profile)) || is_editable == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ net_profile_info_t *profile_info = profile;
+
+ if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (profile_info->ProfileInfo.Pdp.Editable)
+ *is_editable = true;
+ else
+ *is_editable = false;
+
+ return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_is_cellular_default(connection_profile_h profile, bool* is_default)
+{
+ if (!(_connection_libnet_check_profile_validity(profile)) || is_default == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ net_profile_info_t *profile_info = profile;
+
+ if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (profile_info->ProfileInfo.Pdp.DefaultConn)
+ *is_default = true;
+ else
+ *is_default = false;
+
+ return CONNECTION_ERROR_NONE;
+}
+
EXPORT_API int connection_profile_set_cellular_service_type(connection_profile_h profile,
connection_cellular_service_type_e service_type)
{
#include <string.h>
#include <glib.h>
#include <vconf/vconf.h>
+
#include "net_connection_private.h"
static GSList *prof_handle_list = NULL;
connection_opened_cb opened_cb;
connection_closed_cb closed_cb;
connection_set_default_cb set_default_cb;
+ connection_reset_cb reset_profile_cb;
void *opened_user_data;
void *closed_user_data;
void *set_default_user_data;
+ void *reset_profile_user_data;
bool registered;
+ bool is_created;
+};
+
+struct managed_idle_data {
+ GSourceFunc func;
+ gpointer user_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)
+{
+ return libnet.is_created;
+}
static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
{
return CONNECTION_ERROR_OPERATION_ABORTED;
case NET_ERR_TIME_OUT:
return CONNECTION_ERROR_NO_REPLY;
+ case NET_ERR_ACCESS_DENIED:
+ return CONNECTION_ERROR_PERMISSION_DENIED;
default:
return CONNECTION_ERROR_OPERATION_FAILED;
}
}
}
+static void __libnet_set_reset_profile_cb(connection_opened_cb user_cb, void *user_data)
+{
+ if (user_cb != NULL) {
+ libnet.reset_profile_cb = user_cb;
+ libnet.reset_profile_user_data = user_data;
+ }
+}
+
static void __libnet_set_opened_cb(connection_opened_cb user_cb, void *user_data)
{
if (user_cb) {
}
}
+static gboolean __libnet_reset_profile_cb_idle(gpointer data)
+{
+ connection_error_e result = (connection_error_e)data;
+
+ if (libnet.reset_profile_cb != NULL)
+ libnet.reset_profile_cb(result, libnet.reset_profile_user_data);
+
+ libnet.reset_profile_cb = NULL;
+ libnet.reset_profile_user_data = NULL;
+
+ return FALSE;
+}
+
+static void __libnet_reset_profile_cb(connection_error_e result)
+{
+ if (_connection_is_created() != true) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Application is not registered"
+ "If multi-threaded, thread integrity be broken.");
+ return;
+ }
+
+ if (libnet.reset_profile_cb != NULL)
+ _connection_callback_add(__libnet_reset_profile_cb_idle, (gpointer)result);
+}
+
static void __libnet_opened_cb(connection_error_e result)
{
if (libnet.opened_cb)
case NET_EVENT_WIFI_WPS_RSP:
CONNECTION_LOG(CONNECTION_INFO, "Got wifi WPS RSP\n");
/* fall through */
+ case NET_EVENT_CELLULAR_RESET_DEFAULT_RSP:
+ result = __libnet_convert_to_cp_error_type(event_cb->Error);
+ CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result);
+ __libnet_reset_profile_cb(result);
default :
CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n");
break;
net_profile_name_t profile_name;
rv = net_get_wifi_state(&wlan_state, &profile_name);
- if (rv != NET_ERR_NONE) {
- CONNECTION_LOG(CONNECTION_ERROR, "Error!! net_get_wifi_state() failed.\n");
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get Wi-Fi state[%d]", rv);
return CONNECTION_ERROR_OPERATION_FAILED;
}
int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
{
+ int rv;
struct _profile_list_s ethernet_profiles = {0, 0, NULL};
- net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
-
- if (ethernet_profiles.count == 0) {
- *state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
- return CONNECTION_ERROR_NONE;
+ rv = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
}
switch (ethernet_profiles.profiles->ProfileState) {
int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
{
int i = 0;
+ int rv = 0;
struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
- net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
+ rv = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ }
if (bluetooth_profiles.count == 0) {
*state = CONNECTION_BT_STATE_DEACTIVATED;
rv = net_get_active_net_info(&active_profile);
if (rv == NET_ERR_NO_SERVICE)
return CONNECTION_ERROR_NO_CONNECTION;
- else if (rv != NET_ERR_NONE)
+ else if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
*profile = g_try_malloc0(sizeof(net_profile_info_t));
return CONNECTION_ERROR_NONE;
}
+int _connection_libnet_reset_profile(connection_reset_option_e type,
+ connection_cellular_subscriber_id_e id, connection_reset_cb callback, void *user_data)
+{
+ int rv;
+
+ rv = net_reset_profile(type, id);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to add profile[%d]", rv);
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ __libnet_set_reset_profile_cb(callback, user_data);
+
+ return CONNECTION_ERROR_NONE;
+}
+
int _connection_libnet_open_profile(connection_profile_h profile, connection_opened_cb callback, void* user_data)
{
+ int rv;
+
if (!(_connection_libnet_check_profile_validity(profile))) {
- CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
return CONNECTION_ERROR_INVALID_PARAMETER;
}
net_profile_info_t *profile_info = profile;
- if (net_open_connection_with_profile(profile_info->ProfileName) != NET_ERR_NONE)
+ rv = net_open_connection_with_profile(profile_info->ProfileName);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
__libnet_set_opened_cb(callback, user_data);
struct _profile_list_s cellular_profiles = {0, 0, NULL};
rv = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
- if (rv != NET_ERR_NONE)
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get profile list (%d)", rv);
return CONNECTION_ERROR_OPERATION_FAILED;
+ }
for (;i < cellular_profiles.count;i++)
if (cellular_profiles.profiles[i].ProfileInfo.Pdp.ServiceType == service_type)
int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
{
+ int rv;
+
if (!(_connection_libnet_check_profile_validity(profile))) {
CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
return CONNECTION_ERROR_INVALID_PARAMETER;
if (service_type != type)
return CONNECTION_ERROR_INVALID_PARAMETER;
- if (net_set_default_cellular_service_profile(profile_info->ProfileName) != NET_ERR_NONE)
+ rv = net_set_default_cellular_service_profile(profile_info->ProfileName);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
return CONNECTION_ERROR_NONE;
int _connection_libnet_set_cellular_service_profile_async(connection_cellular_service_type_e type,
connection_profile_h profile, connection_set_default_cb callback, void* user_data)
{
+ int rv;
+
if (!(_connection_libnet_check_profile_validity(profile))) {
CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
return CONNECTION_ERROR_INVALID_PARAMETER;
if (service_type != type)
return CONNECTION_ERROR_INVALID_PARAMETER;
- if (net_set_default_cellular_service_profile_async(profile_info->ProfileName) != NET_ERR_NONE)
+ rv = net_set_default_cellular_service_profile_async(profile_info->ProfileName);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
__libnet_set_default_cb(callback, user_data);
int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
{
+ int rv;
+
if (!(_connection_libnet_check_profile_validity(profile))) {
CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
return CONNECTION_ERROR_INVALID_PARAMETER;
net_profile_info_t *profile_info = profile;
+ rv = net_close_connection(profile_info->ProfileName);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED;
+
if (net_close_connection(profile_info->ProfileName) != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
int _connection_libnet_add_route(const char *interface_name, const char *host_address)
{
+ int rv;
char *endstr = strrchr(host_address, '.');
if (endstr == NULL ||
return CONNECTION_ERROR_INVALID_PARAMETER;
}
- if (net_add_route(host_address, interface_name) != NET_ERR_NONE)
+ rv = net_add_route(host_address, interface_name);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED;
+
+ return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_remove_route(const char *interface_name, const char *host_address)
+{
+ int rv;
+ char *endstr = strrchr(host_address, '.');
+
+ if (endstr == NULL ||
+ strcmp(endstr, ".0") == 0 ||
+ strncmp(host_address, "0.", 2) == 0 ||
+ strstr(host_address, ".0.") != NULL ||
+ strstr(host_address, "255") != NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid IP address Passed");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ rv = net_remove_route(host_address, interface_name);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
return CONNECTION_ERROR_NONE;
int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)
{
- if (net_set_statistics(device_type, statistics_type) != NET_ERR_NONE)
+ int rv;
+ rv = net_set_statistics(device_type, statistics_type);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
return CONNECTION_ERROR_OPERATION_FAILED;
return CONNECTION_ERROR_NONE;
int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size)
{
- if (net_get_statistics(NET_DEVICE_WIFI, statistics_type, size) != NET_ERR_NONE)
- return CONNECTION_ERROR_OPERATION_FAILED;
+ int rv;
+ rv = net_get_statistics(NET_DEVICE_WIFI, statistics_type, size);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ }else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED;
- return CONNECTION_ERROR_NONE;
+ return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile,
+ connection_cellular_subscriber_id_e sim_id)
+{
+ char *modem_path = NULL;
+ net_profile_info_t *profile_info = (net_profile_info_t *)profile;
+
+ if (net_get_cellular_modem_object_path(&modem_path, sim_id) != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get subscriber[%d]", sim_id);
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ if (!modem_path) {
+ CONNECTION_LOG(CONNECTION_ERROR, "NULL modem object path");
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ g_strlcpy(profile_info->ProfileInfo.Pdp.PSModemPath, modem_path,
+ NET_PROFILE_NAME_LEN_MAX);
+ g_free(modem_path);
+
+ return CONNECTION_ERROR_NONE;
+}
+
+static void __connection_idle_destroy_cb(gpointer data)
+{
+ if (!data)
+ return;
+
+ managed_idler_list = g_slist_remove(managed_idler_list, data);
+ g_free(data);
+}
+
+static gboolean __connection_idle_cb(gpointer user_data)
+{
+ struct managed_idle_data *data = (struct managed_idle_data *)user_data;
+
+ if (!data)
+ return FALSE;
+
+ return data->func(data->user_data);
+}
+
+guint _connection_callback_add(GSourceFunc func, gpointer user_data)
+{
+ guint id;
+ struct managed_idle_data *data;
+
+ if (!func)
+ return 0;
+
+ data = g_try_new0(struct managed_idle_data, 1);
+ if (!data)
+ return 0;
+
+ data->func = func;
+ data->user_data = user_data;
+
+ id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, __connection_idle_cb, data,
+ __connection_idle_destroy_cb);
+ if (!id) {
+ g_free(data);
+ return id;
+ }
+
+ data->id = id;
+
+ managed_idler_list = g_slist_append(managed_idler_list, data);
+
+ return id;
+}
+
+void _connection_callback_cleanup(void)
+{
+ GSList *cur = managed_idler_list;
+ GSource *src;
+ struct managed_idle_data *data;
+
+ while (cur) {
+ GSList *next = cur->next;
+ data = (struct managed_idle_data *)cur->data;
+
+ src = g_main_context_find_source_by_id(g_main_context_default(), data->id);
+ if (src) {
+ g_source_destroy(src);
+ cur = managed_idler_list;
+ } else
+ cur = next;
+ }
+
+ g_slist_free(managed_idler_list);
+ managed_idler_list = NULL;
}
+int _connection_libnet_check_get_privilege()
+{
+ int rv;
+
+ rv = net_check_get_privilege();
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED;
+
+ return CONNECTION_ERROR_NONE;
+}
+
+int _connection_libnet_check_profile_privilege()
+{
+ int rv;
+
+ rv = net_check_profile_privilege();
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED;
+
+ 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)
+{
+ 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;
+ }
+ }
+ CONNECTION_LOG(CONNECTION_ERROR, "Not checked enable feature yet");
+ return false;
+}
return false;
}
- buf[strlen(buf) - 1] = '\0';
+ if (rv >= 0)
+ buf[rv] = '\0';
+
return true;
}
}
}
+static const char *test_print_error(connection_error_e error)
+{
+ switch (error) {
+ case CONNECTION_ERROR_NONE:
+ return "CONNECTION_ERROR_NONE";
+ case CONNECTION_ERROR_INVALID_PARAMETER:
+ return "CONNECTION_ERROR_INVALID_PARAMETER";
+ case CONNECTION_ERROR_OUT_OF_MEMORY:
+ return "CONNECTION_ERROR_OUT_OF_MEMORY";
+ case CONNECTION_ERROR_INVALID_OPERATION:
+ return "CONNECTION_ERROR_INVALID_OPERATION";
+ case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
+ return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
+ case CONNECTION_ERROR_OPERATION_FAILED:
+ return "CONNECTION_ERROR_OPERATION_FAILED";
+ case CONNECTION_ERROR_ITERATOR_END:
+ return "CONNECTION_ERROR_ITERATOR_END";
+ case CONNECTION_ERROR_NO_CONNECTION:
+ return "CONNECTION_ERROR_NO_CONNECTION";
+ case CONNECTION_ERROR_NOW_IN_PROGRESS:
+ return "CONNECTION_ERROR_NOW_IN_PROGRESS";
+ case CONNECTION_ERROR_ALREADY_EXISTS:
+ return "CONNECTION_ERROR_ALREADY_EXISTS";
+ case CONNECTION_ERROR_OPERATION_ABORTED:
+ return "CONNECTION_ERROR_OPERATION_ABORTED";
+ case CONNECTION_ERROR_DHCP_FAILED:
+ return "CONNECTION_ERROR_DHCP_FAILED";
+ case CONNECTION_ERROR_INVALID_KEY:
+ return "CONNECTION_ERROR_INVALID_KEY";
+ case CONNECTION_ERROR_NO_REPLY:
+ return "CONNECTION_ERROR_NO_REPLY";
+ case CONNECTION_ERROR_PERMISSION_DENIED:
+ return "CONNECTION_ERROR_PERMISSION_DENIED";
+ case CONNECTION_ERROR_NOT_SUPPORTED:
+ return "CONNECTION_ERROR_NOT_SUPPORTED";
+ default:
+ return "CONNECTION_ERROR_UNKNOWN";
+ }
+}
+
static void test_type_changed_callback(connection_type_e type, void* user_data)
{
printf("Type changed callback, connection type : %d\n", type);
printf("Connection close Failed, err : %d\n", result);
}
+static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
+{
+ if (result == CONNECTION_ERROR_NONE)
+ printf("Reset profile Succeeded\n");
+ else
+ printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
+}
+
static void test_connection_set_default_callback(connection_error_e result, void* user_data)
{
if (result == CONNECTION_ERROR_NONE)
char *password = NULL;
char *home_url = NULL;
bool roaming = false;
+ bool hidden = false;
+ bool editable = false;
if (connection_profile_get_cellular_network_type(profile, &network_type) != CONNECTION_ERROR_NONE)
printf("Fail to get cellular network type!\n");
printf("Fail to get cellular is roaming!\n");
else
printf("Cellular roaming : %s\n", roaming ? "true" : "false");
+
+ if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
+ printf("Fail to get cellular hidden state!\n");
+ else
+ printf("Cellular hidden : %s\n", hidden ? "true" : "false");
+
+ if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
+ printf("Fail to get cellular editing state!\n");
+ else
+ printf("Cellular editable : %s\n", editable ? "true" : "false");
}
static void test_print_wifi_info(connection_profile_h profile)
return 1;
}
+int test_get_default_profile_list(void)
+{
+ int rv = 0;
+ char *profile_name = NULL;
+ connection_profile_iterator_h profile_iter;
+ connection_profile_h profile_h;
+ connection_cellular_service_type_e service_type;
+ bool is_default = false;
+
+ rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
+ return -1;
+ }
+
+ while (connection_profile_iterator_has_next(profile_iter)) {
+ if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile handle\n");
+ return -1;
+ }
+
+ if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile name\n");
+ return -1;
+ }
+ printf("profile name : %s\n", profile_name);
+ g_free(profile_name);
+
+ if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile service type\n");
+ return -1;
+ }
+ printf("service type : %d\n", service_type);
+
+ if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile subscriber id\n");
+ return -1;
+ }
+ printf("Default : %d\n", is_default);
+ }
+
+ return 1;
+}
+
int test_get_connected_profile_list(void)
{
int rv = 0;
char *profile_name = NULL;
connection_profile_iterator_h profile_iter;
connection_profile_h profile_h;
+ bool is_default = false;
+ connection_profile_type_e type;
rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
if (rv != CONNECTION_ERROR_NONE) {
}
printf("profile name : %s\n", profile_name);
g_free(profile_name);
+
+ if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile type\n");
+ return -1;
+ }
+ printf("profile type is %d\n", type);
+
+ if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
+ if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile is default\n");
+ return -1;
+ }
+ printf("[%s]\n", is_default ? "default" : "not default");
+ }
}
return 1;
return 1;
}
+int test_remove_route(void)
+{
+ int rv = 0;
+ char ip_addr[30];
+ char if_name[40];
+
+ if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 30) == false)
+ return -1;
+
+ if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
+ return -1;
+
+ rv = connection_remove_route(connection, if_name, ip_addr);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to remove the route [%s]\n", test_print_error(rv));
+ return -1;
+ }
+
+ return 1;
+}
+
int test_get_bt_state(void)
{
int rv = 0;
return 1;
}
+int test_reset_profile(void)
+{
+ int type, sim_id, rv;
+
+ rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
+
+ if (rv == false || (type != 0 && type != 1)) {
+ printf("Invalid input!!\n");
+ return -1;
+ }
+
+ rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
+
+ if (rv == false || (sim_id != 0 && sim_id != 1)) {
+ printf("Invalid input!!\n");
+ return -1;
+ }
+
+ if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE) {
+ return -1;
+ }
+
+ return 1;
+}
+
int main(int argc, char **argv)
{
-
GMainLoop *mainloop;
mainloop = g_main_loop_new (NULL, FALSE);
rv = test_add_route();
break;
case 'r':
- rv = test_get_bt_state();
+ rv = test_remove_route();
break;
case 's':
+ rv = test_get_bt_state();
+ break;
+ case 't':
rv = test_get_profile_id();
break;
+ case 'u':
+ rv = test_reset_profile();
+ break;
+ case 'v':
+ rv = test_get_default_profile_list();
+ break;
}
if (rv == 1)