*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <config.h>
#endif
+#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <gdbus.h>
+#include <gweb/gresolv.h>
#include "connman.h"
static GSList *driver_list = NULL;
-struct connman_route {
- char *host;
- char *netmask;
- char *gateway;
-};
-
struct connman_provider {
- struct connman_element element;
+ int refcount;
+ bool immutable;
struct connman_service *vpn_service;
+ int index;
char *identifier;
- char *name;
- char *type;
- char *host;
- char *dns;
- char *domain;
- GSList *route_list;
+ int family;
struct connman_provider_driver *driver;
void *driver_data;
};
void __connman_provider_append_properties(struct connman_provider *provider,
DBusMessageIter *iter)
{
- if (provider->host != NULL)
+ const char *host, *domain, *type;
+
+ if (!provider->driver || !provider->driver->get_property)
+ return;
+
+ host = provider->driver->get_property(provider, "Host");
+ domain = provider->driver->get_property(provider, "Domain");
+ type = provider->driver->get_property(provider, "Type");
+
+ if (host)
connman_dbus_dict_append_basic(iter, "Host",
- DBUS_TYPE_STRING, &provider->host);
+ DBUS_TYPE_STRING, &host);
- if (provider->domain != NULL)
+ if (domain)
connman_dbus_dict_append_basic(iter, "Domain",
- DBUS_TYPE_STRING, &provider->domain);
+ DBUS_TYPE_STRING, &domain);
- if (provider->type != NULL)
+ if (type)
connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING,
- &provider->type);
+ &type);
}
-static struct connman_provider *connman_provider_lookup(const char *identifier)
+struct connman_provider *
+connman_provider_ref_debug(struct connman_provider *provider,
+ const char *file, int line, const char *caller)
{
- struct connman_provider *provider = NULL;
+ DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount + 1,
+ file, line, caller);
- provider = g_hash_table_lookup(provider_hash, identifier);
+ __sync_fetch_and_add(&provider->refcount, 1);
return provider;
}
-static int connman_provider_setup_vpn_ipv4(struct connman_provider *provider,
- struct connman_element *element)
+static void provider_remove(struct connman_provider *provider)
{
- if (element == NULL || provider == NULL)
- return -EINVAL;
-
- DBG("set vpn type %d", element->type);
-
- g_free(element->ipv4.address);
- element->ipv4.address = g_strdup(provider->element.ipv4.address);
-
- g_free(element->ipv4.peer);
- element->ipv4.peer = g_strdup(provider->element.ipv4.peer);
-
- g_free(element->ipv4.netmask);
- element->ipv4.netmask = g_strdup(provider->element.ipv4.netmask);
-
- g_free(element->ipv4.gateway);
- element->ipv4.gateway = g_strdup(provider->element.ipv4.gateway);
-
- g_free(element->ipv4.broadcast);
- element->ipv4.broadcast = g_strdup(provider->element.ipv4.broadcast);
-
- g_free(element->ipv4.pac);
- element->ipv4.pac = g_strdup(provider->element.ipv4.pac);
-
- return connman_element_register(element, &provider->element);
+ if (provider->driver) {
+ provider->driver->remove(provider);
+ provider->driver = NULL;
+ }
}
-struct connman_provider *connman_provider_ref(struct connman_provider *provider)
+static void provider_destruct(struct connman_provider *provider)
{
DBG("provider %p", provider);
- if (connman_element_ref(&provider->element) == NULL)
- return NULL;
-
- return provider;
+ g_free(provider->identifier);
+ g_free(provider);
}
-void connman_provider_unref(struct connman_provider *provider)
+void connman_provider_unref_debug(struct connman_provider *provider,
+ const char *file, int line, const char *caller)
{
- DBG("provider %p", provider);
+ DBG("%p ref %d by %s:%d:%s()", provider, provider->refcount - 1,
+ file, line, caller);
- connman_element_unref(&provider->element);
+ if (__sync_fetch_and_sub(&provider->refcount, 1) != 1)
+ return;
+
+ provider_destruct(provider);
}
-static gboolean match_driver(struct connman_provider *provider,
- struct connman_provider_driver *driver)
+static int provider_indicate_state(struct connman_provider *provider,
+ enum connman_service_state state)
{
- if (g_strcmp0(driver->name, provider->type) == 0)
- return TRUE;
+ DBG("state %d", state);
+
+ __connman_service_ipconfig_indicate_state(provider->vpn_service, state,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
- return FALSE;
+ return __connman_service_ipconfig_indicate_state(provider->vpn_service,
+ state, CONNMAN_IPCONFIG_TYPE_IPV6);
}
-static int provider_probe(struct connman_provider *provider)
+int connman_provider_disconnect(struct connman_provider *provider)
{
- GSList *list;
-
- DBG("provider %p name %s", provider, provider->name);
-
- if (provider->driver != NULL)
- return -EALREADY;
+ int err;
- for (list = driver_list; list; list = list->next) {
- struct connman_provider_driver *driver = list->data;
+ DBG("provider %p", provider);
- if (match_driver(provider, driver) == FALSE)
- continue;
+ if (provider->driver && provider->driver->disconnect)
+ err = provider->driver->disconnect(provider);
+ else
+ return -EOPNOTSUPP;
- DBG("driver %p name %s", driver, driver->name);
+ if (provider->vpn_service)
+ provider_indicate_state(provider,
+ CONNMAN_SERVICE_STATE_DISCONNECT);
- if (driver->probe != NULL && driver->probe(provider) == 0) {
- provider->driver = driver;
- break;
- }
- }
+ if (err < 0)
+ return err;
- if (provider->driver == NULL)
- return -ENODEV;
+ if (provider->vpn_service)
+ provider_indicate_state(provider,
+ CONNMAN_SERVICE_STATE_IDLE);
return 0;
}
-int __connman_provider_disconnect(struct connman_provider *provider)
+int connman_provider_remove(struct connman_provider *provider)
{
- int err;
+ DBG("Removing VPN %s", provider->identifier);
- DBG("provider %p", provider);
-
- if (provider->driver != NULL && provider->driver->disconnect != NULL)
- err = provider->driver->disconnect(provider);
- else
- return -EOPNOTSUPP;
+ provider_remove(provider);
- if (provider->vpn_service != NULL)
- __connman_service_indicate_state(provider->vpn_service,
- CONNMAN_SERVICE_STATE_DISCONNECT);
- if (err < 0) {
- if (err != -EINPROGRESS)
- return err;
+ connman_provider_set_state(provider, CONNMAN_PROVIDER_STATE_IDLE);
- return -EINPROGRESS;
- }
+ g_hash_table_remove(provider_hash, provider->identifier);
return 0;
}
-int __connman_provider_connect(struct connman_provider *provider)
+int __connman_provider_connect(struct connman_provider *provider,
+ const char *dbus_sender)
{
int err;
DBG("provider %p", provider);
- g_free(provider->element.ipv4.address);
- g_free(provider->element.ipv4.peer);
- g_free(provider->element.ipv4.netmask);
- g_free(provider->element.ipv4.gateway);
- g_free(provider->element.ipv4.broadcast);
- g_free(provider->element.ipv4.pac);
-
- provider->element.ipv4.address = NULL;
- provider->element.ipv4.peer = NULL;
- provider->element.ipv4.netmask = NULL;
- provider->element.ipv4.gateway = NULL;
- provider->element.ipv4.broadcast = NULL;
- provider->element.ipv4.pac = NULL;
-
- if (provider->driver != NULL && provider->driver->connect != NULL)
- err = provider->driver->connect(provider);
+ if (provider->driver && provider->driver->connect)
+ err = provider->driver->connect(provider, dbus_sender);
else
return -EOPNOTSUPP;
if (err != -EINPROGRESS)
return err;
- __connman_service_indicate_state(provider->vpn_service,
+ provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_ASSOCIATION);
+
return -EINPROGRESS;
}
return 0;
}
-int __connman_provider_remove(const char *path)
+int __connman_provider_remove_by_path(const char *path)
{
struct connman_provider *provider;
GHashTableIter iter;
DBG("path %s", path);
g_hash_table_iter_init(&iter, provider_hash);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
const char *srv_path;
provider = value;
- if (provider->vpn_service == NULL)
+ if (!provider->vpn_service)
continue;
srv_path = __connman_service_get_path(provider->vpn_service);
if (g_strcmp0(srv_path, path) == 0) {
DBG("Removing VPN %s", provider->identifier);
+
+ provider_remove(provider);
+
+ connman_provider_set_state(provider,
+ CONNMAN_PROVIDER_STATE_IDLE);
+
g_hash_table_remove(provider_hash,
provider->identifier);
return 0;
}
static int set_connected(struct connman_provider *provider,
- connman_bool_t connected)
+ bool connected)
{
struct connman_service *service = provider->vpn_service;
+ struct connman_ipconfig *ipconfig;
- if (service == NULL)
+ if (!service)
return -ENODEV;
- if (connected == TRUE) {
- enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
- struct connman_element *element;
- char *nameservers = NULL, *name = NULL;
- const char *value;
- char *second_ns;
- GSList *list;
- int err;
-
- __connman_service_indicate_state(provider->vpn_service,
- CONNMAN_SERVICE_STATE_CONFIGURATION);
-
- type = CONNMAN_ELEMENT_TYPE_IPV4;
-
- element = connman_element_create(NULL);
- if (element == NULL)
- return -ENOMEM;
-
- element->type = type;
- element->index = provider->element.index;
-
- err = connman_provider_setup_vpn_ipv4(provider, element);
- if (err < 0) {
- connman_element_unref(element);
+ ipconfig = __connman_service_get_ipconfig(service, provider->family);
- __connman_service_indicate_state(service,
+ if (connected) {
+ if (!ipconfig) {
+ provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_FAILURE);
-
- return err;
+ return -EIO;
}
- __connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_READY);
-
- __connman_service_set_domainname(service, provider->domain);
-
- name = connman_inet_ifname(provider->element.index);
+ __connman_ipconfig_address_add(ipconfig);
+#if defined TIZEN_EXT
+ __connman_ipconfig_gateway_add(ipconfig, service);
+#else
+ __connman_ipconfig_gateway_add(ipconfig);
+#endif
- nameservers = g_strdup(provider->dns);
- value = nameservers;
- second_ns = strchr(value, ' ');
- if (second_ns)
- *(second_ns++) = 0;
- __connman_service_append_nameserver(service, value);
- value = second_ns;
+ provider_indicate_state(provider,
+ CONNMAN_SERVICE_STATE_READY);
- while (value) {
- char *next = strchr(value, ' ');
- if (next)
- *(next++) = 0;
+ if (provider->driver && provider->driver->set_routes)
+ provider->driver->set_routes(provider,
+ CONNMAN_PROVIDER_ROUTE_ALL);
- connman_resolver_append(name, provider->domain, value);
- value = next;
+ } else {
+ if (ipconfig) {
+ provider_indicate_state(provider,
+ CONNMAN_SERVICE_STATE_DISCONNECT);
+ __connman_ipconfig_gateway_remove(ipconfig);
}
- g_free(nameservers);
- g_free(name);
-
- for (list = provider->route_list; list; list = list->next) {
- struct connman_route *route = list->data;
-
- connman_inet_add_network_route(provider->element.index,
- route->host,
- route->gateway,
- route->netmask);
- /* XXX Need to handle IPv6 too */
- }
- } else {
- connman_element_unregister_children(&provider->element);
- __connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_IDLE);
+ provider_indicate_state(provider,
+ CONNMAN_SERVICE_STATE_IDLE);
}
return 0;
int connman_provider_set_state(struct connman_provider *provider,
enum connman_provider_state state)
{
- if (provider == NULL || provider->vpn_service == NULL)
+ if (!provider || !provider->vpn_service)
return -EINVAL;
switch (state) {
case CONNMAN_PROVIDER_STATE_UNKNOWN:
return -EINVAL;
case CONNMAN_PROVIDER_STATE_IDLE:
- return set_connected(provider, FALSE);
+ return set_connected(provider, false);
case CONNMAN_PROVIDER_STATE_CONNECT:
- return __connman_service_indicate_state(provider->vpn_service,
+ return provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_ASSOCIATION);
case CONNMAN_PROVIDER_STATE_READY:
- return set_connected(provider, TRUE);
+ return set_connected(provider, true);
case CONNMAN_PROVIDER_STATE_DISCONNECT:
- return __connman_service_indicate_state(provider->vpn_service,
+ return provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_DISCONNECT);
case CONNMAN_PROVIDER_STATE_FAILURE:
- return __connman_service_indicate_state(provider->vpn_service,
+ return provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_FAILURE);
}
return -EINVAL;
}
-static void unregister_provider(gpointer data)
-{
- struct connman_provider *provider = data;
- struct connman_service *service = provider->vpn_service;
-
- DBG("provider %p", provider);
-
- provider->vpn_service = NULL;
- __connman_service_put(service);
+int connman_provider_indicate_error(struct connman_provider *provider,
+ enum connman_provider_error error)
+{
+ enum connman_service_error service_error;
+
+ switch (error) {
+ case CONNMAN_PROVIDER_ERROR_LOGIN_FAILED:
+ service_error = CONNMAN_SERVICE_ERROR_LOGIN_FAILED;
+ break;
+ case CONNMAN_PROVIDER_ERROR_AUTH_FAILED:
+ service_error = CONNMAN_SERVICE_ERROR_AUTH_FAILED;
+ break;
+ case CONNMAN_PROVIDER_ERROR_CONNECT_FAILED:
+ service_error = CONNMAN_SERVICE_ERROR_CONNECT_FAILED;
+ break;
+ default:
+ service_error = CONNMAN_SERVICE_ERROR_UNKNOWN;
+ break;
+ }
- connman_element_unregister(&provider->element);
- connman_provider_unref(provider);
+ return __connman_service_indicate_error(provider->vpn_service,
+ service_error);
}
-static void provider_destruct(struct connman_element *element)
+int connman_provider_create_service(struct connman_provider *provider)
{
- struct connman_provider *provider = element->private;
- GSList *list;
+ if (provider->vpn_service) {
+ bool connected;
- DBG("provider %p", provider);
+ connected = __connman_service_is_connected_state(
+ provider->vpn_service, CONNMAN_IPCONFIG_TYPE_IPV4);
+ if (connected)
+ return -EALREADY;
- g_free(provider->name);
- g_free(provider->type);
- g_free(provider->domain);
- g_free(provider->identifier);
- g_free(provider->dns);
+ connected = __connman_service_is_connected_state(
+ provider->vpn_service, CONNMAN_IPCONFIG_TYPE_IPV6);
+ if (connected)
+ return -EALREADY;
- for (list = provider->route_list; list; list = list->next) {
- struct connman_route *route = list->data;
-
- g_free(route->host);
- g_free(route->netmask);
- g_free(route->gateway);
+ return 0;
}
- g_slist_free(provider->route_list);
-}
-static void provider_initialize(struct connman_provider *provider)
-{
- DBG("provider %p", provider);
-
- __connman_element_initialize(&provider->element);
+ provider->vpn_service =
+ __connman_service_create_from_provider(provider);
- provider->element.private = provider;
- provider->element.destruct = provider_destruct;
+ if (!provider->vpn_service) {
+ connman_warn("service creation failed for provider %s",
+ provider->identifier);
- provider->element.ipv4.address = NULL;
- provider->element.ipv4.netmask = NULL;
- provider->element.ipv4.gateway = NULL;
- provider->element.ipv4.broadcast = NULL;
- provider->element.ipv4.pac = NULL;
+ g_hash_table_remove(provider_hash, provider->identifier);
+ return -EOPNOTSUPP;
+ }
- provider->name = NULL;
- provider->type = NULL;
- provider->dns = NULL;
- provider->domain = NULL;
- provider->identifier = NULL;
- provider->route_list = NULL;
+ return 0;
}
-static struct connman_provider *connman_provider_new(void)
-{
- struct connman_provider *provider;
+bool __connman_provider_is_immutable(struct connman_provider *provider)
- provider = g_try_new0(struct connman_provider, 1);
- if (provider == NULL)
- return NULL;
-
- DBG("provider %p", provider);
- provider_initialize(provider);
+{
+ if (provider)
+ return provider->immutable;
- return provider;
+ return false;
}
-static struct connman_provider *connman_provider_get(const char *identifier)
+int connman_provider_set_immutable(struct connman_provider *provider,
+ bool immutable)
{
- struct connman_provider *provider;
-
- provider = g_hash_table_lookup(provider_hash, identifier);
- if (provider != NULL)
- return provider;
-
- provider = connman_provider_new();
- if (provider == NULL)
- return NULL;
-
- DBG("provider %p", provider);
-
- provider->identifier = g_strdup(identifier);
-
- g_hash_table_insert(provider_hash, provider->identifier, provider);
+ if (!provider)
+ return -EINVAL;
- provider->element.name = g_strdup(identifier);
- connman_element_register(&provider->element, NULL);
+ provider->immutable = immutable;
- return provider;
+ return 0;
}
-static void provider_dbus_ident(char *ident)
+static struct connman_provider *provider_lookup(const char *identifier)
{
- int i, len = strlen(ident);
-
- for (i = 0; i < len; i++) {
- if (ident[i] >= '0' && ident[i] <= '9')
- continue;
- if (ident[i] >= 'a' && ident[i] <= 'z')
- continue;
- if (ident[i] >= 'A' && ident[i] <= 'Z')
- continue;
- ident[i] = '_';
- }
+ return g_hash_table_lookup(provider_hash, identifier);
}
-int __connman_provider_create_and_connect(DBusMessage *msg)
+static void connection_ready(DBusMessage *msg, int error_code, void *user_data)
{
- struct connman_provider *provider;
- DBusMessageIter iter, array;
- const char *type = NULL, *name = NULL, *service_path = NULL;
- const char *host = NULL, *domain = NULL;
- char *ident;
- gboolean created = FALSE;
- int err;
-
- dbus_message_iter_init(msg, &iter);
- dbus_message_iter_recurse(&iter, &array);
-
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key;
-
- dbus_message_iter_recurse(&array, &entry);
- dbus_message_iter_get_basic(&entry, &key);
-
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
-
- switch (dbus_message_iter_get_arg_type(&value)) {
- case DBUS_TYPE_STRING:
- if (g_str_equal(key, "Type") == TRUE)
- dbus_message_iter_get_basic(&value, &type);
- else if (g_str_equal(key, "Name") == TRUE)
- dbus_message_iter_get_basic(&value, &name);
- else if (g_str_equal(key, "Host") == TRUE)
- dbus_message_iter_get_basic(&value, &host);
- else if (g_str_equal(key, "VPN.Domain") == TRUE)
- dbus_message_iter_get_basic(&value, &domain);
- break;
- }
-
- dbus_message_iter_next(&array);
- }
-
- if (host == NULL || domain == NULL) {
- err = -EINVAL;
- goto failed;
- }
+ DBusMessage *reply;
+ const char *identifier = user_data;
- DBG("Type %s name %s", type, name);
-
- if (type == NULL || name == NULL) {
- err = -EOPNOTSUPP;
- goto failed;
- }
-
- ident = g_strdup_printf("%s_%s", host, domain);
- provider_dbus_ident(ident);
-
- DBG("ident %s", ident);
-
- provider = connman_provider_lookup(ident);
-
- if (provider == NULL) {
- created = TRUE;
- provider = connman_provider_get(ident);
- if (provider) {
- provider->host = g_strdup(host);
- provider->domain = g_strdup(domain);
- provider->name = g_strdup(name);
- provider->type = g_strdup(type);
- }
- }
+ DBG("msg %p error %d", msg, error_code);
- if (provider == NULL) {
- DBG("can not create provider");
- err = -EOPNOTSUPP;
- goto failed;
- }
- dbus_message_iter_init(msg, &iter);
- dbus_message_iter_recurse(&iter, &array);
-
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
- DBusMessageIter entry, value;
- const char *key, *str;
-
- dbus_message_iter_recurse(&array, &entry);
- dbus_message_iter_get_basic(&entry, &key);
-
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
-
- switch (dbus_message_iter_get_arg_type(&value)) {
- case DBUS_TYPE_STRING:
- dbus_message_iter_get_basic(&value, &str);
- connman_provider_set_string(provider, key, str);
- break;
+ if (error_code != 0) {
+ reply = __connman_error_failed(msg, -error_code);
+ if (!g_dbus_send_message(connection, reply))
+ DBG("reply %p send failed", reply);
+ } else {
+ const char *path;
+ struct connman_provider *provider;
+
+ provider = provider_lookup(identifier);
+ if (!provider) {
+ reply = __connman_error_failed(msg, EINVAL);
+ g_dbus_send_message(connection, reply);
+ return;
}
- dbus_message_iter_next(&array);
- }
-
- g_free(ident);
+ path = __connman_service_get_path(provider->vpn_service);
- if (provider == NULL) {
- err = -EOPNOTSUPP;
- goto failed;
+ g_dbus_send_reply(connection, msg,
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID);
}
+}
- if (created == TRUE)
- provider_probe(provider);
-
- if (provider->vpn_service == NULL)
- provider->vpn_service =
- __connman_service_create_from_provider(provider);
- if (provider->vpn_service == NULL) {
- err = -EOPNOTSUPP;
- goto failed;
- }
+int __connman_provider_create_and_connect(DBusMessage *msg)
+{
+ struct connman_provider_driver *driver;
- err = __connman_service_connect(provider->vpn_service);
- if (err < 0 && err != -EINPROGRESS)
- goto failed;
+ if (!driver_list)
+ return -EINVAL;
- service_path = __connman_service_get_path(provider->vpn_service);
- g_dbus_send_reply(connection, msg,
- DBUS_TYPE_OBJECT_PATH, &service_path,
- DBUS_TYPE_INVALID);
- return 0;
+ driver = driver_list->data;
+ if (!driver || !driver->create)
+ return -EINVAL;
-failed:
- if (provider != NULL && created == TRUE) {
- DBG("can not connect delete provider");
- connman_provider_unref(provider);
+ DBG("msg %p", msg);
- if (provider->vpn_service != NULL) {
- __connman_service_put(provider->vpn_service);
- provider->vpn_service = NULL;
- }
- }
-
- return err;
+ return driver->create(msg, connection_ready);
}
-const char * __connman_provider_get_ident(struct connman_provider *provider)
+const char *__connman_provider_get_ident(struct connman_provider *provider)
{
- if (provider == NULL)
+ if (!provider)
return NULL;
return provider->identifier;
int connman_provider_set_string(struct connman_provider *provider,
const char *key, const char *value)
{
- DBG("provider %p key %s value %s", provider, key, value);
-
- if (g_str_equal(key, "Type") == TRUE) {
- g_free(provider->type);
- provider->type = g_strdup(value);
- } else if (g_str_equal(key, "Name") == TRUE) {
- g_free(provider->name);
- provider->name = g_strdup(value);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
- g_free(provider->element.ipv4.gateway);
- provider->element.ipv4.gateway = g_strdup(value);
- } else if (g_str_equal(key, "Address") == TRUE) {
- g_free(provider->element.ipv4.address);
- provider->element.ipv4.address = g_strdup(value);
- } else if (g_str_equal(key, "Peer") == TRUE) {
- g_free(provider->element.ipv4.peer);
- provider->element.ipv4.peer = g_strdup(value);
- } else if (g_str_equal(key, "Netmask") == TRUE) {
- g_free(provider->element.ipv4.netmask);
- provider->element.ipv4.netmask = g_strdup(value);
- } else if (g_str_equal(key, "PAC") == TRUE) {
- g_free(provider->element.ipv4.pac);
- provider->element.ipv4.pac = g_strdup(value);
- __connman_service_set_proxy_autoconfig(provider->vpn_service,
- value);
- } else if (g_str_equal(key, "DNS") == TRUE) {
- g_free(provider->dns);
- provider->dns = g_strdup(value);
- } else if (g_str_equal(key, "Domain") == TRUE) {
- g_free(provider->domain);
- provider->domain = g_strdup(value);
- }
+ if (provider->driver && provider->driver->set_property)
+ return provider->driver->set_property(provider, key, value);
- return connman_element_set_string(&provider->element, key, value);
+ return 0;
}
const char *connman_provider_get_string(struct connman_provider *provider,
const char *key)
{
- DBG("provider %p key %s", provider, key);
+ if (provider->driver && provider->driver->get_property)
+ return provider->driver->get_property(provider, key);
+
+ return NULL;
+}
+
+bool
+__connman_provider_check_routes(struct connman_provider *provider)
+{
+ if (!provider)
+ return false;
- if (g_str_equal(key, "Type") == TRUE)
- return provider->type;
- else if (g_str_equal(key, "Name") == TRUE)
- return provider->name;
+ if (provider->driver && provider->driver->check_routes)
+ return provider->driver->check_routes(provider);
- return connman_element_get_string(&provider->element, key);
+ return false;
}
void *connman_provider_get_data(struct connman_provider *provider)
DBG("");
- if (service == NULL)
+ if (!service)
return;
ipconfig = __connman_service_get_ip4config(service);
- if (ipconfig == NULL) {
- __connman_service_create_ip4config(service, index);
+ if (!ipconfig) {
+ connman_service_create_ip4config(service, index);
ipconfig = __connman_service_get_ip4config(service);
- if (ipconfig == NULL) {
+ if (!ipconfig) {
DBG("Couldnt create ipconfig");
goto done;
}
}
- connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_FIXED);
+ __connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_OFF);
__connman_ipconfig_set_index(ipconfig, index);
-
ipconfig = __connman_service_get_ip6config(service);
- if (ipconfig == NULL) {
- __connman_service_create_ip6config(service, index);
+ if (!ipconfig) {
+ connman_service_create_ip6config(service, index);
ipconfig = __connman_service_get_ip6config(service);
- if (ipconfig == NULL) {
+ if (!ipconfig) {
DBG("Couldnt create ipconfig for IPv6");
goto done;
}
}
- connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_OFF);
+ __connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_OFF);
__connman_ipconfig_set_index(ipconfig, index);
done:
- provider->element.index = index;
+ provider->index = index;
}
int connman_provider_get_index(struct connman_provider *provider)
{
- return provider->element.index;
+ return provider->index;
}
-int connman_provider_append_route(struct connman_provider *provider,
- const char *host, const char *netmask,
- const char *gateway)
+int connman_provider_set_ipaddress(struct connman_provider *provider,
+ struct connman_ipaddress *ipaddress)
{
- struct connman_route *route;
+ struct connman_ipconfig *ipconfig = NULL;
+
+ ipconfig = __connman_service_get_ipconfig(provider->vpn_service,
+ ipaddress->family);
+ if (!ipconfig)
+ return -EINVAL;
- route = g_try_new0(struct connman_route, 1);
- if (route == NULL)
- return -ENOMEM;
+ provider->family = ipaddress->family;
- route->host = g_strdup(host);
- route->netmask = g_strdup(netmask);
- route->gateway = g_strdup(gateway);
+ __connman_ipconfig_set_method(ipconfig, CONNMAN_IPCONFIG_METHOD_FIXED);
- provider->route_list = g_slist_append(provider->route_list, route);
+ __connman_ipconfig_set_local(ipconfig, ipaddress->local);
+ __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
+ __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
+ __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
+ __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
- return TRUE;
+ return 0;
}
-const char *connman_provider_get_driver_name(struct connman_provider *provider)
+int connman_provider_set_pac(struct connman_provider *provider, const char *pac)
{
- return provider->driver->name;
+ DBG("provider %p pac %s", provider, pac);
+
+ __connman_service_set_pac(provider->vpn_service, pac);
+
+ return 0;
}
-static gint compare_priority(gconstpointer a, gconstpointer b)
+
+int connman_provider_set_domain(struct connman_provider *provider,
+ const char *domain)
{
+ DBG("provider %p domain %s", provider, domain);
+
+ __connman_service_set_domainname(provider->vpn_service, domain);
+
return 0;
}
-static void clean_provider(gpointer key, gpointer value, gpointer user_data)
+int connman_provider_set_nameservers(struct connman_provider *provider,
+ char * const *nameservers)
{
- struct connman_provider *provider = value;
+ int i;
- if (provider->driver != NULL && provider->driver->remove)
- provider->driver->remove(provider);
+ DBG("provider %p nameservers %p", provider, nameservers);
+
+ __connman_service_nameserver_clear(provider->vpn_service);
+
+ if (!nameservers)
+ return 0;
+
+ for (i = 0; nameservers[i]; i++)
+#if defined TIZEN_EXT
+ __connman_service_nameserver_append(provider->vpn_service,
+ nameservers[i], false,
+ CONNMAN_IPCONFIG_TYPE_ALL);
+#else
+ __connman_service_nameserver_append(provider->vpn_service,
+ nameservers[i], false);
+#endif
+
+ return 0;
+}
+
+static void unregister_provider(gpointer data)
+{
+ struct connman_provider *provider = data;
+
+ DBG("provider %p service %p", provider, provider->vpn_service);
+
+ if (provider->vpn_service) {
+ connman_service_unref(provider->vpn_service);
+ provider->vpn_service = NULL;
+ }
+
+ connman_provider_unref(provider);
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+ return 0;
}
int connman_provider_driver_register(struct connman_provider_driver *driver)
driver_list = g_slist_remove(driver_list, driver);
}
-static void provider_remove(gpointer key, gpointer value,
+void connman_provider_set_driver(struct connman_provider *provider,
+ struct connman_provider_driver *driver)
+{
+ provider->driver = driver;
+}
+
+static void provider_disconnect_all(gpointer key, gpointer value,
gpointer user_data)
{
struct connman_provider *provider = value;
- g_hash_table_remove(provider_hash, provider->identifier);
+ connman_provider_disconnect(provider);
}
-static void provider_offline_mode(connman_bool_t enabled)
+static void provider_offline_mode(bool enabled)
{
DBG("enabled %d", enabled);
- if (enabled == TRUE)
- g_hash_table_foreach(provider_hash, provider_remove, NULL);
+ if (enabled)
+ g_hash_table_foreach(provider_hash, provider_disconnect_all,
+ NULL);
}
+static void provider_initialize(struct connman_provider *provider)
+{
+ DBG("provider %p", provider);
+
+ provider->index = 0;
+ provider->identifier = NULL;
+}
+
+static struct connman_provider *provider_new(void)
+{
+ struct connman_provider *provider;
+
+ provider = g_try_new0(struct connman_provider, 1);
+ if (!provider)
+ return NULL;
+
+ provider->refcount = 1;
+
+ DBG("provider %p", provider);
+ provider_initialize(provider);
+
+ return provider;
+}
+
+struct connman_provider *connman_provider_get(const char *identifier)
+{
+ struct connman_provider *provider;
+
+ provider = g_hash_table_lookup(provider_hash, identifier);
+ if (provider)
+ return provider;
+
+ provider = provider_new();
+ if (!provider)
+ return NULL;
+
+ DBG("provider %p", provider);
+
+ provider->identifier = g_strdup(identifier);
+
+ g_hash_table_insert(provider_hash, provider->identifier, provider);
+
+ return provider;
+}
+
+void connman_provider_put(struct connman_provider *provider)
+{
+ g_hash_table_remove(provider_hash, provider->identifier);
+}
+
+static struct connman_provider *provider_get(int index)
+{
+ GHashTableIter iter;
+ gpointer value, key;
+
+ g_hash_table_iter_init(&iter, provider_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ struct connman_provider *provider = value;
+
+ if (provider->index == index)
+ return provider;
+ }
+
+ return NULL;
+}
+
+static void provider_service_changed(struct connman_service *service,
+ enum connman_service_state state)
+{
+ struct connman_provider *provider;
+ int vpn_index, service_index;
+
+ if (!service)
+ return;
+
+ 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_READY:
+ case CONNMAN_SERVICE_STATE_ONLINE:
+ return;
+ case CONNMAN_SERVICE_STATE_DISCONNECT:
+ case CONNMAN_SERVICE_STATE_FAILURE:
+ break;
+ }
+
+ service_index = __connman_service_get_index(service);
+
+ vpn_index = __connman_connection_get_vpn_index(service_index);
+
+ DBG("service %p %s state %d index %d/%d", service,
+ __connman_service_get_ident(service),
+ state, service_index, vpn_index);
+
+ if (vpn_index < 0)
+ return;
+
+ provider = provider_get(vpn_index);
+ if (!provider)
+ return;
+
+ DBG("disconnect %p index %d", provider, vpn_index);
+
+ connman_provider_disconnect(provider);
+
+ return;
+}
+
static struct connman_notifier provider_notifier = {
.name = "provider",
.offline_mode = provider_offline_mode,
+ .service_state_changed = provider_service_changed,
};
int __connman_provider_init(void)
connman_notifier_unregister(&provider_notifier);
- g_hash_table_foreach(provider_hash, clean_provider, NULL);
-
g_hash_table_destroy(provider_hash);
provider_hash = NULL;