#include <netdb.h>
#include <gdbus.h>
+#include <connman/storage.h>
+
#include "connman.h"
#define CONNECT_TIMEOUT 120
};
struct connman_service {
- gint refcount;
- gint session_usage_count;
+ int refcount;
+ int session_usage_count;
char *identifier;
char *path;
enum connman_service_type type;
char *passphrase;
char *agent_passphrase;
connman_bool_t roaming;
- connman_bool_t login_required;
connman_bool_t network_created;
struct connman_ipconfig *ipconfig_ipv4;
struct connman_ipconfig *ipconfig_ipv6;
struct connman_provider *provider;
char **nameservers;
char **nameservers_config;
+ char **nameservers_auto;
char **domains;
char *domainname;
char **timeservers;
char *phase2;
DBusMessage *pending;
guint timeout;
- struct connman_location *location;
struct connman_stats stats;
struct connman_stats stats_roaming;
GHashTable *counter_table;
char **excludes;
char *pac;
connman_bool_t wps;
+ int online_check_count;
};
static void append_path(gpointer value, gpointer user_data)
struct connman_service *service = value;
DBusMessageIter *iter = user_data;
- if (service->path == NULL || service->hidden == TRUE)
+ if (service->path == NULL)
return;
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
case CONNMAN_SERVICE_SECURITY_WEP:
return "wep";
case CONNMAN_SERVICE_SECURITY_PSK:
+ case CONNMAN_SERVICE_SECURITY_WPA:
+ case CONNMAN_SERVICE_SECURITY_RSN:
return "psk";
case CONNMAN_SERVICE_SECURITY_8021X:
return "ieee8021x";
- case CONNMAN_SERVICE_SECURITY_WPA:
- return "wpa";
- case CONNMAN_SERVICE_SECURITY_RSN:
- return "rsn";
}
return NULL;
static int service_load(struct connman_service *service)
{
- const char *ident = "default";
GKeyFile *keyfile;
GError *error = NULL;
- gchar *pathname, *data = NULL;
gsize length;
gchar *str;
connman_bool_t autoconnect;
DBG("service %p", service);
- if (ident == NULL)
- return -EINVAL;
-
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
- if (pathname == NULL)
- return -ENOMEM;
-
- keyfile = g_key_file_new();
-
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
- g_free(pathname);
- return -ENOENT;
- }
-
- g_free(pathname);
-
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE) {
- g_free(data);
- return -EILSEQ;
- }
-
- g_free(data);
+ keyfile = connman_storage_load_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
switch (service->type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
service->state_ipv4 = service->state_ipv6 =
CONNMAN_SERVICE_STATE_FAILURE;
service->error = string2error(str);
+ g_free(str);
}
break;
}
static int service_save(struct connman_service *service)
{
- const char *ident = "default";
GKeyFile *keyfile;
- gchar *pathname, *data = NULL;
- gsize length;
gchar *str;
+ guint freq;
const char *cst_str = NULL;
int err = 0;
DBG("service %p", service);
- if (ident == NULL)
- return -EINVAL;
-
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
- if (pathname == NULL)
- return -ENOMEM;
-
- keyfile = g_key_file_new();
-
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
- goto update;
-
- if (length > 0) {
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE)
- goto done;
- }
-
- g_free(data);
+ keyfile = __connman_storage_open_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
-update:
if (service->name != NULL)
g_key_file_set_string(keyfile, service->identifier,
"Name", service->name);
g_string_free(str, TRUE);
}
+
+ freq = connman_network_get_frequency(service->network);
+ g_key_file_set_integer(keyfile, service->identifier,
+ "Frequency", freq);
}
/* fall through */
g_key_file_remove_key(keyfile, service->identifier,
"Proxy.URL", NULL);
- data = g_key_file_to_data(keyfile, &length, NULL);
-
- if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
- connman_error("Failed to store service information");
-
done:
- g_free(data);
+ __connman_storage_save_service(keyfile, service->identifier);
g_key_file_free(keyfile);
- g_free(pathname);
-
return err;
}
goto done;
}
- if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
- if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION ||
- state_b == CONNMAN_SERVICE_STATE_ONLINE ||
- state_b == CONNMAN_SERVICE_STATE_READY)
- result = state_b;
- else
- result = state_a;
+ if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
+ result = state_a;
goto done;
}
- if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
- if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION ||
- state_a == CONNMAN_SERVICE_STATE_ONLINE ||
- state_a == CONNMAN_SERVICE_STATE_READY)
- result = state_a;
- else
- result = state_b;
+ if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
+ result = state_b;
goto done;
}
- if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
- if (state_b == CONNMAN_SERVICE_STATE_ONLINE ||
- state_b == CONNMAN_SERVICE_STATE_READY)
- result = state_b;
- else
- result = state_a;
+ if (state_a == CONNMAN_SERVICE_STATE_READY) {
+ result = state_a;
goto done;
}
- if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
- if (state_a == CONNMAN_SERVICE_STATE_ONLINE ||
- state_a == CONNMAN_SERVICE_STATE_READY)
- result = state_a;
- else
- result = state_b;
+ if (state_b == CONNMAN_SERVICE_STATE_READY) {
+ result = state_b;
goto done;
}
- if (state_a == CONNMAN_SERVICE_STATE_READY) {
- if (state_b == CONNMAN_SERVICE_STATE_ONLINE ||
- state_b == CONNMAN_SERVICE_STATE_DISCONNECT)
- result = state_b;
- else
- result = state_a;
+ if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+ result = state_a;
goto done;
}
- if (state_b == CONNMAN_SERVICE_STATE_READY) {
- if (state_a == CONNMAN_SERVICE_STATE_ONLINE ||
- state_a == CONNMAN_SERVICE_STATE_DISCONNECT)
- result = state_a;
- else
- result = state_b;
+ if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+ result = state_b;
goto done;
}
- if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
- if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT)
- result = state_b;
- else
- result = state_a;
+ if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+ result = state_a;
goto done;
}
- if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
- if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT)
- result = state_a;
- else
- result = state_b;
+ if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+ result = state_b;
goto done;
}
break;
}
- connman_resolver_remove_all(ifname);
-
if (service->nameservers_config != NULL) {
int i;
connman_resolver_flush();
}
+/*
+ * The is_auto variable is set to true when IPv6 autoconf nameservers are
+ * inserted to resolver via netlink message (see rtnl.c:rtnl_newnduseropt()
+ * for details) and not through service.c
+ */
int __connman_service_nameserver_append(struct connman_service *service,
- const char *nameserver)
+ const char *nameserver, gboolean is_auto)
{
- int len;
+ char **nameservers;
+ int len, i;
- DBG("service %p nameserver %s", service, nameserver);
+ DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
if (nameserver == NULL)
return -EINVAL;
- if (service->nameservers != NULL) {
- int i;
+ if (is_auto == TRUE)
+ nameservers = service->nameservers_auto;
+ else
+ nameservers = service->nameservers;
- for (i = 0; service->nameservers[i] != NULL; i++)
- if (g_strcmp0(service->nameservers[i], nameserver) == 0)
- return -EEXIST;
+ for (i = 0; nameservers != NULL && nameservers[i] != NULL; i++)
+ if (g_strcmp0(nameservers[i], nameserver) == 0)
+ return -EEXIST;
- len = g_strv_length(service->nameservers);
- service->nameservers = g_try_renew(char *, service->nameservers,
- len + 2);
+ if (nameservers != NULL) {
+ len = g_strv_length(nameservers);
+ nameservers = g_try_renew(char *, nameservers, len + 2);
} else {
len = 0;
- service->nameservers = g_try_new0(char *, len + 2);
+ nameservers = g_try_new0(char *, len + 2);
}
- if (service->nameservers == NULL)
+ if (nameservers == NULL)
return -ENOMEM;
- service->nameservers[len] = g_strdup(nameserver);
- service->nameservers[len + 1] = NULL;
+ nameservers[len] = g_strdup(nameserver);
+ if (nameservers[len] == NULL)
+ return -ENOMEM;
- update_nameservers(service);
+ nameservers[len + 1] = NULL;
+
+ if (is_auto == TRUE) {
+ service->nameservers_auto = nameservers;
+ } else {
+ service->nameservers = nameservers;
+ update_nameservers(service);
+ }
return 0;
}
int __connman_service_nameserver_remove(struct connman_service *service,
- const char *nameserver)
+ const char *nameserver, gboolean is_auto)
{
- char **servers;
+ char **servers, **nameservers;
+ gboolean found = FALSE;
int len, i, j;
- DBG("service %p nameserver %s", service, nameserver);
+ DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
if (nameserver == NULL)
return -EINVAL;
- if (service->nameservers == NULL)
+ if (is_auto == TRUE)
+ nameservers = service->nameservers_auto;
+ else
+ nameservers = service->nameservers;
+
+ if (nameservers == NULL)
return 0;
- len = g_strv_length(service->nameservers);
- if (len == 1) {
- if (g_strcmp0(service->nameservers[0], nameserver) != 0)
- return 0;
+ for (i = 0; nameservers != NULL && nameservers[i] != NULL; i++)
+ if (g_strcmp0(nameservers[i], nameserver) == 0) {
+ found = TRUE;
+ break;
+ }
+
+ if (found == FALSE)
+ return 0;
+
+ len = g_strv_length(nameservers);
- g_strfreev(service->nameservers);
- service->nameservers = NULL;
+ if (len == 1) {
+ g_strfreev(nameservers);
+ if (is_auto == TRUE)
+ service->nameservers_auto = NULL;
+ else
+ service->nameservers = NULL;
return 0;
}
return -ENOMEM;
for (i = 0, j = 0; i < len; i++) {
- if (g_strcmp0(service->nameservers[i], nameserver) != 0) {
- servers[j] = g_strdup(service->nameservers[i]);
+ if (g_strcmp0(nameservers[i], nameserver) != 0) {
+ servers[j] = g_strdup(nameservers[i]);
+ if (servers[j] == NULL)
+ return -ENOMEM;
j++;
}
}
servers[len - 1] = NULL;
- g_strfreev(service->nameservers);
- service->nameservers = servers;
+ g_strfreev(nameservers);
+ nameservers = servers;
- update_nameservers(service);
+ if (is_auto == TRUE) {
+ service->nameservers_auto = nameservers;
+ } else {
+ service->nameservers = nameservers;
+ update_nameservers(service);
+ }
return 0;
}
__connman_notifier_default_changed(service);
}
-const char *__connman_service_default(void)
-{
- struct connman_service *service;
-
- service = get_default();
- if (service == NULL)
- return "";
-
- return __connman_service_type2string(service->type);
-}
-
static void state_changed(struct connman_service *service)
{
const char *str;
DBUS_TYPE_BOOLEAN, &service->autoconnect);
}
-static void passphrase_changed(struct connman_service *service)
+static void append_security(DBusMessageIter *iter, void *user_data)
{
- dbus_bool_t required;
+ struct connman_service *service = user_data;
+ const char *str;
- switch (service->type) {
- case CONNMAN_SERVICE_TYPE_UNKNOWN:
- case CONNMAN_SERVICE_TYPE_SYSTEM:
- case CONNMAN_SERVICE_TYPE_ETHERNET:
- case CONNMAN_SERVICE_TYPE_WIMAX:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- case CONNMAN_SERVICE_TYPE_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_GADGET:
- return;
- case CONNMAN_SERVICE_TYPE_WIFI:
- required = FALSE;
+ str = security2string(service->security);
+ if (str != NULL)
+ dbus_message_iter_append_basic(iter,
+ DBUS_TYPE_STRING, &str);
+ /*
+ * Some access points incorrectly advertise WPS even when they
+ * are configured as open or no security, so filter
+ * appropriately.
+ */
+ if (service->wps == TRUE) {
switch (service->security) {
- case CONNMAN_SERVICE_SECURITY_UNKNOWN:
- case CONNMAN_SERVICE_SECURITY_NONE:
- break;
- case CONNMAN_SERVICE_SECURITY_WEP:
case CONNMAN_SERVICE_SECURITY_PSK:
case CONNMAN_SERVICE_SECURITY_WPA:
case CONNMAN_SERVICE_SECURITY_RSN:
- if (service->passphrase == NULL)
- required = TRUE;
+ str = "wps";
+ dbus_message_iter_append_basic(iter,
+ DBUS_TYPE_STRING, &str);
break;
+ case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+ case CONNMAN_SERVICE_SECURITY_NONE:
+ case CONNMAN_SERVICE_SECURITY_WEP:
case CONNMAN_SERVICE_SECURITY_8021X:
break;
}
- break;
}
-
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
- DBUS_TYPE_BOOLEAN, &required);
-}
-
-static void login_changed(struct connman_service *service)
-{
- dbus_bool_t required = service->login_required;
-
- if (service->path == NULL)
- return;
-
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "LoginRequired",
- DBUS_TYPE_BOOLEAN, &required);
-}
-
-static void append_security(DBusMessageIter *iter, void *user_data)
-{
- struct connman_service *service = user_data;
- const char *str;
-
- str = security2string(service->security);
- if (str != NULL)
- dbus_message_iter_append_basic(iter,
- DBUS_TYPE_STRING, &str);
-
- str = "wps";
- if (service->wps == TRUE)
- dbus_message_iter_append_basic(iter,
- DBUS_TYPE_STRING, &str);
}
static void append_ethernet(DBusMessageIter *iter, void *user_data)
if (service->nameservers_config != NULL) {
append_nameserver(iter, &service->nameservers_config);
return;
- } else if (service->nameservers != NULL) {
- append_nameserver(iter, &service->nameservers);
- return;
+ } else {
+ if (service->nameservers != NULL)
+ append_nameserver(iter, &service->nameservers);
+
+ if (service->nameservers_auto != NULL)
+ append_nameserver(iter, &service->nameservers_auto);
}
}
stats->data.time = stats->data_last.time + seconds;
}
-static char *wifi_build_group_name(const unsigned char *ssid,
- unsigned int ssid_len,
- const char *mode,
- const char *security)
-{
- GString *str;
- unsigned int i;
-
- /* the last 3 is for the 2 '_' and '\0' */
- str = g_string_sized_new((ssid_len * 2) + strlen(mode)
- + strlen(security) + 3);
- if (str == NULL)
- return NULL;
-
- for (i = 0; i < ssid_len; i++)
- g_string_append_printf(str, "%02x", ssid[i]);
-
- g_string_append_printf(str, "_%s_%s", mode, security);
-
- return g_string_free(str, FALSE);
-}
-
void __connman_service_notify(struct connman_service *service,
unsigned int rx_packets, unsigned int tx_packets,
unsigned int rx_bytes, unsigned int tx_bytes,
void __connman_service_session_inc(struct connman_service *service)
{
DBG("service %p ref count %d", service,
- g_atomic_int_get(&service->session_usage_count) + 1);
+ service->session_usage_count + 1);
- g_atomic_int_inc(&service->session_usage_count);
+ __sync_fetch_and_add(&service->session_usage_count, 1);
}
connman_bool_t __connman_service_session_dec(struct connman_service *service)
{
DBG("service %p ref count %d", service,
- g_atomic_int_get(&service->session_usage_count) - 1);
+ service->session_usage_count - 1);
- if (g_atomic_int_dec_and_test(&service->session_usage_count) == FALSE)
+ if (__sync_fetch_and_sub(&service->session_usage_count, 1) != 1)
return FALSE;
return TRUE;
static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
struct connman_service *service)
{
- dbus_bool_t required;
const char *str;
str = __connman_service_type2string(service->type);
connman_dbus_dict_append_basic(dict, "Name",
DBUS_TYPE_STRING, &service->name);
- connman_dbus_dict_append_basic(dict, "LoginRequired",
- DBUS_TYPE_BOOLEAN, &service->login_required);
-
switch (service->type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
case CONNMAN_SERVICE_TYPE_SYSTEM:
connman_dbus_dict_append_basic(dict, "Roaming",
DBUS_TYPE_BOOLEAN, &service->roaming);
- required = FALSE;
- connman_dbus_dict_append_basic(dict, "SetupRequired",
- DBUS_TYPE_BOOLEAN, &required);
connman_dbus_dict_append_dict(dict, "Ethernet",
append_ethernet, service);
break;
case CONNMAN_SERVICE_TYPE_WIFI:
- if (service->passphrase != NULL && limited == FALSE)
- connman_dbus_dict_append_basic(dict, "Passphrase",
- DBUS_TYPE_STRING, &service->passphrase);
-
- required = FALSE;
-
- switch (service->security) {
- case CONNMAN_SERVICE_SECURITY_UNKNOWN:
- case CONNMAN_SERVICE_SECURITY_NONE:
- break;
- case CONNMAN_SERVICE_SECURITY_WEP:
- case CONNMAN_SERVICE_SECURITY_PSK:
- case CONNMAN_SERVICE_SECURITY_WPA:
- case CONNMAN_SERVICE_SECURITY_RSN:
- if (service->passphrase == NULL)
- required = TRUE;
- break;
- case CONNMAN_SERVICE_SECURITY_8021X:
- break;
- }
-
- connman_dbus_dict_append_basic(dict, "PassphraseRequired",
- DBUS_TYPE_BOOLEAN, &required);
-
- /* fall through */
case CONNMAN_SERVICE_TYPE_ETHERNET:
case CONNMAN_SERVICE_TYPE_WIMAX:
case CONNMAN_SERVICE_TYPE_BLUETOOTH:
DBusMessageIter *iter = user_data;
DBusMessageIter entry, dict;
- if (service->path == NULL || service->hidden == TRUE)
+ if (service->path == NULL)
return;
dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &entry);
g_sequence_foreach(service_list, append_struct, iter);
}
+connman_bool_t __connman_service_is_hidden(struct connman_service *service)
+{
+ return service->hidden;
+}
+
int __connman_service_get_index(struct connman_service *service)
{
if (service == NULL)
void __connman_service_set_domainname(struct connman_service *service,
const char *domainname)
{
- if (service == NULL)
+ if (service == NULL || service->hidden == TRUE)
return;
g_free(service->domainname);
return NULL;
if (service->nameservers_config != NULL)
- return service->nameservers_config;
- else if (service->nameservers != NULL)
- return service->nameservers;
+ return g_strdupv(service->nameservers_config);
+ else if (service->nameservers != NULL ||
+ service->nameservers_auto != NULL) {
+ int len = 0, len_auto = 0, i;
+ char **nameservers;
+
+ if (service->nameservers != NULL)
+ len = g_strv_length(service->nameservers);
+ if (service->nameservers_auto != NULL)
+ len_auto = g_strv_length(service->nameservers_auto);
+
+ nameservers = g_try_new0(char *, len + len_auto + 1);
+ if (nameservers == NULL)
+ return NULL;
+
+ for (i = 0; i < len; i++)
+ nameservers[i] = g_strdup(service->nameservers[i]);
+
+ for (i = 0; i < len_auto; i++)
+ nameservers[i + len] =
+ g_strdup(service->nameservers_auto[i]);
+
+ return nameservers;
+ }
return NULL;
}
void connman_service_set_proxy_method(struct connman_service *service,
enum connman_service_proxy_method method)
{
- if (service == NULL)
+ if (service == NULL || service->hidden == TRUE)
return;
service->proxy = method;
void __connman_service_set_proxy_autoconfig(struct connman_service *service,
const char *url)
{
- if (service == NULL)
+ if (service == NULL || service->hidden == TRUE)
return;
service->proxy = CONNMAN_SERVICE_PROXY_METHOD_AUTO;
const char *timeserver)
{
char **servers;
- int len, i, j;
+ int len, i, j, found = 0;
DBG("service %p timeserver %s", service, timeserver);
if (service->timeservers == NULL)
return 0;
+ for (i = 0; service->timeservers != NULL &&
+ service->timeservers[i] != NULL; i++)
+ if (g_strcmp0(service->timeservers[i], timeserver) == 0) {
+ found = 1;
+ break;
+ }
+
+ if (found == 0)
+ return 0;
+
len = g_strv_length(service->timeservers);
- if (len == 1) {
- if (g_strcmp0(service->timeservers[0], timeserver) != 0)
- return 0;
+ if (len == 1) {
g_strfreev(service->timeservers);
service->timeservers = NULL;
return 0;
}
- servers = g_try_new0(char *, len - 1);
+ servers = g_try_new0(char *, len);
if (servers == NULL)
return -ENOMEM;
for (i = 0, j = 0; i < len; i++) {
if (g_strcmp0(service->timeservers[i], timeserver) != 0) {
servers[j] = g_strdup(service->timeservers[i]);
+ if (servers[j] == NULL)
+ return -ENOMEM;
j++;
}
}
- servers[len - 2] = NULL;
+ servers[len - 1] = NULL;
g_strfreev(service->timeservers);
service->timeservers = servers;
void __connman_service_set_pac(struct connman_service *service,
const char *pac)
{
+ if (service->hidden == TRUE)
+ return;
g_free(service->pac);
service->pac = g_strdup(pac);
void __connman_service_set_identity(struct connman_service *service,
const char *identity)
{
- if (service->immutable)
+ if (service->immutable || service->hidden == TRUE)
return;
g_free(service->identity);
void __connman_service_set_agent_identity(struct connman_service *service,
const char *agent_identity)
{
+ if (service->hidden == TRUE)
+ return;
g_free(service->agent_identity);
service->agent_identity = g_strdup(agent_identity);
void __connman_service_set_passphrase(struct connman_service *service,
const char* passphrase)
{
- if (service->immutable == TRUE)
+ if (service->immutable == TRUE || service->hidden == TRUE)
return;
g_free(service->passphrase);
service->passphrase = g_strdup(passphrase);
- passphrase_changed(service);
-
if (service->network != NULL)
connman_network_set_string(service->network,
"WiFi.Passphrase",
void __connman_service_set_agent_passphrase(struct connman_service *service,
const char *agent_passphrase)
{
+ if (service->hidden == TRUE)
+ return;
g_free(service->agent_passphrase);
service->agent_passphrase = g_strdup(agent_passphrase);
autoconnect_changed(service);
service_save(service);
- } else if (g_str_equal(name, "Passphrase") == TRUE) {
- const char *passphrase;
-
- if (type != DBUS_TYPE_STRING)
- return __connman_error_invalid_arguments(msg);
-
- if (service->immutable == TRUE)
- return __connman_error_not_supported(msg);
-
- dbus_message_iter_get_basic(&value, &passphrase);
-
- __connman_service_set_passphrase(service, passphrase);
} else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
DBusMessageIter entry;
GString *str;
g_get_current_time(&service->modified);
service_save(service);
- } else if (g_str_equal(name, "Passphrase") == TRUE) {
- if (service->immutable == TRUE)
- return __connman_error_not_supported(msg);
-
- g_free(service->passphrase);
- service->passphrase = NULL;
-
- passphrase_changed(service);
-
- service_save(service);
} else
return __connman_error_invalid_property(msg);
return __connman_device_get_reconnect(device);
}
-static void request_input_cb (struct connman_service *service,
- const char *identity, const char *passphrase,
- void *user_data)
+static DBusMessage *connect_service(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
{
- DBG ("RequestInput return, %p", service);
+ struct connman_service *service = user_data;
+ GSequenceIter *iter;
+ int err;
- if (identity == NULL && passphrase == NULL && service->wps == FALSE)
- return;
+ DBG("service %p", service);
- if (identity != NULL)
- __connman_service_set_agent_identity(service, identity);
-
- if (passphrase != NULL) {
- switch (service->security) {
- case CONNMAN_SERVICE_SECURITY_WEP:
- case CONNMAN_SERVICE_SECURITY_PSK:
- __connman_service_set_passphrase(service, passphrase);
- break;
- case CONNMAN_SERVICE_SECURITY_8021X:
- __connman_service_set_agent_passphrase(service,
- passphrase);
- break;
- case CONNMAN_SERVICE_SECURITY_UNKNOWN:
- case CONNMAN_SERVICE_SECURITY_NONE:
- case CONNMAN_SERVICE_SECURITY_WPA:
- case CONNMAN_SERVICE_SECURITY_RSN:
- DBG("service security '%s' not handled",
- security2string(service->security));
- break;
- }
- }
-
- __connman_service_connect(service);
-
- /* Never cache agent provided credentials */
- __connman_service_set_agent_identity(service, NULL);
- __connman_service_set_agent_passphrase(service, NULL);
-}
-
-static DBusMessage *connect_service(DBusConnection *conn,
- DBusMessage *msg, void *user_data)
-{
- struct connman_service *service = user_data;
- GSequenceIter *iter;
- int err;
-
- DBG("service %p", service);
-
- if (service->pending != NULL)
- return __connman_error_in_progress(msg);
+ if (service->pending != NULL)
+ return __connman_error_in_progress(msg);
iter = g_sequence_get_begin_iter(service_list);
if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET)
return __connman_error_not_supported(msg);
- if (service->immutable == TRUE)
+ if (service->immutable == TRUE || service->hidden == TRUE)
return __connman_error_not_supported(msg);
if (service->favorite == FALSE && service->state !=
CONNMAN_SERVICE_STATE_FAILURE)
return __connman_error_not_supported(msg);
- if (service->network != NULL) {
- set_reconnect_state(service, FALSE);
+ set_reconnect_state(service, FALSE);
- __connman_network_disconnect(service->network);
- }
+ __connman_service_disconnect(service);
g_free(service->passphrase);
service->passphrase = NULL;
- passphrase_changed(service);
-
set_idle(service);
__connman_service_set_favorite(service, FALSE);
return a == b;
}
+static void downgrade_state(struct connman_service *service)
+{
+ if (service == NULL)
+ return;
+
+ DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
+ service->state_ipv6);
+
+ if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
+ __connman_service_ipconfig_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+
+ if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
+ __connman_service_ipconfig_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+}
+
+static void apply_relevant_default_downgrade(struct connman_service *service)
+{
+ struct connman_service *def_service;
+
+ def_service = get_default();
+ if (def_service == NULL)
+ return;
+
+ if (def_service == service &&
+ def_service->state == CONNMAN_SERVICE_STATE_ONLINE)
+ def_service->state = CONNMAN_SERVICE_STATE_READY;
+}
+
static DBusMessage *move_service(DBusConnection *conn,
DBusMessage *msg, void *user_data,
gboolean before)
return __connman_error_not_supported(msg);
target = find_service(path);
- if (target == NULL || target->favorite == FALSE || target == service)
+ if (target == NULL || target->favorite == FALSE || target == service ||
+ target->type == CONNMAN_SERVICE_TYPE_VPN)
return __connman_error_invalid_service(msg);
target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
src = g_hash_table_lookup(service_hash, service->identifier);
dst = g_hash_table_lookup(service_hash, target->identifier);
- before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
+ /*
+ * If the service which goes down is the default service and is
+ * online, we downgrade directly its state to ready so:
+ * the service which goes up, needs to recompute its state which
+ * is triggered via downgrading it - if relevant - to state ready.
+ */
+ if (before == TRUE) {
+ apply_relevant_default_downgrade(target);
+ g_sequence_move(src, dst);
+ downgrade_state(service);
+ } else {
+ apply_relevant_default_downgrade(service);
+ g_sequence_move(dst, src);
+ downgrade_state(target);
+ }
services_changed(FALSE);
__connman_notifier_service_remove(service);
stats_stop(service);
- service_save(service);
service->path = NULL;
g_hash_table_destroy(service->counter_table);
if (service->network != NULL) {
+ __connman_network_disconnect(service->network);
if (service->network_created == TRUE)
connman_network_unref(service->network);
}
service->ipconfig_ipv6 = NULL;
}
- if (service->location != NULL)
- connman_location_unref(service->location);
-
g_strfreev(service->nameservers);
g_strfreev(service->nameservers_config);
+ g_strfreev(service->nameservers_auto);
g_strfreev(service->domains);
g_strfreev(service->proxies);
g_strfreev(service->excludes);
*/
void __connman_service_put(struct connman_service *service)
{
+ GSequenceIter *iter;
+
DBG("service %p", service);
- if (g_atomic_int_dec_and_test(&service->refcount) == TRUE) {
- GSequenceIter *iter;
+ if (__sync_fetch_and_sub(&service->refcount, 1) != 1)
+ return;
- iter = g_hash_table_lookup(service_hash, service->identifier);
- if (iter != NULL) {
- reply_pending(service, ECONNABORTED);
+ iter = g_hash_table_lookup(service_hash, service->identifier);
+ if (iter != NULL) {
+ reply_pending(service, ECONNABORTED);
- __connman_service_disconnect(service);
+ __connman_service_disconnect(service);
- g_sequence_remove(iter);
- } else
- service_free(service);
+ g_sequence_remove(iter);
+ } else {
+ service_free(service);
}
}
service_initialize(service);
- service->location = __connman_location_create(service);
-
return service;
}
-struct connman_location *__connman_service_get_location(struct connman_service *service)
-{
- return service->location;
-}
-
/**
* connman_service_ref:
* @service: service structure
{
DBG("%p", service);
- g_atomic_int_inc(&service->refcount);
+ __sync_fetch_and_add(&service->refcount, 1);
return service;
}
{
GSequenceIter *iter;
+ if (service->hidden == TRUE)
+ return -EOPNOTSUPP;
iter = g_hash_table_lookup(service_hash, service->identifier);
if (iter == NULL)
return -ENOENT;
return -EALREADY;
service->favorite = favorite;
+ service->order = __connman_service_get_order(service);
favorite_changed(service);
int __connman_service_set_immutable(struct connman_service *service,
connman_bool_t immutable)
{
+ if (service->hidden == TRUE)
+ return -EOPNOTSUPP;
service->immutable = immutable;
immutable_changed(service);
void __connman_service_set_string(struct connman_service *service,
const char *key, const char *value)
{
+ if (service->hidden == TRUE)
+ return;
if (g_str_equal(key, "EAP") == TRUE) {
g_free(service->eap);
service->eap = g_strdup(value);
}
}
+void __connman_service_add_passphrase(struct connman_service *service,
+ const gchar *passphrase)
+{
+ switch (service->security) {
+ case CONNMAN_SERVICE_SECURITY_WEP:
+ case CONNMAN_SERVICE_SECURITY_PSK:
+ __connman_service_set_passphrase(service, passphrase);
+ break;
+ case CONNMAN_SERVICE_SECURITY_8021X:
+ __connman_service_set_agent_passphrase(service,
+ passphrase);
+ break;
+ case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+ case CONNMAN_SERVICE_SECURITY_NONE:
+ case CONNMAN_SERVICE_SECURITY_WPA:
+ case CONNMAN_SERVICE_SECURITY_RSN:
+ DBG("service security '%s' (%d) not handled",
+ security2string(service->security),
+ service->security);
+ break;
+ }
+
+}
+
+static void request_input_cb (struct connman_service *service,
+ connman_bool_t values_received,
+ const char *name, int name_len,
+ const char *identity, const char *passphrase,
+ void *user_data)
+{
+ struct connman_device *device;
+
+ DBG ("RequestInput return, %p", service);
+
+ if (service->hidden == TRUE && name_len > 0 && name_len <= 32) {
+ device = connman_network_get_device(service->network);
+ __connman_device_request_hidden_scan(device,
+ name, name_len,
+ identity, passphrase);
+ }
+
+ if (values_received == FALSE || service->hidden == TRUE) {
+ service_complete(service);
+ services_changed(FALSE);
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
+ return;
+ }
+
+ if (identity != NULL)
+ __connman_service_set_agent_identity(service, identity);
+
+ if (passphrase != NULL)
+ __connman_service_add_passphrase(service, passphrase);
+
+ __connman_service_connect(service);
+
+ /* Never cache agent provided credentials */
+ __connman_service_set_agent_identity(service, NULL);
+ __connman_service_set_agent_passphrase(service, NULL);
+}
+
+static void downgrade_connected_services(void)
+{
+ struct connman_service *up_service;
+ GSequenceIter *iter;
+
+ iter = g_sequence_get_begin_iter(service_list);
+ while (g_sequence_iter_is_end(iter) == FALSE) {
+ up_service = g_sequence_get(iter);
+
+ if (is_connected(up_service) == FALSE) {
+ iter = g_sequence_iter_next(iter);
+ continue;
+ }
+
+ if (up_service->state == CONNMAN_SERVICE_STATE_ONLINE)
+ return;
+
+ downgrade_state(up_service);
+
+ iter = g_sequence_iter_next(iter);
+ }
+}
+
static int service_indicate_state(struct connman_service *service)
{
enum connman_service_state old_state, new_state;
+ struct connman_service *def_service;
GSequenceIter *iter;
if (service == NULL)
if (old_state == new_state)
return -EALREADY;
+ def_service = get_default();
+
+ if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
+ if (def_service != NULL && def_service != service &&
+ def_service->state == CONNMAN_SERVICE_STATE_ONLINE)
+ return -EALREADY;
+ }
+
service->state = new_state;
state_changed(service);
}
if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
- if (service->login_required == TRUE) {
- service->login_required = FALSE;
- login_changed(service);
- }
-
connman_timeserver_sync();
}
service->ipconfig_ipv6);
} else if (new_state == CONNMAN_SERVICE_STATE_DISCONNECT) {
- struct connman_service *def_service = get_default();
+ def_service = get_default();
if (__connman_notifier_count_connected() == 0 &&
def_service != NULL &&
def_service->provider != NULL)
__connman_provider_disconnect(def_service->provider);
- __connman_location_finish(service);
-
default_changed();
+ __connman_wispr_stop(service);
+
__connman_wpad_stop(service);
update_nameservers(service);
domain_changed(service);
__connman_notifier_disconnect(service->type);
+
+ /*
+ * Previous services which are connected and which states
+ * are set to online should reset relevantly ipconfig_state
+ * to ready so wispr/portal will be rerun on those
+ */
+ downgrade_connected_services();
}
if (new_state == CONNMAN_SERVICE_STATE_FAILURE) {
default_changed();
- __connman_location_detect(service);
-
return 0;
}
struct connman_service *service,
enum connman_ipconfig_type type)
{
+ if (service == NULL)
+ return CONNMAN_SERVICE_STATE_UNKNOWN;
+
if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
return service->state_ipv4;
*/
if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
- return;
+ goto done;
if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
(service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
service->pac != NULL))
- return;
+ goto done;
if (__connman_wpad_start(service) < 0) {
service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
__connman_notifier_proxy_changed(service);
+ goto done;
+ }
+
+ return;
+
+done:
+ __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+/*
+ * How many networks are connected at the same time. If more than 1,
+ * then set the rp_filter setting properly (loose mode routing) so that network
+ * connectivity works ok. This is only done for IPv4 networks as IPv6
+ * does not have rp_filter knob.
+ */
+static int connected_networks_count;
+static int original_rp_filter;
+
+static void service_rp_filter(struct connman_service *service,
+ gboolean connected)
+{
+ enum connman_ipconfig_method method;
+
+ method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
+
+ switch (method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ return;
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ break;
+ }
+
+ if (connected == TRUE) {
+ if (connected_networks_count == 1) {
+ int filter_value;
+ filter_value = __connman_ipconfig_set_rp_filter();
+ if (filter_value < 0)
+ return;
+
+ original_rp_filter = filter_value;
+ }
+ connected_networks_count++;
+
+ } else {
+ if (connected_networks_count == 2)
+ __connman_ipconfig_unset_rp_filter(original_rp_filter);
+
+ connected_networks_count--;
+ if (connected_networks_count < 0)
+ connected_networks_count = 0;
}
+
+ DBG("%s %s ipconfig %p method %d count %d filter %d",
+ connected ? "connected" : "disconnected", service->identifier,
+ service->ipconfig_ipv4, method,
+ connected_networks_count, original_rp_filter);
+}
+
+static gboolean redo_wispr(gpointer user_data)
+{
+ struct connman_service *service = user_data;
+
+ DBG("");
+
+ __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV6);
+
+ return FALSE;
+}
+
+int __connman_service_online_check_failed(struct connman_service *service,
+ enum connman_ipconfig_type type)
+{
+ DBG("service %p type %d count %d", service, type,
+ service->online_check_count);
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ /* currently we only retry IPv6 stuff */
+ return 0;
+
+ if (service->online_check_count != 1)
+ return 0;
+
+ service->online_check_count = 0;
+
+ /*
+ * We set the timeout to 1 sec so that we have a chance to get
+ * necessary IPv6 router advertisement messages that might have
+ * DNS data etc.
+ */
+ g_timeout_add_seconds(1, redo_wispr, service);
+
+ return EAGAIN;
}
int __connman_service_ipconfig_indicate_state(struct connman_service *service,
{
struct connman_ipconfig *ipconfig = NULL;
enum connman_service_state old_state;
+ int ret;
if (service == NULL)
return -EINVAL;
case CONNMAN_SERVICE_STATE_READY:
update_nameservers(service);
- if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
check_proxy_setup(service);
+ service_rp_filter(service, TRUE);
+ } else {
+ service->online_check_count = 1;
+ __connman_wispr_start(service, type);
+ }
break;
case CONNMAN_SERVICE_STATE_ONLINE:
break;
case CONNMAN_SERVICE_STATE_DISCONNECT:
if (service->state == CONNMAN_SERVICE_STATE_IDLE)
return -EINVAL;
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ service_rp_filter(service, FALSE);
+
break;
case CONNMAN_SERVICE_STATE_FAILURE:
break;
else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
service->state_ipv6 = new_state;
- return service_indicate_state(service);
-}
-
-int __connman_service_request_login(struct connman_service *service)
-{
- DBG("service %p", service);
+ ret = service_indicate_state(service);
- if (service == NULL)
- return -EINVAL;
+ /*
+ * If the ipconfig method is OFF, then we set the state to IDLE
+ * so that it will not affect the combined state in the future.
+ */
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+ enum connman_ipconfig_method method;
+ method = __connman_ipconfig_get_method(service->ipconfig_ipv4);
+ if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
+ method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
+ service->state_ipv4 = CONNMAN_SERVICE_STATE_IDLE;
+ ret = service_indicate_state(service);
+ }
- service->login_required = TRUE;
- login_changed(service);
+ } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+ enum connman_ipconfig_method method;
+ method = __connman_ipconfig_get_method(service->ipconfig_ipv6);
+ if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
+ method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
+ service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+ ret = service_indicate_state(service);
+ }
+ }
- return 0;
+ return ret;
}
static connman_bool_t prepare_network(struct connman_service *service)
{
int err;
+ if (service->hidden == TRUE)
+ return -EPERM;
+
switch (service->type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
case CONNMAN_SERVICE_TYPE_SYSTEM:
__connman_provider_disconnect(service->provider);
if (service->userconnect == TRUE) {
- if (err == -ENOKEY) {
- if (__connman_agent_request_input(service,
+ if (err == -ENOKEY || err == -EPERM) {
+ if (__connman_agent_request_passphrase_input(service,
request_input_cb,
NULL) == -EIO)
return -EINPROGRESS;
int __connman_service_disconnect_all(void)
{
GSequenceIter *iter;
+ GSList *services = NULL, *list;
DBG("");
while (g_sequence_iter_is_end(iter) == FALSE) {
struct connman_service *service = g_sequence_get(iter);
- service->ignore = TRUE;
-
- set_reconnect_state(service, FALSE);
-
- __connman_service_disconnect(service);
+ services = g_slist_prepend(services, service);
iter = g_sequence_iter_next(iter);
}
- return 0;
+ for (list = services; list != NULL; list = list->next) {
+ struct connman_service *service = list->data;
-}
+ service->ignore = TRUE;
-/**
- * __connman_service_lookup:
- * @pattern: search pattern
- * @path: return object path
- *
- * Look up a service path from a search pattern
- */
-int __connman_service_lookup(const char *pattern, const char **path)
-{
- GHashTableIter iter;
- gpointer key, value;
+ set_reconnect_state(service, FALSE);
- g_hash_table_iter_init(&iter, service_hash);
+ __connman_service_disconnect(service);
+ }
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- GSequenceIter *iter = value;
- struct connman_service *service = g_sequence_get(iter);
+ g_slist_free(list);
- if (g_strcmp0(service->identifier, pattern) == 0 ||
- g_strcmp0(service->name, pattern) == 0) {
- *path = (const char *) service->path;
- return 0;
- }
- }
+ return 0;
- return -ENXIO;
}
/**
return NULL;
}
-static struct connman_network *create_hidden_wifi(struct connman_device *device,
- const char *ssid, const char *mode, const char *security,
- const char *group)
-{
- struct connman_network *network;
- char *name;
- int index;
- unsigned int i, ssid_len;
-
- ssid_len = strlen(ssid);
- if (ssid_len < 1)
- return NULL;
-
- network = connman_network_create(group, CONNMAN_NETWORK_TYPE_WIFI);
- if (network == NULL)
- return NULL;
-
- connman_network_set_blob(network, "WiFi.SSID",
- (unsigned char *) ssid, ssid_len);
-
- connman_network_set_string(network, "WiFi.Mode", mode);
- connman_network_set_string(network, "WiFi.Security", security);
-
- name = g_try_malloc0(ssid_len + 1);
- if (name == NULL) {
- connman_network_unref(network);
- return NULL;
- }
-
- for (i = 0; i < ssid_len; i++) {
- if (g_ascii_isprint(ssid[i]))
- name[i] = ssid[i];
- else
- name[i] = ' ';
- }
-
- connman_network_set_name(network, name);
-
- g_free(name);
-
- index = connman_device_get_index(device);
- connman_network_set_index(network, index);
-
- if (connman_device_add_network(device, network) < 0) {
- connman_network_unref(network);
- return NULL;
- }
-
- connman_network_set_available(network, TRUE);
-
- return network;
-}
-
-int __connman_service_create_and_connect(DBusMessage *msg)
-{
- struct connman_service *service;
- struct connman_network *network;
- struct connman_device *device;
- DBusMessageIter iter, array;
- const char *mode = "managed", *security = "none", *group_security;
- const char *type = NULL, *ssid = NULL, *passphrase = NULL;
- unsigned int ssid_len = 0;
- const char *ident;
- char *name, *group;
- int err;
-
- dbus_message_iter_init(msg, &iter);
- dbus_message_iter_recurse(&iter, &array);
-
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key;
-
- dbus_message_iter_recurse(&array, &entry);
- dbus_message_iter_get_basic(&entry, &key);
-
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
-
- switch (dbus_message_iter_get_arg_type(&value)) {
- case DBUS_TYPE_STRING:
- if (g_str_equal(key, "Type") == TRUE)
- dbus_message_iter_get_basic(&value, &type);
- else if (g_str_equal(key, "WiFi.Mode") == TRUE ||
- g_str_equal(key, "Mode") == TRUE)
- dbus_message_iter_get_basic(&value, &mode);
- else if (g_str_equal(key, "WiFi.Security") == TRUE ||
- g_str_equal(key, "Security") == TRUE)
- dbus_message_iter_get_basic(&value, &security);
- else if (g_str_equal(key, "WiFi.Passphrase") == TRUE ||
- g_str_equal(key, "Passphrase") == TRUE)
- dbus_message_iter_get_basic(&value, &passphrase);
- else if (g_str_equal(key, "WiFi.SSID") == TRUE ||
- g_str_equal(key, "SSID") == TRUE)
- dbus_message_iter_get_basic(&value, &ssid);
- }
-
- dbus_message_iter_next(&array);
- }
-
- if (type == NULL)
- return -EINVAL;
-
- if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
- return -EOPNOTSUPP;
-
- if (ssid == NULL)
- return -EINVAL;
-
- ssid_len = strlen(ssid);
- if (ssid_len < 1)
- return -EINVAL;
-
- if (g_strcmp0(security, "none") != 0 &&
- g_strcmp0(security, "wep") != 0 &&
- g_strcmp0(security, "psk") != 0 &&
- g_strcmp0(security, "wpa") != 0 &&
- g_strcmp0(security, "rsn") != 0 &&
- g_strcmp0(security, "ieee8021x") != 0)
- return -EINVAL;
-
- device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
- if (device == NULL)
- return -EOPNOTSUPP;
-
- ident = connman_device_get_ident(device);
- if (ident == NULL)
- return -EOPNOTSUPP;
-
-
- if (!g_strcmp0(security, "wpa") ||
- !g_strcmp0(security, "rsn"))
- group_security = "psk";
- else
- group_security = security;
-
- group = wifi_build_group_name((unsigned char *) ssid,
- ssid_len, mode, group_security);
- if (group == NULL)
- return -EINVAL;
-
- name = g_strdup_printf("%s_%s_%s", type, ident, group);
-
- service = lookup_by_identifier(name);
-
- if (service != NULL)
- goto done;
-
- network = create_hidden_wifi(device, ssid, mode, security, group);
- if (network != NULL)
- connman_network_set_group(network, group);
-
- service = lookup_by_identifier(name);
-
-done:
- g_free(name);
- g_free(group);
-
- if (service == NULL) {
- err = -EOPNOTSUPP;
- goto failed;
- }
-
- service->network_created = TRUE;
-
- if (is_connected(service) == TRUE) {
- err = -EISCONN;
- goto failed;
- }
-
- if (is_connecting(service) == TRUE) {
- err = -EALREADY;
- goto failed;
- }
-
- set_reconnect_state(service, FALSE);
-
- __connman_device_disconnect(device);
-
- if (passphrase != NULL) {
- g_free(service->passphrase);
- service->passphrase = g_strdup(passphrase);
- }
-
- service->userconnect = TRUE;
-
- err = __connman_service_connect(service);
- if (err < 0 && err != -EINPROGRESS)
- goto failed;
-
- service->pending = dbus_message_ref(msg);
-
- return 0;
-
-failed:
- if (service != NULL && service->network_created == TRUE) {
- struct connman_network *network = service->network;
-
- if (network != NULL) {
- connman_network_set_available(network, FALSE);
- __connman_device_cleanup_networks(device);
- } else
- __connman_service_put(service);
- }
-
- return err;
-}
-
static void provision_changed(gpointer value, gpointer user_data)
{
struct connman_service *service = value;
g_sequence_foreach(service_list, provision_changed, (void *)ident);
}
-int __connman_service_provision(DBusMessage *msg)
-{
- GKeyFile *keyfile = NULL;
- const char *config_str = NULL;
- char *group = NULL, *ident = NULL;
- int err = 0;
- struct connman_service *service;
-
- DBG("");
-
- dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &config_str,
- DBUS_TYPE_INVALID);
-
- if (config_str == NULL || strlen(config_str) == 0)
- return -EINVAL;
-
- keyfile = g_key_file_new();
-
- /* populate GKeyFile with config_str */
- if (g_key_file_load_from_data(keyfile, config_str,
- strlen(config_str), 0, NULL) == FALSE) {
- err = -EINVAL;
- goto done;
- }
-
- /*
- * read only one group of settings (only one service supported, no
- * global settings)
- */
- group = g_key_file_get_start_group(keyfile);
-
- if (group == NULL || g_str_has_prefix(group, "service_") == FALSE) {
- err = -EINVAL;
- goto done;
- }
-
- err = __connman_config_load_service(keyfile, group, TRUE);
- if (err < 0)
- goto done;
-
- ident = group + strlen("service_");
-
- /* trigger service provisioning if service exists */
- service = lookup_by_identifier(ident);
- if (service != NULL)
- __connman_config_provision_service(service);
-
- g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
-
-done:
- if (group != NULL)
- g_free(group);
-
- if (keyfile != NULL)
- g_key_file_free(keyfile);
-
- return err;
-}
-
/**
* __connman_service_get:
* @identifier: service identifier
static void setup_ip4config(struct connman_service *service, int index,
enum connman_ipconfig_method method)
{
- if (index < 0)
- return;
-
service->ipconfig_ipv4 = connman_ipconfig_create(index,
CONNMAN_IPCONFIG_TYPE_IPV4);
if (service->ipconfig_ipv4 == NULL)
static void setup_ip6config(struct connman_service *service, int index)
{
- if (index < 0)
- return;
-
service->ipconfig_ipv6 = connman_ipconfig_create(index,
CONNMAN_IPCONFIG_TYPE_IPV6);
if (service->ipconfig_ipv6 == NULL)
if (service->ipconfig_ipv4 == NULL)
return;
- keyfile = __connman_storage_open_profile("default");
+ keyfile = connman_storage_load_service(service->identifier);
if (keyfile == NULL)
return;
if (service->ipconfig_ipv6 == NULL)
return;
- keyfile = __connman_storage_open_profile("default");
+ keyfile = connman_storage_load_service(service->identifier);
if (keyfile == NULL)
return;
return;
setup_ip6config(service, index);
+
__connman_service_read_ip6config(service);
}
DBG("network %p", network);
+ if (network == NULL)
+ return NULL;
+
ident = __connman_network_get_ident(network);
if (ident == NULL)
return NULL;
DBG("network %p", network);
+ if (network == NULL)
+ return NULL;
+
ident = __connman_network_get_ident(network);
if (ident == NULL)
return NULL;
void __connman_service_update_from_network(struct connman_network *network)
{
+ connman_bool_t need_sort = FALSE;
struct connman_service *service;
connman_uint8_t strength;
connman_bool_t roaming;
goto roaming;
service->strength = strength;
+ need_sort = TRUE;
strength_changed(service);
roaming:
roaming = connman_network_get_bool(service->network, "Roaming");
if (roaming == service->roaming)
- return;
+ goto sorting;
stats_enable = stats_enabled(service);
if (stats_enable == TRUE)
stats_stop(service);
service->roaming = roaming;
+ need_sort = TRUE;
if (stats_enable == TRUE)
stats_start(service);
roaming_changed(service);
- iter = g_hash_table_lookup(service_hash, service->identifier);
- if (iter != NULL)
- g_sequence_sort_changed(iter, service_compare, NULL);
+sorting:
+ if (need_sort == TRUE) {
+ iter = g_hash_table_lookup(service_hash, service->identifier);
+ if (iter != NULL)
+ g_sequence_sort_changed(iter, service_compare, NULL);
+ }
}
void __connman_service_remove_from_network(struct connman_network *network)
if (service == NULL)
return;
+ __connman_connection_gateway_remove(service,
+ CONNMAN_IPCONFIG_TYPE_ALL);
+
__connman_service_put(service);
}
return service;
}
-void __connman_service_downgrade_state(struct connman_service *service)
-{
- if (service == NULL)
- return;
-
- DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
- service->state_ipv6);
-
- if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
- __connman_service_ipconfig_indicate_state(service,
- CONNMAN_SERVICE_STATE_READY,
- CONNMAN_IPCONFIG_TYPE_IPV4);
-
- if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
- __connman_service_ipconfig_indicate_state(service,
- CONNMAN_SERVICE_STATE_READY,
- CONNMAN_IPCONFIG_TYPE_IPV6);
-}
-
int __connman_service_init(void)
{
DBG("");