#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;
unsigned int order;
char *name;
char *passphrase;
- char *profile;
+ 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;
/* 802.1x settings from the config files */
char *eap;
char *identity;
+ char *agent_identity;
char *ca_cert_file;
char *client_cert_file;
char *private_key_file;
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,
void __connman_service_list(DBusMessageIter *iter, void *user_data)
{
+ if (service_list == NULL)
+ return;
+
g_sequence_foreach(service_list, append_path, iter);
}
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;
return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
}
-static enum connman_service_state combine_state(
- enum connman_service_state state_a,
- enum connman_service_state state_b)
+static int service_load(struct connman_service *service)
{
- enum connman_service_state result;
+ GKeyFile *keyfile;
+ GError *error = NULL;
+ gsize length;
+ gchar *str;
+ connman_bool_t autoconnect;
+ unsigned int ssid_len;
+ int err = 0;
- if (state_a == state_b) {
- result = state_a;
- goto done;
- }
+ DBG("service %p", service);
- if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
- result = state_b;
- goto done;
- }
+ keyfile = connman_storage_load_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
- if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
- result = state_a;
- goto done;
- }
+ switch (service->type) {
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ case CONNMAN_SERVICE_TYPE_SYSTEM:
+ case CONNMAN_SERVICE_TYPE_ETHERNET:
+ case CONNMAN_SERVICE_TYPE_GPS:
+ case CONNMAN_SERVICE_TYPE_VPN:
+ case CONNMAN_SERVICE_TYPE_GADGET:
+ break;
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ if (service->name == NULL) {
+ gchar *name;
- if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
- result = state_b;
- goto done;
- }
+ name = g_key_file_get_string(keyfile,
+ service->identifier, "Name", NULL);
+ if (name != NULL) {
+ g_free(service->name);
+ service->name = name;
+ }
- if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
- result = state_a;
- goto done;
- }
+ if (service->network != NULL)
+ connman_network_set_name(service->network,
+ name);
+ }
- 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;
- goto done;
- }
+ if (service->network &&
+ connman_network_get_blob(service->network,
+ "WiFi.SSID", &ssid_len) == NULL) {
+ gchar *hex_ssid;
- 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;
- goto done;
- }
+ hex_ssid = g_key_file_get_string(keyfile,
+ service->identifier,
+ "SSID", NULL);
- 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;
- goto done;
- }
+ if (hex_ssid != NULL) {
+ gchar *ssid;
+ unsigned int i, j = 0, hex;
+ size_t hex_ssid_len = strlen(hex_ssid);
- 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;
- goto done;
- }
+ ssid = g_try_malloc0(hex_ssid_len / 2);
+ if (ssid == NULL) {
+ g_free(hex_ssid);
+ err = -ENOMEM;
+ 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;
- goto done;
- }
+ for (i = 0; i < hex_ssid_len; i += 2) {
+ sscanf(hex_ssid + i, "%02x", &hex);
+ ssid[j++] = hex;
+ }
- 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;
- goto done;
+ connman_network_set_blob(service->network,
+ "WiFi.SSID", ssid, hex_ssid_len / 2);
+ }
+
+ g_free(hex_ssid);
+ }
+ /* fall through */
+
+ case CONNMAN_SERVICE_TYPE_WIMAX:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ service->favorite = g_key_file_get_boolean(keyfile,
+ service->identifier, "Favorite", NULL);
+
+ autoconnect = g_key_file_get_boolean(keyfile,
+ service->identifier, "AutoConnect", &error);
+ if (error == NULL)
+ service->autoconnect = autoconnect;
+ g_clear_error(&error);
+
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Failure", NULL);
+ if (str != NULL) {
+ if (service->favorite == FALSE)
+ service->state_ipv4 = service->state_ipv6 =
+ CONNMAN_SERVICE_STATE_FAILURE;
+ service->error = string2error(str);
+ g_free(str);
+ }
+ break;
}
- if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
- if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT)
- result = state_b;
- else
- result = state_a;
- goto done;
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Modified", NULL);
+ if (str != NULL) {
+ g_time_val_from_iso8601(str, &service->modified);
+ g_free(str);
}
- if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
- if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT)
- result = state_a;
- else
- result = state_b;
- goto done;
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Passphrase", NULL);
+ if (str != NULL) {
+ g_free(service->passphrase);
+ service->passphrase = str;
}
- if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
- result = state_a;
- goto done;
+ if (service->ipconfig_ipv4 != NULL)
+ __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
+ service->identifier, "IPv4.");
+
+ if (service->ipconfig_ipv6 != NULL)
+ __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
+ service->identifier, "IPv6.");
+
+ service->nameservers_config = g_key_file_get_string_list(keyfile,
+ service->identifier, "Nameservers", &length, NULL);
+ if (service->nameservers_config != NULL && length == 0) {
+ g_strfreev(service->nameservers_config);
+ service->nameservers_config = NULL;
}
- if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
- result = state_b;
- goto done;
+ service->domains = g_key_file_get_string_list(keyfile,
+ service->identifier, "Domains", &length, NULL);
+ if (service->domains != NULL && length == 0) {
+ g_strfreev(service->domains);
+ service->domains = NULL;
}
- result = CONNMAN_SERVICE_STATE_FAILURE;
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Proxy.Method", NULL);
+ if (str != NULL)
+ service->proxy_config = string2proxymethod(str);
-done:
- return result;
-}
+ g_free(str);
-static connman_bool_t is_connecting_state(struct connman_service *service,
- enum connman_service_state state)
-{
- switch (state) {
- case CONNMAN_SERVICE_STATE_UNKNOWN:
- case CONNMAN_SERVICE_STATE_IDLE:
- case CONNMAN_SERVICE_STATE_FAILURE:
- if (service->network != NULL)
- return connman_network_get_connecting(service->network);
- case CONNMAN_SERVICE_STATE_DISCONNECT:
- case CONNMAN_SERVICE_STATE_READY:
- case CONNMAN_SERVICE_STATE_ONLINE:
- break;
- case CONNMAN_SERVICE_STATE_ASSOCIATION:
- case CONNMAN_SERVICE_STATE_CONFIGURATION:
- return TRUE;
+ service->proxies = g_key_file_get_string_list(keyfile,
+ service->identifier, "Proxy.Servers", &length, NULL);
+ if (service->proxies != NULL && length == 0) {
+ g_strfreev(service->proxies);
+ service->proxies = NULL;
}
- return FALSE;
-}
+ service->excludes = g_key_file_get_string_list(keyfile,
+ service->identifier, "Proxy.Excludes", &length, NULL);
+ if (service->excludes != NULL && length == 0) {
+ g_strfreev(service->excludes);
+ service->excludes = NULL;
+ }
-static connman_bool_t is_connected_state(const struct connman_service *service,
- enum connman_service_state state)
-{
- switch (state) {
- case CONNMAN_SERVICE_STATE_UNKNOWN:
- case CONNMAN_SERVICE_STATE_IDLE:
- case CONNMAN_SERVICE_STATE_ASSOCIATION:
- case CONNMAN_SERVICE_STATE_CONFIGURATION:
- case CONNMAN_SERVICE_STATE_DISCONNECT:
- case CONNMAN_SERVICE_STATE_FAILURE:
- break;
- case CONNMAN_SERVICE_STATE_READY:
- case CONNMAN_SERVICE_STATE_ONLINE:
- return TRUE;
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Proxy.URL", NULL);
+ if (str != NULL) {
+ g_free(service->pac);
+ service->pac = str;
}
- return FALSE;
-}
+done:
+ g_key_file_free(keyfile);
-static connman_bool_t is_connecting(struct connman_service *service)
-{
- return is_connecting_state(service, service->state);
+ return err;
}
-static connman_bool_t is_connected(struct connman_service *service)
+static int service_save(struct connman_service *service)
{
- return is_connected_state(service, service->state);
-}
+ GKeyFile *keyfile;
+ gchar *str;
+ guint freq;
+ const char *cst_str = NULL;
+ int err = 0;
-static void update_nameservers(struct connman_service *service)
-{
- const char *ifname;
+ DBG("service %p", service);
- if (service->ipconfig_ipv4)
- ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv4);
- else if (service->ipconfig_ipv6)
- ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv6);
- else
- ifname = NULL;
+ keyfile = __connman_storage_open_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
- if (ifname == NULL)
- return;
+ if (service->name != NULL)
+ g_key_file_set_string(keyfile, service->identifier,
+ "Name", service->name);
- switch (combine_state(service->state_ipv4, service->state_ipv6)) {
- case CONNMAN_SERVICE_STATE_UNKNOWN:
- case CONNMAN_SERVICE_STATE_IDLE:
- case CONNMAN_SERVICE_STATE_ASSOCIATION:
- case CONNMAN_SERVICE_STATE_CONFIGURATION:
- return;
- case CONNMAN_SERVICE_STATE_FAILURE:
- case CONNMAN_SERVICE_STATE_DISCONNECT:
- connman_resolver_remove_all(ifname);
- return;
- case CONNMAN_SERVICE_STATE_READY:
- case CONNMAN_SERVICE_STATE_ONLINE:
+ switch (service->type) {
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ case CONNMAN_SERVICE_TYPE_SYSTEM:
+ case CONNMAN_SERVICE_TYPE_ETHERNET:
+ case CONNMAN_SERVICE_TYPE_GPS:
+ case CONNMAN_SERVICE_TYPE_VPN:
+ case CONNMAN_SERVICE_TYPE_GADGET:
break;
- }
-
- connman_resolver_remove_all(ifname);
-
- if (service->nameservers_config != NULL) {
- int i;
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ if (service->network) {
+ const unsigned char *ssid;
+ unsigned int ssid_len = 0;
- for (i = 0; service->nameservers_config[i] != NULL; i++) {
- connman_resolver_append(ifname, NULL,
- service->nameservers_config[i]);
- }
- } else if (service->nameservers != NULL) {
- int i;
+ ssid = connman_network_get_blob(service->network,
+ "WiFi.SSID", &ssid_len);
- for (i = 0; service->nameservers[i] != NULL; i++) {
- connman_resolver_append(ifname, NULL,
- service->nameservers[i]);
- }
- }
+ if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
+ char *identifier = service->identifier;
+ GString *str;
+ unsigned int i;
- if (service->domains != NULL) {
- int i;
+ str = g_string_sized_new(ssid_len * 2);
+ if (str == NULL) {
+ err = -ENOMEM;
+ goto done;
+ }
- for (i = 0; service->domains[i]; i++)
- connman_resolver_append(ifname, service->domains[i],
- NULL);
- } else if (service->domainname != NULL)
- connman_resolver_append(ifname, service->domainname, NULL);
+ for (i = 0; i < ssid_len; i++)
+ g_string_append_printf(str,
+ "%02x", ssid[i]);
- connman_resolver_flush();
-}
+ g_key_file_set_string(keyfile, identifier,
+ "SSID", str->str);
-int __connman_service_nameserver_append(struct connman_service *service,
- const char *nameserver)
-{
- int len;
+ g_string_free(str, TRUE);
+ }
- DBG("service %p nameserver %s", service, nameserver);
+ freq = connman_network_get_frequency(service->network);
+ g_key_file_set_integer(keyfile, service->identifier,
+ "Frequency", freq);
+ }
+ /* fall through */
- if (nameserver == NULL)
- return -EINVAL;
+ case CONNMAN_SERVICE_TYPE_WIMAX:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ g_key_file_set_boolean(keyfile, service->identifier,
+ "Favorite", service->favorite);
- if (service->nameservers != NULL) {
- int i;
+ if (service->favorite == TRUE)
+ g_key_file_set_boolean(keyfile, service->identifier,
+ "AutoConnect", service->autoconnect);
- for (i = 0; service->nameservers[i] != NULL; i++)
- if (g_strcmp0(service->nameservers[i], nameserver) == 0)
- return -EEXIST;
+ if (service->state_ipv4 == CONNMAN_SERVICE_STATE_FAILURE ||
+ service->state_ipv6 == CONNMAN_SERVICE_STATE_FAILURE) {
+ const char *failure = error2string(service->error);
+ if (failure != NULL)
+ g_key_file_set_string(keyfile,
+ service->identifier,
+ "Failure", failure);
+ } else {
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Failure", NULL);
+ }
+ break;
+ }
- len = g_strv_length(service->nameservers);
- service->nameservers = g_try_renew(char *, service->nameservers,
- len + 2);
- } else {
- len = 0;
- service->nameservers = g_try_new0(char *, len + 2);
+ str = g_time_val_to_iso8601(&service->modified);
+ if (str != NULL) {
+ g_key_file_set_string(keyfile, service->identifier,
+ "Modified", str);
+ g_free(str);
}
- if (service->nameservers == NULL)
- return -ENOMEM;
+ if (service->passphrase != NULL && strlen(service->passphrase) > 0)
+ g_key_file_set_string(keyfile, service->identifier,
+ "Passphrase", service->passphrase);
+ else
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Passphrase", NULL);
- service->nameservers[len] = g_strdup(nameserver);
- service->nameservers[len + 1] = NULL;
+ if (service->ipconfig_ipv4 != NULL)
+ __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
+ service->identifier, "IPv4.");
- update_nameservers(service);
+ if (service->ipconfig_ipv6 != NULL)
+ __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
+ service->identifier, "IPv6.");
- return 0;
-}
+ if (service->nameservers_config != NULL) {
+ guint len = g_strv_length(service->nameservers_config);
-int __connman_service_nameserver_remove(struct connman_service *service,
- const char *nameserver)
-{
- char **servers;
- int len, i, j;
+ g_key_file_set_string_list(keyfile, service->identifier,
+ "Nameservers",
+ (const gchar **) service->nameservers_config, len);
+ } else
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Nameservers", NULL);
- DBG("service %p nameserver %s", service, nameserver);
+ if (service->domains != NULL) {
+ guint len = g_strv_length(service->domains);
- if (nameserver == NULL)
- return -EINVAL;
+ g_key_file_set_string_list(keyfile, service->identifier,
+ "Domains",
+ (const gchar **) service->domains, len);
+ } else
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Domains", NULL);
- if (service->nameservers == NULL)
- return 0;
+ cst_str = proxymethod2string(service->proxy_config);
+ if (cst_str != NULL)
+ g_key_file_set_string(keyfile, service->identifier,
+ "Proxy.Method", cst_str);
- len = g_strv_length(service->nameservers);
- if (len == 1) {
- if (g_strcmp0(service->nameservers[0], nameserver) != 0)
- return 0;
+ if (service->proxies != NULL) {
+ guint len = g_strv_length(service->proxies);
- g_strfreev(service->nameservers);
- service->nameservers = NULL;
+ g_key_file_set_string_list(keyfile, service->identifier,
+ "Proxy.Servers",
+ (const gchar **) service->proxies, len);
+ } else
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Proxy.Servers", NULL);
- return 0;
- }
+ if (service->excludes != NULL) {
+ guint len = g_strv_length(service->excludes);
- servers = g_try_new0(char *, len - 1);
- if (servers == NULL)
- return -ENOMEM;
+ g_key_file_set_string_list(keyfile, service->identifier,
+ "Proxy.Excludes",
+ (const gchar **) service->excludes, len);
+ } else
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Proxy.Excludes", NULL);
- for (i = 0, j = 0; i < len; i++) {
- if (g_strcmp0(service->nameservers[i], nameserver) != 0) {
- servers[j] = g_strdup(service->nameservers[i]);
- j++;
- }
- }
- servers[len - 2] = NULL;
+ if (service->pac != NULL && strlen(service->pac) > 0)
+ g_key_file_set_string(keyfile, service->identifier,
+ "Proxy.URL", service->pac);
+ else
+ g_key_file_remove_key(keyfile, service->identifier,
+ "Proxy.URL", NULL);
- g_strfreev(service->nameservers);
- service->nameservers = servers;
+done:
+ __connman_storage_save_service(keyfile, service->identifier);
- update_nameservers(service);
+ g_key_file_free(keyfile);
- return 0;
+ return err;
}
-void __connman_service_nameserver_clear(struct connman_service *service)
+static guint changed_timeout = 0;
+
+static gboolean notify_services_changed(gpointer user_data)
{
- g_strfreev(service->nameservers);
- service->nameservers = NULL;
+ changed_timeout = 0;
- update_nameservers(service);
+ connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE, "Services",
+ DBUS_TYPE_OBJECT_PATH, __connman_service_list,
+ NULL);
+
+ return FALSE;
}
-static void nameserver_add_routes(int index, char **nameservers,
- const char *gw)
+static void services_changed(gboolean delayed)
{
- int i, ret, family;
- struct addrinfo hints;
- struct addrinfo *addr;
-
- for (i = 0; nameservers[i] != NULL; i++) {
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_flags = AI_NUMERICHOST;
- addr = NULL;
+ DBG("");
- ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
- if (ret == EAI_NONAME)
- family = AF_INET; /* use the IPv4 as a default */
- else if (ret != 0)
- continue;
- else
- family = addr->ai_family;
+ if (changed_timeout > 0) {
+ g_source_remove(changed_timeout);
+ changed_timeout = 0;
+ }
- if (family == AF_INET) {
- if (connman_inet_compare_subnet(index,
- nameservers[i]) != TRUE)
- connman_inet_add_host_route(index,
- nameservers[i], gw);
- } else if (family == AF_INET6)
- connman_inet_add_ipv6_host_route(index,
- nameservers[i], gw);
+ if (__connman_connection_update_gateway() == TRUE) {
+ notify_services_changed(NULL);
+ return;
+ }
- freeaddrinfo(addr);
+ if (delayed == FALSE) {
+ notify_services_changed(NULL);
+ return;
}
+
+ changed_timeout = g_timeout_add_seconds(1, notify_services_changed,
+ NULL);
}
-static void nameserver_del_routes(int index, char **nameservers)
+static enum connman_service_state combine_state(
+ enum connman_service_state state_a,
+ enum connman_service_state state_b)
{
- int i, ret, family;
- struct addrinfo hints;
- struct addrinfo *addr;
-
- for (i = 0; nameservers[i] != NULL; i++) {
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_flags = AI_NUMERICHOST;
- addr = NULL;
+ enum connman_service_state result;
- ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
- if (ret == EAI_NONAME)
- family = AF_INET; /* use the IPv4 as a default */
- else if (ret != 0)
- continue;
- else
- family = addr->ai_family;
+ if (state_a == state_b) {
+ result = state_a;
+ goto done;
+ }
- if (family == AF_INET)
- connman_inet_del_host_route(index, nameservers[i]);
- else if (family == AF_INET6)
- connman_inet_del_ipv6_host_route(index,
- nameservers[i]);
+ if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
+ result = state_b;
+ goto done;
+ }
- freeaddrinfo(addr);
+ if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
+ result = state_a;
+ goto done;
}
-}
-void __connman_service_nameserver_add_routes(struct connman_service *service,
- const char *gw)
-{
- int index = -1;
+ if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
+ result = state_b;
+ goto done;
+ }
- if (service == NULL)
- return;
+ if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
+ result = state_a;
+ goto done;
+ }
- if (service->network != NULL)
- index = connman_network_get_index(service->network);
- else if (service->provider != NULL)
- index = connman_provider_get_index(service->provider);
+ if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
+ result = state_a;
+ goto done;
+ }
- if (service->nameservers_config != NULL) {
- /*
- * Configured nameserver takes preference over the
- * discoverd nameserver gathered from DHCP, VPN, etc.
- */
- nameserver_add_routes(index, service->nameservers_config, gw);
- } else if (service->nameservers != NULL) {
- /*
- * We add nameservers host routes for nameservers that
- * are not on our subnet. For those who are, the subnet
- * route will be installed by the time the dns proxy code
- * tries to reach them. The subnet route is installed
- * when setting the interface IP address.
- */
- nameserver_add_routes(index, service->nameservers, gw);
+ if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
+ result = state_b;
+ goto done;
}
-}
-void __connman_service_nameserver_del_routes(struct connman_service *service)
-{
- int index = -1;
+ if (state_a == CONNMAN_SERVICE_STATE_READY) {
+ result = state_a;
+ goto done;
+ }
- if (service == NULL)
- return;
+ if (state_b == CONNMAN_SERVICE_STATE_READY) {
+ result = state_b;
+ goto done;
+ }
- if (service->network != NULL)
- index = connman_network_get_index(service->network);
- else if (service->provider != NULL)
- index = connman_provider_get_index(service->provider);
+ if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+ result = state_a;
+ goto done;
+ }
- if (service->nameservers_config != NULL)
- nameserver_del_routes(index, service->nameservers_config);
- else if (service->nameservers != NULL)
- nameserver_del_routes(index, service->nameservers);
-}
+ if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+ result = state_b;
+ goto done;
+ }
-static struct connman_stats *stats_get(struct connman_service *service)
-{
- if (service->roaming == TRUE)
- return &service->stats_roaming;
- else
- return &service->stats;
+ if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+ result = state_b;
+ goto done;
+ }
+
+ if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT) {
+ result = state_b;
+ goto done;
+ }
+
+ result = CONNMAN_SERVICE_STATE_FAILURE;
+
+done:
+ return result;
}
-static connman_bool_t stats_enabled(struct connman_service *service)
+static connman_bool_t is_connecting_state(struct connman_service *service,
+ enum connman_service_state state)
{
- struct connman_stats *stats = stats_get(service);
+ switch (state) {
+ case CONNMAN_SERVICE_STATE_UNKNOWN:
+ case CONNMAN_SERVICE_STATE_IDLE:
+ case CONNMAN_SERVICE_STATE_FAILURE:
+ if (service->network != NULL)
+ return connman_network_get_connecting(service->network);
+ case CONNMAN_SERVICE_STATE_DISCONNECT:
+ case CONNMAN_SERVICE_STATE_READY:
+ case CONNMAN_SERVICE_STATE_ONLINE:
+ break;
+ case CONNMAN_SERVICE_STATE_ASSOCIATION:
+ case CONNMAN_SERVICE_STATE_CONFIGURATION:
+ return TRUE;
+ }
- return stats->enabled;
+ return FALSE;
}
-static void stats_start(struct connman_service *service)
+static connman_bool_t is_connected_state(const struct connman_service *service,
+ enum connman_service_state state)
{
- struct connman_stats *stats = stats_get(service);
-
- DBG("service %p", service);
+ switch (state) {
+ case CONNMAN_SERVICE_STATE_UNKNOWN:
+ case CONNMAN_SERVICE_STATE_IDLE:
+ case CONNMAN_SERVICE_STATE_ASSOCIATION:
+ case CONNMAN_SERVICE_STATE_CONFIGURATION:
+ case CONNMAN_SERVICE_STATE_DISCONNECT:
+ case CONNMAN_SERVICE_STATE_FAILURE:
+ break;
+ case CONNMAN_SERVICE_STATE_READY:
+ case CONNMAN_SERVICE_STATE_ONLINE:
+ return TRUE;
+ }
- if (stats->timer == NULL)
- return;
+ return FALSE;
+}
- stats->enabled = TRUE;
- stats->data_last.time = stats->data.time;
+static connman_bool_t is_connecting(struct connman_service *service)
+{
+ return is_connecting_state(service, service->state);
+}
- g_timer_start(stats->timer);
+static connman_bool_t is_connected(struct connman_service *service)
+{
+ return is_connected_state(service, service->state);
}
-static void stats_stop(struct connman_service *service)
+static void update_nameservers(struct connman_service *service)
{
- struct connman_stats *stats = stats_get(service);
- unsigned int seconds;
+ const char *ifname;
- DBG("service %p", service);
+ if (service->ipconfig_ipv4)
+ ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv4);
+ else if (service->ipconfig_ipv6)
+ ifname = connman_ipconfig_get_ifname(service->ipconfig_ipv6);
+ else
+ ifname = NULL;
- if (stats->timer == NULL)
+ if (ifname == NULL)
return;
- if (stats->enabled == FALSE)
+ switch (combine_state(service->state_ipv4, service->state_ipv6)) {
+ case CONNMAN_SERVICE_STATE_UNKNOWN:
+ case CONNMAN_SERVICE_STATE_IDLE:
+ case CONNMAN_SERVICE_STATE_ASSOCIATION:
+ case CONNMAN_SERVICE_STATE_CONFIGURATION:
+ return;
+ case CONNMAN_SERVICE_STATE_FAILURE:
+ case CONNMAN_SERVICE_STATE_DISCONNECT:
+ connman_resolver_remove_all(ifname);
return;
+ case CONNMAN_SERVICE_STATE_READY:
+ case CONNMAN_SERVICE_STATE_ONLINE:
+ break;
+ }
- g_timer_stop(stats->timer);
+ if (service->nameservers_config != NULL) {
+ int i;
- seconds = g_timer_elapsed(stats->timer, NULL);
- stats->data.time = stats->data_last.time + seconds;
+ for (i = 0; service->nameservers_config[i] != NULL; i++) {
+ connman_resolver_append(ifname, NULL,
+ service->nameservers_config[i]);
+ }
+ } else if (service->nameservers != NULL) {
+ int i;
- stats->enabled = FALSE;
+ for (i = 0; service->nameservers[i] != NULL; i++) {
+ connman_resolver_append(ifname, NULL,
+ service->nameservers[i]);
+ }
+ }
+
+ if (service->domains != NULL) {
+ int i;
+
+ for (i = 0; service->domains[i]; i++)
+ connman_resolver_append(ifname, service->domains[i],
+ NULL);
+ } else if (service->domainname != NULL)
+ connman_resolver_append(ifname, service->domainname, NULL);
+
+ connman_resolver_flush();
}
-static void reset_stats(struct connman_service *service)
+/*
+ * 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, gboolean is_auto)
{
- DBG("service %p", service);
+ char **nameservers;
+ int len, i;
- /* home */
- service->stats.valid = FALSE;
+ DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
- service->stats.data.rx_packets = 0;
- service->stats.data.tx_packets = 0;
- service->stats.data.rx_bytes = 0;
- service->stats.data.tx_bytes = 0;
- service->stats.data.rx_errors = 0;
- service->stats.data.tx_errors = 0;
- service->stats.data.rx_dropped = 0;
- service->stats.data.tx_dropped = 0;
- service->stats.data.time = 0;
- service->stats.data_last.time = 0;
+ if (nameserver == NULL)
+ return -EINVAL;
- g_timer_reset(service->stats.timer);
+ if (is_auto == TRUE)
+ nameservers = service->nameservers_auto;
+ else
+ nameservers = service->nameservers;
- /* roaming */
- service->stats_roaming.valid = FALSE;
+ for (i = 0; nameservers != NULL && nameservers[i] != NULL; i++)
+ if (g_strcmp0(nameservers[i], nameserver) == 0)
+ return -EEXIST;
- service->stats_roaming.data.rx_packets = 0;
- service->stats_roaming.data.tx_packets = 0;
- service->stats_roaming.data.rx_bytes = 0;
- service->stats_roaming.data.tx_bytes = 0;
- service->stats_roaming.data.rx_errors = 0;
- service->stats_roaming.data.tx_errors = 0;
- service->stats_roaming.data.rx_dropped = 0;
- service->stats_roaming.data.tx_dropped = 0;
- service->stats_roaming.data.time = 0;
- service->stats_roaming.data_last.time = 0;
+ if (nameservers != NULL) {
+ len = g_strv_length(nameservers);
+ nameservers = g_try_renew(char *, nameservers, len + 2);
+ } else {
+ len = 0;
+ nameservers = g_try_new0(char *, len + 2);
+ }
- g_timer_reset(service->stats_roaming.timer);
+ if (nameservers == NULL)
+ return -ENOMEM;
+
+ nameservers[len] = g_strdup(nameserver);
+ if (nameservers[len] == NULL)
+ return -ENOMEM;
+
+ nameservers[len + 1] = NULL;
+
+ if (is_auto == TRUE) {
+ service->nameservers_auto = nameservers;
+ } else {
+ service->nameservers = nameservers;
+ update_nameservers(service);
+ }
+
+ return 0;
}
-static struct connman_service *get_default(void)
+int __connman_service_nameserver_remove(struct connman_service *service,
+ const char *nameserver, gboolean is_auto)
{
- struct connman_service *service;
- GSequenceIter *iter;
+ char **servers, **nameservers;
+ gboolean found = FALSE;
+ int len, i, j;
- iter = g_sequence_get_begin_iter(service_list);
+ DBG("service %p nameserver %s auto %d", service, nameserver, is_auto);
- if (g_sequence_iter_is_end(iter) == TRUE)
- return NULL;
+ if (nameserver == NULL)
+ return -EINVAL;
- service = g_sequence_get(iter);
+ if (is_auto == TRUE)
+ nameservers = service->nameservers_auto;
+ else
+ nameservers = service->nameservers;
- if (is_connected(service) == FALSE)
- return NULL;
+ if (nameservers == NULL)
+ return 0;
- return service;
-}
+ for (i = 0; nameservers != NULL && nameservers[i] != NULL; i++)
+ if (g_strcmp0(nameservers[i], nameserver) == 0) {
+ found = TRUE;
+ break;
+ }
-static void default_changed(void)
-{
- struct connman_service *service = get_default();
+ if (found == FALSE)
+ return 0;
- __connman_notifier_default_changed(service);
-}
+ len = g_strv_length(nameservers);
-const char *__connman_service_default(void)
-{
- struct connman_service *service;
+ if (len == 1) {
+ g_strfreev(nameservers);
+ if (is_auto == TRUE)
+ service->nameservers_auto = NULL;
+ else
+ service->nameservers = NULL;
- service = get_default();
- if (service == NULL)
- return "";
+ return 0;
+ }
- return __connman_service_type2string(service->type);
-}
+ servers = g_try_new0(char *, len);
+ if (servers == NULL)
+ return -ENOMEM;
-static void state_changed(struct connman_service *service)
-{
- const char *str;
+ for (i = 0, j = 0; i < len; 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;
- __connman_notifier_service_state_changed(service, service->state);
+ g_strfreev(nameservers);
+ nameservers = servers;
- str = state2string(service->state);
- if (str == NULL)
- return;
+ if (is_auto == TRUE) {
+ service->nameservers_auto = nameservers;
+ } else {
+ service->nameservers = nameservers;
+ update_nameservers(service);
+ }
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "State",
- DBUS_TYPE_STRING, &str);
+ return 0;
}
-static void strength_changed(struct connman_service *service)
+void __connman_service_nameserver_clear(struct connman_service *service)
{
- if (service->strength == 0)
- return;
+ g_strfreev(service->nameservers);
+ service->nameservers = NULL;
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Strength",
- DBUS_TYPE_BYTE, &service->strength);
+ update_nameservers(service);
}
-static void favorite_changed(struct connman_service *service)
+static void nameserver_add_routes(int index, char **nameservers,
+ const char *gw)
{
- if (service->path == NULL)
- return;
+ int i, ret, family;
+ struct addrinfo hints;
+ struct addrinfo *addr;
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Favorite",
- DBUS_TYPE_BOOLEAN, &service->favorite);
-}
+ for (i = 0; nameservers[i] != NULL; i++) {
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ addr = NULL;
-static void immutable_changed(struct connman_service *service)
-{
- if (service->path == NULL)
- return;
+ ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
+ if (ret == EAI_NONAME)
+ family = AF_INET; /* use the IPv4 as a default */
+ else if (ret != 0)
+ continue;
+ else
+ family = addr->ai_family;
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Immutable",
- DBUS_TYPE_BOOLEAN, &service->immutable);
+ if (family == AF_INET) {
+ if (connman_inet_compare_subnet(index,
+ nameservers[i]) != TRUE)
+ connman_inet_add_host_route(index,
+ nameservers[i], gw);
+ } else if (family == AF_INET6)
+ connman_inet_add_ipv6_host_route(index,
+ nameservers[i], gw);
+
+ freeaddrinfo(addr);
+ }
}
-static void roaming_changed(struct connman_service *service)
+static void nameserver_del_routes(int index, char **nameservers)
{
- if (service->path == NULL)
- return;
+ int i, ret, family;
+ struct addrinfo hints;
+ struct addrinfo *addr;
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Roaming",
- DBUS_TYPE_BOOLEAN, &service->roaming);
-}
+ for (i = 0; nameservers[i] != NULL; i++) {
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ addr = NULL;
-static void autoconnect_changed(struct connman_service *service)
-{
- if (service->path == NULL)
- return;
+ ret = getaddrinfo(nameservers[i], NULL, &hints, &addr);
+ if (ret == EAI_NONAME)
+ family = AF_INET; /* use the IPv4 as a default */
+ else if (ret != 0)
+ continue;
+ else
+ family = addr->ai_family;
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "AutoConnect",
- DBUS_TYPE_BOOLEAN, &service->autoconnect);
+ if (family == AF_INET)
+ connman_inet_del_host_route(index, nameservers[i]);
+ else if (family == AF_INET6)
+ connman_inet_del_ipv6_host_route(index,
+ nameservers[i]);
+
+ freeaddrinfo(addr);
+ }
}
-static void passphrase_changed(struct connman_service *service)
+void __connman_service_nameserver_add_routes(struct connman_service *service,
+ const char *gw)
{
- dbus_bool_t required;
+ int index = -1;
- 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:
+ if (service == NULL)
return;
- case CONNMAN_SERVICE_TYPE_WIFI:
- 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;
- }
- break;
- }
+ if (service->network != NULL)
+ index = connman_network_get_index(service->network);
+ else if (service->provider != NULL)
+ index = connman_provider_get_index(service->provider);
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "PassphraseRequired",
- DBUS_TYPE_BOOLEAN, &required);
+ if (service->nameservers_config != NULL) {
+ /*
+ * Configured nameserver takes preference over the
+ * discoverd nameserver gathered from DHCP, VPN, etc.
+ */
+ nameserver_add_routes(index, service->nameservers_config, gw);
+ } else if (service->nameservers != NULL) {
+ /*
+ * We add nameservers host routes for nameservers that
+ * are not on our subnet. For those who are, the subnet
+ * route will be installed by the time the dns proxy code
+ * tries to reach them. The subnet route is installed
+ * when setting the interface IP address.
+ */
+ nameserver_add_routes(index, service->nameservers, gw);
+ }
}
-static void login_changed(struct connman_service *service)
+void __connman_service_nameserver_del_routes(struct connman_service *service)
{
- dbus_bool_t required = service->login_required;
+ int index = -1;
- if (service->path == NULL)
+ if (service == NULL)
return;
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "LoginRequired",
- DBUS_TYPE_BOOLEAN, &required);
+ if (service->network != NULL)
+ index = connman_network_get_index(service->network);
+ else if (service->provider != NULL)
+ index = connman_provider_get_index(service->provider);
+
+ if (service->nameservers_config != NULL)
+ nameserver_del_routes(index, service->nameservers_config);
+ else if (service->nameservers != NULL)
+ nameserver_del_routes(index, service->nameservers);
}
-static void append_security(DBusMessageIter *iter, void *user_data)
+static struct connman_stats *stats_get(struct connman_service *service)
{
- 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);
+ if (service->roaming == TRUE)
+ return &service->stats_roaming;
+ else
+ return &service->stats;
}
-static void append_ethernet(DBusMessageIter *iter, void *user_data)
+static connman_bool_t stats_enabled(struct connman_service *service)
{
- struct connman_service *service = user_data;
+ struct connman_stats *stats = stats_get(service);
- if (service->ipconfig_ipv4 != NULL)
- __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
- iter);
- else if (service->ipconfig_ipv6 != NULL)
- __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
- iter);
+ return stats->enabled;
}
-static void append_ipv4(DBusMessageIter *iter, void *user_data)
+static void stats_start(struct connman_service *service)
{
- struct connman_service *service = user_data;
+ struct connman_stats *stats = stats_get(service);
- DBG("ipv4 %p state %s", service->ipconfig_ipv4,
- state2string(service->state_ipv4));
+ DBG("service %p", service);
- if (is_connected_state(service, service->state_ipv4) == FALSE)
+ if (stats->timer == NULL)
+ return;
+
+ stats->enabled = TRUE;
+ stats->data_last.time = stats->data.time;
+
+ g_timer_start(stats->timer);
+}
+
+static void stats_stop(struct connman_service *service)
+{
+ struct connman_stats *stats = stats_get(service);
+ unsigned int seconds;
+
+ DBG("service %p", service);
+
+ if (stats->timer == NULL)
+ return;
+
+ if (stats->enabled == FALSE)
+ return;
+
+ g_timer_stop(stats->timer);
+
+ seconds = g_timer_elapsed(stats->timer, NULL);
+ stats->data.time = stats->data_last.time + seconds;
+
+ stats->enabled = FALSE;
+}
+
+static void reset_stats(struct connman_service *service)
+{
+ DBG("service %p", service);
+
+ /* home */
+ service->stats.valid = FALSE;
+
+ service->stats.data.rx_packets = 0;
+ service->stats.data.tx_packets = 0;
+ service->stats.data.rx_bytes = 0;
+ service->stats.data.tx_bytes = 0;
+ service->stats.data.rx_errors = 0;
+ service->stats.data.tx_errors = 0;
+ service->stats.data.rx_dropped = 0;
+ service->stats.data.tx_dropped = 0;
+ service->stats.data.time = 0;
+ service->stats.data_last.time = 0;
+
+ g_timer_reset(service->stats.timer);
+
+ /* roaming */
+ service->stats_roaming.valid = FALSE;
+
+ service->stats_roaming.data.rx_packets = 0;
+ service->stats_roaming.data.tx_packets = 0;
+ service->stats_roaming.data.rx_bytes = 0;
+ service->stats_roaming.data.tx_bytes = 0;
+ service->stats_roaming.data.rx_errors = 0;
+ service->stats_roaming.data.tx_errors = 0;
+ service->stats_roaming.data.rx_dropped = 0;
+ service->stats_roaming.data.tx_dropped = 0;
+ service->stats_roaming.data.time = 0;
+ service->stats_roaming.data_last.time = 0;
+
+ g_timer_reset(service->stats_roaming.timer);
+}
+
+static struct connman_service *get_default(void)
+{
+ struct connman_service *service;
+ GSequenceIter *iter;
+
+ iter = g_sequence_get_begin_iter(service_list);
+
+ if (g_sequence_iter_is_end(iter) == TRUE)
+ return NULL;
+
+ service = g_sequence_get(iter);
+
+ if (is_connected(service) == FALSE)
+ return NULL;
+
+ return service;
+}
+
+static void default_changed(void)
+{
+ struct connman_service *service = get_default();
+
+ __connman_notifier_default_changed(service);
+}
+
+static void state_changed(struct connman_service *service)
+{
+ const char *str;
+
+ __connman_notifier_service_state_changed(service, service->state);
+
+ str = state2string(service->state);
+ if (str == NULL)
+ return;
+
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "State",
+ DBUS_TYPE_STRING, &str);
+}
+
+static void strength_changed(struct connman_service *service)
+{
+ if (service->strength == 0)
+ return;
+
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "Strength",
+ DBUS_TYPE_BYTE, &service->strength);
+}
+
+static void favorite_changed(struct connman_service *service)
+{
+ if (service->path == NULL)
+ return;
+
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "Favorite",
+ DBUS_TYPE_BOOLEAN, &service->favorite);
+}
+
+static void immutable_changed(struct connman_service *service)
+{
+ if (service->path == NULL)
+ return;
+
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "Immutable",
+ DBUS_TYPE_BOOLEAN, &service->immutable);
+}
+
+static void roaming_changed(struct connman_service *service)
+{
+ if (service->path == NULL)
+ return;
+
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "Roaming",
+ DBUS_TYPE_BOOLEAN, &service->roaming);
+}
+
+static void autoconnect_changed(struct connman_service *service)
+{
+ if (service->path == NULL)
+ return;
+
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "AutoConnect",
+ DBUS_TYPE_BOOLEAN, &service->autoconnect);
+}
+
+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);
+
+ /*
+ * 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_PSK:
+ case CONNMAN_SERVICE_SECURITY_WPA:
+ case CONNMAN_SERVICE_SECURITY_RSN:
+ 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;
+ }
+ }
+}
+
+static void append_ethernet(DBusMessageIter *iter, void *user_data)
+{
+ struct connman_service *service = user_data;
+
+ if (service->ipconfig_ipv4 != NULL)
+ __connman_ipconfig_append_ethernet(service->ipconfig_ipv4,
+ iter);
+ else if (service->ipconfig_ipv6 != NULL)
+ __connman_ipconfig_append_ethernet(service->ipconfig_ipv6,
+ iter);
+}
+
+static void append_ipv4(DBusMessageIter *iter, void *user_data)
+{
+ struct connman_service *service = user_data;
+
+ DBG("ipv4 %p state %s", service->ipconfig_ipv4,
+ state2string(service->state_ipv4));
+
+ if (is_connected_state(service, service->state_ipv4) == FALSE)
return;
if (service->ipconfig_ipv4 != NULL)
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);
}
}
void __connman_service_session_inc(struct connman_service *service)
{
- DBG("service %p", service);
+ DBG("service %p ref count %d", service,
+ 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)
{
- connman_bool_t in_use;
-
- if (g_atomic_int_dec_and_test(&service->session_usage_count) == TRUE)
- in_use = FALSE;
- else
- in_use = TRUE;
+ DBG("service %p ref count %d", service,
+ service->session_usage_count - 1);
- DBG("service %p last %d", service, in_use);
+ if (__sync_fetch_and_sub(&service->session_usage_count, 1) != 1)
+ return FALSE;
- return in_use;
+ 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 (pac == NULL)
+ if (service->hidden == TRUE)
return;
-
g_free(service->pac);
service->pac = g_strdup(pac);
+
+ proxy_changed(service);
}
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);
service->identity);
}
-void __connman_service_set_passphrase(struct connman_service *service,
- const char* passphrase)
+void __connman_service_set_agent_identity(struct connman_service *service,
+ const char *agent_identity)
{
- if (service->immutable == TRUE)
+ if (service->hidden == TRUE)
+ return;
+ g_free(service->agent_identity);
+ service->agent_identity = g_strdup(agent_identity);
+
+ if (service->network != NULL)
+ connman_network_set_string(service->network,
+ "WiFi.AgentIdentity",
+ service->agent_identity);
+}
+
+void __connman_service_set_passphrase(struct connman_service *service,
+ const char* passphrase)
+{
+ 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",
service->passphrase);
- __connman_storage_save_service(service);
+ service_save(service);
+}
+
+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);
+
+ if (service->network != NULL)
+ connman_network_set_string(service->network,
+ "WiFi.AgentPassphrase",
+ service->agent_passphrase);
}
static DBusMessage *get_properties(DBusConnection *conn,
enum connman_ipconfig_type type;
int err;
+ if (ipconfig == NULL)
+ return -EINVAL;
+
old_method = __connman_ipconfig_get_method(ipconfig);
if (is_connecting_state(service, state) ||
autoconnect_changed(service);
- __connman_storage_save_service(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);
+ service_save(service);
} else if (g_str_equal(name, "Nameservers.Configuration") == TRUE) {
DBusMessageIter entry;
GString *str;
update_nameservers(service);
dns_configuration_changed(service);
- __connman_storage_save_service(service);
+ service_save(service);
} else if (g_str_equal(name, "Domains.Configuration") == TRUE) {
DBusMessageIter entry;
GString *str;
update_nameservers(service);
domain_configuration_changed(service);
- __connman_storage_save_service(service);
+ service_save(service);
} else if (g_str_equal(name, "Proxy.Configuration") == TRUE) {
int err;
proxy_configuration_changed(service);
- __connman_storage_save_service(service);
+ __connman_notifier_proxy_changed(service);
+
+ service_save(service);
} else if (g_str_equal(name, "IPv4.Configuration") == TRUE ||
g_str_equal(name, "IPv6.Configuration")) {
__connman_network_set_ipconfig(service->network,
ipv4, ipv6);
- __connman_storage_save_service(service);
+ service_save(service);
} else
return __connman_error_invalid_property(msg);
set_idle(service);
g_get_current_time(&service->modified);
- __connman_storage_save_service(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);
-
- __connman_storage_save_service(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)
-{
- DBG ("RequestInput return, %p", service);
-
- if (identity == NULL && passphrase == NULL && service->wps == FALSE)
- return;
-
- if (identity != NULL)
- __connman_service_set_identity(service, identity);
-
- if (passphrase != NULL)
- __connman_service_set_passphrase(service, passphrase);
-
- __connman_service_connect(service);
-}
-
static DBusMessage *connect_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
err = __connman_service_connect(service);
if (err < 0) {
- if (err == -ENOKEY) {
- if (__connman_agent_request_input(service,
- request_input_cb,
- NULL) == 0)
- return NULL;
- }
-
if (service->pending == NULL)
return NULL;
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);
- __connman_storage_save_service(service);
+ service_save(service);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
+static gboolean check_suitable_state(enum connman_service_state a,
+ enum connman_service_state b)
+{
+ /*
+ * Special check so that "ready" service can be moved before
+ * "online" one.
+ */
+ if ((a == CONNMAN_SERVICE_STATE_ONLINE &&
+ b == CONNMAN_SERVICE_STATE_READY) ||
+ (b == CONNMAN_SERVICE_STATE_ONLINE &&
+ a == CONNMAN_SERVICE_STATE_READY))
+ return TRUE;
+
+ 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)
struct connman_service *target;
const char *path;
GSequenceIter *src, *dst;
+ enum connman_ipconfig_method target4, target6;
+ enum connman_ipconfig_method service4, service6;
DBG("service %p", service);
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);
- DBG("target %s", target->identifier);
+ target4 = __connman_ipconfig_get_method(target->ipconfig_ipv4);
+ target6 = __connman_ipconfig_get_method(target->ipconfig_ipv6);
+ service4 = __connman_ipconfig_get_method(service->ipconfig_ipv4);
+ service6 = __connman_ipconfig_get_method(service->ipconfig_ipv6);
- if (target->state_ipv4 != service->state_ipv4 &&
- target->state_ipv6 != service->state_ipv6)
- return __connman_error_invalid_service(msg);
+ DBG("target %s method %d/%d state %d/%d", target->identifier,
+ target4, target6,
+ target->state_ipv4, target->state_ipv6);
+
+ DBG("service %s method %d/%d state %d/%d", service->identifier,
+ service4, service6,
+ service->state_ipv4, service->state_ipv6);
+
+ /*
+ * If method is OFF, then we do not need to check the corresponding
+ * ipconfig state.
+ */
+ if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (check_suitable_state(target->state_ipv6,
+ service->state_ipv6) == FALSE)
+ return __connman_error_invalid_service(msg);
+ }
+ }
+
+ if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (check_suitable_state(target->state_ipv4,
+ service->state_ipv4) == FALSE)
+ return __connman_error_invalid_service(msg);
+ }
+ }
+
+ if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (check_suitable_state(target->state_ipv6,
+ service->state_ipv6) == FALSE)
+ return __connman_error_invalid_service(msg);
+ }
+ }
+
+ if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
+ if (check_suitable_state(target->state_ipv4,
+ service->state_ipv4) == FALSE)
+ return __connman_error_invalid_service(msg);
+ }
+ }
g_get_current_time(&service->modified);
- __connman_storage_save_service(service);
+ service_save(service);
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);
+ }
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
__connman_notifier_service_remove(service);
stats_stop(service);
- __connman_storage_save_service(service);
service->path = NULL;
if (path != NULL) {
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
g_dbus_unregister_interface(connection, path,
CONNMAN_SERVICE_INTERFACE);
g_hash_table_destroy(service->counter_table);
if (service->network != NULL) {
+ __connman_network_disconnect(service->network);
if (service->network_created == TRUE)
- connman_network_unregister(service->network);
- connman_network_unref(service->network);
+ connman_network_unref(service->network);
}
if (service->provider != NULL)
connman_provider_unref(service->provider);
if (service->ipconfig_ipv4 != NULL) {
+ connman_ipconfig_set_ops(service->ipconfig_ipv4, NULL);
+ connman_ipconfig_set_data(service->ipconfig_ipv4, NULL);
connman_ipconfig_unref(service->ipconfig_ipv4);
service->ipconfig_ipv4 = NULL;
}
if (service->ipconfig_ipv6 != NULL) {
+ connman_ipconfig_set_ops(service->ipconfig_ipv6, NULL);
+ connman_ipconfig_set_data(service->ipconfig_ipv6, NULL);
connman_ipconfig_unref(service->ipconfig_ipv6);
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);
g_free(service->domainname);
g_free(service->pac);
- g_free(service->profile);
g_free(service->name);
g_free(service->passphrase);
+ g_free(service->agent_passphrase);
g_free(service->identifier);
g_free(service->eap);
g_free(service->identity);
+ g_free(service->agent_identity);
g_free(service->ca_cert_file);
g_free(service->client_cert_file);
g_free(service->private_key_file);
*/
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;
}
state_b = service_b->state;
if (state_a != state_b) {
- if (is_connected(service_a) == TRUE)
+ gboolean a_connected = is_connected(service_a);
+ gboolean b_connected = is_connected(service_b);
+
+ if (a_connected == TRUE && b_connected == TRUE) {
+ /* We prefer online over ready state */
+ if (state_a == CONNMAN_SERVICE_STATE_ONLINE)
+ return -1;
+
+ if (state_b == CONNMAN_SERVICE_STATE_ONLINE)
+ return 1;
+ }
+
+ if (a_connected == TRUE)
return -1;
- if (is_connected(service_b) == TRUE)
+ if (b_connected == TRUE)
return 1;
if (is_connecting(service_a) == TRUE)
{
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);
g_sequence_sort_changed(iter, service_compare, NULL);
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
return 0;
}
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);
__connman_service_auto_connect();
g_get_current_time(&service->modified);
- __connman_storage_save_service(service);
+ service_save(service);
}
static void report_error_cb(struct connman_service *service,
__connman_service_connect(service);
else {
service_complete(service);
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
+ }
+}
+
+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 __connman_service_indicate_state(struct connman_service *service)
+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)
old_state = service->state;
new_state = combine_state(service->state_ipv4, service->state_ipv6);
- if (old_state == new_state)
- return -EALREADY;
-
DBG("service %p old %s - new %s/%s => %s",
service,
state2string(old_state),
state2string(service->state_ipv6),
state2string(new_state));
+ 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();
-
- default_changed();
}
if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
service->userconnect = FALSE;
g_get_current_time(&service->modified);
- __connman_storage_save_service(service);
+ service_save(service);
update_nameservers(service);
dns_changed(service);
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) {
if (iter != NULL)
g_sequence_sort_changed(iter, service_compare, NULL);
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
+
+ if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
+ default_changed();
return 0;
}
if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
__connman_service_set_passphrase(service, NULL);
- return __connman_service_ipconfig_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_FAILURE,
CONNMAN_IPCONFIG_TYPE_IPV4);
+ __connman_service_ipconfig_indicate_state(service,
+ CONNMAN_SERVICE_STATE_FAILURE,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+ return 0;
}
int __connman_service_clear_error(struct connman_service *service)
default_changed();
- __connman_location_detect(service);
-
return 0;
}
-int __connman_service_ipconfig_indicate_state(struct connman_service *service,
- enum connman_service_state new_state,
+enum connman_service_state __connman_service_ipconfig_get_state(
+ struct connman_service *service,
enum connman_ipconfig_type type)
{
- struct connman_ipconfig *ipconfig = NULL;
- enum connman_service_state old_state;
- enum connman_service_proxy_method proxy_config;
-
if (service == NULL)
- return -EINVAL;
+ return CONNMAN_SERVICE_STATE_UNKNOWN;
- if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
- old_state = service->state_ipv4;
- ipconfig = service->ipconfig_ipv4;
- } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
- old_state = service->state_ipv6;
- ipconfig = service->ipconfig_ipv6;
- }
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ return service->state_ipv4;
- if (ipconfig == NULL)
- return -EINVAL;
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ return service->state_ipv6;
- /* Any change? */
- if (old_state == new_state)
- return -EALREADY;
+ return CONNMAN_SERVICE_STATE_UNKNOWN;
+}
- DBG("service %p (%s) state %d (%s) type %d (%s)",
- service, service ? service->identifier : NULL,
- new_state, state2string(new_state),
- type, __connman_ipconfig_type2string(type));
+static void check_proxy_setup(struct connman_service *service)
+{
+ /*
+ * We start WPAD if we haven't got a PAC URL from DHCP and
+ * if our proxy manual configuration is either empty or set
+ * to AUTO with an empty URL.
+ */
- switch (new_state) {
- case CONNMAN_SERVICE_STATE_UNKNOWN:
- case CONNMAN_SERVICE_STATE_IDLE:
- if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
- return -EINVAL;
- break;
- case CONNMAN_SERVICE_STATE_ASSOCIATION:
- break;
- case CONNMAN_SERVICE_STATE_CONFIGURATION:
- __connman_ipconfig_enable(ipconfig);
- break;
- case CONNMAN_SERVICE_STATE_READY:
- update_nameservers(service);
+ if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
+ goto done;
- proxy_config = service->proxy_config;
+ if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
+ (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
+ service->pac != NULL))
+ goto done;
- /*
- * We start WPAD if we haven't got a PAC URL from DHCP and
- * if our proxy manual configuration is either empty or set
- * to AUTO with an empty URL.
- */
- if (service->proxy == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
- (proxy_config == CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN ||
- (proxy_config ==
- CONNMAN_SERVICE_PROXY_METHOD_AUTO &&
- service->pac == NULL)))
- if (__connman_wpad_start(service) < 0) {
- service->proxy =
- CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
-
- __connman_notifier_proxy_changed(service);
- }
+ 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,
+ enum connman_service_state new_state,
+ enum connman_ipconfig_type type)
+{
+ struct connman_ipconfig *ipconfig = NULL;
+ enum connman_service_state old_state;
+ int ret;
+
+ if (service == NULL)
+ return -EINVAL;
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+ old_state = service->state_ipv4;
+ ipconfig = service->ipconfig_ipv4;
+ } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+ old_state = service->state_ipv6;
+ ipconfig = service->ipconfig_ipv6;
+ }
+
+ if (ipconfig == NULL)
+ return -EINVAL;
+
+ /* Any change? */
+ if (old_state == new_state)
+ return -EALREADY;
+
+ DBG("service %p (%s) state %d (%s) type %d (%s)",
+ service, service ? service->identifier : NULL,
+ new_state, state2string(new_state),
+ type, __connman_ipconfig_type2string(type));
+ switch (new_state) {
+ case CONNMAN_SERVICE_STATE_UNKNOWN:
+ case CONNMAN_SERVICE_STATE_IDLE:
+ if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
+ return -EINVAL;
+ break;
+ case CONNMAN_SERVICE_STATE_ASSOCIATION:
+ break;
+ case CONNMAN_SERVICE_STATE_CONFIGURATION:
+ __connman_ipconfig_enable(ipconfig);
+ break;
+ case CONNMAN_SERVICE_STATE_READY:
+ update_nameservers(service);
+
+ 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 __connman_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:
if (g_str_equal(service->eap, "tls") == TRUE)
break;
- if (service->immutable != TRUE)
+ /*
+ * Return -ENOKEY if either identity or passphrase is
+ * missing. Agent provided credentials can be used as
+ * fallback if needed.
+ */
+ if ((service->identity == NULL &&
+ service->agent_identity == NULL) ||
+ (service->passphrase == NULL &&
+ service->agent_passphrase == NULL))
return -ENOKEY;
break;
return -EINPROGRESS;
}
- if (err == -ENOKEY)
- return -ENOKEY;
-
- if (service->userconnect == TRUE)
- reply_pending(service, err);
-
__connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_FAILURE,
CONNMAN_IPCONFIG_TYPE_IPV4);
CONNMAN_SERVICE_STATE_FAILURE,
CONNMAN_IPCONFIG_TYPE_IPV6);
+ if (service->network != NULL)
+ __connman_network_disconnect(service->network);
+ else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
+ service->provider != NULL)
+ __connman_provider_disconnect(service->provider);
+
+ if (service->userconnect == TRUE) {
+ if (err == -ENOKEY || err == -EPERM) {
+ if (__connman_agent_request_passphrase_input(service,
+ request_input_cb,
+ NULL) == -EIO)
+ return -EINPROGRESS;
+ }
+ reply_pending(service, err);
+ }
+
return err;
}
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)
+static void provision_changed(gpointer value, gpointer user_data)
{
- 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(NULL, CONNMAN_NETWORK_TYPE_WIFI);
- if (network == NULL)
- return NULL;
-
- connman_network_register(network);
+ struct connman_service *service = value;
+ char *path = user_data;
- connman_network_set_blob(network, "WiFi.SSID",
- (unsigned char *) ssid, ssid_len);
+ __connman_config_provision_service_ident(service, path);
+}
- connman_network_set_string(network, "WiFi.Mode", mode);
- connman_network_set_string(network, "WiFi.Security", security);
+void __connman_service_provision_changed(const char *ident)
+{
+ g_sequence_foreach(service_list, provision_changed, (void *)ident);
+}
- name = g_try_malloc0(ssid_len + 1);
- if (name == NULL) {
- connman_network_unregister(network);
- connman_network_unref(network);
- return NULL;
- }
+/**
+ * __connman_service_get:
+ * @identifier: service identifier
+ *
+ * Look up a service by identifier or create a new one if not found
+ */
+static struct connman_service *service_get(const char *identifier)
+{
+ struct connman_service *service;
+ GSequenceIter *iter;
- for (i = 0; i < ssid_len; i++) {
- if (g_ascii_isprint(ssid[i]))
- name[i] = ssid[i];
- else
- name[i] = ' ';
+ iter = g_hash_table_lookup(service_hash, identifier);
+ if (iter != NULL) {
+ service = g_sequence_get(iter);
+ if (service != NULL)
+ connman_service_ref(service);
+ return service;
}
- connman_network_set_name(network, name);
+ service = connman_service_create();
+ if (service == NULL)
+ return NULL;
- g_free(name);
+ DBG("service %p", service);
- index = connman_device_get_index(device);
- connman_network_set_index(network, index);
+ service->identifier = g_strdup(identifier);
- if (connman_device_add_network(device, network) < 0) {
- connman_network_unregister(network);
- connman_network_unref(network);
- return NULL;
- }
+ iter = g_sequence_insert_sorted(service_list, service,
+ service_compare, NULL);
- connman_network_set_available(network, TRUE);
+ g_hash_table_insert(service_hash, service->identifier, iter);
- return network;
+ return service;
}
-int __connman_service_create_and_connect(DBusMessage *msg)
+static int service_register(struct connman_service *service)
{
- 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);
+ GSequenceIter *iter;
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key;
+ DBG("service %p", service);
- dbus_message_iter_recurse(&array, &entry);
- dbus_message_iter_get_basic(&entry, &key);
+ if (service->path != NULL)
+ return -EALREADY;
- 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);
- }
+ service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
+ service->identifier);
- dbus_message_iter_next(&array);
- }
+ DBG("path %s", service->path);
- if (type == NULL)
- return -EINVAL;
+ __connman_config_provision_service(service);
- if (g_strcmp0(type, "wifi") != 0 || g_strcmp0(mode, "managed") != 0)
- return -EOPNOTSUPP;
+ service_load(service);
- if (ssid == NULL)
- return -EINVAL;
+ g_dbus_register_interface(connection, service->path,
+ CONNMAN_SERVICE_INTERFACE,
+ service_methods, service_signals,
+ NULL, service, NULL);
- ssid_len = strlen(ssid);
- if (ssid_len < 1)
- return -EINVAL;
+ iter = g_hash_table_lookup(service_hash, service->identifier);
+ if (iter != NULL)
+ g_sequence_sort_changed(iter, service_compare, NULL);
- 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;
+ services_changed(TRUE);
- device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
- if (device == NULL)
- return -EOPNOTSUPP;
+ return 0;
+}
- ident = connman_device_get_ident(device);
- if (ident == NULL)
- return -EOPNOTSUPP;
+static void service_up(struct connman_ipconfig *ipconfig)
+{
+ struct connman_service *service = connman_ipconfig_get_data(ipconfig);
+ DBG("%s up", connman_ipconfig_get_ifname(ipconfig));
- if (!g_strcmp0(security, "wpa") ||
- !g_strcmp0(security, "rsn"))
- group_security = "psk";
- else
- group_security = security;
+ link_changed(service);
- group = connman_wifi_build_group_name((unsigned char *) ssid,
- ssid_len, mode, group_security);
- if (group == NULL)
- return -EINVAL;
+ service->stats.valid = FALSE;
+ service->stats_roaming.valid = FALSE;
+}
- name = g_strdup_printf("%s_%s_%s", type, ident, group);
+static void service_down(struct connman_ipconfig *ipconfig)
+{
+ DBG("%s down", connman_ipconfig_get_ifname(ipconfig));
+}
- service = lookup_by_identifier(name);
+static void service_lower_up(struct connman_ipconfig *ipconfig)
+{
+ struct connman_service *service = connman_ipconfig_get_data(ipconfig);
- if (service != NULL)
- goto done;
-
- network = create_hidden_wifi(device, ssid, mode, security);
- if (network != NULL) {
- connman_network_set_group(network, group);
- service->network_created = TRUE;
- }
-
- service = lookup_by_identifier(name);
-
-done:
- g_free(name);
- g_free(group);
-
- if (service == NULL) {
- err = -EOPNOTSUPP;
- goto failed;
- }
-
- 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;
- char *path = user_data;
-
- __connman_config_provision_service_ident(service, path);
-}
-
-void __connman_service_provision_changed(const char *ident)
-{
- 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
- *
- * Look up a service by identifier or create a new one if not found
- */
-static struct connman_service *service_get(const char *identifier)
-{
- struct connman_service *service;
- GSequenceIter *iter;
-
- iter = g_hash_table_lookup(service_hash, identifier);
- if (iter != NULL) {
- service = g_sequence_get(iter);
- if (service != NULL)
- connman_service_ref(service);
- return service;
- }
-
- service = connman_service_create();
- if (service == NULL)
- return NULL;
-
- DBG("service %p", service);
-
- service->identifier = g_strdup(identifier);
-
- service->profile = g_strdup(__connman_profile_active_ident());
-
- iter = g_sequence_insert_sorted(service_list, service,
- service_compare, NULL);
-
- g_hash_table_insert(service_hash, service->identifier, iter);
-
- return service;
-}
-
-static int service_register(struct connman_service *service)
-{
- const char *path = __connman_profile_active_path();
- GSequenceIter *iter;
-
- DBG("service %p", service);
-
- if (service->path != NULL)
- return -EALREADY;
-
- service->path = g_strdup_printf("%s/%s", path, service->identifier);
-
- DBG("path %s", service->path);
-
- __connman_config_provision_service(service);
-
- __connman_storage_load_service(service);
-
- g_dbus_register_interface(connection, service->path,
- CONNMAN_SERVICE_INTERFACE,
- service_methods, service_signals,
- NULL, service, NULL);
-
- iter = g_hash_table_lookup(service_hash, service->identifier);
- if (iter != NULL)
- g_sequence_sort_changed(iter, service_compare, NULL);
-
- __connman_profile_changed(TRUE);
-
- return 0;
-}
-
-static void service_up(struct connman_ipconfig *ipconfig)
-{
- struct connman_service *service = connman_ipconfig_get_data(ipconfig);
-
- DBG("%s up", connman_ipconfig_get_ifname(ipconfig));
-
- link_changed(service);
-
- service->stats.valid = FALSE;
- service->stats_roaming.valid = FALSE;
-}
-
-static void service_down(struct connman_ipconfig *ipconfig)
-{
- DBG("%s down", connman_ipconfig_get_ifname(ipconfig));
-}
-
-static void service_lower_up(struct connman_ipconfig *ipconfig)
-{
- struct connman_service *service = connman_ipconfig_get_data(ipconfig);
-
- DBG("%s lower up", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s lower up", connman_ipconfig_get_ifname(ipconfig));
stats_start(service);
}
DBG("%s lower down", connman_ipconfig_get_ifname(ipconfig));
stats_stop(service);
- __connman_storage_save_service(service);
+ service_save(service);
}
static void service_ip_bound(struct connman_ipconfig *ipconfig)
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)
connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
}
-void __connman_service_create_ip4config(struct connman_service *service,
- int index)
+void __connman_service_read_ip4config(struct connman_service *service)
{
- const char *ident = service->profile;
GKeyFile *keyfile;
+ if (service->ipconfig_ipv4 == NULL)
+ return;
+
+ keyfile = connman_storage_load_service(service->identifier);
+ if (keyfile == NULL)
+ return;
+
+ __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
+ service->identifier, "IPv4.");
+
+ g_key_file_free(keyfile);
+}
+
+void __connman_service_create_ip4config(struct connman_service *service,
+ int index)
+{
DBG("ipv4 %p", service->ipconfig_ipv4);
if (service->ipconfig_ipv4 != NULL)
return;
setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
+ __connman_service_read_ip4config(service);
+}
- if (ident == NULL)
+void __connman_service_read_ip6config(struct connman_service *service)
+{
+ GKeyFile *keyfile;
+
+ if (service->ipconfig_ipv6 == NULL)
return;
- keyfile = __connman_storage_open_profile(ident);
+ keyfile = connman_storage_load_service(service->identifier);
if (keyfile == NULL)
return;
- if (service->ipconfig_ipv4)
- __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
- service->identifier, "IPv4.");
+ __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
+ service->identifier, "IPv6.");
+
g_key_file_free(keyfile);
}
void __connman_service_create_ip6config(struct connman_service *service,
int index)
{
- const char *ident = service->profile;
- GKeyFile *keyfile;
-
DBG("ipv6 %p", service->ipconfig_ipv6);
if (service->ipconfig_ipv6 != NULL)
setup_ip6config(service, index);
- if (ident == NULL)
- return;
-
- keyfile = __connman_storage_open_profile(ident);
- if (keyfile == NULL)
- return;
-
- if (service->ipconfig_ipv6 != NULL)
- __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
- service->identifier, "IPv6.");
-
- g_key_file_free(keyfile);
+ __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;
service->wps = connman_network_get_bool(network, "WiFi.WPS");
if (service->strength > strength && service->network != NULL) {
- connman_network_unref(service->network);
- service->network = connman_network_ref(network);
+ service->network = network;
strength_changed(service);
}
if (service->network == NULL)
- service->network = connman_network_ref(network);
+ service->network = network;
iter = g_hash_table_lookup(service_hash, service->identifier);
if (iter != NULL)
DBG("network %p", network);
+ if (network == NULL)
+ return NULL;
+
ident = __connman_network_get_ident(network);
if (ident == NULL)
return NULL;
name = g_strdup_printf("%s_%s_%s",
__connman_network_get_type(network), ident, group);
- service = service_get(name);
- g_free(name);
-
- if (service == NULL)
- return NULL;
-
- if (__connman_network_get_weakness(network) == TRUE)
- return service;
-
- if (service->path != NULL) {
- update_from_network(service, network);
- __connman_profile_changed(TRUE);
- return service;
- }
-
- service->type = convert_network_type(network);
-
- 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_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_GADGET:
- service->autoconnect = FALSE;
- break;
- case CONNMAN_SERVICE_TYPE_WIFI:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- service->autoconnect = TRUE;
- break;
- }
-
- service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
- service->state = combine_state(service->state_ipv4, service->state_ipv6);
-
- update_from_network(service, network);
-
- index = connman_network_get_index(network);
-
- if (service->ipconfig_ipv4 == NULL)
- setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
-
- if (service->ipconfig_ipv6 == NULL)
- setup_ip6config(service, index);
-
- service_register(service);
-
- if (service->favorite == TRUE) {
- device = connman_network_get_device(service->network);
- if (device && __connman_device_scanning(device) == FALSE)
- __connman_service_auto_connect();
- }
-
- __connman_notifier_service_add(service);
-
- return service;
-}
-
-void __connman_service_update_from_network(struct connman_network *network)
-{
- struct connman_service *service;
- connman_uint8_t strength;
- connman_bool_t roaming;
- GSequenceIter *iter;
- const char *name;
- connman_bool_t stats_enable;
-
- DBG("network %p", network);
-
- service = __connman_service_lookup_from_network(network);
- if (service == NULL)
- return;
-
- if (service->network == NULL)
- return;
-
- name = connman_network_get_string(service->network, "Name");
- if (g_strcmp0(service->name, name) != 0) {
- g_free(service->name);
- service->name = g_strdup(name);
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Name",
- DBUS_TYPE_STRING, &service->name);
- }
-
- if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
- service->wps = connman_network_get_bool(network, "WiFi.WPS");
-
- strength = connman_network_get_strength(service->network);
- if (strength == service->strength)
- goto roaming;
-
- service->strength = strength;
-
- strength_changed(service);
-
-roaming:
- roaming = connman_network_get_bool(service->network, "Roaming");
- if (roaming == service->roaming)
- return;
-
- stats_enable = stats_enabled(service);
- if (stats_enable == TRUE)
- stats_stop(service);
-
- service->roaming = roaming;
-
- 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);
-}
-
-void __connman_service_remove_from_network(struct connman_network *network)
-{
- struct connman_service *service;
-
- DBG("network %p", network);
-
- service = __connman_service_lookup_from_network(network);
- if (service == NULL)
- return;
-
- __connman_service_put(service);
-}
-
-/**
- * __connman_service_create_from_provider:
- * @provider: provider structure
- *
- * Look up service by provider and if not found, create one
- */
-struct connman_service *
-__connman_service_create_from_provider(struct connman_provider *provider)
-{
- struct connman_service *service;
- const char *ident, *str;
- char *name;
- int index = connman_provider_get_index(provider);
-
- DBG("provider %p", provider);
-
- ident = __connman_provider_get_ident(provider);
- if (ident == NULL)
- return NULL;
-
- name = g_strdup_printf("vpn_%s", ident);
- service = service_get(name);
- g_free(name);
-
- if (service == NULL)
- return NULL;
-
- service->type = CONNMAN_SERVICE_TYPE_VPN;
- service->provider = connman_provider_ref(provider);
- service->autoconnect = FALSE;
-
- service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
-
- str = connman_provider_get_string(provider, "Name");
- if (str != NULL) {
- g_free(service->name);
- service->name = g_strdup(str);
- service->hidden = FALSE;
- } else {
- g_free(service->name);
- service->name = NULL;
- service->hidden = TRUE;
- }
-
- service->strength = 0;
-
- if (service->ipconfig_ipv4 == NULL)
- setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_MANUAL);
-
- if (service->ipconfig_ipv6 == NULL)
- setup_ip6config(service, index);
-
- service_register(service);
-
- __connman_notifier_service_add(service);
-
- return service;
-}
-
-static int service_load(struct connman_service *service)
-{
- const char *ident = service->profile;
- GKeyFile *keyfile;
- GError *error = NULL;
- gchar *pathname, *data = NULL;
- gsize length;
- gchar *str;
- connman_bool_t autoconnect;
- unsigned int ssid_len;
- 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) {
- 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);
-
- switch (service->type) {
- case CONNMAN_SERVICE_TYPE_UNKNOWN:
- case CONNMAN_SERVICE_TYPE_SYSTEM:
- case CONNMAN_SERVICE_TYPE_ETHERNET:
- case CONNMAN_SERVICE_TYPE_GPS:
- case CONNMAN_SERVICE_TYPE_VPN:
- case CONNMAN_SERVICE_TYPE_GADGET:
- break;
- case CONNMAN_SERVICE_TYPE_WIFI:
- if (service->name == NULL) {
- gchar *name;
-
- name = g_key_file_get_string(keyfile,
- service->identifier, "Name", NULL);
- if (name != NULL) {
- g_free(service->name);
- service->name = name;
- }
-
- if (service->network != NULL)
- connman_network_set_name(service->network,
- name);
- }
-
- if (service->network &&
- connman_network_get_blob(service->network,
- "WiFi.SSID", &ssid_len) == NULL) {
- gchar *hex_ssid;
-
- hex_ssid = g_key_file_get_string(keyfile,
- service->identifier,
- "SSID", NULL);
-
- if (hex_ssid != NULL) {
- gchar *ssid;
- unsigned int i, j = 0, hex;
- size_t hex_ssid_len = strlen(hex_ssid);
-
- ssid = g_try_malloc0(hex_ssid_len / 2);
- if (ssid == NULL) {
- g_free(hex_ssid);
- err = -ENOMEM;
- goto done;
- }
-
- for (i = 0; i < hex_ssid_len; i += 2) {
- sscanf(hex_ssid + i, "%02x", &hex);
- ssid[j++] = hex;
- }
-
- connman_network_set_blob(service->network,
- "WiFi.SSID", ssid, hex_ssid_len / 2);
- }
-
- g_free(hex_ssid);
- }
- /* fall through */
-
- case CONNMAN_SERVICE_TYPE_WIMAX:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- service->favorite = g_key_file_get_boolean(keyfile,
- service->identifier, "Favorite", NULL);
-
- autoconnect = g_key_file_get_boolean(keyfile,
- service->identifier, "AutoConnect", &error);
- if (error == NULL)
- service->autoconnect = autoconnect;
- g_clear_error(&error);
-
- str = g_key_file_get_string(keyfile,
- service->identifier, "Failure", NULL);
- if (str != NULL) {
- if (service->favorite == FALSE)
- service->state_ipv4 = service->state_ipv6 =
- CONNMAN_SERVICE_STATE_FAILURE;
- service->error = string2error(str);
- }
- break;
- }
-
- str = g_key_file_get_string(keyfile,
- service->identifier, "Modified", NULL);
- if (str != NULL) {
- g_time_val_from_iso8601(str, &service->modified);
- g_free(str);
- }
-
- str = g_key_file_get_string(keyfile,
- service->identifier, "Passphrase", NULL);
- if (str != NULL) {
- g_free(service->passphrase);
- service->passphrase = str;
- }
-
- if (service->ipconfig_ipv4 != NULL)
- __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
- service->identifier, "IPv4.");
-
- if (service->ipconfig_ipv6 != NULL)
- __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
- service->identifier, "IPv6.");
-
- service->nameservers_config = g_key_file_get_string_list(keyfile,
- service->identifier, "Nameservers", &length, NULL);
- if (service->nameservers_config != NULL && length == 0) {
- g_strfreev(service->nameservers_config);
- service->nameservers_config = NULL;
- }
-
- service->domains = g_key_file_get_string_list(keyfile,
- service->identifier, "Domains", &length, NULL);
- if (service->domains != NULL && length == 0) {
- g_strfreev(service->domains);
- service->domains = NULL;
- }
-
- str = g_key_file_get_string(keyfile,
- service->identifier, "Proxy.Method", NULL);
- if (str != NULL)
- service->proxy_config = string2proxymethod(str);
-
- g_free(str);
-
- service->proxies = g_key_file_get_string_list(keyfile,
- service->identifier, "Proxy.Servers", &length, NULL);
- if (service->proxies != NULL && length == 0) {
- g_strfreev(service->proxies);
- service->proxies = NULL;
- }
-
- service->excludes = g_key_file_get_string_list(keyfile,
- service->identifier, "Proxy.Excludes", &length, NULL);
- if (service->excludes != NULL && length == 0) {
- g_strfreev(service->excludes);
- service->excludes = NULL;
- }
-
- str = g_key_file_get_string(keyfile,
- service->identifier, "Proxy.URL", NULL);
- if (str != NULL) {
- g_free(service->pac);
- service->pac = str;
- }
-
-done:
- g_key_file_free(keyfile);
-
- return err;
-}
-
-static int service_save(struct connman_service *service)
-{
- const char *ident = service->profile;
- GKeyFile *keyfile;
- gchar *pathname, *data = NULL;
- gsize length;
- gchar *str;
- 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;
+ service = service_get(name);
+ g_free(name);
- keyfile = g_key_file_new();
+ if (service == NULL)
+ return NULL;
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
- goto update;
+ if (__connman_network_get_weakness(network) == TRUE)
+ return service;
- if (length > 0) {
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE)
- goto done;
+ if (service->path != NULL) {
+ update_from_network(service, network);
+ services_changed(TRUE);
+ return service;
}
- g_free(data);
-
-update:
- if (service->name != NULL)
- g_key_file_set_string(keyfile, service->identifier,
- "Name", service->name);
+ service->type = convert_network_type(network);
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_GPS:
case CONNMAN_SERVICE_TYPE_VPN:
case CONNMAN_SERVICE_TYPE_GADGET:
+ service->autoconnect = FALSE;
break;
case CONNMAN_SERVICE_TYPE_WIFI:
- if (service->network) {
- const unsigned char *ssid;
- unsigned int ssid_len = 0;
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ service->autoconnect = TRUE;
+ break;
+ }
- ssid = connman_network_get_blob(service->network,
- "WiFi.SSID", &ssid_len);
+ service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+ service->state = combine_state(service->state_ipv4, service->state_ipv6);
- if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
- char *identifier = service->identifier;
- GString *str;
- unsigned int i;
+ update_from_network(service, network);
- str = g_string_sized_new(ssid_len * 2);
- if (str == NULL) {
- err = -ENOMEM;
- goto done;
- }
+ index = connman_network_get_index(network);
- for (i = 0; i < ssid_len; i++)
- g_string_append_printf(str,
- "%02x", ssid[i]);
+ if (service->ipconfig_ipv4 == NULL)
+ setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
- g_key_file_set_string(keyfile, identifier,
- "SSID", str->str);
+ if (service->ipconfig_ipv6 == NULL)
+ setup_ip6config(service, index);
- g_string_free(str, TRUE);
- }
- }
- /* fall through */
+ service_register(service);
- case CONNMAN_SERVICE_TYPE_WIMAX:
- case CONNMAN_SERVICE_TYPE_BLUETOOTH:
- case CONNMAN_SERVICE_TYPE_CELLULAR:
- g_key_file_set_boolean(keyfile, service->identifier,
- "Favorite", service->favorite);
+ if (service->favorite == TRUE) {
+ device = connman_network_get_device(service->network);
+ if (device && __connman_device_scanning(device) == FALSE)
+ __connman_service_auto_connect();
+ }
- if (service->favorite == TRUE)
- g_key_file_set_boolean(keyfile, service->identifier,
- "AutoConnect", service->autoconnect);
+ __connman_notifier_service_add(service, service->name);
- if (service->state_ipv4 == CONNMAN_SERVICE_STATE_FAILURE ||
- service->state_ipv6 == CONNMAN_SERVICE_STATE_FAILURE) {
- const char *failure = error2string(service->error);
- if (failure != NULL)
- g_key_file_set_string(keyfile,
- service->identifier,
- "Failure", failure);
- } else {
- g_key_file_remove_key(keyfile, service->identifier,
- "Failure", NULL);
- }
- break;
+ return service;
+}
+
+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;
+ GSequenceIter *iter;
+ const char *name;
+ connman_bool_t stats_enable;
+
+ DBG("network %p", network);
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
+
+ if (service->network == NULL)
+ return;
+
+ name = connman_network_get_string(service->network, "Name");
+ if (g_strcmp0(service->name, name) != 0) {
+ g_free(service->name);
+ service->name = g_strdup(name);
+ connman_dbus_property_changed_basic(service->path,
+ CONNMAN_SERVICE_INTERFACE, "Name",
+ DBUS_TYPE_STRING, &service->name);
}
- str = g_time_val_to_iso8601(&service->modified);
- if (str != NULL) {
- g_key_file_set_string(keyfile, service->identifier,
- "Modified", str);
- g_free(str);
+ if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+ service->wps = connman_network_get_bool(network, "WiFi.WPS");
+
+ strength = connman_network_get_strength(service->network);
+ if (strength == service->strength)
+ goto roaming;
+
+ service->strength = strength;
+ need_sort = TRUE;
+
+ strength_changed(service);
+
+roaming:
+ roaming = connman_network_get_bool(service->network, "Roaming");
+ if (roaming == service->roaming)
+ 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);
+
+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);
}
+}
- if (service->passphrase != NULL && strlen(service->passphrase) > 0)
- g_key_file_set_string(keyfile, service->identifier,
- "Passphrase", service->passphrase);
- else
- g_key_file_remove_key(keyfile, service->identifier,
- "Passphrase", NULL);
+void __connman_service_remove_from_network(struct connman_network *network)
+{
+ struct connman_service *service;
- if (service->ipconfig_ipv4 != NULL)
- __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
- service->identifier, "IPv4.");
+ DBG("network %p", network);
- if (service->ipconfig_ipv6 != NULL)
- __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
- service->identifier, "IPv6.");
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
- if (service->nameservers_config != NULL) {
- guint len = g_strv_length(service->nameservers_config);
+ __connman_connection_gateway_remove(service,
+ CONNMAN_IPCONFIG_TYPE_ALL);
- g_key_file_set_string_list(keyfile, service->identifier,
- "Nameservers",
- (const gchar **) service->nameservers_config, len);
- } else
- g_key_file_remove_key(keyfile, service->identifier,
- "Nameservers", NULL);
+ __connman_service_put(service);
+}
- if (service->domains != NULL) {
- guint len = g_strv_length(service->domains);
+/**
+ * __connman_service_create_from_provider:
+ * @provider: provider structure
+ *
+ * Look up service by provider and if not found, create one
+ */
+struct connman_service *
+__connman_service_create_from_provider(struct connman_provider *provider)
+{
+ struct connman_service *service;
+ const char *ident, *str;
+ char *name;
+ int index = connman_provider_get_index(provider);
- g_key_file_set_string_list(keyfile, service->identifier,
- "Domains",
- (const gchar **) service->domains, len);
- } else
- g_key_file_remove_key(keyfile, service->identifier,
- "Domains", NULL);
+ DBG("provider %p", provider);
- cst_str = proxymethod2string(service->proxy_config);
- if (cst_str != NULL)
- g_key_file_set_string(keyfile, service->identifier,
- "Proxy.Method", cst_str);
+ ident = __connman_provider_get_ident(provider);
+ if (ident == NULL)
+ return NULL;
- if (service->proxies != NULL) {
- guint len = g_strv_length(service->proxies);
+ name = g_strdup_printf("vpn_%s", ident);
+ service = service_get(name);
+ g_free(name);
- g_key_file_set_string_list(keyfile, service->identifier,
- "Proxy.Servers",
- (const gchar **) service->proxies, len);
- } else
- g_key_file_remove_key(keyfile, service->identifier,
- "Proxy.Servers", NULL);
+ if (service == NULL)
+ return NULL;
- if (service->excludes != NULL) {
- guint len = g_strv_length(service->excludes);
+ service->type = CONNMAN_SERVICE_TYPE_VPN;
+ service->provider = connman_provider_ref(provider);
+ service->autoconnect = FALSE;
+ service->userconnect = TRUE;
- g_key_file_set_string_list(keyfile, service->identifier,
- "Proxy.Excludes",
- (const gchar **) service->excludes, len);
- } else
- g_key_file_remove_key(keyfile, service->identifier,
- "Proxy.Excludes", NULL);
+ service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
- if (service->pac != NULL && strlen(service->pac) > 0)
- g_key_file_set_string(keyfile, service->identifier,
- "Proxy.URL", service->pac);
- else
- g_key_file_remove_key(keyfile, service->identifier,
- "Proxy.URL", NULL);
+ str = connman_provider_get_string(provider, "Name");
+ if (str != NULL) {
+ g_free(service->name);
+ service->name = g_strdup(str);
+ service->hidden = FALSE;
+ } else {
+ g_free(service->name);
+ service->name = NULL;
+ service->hidden = TRUE;
+ }
- data = g_key_file_to_data(keyfile, &length, NULL);
+ service->strength = 0;
- if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
- connman_error("Failed to store service information");
+ if (service->ipconfig_ipv4 == NULL)
+ setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_MANUAL);
-done:
- g_free(data);
+ if (service->ipconfig_ipv6 == NULL)
+ setup_ip6config(service, index);
- g_key_file_free(keyfile);
+ service_register(service);
- g_free(pathname);
+ __connman_notifier_service_add(service, service->name);
- return err;
+ return service;
}
-static struct connman_storage service_storage = {
- .name = "service",
- .priority = CONNMAN_STORAGE_PRIORITY_LOW,
- .service_load = service_load,
- .service_save = service_save,
-};
-
int __connman_service_init(void)
{
DBG("");
connection = connman_dbus_get_connection();
- if (connman_storage_register(&service_storage) < 0)
- connman_error("Failed to register service storage");
-
service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, NULL);
void __connman_service_cleanup(void)
{
+ GSequence *list;
+
DBG("");
- g_sequence_free(service_list);
+ list = service_list;
service_list = NULL;
+ g_sequence_free(list);
g_hash_table_destroy(service_hash);
service_hash = NULL;
g_slist_free(counter_list);
counter_list = NULL;
- connman_storage_unregister(&service_storage);
-
dbus_connection_unref(connection);
}