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 NULL;
}
-#if 0
-static const char *subtype2string(enum connman_element_subtype type)
-{
- 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";
- }
-
- return NULL;
-}
-#endif
-
-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";
- }
-
- return NULL;
-}
-
-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;
-}
-
-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;
-}
-
-#if 0
-static void append_property(DBusMessageIter *dict,
- struct connman_property *property)
-{
- if (property->value == NULL)
- return;
-
- 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;
- }
-}
-
-static void add_common_properties(struct connman_element *element,
- DBusMessageIter *dict)
-{
- const char *address = NULL, *netmask = NULL, *gateway = NULL;
- GSList *list;
-
- 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);
- }
-
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
-
- append_property(dict, property);
- }
-
- __connman_element_unlock(element);
-}
-
-static void set_common_property(struct connman_element *element,
- const char *name, DBusMessageIter *value)
-{
- GSList *list;
-
- if (g_str_equal(name, "Priority") == TRUE) {
- dbus_message_iter_get_basic(value, &element->priority);
- return;
- }
-
- __connman_element_lock(element);
-
- for (list = element->properties; list; list = list->next) {
- struct connman_property *property = list->data;
- const char *str;
-
- if (g_str_equal(property->name, name) == FALSE)
- continue;
-
- if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
- continue;
-
- property->flags &= ~CONNMAN_PROPERTY_FLAG_REFERENCE;
-
- 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;
- }
-
- __connman_element_unlock(element);
-}
-#endif
-
static void emit_element_signal(DBusConnection *conn, const char *member,
struct connman_element *element)
{
return data.count;
}
+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 (element->parent == NULL)
+ return NULL;
+
+ return __connman_element_get_network(element->parent);
+}
+
+struct connman_service *__connman_element_get_service(struct connman_element *element)
+{
+ struct connman_service *service = NULL;
+ struct connman_network *network;
+ struct connman_device *device;
+ enum connman_device_type type;
+
+ device = __connman_element_get_device(element);
+ if (device == NULL)
+ return NULL;
+
+ type = connman_device_get_type(device);
+
+ switch (type) {
+ case CONNMAN_DEVICE_TYPE_UNKNOWN:
+ case CONNMAN_DEVICE_TYPE_VENDOR:
+ case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+ case CONNMAN_DEVICE_TYPE_GPS:
+ case CONNMAN_DEVICE_TYPE_MBM:
+ case CONNMAN_DEVICE_TYPE_HSO:
+ case CONNMAN_DEVICE_TYPE_NOZOMI:
+ case CONNMAN_DEVICE_TYPE_HUAWEI:
+ case CONNMAN_DEVICE_TYPE_NOVATEL:
+ break;
+ case CONNMAN_DEVICE_TYPE_ETHERNET:
+ service = __connman_service_lookup_from_device(device);
+ break;
+ case CONNMAN_DEVICE_TYPE_WIFI:
+ case CONNMAN_DEVICE_TYPE_WIMAX:
+ network = __connman_element_get_network(element);
+ if (network == NULL)
+ return NULL;
+ service = __connman_service_lookup_from_network(network);
+ break;
+ }
+
+ return service;
+}
+
+struct connman_device *__connman_element_get_device(struct connman_element *element)
+{
+ if (element->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
+ element->device != NULL)
+ return element->device;
+
+ if (element->parent == NULL)
+ return NULL;
+
+ return __connman_element_get_device(element->parent);
+}
+
+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)
+ return element->path;
+
+ if (element->parent == NULL)
+ return NULL;
+
+ return __connman_element_get_network_path(element->parent);
+}
+
static gint compare_priority(gconstpointer a, gconstpointer b)
{
const struct connman_driver *driver1 = a;
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)
+ if (element->type == driver->type ||
+ driver->type == CONNMAN_ELEMENT_TYPE_UNKNOWN)
return TRUE;
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);
+}
+
+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->configuring = FALSE;
+
+ 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);
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,
+static int set_static_property(struct connman_element *element,
const char *name, int type, const void *value)
{
struct connman_property *property;
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;
+ property->id = CONNMAN_PROPERTY_ID_INVALID;
+ property->type = type;
DBG("name %s type %d value %p", name, type, value);
}
__connman_element_lock(element);
- element->properties = g_slist_append(element->properties, property);
- __connman_element_unlock(element);
-
- return 0;
-}
-
-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;
- }
- }
+ g_hash_table_replace(element->properties, g_strdup(name), property);
__connman_element_unlock(element);
return 0;
}
-int connman_element_add_static_array_property(struct connman_element *element,
+static int set_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);
-
- property->flags &= ~CONNMAN_PROPERTY_FLAG_REFERENCE;
-
- if (propid_table[i].type != DBUS_TYPE_STRING)
- continue;
-
- if (propid_table[i].value)
- property->value = g_strdup(propid_table[i].value);
- else
- property->value = g_strdup("");
- }
-}
-
-static int define_properties_valist(struct connman_element *element,
- va_list args)
-{
- enum connman_property_id id;
-
- DBG("element %p name %s", element, element->name);
-
- id = va_arg(args, enum connman_property_id);
-
- while (id != CONNMAN_PROPERTY_ID_INVALID) {
-
- DBG("property %d", id);
-
- create_property(element, id);
-
- id = va_arg(args, enum connman_property_id);
- }
-
- 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, ...)
-{
- va_list args;
- int err;
+ struct connman_property *property;
DBG("element %p name %s", element, element->name);
- va_start(args, element);
+ if (type != DBUS_TYPE_BYTE)
+ return -EINVAL;
- err = define_properties_valist(element, args);
+ property = g_try_new0(struct connman_property, 1);
+ if (property == NULL)
+ return -ENOMEM;
- va_end(args);
+ property->id = CONNMAN_PROPERTY_ID_INVALID;
+ property->type = DBUS_TYPE_ARRAY;
+ property->subtype = type;
- return err;
-}
+ DBG("name %s type %d value %p", name, type, value);
-int connman_element_create_property(struct connman_element *element,
- const char *name, int type)
-{
- return -EIO;
+ 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);
+
+ g_hash_table_replace(element->properties, g_strdup(name), property);
+
+ __connman_element_unlock(element);
+
+ return 0;
}
-int connman_element_set_property(struct connman_element *element,
+#if 0
+static int set_property(struct connman_element *element,
enum connman_property_id id, const void *value)
{
switch (id) {
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);
- break;
default:
return -EINVAL;
}
return 0;
}
+#endif
int connman_element_get_value(struct connman_element *element,
enum connman_property_id id, void *value)
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);
+ __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,
*((char **) value) = element->ipv4.nameserver;
__connman_element_unlock(element);
break;
- case CONNMAN_PROPERTY_ID_WIFI_SECURITY:
- if (element->wifi.security == NULL)
- return connman_element_get_value(element->parent,
- id, value);
- __connman_element_lock(element);
- *((char **) value) = element->wifi.security;
- __connman_element_unlock(element);
- break;
- case CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE:
- if (element->wifi.passphrase == NULL)
- return connman_element_get_value(element->parent,
- id, value);
- __connman_element_lock(element);
- *((char **) value) = element->wifi.passphrase;
- __connman_element_unlock(element);
- 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_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) {
+ *((char **) value) = property->value;
+ *len = property->size;
+ found = TRUE;
}
__connman_element_unlock(element);
return found;
}
-gboolean connman_element_match_static_property(struct connman_element *element,
+#if 0
+static gboolean match_static_property(struct connman_element *element,
const char *name, const void *value)
{
- GSList *list;
+ struct connman_property *property;
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;
-
+ 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));
-
- if (result == TRUE)
- break;
}
__connman_element_unlock(element);
return result;
}
+#endif
-static void append_connections(DBusMessageIter *entry)
+/**
+ * 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)
{
- DBusMessageIter value, iter;
- const char *key = "Connections";
+ return set_static_property(element, key, DBUS_TYPE_STRING, &value);
+}
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
+/**
+ * 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)
+{
+ const char *value;
- dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
- &value);
+ if (get_static_property(element, key, &value) == FALSE)
+ return NULL;
- 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);
+ return value;
+}
- dbus_message_iter_close_container(entry, &value);
+/**
+ * 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)
+{
+ return set_static_property(element, key, DBUS_TYPE_BYTE, &value);
}
-static void emit_connections_signal(DBusConnection *conn)
+/**
+ * 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)
{
- DBusMessage *signal;
- DBusMessageIter entry;
+ connman_uint8_t value;
- DBG("conn %p", conn);
+ if (get_static_property(element, key, &value) == FALSE)
+ return 0;
- signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
- CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
- if (signal == NULL)
- return;
+ return value;
+}
- dbus_message_iter_init_append(signal, &entry);
+/**
+ * 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)
+{
+ return set_static_array_property(element, key,
+ DBUS_TYPE_BYTE, &data, size);
+}
+
+/**
+ * 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)
+{
+ void *value;
+
+ if (get_static_array_property(element, key, &value, size) == FALSE)
+ return NULL;
- append_connections(&entry);
+ return value;
+}
- g_dbus_send_message(conn, signal);
+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;
+
+ 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);
+
+ 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);
+
+ 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);
+ }
+
+ return 0;
}
static void append_state(DBusMessageIter *entry, const char *state)
append_state(&entry, state);
g_dbus_send_message(conn, signal);
-}
-static void set_signal_strength(struct connman_element *connection)
-{
- struct connman_element *element = connection;
+ signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE, "StateChanged");
+ if (signal == NULL)
+ return;
- while (element != NULL) {
- if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK) {
- connection->strength = element->strength;
- break;
- }
+ dbus_message_iter_init_append(signal, &entry);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &state);
- element = element->parent;
- }
+ g_dbus_send_message(conn, signal);
}
static void probe_element(struct connman_element *element)
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);
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 (element->type == CONNMAN_ELEMENT_TYPE_CONNECTION) {
- set_signal_strength(element);
- emit_connections_signal(connection);
- emit_state_change(connection, "online");
+ 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");
}
emit_element_signal(connection, "ElementAdded", element);
}
}
+ if (element->type == CONNMAN_ELEMENT_TYPE_DHCP)
+ element->ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
+
element->parent = parent;
__connman_element_unlock(element);
if (__connman_element_count(NULL,
CONNMAN_ELEMENT_TYPE_CONNECTION) == 0)
emit_state_change(connection, "offline");
- emit_connections_signal(connection);
}
emit_element_signal(connection, "ElementRemoved", element);
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_element_signal(connection, "ElementUpdated", element);
return FALSE;
element->enabled = enabled;
+ connman_element_update(element);
+
return 0;
}
-int __connman_element_init(DBusConnection *conn, const char *device)
+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(DBusConnection *conn, const char *device,
+ const char *nodevice)
{
struct connman_element *element;
element->path = g_strdup("/");
element->type = CONNMAN_ELEMENT_TYPE_ROOT;
- create_default_properties(element);
-
element_root = g_node_new(element);
+ __connman_notifier_init();
+ __connman_service_init();
__connman_network_init();
__connman_device_init();
started = TRUE;
+ __connman_storage_init_device();
+
__connman_connection_init();
__connman_ipv4_init();
- __connman_detect_init();
+ __connman_rfkill_init();
}
void __connman_element_stop(void)
{
DBG("");
- __connman_detect_cleanup();
+ __connman_rfkill_cleanup();
__connman_ipv4_cleanup();
__connman_connection_cleanup();
}
__connman_device_cleanup();
__connman_network_cleanup();
+ __connman_service_cleanup();
+ __connman_notifier_cleanup();
g_node_traverse(element_root, G_POST_ORDER, G_TRAVERSE_ALL, -1,
free_driver, NULL);