*
* 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
static GNode *element_root = NULL;
static GSList *driver_list = NULL;
static gchar *device_filter = NULL;
+static gchar *nodevice_filter = NULL;
static gboolean started = FALSE;
return "network";
case CONNMAN_ELEMENT_TYPE_SERVICE:
return "service";
- case CONNMAN_ELEMENT_TYPE_PPP:
- return "ppp";
case CONNMAN_ELEMENT_TYPE_IPV4:
return "ipv4";
case CONNMAN_ELEMENT_TYPE_IPV6:
return NULL;
}
-const char *__connman_ipv4_method2string(enum connman_ipv4_method method)
-{
- switch (method) {
- case CONNMAN_IPV4_METHOD_UNKNOWN:
- return "unknown";
- case CONNMAN_IPV4_METHOD_OFF:
- return "off";
- case CONNMAN_IPV4_METHOD_STATIC:
- return "static";
- case CONNMAN_IPV4_METHOD_DHCP:
- return "dhcp";
- }
-
- return "unknown";
-}
-
-enum connman_ipv4_method __connman_ipv4_string2method(const char *method)
-{
- if (strcasecmp(method, "off") == 0)
- return CONNMAN_IPV4_METHOD_OFF;
- else if (strcasecmp(method, "static") == 0)
- return CONNMAN_IPV4_METHOD_STATIC;
- else if (strcasecmp(method, "dhcp") == 0)
- return CONNMAN_IPV4_METHOD_DHCP;
- else
- return CONNMAN_IPV4_METHOD_UNKNOWN;
-}
-
-static void emit_element_signal(DBusConnection *conn, const char *member,
- struct connman_element *element)
-{
- DBusMessage *signal;
-
- if (__connman_debug_enabled() == FALSE)
- return;
-
- DBG("conn %p member %s", conn, member);
-
- if (element == NULL)
- return;
-
- signal = dbus_message_new_signal(element->path,
- CONNMAN_DEBUG_INTERFACE, member);
- if (signal == NULL)
- return;
-
- g_dbus_send_message(conn, signal);
-}
-
struct foreach_data {
enum connman_element_type type;
element_cb_t callback;
append_path, &filter);
}
-struct count_data {
- enum connman_element_type type;
- int count;
-};
-
-static gboolean count_element(GNode *node, gpointer user_data)
+static struct connman_network *__connman_element_get_network(struct connman_element *element)
{
- 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;
+ if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
+ element->network != NULL)
+ return element->network;
- data->count++;
+ if (element->parent == NULL)
+ return NULL;
- return FALSE;
+ return __connman_element_get_network(element->parent);
}
-int __connman_element_count(struct connman_element *element,
- enum connman_element_type type)
+struct connman_service *__connman_element_get_service(struct connman_element *element)
{
- struct count_data data = { type, 0 };
- GNode *node;
+ struct connman_service *service = NULL;
+ struct connman_network *network;
+ struct connman_device *device;
+ enum connman_device_type type;
- DBG("");
+ device = __connman_element_get_device(element);
+ if (device == NULL)
+ return NULL;
- 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;
+ type = connman_device_get_type(device);
- g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
- count_element, &data);
+ switch (type) {
+ case CONNMAN_DEVICE_TYPE_UNKNOWN:
+ case CONNMAN_DEVICE_TYPE_VENDOR:
+ case CONNMAN_DEVICE_TYPE_GPS:
+ break;
+ case CONNMAN_DEVICE_TYPE_ETHERNET:
+ case CONNMAN_DEVICE_TYPE_WIFI:
+ case CONNMAN_DEVICE_TYPE_WIMAX:
+ case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+ case CONNMAN_DEVICE_TYPE_CELLULAR:
+ case CONNMAN_DEVICE_TYPE_MBM:
+ case CONNMAN_DEVICE_TYPE_HSO:
+ network = __connman_element_get_network(element);
+ if (network == NULL)
+ return NULL;
+ service = __connman_service_lookup_from_network(network);
+ break;
+ }
- return data.count;
+ return service;
}
-const char *__connman_element_get_device(struct connman_element *element)
+struct connman_device *__connman_element_get_device(struct connman_element *element)
{
if (element->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
element->device != NULL)
- return element->path;
+ return element->device;
if (element->parent == NULL)
return NULL;
return __connman_element_get_device(element->parent);
}
-const char *__connman_element_get_network(struct connman_element *element)
+const char *__connman_element_get_device_path(struct connman_element *element)
+{
+ struct connman_device *device;
+
+ device = __connman_element_get_device(element);
+ if (device == NULL)
+ return NULL;
+
+ return connman_device_get_path(device);
+}
+
+const char *__connman_element_get_network_path(struct connman_element *element)
{
if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
element->network != NULL)
if (element->parent == NULL)
return NULL;
- return __connman_element_get_network(element->parent);
+ return __connman_element_get_network_path(element->parent);
+}
+
+struct find_data {
+ enum connman_service_type type;
+ struct connman_device *device;
+};
+
+static gboolean find_device(GNode *node, gpointer user_data)
+{
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
+
+ if (element->device == NULL)
+ return FALSE;
+
+ if (data->type != connman_device_get_type(element->device))
+ return FALSE;
+
+ data->device = element->device;
+
+ return TRUE;
+}
+
+struct connman_device *__connman_element_find_device(enum connman_service_type type)
+{
+ struct find_data data = { .type = type, .device = NULL };
+
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, find_device, &data);
+
+ return data.device;
+}
+
+static gboolean request_scan(GNode *node, gpointer user_data)
+{
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+ enum connman_service_type type;
+
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
+
+ if (element->device == NULL)
+ return FALSE;
+
+ type = __connman_device_get_service_type(element->device);
+
+ switch (type) {
+ case CONNMAN_SERVICE_TYPE_UNKNOWN:
+ case CONNMAN_SERVICE_TYPE_SYSTEM:
+ 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:
+ case CONNMAN_SERVICE_TYPE_WIMAX:
+ if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
+ data->type != type)
+ return FALSE;
+ break;
+ }
+
+ __connman_device_scan(element->device);
+
+ return FALSE;
+}
+
+int __connman_element_request_scan(enum connman_service_type type)
+{
+ struct find_data data = { .type = type, .device = NULL };
+
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, request_scan, &data);
+
+ return 0;
+}
+
+static gboolean enable_technology(GNode *node, gpointer user_data)
+{
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+ enum connman_service_type type;
+
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
+
+ if (element->device == NULL)
+ return FALSE;
+
+ type = __connman_device_get_service_type(element->device);
+
+ 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:
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ case CONNMAN_SERVICE_TYPE_WIMAX:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
+ data->type != type)
+ return FALSE;
+ break;
+ }
+
+ __connman_device_enable_persistent(element->device);
+
+ return FALSE;
+}
+
+int __connman_element_enable_technology(enum connman_service_type type)
+{
+ struct find_data data = { .type = type, .device = NULL };
+
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, enable_technology, &data);
+
+ return 0;
+}
+
+static gboolean disable_technology(GNode *node, gpointer user_data)
+{
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+ enum connman_service_type type;
+
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
+
+ if (element->device == NULL)
+ return FALSE;
+
+ type = __connman_device_get_service_type(element->device);
+
+ 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:
+ case CONNMAN_SERVICE_TYPE_WIFI:
+ case CONNMAN_SERVICE_TYPE_WIMAX:
+ case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+ case CONNMAN_SERVICE_TYPE_CELLULAR:
+ if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
+ data->type != type)
+ return FALSE;
+ break;
+ }
+
+ __connman_device_disable_persistent(element->device);
+
+ return FALSE;
+}
+
+int __connman_element_disable_technology(enum connman_service_type type)
+{
+ struct find_data data = { .type = type, .device = NULL };
+
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, disable_technology, &data);
+
+ return 0;
}
static gint compare_priority(gconstpointer a, gconstpointer b)
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->name = NULL;
element->type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
+ element->state = CONNMAN_ELEMENT_STATE_UNKNOWN;
+ element->error = CONNMAN_ELEMENT_ERROR_UNKNOWN;
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.network);
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);
case DBUS_TYPE_STRING:
property->value = g_strdup(*((const char **) value));
break;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_BYTE:
property->value = g_try_malloc(1);
if (property->value != NULL)
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)
switch (id) {
case CONNMAN_PROPERTY_ID_IPV4_METHOD:
- if (element->ipv4.method == CONNMAN_IPV4_METHOD_UNKNOWN)
+ 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_ipv4_method2string(element->ipv4.method);
- __connman_element_unlock(element);
+ *((const char **) value) = __connman_ipconfig_method2string(element->ipv4.method);
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);
+ *((char **) value) = element->ipv4.timeserver;
+ 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) {
*((char **) value) = property->value;
found = TRUE;
break;
+ case DBUS_TYPE_BOOLEAN:
case DBUS_TYPE_BYTE:
memcpy(value, property->value, 1);
found = TRUE;
}
}
- __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) {
- *((char **) value) = property->value;
+ *((void **) value) = property->value;
*len = property->size;
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
}
/**
+ * connman_element_set_bool:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: boolean value
+ *
+ * Set boolean value for specific key
+ */
+int connman_element_set_bool(struct connman_element *element,
+ const char *key, connman_bool_t value)
+{
+ return set_static_property(element, key, DBUS_TYPE_BOOLEAN, &value);
+}
+
+/**
+ * connman_element_get_bool:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get boolean value for specific key
+ */
+connman_bool_t connman_element_get_bool(struct connman_element *element,
+ const char *key)
+{
+ connman_bool_t value;
+
+ if (get_static_property(element, key, &value) == FALSE)
+ return FALSE;
+
+ return value;
+}
+
+/**
* connman_element_set_uint8:
* @element: element structure
* @key: unique identifier
int connman_element_set_uint8(struct connman_element *element,
const char *key, connman_uint8_t value)
{
- return set_static_property(element, key, DBUS_TYPE_BYTE, &value);
+ return set_static_property(element, key, DBUS_TYPE_BYTE, &value);
}
/**
connman_uint8_t value;
if (get_static_property(element, key, &value) == FALSE)
- return 0;
+ return 0;
return value;
}
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;
-
- 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);
-
- 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);
-
- 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_ipv4_method method;
- const char *str;
-
- if (type != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(value, &str);
- method = __connman_ipv4_string2method(str);
- if (method == CONNMAN_IPV4_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);
- }
-
- return 0;
-}
-
-static void append_state(DBusMessageIter *entry, const char *state)
-{
- DBusMessageIter value;
- const char *key = "State";
-
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
-
- dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_STRING_AS_STRING, &value);
- dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &state);
- dbus_message_iter_close_container(entry, &value);
-}
-
-static void emit_state_change(DBusConnection *conn, const char *state)
-{
- DBusMessage *signal;
- DBusMessageIter entry;
-
- DBG("conn %p", conn);
-
- signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &entry);
-
- append_state(&entry, 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->parent = element_root->data;
node = element_root;
- basepath = "";
+ basepath = "/device";
}
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);
+ return;
+ }
DBG("element %p path %s", element, element->path);
g_node_append_data(node, element);
- if (element->type == CONNMAN_ELEMENT_TYPE_DHCP) {
- element->parent->configuring = TRUE;
-
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
- emit_state_change(connection, "connecting");
- }
+ if (started == FALSE)
+ return;
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- struct connman_element *parent = element->parent;
+ probe_element(element);
+}
- while (parent) {
- parent->configuring = FALSE;
- parent = parent->parent;
- }
+gboolean __connman_element_device_isfiltered(const char *devname)
+{
+ if (device_filter == NULL)
+ goto nodevice;
- if (__connman_element_count(NULL,
- CONNMAN_ELEMENT_TYPE_CONNECTION) == 1)
- emit_state_change(connection, "online");
+ if (g_pattern_match_simple(device_filter, devname) == FALSE) {
+ DBG("ignoring device %s (match)", devname);
+ return TRUE;
}
- emit_element_signal(connection, "ElementAdded", element);
+nodevice:
+ if (nodevice_filter == NULL)
+ return FALSE;
- if (started == FALSE)
- return;
+ if (g_pattern_match_simple(nodevice_filter, devname) == TRUE) {
+ DBG("ignoring device %s (no match)", devname);
+ return TRUE;
+ }
- probe_element(element);
+ return FALSE;
}
/**
if (element->devname == NULL)
element->devname = g_strdup(element->name);
- if (device_filter && element->type == CONNMAN_ELEMENT_TYPE_DEVICE) {
- if (g_pattern_match_simple(device_filter,
- element->devname) == FALSE) {
- DBG("ignoring %s [%s] device", element->name,
- element->devname);
- return -EPERM;
- }
- }
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ goto setup;
+
+ if (__connman_element_device_isfiltered(element->devname) == TRUE)
+ return -EPERM;
+setup:
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;
}
}
if (element->type == CONNMAN_ELEMENT_TYPE_DHCP)
- element->ipv4.method = CONNMAN_IPV4_METHOD_DHCP;
+ element->ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
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");
- }
-
- emit_element_signal(connection, "ElementRemoved", element);
-
connman_element_unref(element);
return FALSE;
if (element->driver && element->driver->update)
element->driver->update(element);
- emit_element_signal(connection, "ElementUpdated", element);
-
return FALSE;
}
return 0;
}
-int __connman_element_init(DBusConnection *conn, const char *device,
- const char *nodevice)
+static enum connman_service_error convert_error(enum connman_element_error error)
+{
+ switch (error) {
+ case CONNMAN_ELEMENT_ERROR_UNKNOWN:
+ case CONNMAN_ELEMENT_ERROR_FAILED:
+ break;
+ case CONNMAN_ELEMENT_ERROR_DHCP_FAILED:
+ return CONNMAN_SERVICE_ERROR_DHCP_FAILED;
+ case CONNMAN_ELEMENT_ERROR_CONNECT_FAILED:
+ return CONNMAN_SERVICE_ERROR_CONNECT_FAILED;
+ }
+
+ return CONNMAN_SERVICE_ERROR_UNKNOWN;
+}
+
+/**
+ * connman_element_set_error:
+ * @element: element structure
+ * @error: error identifier
+ *
+ * Set error state and specific error identifier
+ */
+void connman_element_set_error(struct connman_element *element,
+ enum connman_element_error error)
+{
+ struct connman_service *service;
+
+ DBG("element %p error %d", element, error);
+
+ if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
+ return;
+
+ element->state = CONNMAN_ELEMENT_STATE_ERROR;
+ element->error = error;
+
+ if (element->driver && element->driver->change)
+ element->driver->change(element);
+
+ service = __connman_element_get_service(element);
+ __connman_service_indicate_error(service, convert_error(error));
+}
+
+int __connman_element_init(const char *device, const char *nodevice)
{
struct connman_element *element;
- DBG("conn %p", conn);
+ DBG("");
- connection = dbus_connection_ref(conn);
+ connection = connman_dbus_get_connection();
if (connection == NULL)
return -EIO;
device_filter = g_strdup(device);
+ nodevice_filter = g_strdup(nodevice);
element = connman_element_create("root");
element_root = g_node_new(element);
+ __connman_technology_init();
__connman_notifier_init();
+ __connman_service_init();
+ __connman_provider_init();
__connman_network_init();
__connman_device_init();
{
DBG("");
+ __connman_storage_init_profile();
+
g_node_traverse(element_root, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
probe_node, NULL);
started = TRUE;
- __connman_storage_init_device();
+ __connman_rtnl_start();
+ __connman_udev_start();
__connman_connection_init();
__connman_ipv4_init();
- __connman_detect_init();
+ __connman_dhcp_init();
+
+ if (__connman_rfkill_init() < 0)
+ __connman_udev_enable_rfkill_processing();
}
void __connman_element_stop(void)
{
DBG("");
- __connman_detect_cleanup();
+ __connman_rfkill_cleanup();
+
+ __connman_dhcp_cleanup();
__connman_ipv4_cleanup();
+ __connman_provider_cleanup();
__connman_connection_cleanup();
}
if (element->driver->remove)
element->driver->remove(element);
- __connman_element_lock(element);
element->driver = NULL;
- __connman_element_unlock(element);
}
return FALSE;
__connman_device_cleanup();
__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);
g_node_destroy(element_root);
element_root = NULL;
+ g_free(nodevice_filter);
g_free(device_filter);
+ if (connection == NULL)
+ return;
+
dbus_connection_unref(connection);
}