struct _libnet_s {
connection_opened_cb opened_cb;
connection_closed_cb closed_cb;
+ connection_set_default_cb set_default_cb;
void *opened_user_data;
void *closed_user_data;
+ void *set_default_user_data;
bool registered;
};
static struct _profile_list_s profile_iterator = {0, 0, NULL};
-static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, false};
+static struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false};
static connection_error_e __libnet_convert_to_cp_error_type(net_err_t err_type)
{
return "INVALID_KEY";
case CONNECTION_ERROR_NO_REPLY:
return "NO_REPLY";
+ case CONNECTION_ERROR_PERMISSION_DENIED:
+ return "PERMISSION_DENIED";
+ case CONNECTION_ERROR_NOT_SUPPORTED:
+ return "NOT_SUPPORTED";
}
return "UNKNOWN";
libnet.closed_user_data = NULL;
}
+static void __libnet_set_default_cb(connection_set_default_cb user_cb, void *user_data)
+{
+ if (user_cb) {
+ libnet.set_default_cb = user_cb;
+ libnet.set_default_user_data = user_data;
+ }
+}
+
+static void __libnet_default_cb(connection_error_e result)
+{
+ if (libnet.set_default_cb)
+ libnet.set_default_cb(result, libnet.set_default_user_data);
+
+ libnet.set_default_cb = NULL;
+ libnet.set_default_user_data = NULL;
+}
+
static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
{
if (profile_name == NULL)
case NET_EVENT_WIFI_POWER_RSP:
CONNECTION_LOG(CONNECTION_INFO, "Got wifi power IND\n");
break;
+ case NET_EVENT_CELLULAR_SET_DEFAULT_RSP:
+ result = __libnet_convert_to_cp_error_type(event_cb->Error);
+ CONNECTION_LOG(CONNECTION_INFO, "Got set default profile RSP %d\n", result);
+ __libnet_default_cb(result);
+ break;
case NET_EVENT_WIFI_WPS_RSP:
CONNECTION_LOG(CONNECTION_INFO, "Got wifi WPS RSP\n");
/* fall through */
}
-bool _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
+int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
{
+ int rv;
net_wifi_state_t wlan_state;
net_profile_name_t profile_name;
- if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) {
+ 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");
- return false;
+ return CONNECTION_ERROR_OPERATION_FAILED;
}
switch (wlan_state) {
break;
default :
CONNECTION_LOG(CONNECTION_ERROR, "Error!! Unknown state\n");
- return false;
+ return CONNECTION_ERROR_INVALID_OPERATION;
}
- return true;
+ return CONNECTION_ERROR_NONE;
}
-bool _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
+int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
{
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 true;
+ return CONNECTION_ERROR_NONE;
}
switch (ethernet_profiles.profiles->ProfileState) {
*state = CONNECTION_ETHERNET_STATE_DISCONNECTED;
break;
default:
- return false;
+ return CONNECTION_ERROR_OPERATION_FAILED;
}
__libnet_clear_profile_list(ðernet_profiles);
- return true;
+ return CONNECTION_ERROR_NONE;
}
-bool _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
+int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
{
int i = 0;
struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
if (bluetooth_profiles.count == 0) {
*state = CONNECTION_BT_STATE_DEACTIVATED;
- return true;
+ return CONNECTION_ERROR_NONE;
}
for (; i < bluetooth_profiles.count; i++) {
break;
default:
__libnet_clear_profile_list(&bluetooth_profiles);
- return false;
+ return CONNECTION_ERROR_OPERATION_FAILED;
}
}
done:
__libnet_clear_profile_list(&bluetooth_profiles);
- return true;
+ return CONNECTION_ERROR_NONE;
}
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 rv;
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 all_profiles = {0, 0, NULL};
__libnet_clear_profile_list(&profile_iterator);
- rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count);
- if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE)
- return CONNECTION_ERROR_OPERATION_FAILED;
-
- CONNECTION_LOG(CONNECTION_INFO, "Wifi profile count : %d\n", wifi_profiles.count);
+ rv = net_get_profile_list(NET_DEVICE_MAX, &all_profiles.profiles, &all_profiles.count);
- rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count);
- if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) {
- __libnet_clear_profile_list(&wifi_profiles);
- return CONNECTION_ERROR_OPERATION_FAILED;
- }
- CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count : %d\n", cellular_profiles.count);
-
- rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count);
- if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) {
- __libnet_clear_profile_list(&wifi_profiles);
- __libnet_clear_profile_list(&cellular_profiles);
- return CONNECTION_ERROR_OPERATION_FAILED;
- }
- CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d\n", ethernet_profiles.count);
-
- rv4 = net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
- if (rv4 != NET_ERR_NO_SERVICE && rv4 != NET_ERR_NONE) {
- __libnet_clear_profile_list(&wifi_profiles);
- __libnet_clear_profile_list(&cellular_profiles);
- __libnet_clear_profile_list(ðernet_profiles);
- return CONNECTION_ERROR_OPERATION_FAILED;
+ if (rv != NET_ERR_NONE) {
+ if (rv == NET_ERR_NO_SERVICE) {
+ *profile_iter_h = &profile_iterator;
+ return CONNECTION_ERROR_NONE;
+ } else
+ return CONNECTION_ERROR_OPERATION_FAILED;
}
- CONNECTION_LOG(CONNECTION_INFO, "Bluetooth profile count : %d\n", bluetooth_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 = all_profiles.count;
CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d\n", count);
+
if (count == 0)
return CONNECTION_ERROR_NONE;
- profiles = g_try_new0(net_profile_info_t, count);
- if (profiles == NULL) {
- __libnet_clear_profile_list(&wifi_profiles);
- __libnet_clear_profile_list(&cellular_profiles);
- __libnet_clear_profile_list(ðernet_profiles);
- __libnet_clear_profile_list(&bluetooth_profiles);
- return CONNECTION_ERROR_OUT_OF_MEMORY;
- }
-
- profile_iterator.profiles = profiles;
-
- if (wifi_profiles.count > 0) {
- memcpy(profiles, wifi_profiles.profiles,
- sizeof(net_profile_info_t) * wifi_profiles.count);
- profiles += wifi_profiles.count;
- }
-
- if (cellular_profiles.count > 0) {
- memcpy(profiles, cellular_profiles.profiles,
- sizeof(net_profile_info_t) * cellular_profiles.count);
- profiles += cellular_profiles.count;
- }
-
- if (ethernet_profiles.count > 0) {
- memcpy(profiles, ethernet_profiles.profiles,
- sizeof(net_profile_info_t) * ethernet_profiles.count);
- profiles += ethernet_profiles.count;
- }
-
- if (bluetooth_profiles.count > 0)
- memcpy(profiles, bluetooth_profiles.profiles,
- sizeof(net_profile_info_t) * bluetooth_profiles.count);
+ profile_iterator.profiles = all_profiles.profiles;
break;
case CONNECTION_ITERATOR_TYPE_CONNECTED:
- count = __libnet_get_connected_count(&wifi_profiles);
- count += __libnet_get_connected_count(&cellular_profiles);
- count += __libnet_get_connected_count(ðernet_profiles);
- count += __libnet_get_connected_count(&bluetooth_profiles);
+ count = __libnet_get_connected_count(&all_profiles);
CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d\n", count);
+
if (count == 0)
return CONNECTION_ERROR_NONE;
profiles = g_try_new0(net_profile_info_t, count);
if (profiles == NULL) {
- __libnet_clear_profile_list(&wifi_profiles);
- __libnet_clear_profile_list(&cellular_profiles);
- __libnet_clear_profile_list(ðernet_profiles);
- __libnet_clear_profile_list(&bluetooth_profiles);
+ __libnet_clear_profile_list(&all_profiles);
return CONNECTION_ERROR_OUT_OF_MEMORY;
+ break;
+ case CONNECTION_ITERATOR_TYPE_DEFAULT:
+ /* To do : Not supported yet */
+ break;
}
profile_iterator.profiles = profiles;
- if (wifi_profiles.count > 0)
- __libnet_copy_connected_profile(&profiles, &wifi_profiles);
-
- if (cellular_profiles.count > 0)
- __libnet_copy_connected_profile(&profiles, &cellular_profiles);
+ __libnet_copy_connected_profile(&profiles, &all_profiles);
- if (ethernet_profiles.count > 0)
- __libnet_copy_connected_profile(&profiles, ðernet_profiles);
-
- if (bluetooth_profiles.count > 0)
- __libnet_copy_connected_profile(&profiles, &bluetooth_profiles);
-
- break;
+ __libnet_clear_profile_list(&all_profiles);
}
- __libnet_clear_profile_list(&wifi_profiles);
- __libnet_clear_profile_list(&cellular_profiles);
- __libnet_clear_profile_list(ðernet_profiles);
- __libnet_clear_profile_list(&bluetooth_profiles);
-
profile_iterator.count = count;
return CONNECTION_ERROR_NONE;
return CONNECTION_ERROR_NONE;
}
-int _connection_libnet_set_cellular_service_profile(connection_cellular_service_type_e type, connection_profile_h profile)
+int _connection_libnet_set_cellular_service_profile_sync(connection_cellular_service_type_e type, connection_profile_h profile)
{
if (!(_connection_libnet_check_profile_validity(profile))) {
CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n");
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)
+{
+ 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;
+ connection_cellular_service_type_e service_type;
+
+ service_type = _profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType);
+
+ if (service_type != type)
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+
+ if (net_set_default_cellular_service_profile_async(profile_info->ProfileName) != NET_ERR_NONE)
+ return CONNECTION_ERROR_OPERATION_FAILED;
+
+ __libnet_set_default_cb(callback, user_data);
+
+ return CONNECTION_ERROR_NONE;
+}
+
int _connection_libnet_close_profile(connection_profile_h profile, connection_closed_cb callback, void *user_data)
{
if (!(_connection_libnet_check_profile_validity(profile))) {
return true;
}
-void _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
+bool _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile)
{
net_profile_info_t *profile_info = profile;
- g_hash_table_remove(profile_cb_table, profile_info->ProfileName);
+ if (g_hash_table_remove(profile_cb_table, profile_info->ProfileName) == TRUE)
+ return true;
+
+ return false;
}
int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type)