enum connman_device_type type;
enum connman_device_mode mode;
enum connman_device_policy policy;
- gboolean powered;
- gboolean carrier;
- gboolean scanning;
- char *path;
+ connman_bool_t powered;
+ connman_bool_t carrier;
+ connman_bool_t scanning;
+ char *name;
+ char *node;
char *interface;
struct connman_device_driver *driver;
return CONNMAN_DEVICE_POLICY_UNKNOWN;
}
-static int set_powered(struct connman_device *device, gboolean powered)
+static int set_powered(struct connman_device *device, connman_bool_t powered)
{
struct connman_device_driver *driver = device->driver;
int err;
return __connman_error_permission_denied(msg);
if (g_str_equal(name, "Powered") == TRUE) {
- gboolean powered;
+ connman_bool_t powered;
int err;
dbus_message_iter_get_basic(&value, &powered);
return __connman_error_failed(msg);
}
- __connman_element_store(&device->element);
+ __connman_storage_save_device(device);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
if (!device->driver || !device->driver->scan)
return __connman_error_not_supported(msg);
+ if (device->powered == FALSE)
+ return __connman_error_failed(msg);
+
err = device->driver->scan(device);
if (err < 0)
return __connman_error_failed(msg);
connman_bool_t __connman_device_has_driver(struct connman_device *device)
{
- if (device->driver == NULL)
+ if (device == NULL || device->driver == NULL)
return FALSE;
return device->registered;
DBG("element %p name %s", element, element->name);
- g_free(device->path);
+ g_free(device->node);
+ g_free(device->name);
g_free(device->interface);
g_hash_table_destroy(device->networks);
}
/**
- * connman_device_set_path:
- * @device: device structure
- * @path: path name
- *
- * Set path name of device
- */
-void connman_device_set_path(struct connman_device *device, const char *path)
-{
- g_free(device->element.devpath);
- device->element.devpath = g_strdup(path);
-
- g_free(device->path);
- device->path = g_strdup(path);
-}
-
-/**
* connman_device_get_path:
* @device: device structure
*
*/
const char *connman_device_get_path(struct connman_device *device)
{
- return device->path;
+ return device->element.path;
}
/**
}
/**
+ * connman_device_set_string:
+ * @device: device structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_device_set_string(struct connman_device *device,
+ const char *key, const char *value)
+{
+ DBG("device %p key %s value %s", device, key, value);
+
+ if (g_str_equal(key, "Name") == TRUE) {
+ g_free(device->name);
+ device->name = g_strdup(value);
+ } else if (g_str_equal(key, "Node") == TRUE) {
+ g_free(device->node);
+ device->node = g_strdup(value);
+ }
+
+ return 0;
+}
+
+/**
+ * connman_device_get_string:
+ * @device: device structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_device_get_string(struct connman_device *device,
+ const char *key)
+{
+ DBG("device %p key %s", device);
+
+ if (g_str_equal(key, "Name") == TRUE)
+ return device->name;
+ else if (g_str_equal(key, "Node") == TRUE)
+ return device->node;
+
+ return NULL;
+}
+
+/**
* connman_device_add_network:
* @device: device structure
* @network: network structure
.remove = device_remove,
};
+static int device_load(struct connman_device *device)
+{
+ GKeyFile *keyfile;
+ gchar *pathname, *data = NULL;
+ gsize length;
+ const char *str;
+
+ DBG("device %p", device);
+
+ pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
+ device->element.name);
+ if (pathname == NULL)
+ return -ENOMEM;
+
+ keyfile = g_key_file_new();
+
+ if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
+ g_free(pathname);
+ return -ENOENT;
+ }
+
+ g_free(pathname);
+
+ if (g_key_file_load_from_data(keyfile, data, length,
+ 0, NULL) == FALSE) {
+ g_free(data);
+ return -EILSEQ;
+ }
+
+ g_free(data);
+
+ str = g_key_file_get_string(keyfile, "Configuration", "Policy", NULL);
+ if (str != NULL)
+ device->policy = string2policy(str);
+
+ g_key_file_free(keyfile);
+
+ return 0;
+}
+
+static int device_save(struct connman_device *device)
+{
+ GKeyFile *keyfile;
+ gchar *pathname, *data = NULL;
+ gsize length;
+ const char *str;
+
+ DBG("device %p", device);
+
+ pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
+ device->element.name);
+ if (pathname == NULL)
+ return -ENOMEM;
+
+ keyfile = g_key_file_new();
+
+ if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
+ goto update;
+
+ if (length > 0) {
+ if (g_key_file_load_from_data(keyfile, data, length,
+ 0, NULL) == FALSE)
+ goto done;
+ }
+
+ g_free(data);
+
+update:
+ str = policy2string(device->policy);
+ if (str != NULL)
+ g_key_file_set_string(keyfile, "Configuration", "Policy", str);
+
+ data = g_key_file_to_data(keyfile, &length, NULL);
+
+ g_file_set_contents(pathname, data, length, NULL);
+
+done:
+ g_free(data);
+
+ g_key_file_free(keyfile);
+
+ g_free(pathname);
+
+ return 0;
+}
+
static struct connman_storage device_storage = {
.name = "device",
.priority = CONNMAN_STORAGE_PRIORITY_LOW,
+ .device_load = device_load,
+ .device_save = device_save,
};
int __connman_device_init(void)