X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fdevice.c;h=b4bf28467a92500e38a222df8d1d13b2c45d5138;hb=ff76ad35726a05cd5bf66ab09c2681f3bee8912d;hp=60c50fde6f8165a0e57b7366a9f63205f04a440d;hpb=fa0e75c2255edd7cecd8a1d63390e7e000cc7d83;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/device.c b/src/device.c index 60c50fd..b4bf284 100644 --- a/src/device.c +++ b/src/device.c @@ -43,10 +43,7 @@ struct connman_device { enum connman_device_type type; enum connman_pending_type powered_pending; /* Indicates a pending enable/disable request */ - connman_bool_t offlinemode; - connman_bool_t blocked; connman_bool_t powered; - connman_bool_t powered_persistent; connman_bool_t scanning; connman_bool_t disconnected; connman_bool_t reconnect; @@ -224,11 +221,8 @@ static gboolean device_pending_reset(gpointer user_data) DBG("device %p", device); /* Power request timedout, reset power pending state. */ - if (device->pending_timeout > 0) { - g_source_remove(device->pending_timeout); - device->pending_timeout = 0; - device->powered_pending = PENDING_NONE; - } + device->pending_timeout = 0; + device->powered_pending = PENDING_NONE; return FALSE; } @@ -237,14 +231,11 @@ int __connman_device_enable(struct connman_device *device) { int err; - DBG("device %p %d", device, device->blocked); + DBG("device %p", device); if (!device->driver || !device->driver->enable) return -EOPNOTSUPP; - if (device->blocked == TRUE) - return -ENOLINK; - /* There is an ongoing power disable request. */ if (device->powered_pending == PENDING_DISABLE) return -EBUSY; @@ -293,9 +284,6 @@ int __connman_device_disable(struct connman_device *device) if (!device->driver || !device->driver->disable) return -EOPNOTSUPP; - if (device->blocked == TRUE) - return -ENOLINK; - /* Ongoing power enable request */ if (device->powered_pending == PENDING_ENABLE) return -EBUSY; @@ -306,6 +294,7 @@ int __connman_device_disable(struct connman_device *device) if (device->powered_pending == PENDING_NONE && device->powered == FALSE) return -EALREADY; + device->powered_pending = PENDING_DISABLE; device->reconnect = FALSE; clear_scan_trigger(device); @@ -328,29 +317,6 @@ done: return err; } -static int set_powered(struct connman_device *device, connman_bool_t powered) -{ - DBG("device %p powered %d", device, powered); - - if (powered == TRUE) - return __connman_device_enable(device); - else - return __connman_device_disable(device); -} - -static int setup_device(struct connman_device *device) -{ - DBG("device %p", device); - - __connman_technology_add_device(device); - - if (device->offlinemode == FALSE && - device->powered_persistent == TRUE) - __connman_device_enable(device); - - return 0; -} - static void probe_driver(struct connman_device_driver *driver) { GSList *list; @@ -371,7 +337,7 @@ static void probe_driver(struct connman_device_driver *driver) device->driver = driver; - setup_device(device); + __connman_technology_add_device(device); } } @@ -501,7 +467,6 @@ struct connman_device *connman_device_create(const char *node, enum connman_device_type type) { struct connman_device *device; - enum connman_service_type service_type; connman_bool_t bg_scan; DBG("node %s type %d", node, type); @@ -519,12 +484,8 @@ struct connman_device *connman_device_create(const char *node, device->type = type; device->name = g_strdup(type2description(device->type)); - device->powered_persistent = TRUE; - device->phyindex = -1; - service_type = __connman_device_get_service_type(device); - device->blocked = __connman_technology_get_blocked(service_type); device->backoff_interval = SCAN_INITIAL_DELAY; switch (type) { @@ -700,13 +661,13 @@ int connman_device_set_powered(struct connman_device *device, if (device->powered == powered) return -EALREADY; - /* Reset pending request */ - g_source_remove(device->pending_timeout); - device->pending_timeout = 0; - device->powered_pending = PENDING_NONE; + if (device->pending_timeout) { + /* Reset pending request */ + g_source_remove(device->pending_timeout); + device->pending_timeout = 0; + } - if (device->offlinemode == TRUE && powered == TRUE) - return __connman_device_disable(device); + device->powered_pending = PENDING_NONE; device->powered = powered; @@ -727,39 +688,14 @@ int connman_device_set_powered(struct connman_device *device, reset_scan_trigger(device); - if (device->driver && device->driver->scan) + if (device->driver && device->driver->scan_fast) + device->driver->scan_fast(device); + else if (device->driver && device->driver->scan) device->driver->scan(device); return 0; } -int __connman_device_set_blocked(struct connman_device *device, - connman_bool_t blocked) -{ - connman_bool_t powered; - - DBG("device %p blocked %d", device, blocked); - - device->blocked = blocked; - - if (device->offlinemode == TRUE) - return 0; - - connman_info("%s {rfkill} blocked %d", device->interface, blocked); - - if (blocked == FALSE) - powered = device->powered_persistent; - else - powered = FALSE; - - return set_powered(device, powered); -} - -connman_bool_t __connman_device_get_blocked(struct connman_device *device) -{ - return device->blocked; -} - static int device_scan(struct connman_device *device) { if (!device->driver || !device->driver->scan) @@ -773,28 +709,6 @@ static int device_scan(struct connman_device *device) return device->driver->scan(device); } -int __connman_device_enable_persistent(struct connman_device *device) -{ - DBG("device %p", device); - - device->powered_persistent = TRUE; - - __connman_storage_save_device(device); - - return __connman_device_enable(device); -} - -int __connman_device_disable_persistent(struct connman_device *device) -{ - DBG("device %p", device); - - device->powered_persistent = FALSE; - - __connman_storage_save_device(device); - - return __connman_device_disable(device); -} - int __connman_device_disconnect(struct connman_device *device) { GHashTableIter iter; @@ -1151,7 +1065,13 @@ static gboolean match_driver(struct connman_device *device, return FALSE; } -static int device_probe(struct connman_device *device) +/** + * connman_device_register: + * @device: device structure + * + * Register device with the system + */ +int connman_device_register(struct connman_device *device) { GSList *list; @@ -1177,32 +1097,7 @@ static int device_probe(struct connman_device *device) if (device->driver == NULL) return 0; - return setup_device(device); -} - -static void device_remove(struct connman_device *device) -{ - DBG("device %p name %s", device, device->name); - - if (device->driver == NULL) - return; - - remove_device(device); -} - -/** - * connman_device_register: - * @device: device structure - * - * Register device with the system - */ -int connman_device_register(struct connman_device *device) -{ - __connman_storage_load_device(device); - - device->offlinemode = __connman_profile_get_offlinemode(); - - return device_probe(device); + return __connman_technology_add_device(device); } /** @@ -1213,9 +1108,12 @@ int connman_device_register(struct connman_device *device) */ void connman_device_unregister(struct connman_device *device) { - __connman_storage_save_device(device); + DBG("device %p name %s", device, device->name); + + if (device->driver == NULL) + return; - device_remove(device); + remove_device(device); } /** @@ -1334,72 +1232,6 @@ nodevice: return FALSE; } -static int device_load(struct connman_device *device) -{ - const char *ident = __connman_profile_active_ident(); - GKeyFile *keyfile; - GError *error = NULL; - gchar *identifier; - connman_bool_t powered; - - DBG("device %p", device); - - keyfile = __connman_storage_open_profile(ident); - if (keyfile == NULL) - return 0; - - identifier = g_strdup_printf("device_%s", device->name); - if (identifier == NULL) - goto done; - - powered = g_key_file_get_boolean(keyfile, identifier, - "Powered", &error); - if (error == NULL) - device->powered_persistent = powered; - g_clear_error(&error); - -done: - g_free(identifier); - - __connman_storage_close_profile(ident, keyfile, FALSE); - - return 0; -} - -static int device_save(struct connman_device *device) -{ - const char *ident = __connman_profile_active_ident(); - GKeyFile *keyfile; - gchar *identifier; - - DBG("device %p", device); - - keyfile = __connman_storage_open_profile(ident); - if (keyfile == NULL) - return 0; - - identifier = g_strdup_printf("device_%s", device->name); - if (identifier == NULL) - goto done; - - g_key_file_set_boolean(keyfile, identifier, - "Powered", device->powered_persistent); - -done: - g_free(identifier); - - __connman_storage_close_profile(ident, keyfile, TRUE); - - 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(const char *device, const char *nodevice) { DBG(""); @@ -1410,7 +1242,7 @@ int __connman_device_init(const char *device, const char *nodevice) if (nodevice != NULL) nodevice_filter = g_strsplit(nodevice, ",", -1); - return connman_storage_register(&device_storage); + return 0; } void __connman_device_cleanup(void) @@ -1419,6 +1251,4 @@ void __connman_device_cleanup(void) g_strfreev(nodevice_filter); g_strfreev(device_filter); - - connman_storage_unregister(&device_storage); }