*
* Connection Manager
*
- * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2010 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
append_path, &filter);
}
-struct count_data {
- enum connman_element_type type;
- int count;
-};
-
-static gboolean count_element(GNode *node, gpointer user_data)
-{
- struct connman_element *element = node->data;
- struct count_data *data = user_data;
-
- DBG("element %p name %s", element, element->name);
-
- if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
- return FALSE;
-
- if (data->type != CONNMAN_ELEMENT_TYPE_UNKNOWN &&
- data->type != element->type)
- return FALSE;
-
- data->count++;
-
- return FALSE;
-}
-
-int __connman_element_count(struct connman_element *element,
- enum connman_element_type type)
-{
- struct count_data data = { type, 0 };
- GNode *node;
-
- DBG("");
-
- if (element != NULL) {
- node = g_node_find(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, element);
- if (node == NULL)
- return 0;
- } else
- node = element_root;
-
- g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
- count_element, &data);
-
- return data.count;
-}
-
static struct connman_network *__connman_element_get_network(struct connman_element *element)
{
if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
case CONNMAN_SERVICE_TYPE_ETHERNET:
case CONNMAN_SERVICE_TYPE_BLUETOOTH:
case CONNMAN_SERVICE_TYPE_CELLULAR:
+ case CONNMAN_SERVICE_TYPE_GPS:
case CONNMAN_SERVICE_TYPE_VPN:
return FALSE;
case CONNMAN_SERVICE_TYPE_WIFI:
switch (type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
case CONNMAN_SERVICE_TYPE_SYSTEM:
+ case CONNMAN_SERVICE_TYPE_GPS:
case CONNMAN_SERVICE_TYPE_VPN:
return FALSE;
case CONNMAN_SERVICE_TYPE_ETHERNET:
switch (type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
case CONNMAN_SERVICE_TYPE_SYSTEM:
+ case CONNMAN_SERVICE_TYPE_GPS:
case CONNMAN_SERVICE_TYPE_VPN:
return FALSE;
case CONNMAN_SERVICE_TYPE_ETHERNET:
if (driver->probe(element) < 0)
return FALSE;
- __connman_element_lock(element);
element->driver = driver;
- __connman_element_unlock(element);
}
return FALSE;
if (driver->remove)
driver->remove(element);
- __connman_element_lock(element);
element->driver = NULL;
- __connman_element_unlock(element);
}
return FALSE;
g_free(property);
}
+static void unregister_child(gpointer data)
+{
+ struct connman_element *element = data;
+
+ DBG("element %p", element);
+
+ connman_element_unref(element);
+}
+
void __connman_element_initialize(struct connman_element *element)
{
DBG("element %p", element);
element->index = -1;
element->enabled = FALSE;
- element->configuring = FALSE;
+ element->children = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, unregister_child);
element->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, unregister_property);
{
DBG("element %p name %s", element, element->name);
- __connman_element_lock(element);
-
g_hash_table_destroy(element->properties);
element->properties = NULL;
+}
+
+static void free_children(struct connman_element *element)
+{
+ DBG("element %p name %s", element, element->name);
- __connman_element_unlock(element);
+ g_hash_table_destroy(element->children);
+ element->children = NULL;
}
void connman_element_unref(struct connman_element *element)
if (g_atomic_int_dec_and_test(&element->refcount) == TRUE) {
if (element->destruct)
element->destruct(element);
+ free_children(element);
free_properties(element);
g_free(element->ipv4.address);
g_free(element->ipv4.netmask);
g_free(element->ipv4.broadcast);
g_free(element->ipv4.nameserver);
g_free(element->ipv4.timeserver);
+ g_free(element->ipv4.pac);
g_free(element->devname);
g_free(element->path);
g_free(element->name);
break;
}
- __connman_element_lock(element);
-
g_hash_table_replace(element->properties, g_strdup(name), property);
- __connman_element_unlock(element);
-
return 0;
}
break;
}
- __connman_element_lock(element);
-
g_hash_table_replace(element->properties, g_strdup(name), property);
- __connman_element_unlock(element);
-
return 0;
}
-#if 0
-static int set_property(struct connman_element *element,
- enum connman_property_id id, const void *value)
-{
- switch (id) {
- case CONNMAN_PROPERTY_ID_IPV4_ADDRESS:
- __connman_element_lock(element);
- g_free(element->ipv4.address);
- element->ipv4.address = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
- break;
- case CONNMAN_PROPERTY_ID_IPV4_NETMASK:
- __connman_element_lock(element);
- g_free(element->ipv4.netmask);
- element->ipv4.netmask = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
- break;
- case CONNMAN_PROPERTY_ID_IPV4_GATEWAY:
- __connman_element_lock(element);
- g_free(element->ipv4.gateway);
- element->ipv4.gateway = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
- break;
- case CONNMAN_PROPERTY_ID_IPV4_BROADCAST:
- __connman_element_lock(element);
- g_free(element->ipv4.broadcast);
- element->ipv4.broadcast = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
- break;
- case CONNMAN_PROPERTY_ID_IPV4_NAMESERVER:
- __connman_element_lock(element);
- g_free(element->ipv4.nameserver);
- element->ipv4.nameserver = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
- break;
- default:
- return -EINVAL;
- }
-
- return 0;
-}
-#endif
-
int connman_element_get_value(struct connman_element *element,
enum connman_property_id id, void *value)
{
if (element->ipv4.method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((const char **) value) = __connman_ipconfig_method2string(element->ipv4.method);
- __connman_element_unlock(element);
break;
case CONNMAN_PROPERTY_ID_IPV4_ADDRESS:
if (element->ipv4.address == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((char **) value) = element->ipv4.address;
- __connman_element_unlock(element);
break;
case CONNMAN_PROPERTY_ID_IPV4_NETMASK:
if (element->ipv4.netmask == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((char **) value) = element->ipv4.netmask;
- __connman_element_unlock(element);
break;
case CONNMAN_PROPERTY_ID_IPV4_GATEWAY:
if (element->ipv4.gateway == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((char **) value) = element->ipv4.gateway;
- __connman_element_unlock(element);
break;
case CONNMAN_PROPERTY_ID_IPV4_BROADCAST:
if (element->ipv4.broadcast == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((char **) value) = element->ipv4.broadcast;
- __connman_element_unlock(element);
break;
case CONNMAN_PROPERTY_ID_IPV4_NAMESERVER:
if (element->ipv4.nameserver == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((char **) value) = element->ipv4.nameserver;
- __connman_element_unlock(element);
break;
case CONNMAN_PROPERTY_ID_IPV4_TIMESERVER:
if (element->ipv4.timeserver == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
*((char **) value) = element->ipv4.timeserver;
- __connman_element_unlock(element);
+ break;
+ case CONNMAN_PROPERTY_ID_IPV4_PAC:
+ if (element->ipv4.pac == NULL)
+ return connman_element_get_value(element->parent,
+ id, value);
+ *((char **) value) = element->ipv4.pac;
break;
default:
return -EINVAL;
DBG("element %p name %s", element, element->name);
- __connman_element_lock(element);
-
property = g_hash_table_lookup(element->properties, name);
if (property != NULL) {
switch (property->type) {
}
}
- __connman_element_unlock(element);
-
if (found == FALSE && element->parent != NULL)
return get_static_property(element->parent, name, value);
DBG("element %p name %s", element, element->name);
- __connman_element_lock(element);
-
property = g_hash_table_lookup(element->properties, name);
if (property != NULL) {
*((void **) value) = property->value;
found = TRUE;
}
- __connman_element_unlock(element);
-
return found;
}
-#if 0
-static gboolean match_static_property(struct connman_element *element,
- const char *name, const void *value)
-{
- struct connman_property *property;
- gboolean result = FALSE;
-
- DBG("element %p name %s", element, element->name);
-
- __connman_element_lock(element);
-
- property = g_hash_table_lookup(element->properties, name);
- if (property != NULL) {
- if (property->type == DBUS_TYPE_STRING)
- result = g_str_equal(property->value,
- *((const char **) value));
- }
-
- __connman_element_unlock(element);
-
- return result;
-}
-#endif
-
/**
* connman_element_set_string:
* @element: element structure
return value;
}
-int __connman_element_append_ipv4(struct connman_element *element,
- DBusMessageIter *dict)
-{
- const char *method = NULL;
- const char *address = NULL, *netmask = NULL, *gateway = NULL;
- const char *broadcast = NULL, *nameserver = NULL;
- const char *timeserver = NULL;
-
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_METHOD, &method);
-
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_ADDRESS, &address);
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_NETMASK, &netmask);
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_BROADCAST, &broadcast);
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
- connman_element_get_value(element,
- CONNMAN_PROPERTY_ID_IPV4_TIMESERVER, ×erver);
-
- if (method != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Method",
- DBUS_TYPE_STRING, &method);
-
- if (address != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Address",
- DBUS_TYPE_STRING, &address);
-
- if (netmask != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Netmask",
- DBUS_TYPE_STRING, &netmask);
-
- if (gateway != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Gateway",
- DBUS_TYPE_STRING, &gateway);
-
- if (broadcast != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Broadcast",
- DBUS_TYPE_STRING, &broadcast);
-
- if (nameserver != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Nameserver",
- DBUS_TYPE_STRING, &nameserver);
-
- if (timeserver != NULL)
- connman_dbus_dict_append_variant(dict, "IPv4.Timeserver",
- DBUS_TYPE_STRING, ×erver);
-
- return 0;
-}
-
-int __connman_element_set_ipv4(struct connman_element *element,
- const char *name, DBusMessageIter *value)
-{
- int type;
-
- type = dbus_message_iter_get_arg_type(value);
-
- if (g_str_equal(name, "IPv4.Method") == TRUE) {
- enum connman_ipconfig_method method;
- const char *str;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &str);
- method = __connman_ipconfig_string2method(str);
- if (method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
- return -EINVAL;
-
- if (method == element->ipv4.method)
- return -EALREADY;
-
- element->ipv4.method = method;
-
- connman_element_update(element);
- } else if (g_str_equal(name, "IPv4.Address") == TRUE) {
- const char *address;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &address);
-
- g_free(element->ipv4.address);
- element->ipv4.address = g_strdup(address);
-
- connman_element_update(element);
- } else if (g_str_equal(name, "IPv4.Netmask") == TRUE) {
- const char *netmask;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &netmask);
-
- g_free(element->ipv4.netmask);
- element->ipv4.netmask = g_strdup(netmask);
-
- connman_element_update(element);
- } else if (g_str_equal(name, "IPv4.Gateway") == TRUE) {
- const char *gateway;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &gateway);
-
- g_free(element->ipv4.gateway);
- element->ipv4.gateway = g_strdup(gateway);
-
- connman_element_update(element);
- } else if (g_str_equal(name, "IPv4.Broadcast") == TRUE) {
- const char *broadcast;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &broadcast);
-
- g_free(element->ipv4.broadcast);
- element->ipv4.broadcast = g_strdup(broadcast);
-
- connman_element_update(element);
- } else if (g_str_equal(name, "IPv4.Nameserver") == TRUE) {
- const char *nameserver;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &nameserver);
-
- g_free(element->ipv4.nameserver);
- element->ipv4.nameserver = g_strdup(nameserver);
-
- connman_element_update(element);
- } else if (g_str_equal(name, "IPv4.Timeserver") == TRUE) {
- const char *timeserver;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, ×erver);
-
- g_free(element->ipv4.timeserver);
- element->ipv4.nameserver = g_strdup(timeserver);
-
- connman_element_update(element);
- }
-
- return 0;
-}
-
-static void emit_state_change(DBusConnection *conn, const char *state)
-{
- DBusMessage *signal;
- DBusMessageIter iter;
-
- connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "State",
- DBUS_TYPE_STRING, &state);
-
- signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "StateChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &state);
-
- g_dbus_send_message(conn, signal);
-}
-
static void probe_element(struct connman_element *element)
{
GSList *list;
DBG("driver %p name %s", driver, driver->name);
if (driver->probe(element) == 0) {
- __connman_element_lock(element);
element->driver = driver;
- __connman_element_unlock(element);
break;
}
}
const gchar *basepath;
GNode *node;
- __connman_element_lock(element);
-
if (element->parent) {
node = g_node_find(element_root, G_PRE_ORDER,
G_TRAVERSE_ALL, element->parent);
element->path = g_strdup_printf("%s/%s", basepath, element->name);
- __connman_element_unlock(element);
-
if (node == NULL) {
connman_error("Element registration for %s failed",
element->path);
g_node_append_data(node, element);
- if (element->type == CONNMAN_ELEMENT_TYPE_DHCP) {
- element->parent->configuring = TRUE;
-
-#if 0
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
- emit_state_change(connection, "connecting");
-#endif
- }
-
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- struct connman_element *parent = element->parent;
-
- while (parent) {
- parent->configuring = FALSE;
- parent = parent->parent;
- }
-
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 1)
- emit_state_change(connection, "online");
- }
-
if (started == FALSE)
return;
if (element->devname == NULL)
element->devname = g_strdup(element->name);
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
goto setup;
if (__connman_element_device_isfiltered(element->devname) == TRUE)
if (connman_element_ref(element) == NULL)
return -EINVAL;
- __connman_element_lock(element);
-
if (element->name == NULL) {
element->name = g_strdup(type2string(element->type));
if (element->name == NULL) {
- __connman_element_unlock(element);
return -EINVAL;
}
}
element->parent = parent;
- __connman_element_unlock(element);
-
register_element(element, NULL);
return 0;
if (element->driver->remove)
element->driver->remove(element);
- __connman_element_lock(element);
element->driver = NULL;
- __connman_element_unlock(element);
}
if (node != NULL)
g_node_destroy(node);
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
- emit_state_change(connection, "offline");
- }
-
connman_element_unref(element);
return FALSE;
element_root = g_node_new(element);
+ __connman_technology_init();
__connman_notifier_init();
__connman_service_init();
__connman_provider_init();
if (element->driver->remove)
element->driver->remove(element);
- __connman_element_lock(element);
element->driver = NULL;
- __connman_element_unlock(element);
}
return FALSE;
__connman_network_cleanup();
__connman_service_cleanup();
__connman_notifier_cleanup();
+ __connman_technology_cleanup();
g_node_traverse(element_root, G_POST_ORDER, G_TRAVERSE_ALL, -1,
free_driver, NULL);