*
* 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;
-static struct {
- enum connman_property_id id;
- int type;
- const char *name;
- const void *value;
-} propid_table[] = {
- { CONNMAN_PROPERTY_ID_IPV4_METHOD,
- DBUS_TYPE_STRING, "IPv4.Method", "dhcp" },
- { CONNMAN_PROPERTY_ID_IPV4_ADDRESS,
- DBUS_TYPE_STRING, "IPv4.Address" },
- { CONNMAN_PROPERTY_ID_IPV4_NETMASK,
- DBUS_TYPE_STRING, "IPv4.Netmask" },
- { CONNMAN_PROPERTY_ID_IPV4_GATEWAY,
- DBUS_TYPE_STRING, "IPv4.Gateway" },
- { CONNMAN_PROPERTY_ID_IPV4_BROADCAST,
- DBUS_TYPE_STRING, "IPv4.Broadcast" },
- { CONNMAN_PROPERTY_ID_IPV4_NAMESERVER,
- DBUS_TYPE_STRING, "IPv4.Nameserver" },
-
- { CONNMAN_PROPERTY_ID_WIFI_SECURITY,
- DBUS_TYPE_STRING, "WiFi.Security" },
- { CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE,
- DBUS_TYPE_STRING, "WiFi.Passphrase" },
-
- { }
-};
-
-static int propid2type(enum connman_property_id id)
-{
- int i;
-
- for (i = 0; propid_table[i].name; i++) {
- if (propid_table[i].id == id)
- return propid_table[i].type;
- }
-
- return DBUS_TYPE_INVALID;
-}
-
-static const char *propid2name(enum connman_property_id id)
-{
- int i;
-
- for (i = 0; propid_table[i].name; i++) {
- if (propid_table[i].id == id)
- return propid_table[i].name;
- }
-
- return NULL;
-}
-
static const char *type2string(enum connman_element_type type)
{
switch (type) {
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 "zeroconf";
case CONNMAN_ELEMENT_TYPE_CONNECTION:
return "connection";
+ case CONNMAN_ELEMENT_TYPE_VENDOR:
+ return "vendor";
}
return NULL;
}
-static const char *subtype2string(enum connman_element_subtype type)
+struct foreach_data {
+ enum connman_element_type type;
+ element_cb_t callback;
+ gpointer user_data;
+};
+
+static gboolean foreach_callback(GNode *node, gpointer user_data)
{
- switch (type) {
- case CONNMAN_ELEMENT_SUBTYPE_UNKNOWN:
- return "unknown";
- case CONNMAN_ELEMENT_SUBTYPE_FAKE:
- return "fake";
- case CONNMAN_ELEMENT_SUBTYPE_ETHERNET:
- return "ethernet";
- case CONNMAN_ELEMENT_SUBTYPE_WIFI:
- return "wifi";
- case CONNMAN_ELEMENT_SUBTYPE_WIMAX:
- return "wimax";
- case CONNMAN_ELEMENT_SUBTYPE_CELLULAR:
- return "cellular";
- case CONNMAN_ELEMENT_SUBTYPE_BLUETOOTH:
- return "bluetooth";
- }
+ struct connman_element *element = node->data;
+ struct foreach_data *data = user_data;
- return NULL;
-}
+ DBG("element %p name %s", element, element->name);
-const char *__connman_element_policy2string(enum connman_element_policy policy)
-{
- switch (policy) {
- case CONNMAN_ELEMENT_POLICY_UNKNOWN:
- return "unknown";
- case CONNMAN_ELEMENT_POLICY_IGNORE:
- return "ignore";
- case CONNMAN_ELEMENT_POLICY_AUTO:
- return "auto";
- case CONNMAN_ELEMENT_POLICY_ASK:
- return "ask";
- }
+ if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
+ return FALSE;
- return NULL;
-}
+ if (data->type != CONNMAN_ELEMENT_TYPE_UNKNOWN &&
+ data->type != element->type)
+ return FALSE;
-enum connman_element_policy __connman_element_string2policy(const char *policy)
-{
- if (strcasecmp(policy, "ignore") == 0)
- return CONNMAN_ELEMENT_POLICY_IGNORE;
- else if (strcasecmp(policy, "auto") == 0)
- return CONNMAN_ELEMENT_POLICY_AUTO;
- else if (strcasecmp(policy, "ask") == 0)
- return CONNMAN_ELEMENT_POLICY_ASK;
- else
- return CONNMAN_ELEMENT_POLICY_UNKNOWN;
+ if (data->callback)
+ data->callback(element, data->user_data);
+
+ return FALSE;
}
-const char *__connman_ipv4_method2string(enum connman_ipv4_method method)
+void __connman_element_foreach(struct connman_element *element,
+ enum connman_element_type type,
+ element_cb_t callback, gpointer user_data)
{
- 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";
- }
+ struct foreach_data data = { type, callback, user_data };
+ GNode *node;
- return "unknown";
-}
+ DBG("");
-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;
+ if (element != NULL) {
+ node = g_node_find(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, element);
+ if (node == NULL)
+ return;
+ } else
+ node = element_root;
+
+ g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+ foreach_callback, &data);
}
-static void append_property(DBusMessageIter *dict,
- struct connman_property *property)
+struct append_filter {
+ enum connman_element_type type;
+ DBusMessageIter *iter;
+};
+
+static gboolean append_path(GNode *node, gpointer user_data)
{
- if (property->value == NULL)
- return;
+ struct connman_element *element = node->data;
+ struct append_filter *filter = user_data;
- switch (property->type) {
- case DBUS_TYPE_ARRAY:
- connman_dbus_dict_append_array(dict, property->name,
- property->subtype, &property->value, property->size);
- break;
- case DBUS_TYPE_STRING:
- connman_dbus_dict_append_variant(dict, property->name,
- property->type, &property->value);
- break;
- default:
- connman_dbus_dict_append_variant(dict, property->name,
- property->type, property->value);
- break;
- }
-}
+ DBG("element %p name %s", element, element->name);
-static void add_common_properties(struct connman_element *element,
- DBusMessageIter *dict)
-{
- const char *address = NULL, *netmask = NULL, *gateway = NULL;
- GSList *list;
+ if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
+ return FALSE;
- 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 (element->priority > 0)
- connman_dbus_dict_append_variant(dict, "Priority",
- DBUS_TYPE_UINT16, &element->priority);
-
- 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 (element->wifi.security != NULL) {
- const char *passphrase = "";
-
- connman_dbus_dict_append_variant(dict, "WiFi.Security",
- DBUS_TYPE_STRING, &element->wifi.security);
-
- if (element->wifi.passphrase != NULL)
- passphrase = element->wifi.passphrase;
-
- connman_dbus_dict_append_variant(dict, "WiFi.Passphrase",
- DBUS_TYPE_STRING, &passphrase);
- }
+ if (filter->type != CONNMAN_ELEMENT_TYPE_UNKNOWN &&
+ filter->type != element->type)
+ return FALSE;
- __connman_element_lock(element);
+ if (filter->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
+ __connman_device_has_driver(element->device) == FALSE)
+ return FALSE;
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
+ if (filter->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
+ __connman_network_has_driver(element->network) == FALSE)
+ return FALSE;
- append_property(dict, property);
- }
+ dbus_message_iter_append_basic(filter->iter,
+ DBUS_TYPE_OBJECT_PATH, &element->path);
- __connman_element_unlock(element);
+ return FALSE;
}
-static void set_common_property(struct connman_element *element,
- const char *name, DBusMessageIter *value)
+void __connman_element_list(struct connman_element *element,
+ enum connman_element_type type,
+ DBusMessageIter *iter)
{
- GSList *list;
-
- if (g_str_equal(name, "Priority") == TRUE) {
- dbus_message_iter_get_basic(value, &element->priority);
- return;
- }
-
- __connman_element_lock(element);
+ struct append_filter filter = { type, iter };
+ GNode *node;
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
- const char *str;
+ DBG("");
- if (g_str_equal(property->name, name) == FALSE)
- continue;
+ if (element != NULL) {
+ node = g_node_find(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, element);
+ if (node == NULL)
+ return;
+ } else
+ node = element_root;
- if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
- continue;
+ g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+ append_path, &filter);
+}
- property->flags &= ~CONNMAN_PROPERTY_FLAG_REFERENCE;
+static struct connman_network *__connman_element_get_network(struct connman_element *element)
+{
+ if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
+ element->network != NULL)
+ return element->network;
- if (property->type == DBUS_TYPE_STRING) {
- dbus_message_iter_get_basic(value, &str);
- g_free(property->value);
- property->value = g_strdup(str);
- } else
- property->value = NULL;
- }
+ if (element->parent == NULL)
+ return NULL;
- __connman_element_unlock(element);
+ return __connman_element_get_network(element->parent);
}
-static void emit_enabled_signal(DBusConnection *conn,
- struct connman_element *element)
+struct connman_service *__connman_element_get_service(struct connman_element *element)
{
- DBusMessage *signal;
- DBusMessageIter entry, value;
- const char *iface, *key;
+ struct connman_service *service = NULL;
+ struct connman_network *network;
+ struct connman_device *device;
+ enum connman_device_type type;
- DBG("conn %p", conn);
+ device = __connman_element_get_device(element);
+ if (device == NULL)
+ return NULL;
- if (element == NULL)
- return;
+ type = connman_device_get_type(device);
- switch (element->type) {
- case CONNMAN_ELEMENT_TYPE_DEVICE:
- iface = CONNMAN_DEVICE_INTERFACE;
- key = "Powered";
- break;
- case CONNMAN_ELEMENT_TYPE_NETWORK:
- iface = CONNMAN_NETWORK_INTERFACE;
- key = "Connected";
+ switch (type) {
+ case CONNMAN_DEVICE_TYPE_UNKNOWN:
+ case CONNMAN_DEVICE_TYPE_VENDOR:
+ case CONNMAN_DEVICE_TYPE_GPS:
break;
- case CONNMAN_ELEMENT_TYPE_CONNECTION:
- iface = CONNMAN_CONNECTION_INTERFACE;
- key = "Default";
+ 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;
- default:
- return;
}
- signal = dbus_message_new_signal(element->path,
- iface, "PropertyChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &entry);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
- dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_BOOLEAN_AS_STRING, &value);
- dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN,
- &element->enabled);
- dbus_message_iter_close_container(&entry, &value);
-
- g_dbus_send_message(conn, signal);
+ return service;
}
-static void emit_scanning_signal(DBusConnection *conn,
- struct connman_element *element)
+struct connman_device *__connman_element_get_device(struct connman_element *element)
{
- DBusMessage *signal;
- DBusMessageIter entry, value;
- const char *key = "Scanning";
+ if (element->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
+ element->device != NULL)
+ return element->device;
- DBG("conn %p", conn);
+ if (element->parent == NULL)
+ return NULL;
- if (element == NULL)
- return;
+ return __connman_element_get_device(element->parent);
+}
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
- return;
+const char *__connman_element_get_device_path(struct connman_element *element)
+{
+ struct connman_device *device;
- signal = dbus_message_new_signal(element->path,
- CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
- if (signal == NULL)
- return;
+ device = __connman_element_get_device(element);
+ if (device == NULL)
+ return NULL;
- dbus_message_iter_init_append(signal, &entry);
+ return connman_device_get_path(device);
+}
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+const char *__connman_element_get_network_path(struct connman_element *element)
+{
+ if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
+ element->network != NULL)
+ return element->path;
- dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_BOOLEAN_AS_STRING, &value);
- dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN,
- &element->scanning);
- dbus_message_iter_close_container(&entry, &value);
+ if (element->parent == NULL)
+ return NULL;
- g_dbus_send_message(conn, signal);
+ return __connman_element_get_network_path(element->parent);
}
-static DBusMessage *do_enable(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- struct connman_element *element = data;
+struct find_data {
+ enum connman_service_type type;
+ struct connman_device *device;
+};
- DBG("conn %p", conn);
+static gboolean find_device(GNode *node, gpointer user_data)
+{
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
- if (element->enabled == TRUE)
- return __connman_error_failed(msg);
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
- if (element->driver && element->driver->enable) {
- DBG("Calling enable callback");
- if (element->driver->enable(element) < 0)
- return __connman_error_failed(msg);
- }
+ if (element->device == NULL)
+ return FALSE;
- element->enabled = TRUE;
+ if (data->type != connman_device_get_type(element->device))
+ return FALSE;
- emit_enabled_signal(connection, element);
+ data->device = element->device;
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ return TRUE;
}
-static DBusMessage *do_disable(DBusConnection *conn,
- DBusMessage *msg, void *data)
+struct connman_device *__connman_element_find_device(enum connman_service_type type)
{
- struct connman_element *element = data;
-
- DBG("conn %p", conn);
-
- if (element->enabled == FALSE)
- return __connman_error_failed(msg);
-
- if (element->driver && element->driver->disable) {
- DBG("Calling disable callback");
- if (element->driver->disable(element) < 0)
- return __connman_error_failed(msg);
- }
-
- element->enabled = FALSE;
+ struct find_data data = { .type = type, .device = NULL };
- emit_enabled_signal(connection, element);
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, find_device, &data);
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ return data.device;
}
-static DBusMessage *network_get_properties(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static gboolean request_scan(GNode *node, gpointer user_data)
{
- struct connman_element *element = data;
- DBusMessage *reply;
- DBusMessageIter array, dict;
-
- DBG("conn %p", conn);
-
- reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
- return NULL;
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+ enum connman_service_type type;
- dbus_message_iter_init_append(reply, &array);
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
- dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+ if (element->device == NULL)
+ return FALSE;
- if (element->parent)
- connman_dbus_dict_append_variant(&dict, "Device",
- DBUS_TYPE_OBJECT_PATH, &element->parent->path);
+ type = __connman_device_get_service_type(element->device);
- connman_dbus_dict_append_variant(&dict, "Available",
- DBUS_TYPE_BOOLEAN, &element->available);
+ 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_dbus_dict_append_variant(&dict, "Connected",
- DBUS_TYPE_BOOLEAN, &element->enabled);
+ __connman_device_scan(element->device);
- connman_dbus_dict_append_variant(&dict, "Remember",
- DBUS_TYPE_BOOLEAN, &element->remember);
+ return FALSE;
+}
- add_common_properties(element, &dict);
+int __connman_element_request_scan(enum connman_service_type type)
+{
+ struct find_data data = { .type = type, .device = NULL };
- dbus_message_iter_close_container(&array, &dict);
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, request_scan, &data);
- return reply;
+ return 0;
}
-static DBusMessage *network_set_property(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static gboolean enable_technology(GNode *node, gpointer user_data)
{
- struct connman_element *element = data;
- DBusMessageIter iter;
- DBusMessageIter value;
- const char *name;
-
- DBG("conn %p", conn);
-
- if (dbus_message_iter_init(msg, &iter) == FALSE)
- return __connman_error_invalid_arguments(msg);
+ struct connman_element *element = node->data;
+ struct find_data *data = user_data;
+ enum connman_service_type type;
- dbus_message_iter_get_basic(&iter, &name);
- dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &value);
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
- if (__connman_security_check_privileges(msg) < 0)
- return __connman_error_permission_denied(msg);
+ if (element->device == NULL)
+ return FALSE;
- if (g_str_equal(name, "Remember") == TRUE) {
- dbus_message_iter_get_basic(&value, &element->remember);
- } else if (g_str_equal(name, "WiFi.Passphrase") == TRUE) {
- const char *str;
+ type = __connman_device_get_service_type(element->device);
- dbus_message_iter_get_basic(&value, &str);
- g_free(element->wifi.passphrase);
- element->wifi.passphrase = g_strdup(str);
- } else
- set_common_property(element, name, &value);
+ 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_element_store(element);
+ __connman_device_enable_persistent(element->device);
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ return FALSE;
}
-static DBusMessage *connection_get_properties(DBusConnection *conn,
- DBusMessage *msg, void *data)
+int __connman_element_enable_technology(enum connman_service_type type)
{
- struct connman_element *element = data;
- DBusMessage *reply;
- DBusMessageIter array, dict;
- const char *str;
+ struct find_data data = { .type = type, .device = NULL };
- DBG("conn %p", conn);
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, enable_technology, &data);
- reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
- return NULL;
-
- dbus_message_iter_init_append(reply, &array);
-
- dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+ return 0;
+}
- str = subtype2string(element->subtype);
- if (str != NULL)
- connman_dbus_dict_append_variant(&dict, "Type",
- DBUS_TYPE_STRING, &str);
+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->devname != NULL)
- connman_dbus_dict_append_variant(&dict, "Interface",
- DBUS_TYPE_STRING, &element->devname);
+ if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+ return FALSE;
- if (element->subtype == CONNMAN_ELEMENT_SUBTYPE_WIFI ||
- element->subtype == CONNMAN_ELEMENT_SUBTYPE_WIMAX)
- connman_dbus_dict_append_variant(&dict, "Strength",
- DBUS_TYPE_BYTE, &element->strength);
+ if (element->device == NULL)
+ return FALSE;
- connman_dbus_dict_append_variant(&dict, "Default",
- DBUS_TYPE_BOOLEAN, &element->enabled);
+ type = __connman_device_get_service_type(element->device);
- add_common_properties(element, &dict);
+ 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;
+ }
- dbus_message_iter_close_container(&array, &dict);
+ __connman_device_disable_persistent(element->device);
- return reply;
+ return FALSE;
}
-static DBusMessage *connection_set_property(DBusConnection *conn,
- DBusMessage *msg, void *data)
+int __connman_element_disable_technology(enum connman_service_type type)
{
- struct connman_element *element = data;
- DBusMessageIter iter, value;
- const char *name;
-
- DBG("conn %p", conn);
-
- if (dbus_message_iter_init(msg, &iter) == FALSE)
- return __connman_error_invalid_arguments(msg);
-
- dbus_message_iter_get_basic(&iter, &name);
- dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &value);
+ struct find_data data = { .type = type, .device = NULL };
- if (__connman_security_check_privileges(msg) < 0)
- return __connman_error_permission_denied(msg);
+ g_node_traverse(element_root, G_PRE_ORDER,
+ G_TRAVERSE_ALL, -1, disable_technology, &data);
- if (g_str_equal(name, "Default") == TRUE) {
- dbus_bool_t enabled;
-
- dbus_message_iter_get_basic(&value, &enabled);
+ return 0;
+}
- if (enabled == TRUE)
- return do_enable(conn, msg, element);
- else
- return do_disable(conn, msg, element);
- }
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+ const struct connman_driver *driver1 = a;
+ const struct connman_driver *driver2 = b;
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+ return driver2->priority - driver1->priority;
}
-static GDBusMethodTable network_methods[] = {
- { "GetProperties", "", "a{sv}", network_get_properties },
- { "SetProperty", "sv", "", network_set_property },
- { "Connect", "", "", do_enable },
- { "Disconnect", "", "", do_disable },
- { },
-};
-
-static GDBusMethodTable connection_methods[] = {
- { "GetProperties", "", "a{sv}", connection_get_properties },
- { "SetProperty", "sv", "", connection_set_property },
- { },
-};
+static gboolean match_driver(struct connman_element *element,
+ struct connman_driver *driver)
+{
+ if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
+ return FALSE;
-static GDBusSignalTable element_signals[] = {
- { "PropertyChanged", "sv" },
- { },
-};
+ if (element->type == driver->type ||
+ driver->type == CONNMAN_ELEMENT_TYPE_UNKNOWN)
+ return TRUE;
-struct append_filter {
- enum connman_element_type type;
- DBusMessageIter *iter;
-};
+ return FALSE;
+}
-static gboolean append_path(GNode *node, gpointer user_data)
+static gboolean probe_driver(GNode *node, gpointer data)
{
struct connman_element *element = node->data;
- struct append_filter *filter = user_data;
+ struct connman_driver *driver = data;
DBG("element %p name %s", element, element->name);
- if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
- return FALSE;
-
- if (filter->type != CONNMAN_ELEMENT_TYPE_UNKNOWN &&
- filter->type != element->type)
- return FALSE;
+ if (!element->driver && match_driver(element, driver) == TRUE) {
+ if (driver->probe(element) < 0)
+ return FALSE;
- dbus_message_iter_append_basic(filter->iter,
- DBUS_TYPE_OBJECT_PATH, &element->path);
-
- return FALSE;
-}
-
-void __connman_element_list(struct connman_element *element,
- enum connman_element_type type,
- DBusMessageIter *iter)
-{
- struct append_filter filter = { type, iter };
- GNode *node;
-
- DBG("");
-
- if (element != NULL) {
- node = g_node_find(element_root, G_PRE_ORDER,
- G_TRAVERSE_ALL, element);
- if (node == NULL)
- return;
- } else
- node = element_root;
-
- g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
- 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 gint compare_priority(gconstpointer a, gconstpointer b)
-{
- const struct connman_driver *driver1 = a;
- const struct connman_driver *driver2 = b;
-
- return driver2->priority - driver1->priority;
-}
-
-static gboolean match_driver(struct connman_element *element,
- struct connman_driver *driver)
-{
- if (element->type == CONNMAN_ELEMENT_TYPE_ROOT)
- return FALSE;
-
- if (element->type != driver->type &&
- driver->type != CONNMAN_ELEMENT_TYPE_UNKNOWN)
- return FALSE;
-
- if (element->subtype == driver->subtype ||
- driver->subtype == CONNMAN_ELEMENT_SUBTYPE_UNKNOWN)
- return TRUE;
-
- return FALSE;
-}
-
-static void enable_element(struct connman_element *element)
-{
- if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
- return;
-
- if (element->policy != CONNMAN_ELEMENT_POLICY_AUTO)
- return;
-
- if (element->driver && element->driver->enable) {
- if (element->driver->enable(element) == 0) {
- element->enabled = TRUE;
- emit_enabled_signal(connection, element);
- }
- }
-}
-
-static gboolean probe_driver(GNode *node, gpointer data)
-{
- struct connman_element *element = node->data;
- struct connman_driver *driver = data;
-
- DBG("element %p name %s", element, element->name);
-
- if (!element->driver && match_driver(element, driver) == TRUE) {
- if (driver->probe(element) < 0)
- return FALSE;
-
- __connman_element_lock(element);
- element->driver = driver;
- __connman_element_unlock(element);
-
- enable_element(element);
- }
+ element->driver = driver;
+ }
return FALSE;
}
return 0;
}
-static void disable_element(struct connman_element *element)
-{
- if (element->policy != CONNMAN_ELEMENT_POLICY_AUTO)
- return;
-
- if (element->enabled == FALSE)
- return;
-
- if (element->driver && element->driver->disable) {
- if (element->driver->disable(element) == 0) {
- element->enabled = FALSE;
- emit_enabled_signal(connection, element);
- }
- }
-}
-
static gboolean remove_driver(GNode *node, gpointer data)
{
struct connman_element *element = node->data;
DBG("element %p name %s", element, element->name);
if (element->driver == driver) {
- disable_element(element);
-
if (driver->remove)
driver->remove(element);
- __connman_element_lock(element);
element->driver = NULL;
- __connman_element_unlock(element);
}
return FALSE;
G_TRAVERSE_ALL, -1, remove_driver, driver);
}
+static void unregister_property(gpointer data)
+{
+ struct connman_property *property = data;
+
+ DBG("property %p", property);
+
+ g_free(property->value);
+ 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->refcount = 1;
+
+ 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->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);
+}
+
/**
* connman_element_create:
* @name: element name
DBG("element %p", element);
- element->refcount = 1;
-
- element->name = g_strdup(name);
- element->type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
- element->subtype = CONNMAN_ELEMENT_SUBTYPE_UNKNOWN;
- element->state = CONNMAN_ELEMENT_STATE_CLOSED;
- element->policy = CONNMAN_ELEMENT_POLICY_AUTO;
- element->index = -1;
- element->enabled = FALSE;
+ __connman_element_initialize(element);
return element;
}
static void free_properties(struct connman_element *element)
{
- GSList *list;
-
DBG("element %p name %s", element, element->name);
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE))
- g_free(property->value);
-
- g_free(property->name);
- g_free(property);
- }
-
- g_slist_free(element->properties);
-
+ g_hash_table_destroy(element->properties);
element->properties = NULL;
-
- __connman_element_unlock(element);
}
-void connman_element_unref(struct connman_element *element)
+static void free_children(struct connman_element *element)
{
- DBG("element %p name %s refcount %d", element, element->name,
- g_atomic_int_get(&element->refcount) - 1);
-
- if (g_atomic_int_dec_and_test(&element->refcount) == TRUE) {
- if (element->destruct)
- element->destruct(element);
- free_properties(element);
- g_free(element->ipv4.address);
- g_free(element->ipv4.netmask);
- g_free(element->ipv4.gateway);
- g_free(element->ipv4.network);
- g_free(element->ipv4.broadcast);
- g_free(element->ipv4.nameserver);
- g_free(element->devname);
- g_free(element->devpath);
- g_free(element->path);
- g_free(element->name);
- g_free(element);
- }
-}
-
-int connman_element_add_static_property(struct connman_element *element,
- const char *name, int type, const void *value)
-{
- struct connman_property *property;
-
- DBG("element %p name %s", element, element->name);
-
- if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_BYTE)
- return -EINVAL;
-
- property = g_try_new0(struct connman_property, 1);
- if (property == NULL)
- return -ENOMEM;
-
- property->flags = CONNMAN_PROPERTY_FLAG_STATIC;
- property->id = CONNMAN_PROPERTY_ID_INVALID;
- property->name = g_strdup(name);
- property->type = type;
-
- DBG("name %s type %d value %p", name, type, value);
-
- switch (type) {
- case DBUS_TYPE_STRING:
- property->value = g_strdup(*((const char **) value));
- break;
- case DBUS_TYPE_BYTE:
- property->value = g_try_malloc(1);
- if (property->value != NULL)
- memcpy(property->value, value, 1);
- break;
- }
-
- __connman_element_lock(element);
- element->properties = g_slist_append(element->properties, property);
- __connman_element_unlock(element);
-
- return 0;
-}
-
-static void emit_property_changed(DBusConnection *conn,
- struct connman_element *element,
- const char *name, int type, const void *data)
-{
- DBusMessage *signal;
- DBusMessageIter entry, value;
- const char *iface, *sig;
-
- DBG("conn %p", conn);
-
- switch (element->type) {
- case CONNMAN_ELEMENT_TYPE_DEVICE:
- iface = CONNMAN_DEVICE_INTERFACE;
- break;
- case CONNMAN_ELEMENT_TYPE_NETWORK:
- iface = CONNMAN_NETWORK_INTERFACE;
- break;
- case CONNMAN_ELEMENT_TYPE_CONNECTION:
- iface = CONNMAN_CONNECTION_INTERFACE;
- break;
- default:
- return;
- }
-
- signal = dbus_message_new_signal(element->path,
- iface, "PropertyChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &entry);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &name);
-
- switch (type) {
- case DBUS_TYPE_STRING:
- sig = DBUS_TYPE_STRING_AS_STRING;
- break;
- case DBUS_TYPE_BYTE:
- sig = DBUS_TYPE_BYTE_AS_STRING;
- break;
- default:
- sig = DBUS_TYPE_VARIANT_AS_STRING;
- break;
- }
-
- dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
- sig, &value);
- dbus_message_iter_append_basic(&value, type, data);
- dbus_message_iter_close_container(&entry, &value);
-
- g_dbus_send_message(conn, signal);
-}
-
-int connman_element_set_static_property(struct connman_element *element,
- const char *name, int type, const void *value)
-{
- GSList *list;
-
- DBG("element %p name %s", element, element->name);
-
- if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_BYTE)
- return -EINVAL;
-
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (g_str_equal(property->name, name) == FALSE)
- continue;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_STATIC))
- continue;
-
- property->type = type;
- g_free(property->value);
-
- switch (type) {
- case DBUS_TYPE_STRING:
- property->value = g_strdup(*((const char **) value));
- break;
- case DBUS_TYPE_BYTE:
- property->value = g_try_malloc(1);
- if (property->value != NULL)
- memcpy(property->value, value, 1);
- break;
- }
- }
-
- __connman_element_unlock(element);
-
- emit_property_changed(connection, element, name, type, value);
-
- return 0;
-}
-
-int connman_element_add_static_array_property(struct connman_element *element,
- const char *name, int type, const void *value, int len)
-{
- struct connman_property *property;
-
- DBG("element %p name %s", element, element->name);
-
- if (type != DBUS_TYPE_BYTE)
- return -EINVAL;
-
- property = g_try_new0(struct connman_property, 1);
- if (property == NULL)
- return -ENOMEM;
-
- property->flags = CONNMAN_PROPERTY_FLAG_STATIC;
- property->id = CONNMAN_PROPERTY_ID_INVALID;
- property->name = g_strdup(name);
- property->type = DBUS_TYPE_ARRAY;
- property->subtype = type;
-
- DBG("name %s type %d value %p", name, type, value);
-
- switch (type) {
- case DBUS_TYPE_BYTE:
- property->value = g_try_malloc(len);
- if (property->value != NULL) {
- memcpy(property->value,
- *((const unsigned char **) value), len);
- property->size = len;
- }
- break;
- }
-
- __connman_element_lock(element);
- element->properties = g_slist_append(element->properties, property);
- __connman_element_unlock(element);
-
- return 0;
-}
-
-static void *get_reference_value(struct connman_element *element,
- enum connman_property_id id)
-{
- GSList *list;
-
- DBG("element %p name %s", element, element->name);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (property->id != id)
- continue;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE))
- return property->value;
- }
-
- if (element->parent == NULL)
- return NULL;
-
- return get_reference_value(element->parent, id);
-}
-
-static void set_reference_properties(struct connman_element *element)
-{
- GSList *list;
-
- DBG("element %p name %s", element, element->name);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE))
- continue;
-
- property->value = get_reference_value(element->parent,
- property->id);
- }
-}
-
-static struct connman_property *create_property(struct connman_element *element,
- enum connman_property_id id)
-{
- struct connman_property *property;
- GSList *list;
-
- DBG("element %p name %s", element, element->name);
-
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- property = list->data;
-
- if (property->id == id)
- goto unlock;
- }
-
- property = g_try_new0(struct connman_property, 1);
- if (property == NULL)
- goto unlock;
-
- property->flags = CONNMAN_PROPERTY_FLAG_REFERENCE;
- property->id = id;
- property->name = g_strdup(propid2name(id));
- property->type = propid2type(id);
-
- if (property->name == NULL) {
- g_free(property);
- property = NULL;
- goto unlock;
- }
-
- element->properties = g_slist_append(element->properties, property);
-
-unlock:
- __connman_element_unlock(element);
-
- return property;
-}
-
-static void create_default_properties(struct connman_element *element)
-{
- struct connman_property *property;
- int i;
-
- DBG("element %p name %s", element, element->name);
-
- for (i = 0; propid_table[i].name; i++) {
- DBG("property %s", propid_table[i].name);
-
- property = create_property(element, propid_table[i].id);
+ DBG("element %p name %s", element, element->name);
- property->flags &= ~CONNMAN_PROPERTY_FLAG_REFERENCE;
+ g_hash_table_destroy(element->children);
+ element->children = NULL;
+}
- if (propid_table[i].type != DBUS_TYPE_STRING)
- continue;
+void connman_element_unref(struct connman_element *element)
+{
+ DBG("element %p name %s refcount %d", element, element->name,
+ g_atomic_int_get(&element->refcount) - 1);
- if (propid_table[i].value)
- property->value = g_strdup(propid_table[i].value);
- else
- property->value = g_strdup("");
+ 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.gateway);
+ 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);
+ g_free(element);
}
}
-static int define_properties_valist(struct connman_element *element,
- va_list args)
+static int set_static_property(struct connman_element *element,
+ const char *name, int type, const void *value)
{
- enum connman_property_id id;
+ struct connman_property *property;
DBG("element %p name %s", element, element->name);
- id = va_arg(args, enum connman_property_id);
+ if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_BYTE)
+ return -EINVAL;
- while (id != CONNMAN_PROPERTY_ID_INVALID) {
+ property = g_try_new0(struct connman_property, 1);
+ if (property == NULL)
+ return -ENOMEM;
- DBG("property %d", id);
+ property->id = CONNMAN_PROPERTY_ID_INVALID;
+ property->type = type;
- create_property(element, id);
+ DBG("name %s type %d value %p", name, type, value);
- id = va_arg(args, enum connman_property_id);
+ switch (type) {
+ 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)
+ memcpy(property->value, value, 1);
+ break;
}
+ g_hash_table_replace(element->properties, g_strdup(name), property);
+
return 0;
}
-/**
- * connman_element_define_properties:
- * @element: an element
- * @varargs: list of property identifiers
- *
- * Define the valid properties for an element.
- *
- * Returns: %0 on success
- */
-int connman_element_define_properties(struct connman_element *element, ...)
+static int set_static_array_property(struct connman_element *element,
+ const char *name, int type, const void *value, int len)
{
- va_list args;
- int err;
+ struct connman_property *property;
DBG("element %p name %s", element, element->name);
- va_start(args, element);
-
- err = define_properties_valist(element, args);
+ if (type != DBUS_TYPE_BYTE)
+ return -EINVAL;
- va_end(args);
+ property = g_try_new0(struct connman_property, 1);
+ if (property == NULL)
+ return -ENOMEM;
- return err;
-}
+ property->id = CONNMAN_PROPERTY_ID_INVALID;
+ property->type = DBUS_TYPE_ARRAY;
+ property->subtype = type;
-int connman_element_create_property(struct connman_element *element,
- const char *name, int type)
-{
- return -EIO;
-}
+ DBG("name %s type %d value %p", name, type, value);
-int connman_element_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;
- case CONNMAN_PROPERTY_ID_WIFI_SECURITY:
- __connman_element_lock(element);
- g_free(element->wifi.security);
- element->wifi.security = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
- break;
- case CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE:
- __connman_element_lock(element);
- g_free(element->wifi.passphrase);
- element->wifi.passphrase = g_strdup(*((const char **) value));
- __connman_element_unlock(element);
+ switch (type) {
+ case DBUS_TYPE_BYTE:
+ property->value = g_try_malloc(len);
+ if (property->value != NULL) {
+ memcpy(property->value,
+ *((const unsigned char **) value), len);
+ property->size = len;
+ }
break;
- default:
- return -EINVAL;
}
+ g_hash_table_replace(element->properties, g_strdup(name), property);
+
return 0;
}
return -EINVAL;
switch (id) {
+ case CONNMAN_PROPERTY_ID_IPV4_METHOD:
+ if (element->ipv4.method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
+ return connman_element_get_value(element->parent,
+ id, value);
+ *((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_WIFI_SECURITY:
- if (element->wifi.security == NULL)
+ 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->wifi.security;
- __connman_element_unlock(element);
+ *((char **) value) = element->ipv4.timeserver;
break;
- case CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE:
- if (element->wifi.passphrase == NULL)
+ case CONNMAN_PROPERTY_ID_IPV4_PAC:
+ if (element->ipv4.pac == NULL)
return connman_element_get_value(element->parent,
id, value);
- __connman_element_lock(element);
- *((char **) value) = element->wifi.passphrase;
- __connman_element_unlock(element);
+ *((char **) value) = element->ipv4.pac;
break;
default:
return -EINVAL;
return 0;
}
-gboolean connman_element_get_static_property(struct connman_element *element,
+static gboolean get_static_property(struct connman_element *element,
const char *name, void *value)
{
- GSList *list;
+ struct connman_property *property;
gboolean found = FALSE;
DBG("element %p name %s", element, element->name);
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_STATIC))
- continue;
-
- if (g_str_equal(property->name, name) == TRUE) {
- switch (property->type) {
- case DBUS_TYPE_STRING:
- *((char **) value) = property->value;
- found = TRUE;
- break;
- }
+ property = g_hash_table_lookup(element->properties, name);
+ if (property != NULL) {
+ switch (property->type) {
+ case DBUS_TYPE_STRING:
+ *((char **) value) = property->value;
+ found = TRUE;
+ break;
+ case DBUS_TYPE_BOOLEAN:
+ case DBUS_TYPE_BYTE:
+ memcpy(value, property->value, 1);
+ found = TRUE;
break;
}
}
- __connman_element_unlock(element);
+ if (found == FALSE && element->parent != NULL)
+ return get_static_property(element->parent, name, value);
return found;
}
-gboolean connman_element_get_static_array_property(struct connman_element *element,
- const char *name, void *value, int *len)
+static gboolean get_static_array_property(struct connman_element *element,
+ const char *name, void *value, unsigned int *len)
{
- GSList *list;
+ struct connman_property *property;
gboolean found = FALSE;
DBG("element %p name %s", element, element->name);
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_STATIC))
- continue;
-
- if (g_str_equal(property->name, name) == TRUE) {
- *((char **) value) = property->value;
- *len = property->size;
- found = TRUE;
- break;
- }
+ property = g_hash_table_lookup(element->properties, name);
+ if (property != NULL) {
+ *((void **) value) = property->value;
+ *len = property->size;
+ found = TRUE;
}
- __connman_element_unlock(element);
-
return found;
}
-gboolean connman_element_match_static_property(struct connman_element *element,
- const char *name, const void *value)
+/**
+ * connman_element_set_string:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_element_set_string(struct connman_element *element,
+ const char *key, const char *value)
{
- GSList *list;
- gboolean result = FALSE;
-
- DBG("element %p name %s", element, element->name);
-
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- if (!(property->flags & CONNMAN_PROPERTY_FLAG_STATIC))
- continue;
-
- if (g_str_equal(property->name, name) == FALSE)
- continue;
-
- if (property->type == DBUS_TYPE_STRING)
- result = g_str_equal(property->value,
- *((const char **) value));
-
- if (result == TRUE)
- break;
- }
-
- __connman_element_unlock(element);
-
- return result;
+ return set_static_property(element, key, DBUS_TYPE_STRING, &value);
}
-static void append_networks(struct connman_element *element,
- DBusMessageIter *entry)
+/**
+ * connman_element_get_string:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_element_get_string(struct connman_element *element,
+ const char *key)
{
- DBusMessageIter value, iter;
- const char *key = "Networks";
-
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
+ const char *value;
- dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
- &value);
-
- dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
- DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
- __connman_element_list(element, CONNMAN_ELEMENT_TYPE_NETWORK, &iter);
- dbus_message_iter_close_container(&value, &iter);
+ if (get_static_property(element, key, &value) == FALSE)
+ return NULL;
- dbus_message_iter_close_container(entry, &value);
+ return value;
}
-static void emit_networks_signal(DBusConnection *conn,
- struct connman_element *device)
+/**
+ * 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)
{
- DBusMessage *signal;
- DBusMessageIter entry;
-
- DBG("conn %p", conn);
-
- if (device == NULL)
- return;
-
- signal = dbus_message_new_signal(device->path,
- CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &entry);
-
- append_networks(device, &entry);
-
- g_dbus_send_message(conn, signal);
+ return set_static_property(element, key, DBUS_TYPE_BOOLEAN, &value);
}
-static void append_connections(DBusMessageIter *entry)
+/**
+ * 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)
{
- DBusMessageIter value, iter;
- const char *key = "Connections";
-
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
+ connman_bool_t value;
- dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
- &value);
-
- dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
- DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
- __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_CONNECTION, &iter);
- dbus_message_iter_close_container(&value, &iter);
+ if (get_static_property(element, key, &value) == FALSE)
+ return FALSE;
- dbus_message_iter_close_container(entry, &value);
+ return value;
}
-static void emit_connections_signal(DBusConnection *conn)
+/**
+ * connman_element_set_uint8:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: integer value
+ *
+ * Set integer value for specific key
+ */
+int connman_element_set_uint8(struct connman_element *element,
+ const char *key, connman_uint8_t value)
{
- 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_connections(&entry);
-
- g_dbus_send_message(conn, signal);
+ return set_static_property(element, key, DBUS_TYPE_BYTE, &value);
}
-static void append_state(DBusMessageIter *entry, const char *state)
+/**
+ * connman_element_get_uint8:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get integer value for specific key
+ */
+connman_uint8_t connman_element_get_uint8(struct connman_element *element,
+ const char *key)
{
- DBusMessageIter value;
- const char *key = "State";
+ connman_uint8_t value;
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
+ if (get_static_property(element, key, &value) == FALSE)
+ return 0;
- 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);
+ return value;
}
-static void emit_state_change(DBusConnection *conn, const char *state)
+/**
+ * connman_element_set_blob:
+ * @element: element structure
+ * @key: unique identifier
+ * @data: blob data
+ * @size: blob size
+ *
+ * Set binary blob value for specific key
+ */
+int connman_element_set_blob(struct connman_element *element,
+ const char *key, const void *data, unsigned int size)
{
- 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);
+ return set_static_array_property(element, key,
+ DBUS_TYPE_BYTE, &data, size);
}
-static void set_signal_strength(struct connman_element *connection)
+/**
+ * connman_element_get_blob:
+ * @element: element structure
+ * @key: unique identifier
+ * @size: pointer to blob size
+ *
+ * Get binary blob value for specific key
+ */
+const void *connman_element_get_blob(struct connman_element *element,
+ const char *key, unsigned int *size)
{
- struct connman_element *element = connection;
+ void *value;
- while (element != NULL) {
- if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK) {
- connection->strength = element->strength;
- break;
- }
+ if (get_static_array_property(element, key, &value, size) == FALSE)
+ return NULL;
- element = element->parent;
- }
+ return value;
}
static void probe_element(struct connman_element *element)
DBG("driver %p name %s", driver, driver->name);
if (driver->probe(element) == 0) {
- __connman_element_lock(element);
element->driver = driver;
- __connman_element_unlock(element);
-
- enable_element(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);
basepath = element->parent->path;
-
- if (element->subtype == CONNMAN_ELEMENT_SUBTYPE_UNKNOWN)
- element->subtype = element->parent->subtype;
} else {
element->parent = element_root->data;
node = element_root;
- basepath = "";
+ basepath = "/device";
}
element->path = g_strdup_printf("%s/%s", basepath, element->name);
- set_reference_properties(element);
-
- __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);
- __connman_element_load(element);
-
g_node_append_data(node, element);
- if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK) {
- if (g_dbus_register_interface(connection, element->path,
- CONNMAN_NETWORK_INTERFACE,
- network_methods, element_signals,
- NULL, element, NULL) == FALSE)
- connman_error("Failed to register %s network",
- element->path);
- else
- emit_networks_signal(connection, element->parent);
- }
+ if (started == FALSE)
+ return;
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- if (g_dbus_register_interface(connection, element->path,
- CONNMAN_CONNECTION_INTERFACE,
- connection_methods, element_signals,
- NULL, element, NULL) == FALSE)
- connman_error("Failed to register %s connection",
- element->path);
- else {
- set_signal_strength(element);
- emit_connections_signal(connection);
- emit_state_change(connection, "online");
- }
+ probe_element(element);
+}
+
+gboolean __connman_element_device_isfiltered(const char *devname)
+{
+ if (device_filter == NULL)
+ goto nodevice;
+
+ if (g_pattern_match_simple(device_filter, devname) == FALSE) {
+ DBG("ignoring device %s (match)", devname);
+ return TRUE;
}
- __connman_element_store(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;
}
}
- element->parent = parent;
+ if (element->type == CONNMAN_ELEMENT_TYPE_DHCP)
+ element->ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
- __connman_element_unlock(element);
+ element->parent = parent;
register_element(element, NULL);
g_node_unlink(node);
if (element->driver) {
- disable_element(element);
-
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_connections_signal(connection);
-
- g_dbus_unregister_interface(connection, element->path,
- CONNMAN_CONNECTION_INTERFACE);
- }
-
- if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK) {
- emit_networks_signal(connection, element->parent);
-
- g_dbus_unregister_interface(connection, element->path,
- CONNMAN_NETWORK_INTERFACE);
- }
-
connman_element_unref(element);
return FALSE;
static gboolean update_element(GNode *node, gpointer user_data)
{
struct connman_element *element = node->data;
- struct connman_element *root = user_data;
DBG("element %p name %s", element, element->name);
if (element->driver && element->driver->update)
element->driver->update(element);
- if (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION &&
- root->type == CONNMAN_ELEMENT_TYPE_NETWORK) {
- if (element->strength != root->strength) {
- element->strength = root->strength;
- emit_property_changed(connection, element, "Strength",
- DBUS_TYPE_BYTE, &element->strength);
- }
- }
-
return FALSE;
}
element->enabled = enabled;
- emit_enabled_signal(connection, element);
+ connman_element_update(element);
return 0;
}
-int connman_element_set_scanning(struct connman_element *element,
- gboolean scanning)
+static enum connman_service_error convert_error(enum connman_element_error error)
{
- if (element->scanning == scanning)
- return 0;
+ 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;
+}
- element->scanning = scanning;
+/**
+ * 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;
- emit_scanning_signal(connection, element);
+ DBG("element %p error %d", element, error);
- return 0;
+ 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(DBusConnection *conn, const char *device)
+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->path = g_strdup("/");
element->type = CONNMAN_ELEMENT_TYPE_ROOT;
- create_default_properties(element);
-
element_root = g_node_new(element);
- __connman_device_init();
+ __connman_technology_init();
+ __connman_notifier_init();
+ __connman_service_init();
+ __connman_provider_init();
__connman_network_init();
+ __connman_device_init();
return 0;
}
{
DBG("");
+ __connman_storage_init_profile();
+
g_node_traverse(element_root, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
probe_node, NULL);
started = TRUE;
- __connman_detect_init();
+ __connman_rtnl_start();
+ __connman_udev_start();
+
+ __connman_connection_init();
+ __connman_ipv4_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();
}
static gboolean free_driver(GNode *node, gpointer data)
DBG("element %p name %s", element, element->name);
if (element->driver) {
- disable_element(element);
-
if (element->driver->remove)
element->driver->remove(element);
- __connman_element_lock(element);
element->driver = NULL;
- __connman_element_unlock(element);
}
return FALSE;
{
DBG("");
- __connman_network_cleanup();
__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);
}