#include <config.h>
#endif
+#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <netdb.h>
#include <gdbus.h>
#include "connman.h"
struct connman_service {
gint refcount;
+ gint session_usage_count;
char *identifier;
char *path;
enum connman_service_type type;
- enum connman_service_mode mode;
enum connman_service_security security;
+ enum connman_service_state state;
enum connman_service_state state_ipv4;
enum connman_service_state state_ipv6;
enum connman_service_error error;
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_network *network;
/* 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;
void __connman_service_list(DBusMessageIter *iter, void *user_data)
{
+ if (service_list == NULL)
+ return;
+
g_sequence_foreach(service_list, append_path, iter);
}
return NULL;
}
-static const char *mode2string(enum connman_service_mode mode)
-{
- switch (mode) {
- case CONNMAN_SERVICE_MODE_UNKNOWN:
- break;
- case CONNMAN_SERVICE_MODE_MANAGED:
- return "managed";
- case CONNMAN_SERVICE_MODE_ADHOC:
- return "adhoc";
- case CONNMAN_SERVICE_MODE_GPRS:
- return "gprs";
- case CONNMAN_SERVICE_MODE_EDGE:
- return "edge";
- case CONNMAN_SERVICE_MODE_UMTS:
- return "umts";
- }
-
- return NULL;
-}
-
static const char *security2string(enum connman_service_security security)
{
switch (security) {
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)
- 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)
- result = state_a;
- else
- result = state_b;
- goto done;
- }
+ connman_network_set_blob(service->network,
+ "WiFi.SSID", ssid, hex_ssid_len / 2);
+ }
- if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
- result = state_a;
- goto done;
- }
+ g_free(hex_ssid);
+ }
+ /* fall through */
- if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
- result = state_b;
- goto done;
+ 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;
}
- if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT) {
- result = state_b;
- 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_DISCONNECT) {
- result = state_a;
- goto done;
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Passphrase", NULL);
+ if (str != NULL) {
+ g_free(service->passphrase);
+ service->passphrase = str;
}
- result = CONNMAN_SERVICE_STATE_FAILURE;
+ if (service->ipconfig_ipv4 != NULL)
+ __connman_ipconfig_load(service->ipconfig_ipv4, keyfile,
+ service->identifier, "IPv4.");
-done:
- return result;
-}
+ if (service->ipconfig_ipv6 != NULL)
+ __connman_ipconfig_load(service->ipconfig_ipv6, keyfile,
+ service->identifier, "IPv6.");
-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->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;
}
- return FALSE;
-}
-
-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;
+ 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;
}
- return FALSE;
-}
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Proxy.Method", NULL);
+ if (str != NULL)
+ service->proxy_config = string2proxymethod(str);
-static connman_bool_t is_connecting(struct connman_service *service)
-{
- enum connman_service_state state;
+ g_free(str);
- state = combine_state(service->state_ipv4, service->state_ipv6);
+ 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 is_connecting_state(service, state);
-}
+ 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(struct connman_service *service)
-{
- enum connman_service_state state;
+ str = g_key_file_get_string(keyfile,
+ service->identifier, "Proxy.URL", NULL);
+ if (str != NULL) {
+ g_free(service->pac);
+ service->pac = str;
+ }
- state = combine_state(service->state_ipv4, service->state_ipv6);
+done:
+ g_key_file_free(keyfile);
- return is_connected_state(service, state);
+ return err;
}
-static connman_bool_t is_idle(struct connman_service *service)
+static int service_save(struct connman_service *service)
{
- enum connman_service_state state;
+ GKeyFile *keyfile;
+ gchar *str;
+ const char *cst_str = NULL;
+ int err = 0;
- state = combine_state(service->state_ipv4, service->state_ipv6);
+ DBG("service %p", service);
- return state == CONNMAN_SERVICE_STATE_IDLE;
-}
+ keyfile = __connman_storage_open_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
+
+ if (service->name != NULL)
+ g_key_file_set_string(keyfile, service->identifier,
+ "Name", service->name);
+
+ 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->network) {
+ const unsigned char *ssid;
+ unsigned int ssid_len = 0;
+
+ ssid = connman_network_get_blob(service->network,
+ "WiFi.SSID", &ssid_len);
+
+ if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
+ char *identifier = service->identifier;
+ GString *str;
+ unsigned int i;
+
+ str = g_string_sized_new(ssid_len * 2);
+ if (str == NULL) {
+ err = -ENOMEM;
+ goto done;
+ }
+
+ for (i = 0; i < ssid_len; i++)
+ g_string_append_printf(str,
+ "%02x", ssid[i]);
+
+ g_key_file_set_string(keyfile, identifier,
+ "SSID", str->str);
+
+ g_string_free(str, TRUE);
+ }
+ }
+ /* fall through */
+
+ 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)
+ g_key_file_set_boolean(keyfile, service->identifier,
+ "AutoConnect", service->autoconnect);
+
+ 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;
+ }
+
+ 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->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);
+
+ if (service->ipconfig_ipv4 != NULL)
+ __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
+ service->identifier, "IPv4.");
+
+ if (service->ipconfig_ipv6 != NULL)
+ __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
+ service->identifier, "IPv6.");
+
+ if (service->nameservers_config != NULL) {
+ guint len = g_strv_length(service->nameservers_config);
+
+ 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);
+
+ if (service->domains != NULL) {
+ guint len = g_strv_length(service->domains);
+
+ 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);
+
+ cst_str = proxymethod2string(service->proxy_config);
+ if (cst_str != NULL)
+ g_key_file_set_string(keyfile, service->identifier,
+ "Proxy.Method", cst_str);
+
+ if (service->proxies != NULL) {
+ guint len = g_strv_length(service->proxies);
+
+ 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->excludes != NULL) {
+ guint len = g_strv_length(service->excludes);
+
+ 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);
+
+ 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);
+
+done:
+ __connman_storage_save_service(keyfile, service->identifier);
+
+ g_key_file_free(keyfile);
+
+ return err;
+}
+
+static guint changed_timeout = 0;
+
+static gboolean notify_services_changed(gpointer user_data)
+{
+ changed_timeout = 0;
+
+ connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE, "Services",
+ DBUS_TYPE_OBJECT_PATH, __connman_service_list,
+ NULL);
+
+ return FALSE;
+}
+
+static void services_changed(gboolean delayed)
+{
+ DBG("");
+
+ if (changed_timeout > 0) {
+ g_source_remove(changed_timeout);
+ changed_timeout = 0;
+ }
+
+ if (__connman_connection_update_gateway() == TRUE) {
+ notify_services_changed(NULL);
+ return;
+ }
+
+ if (delayed == FALSE) {
+ notify_services_changed(NULL);
+ return;
+ }
+
+ changed_timeout = g_timeout_add_seconds(1, notify_services_changed,
+ NULL);
+}
+
+static enum connman_service_state combine_state(
+ enum connman_service_state state_a,
+ enum connman_service_state state_b)
+{
+ enum connman_service_state result;
+
+ if (state_a == state_b) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_a == CONNMAN_SERVICE_STATE_UNKNOWN) {
+ result = state_b;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_UNKNOWN) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_a == CONNMAN_SERVICE_STATE_IDLE) {
+ result = state_b;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_IDLE) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
+ result = state_b;
+ goto done;
+ }
+
+ if (state_a == CONNMAN_SERVICE_STATE_READY) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_READY) {
+ result = state_b;
+ goto done;
+ }
+
+ if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+ result = state_a;
+ goto done;
+ }
+
+ if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+ result = state_b;
+ goto done;
+ }
+
+ 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 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;
+ }
+
+ return FALSE;
+}
+
+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;
+ }
+
+ return FALSE;
+}
+
+static connman_bool_t is_connecting(struct connman_service *service)
+{
+ return is_connecting_state(service, service->state);
+}
+
+static connman_bool_t is_connected(struct connman_service *service)
+{
+ return is_connected_state(service, service->state);
+}
static void update_nameservers(struct connman_service *service)
{
return 0;
}
- servers = g_try_new0(char *, len - 1);
+ servers = g_try_new0(char *, len);
if (servers == NULL)
return -ENOMEM;
j++;
}
}
- servers[len - 2] = NULL;
+ servers[len - 1] = NULL;
g_strfreev(service->nameservers);
service->nameservers = servers;
static void nameserver_add_routes(int index, char **nameservers,
const char *gw)
{
- int i;
+ int i, ret, family;
+ struct addrinfo hints;
+ struct addrinfo *addr;
for (i = 0; nameservers[i] != NULL; i++) {
- if (connman_inet_compare_subnet(index, nameservers[i]))
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ addr = NULL;
+
+ 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_inet_add_host_route(index, nameservers[i], gw);
+ 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 nameserver_del_routes(int index, char **nameservers)
{
- int i;
+ int i, ret, family;
+ struct addrinfo hints;
+ struct addrinfo *addr;
- for (i = 0; nameservers[i] != NULL; i++)
- connman_inet_del_host_route(index, nameservers[i]);
+ for (i = 0; nameservers[i] != NULL; i++) {
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ addr = NULL;
+
+ 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 (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);
+ }
}
void __connman_service_nameserver_add_routes(struct connman_service *service,
return __connman_service_type2string(service->type);
}
-static void mode_changed(struct connman_service *service)
-{
- const char *str;
-
- str = mode2string(service->mode);
- if (str == NULL)
- return;
-
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Mode",
- DBUS_TYPE_STRING, &str);
-}
-
static void state_changed(struct connman_service *service)
{
- enum connman_service_state state;
const char *str;
- state = combine_state(service->state_ipv4, service->state_ipv6);
+ __connman_notifier_service_state_changed(service, service->state);
- __connman_notifier_service_state_changed(service, state);
-
- str = state2string(state);
+ str = state2string(service->state);
if (str == NULL)
return;
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);
+ /*
+ * 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)
stats->data.time = stats->data_last.time + seconds;
}
+static char *wifi_build_group_name(const unsigned char *ssid,
+ unsigned int ssid_len,
+ const char *mode,
+ const char *security)
+{
+ GString *str;
+ unsigned int i;
+
+ /* the last 3 is for the 2 '_' and '\0' */
+ str = g_string_sized_new((ssid_len * 2) + strlen(mode)
+ + strlen(security) + 3);
+ if (str == NULL)
+ return NULL;
+
+ for (i = 0; i < ssid_len; i++)
+ g_string_append_printf(str, "%02x", ssid[i]);
+
+ g_string_append_printf(str, "_%s_%s", mode, security);
+
+ return g_string_free(str, FALSE);
+}
+
void __connman_service_notify(struct connman_service *service,
unsigned int rx_packets, unsigned int tx_packets,
unsigned int rx_bytes, unsigned int tx_bytes,
}
GSequence *__connman_service_get_list(struct connman_session *session,
- service_match_cb service_match)
+ service_match_cb service_match,
+ create_service_entry_cb create_service_entry,
+ GDestroyNotify destroy_service_entry)
{
GSequence *list;
GSequenceIter *iter;
struct connman_service *service;
+ struct service_entry *entry;
- list = g_sequence_new(NULL);
+ list = g_sequence_new(destroy_service_entry);
if (list == NULL)
return NULL;
while (g_sequence_iter_is_end(iter) == FALSE) {
service = g_sequence_get(iter);
- if (service_match(session, service) == TRUE)
- g_sequence_append(list, service);
+ if (service_match(session, service) == TRUE) {
+ entry = create_service_entry(service, service->name,
+ service->state);
+ if (entry == NULL)
+ return list;
+
+ g_sequence_append(list, entry);
+ }
iter = g_sequence_iter_next(iter);
}
return list;
}
-connman_bool_t __connman_service_is_connecting(struct connman_service *service)
+void __connman_service_session_inc(struct connman_service *service)
{
- return is_connecting(service);
-}
+ DBG("service %p ref count %d", service,
+ g_atomic_int_get(&service->session_usage_count) + 1);
-connman_bool_t __connman_service_is_connected(struct connman_service *service)
-{
- return is_connected(service);
+ g_atomic_int_inc(&service->session_usage_count);
}
-connman_bool_t __connman_service_is_idle(struct connman_service *service)
+connman_bool_t __connman_service_session_dec(struct connman_service *service)
{
- return is_idle(service);
-}
+ DBG("service %p ref count %d", service,
+ g_atomic_int_get(&service->session_usage_count) - 1);
-const char *__connman_service_get_name(struct connman_service *service)
-{
- return service->name;
+ if (g_atomic_int_dec_and_test(&service->session_usage_count) == FALSE)
+ return FALSE;
+
+ return TRUE;
}
static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
connman_dbus_dict_append_basic(dict, "Type",
DBUS_TYPE_STRING, &str);
- str = mode2string(service->mode);
- if (str != NULL)
- connman_dbus_dict_append_basic(dict, "Mode",
- DBUS_TYPE_STRING, &str);
-
connman_dbus_dict_append_array(dict, "Security",
DBUS_TYPE_STRING, append_security, service);
- str = state2string(combine_state(service->state_ipv4,
- service->state_ipv6));
+ str = state2string(service->state);
if (str != NULL)
connman_dbus_dict_append_basic(dict, "State",
DBUS_TYPE_STRING, &str);
if (service->timeservers == NULL)
return;
- switch (combine_state(service->state_ipv4, service->state_ipv6)) {
+ switch (service->state) {
case CONNMAN_SERVICE_STATE_UNKNOWN:
case CONNMAN_SERVICE_STATE_IDLE:
case CONNMAN_SERVICE_STATE_ASSOCIATION:
void __connman_service_set_pac(struct connman_service *service,
const char *pac)
{
- if (pac == NULL)
- return;
-
g_free(service->pac);
service->pac = g_strdup(pac);
+
+ proxy_changed(service);
}
void __connman_service_set_identity(struct connman_service *service,
service->identity);
}
+void __connman_service_set_agent_identity(struct connman_service *service,
+ const char *agent_identity)
+{
+ 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)
{
"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)
+{
+ 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);
+ service_save(service);
} else if (g_str_equal(name, "Passphrase") == TRUE) {
const char *passphrase;
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);
static void set_idle(struct connman_service *service)
{
- service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+ service->state = service->state_ipv4 = service->state_ipv6 =
+ CONNMAN_SERVICE_STATE_IDLE;
service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
state_changed(service);
}
set_idle(service);
g_get_current_time(&service->modified);
- __connman_storage_save_service(service);
+ service_save(service);
} else if (g_str_equal(name, "Passphrase") == TRUE) {
if (service->immutable == TRUE)
return __connman_error_not_supported(msg);
passphrase_changed(service);
- __connman_storage_save_service(service);
+ service_save(service);
} else
return __connman_error_invalid_property(msg);
if (service->ignore == TRUE)
return TRUE;
- if (combine_state(service->state_ipv4, service->state_ipv6) ==
- CONNMAN_SERVICE_STATE_FAILURE)
+ if (service->state == CONNMAN_SERVICE_STATE_FAILURE)
return TRUE;
return FALSE;
if (is_connected(service) == TRUE)
return;
- if (is_ignore(service) == FALSE &&
- combine_state(service->state_ipv4,
- service->state_ipv6) ==
+ if (is_ignore(service) == FALSE && service->state ==
CONNMAN_SERVICE_STATE_IDLE)
break;
} else
autoconnect = TRUE;
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_FAILURE,
CONNMAN_IPCONFIG_TYPE_IPV4);
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_FAILURE,
CONNMAN_IPCONFIG_TYPE_IPV6);
return FALSE;
device = connman_network_get_device(service->network);
- if (device == NULL)
- return FALSE;
-
- 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);
+ if (device == NULL)
+ return FALSE;
- __connman_service_connect(service);
+ return __connman_device_get_reconnect(device);
}
static DBusMessage *connect_service(DBusConnection *conn,
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->immutable == TRUE)
return __connman_error_not_supported(msg);
- if (service->favorite == FALSE &&
- combine_state(service->state_ipv4, service->state_ipv6) !=
+ if (service->favorite == FALSE && service->state !=
CONNMAN_SERVICE_STATE_FAILURE)
return __connman_error_not_supported(msg);
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 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);
- __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_unref(service->network);
+ if (service->network != NULL) {
+ if (service->network_created == TRUE)
+ 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->domains);
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);
DBG("service %p", service);
service->refcount = 1;
+ service->session_usage_count = 0;
+
+ service->network_created = FALSE;
service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
- service->mode = CONNMAN_SERVICE_MODE_UNKNOWN;
service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
+ service->state = CONNMAN_SERVICE_STATE_UNKNOWN;
service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
service->state_ipv6 = CONNMAN_SERVICE_STATE_UNKNOWN;
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
struct connman_service *service_b = (void *) b;
enum connman_service_state state_a, state_b;
- state_a = combine_state(service_a->state_ipv4, service_a->state_ipv6);
- state_b = combine_state(service_b->state_ipv4, service_b->state_ipv6);
+ state_a = service_a->state;
+ 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)
g_sequence_sort_changed(iter, service_compare, NULL);
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
return 0;
}
-connman_bool_t __connman_service_get_immutable(struct connman_service *service)
-{
- if (service == NULL)
- return FALSE;
-
- return service->immutable;
-}
-
int __connman_service_set_immutable(struct connman_service *service,
connman_bool_t immutable)
{
__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);
- __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
+ services_changed(FALSE);
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
}
}
-int __connman_service_indicate_state(struct connman_service *service,
- enum connman_service_state new_state,
- enum connman_ipconfig_type type)
+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) {
+ 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) {
+ switch (service->security) {
+ case CONNMAN_SERVICE_SECURITY_WEP:
+ case CONNMAN_SERVICE_SECURITY_PSK:
+ __connman_service_set_passphrase(service, passphrase);
+ break;
+ case CONNMAN_SERVICE_SECURITY_8021X:
+ __connman_service_set_agent_passphrase(service,
+ passphrase);
+ break;
+ case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+ case CONNMAN_SERVICE_SECURITY_NONE:
+ case CONNMAN_SERVICE_SECURITY_WPA:
+ case CONNMAN_SERVICE_SECURITY_RSN:
+ DBG("service security '%s' not handled",
+ security2string(service->security));
+ break;
+ }
+ }
+
+ __connman_service_connect(service);
+
+ /* Never cache agent provided credentials */
+ __connman_service_set_agent_identity(service, NULL);
+ __connman_service_set_agent_passphrase(service, NULL);
+}
+
+static int service_indicate_state(struct connman_service *service)
{
- enum connman_service_state service_state,
- state = CONNMAN_SERVICE_STATE_IDLE;
+ enum connman_service_state old_state, new_state;
GSequenceIter *iter;
if (service == NULL)
return -EINVAL;
- if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
- if (service->state_ipv4 == new_state)
- return -EALREADY;
- state = combine_state(new_state, service->state_ipv6);
- } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
- if (service->state_ipv6 == new_state)
- return -EALREADY;
- state = combine_state(new_state, service->state_ipv4);
- } else
- return -EINVAL;
-
- service_state = combine_state(service->state_ipv4,
- service->state_ipv6);
+ old_state = service->state;
+ new_state = combine_state(service->state_ipv4, service->state_ipv6);
- DBG("service %p state %s/%s => %s new %s/%d => %s",
+ DBG("service %p old %s - new %s/%s => %s",
service,
+ state2string(old_state),
state2string(service->state_ipv4),
state2string(service->state_ipv6),
- state2string(service_state),
- state2string(new_state),
- type,
- state2string(state));
+ state2string(new_state));
- if (service_state == CONNMAN_SERVICE_STATE_FAILURE &&
- state == CONNMAN_SERVICE_STATE_IDLE)
- return -EINVAL;
-
- if (service_state == CONNMAN_SERVICE_STATE_IDLE &&
- state == CONNMAN_SERVICE_STATE_DISCONNECT)
- return -EINVAL;
+ if (old_state == new_state)
+ return -EALREADY;
- if (state == CONNMAN_SERVICE_STATE_IDLE &&
- service_state != CONNMAN_SERVICE_STATE_DISCONNECT) {
- state_changed(service);
+ service->state = new_state;
+ state_changed(service);
+ if (new_state == CONNMAN_SERVICE_STATE_IDLE &&
+ old_state != CONNMAN_SERVICE_STATE_DISCONNECT) {
reply_pending(service, ECONNABORTED);
__connman_service_disconnect(service);
__connman_stats_get(service, TRUE,
&service->stats_roaming.data);
}
-
- if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
- new_state == CONNMAN_SERVICE_STATE_CONFIGURATION)
- __connman_ipconfig_enable(service->ipconfig_ipv4);
- else if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
- new_state == CONNMAN_SERVICE_STATE_CONFIGURATION)
- __connman_ipconfig_enable(service->ipconfig_ipv6);
}
- if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
- service->state_ipv4 = new_state;
- else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
- service->state_ipv6 = new_state;
-
- if (state == service_state)
- return -EALREADY;
-
- state_changed(service);
-
- if (state == CONNMAN_SERVICE_STATE_ONLINE) {
+ if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
if (service->login_required == TRUE) {
service->login_required = FALSE;
login_changed(service);
connman_timeserver_sync();
}
- if (state == CONNMAN_SERVICE_STATE_IDLE) {
+ if (new_state == CONNMAN_SERVICE_STATE_IDLE) {
connman_bool_t reconnect;
reconnect = get_reconnect_state(service);
if (reconnect == TRUE)
__connman_service_auto_connect();
+
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
}
- if (state == CONNMAN_SERVICE_STATE_READY) {
- enum connman_service_proxy_method proxy_config;
+ if (new_state == CONNMAN_SERVICE_STATE_READY) {
enum connman_ipconfig_method method;
set_reconnect_state(service, TRUE);
service->userconnect = FALSE;
g_get_current_time(&service->modified);
- __connman_storage_save_service(service);
+ service_save(service);
update_nameservers(service);
dns_changed(service);
domain_changed(service);
- proxy_config = service->proxy_config;
-
- /*
- * 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);
- }
-
__connman_notifier_connect(service->type);
if (service->type == CONNMAN_SERVICE_TYPE_WIFI &&
__connman_ipconfig_disable_ipv6(
service->ipconfig_ipv6);
- } else if (state == CONNMAN_SERVICE_STATE_DISCONNECT) {
- __connman_location_finish(service);
+ } else if (new_state == CONNMAN_SERVICE_STATE_DISCONNECT) {
+ struct connman_service *def_service = get_default();
+
+ if (__connman_notifier_count_connected() == 0 &&
+ def_service != NULL &&
+ def_service->provider != NULL)
+ __connman_provider_disconnect(def_service->provider);
default_changed();
+ __connman_wispr_stop(service);
+
__connman_wpad_stop(service);
update_nameservers(service);
__connman_notifier_disconnect(service->type);
}
- if (state == CONNMAN_SERVICE_STATE_FAILURE) {
+ if (new_state == CONNMAN_SERVICE_STATE_FAILURE) {
if (service->userconnect == TRUE &&
__connman_agent_report_error(service,
error2string(service->error),
report_error_cb, NULL) == -EIO)
return 0;
service_complete(service);
+
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
} else
service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
if (iter != NULL)
g_sequence_sort_changed(iter, service_compare, NULL);
- __connman_profile_changed(FALSE);
+ services_changed(FALSE);
- service_state = combine_state(service->state_ipv4,
- service->state_ipv6);
- if (service_state == CONNMAN_SERVICE_STATE_ONLINE)
+ if (new_state == CONNMAN_SERVICE_STATE_ONLINE)
default_changed();
- if (service_state == CONNMAN_SERVICE_STATE_DISCONNECT) {
- struct connman_service *def_service = get_default();
-
- if (__connman_notifier_count_connected() == 0 &&
- def_service != NULL &&
- def_service->provider != NULL)
- __connman_provider_disconnect(def_service->provider);
- }
-
- if (service_state == CONNMAN_SERVICE_STATE_IDLE ||
- service_state == CONNMAN_SERVICE_STATE_FAILURE)
- __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
-
return 0;
}
if (service->error == CONNMAN_SERVICE_ERROR_INVALID_KEY)
__connman_service_set_passphrase(service, NULL);
- return __connman_service_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)
{
- enum connman_service_state state;
-
DBG("service %p", service);
if (service == NULL)
return -EINVAL;
- state = combine_state(service->state_ipv4, service->state_ipv6);
-
- if (state != CONNMAN_SERVICE_STATE_FAILURE)
+ if (service->state != CONNMAN_SERVICE_STATE_FAILURE)
return -EINVAL;
service->state_ipv4 = service->state_ipv6 =
if (service->favorite == TRUE)
set_reconnect_state(service, TRUE);
- __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE,
+ __connman_service_ipconfig_indicate_state(service,
+ CONNMAN_SERVICE_STATE_IDLE,
CONNMAN_IPCONFIG_TYPE_IPV6);
/*
service->state_ipv4 != CONNMAN_SERVICE_STATE_FAILURE)
return 0;
- return __connman_service_indicate_state(service,
+ return __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_IDLE,
CONNMAN_IPCONFIG_TYPE_IPV4);
}
default_changed();
- __connman_location_detect(service);
-
return 0;
}
+enum connman_service_state __connman_service_ipconfig_get_state(
+ struct connman_service *service,
+ enum connman_ipconfig_type type)
+{
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ return service->state_ipv4;
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ return service->state_ipv6;
+
+ return CONNMAN_SERVICE_STATE_UNKNOWN;
+}
+
+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.
+ */
+
+ if (service->proxy != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN)
+ goto done;
+
+ if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN &&
+ (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_AUTO ||
+ service->pac != NULL))
+ goto done;
+
+ if (__connman_wpad_start(service) < 0) {
+ service->proxy = CONNMAN_SERVICE_PROXY_METHOD_DIRECT;
+ __connman_notifier_proxy_changed(service);
+ }
+
+ return;
+
+done:
+ __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+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);
+ else
+ __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;
+ break;
+ case CONNMAN_SERVICE_STATE_FAILURE:
+ break;
+ }
+
+ /* We keep that state */
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ service->state_ipv4 = new_state;
+ else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ service->state_ipv6 = new_state;
+
+ ret = service_indicate_state(service);
+
+ /*
+ * 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);
+ }
+
+ } 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 ret;
+}
+
int __connman_service_request_login(struct connman_service *service)
{
DBG("service %p", service);
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;
int __connman_service_connect(struct connman_service *service)
{
- enum connman_service_state state;
int err;
- state = combine_state(service->state_ipv4, service->state_ipv6);
-
- DBG("service %p state %s", service, state2string(state));
+ DBG("service %p state %s", service, state2string(service->state));
if (is_connected(service) == TRUE)
return -EISCONN;
return 0;
if (err == -EINPROGRESS) {
- service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
- connect_timeout, service);
+ if (service->timeout == 0)
+ service->timeout = g_timeout_add_seconds(
+ CONNECT_TIMEOUT, connect_timeout, service);
return -EINPROGRESS;
}
- if (err == -ENOKEY)
- return -ENOKEY;
-
- if (service->userconnect == TRUE)
- reply_pending(service, err);
-
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_FAILURE,
CONNMAN_IPCONFIG_TYPE_IPV4);
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
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) {
+ if (__connman_agent_request_passphrase_input(service,
+ request_input_cb,
+ NULL) == -EIO)
+ return -EINPROGRESS;
+ }
+ reply_pending(service, err);
+ }
+
return err;
}
}
static struct connman_network *create_hidden_wifi(struct connman_device *device,
- const char *ssid, const char *mode, const char *security)
+ const char *ssid, const char *mode, const char *security,
+ const char *group)
{
struct connman_network *network;
char *name;
if (ssid_len < 1)
return NULL;
- network = connman_network_create(NULL, CONNMAN_NETWORK_TYPE_WIFI);
+ network = connman_network_create(group, CONNMAN_NETWORK_TYPE_WIFI);
if (network == NULL)
return NULL;
unsigned int ssid_len = 0;
const char *ident;
char *name, *group;
- gboolean created = FALSE;
int err;
dbus_message_iter_init(msg, &iter);
g_strcmp0(security, "ieee8021x") != 0)
return -EINVAL;
- device = __connman_element_find_device(CONNMAN_SERVICE_TYPE_WIFI);
+ device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
if (device == NULL)
return -EOPNOTSUPP;
else
group_security = security;
- group = connman_wifi_build_group_name((unsigned char *) ssid,
+ group = wifi_build_group_name((unsigned char *) ssid,
ssid_len, mode, group_security);
if (group == NULL)
return -EINVAL;
if (service != NULL)
goto done;
- network = create_hidden_wifi(device, ssid, mode, security);
- if (network != NULL) {
+ network = create_hidden_wifi(device, ssid, mode, security, group);
+ if (network != NULL)
connman_network_set_group(network, group);
- created = TRUE;
- }
service = lookup_by_identifier(name);
goto failed;
}
+ service->network_created = TRUE;
+
if (is_connected(service) == TRUE) {
err = -EISCONN;
goto failed;
return 0;
failed:
- if (service != NULL && created == TRUE) {
+ if (service != NULL && service->network_created == TRUE) {
struct connman_network *network = service->network;
if (network != NULL) {
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;
service->identifier = g_strdup(identifier);
- service->profile = g_strdup(__connman_profile_active_ident());
-
iter = g_sequence_insert_sorted(service_list, service,
service_compare, NULL);
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);
+ service->path = g_strdup_printf("%s/service/%s", CONNMAN_PATH,
+ service->identifier);
DBG("path %s", service->path);
__connman_config_provision_service(service);
- __connman_storage_load_service(service);
+ service_load(service);
g_dbus_register_interface(connection, service->path,
CONNMAN_SERVICE_INTERFACE,
if (iter != NULL)
g_sequence_sort_changed(iter, service_compare, NULL);
- __connman_profile_changed(TRUE);
+ services_changed(TRUE);
return 0;
}
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)
if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
method == CONNMAN_IPCONFIG_METHOD_AUTO)
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_READY,
CONNMAN_IPCONFIG_TYPE_IPV6);
if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
method == CONNMAN_IPCONFIG_METHOD_OFF)
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_DISCONNECT,
CONNMAN_IPCONFIG_TYPE_IPV6);
if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
method == CONNMAN_IPCONFIG_METHOD_OFF)
- __connman_service_indicate_state(service,
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_DISCONNECT,
CONNMAN_IPCONFIG_TYPE_IPV4);
.ip_release = service_ip_release,
};
-static void setup_ip4config(struct connman_service *service, int index)
+static void setup_ip4config(struct connman_service *service, int index,
+ enum connman_ipconfig_method method)
{
if (index < 0)
return;
if (service->ipconfig_ipv4 == NULL)
return;
- connman_ipconfig_set_method(service->ipconfig_ipv4,
- CONNMAN_IPCONFIG_METHOD_DHCP);
+ connman_ipconfig_set_method(service->ipconfig_ipv4, method);
connman_ipconfig_set_data(service->ipconfig_ipv4, service);
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_global();
+ 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);
+ 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;
return CONNMAN_SERVICE_TYPE_UNKNOWN;
}
-static enum connman_service_mode convert_wifi_mode(const char *mode)
-{
- if (mode == NULL)
- return CONNMAN_SERVICE_MODE_UNKNOWN;
- else if (g_str_equal(mode, "managed") == TRUE)
- return CONNMAN_SERVICE_MODE_MANAGED;
- else if (g_str_equal(mode, "adhoc") == TRUE)
- return CONNMAN_SERVICE_MODE_ADHOC;
- else
- return CONNMAN_SERVICE_MODE_UNKNOWN;
-}
-
static enum connman_service_security convert_wifi_security(const char *security)
{
if (security == NULL)
return CONNMAN_SERVICE_SECURITY_PSK;
else if (g_str_equal(security, "ieee8021x") == TRUE)
return CONNMAN_SERVICE_SECURITY_8021X;
- else if (g_str_equal(security, "wpa") == TRUE)
- return CONNMAN_SERVICE_SECURITY_WPA;
- else if (g_str_equal(security, "rsn") == TRUE)
- return CONNMAN_SERVICE_SECURITY_RSN;
- else
- return CONNMAN_SERVICE_SECURITY_UNKNOWN;
-}
-
-static enum connman_service_mode convert_cellular_mode(connman_uint8_t mode)
-{
- switch (mode) {
- case 0:
- case 1:
- return CONNMAN_SERVICE_MODE_GPRS;
- case 3:
- return CONNMAN_SERVICE_MODE_EDGE;
- case 2:
- case 4:
- case 5:
- case 6:
- return CONNMAN_SERVICE_MODE_UMTS;
- }
-
- return CONNMAN_SERVICE_MODE_UNKNOWN;
-}
-
-static void update_from_network(struct connman_service *service,
- struct connman_network *network)
-{
- connman_uint8_t strength = service->strength;
- GSequenceIter *iter;
- const char *str;
-
- DBG("service %p network %p", service, network);
-
- if (is_connected(service) == TRUE)
- return;
-
- if (is_connecting(service) == TRUE)
- return;
-
- str = connman_network_get_string(network, "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 = connman_network_get_uint8(network, "Strength");
- service->roaming = connman_network_get_bool(network, "Roaming");
-
- if (service->strength == 0) {
- /*
- * Filter out 0-values; it's unclear what they mean
- * and they cause anomalous sorting of the priority list.
- */
- service->strength = strength;
- }
-
- str = connman_network_get_string(network, "WiFi.Mode");
- service->mode = convert_wifi_mode(str);
-
- str = connman_network_get_string(network, "WiFi.Security");
- service->security = convert_wifi_security(str);
-
- if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
- connman_uint8_t value = connman_network_get_uint8(network,
- "Cellular.Mode");
-
- service->mode = convert_cellular_mode(value);
- } else if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
- 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);
-
- strength_changed(service);
- }
-
- if (service->network == NULL)
- service->network = connman_network_ref(network);
-
- iter = g_hash_table_lookup(service_hash, service->identifier);
- if (iter != NULL)
- g_sequence_sort_changed(iter, service_compare, NULL);
-}
-
-/**
- * __connman_service_create_from_network:
- * @network: network structure
- *
- * Look up service by network and if not found, create one
- */
-struct connman_service * __connman_service_create_from_network(struct connman_network *network)
-{
- struct connman_service *service;
- struct connman_device *device;
- const char *ident, *group;
- char *name;
- int index;
-
- DBG("network %p", network);
-
- ident = __connman_network_get_ident(network);
- if (ident == NULL)
- return NULL;
-
- group = connman_network_get_group(network);
- if (group == 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;
-
- update_from_network(service, network);
-
- index = connman_network_get_index(network);
-
- if (service->ipconfig_ipv4 == NULL)
- setup_ip4config(service, index);
-
- 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;
- enum connman_service_mode mode;
- connman_uint8_t strength, value;
- 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_uint8(service->network, "Strength");
- 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)
- goto done;
-
- 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);
-
-done:
- if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
- return;
-
- value = connman_network_get_uint8(service->network, "Cellular.Mode");
- mode = convert_cellular_mode(value);
-
- if (mode == service->mode)
- return;
-
- service->mode = mode;
-
- mode_changed(service);
-}
-
-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);
+ else if (g_str_equal(security, "wpa") == TRUE)
+ return CONNMAN_SERVICE_SECURITY_WPA;
+ else if (g_str_equal(security, "rsn") == TRUE)
+ return CONNMAN_SERVICE_SECURITY_RSN;
+ else
+ return CONNMAN_SERVICE_SECURITY_UNKNOWN;
}
-/**
- * __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)
+static void update_from_network(struct connman_service *service,
+ struct connman_network *network)
{
- 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);
+ connman_uint8_t strength = service->strength;
+ GSequenceIter *iter;
+ const char *str;
- if (service == NULL)
- return NULL;
+ DBG("service %p network %p", service, network);
- service->type = CONNMAN_SERVICE_TYPE_VPN;
- service->provider = connman_provider_ref(provider);
- service->autoconnect = FALSE;
+ if (is_connected(service) == TRUE)
+ return;
- service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+ if (is_connecting(service) == TRUE)
+ return;
- str = connman_provider_get_string(provider, "Name");
+ str = connman_network_get_string(network, "Name");
if (str != NULL) {
g_free(service->name);
service->name = g_strdup(str);
service->hidden = TRUE;
}
- service->strength = 0;
+ service->strength = connman_network_get_strength(network);
+ service->roaming = connman_network_get_bool(network, "Roaming");
- if (service->ipconfig_ipv4 == NULL)
- service->ipconfig_ipv4 = connman_ipconfig_create(index,
- CONNMAN_IPCONFIG_TYPE_IPV4);
- if (service->ipconfig_ipv4 == NULL)
- return service;
+ if (service->strength == 0) {
+ /*
+ * Filter out 0-values; it's unclear what they mean
+ * and they cause anomalous sorting of the priority list.
+ */
+ service->strength = strength;
+ }
- connman_ipconfig_set_method(service->ipconfig_ipv4,
- CONNMAN_IPCONFIG_METHOD_MANUAL);
- connman_ipconfig_set_data(service->ipconfig_ipv4, service);
- connman_ipconfig_set_ops(service->ipconfig_ipv4, &service_ops);
+ str = connman_network_get_string(network, "WiFi.Security");
+ service->security = convert_wifi_security(str);
- if (service->ipconfig_ipv6 == NULL)
- service->ipconfig_ipv6 = connman_ipconfig_create(index,
- CONNMAN_IPCONFIG_TYPE_IPV6);
- if (service->ipconfig_ipv6 == NULL)
- return service;
+ if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+ service->wps = connman_network_get_bool(network, "WiFi.WPS");
- connman_ipconfig_set_method(service->ipconfig_ipv6,
- CONNMAN_IPCONFIG_METHOD_OFF);
- connman_ipconfig_set_data(service->ipconfig_ipv6, service);
- connman_ipconfig_set_ops(service->ipconfig_ipv6, &service_ops);
+ if (service->strength > strength && service->network != NULL) {
+ service->network = network;
- service_register(service);
+ strength_changed(service);
+ }
- __connman_notifier_service_add(service);
+ if (service->network == NULL)
+ service->network = network;
- return service;
+ iter = g_hash_table_lookup(service_hash, service->identifier);
+ if (iter != NULL)
+ g_sequence_sort_changed(iter, service_compare, NULL);
}
-static int service_load(struct connman_service *service)
+/**
+ * __connman_service_create_from_network:
+ * @network: network structure
+ *
+ * Look up service by network and if not found, create one
+ */
+struct connman_service * __connman_service_create_from_network(struct connman_network *network)
{
- 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;
+ struct connman_service *service;
+ struct connman_device *device;
+ const char *ident, *group;
+ char *name;
+ int index;
- DBG("service %p", service);
+ DBG("network %p", network);
+
+ if (network == NULL)
+ return NULL;
+ ident = __connman_network_get_ident(network);
if (ident == NULL)
- return -EINVAL;
+ return NULL;
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
- if (pathname == NULL)
- return -ENOMEM;
+ group = connman_network_get_group(network);
+ if (group == NULL)
+ return NULL;
- keyfile = g_key_file_new();
+ name = g_strdup_printf("%s_%s_%s",
+ __connman_network_get_type(network), ident, group);
+ service = service_get(name);
+ g_free(name);
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
- g_free(pathname);
- return -ENOENT;
- }
+ if (service == NULL)
+ return NULL;
- g_free(pathname);
+ if (__connman_network_get_weakness(network) == TRUE)
+ return service;
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE) {
- g_free(data);
- return -EILSEQ;
+ if (service->path != NULL) {
+ update_from_network(service, network);
+ services_changed(TRUE);
+ return service;
}
- g_free(data);
+ 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->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);
- }
+ service->autoconnect = TRUE;
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;
- }
+ service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+ service->state = combine_state(service->state_ipv4, service->state_ipv6);
- str = g_key_file_get_string(keyfile,
- service->identifier, "Proxy.Method", NULL);
- if (str != NULL)
- service->proxy_config = string2proxymethod(str);
+ update_from_network(service, network);
- g_free(str);
+ index = connman_network_get_index(network);
- 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;
- }
+ if (service->ipconfig_ipv4 == NULL)
+ setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_DHCP);
- 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;
- }
+ if (service->ipconfig_ipv6 == NULL)
+ setup_ip6config(service, index);
- str = g_key_file_get_string(keyfile,
- service->identifier, "Proxy.URL", NULL);
- if (str != NULL) {
- g_free(service->pac);
- service->pac = str;
+ 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();
}
-done:
- g_key_file_free(keyfile);
+ __connman_notifier_service_add(service, service->name);
- return err;
+ return service;
}
-static int service_save(struct connman_service *service)
+void __connman_service_update_from_network(struct connman_network *network)
{
- 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;
+ struct connman_service *service;
+ connman_uint8_t strength;
+ connman_bool_t roaming;
+ GSequenceIter *iter;
+ const char *name;
+ connman_bool_t stats_enable;
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
- if (pathname == NULL)
- return -ENOMEM;
+ DBG("network %p", network);
- keyfile = g_key_file_new();
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
- goto update;
+ if (service->network == NULL)
+ return;
- if (length > 0) {
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE)
- goto done;
+ 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);
}
- g_free(data);
+ if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+ service->wps = connman_network_get_bool(network, "WiFi.WPS");
-update:
- if (service->name != NULL)
- g_key_file_set_string(keyfile, service->identifier,
- "Name", service->name);
+ strength = connman_network_get_strength(service->network);
+ if (strength == service->strength)
+ goto roaming;
- 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->network) {
- const unsigned char *ssid;
- unsigned int ssid_len = 0;
+ service->strength = strength;
- ssid = connman_network_get_blob(service->network,
- "WiFi.SSID", &ssid_len);
+ strength_changed(service);
- if (ssid != NULL && ssid_len > 0 && ssid[0] != '\0') {
- char *identifier = service->identifier;
- GString *str;
- unsigned int i;
+roaming:
+ roaming = connman_network_get_bool(service->network, "Roaming");
+ if (roaming == service->roaming)
+ return;
- str = g_string_sized_new(ssid_len * 2);
- if (str == NULL) {
- err = -ENOMEM;
- goto done;
- }
+ stats_enable = stats_enabled(service);
+ if (stats_enable == TRUE)
+ stats_stop(service);
- for (i = 0; i < ssid_len; i++)
- g_string_append_printf(str,
- "%02x", ssid[i]);
+ service->roaming = roaming;
- g_key_file_set_string(keyfile, identifier,
- "SSID", str->str);
+ if (stats_enable == TRUE)
+ stats_start(service);
- g_string_free(str, TRUE);
- }
- }
- /* fall through */
+ roaming_changed(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);
+ iter = g_hash_table_lookup(service_hash, service->identifier);
+ if (iter != NULL)
+ g_sequence_sort_changed(iter, service_compare, NULL);
+}
- if (service->favorite == TRUE)
- g_key_file_set_boolean(keyfile, service->identifier,
- "AutoConnect", service->autoconnect);
+void __connman_service_remove_from_network(struct connman_network *network)
+{
+ struct connman_service *service;
- 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;
- }
+ DBG("network %p", network);
- str = g_time_val_to_iso8601(&service->modified);
- if (str != NULL) {
- g_key_file_set_string(keyfile, service->identifier,
- "Modified", str);
- g_free(str);
- }
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
- 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);
+ __connman_service_put(service);
+}
- if (service->ipconfig_ipv4 != NULL)
- __connman_ipconfig_save(service->ipconfig_ipv4, keyfile,
- service->identifier, "IPv4.");
+/**
+ * __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);
- if (service->ipconfig_ipv6 != NULL)
- __connman_ipconfig_save(service->ipconfig_ipv6, keyfile,
- service->identifier, "IPv6.");
+ DBG("provider %p", provider);
- if (service->nameservers_config != NULL) {
- guint len = g_strv_length(service->nameservers_config);
+ ident = __connman_provider_get_ident(provider);
+ if (ident == NULL)
+ return NULL;
- 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);
+ name = g_strdup_printf("vpn_%s", ident);
+ service = service_get(name);
+ g_free(name);
- if (service->domains != NULL) {
- guint len = g_strv_length(service->domains);
+ if (service == NULL)
+ return NULL;
- 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);
+ service->type = CONNMAN_SERVICE_TYPE_VPN;
+ service->provider = connman_provider_ref(provider);
+ service->autoconnect = FALSE;
+ service->userconnect = TRUE;
- cst_str = proxymethod2string(service->proxy_config);
- if (cst_str != NULL)
- g_key_file_set_string(keyfile, service->identifier,
- "Proxy.Method", cst_str);
+ service->state_ipv4 = service->state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
- if (service->proxies != NULL) {
- guint len = g_strv_length(service->proxies);
+ 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;
+ }
- 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);
+ service->strength = 0;
- if (service->excludes != NULL) {
- guint len = g_strv_length(service->excludes);
+ if (service->ipconfig_ipv4 == NULL)
+ setup_ip4config(service, index, CONNMAN_IPCONFIG_METHOD_MANUAL);
- 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);
+ if (service->ipconfig_ipv6 == NULL)
+ setup_ip6config(service, index);
- 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);
+ service_register(service);
- data = g_key_file_to_data(keyfile, &length, NULL);
+ __connman_notifier_service_add(service, service->name);
- if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
- connman_error("Failed to store service information");
+ return service;
+}
-done:
- g_free(data);
+void __connman_service_downgrade_state(struct connman_service *service)
+{
+ if (service == NULL)
+ return;
- g_key_file_free(keyfile);
+ DBG("service %p state4 %d state6 %d", service, service->state_ipv4,
+ service->state_ipv6);
- g_free(pathname);
+ if (service->state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
+ __connman_service_ipconfig_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
- return err;
+ if (service->state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
+ __connman_service_ipconfig_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
}
-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);
}