+static void device_destruct(struct connman_element *element)
+{
+ struct connman_device *device = element->device;
+
+ DBG("element %p name %s", element, element->name);
+
+ g_free(device->interface);
+}
+
+/**
+ * connman_device_create:
+ * @node: device node name (for example an address)
+ * @type: device type
+ *
+ * Allocate a new device of given #type and assign the #node name to it.
+ *
+ * Returns: a newly-allocated #connman_device structure
+ */
+struct connman_device *connman_device_create(const char *node,
+ enum connman_device_type type)
+{
+ struct connman_device *device;
+
+ DBG("node %s type %d", node, type);
+
+ device = g_try_new0(struct connman_device, 1);
+ if (device == NULL)
+ return NULL;
+
+ DBG("device %p", device);
+
+ device->element.name = g_strdup(node);
+ device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
+ device->element.index = -1;
+
+ device->element.device = device;
+ device->element.destruct = device_destruct;
+
+ device->type = type;
+ device->policy = CONNMAN_DEVICE_POLICY_AUTO;
+
+ return device;
+}
+
+/**
+ * connman_device_ref:
+ * @device: device structure
+ *
+ * Increase reference counter of device
+ */
+struct connman_device *connman_device_ref(struct connman_device *device)
+{
+ if (connman_element_ref(&device->element) == NULL)
+ return NULL;
+
+ return device;
+}
+
+/**
+ * connman_device_unref:
+ * @device: device structure
+ *
+ * Decrease reference counter of device
+ */
+void connman_device_unref(struct connman_device *device)
+{
+ connman_element_unref(&device->element);
+}
+
+/**
+ * connman_device_set_interface:
+ * @device: device structure
+ * @index: index number
+ *
+ * Set index number of device
+ */
+void connman_device_set_index(struct connman_device *device, int index)
+{
+ device->element.index = index;
+}
+
+/**
+ * connman_device_get_index:
+ * @device: device structure
+ *
+ * Get index number of device
+ */
+int connman_device_get_index(struct connman_device *device)
+{
+ return device->element.index;
+}
+
+/**
+ * connman_device_set_interface:
+ * @device: device structure
+ * @interface: interface name
+ *
+ * Set interface name of device
+ */
+void connman_device_set_interface(struct connman_device *device,
+ const char *interface)
+{
+ g_free(device->element.devname);
+ device->element.devname = g_strdup(interface);
+
+ g_free(device->interface);
+ device->interface = g_strdup(interface);
+}
+
+/**
+ * connman_device_get_interface:
+ * @device: device structure
+ *
+ * Get interface name of device
+ */
+const char *connman_device_get_interface(struct connman_device *device)
+{
+ return device->interface;
+}
+