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)
304 DBG("device %p", device);
306 err = __connman_device_disable(device);
307 if (err < 0 && err == -EINPROGRESS)
308 __connman_technology_disable_device(device);
310 __connman_technology_remove_device(device);
312 if (device->driver->remove)
313 device->driver->remove(device);
315 device->driver = NULL;
318 static void remove_driver(struct connman_element *element, gpointer user_data)
320 struct connman_device_driver *driver = user_data;
322 DBG("element %p name %s", element, element->name);
324 if (element->device == NULL)
327 if (element->device->driver == driver)
328 remove_device(element->device);
331 connman_bool_t __connman_device_has_driver(struct connman_device *device)
333 if (device == NULL || device->driver == NULL)
339 static GSList *driver_list = NULL;
341 static gint compare_priority(gconstpointer a, gconstpointer b)
343 const struct connman_device_driver *driver1 = a;
344 const struct connman_device_driver *driver2 = b;
346 return driver2->priority - driver1->priority;
350 * connman_device_driver_register:
351 * @driver: device driver definition
353 * Register a new device driver
355 * Returns: %0 on success
357 int connman_device_driver_register(struct connman_device_driver *driver)
359 DBG("driver %p name %s", driver, driver->name);
361 driver_list = g_slist_insert_sorted(driver_list, driver,
364 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
365 probe_driver, driver);
371 * connman_device_driver_unregister:
372 * @driver: device driver definition
374 * Remove a previously registered device driver
376 void connman_device_driver_unregister(struct connman_device_driver *driver)
378 DBG("driver %p name %s", driver, driver->name);
380 driver_list = g_slist_remove(driver_list, driver);
382 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
383 remove_driver, driver);
386 static void unregister_network(gpointer data)
388 struct connman_network *network = data;
390 DBG("network %p", network);
392 connman_element_unregister((struct connman_element *) network);
394 __connman_network_set_device(network, NULL);
396 connman_network_unref(network);
399 static void device_destruct(struct connman_element *element)
401 struct connman_device *device = element->device;
403 DBG("element %p name %s", element, element->name);
405 clear_scan_trigger(device);
407 g_free(device->ident);
408 g_free(device->node);
409 g_free(device->name);
410 g_free(device->address);
411 g_free(device->interface);
413 g_free(device->last_network);
415 g_hash_table_destroy(device->networks);
416 device->networks = NULL;
420 * connman_device_create:
421 * @node: device node name (for example an address)
424 * Allocate a new device of given #type and assign the #node name to it.
426 * Returns: a newly-allocated #connman_device structure
428 struct connman_device *connman_device_create(const char *node,
429 enum connman_device_type type)
431 struct connman_device *device;
433 enum connman_service_type service_type;
435 DBG("node %s type %d", node, type);
437 device = g_try_new0(struct connman_device, 1);
441 DBG("device %p", device);
443 __connman_element_initialize(&device->element);
445 device->element.name = g_strdup(node);
446 device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
448 device->element.device = device;
449 device->element.destruct = device_destruct;
451 str = type2string(type);
453 connman_element_set_string(&device->element,
454 CONNMAN_PROPERTY_ID_TYPE, str);
456 device->element.ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
459 device->name = g_strdup(type2description(device->type));
461 device->powered_persistent = TRUE;
463 device->phyindex = -1;
465 service_type = __connman_device_get_service_type(device);
466 device->blocked = __connman_technology_get_blocked(service_type);
469 case CONNMAN_DEVICE_TYPE_UNKNOWN:
470 case CONNMAN_DEVICE_TYPE_VENDOR:
471 device->scan_interval = 0;
473 case CONNMAN_DEVICE_TYPE_ETHERNET:
474 case CONNMAN_DEVICE_TYPE_WIFI:
475 device->scan_interval = 300;
477 case CONNMAN_DEVICE_TYPE_WIMAX:
478 device->scan_interval = 0;
480 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
481 device->scan_interval = 0;
483 case CONNMAN_DEVICE_TYPE_GPS:
484 device->scan_interval = 0;
486 case CONNMAN_DEVICE_TYPE_CELLULAR:
487 device->scan_interval = 0;
491 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
492 g_free, unregister_network);
498 * connman_device_ref:
499 * @device: device structure
501 * Increase reference counter of device
503 struct connman_device *connman_device_ref(struct connman_device *device)
505 if (connman_element_ref(&device->element) == NULL)
512 * connman_device_unref:
513 * @device: device structure
515 * Decrease reference counter of device
517 void connman_device_unref(struct connman_device *device)
519 connman_element_unref(&device->element);
522 const char *__connman_device_get_type(struct connman_device *device)
524 return type2string(device->type);
528 * connman_device_get_type:
529 * @device: device structure
533 enum connman_device_type connman_device_get_type(struct connman_device *device)
539 * connman_device_set_index:
540 * @device: device structure
541 * @index: index number
543 * Set index number of device
545 void connman_device_set_index(struct connman_device *device, int index)
547 device->element.index = index;
551 * connman_device_get_index:
552 * @device: device structure
554 * Get index number of device
556 int connman_device_get_index(struct connman_device *device)
558 return device->element.index;
561 int __connman_device_get_phyindex(struct connman_device *device)
563 return device->phyindex;
566 void __connman_device_set_phyindex(struct connman_device *device,
569 device->phyindex = phyindex;
573 * connman_device_set_interface:
574 * @device: device structure
575 * @interface: interface name
577 * Set interface name of device
579 void connman_device_set_interface(struct connman_device *device,
580 const char *interface)
582 g_free(device->element.devname);
583 device->element.devname = g_strdup(interface);
585 g_free(device->interface);
586 device->interface = g_strdup(interface);
588 if (device->name == NULL) {
589 const char *str = type2description(device->type);
590 if (str != NULL && device->interface != NULL)
591 device->name = g_strdup_printf("%s (%s)", str,
597 * connman_device_set_ident:
598 * @device: device structure
599 * @ident: unique identifier
601 * Set unique identifier of device
603 void connman_device_set_ident(struct connman_device *device,
606 g_free(device->ident);
607 device->ident = g_strdup(ident);
610 const char *connman_device_get_ident(struct connman_device *device)
612 return device->ident;
616 * connman_device_set_powered:
617 * @device: device structure
618 * @powered: powered state
620 * Change power state of device
622 int connman_device_set_powered(struct connman_device *device,
623 connman_bool_t powered)
625 DBG("driver %p powered %d", device, powered);
627 if (device->powered == powered) {
628 device->powered_pending = powered;
633 __connman_device_enable(device);
635 __connman_device_disable(device);
637 device->powered = powered;
638 device->powered_pending = powered;
640 if (device->powered == TRUE)
641 __connman_technology_enable_device(device);
643 __connman_technology_disable_device(device);
645 if (device->offlinemode == TRUE && powered == TRUE)
646 return connman_device_set_powered(device, FALSE);
648 if (powered == FALSE)
651 reset_scan_trigger(device);
653 if (device->driver->scan)
654 device->driver->scan(device);
659 int __connman_device_set_blocked(struct connman_device *device,
660 connman_bool_t blocked)
662 connman_bool_t powered;
664 DBG("device %p blocked %d", device, blocked);
666 device->blocked = blocked;
668 if (device->offlinemode == TRUE)
671 connman_info("%s {rfkill} blocked %d", device->interface, blocked);
673 if (blocked == FALSE)
674 powered = device->powered_persistent;
678 return set_powered(device, powered);
681 connman_bool_t __connman_device_get_blocked(struct connman_device *device)
683 return device->blocked;
686 int __connman_device_scan(struct connman_device *device)
688 if (!device->driver || !device->driver->scan)
691 if (device->powered == FALSE)
694 reset_scan_trigger(device);
696 return device->driver->scan(device);
699 int __connman_device_enable_persistent(struct connman_device *device)
703 DBG("device %p", device);
705 device->powered_persistent = TRUE;
707 __connman_storage_save_device(device);
709 err = __connman_device_enable(device);
710 if (err == 0 || err == -EINPROGRESS) {
711 device->offlinemode = FALSE;
712 if (__connman_profile_get_offlinemode() == TRUE) {
713 __connman_profile_set_offlinemode(FALSE, FALSE);
715 __connman_profile_save_default();
722 int __connman_device_disable_persistent(struct connman_device *device)
724 DBG("device %p", device);
726 device->powered_persistent = FALSE;
728 __connman_storage_save_device(device);
730 return __connman_device_disable(device);
733 int __connman_device_disconnect(struct connman_device *device)
738 DBG("device %p", device);
740 connman_device_set_disconnected(device, TRUE);
742 g_hash_table_iter_init(&iter, device->networks);
744 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
745 struct connman_network *network = value;
747 if (__connman_network_get_connecting(network) == TRUE) {
749 * Skip network in the process of connecting.
750 * This is a workaround for WiFi networks serviced
751 * by the supplicant plugin that hold a reference
752 * to the network. If we disconnect the network
753 * here then the referenced object will not be
754 * registered and usage (like launching DHCP client)
755 * will fail. There is nothing to be gained by
756 * removing the network here anyway.
758 connman_warn("Skipping disconnect of %s",
759 connman_network_get_identifier(network));
763 __connman_network_disconnect(network);
769 static void mark_network_unavailable(gpointer key, gpointer value,
772 struct connman_network *network = value;
774 if (connman_network_get_connected(network) == TRUE)
777 connman_network_set_available(network, FALSE);
780 static gboolean remove_unavailable_network(gpointer key, gpointer value,
783 struct connman_network *network = value;
785 if (connman_network_get_connected(network) == TRUE)
788 if (connman_network_get_available(network) == TRUE)
794 void __connman_device_cleanup_networks(struct connman_device *device)
796 g_hash_table_foreach_remove(device->networks,
797 remove_unavailable_network, NULL);
801 * connman_device_set_scanning:
802 * @device: device structure
803 * @scanning: scanning state
805 * Change scanning state of device
807 int connman_device_set_scanning(struct connman_device *device,
808 connman_bool_t scanning)
810 DBG("device %p scanning %d", device, scanning);
812 if (!device->driver || !device->driver->scan)
815 if (device->scanning == scanning)
818 device->scanning = scanning;
820 if (scanning == TRUE) {
821 reset_scan_trigger(device);
823 g_hash_table_foreach(device->networks,
824 mark_network_unavailable, NULL);
829 __connman_device_cleanup_networks(device);
831 if (device->connections > 0)
834 if (device->disconnected == TRUE)
837 __connman_service_auto_connect();
843 * connman_device_set_disconnected:
844 * @device: device structure
845 * @disconnected: disconnected state
847 * Change disconnected state of device (only for device with networks)
849 int connman_device_set_disconnected(struct connman_device *device,
850 connman_bool_t disconnected)
852 DBG("device %p disconnected %d", device, disconnected);
854 if (device->disconnected == disconnected)
857 device->disconnected = disconnected;
859 if (disconnected == TRUE)
860 force_scan_trigger(device);
866 * connman_device_get_disconnected:
867 * @device: device structure
869 * Get device disconnected state
871 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
873 return device->disconnected;
877 * connman_device_set_string:
878 * @device: device structure
879 * @key: unique identifier
880 * @value: string value
882 * Set string value for specific key
884 int connman_device_set_string(struct connman_device *device,
885 const char *key, const char *value)
887 DBG("device %p key %s value %s", device, key, value);
889 if (g_str_equal(key, "Address") == TRUE) {
890 g_free(device->address);
891 device->address = g_strdup(value);
892 } else if (g_str_equal(key, "Name") == TRUE) {
893 g_free(device->name);
894 device->name = g_strdup(value);
895 } else if (g_str_equal(key, "Node") == TRUE) {
896 g_free(device->node);
897 device->node = g_strdup(value);
900 return connman_element_set_string(&device->element, key, value);
904 * connman_device_get_string:
905 * @device: device structure
906 * @key: unique identifier
908 * Get string value for specific key
910 const char *connman_device_get_string(struct connman_device *device,
913 DBG("device %p key %s", device, key);
915 if (g_str_equal(key, "Address") == TRUE)
916 return device->address;
917 else if (g_str_equal(key, "Name") == TRUE)
919 else if (g_str_equal(key, "Node") == TRUE)
921 else if (g_str_equal(key, "Interface") == TRUE)
922 return device->interface;
924 return connman_element_get_string(&device->element, key);
927 static void set_offlinemode(struct connman_element *element, gpointer user_data)
929 struct connman_device *device = element->device;
930 connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
931 connman_bool_t powered;
933 DBG("element %p name %s", element, element->name);
938 device->offlinemode = offlinemode;
940 if (device->blocked == TRUE)
943 powered = (offlinemode == TRUE) ? FALSE : TRUE;
945 if (device->powered == powered)
948 if (device->powered_persistent == FALSE)
951 set_powered(device, powered);
954 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
956 DBG("offlinmode %d", offlinemode);
958 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
959 set_offlinemode, GUINT_TO_POINTER(offlinemode));
961 __connman_notifier_offlinemode(offlinemode);
966 void __connman_device_increase_connections(struct connman_device *device)
971 device->connections++;
974 void __connman_device_decrease_connections(struct connman_device *device)
979 device->connections--;
983 * connman_device_add_network:
984 * @device: device structure
985 * @network: network structure
987 * Add new network to the device
989 int connman_device_add_network(struct connman_device *device,
990 struct connman_network *network)
992 const char *identifier = connman_network_get_identifier(network);
995 DBG("device %p network %p", device, network);
997 if (identifier == NULL)
1000 __connman_network_set_device(network, device);
1002 err = connman_element_register((struct connman_element *) network,
1005 __connman_network_set_device(network, NULL);
1009 g_hash_table_insert(device->networks, g_strdup(identifier),
1016 * connman_device_get_network:
1017 * @device: device structure
1018 * @identifier: network identifier
1020 * Get network for given identifier
1022 struct connman_network *connman_device_get_network(struct connman_device *device,
1023 const char *identifier)
1025 DBG("device %p identifier %s", device, identifier);
1027 return g_hash_table_lookup(device->networks, identifier);
1031 * connman_device_remove_network:
1032 * @device: device structure
1033 * @identifier: network identifier
1035 * Remove network for given identifier
1037 int connman_device_remove_network(struct connman_device *device,
1038 const char *identifier)
1040 DBG("device %p identifier %s", device, identifier);
1042 g_hash_table_remove(device->networks, identifier);
1047 void connman_device_remove_all_networks(struct connman_device *device)
1049 g_hash_table_remove_all(device->networks);
1052 void __connman_device_set_network(struct connman_device *device,
1053 struct connman_network *network)
1060 if (device->network == network)
1063 if (device->network != NULL)
1064 connman_network_unref(device->network);
1066 if (network != NULL) {
1067 name = connman_network_get_string(network,
1068 CONNMAN_PROPERTY_ID_NAME);
1069 g_free(device->last_network);
1070 device->last_network = g_strdup(name);
1072 device->network = connman_network_ref(network);
1074 g_free(device->last_network);
1075 device->last_network = NULL;
1077 device->network = NULL;
1081 void __connman_device_set_reconnect(struct connman_device *device,
1082 connman_bool_t reconnect)
1084 device->reconnect = reconnect;
1087 connman_bool_t __connman_device_get_reconnect(
1088 struct connman_device *device)
1090 return device->reconnect;
1094 * connman_device_register:
1095 * @device: device structure
1097 * Register device with the system
1099 int connman_device_register(struct connman_device *device)
1101 __connman_storage_load_device(device);
1103 device->offlinemode = __connman_profile_get_offlinemode();
1105 return connman_element_register(&device->element, NULL);
1109 * connman_device_unregister:
1110 * @device: device structure
1112 * Unregister device with the system
1114 void connman_device_unregister(struct connman_device *device)
1116 __connman_storage_save_device(device);
1118 connman_element_unregister(&device->element);
1122 * connman_device_get_data:
1123 * @device: device structure
1125 * Get private device data pointer
1127 void *connman_device_get_data(struct connman_device *device)
1129 return device->driver_data;
1133 * connman_device_set_data:
1134 * @device: device structure
1135 * @data: data pointer
1137 * Set private device data pointer
1139 void connman_device_set_data(struct connman_device *device, void *data)
1141 device->driver_data = data;
1144 static gboolean match_driver(struct connman_device *device,
1145 struct connman_device_driver *driver)
1147 if (device->type == driver->type ||
1148 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1154 static int device_probe(struct connman_element *element)
1156 struct connman_device *device = element->device;
1159 DBG("element %p name %s", element, element->name);
1164 if (device->driver != NULL)
1167 for (list = driver_list; list; list = list->next) {
1168 struct connman_device_driver *driver = list->data;
1170 if (match_driver(device, driver) == FALSE)
1173 DBG("driver %p name %s", driver, driver->name);
1175 if (driver->probe(device) == 0) {
1176 device->driver = driver;
1181 if (device->driver == NULL)
1184 return setup_device(device);
1187 static void device_remove(struct connman_element *element)
1189 struct connman_device *device = element->device;
1191 DBG("element %p name %s", element, element->name);
1196 if (device->driver == NULL)
1199 remove_device(device);
1202 static struct connman_driver device_driver = {
1204 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
1205 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1206 .probe = device_probe,
1207 .remove = device_remove,
1210 static int device_load(struct connman_device *device)
1212 const char *ident = __connman_profile_active_ident();
1214 GError *error = NULL;
1216 connman_bool_t powered;
1219 DBG("device %p", device);
1221 keyfile = __connman_storage_open_profile(ident);
1222 if (keyfile == NULL)
1225 identifier = g_strdup_printf("device_%s", device->element.name);
1226 if (identifier == NULL)
1229 powered = g_key_file_get_boolean(keyfile, identifier,
1232 device->powered_persistent = powered;
1233 g_clear_error(&error);
1235 val = g_key_file_get_integer(keyfile, identifier,
1236 "ScanInterval", &error);
1238 device->scan_interval = val;
1239 g_clear_error(&error);
1244 __connman_storage_close_profile(ident, keyfile, FALSE);
1249 static int device_save(struct connman_device *device)
1251 const char *ident = __connman_profile_active_ident();
1255 DBG("device %p", device);
1257 keyfile = __connman_storage_open_profile(ident);
1258 if (keyfile == NULL)
1261 identifier = g_strdup_printf("device_%s", device->element.name);
1262 if (identifier == NULL)
1265 g_key_file_set_boolean(keyfile, identifier,
1266 "Powered", device->powered_persistent);
1268 g_key_file_set_integer(keyfile, identifier,
1269 "ScanInterval", device->scan_interval);
1274 __connman_storage_close_profile(ident, keyfile, TRUE);
1279 static struct connman_storage device_storage = {
1281 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
1282 .device_load = device_load,
1283 .device_save = device_save,
1286 int __connman_device_init(void)
1290 if (connman_storage_register(&device_storage) < 0)
1291 connman_error("Failed to register device storage");
1293 return connman_driver_register(&device_driver);
1296 void __connman_device_cleanup(void)
1300 connman_driver_unregister(&device_driver);
1302 connman_storage_unregister(&device_storage);