5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 struct connman_device {
32 struct connman_element element;
33 enum connman_device_type type;
34 connman_bool_t offlinemode;
35 connman_bool_t blocked;
36 connman_bool_t powered;
37 connman_bool_t powered_pending;
38 connman_bool_t powered_persistent;
39 connman_bool_t scanning;
40 connman_bool_t disconnected;
41 connman_bool_t reconnect;
42 connman_uint16_t scan_interval;
49 unsigned int connections;
52 struct connman_device_driver *driver;
56 struct connman_network *network;
60 static gboolean device_scan_trigger(gpointer user_data)
62 struct connman_device *device = user_data;
64 DBG("device %p", device);
66 if (device->driver == NULL) {
67 device->scan_timeout = 0;
71 if (device->driver->scan)
72 device->driver->scan(device);
77 static void clear_scan_trigger(struct connman_device *device)
79 if (device->scan_timeout > 0) {
80 g_source_remove(device->scan_timeout);
81 device->scan_timeout = 0;
85 static void reset_scan_trigger(struct connman_device *device)
87 clear_scan_trigger(device);
89 if (device->scan_interval > 0) {
90 guint interval = device->scan_interval;
91 device->scan_timeout = g_timeout_add_seconds(interval,
92 device_scan_trigger, device);
96 static void force_scan_trigger(struct connman_device *device)
98 clear_scan_trigger(device);
100 device->scan_timeout = g_timeout_add_seconds(5,
101 device_scan_trigger, device);
104 void connman_device_schedule_scan(struct connman_device *device)
106 reset_scan_trigger(device);
109 static const char *type2description(enum connman_device_type type)
112 case CONNMAN_DEVICE_TYPE_UNKNOWN:
113 case CONNMAN_DEVICE_TYPE_VENDOR:
115 case CONNMAN_DEVICE_TYPE_ETHERNET:
117 case CONNMAN_DEVICE_TYPE_WIFI:
119 case CONNMAN_DEVICE_TYPE_WIMAX:
121 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
123 case CONNMAN_DEVICE_TYPE_GPS:
125 case CONNMAN_DEVICE_TYPE_CELLULAR:
132 static const char *type2string(enum connman_device_type type)
135 case CONNMAN_DEVICE_TYPE_UNKNOWN:
136 case CONNMAN_DEVICE_TYPE_VENDOR:
138 case CONNMAN_DEVICE_TYPE_ETHERNET:
140 case CONNMAN_DEVICE_TYPE_WIFI:
142 case CONNMAN_DEVICE_TYPE_WIMAX:
144 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
146 case CONNMAN_DEVICE_TYPE_GPS:
148 case CONNMAN_DEVICE_TYPE_CELLULAR:
155 enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
157 enum connman_device_type type = connman_device_get_type(device);
160 case CONNMAN_DEVICE_TYPE_UNKNOWN:
161 case CONNMAN_DEVICE_TYPE_VENDOR:
162 case CONNMAN_DEVICE_TYPE_GPS:
164 case CONNMAN_DEVICE_TYPE_ETHERNET:
165 return CONNMAN_SERVICE_TYPE_ETHERNET;
166 case CONNMAN_DEVICE_TYPE_WIFI:
167 return CONNMAN_SERVICE_TYPE_WIFI;
168 case CONNMAN_DEVICE_TYPE_WIMAX:
169 return CONNMAN_SERVICE_TYPE_WIMAX;
170 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
171 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
172 case CONNMAN_DEVICE_TYPE_CELLULAR:
173 return CONNMAN_SERVICE_TYPE_CELLULAR;
176 return CONNMAN_SERVICE_TYPE_UNKNOWN;
179 int __connman_device_enable(struct connman_device *device)
183 DBG("device %p %d", device, device->blocked);
185 if (!device->driver || !device->driver->enable)
188 if (device->powered_pending == TRUE)
191 if (device->blocked == TRUE)
194 err = device->driver->enable(device);
196 if (err == -EINPROGRESS) {
197 device->powered_pending = TRUE;
198 device->offlinemode = FALSE;
199 if (__connman_profile_get_offlinemode() == TRUE)
200 __connman_profile_set_offlinemode(FALSE, FALSE);
205 device->powered_pending = TRUE;
206 device->powered = TRUE;
207 device->offlinemode = FALSE;
208 if (__connman_profile_get_offlinemode() == TRUE)
209 __connman_profile_set_offlinemode(FALSE, FALSE);
211 __connman_technology_enable_device(device);
216 int __connman_device_disable(struct connman_device *device)
220 DBG("device %p", device);
222 if (!device->driver || !device->driver->disable)
225 if (device->powered == FALSE)
228 if (device->powered_pending == FALSE)
231 device->reconnect = FALSE;
233 clear_scan_trigger(device);
235 g_hash_table_remove_all(device->networks);
237 err = device->driver->disable(device);
239 if (err == -EINPROGRESS)
240 device->powered_pending = FALSE;
244 device->powered_pending = FALSE;
245 device->powered = FALSE;
247 __connman_technology_disable_device(device);
252 static int set_powered(struct connman_device *device, connman_bool_t powered)
254 DBG("device %p powered %d", device, powered);
257 return __connman_device_enable(device);
259 return __connman_device_disable(device);
262 static int setup_device(struct connman_device *device)
264 DBG("device %p", device);
266 __connman_technology_add_device(device);
268 if (device->offlinemode == FALSE &&
269 device->powered_persistent == TRUE)
270 __connman_device_enable(device);
275 static void probe_driver(struct connman_element *element, gpointer user_data)
277 struct connman_device_driver *driver = user_data;
279 DBG("element %p name %s", element, element->name);
281 if (element->device == NULL)
284 if (element->device->driver != NULL)
287 if (driver->type != element->device->type)
290 if (driver->probe(element->device) < 0)
293 element->device->driver = driver;
295 __connman_element_set_driver(element);
297 setup_device(element->device);
300 static void remove_device(struct connman_device *device)
302 DBG("device %p", device);
304 __connman_device_disable(device);
306 __connman_technology_remove_device(device);
308 if (device->driver->remove)
309 device->driver->remove(device);
311 device->driver = NULL;
314 static void remove_driver(struct connman_element *element, gpointer user_data)
316 struct connman_device_driver *driver = user_data;
318 DBG("element %p name %s", element, element->name);
320 if (element->device == NULL)
323 if (element->device->driver == driver)
324 remove_device(element->device);
327 connman_bool_t __connman_device_has_driver(struct connman_device *device)
329 if (device == NULL || device->driver == NULL)
335 static GSList *driver_list = NULL;
337 static gint compare_priority(gconstpointer a, gconstpointer b)
339 const struct connman_device_driver *driver1 = a;
340 const struct connman_device_driver *driver2 = b;
342 return driver2->priority - driver1->priority;
346 * connman_device_driver_register:
347 * @driver: device driver definition
349 * Register a new device driver
351 * Returns: %0 on success
353 int connman_device_driver_register(struct connman_device_driver *driver)
355 DBG("driver %p name %s", driver, driver->name);
357 driver_list = g_slist_insert_sorted(driver_list, driver,
360 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
361 probe_driver, driver);
367 * connman_device_driver_unregister:
368 * @driver: device driver definition
370 * Remove a previously registered device driver
372 void connman_device_driver_unregister(struct connman_device_driver *driver)
374 DBG("driver %p name %s", driver, driver->name);
376 driver_list = g_slist_remove(driver_list, driver);
378 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
379 remove_driver, driver);
382 static void unregister_network(gpointer data)
384 struct connman_network *network = data;
386 DBG("network %p", network);
388 connman_element_unregister((struct connman_element *) network);
390 __connman_network_set_device(network, NULL);
392 connman_network_unref(network);
395 static void device_destruct(struct connman_element *element)
397 struct connman_device *device = element->device;
399 DBG("element %p name %s", element, element->name);
401 clear_scan_trigger(device);
403 g_free(device->ident);
404 g_free(device->node);
405 g_free(device->name);
406 g_free(device->address);
407 g_free(device->interface);
409 g_free(device->last_network);
411 g_hash_table_destroy(device->networks);
412 device->networks = NULL;
416 * connman_device_create:
417 * @node: device node name (for example an address)
420 * Allocate a new device of given #type and assign the #node name to it.
422 * Returns: a newly-allocated #connman_device structure
424 struct connman_device *connman_device_create(const char *node,
425 enum connman_device_type type)
427 struct connman_device *device;
429 enum connman_service_type service_type;
431 DBG("node %s type %d", node, type);
433 device = g_try_new0(struct connman_device, 1);
437 DBG("device %p", device);
439 __connman_element_initialize(&device->element);
441 device->element.name = g_strdup(node);
442 device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
444 device->element.device = device;
445 device->element.destruct = device_destruct;
447 str = type2string(type);
449 connman_element_set_string(&device->element,
450 CONNMAN_PROPERTY_ID_TYPE, str);
452 device->element.ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
455 device->name = g_strdup(type2description(device->type));
457 device->powered_persistent = TRUE;
459 device->phyindex = -1;
461 service_type = __connman_device_get_service_type(device);
462 device->blocked = __connman_technology_get_blocked(service_type);
465 case CONNMAN_DEVICE_TYPE_UNKNOWN:
466 case CONNMAN_DEVICE_TYPE_VENDOR:
467 device->scan_interval = 0;
469 case CONNMAN_DEVICE_TYPE_ETHERNET:
470 case CONNMAN_DEVICE_TYPE_WIFI:
471 device->scan_interval = 300;
473 case CONNMAN_DEVICE_TYPE_WIMAX:
474 device->scan_interval = 0;
476 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
477 device->scan_interval = 0;
479 case CONNMAN_DEVICE_TYPE_GPS:
480 device->scan_interval = 0;
482 case CONNMAN_DEVICE_TYPE_CELLULAR:
483 device->scan_interval = 0;
487 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
488 g_free, unregister_network);
494 * connman_device_ref:
495 * @device: device structure
497 * Increase reference counter of device
499 struct connman_device *connman_device_ref(struct connman_device *device)
501 if (connman_element_ref(&device->element) == NULL)
508 * connman_device_unref:
509 * @device: device structure
511 * Decrease reference counter of device
513 void connman_device_unref(struct connman_device *device)
515 connman_element_unref(&device->element);
518 const char *__connman_device_get_type(struct connman_device *device)
520 return type2string(device->type);
524 * connman_device_get_type:
525 * @device: device structure
529 enum connman_device_type connman_device_get_type(struct connman_device *device)
535 * connman_device_set_index:
536 * @device: device structure
537 * @index: index number
539 * Set index number of device
541 void connman_device_set_index(struct connman_device *device, int index)
543 device->element.index = index;
547 * connman_device_get_index:
548 * @device: device structure
550 * Get index number of device
552 int connman_device_get_index(struct connman_device *device)
554 return device->element.index;
557 int __connman_device_get_phyindex(struct connman_device *device)
559 return device->phyindex;
562 void __connman_device_set_phyindex(struct connman_device *device,
565 device->phyindex = phyindex;
569 * connman_device_set_interface:
570 * @device: device structure
571 * @interface: interface name
573 * Set interface name of device
575 void connman_device_set_interface(struct connman_device *device,
576 const char *interface)
578 g_free(device->element.devname);
579 device->element.devname = g_strdup(interface);
581 g_free(device->interface);
582 device->interface = g_strdup(interface);
584 if (device->name == NULL) {
585 const char *str = type2description(device->type);
586 if (str != NULL && device->interface != NULL)
587 device->name = g_strdup_printf("%s (%s)", str,
593 * connman_device_set_ident:
594 * @device: device structure
595 * @ident: unique identifier
597 * Set unique identifier of device
599 void connman_device_set_ident(struct connman_device *device,
602 g_free(device->ident);
603 device->ident = g_strdup(ident);
606 const char *connman_device_get_ident(struct connman_device *device)
608 return device->ident;
612 * connman_device_set_powered:
613 * @device: device structure
614 * @powered: powered state
616 * Change power state of device
618 int connman_device_set_powered(struct connman_device *device,
619 connman_bool_t powered)
621 DBG("driver %p powered %d", device, powered);
623 if (device->powered == powered) {
624 device->powered_pending = powered;
629 __connman_device_enable(device);
631 __connman_device_disable(device);
633 device->powered = powered;
634 device->powered_pending = powered;
636 if (device->powered == TRUE)
637 __connman_technology_enable_device(device);
639 __connman_technology_disable_device(device);
641 if (device->offlinemode == TRUE && powered == TRUE)
642 return connman_device_set_powered(device, FALSE);
644 if (powered == FALSE)
647 reset_scan_trigger(device);
649 if (device->driver->scan)
650 device->driver->scan(device);
655 int __connman_device_set_blocked(struct connman_device *device,
656 connman_bool_t blocked)
658 connman_bool_t powered;
660 DBG("device %p blocked %d", device, blocked);
662 device->blocked = blocked;
664 if (device->offlinemode == TRUE)
667 connman_info("%s {rfkill} blocked %d", device->interface, blocked);
669 if (blocked == FALSE)
670 powered = device->powered_persistent;
674 return set_powered(device, powered);
677 connman_bool_t __connman_device_get_blocked(struct connman_device *device)
679 return device->blocked;
682 int __connman_device_scan(struct connman_device *device)
684 if (!device->driver || !device->driver->scan)
687 if (device->powered == FALSE)
690 reset_scan_trigger(device);
692 return device->driver->scan(device);
695 int __connman_device_enable_persistent(struct connman_device *device)
699 DBG("device %p", device);
701 device->powered_persistent = TRUE;
703 __connman_storage_save_device(device);
705 err = __connman_device_enable(device);
706 if (err == 0 || err == -EINPROGRESS) {
707 device->offlinemode = FALSE;
708 if (__connman_profile_get_offlinemode() == TRUE) {
709 __connman_profile_set_offlinemode(FALSE, FALSE);
711 __connman_profile_save_default();
718 int __connman_device_disable_persistent(struct connman_device *device)
720 DBG("device %p", device);
722 device->powered_persistent = FALSE;
724 __connman_storage_save_device(device);
726 return __connman_device_disable(device);
729 int __connman_device_disconnect(struct connman_device *device)
734 DBG("device %p", device);
736 connman_device_set_disconnected(device, TRUE);
738 g_hash_table_iter_init(&iter, device->networks);
740 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
741 struct connman_network *network = value;
743 if (__connman_network_get_connecting(network) == TRUE) {
745 * Skip network in the process of connecting.
746 * This is a workaround for WiFi networks serviced
747 * by the supplicant plugin that hold a reference
748 * to the network. If we disconnect the network
749 * here then the referenced object will not be
750 * registered and usage (like launching DHCP client)
751 * will fail. There is nothing to be gained by
752 * removing the network here anyway.
754 connman_warn("Skipping disconnect of %s",
755 connman_network_get_identifier(network));
759 __connman_network_disconnect(network);
765 static void mark_network_unavailable(gpointer key, gpointer value,
768 struct connman_network *network = value;
770 if (connman_network_get_connected(network) == TRUE)
773 connman_network_set_available(network, FALSE);
776 static gboolean remove_unavailable_network(gpointer key, gpointer value,
779 struct connman_network *network = value;
781 if (connman_network_get_connected(network) == TRUE)
784 if (connman_network_get_available(network) == TRUE)
790 void __connman_device_cleanup_networks(struct connman_device *device)
792 g_hash_table_foreach_remove(device->networks,
793 remove_unavailable_network, NULL);
797 * connman_device_set_scanning:
798 * @device: device structure
799 * @scanning: scanning state
801 * Change scanning state of device
803 int connman_device_set_scanning(struct connman_device *device,
804 connman_bool_t scanning)
806 DBG("device %p scanning %d", device, scanning);
808 if (!device->driver || !device->driver->scan)
811 if (device->scanning == scanning)
814 device->scanning = scanning;
816 if (scanning == TRUE) {
817 reset_scan_trigger(device);
819 g_hash_table_foreach(device->networks,
820 mark_network_unavailable, NULL);
825 __connman_device_cleanup_networks(device);
827 if (device->connections > 0)
830 if (device->disconnected == TRUE)
833 __connman_service_auto_connect();
839 * connman_device_set_disconnected:
840 * @device: device structure
841 * @disconnected: disconnected state
843 * Change disconnected state of device (only for device with networks)
845 int connman_device_set_disconnected(struct connman_device *device,
846 connman_bool_t disconnected)
848 DBG("device %p disconnected %d", device, disconnected);
850 if (device->disconnected == disconnected)
853 device->disconnected = disconnected;
855 if (disconnected == TRUE)
856 force_scan_trigger(device);
862 * connman_device_get_disconnected:
863 * @device: device structure
865 * Get device disconnected state
867 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
869 return device->disconnected;
873 * connman_device_set_string:
874 * @device: device structure
875 * @key: unique identifier
876 * @value: string value
878 * Set string value for specific key
880 int connman_device_set_string(struct connman_device *device,
881 const char *key, const char *value)
883 DBG("device %p key %s value %s", device, key, value);
885 if (g_str_equal(key, "Address") == TRUE) {
886 g_free(device->address);
887 device->address = g_strdup(value);
888 } else if (g_str_equal(key, "Name") == TRUE) {
889 g_free(device->name);
890 device->name = g_strdup(value);
891 } else if (g_str_equal(key, "Node") == TRUE) {
892 g_free(device->node);
893 device->node = g_strdup(value);
896 return connman_element_set_string(&device->element, key, value);
900 * connman_device_get_string:
901 * @device: device structure
902 * @key: unique identifier
904 * Get string value for specific key
906 const char *connman_device_get_string(struct connman_device *device,
909 DBG("device %p key %s", device, key);
911 if (g_str_equal(key, "Address") == TRUE)
912 return device->address;
913 else if (g_str_equal(key, "Name") == TRUE)
915 else if (g_str_equal(key, "Node") == TRUE)
917 else if (g_str_equal(key, "Interface") == TRUE)
918 return device->interface;
920 return connman_element_get_string(&device->element, key);
923 static void set_offlinemode(struct connman_element *element, gpointer user_data)
925 struct connman_device *device = element->device;
926 connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
927 connman_bool_t powered;
929 DBG("element %p name %s", element, element->name);
934 device->offlinemode = offlinemode;
936 if (device->blocked == TRUE)
939 powered = (offlinemode == TRUE) ? FALSE : TRUE;
941 if (device->powered == powered)
944 if (device->powered_persistent == FALSE)
947 set_powered(device, powered);
950 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
952 DBG("offlinmode %d", offlinemode);
954 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
955 set_offlinemode, GUINT_TO_POINTER(offlinemode));
957 __connman_notifier_offlinemode(offlinemode);
962 void __connman_device_increase_connections(struct connman_device *device)
967 device->connections++;
970 void __connman_device_decrease_connections(struct connman_device *device)
975 device->connections--;
979 * connman_device_add_network:
980 * @device: device structure
981 * @network: network structure
983 * Add new network to the device
985 int connman_device_add_network(struct connman_device *device,
986 struct connman_network *network)
988 const char *identifier = connman_network_get_identifier(network);
991 DBG("device %p network %p", device, network);
993 if (identifier == NULL)
996 __connman_network_set_device(network, device);
998 err = connman_element_register((struct connman_element *) network,
1001 __connman_network_set_device(network, NULL);
1005 g_hash_table_insert(device->networks, g_strdup(identifier),
1012 * connman_device_get_network:
1013 * @device: device structure
1014 * @identifier: network identifier
1016 * Get network for given identifier
1018 struct connman_network *connman_device_get_network(struct connman_device *device,
1019 const char *identifier)
1021 DBG("device %p identifier %s", device, identifier);
1023 return g_hash_table_lookup(device->networks, identifier);
1027 * connman_device_remove_network:
1028 * @device: device structure
1029 * @identifier: network identifier
1031 * Remove network for given identifier
1033 int connman_device_remove_network(struct connman_device *device,
1034 const char *identifier)
1036 DBG("device %p identifier %s", device, identifier);
1038 g_hash_table_remove(device->networks, identifier);
1043 void connman_device_remove_all_networks(struct connman_device *device)
1045 g_hash_table_remove_all(device->networks);
1048 void __connman_device_set_network(struct connman_device *device,
1049 struct connman_network *network)
1056 if (device->network == network)
1059 if (device->network != NULL)
1060 connman_network_unref(device->network);
1062 if (network != NULL) {
1063 name = connman_network_get_string(network,
1064 CONNMAN_PROPERTY_ID_NAME);
1065 g_free(device->last_network);
1066 device->last_network = g_strdup(name);
1068 device->network = connman_network_ref(network);
1070 g_free(device->last_network);
1071 device->last_network = NULL;
1073 device->network = NULL;
1077 void __connman_device_set_reconnect(struct connman_device *device,
1078 connman_bool_t reconnect)
1080 device->reconnect = reconnect;
1083 connman_bool_t __connman_device_get_reconnect(
1084 struct connman_device *device)
1086 return device->reconnect;
1090 * connman_device_register:
1091 * @device: device structure
1093 * Register device with the system
1095 int connman_device_register(struct connman_device *device)
1097 __connman_storage_load_device(device);
1099 device->offlinemode = __connman_profile_get_offlinemode();
1101 return connman_element_register(&device->element, NULL);
1105 * connman_device_unregister:
1106 * @device: device structure
1108 * Unregister device with the system
1110 void connman_device_unregister(struct connman_device *device)
1112 __connman_storage_save_device(device);
1114 connman_element_unregister(&device->element);
1118 * connman_device_get_data:
1119 * @device: device structure
1121 * Get private device data pointer
1123 void *connman_device_get_data(struct connman_device *device)
1125 return device->driver_data;
1129 * connman_device_set_data:
1130 * @device: device structure
1131 * @data: data pointer
1133 * Set private device data pointer
1135 void connman_device_set_data(struct connman_device *device, void *data)
1137 device->driver_data = data;
1140 static gboolean match_driver(struct connman_device *device,
1141 struct connman_device_driver *driver)
1143 if (device->type == driver->type ||
1144 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1150 static int device_probe(struct connman_element *element)
1152 struct connman_device *device = element->device;
1155 DBG("element %p name %s", element, element->name);
1160 if (device->driver != NULL)
1163 for (list = driver_list; list; list = list->next) {
1164 struct connman_device_driver *driver = list->data;
1166 if (match_driver(device, driver) == FALSE)
1169 DBG("driver %p name %s", driver, driver->name);
1171 if (driver->probe(device) == 0) {
1172 device->driver = driver;
1177 if (device->driver == NULL)
1180 return setup_device(device);
1183 static void device_remove(struct connman_element *element)
1185 struct connman_device *device = element->device;
1187 DBG("element %p name %s", element, element->name);
1192 if (device->driver == NULL)
1195 remove_device(device);
1198 static struct connman_driver device_driver = {
1200 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
1201 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1202 .probe = device_probe,
1203 .remove = device_remove,
1206 static int device_load(struct connman_device *device)
1208 const char *ident = __connman_profile_active_ident();
1210 GError *error = NULL;
1212 connman_bool_t powered;
1215 DBG("device %p", device);
1217 keyfile = __connman_storage_open_profile(ident);
1218 if (keyfile == NULL)
1221 identifier = g_strdup_printf("device_%s", device->element.name);
1222 if (identifier == NULL)
1225 powered = g_key_file_get_boolean(keyfile, identifier,
1228 device->powered_persistent = powered;
1229 g_clear_error(&error);
1231 val = g_key_file_get_integer(keyfile, identifier,
1232 "ScanInterval", &error);
1234 device->scan_interval = val;
1235 g_clear_error(&error);
1240 __connman_storage_close_profile(ident, keyfile, FALSE);
1245 static int device_save(struct connman_device *device)
1247 const char *ident = __connman_profile_active_ident();
1251 DBG("device %p", device);
1253 keyfile = __connman_storage_open_profile(ident);
1254 if (keyfile == NULL)
1257 identifier = g_strdup_printf("device_%s", device->element.name);
1258 if (identifier == NULL)
1261 g_key_file_set_boolean(keyfile, identifier,
1262 "Powered", device->powered_persistent);
1264 g_key_file_set_integer(keyfile, identifier,
1265 "ScanInterval", device->scan_interval);
1270 __connman_storage_close_profile(ident, keyfile, TRUE);
1275 static struct connman_storage device_storage = {
1277 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
1278 .device_load = device_load,
1279 .device_save = device_save,
1282 int __connman_device_init(void)
1286 if (connman_storage_register(&device_storage) < 0)
1287 connman_error("Failed to register device storage");
1289 return connman_driver_register(&device_driver);
1292 void __connman_device_cleanup(void)
1296 connman_driver_unregister(&device_driver);
1298 connman_storage_unregister(&device_storage);