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;
50 unsigned int connections;
53 struct connman_device_driver *driver;
57 struct connman_network *network;
61 static gboolean device_scan_trigger(gpointer user_data)
63 struct connman_device *device = user_data;
65 DBG("device %p", device);
67 if (device->driver == NULL) {
68 device->scan_timeout = 0;
72 if (device->driver->scan)
73 device->driver->scan(device);
78 static void clear_scan_trigger(struct connman_device *device)
80 if (device->scan_timeout > 0) {
81 g_source_remove(device->scan_timeout);
82 device->scan_timeout = 0;
86 static void reset_scan_trigger(struct connman_device *device)
88 clear_scan_trigger(device);
90 if (device->scan_interval > 0) {
91 guint interval = device->scan_interval;
92 device->scan_timeout = g_timeout_add_seconds(interval,
93 device_scan_trigger, device);
97 static void force_scan_trigger(struct connman_device *device)
99 clear_scan_trigger(device);
101 device->scan_timeout = g_timeout_add_seconds(5,
102 device_scan_trigger, device);
105 void connman_device_schedule_scan(struct connman_device *device)
107 reset_scan_trigger(device);
110 static const char *type2description(enum connman_device_type type)
113 case CONNMAN_DEVICE_TYPE_UNKNOWN:
114 case CONNMAN_DEVICE_TYPE_VENDOR:
116 case CONNMAN_DEVICE_TYPE_ETHERNET:
118 case CONNMAN_DEVICE_TYPE_WIFI:
120 case CONNMAN_DEVICE_TYPE_WIMAX:
122 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
124 case CONNMAN_DEVICE_TYPE_GPS:
126 case CONNMAN_DEVICE_TYPE_CELLULAR:
133 static const char *type2string(enum connman_device_type type)
136 case CONNMAN_DEVICE_TYPE_UNKNOWN:
137 case CONNMAN_DEVICE_TYPE_VENDOR:
139 case CONNMAN_DEVICE_TYPE_ETHERNET:
141 case CONNMAN_DEVICE_TYPE_WIFI:
143 case CONNMAN_DEVICE_TYPE_WIMAX:
145 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
147 case CONNMAN_DEVICE_TYPE_GPS:
149 case CONNMAN_DEVICE_TYPE_CELLULAR:
156 enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
158 enum connman_device_type type = connman_device_get_type(device);
161 case CONNMAN_DEVICE_TYPE_UNKNOWN:
162 case CONNMAN_DEVICE_TYPE_VENDOR:
163 case CONNMAN_DEVICE_TYPE_GPS:
165 case CONNMAN_DEVICE_TYPE_ETHERNET:
166 return CONNMAN_SERVICE_TYPE_ETHERNET;
167 case CONNMAN_DEVICE_TYPE_WIFI:
168 return CONNMAN_SERVICE_TYPE_WIFI;
169 case CONNMAN_DEVICE_TYPE_WIMAX:
170 return CONNMAN_SERVICE_TYPE_WIMAX;
171 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
172 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
173 case CONNMAN_DEVICE_TYPE_CELLULAR:
174 return CONNMAN_SERVICE_TYPE_CELLULAR;
177 return CONNMAN_SERVICE_TYPE_UNKNOWN;
180 int __connman_device_enable(struct connman_device *device)
184 DBG("device %p %d", device, device->blocked);
186 if (!device->driver || !device->driver->enable)
189 if (device->powered_pending == TRUE)
192 if (device->blocked == TRUE)
195 err = device->driver->enable(device);
197 if (err == -EINPROGRESS) {
198 device->powered_pending = TRUE;
199 device->offlinemode = FALSE;
200 if (__connman_profile_get_offlinemode() == TRUE)
201 __connman_profile_set_offlinemode(FALSE, FALSE);
206 device->powered_pending = TRUE;
207 device->powered = TRUE;
208 device->offlinemode = FALSE;
209 if (__connman_profile_get_offlinemode() == TRUE)
210 __connman_profile_set_offlinemode(FALSE, FALSE);
212 __connman_technology_enable_device(device);
217 int __connman_device_disable(struct connman_device *device)
221 DBG("device %p", device);
223 if (!device->driver || !device->driver->disable)
226 if (device->powered == FALSE)
229 if (device->powered_pending == FALSE)
232 device->reconnect = FALSE;
234 clear_scan_trigger(device);
236 g_hash_table_remove_all(device->networks);
238 err = device->driver->disable(device);
240 if (err == -EINPROGRESS)
241 device->powered_pending = FALSE;
245 device->powered_pending = FALSE;
246 device->powered = FALSE;
248 __connman_technology_disable_device(device);
253 static int set_powered(struct connman_device *device, connman_bool_t powered)
255 DBG("device %p powered %d", device, powered);
258 return __connman_device_enable(device);
260 return __connman_device_disable(device);
263 static int setup_device(struct connman_device *device)
265 DBG("device %p", device);
267 __connman_technology_add_device(device);
269 if (device->offlinemode == FALSE &&
270 device->powered_persistent == TRUE)
271 __connman_device_enable(device);
276 static void probe_driver(struct connman_element *element, gpointer user_data)
278 struct connman_device_driver *driver = user_data;
280 DBG("element %p name %s", element, element->name);
282 if (element->device == NULL)
285 if (element->device->driver != NULL)
288 if (driver->type != element->device->type)
291 if (driver->probe(element->device) < 0)
294 element->device->driver = driver;
296 __connman_element_set_driver(element);
298 setup_device(element->device);
301 static void remove_device(struct connman_device *device)
305 DBG("device %p", device);
307 err = __connman_device_disable(device);
308 if (err < 0 && err == -EINPROGRESS)
309 __connman_technology_disable_device(device);
311 __connman_technology_remove_device(device);
313 if (device->driver->remove)
314 device->driver->remove(device);
316 device->driver = NULL;
319 static void remove_driver(struct connman_element *element, gpointer user_data)
321 struct connman_device_driver *driver = user_data;
323 DBG("element %p name %s", element, element->name);
325 if (element->device == NULL)
328 if (element->device->driver == driver)
329 remove_device(element->device);
332 connman_bool_t __connman_device_has_driver(struct connman_device *device)
334 if (device == NULL || device->driver == NULL)
340 static GSList *driver_list = NULL;
342 static gint compare_priority(gconstpointer a, gconstpointer b)
344 const struct connman_device_driver *driver1 = a;
345 const struct connman_device_driver *driver2 = b;
347 return driver2->priority - driver1->priority;
351 * connman_device_driver_register:
352 * @driver: device driver definition
354 * Register a new device driver
356 * Returns: %0 on success
358 int connman_device_driver_register(struct connman_device_driver *driver)
360 DBG("driver %p name %s", driver, driver->name);
362 driver_list = g_slist_insert_sorted(driver_list, driver,
365 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
366 probe_driver, driver);
372 * connman_device_driver_unregister:
373 * @driver: device driver definition
375 * Remove a previously registered device driver
377 void connman_device_driver_unregister(struct connman_device_driver *driver)
379 DBG("driver %p name %s", driver, driver->name);
381 driver_list = g_slist_remove(driver_list, driver);
383 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
384 remove_driver, driver);
387 static void unregister_network(gpointer data)
389 struct connman_network *network = data;
391 DBG("network %p", network);
393 connman_element_unregister((struct connman_element *) network);
395 __connman_network_set_device(network, NULL);
397 connman_network_unref(network);
400 static void device_destruct(struct connman_element *element)
402 struct connman_device *device = element->device;
404 DBG("element %p name %s", element, element->name);
406 clear_scan_trigger(device);
408 g_free(device->ident);
409 g_free(device->node);
410 g_free(device->name);
411 g_free(device->address);
412 g_free(device->control);
413 g_free(device->interface);
415 g_free(device->last_network);
417 g_hash_table_destroy(device->networks);
418 device->networks = NULL;
422 * connman_device_create:
423 * @node: device node name (for example an address)
426 * Allocate a new device of given #type and assign the #node name to it.
428 * Returns: a newly-allocated #connman_device structure
430 struct connman_device *connman_device_create(const char *node,
431 enum connman_device_type type)
433 struct connman_device *device;
435 enum connman_service_type service_type;
437 DBG("node %s type %d", node, type);
439 device = g_try_new0(struct connman_device, 1);
443 DBG("device %p", device);
445 __connman_element_initialize(&device->element);
447 device->element.name = g_strdup(node);
448 device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
450 device->element.device = device;
451 device->element.destruct = device_destruct;
453 str = type2string(type);
455 connman_element_set_string(&device->element,
456 CONNMAN_PROPERTY_ID_TYPE, str);
458 device->element.ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
461 device->name = g_strdup(type2description(device->type));
463 device->powered_persistent = TRUE;
465 device->phyindex = -1;
467 service_type = __connman_device_get_service_type(device);
468 device->blocked = __connman_technology_get_blocked(service_type);
471 case CONNMAN_DEVICE_TYPE_UNKNOWN:
472 case CONNMAN_DEVICE_TYPE_VENDOR:
473 device->scan_interval = 0;
475 case CONNMAN_DEVICE_TYPE_ETHERNET:
476 case CONNMAN_DEVICE_TYPE_WIFI:
477 device->scan_interval = 300;
479 case CONNMAN_DEVICE_TYPE_WIMAX:
480 device->scan_interval = 0;
482 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
483 device->scan_interval = 0;
485 case CONNMAN_DEVICE_TYPE_GPS:
486 device->scan_interval = 0;
488 case CONNMAN_DEVICE_TYPE_CELLULAR:
489 device->scan_interval = 0;
493 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
494 g_free, unregister_network);
500 * connman_device_ref:
501 * @device: device structure
503 * Increase reference counter of device
505 struct connman_device *connman_device_ref(struct connman_device *device)
507 if (connman_element_ref(&device->element) == NULL)
514 * connman_device_unref:
515 * @device: device structure
517 * Decrease reference counter of device
519 void connman_device_unref(struct connman_device *device)
521 connman_element_unref(&device->element);
524 const char *__connman_device_get_type(struct connman_device *device)
526 return type2string(device->type);
530 * connman_device_get_type:
531 * @device: device structure
535 enum connman_device_type connman_device_get_type(struct connman_device *device)
541 * connman_device_set_index:
542 * @device: device structure
543 * @index: index number
545 * Set index number of device
547 void connman_device_set_index(struct connman_device *device, int index)
549 device->element.index = index;
553 * connman_device_get_index:
554 * @device: device structure
556 * Get index number of device
558 int connman_device_get_index(struct connman_device *device)
560 return device->element.index;
563 int __connman_device_get_phyindex(struct connman_device *device)
565 return device->phyindex;
568 void __connman_device_set_phyindex(struct connman_device *device,
571 device->phyindex = phyindex;
575 * connman_device_set_interface:
576 * @device: device structure
577 * @interface: interface name
578 * @control: control interface
580 * Set interface name of device
582 void connman_device_set_interface(struct connman_device *device,
583 const char *interface, const char *control)
585 g_free(device->element.devname);
586 device->element.devname = g_strdup(interface);
588 g_free(device->interface);
589 device->interface = g_strdup(interface);
591 g_free(device->control);
592 device->control = g_strdup(control);
594 if (device->name == NULL) {
595 const char *str = type2description(device->type);
596 if (str != NULL && device->interface != NULL)
597 device->name = g_strdup_printf("%s (%s)", str,
602 const char *connman_device_get_control(struct connman_device *device)
604 return device->control;
608 * connman_device_set_ident:
609 * @device: device structure
610 * @ident: unique identifier
612 * Set unique identifier of device
614 void connman_device_set_ident(struct connman_device *device,
617 g_free(device->ident);
618 device->ident = g_strdup(ident);
621 const char *connman_device_get_ident(struct connman_device *device)
623 return device->ident;
627 * connman_device_set_powered:
628 * @device: device structure
629 * @powered: powered state
631 * Change power state of device
633 int connman_device_set_powered(struct connman_device *device,
634 connman_bool_t powered)
636 DBG("driver %p powered %d", device, powered);
638 if (device->powered == powered) {
639 device->powered_pending = powered;
644 __connman_device_enable(device);
646 __connman_device_disable(device);
648 device->powered = powered;
649 device->powered_pending = powered;
651 if (device->powered == TRUE)
652 __connman_technology_enable_device(device);
654 __connman_technology_disable_device(device);
656 if (device->offlinemode == TRUE && powered == TRUE)
657 return connman_device_set_powered(device, FALSE);
659 if (powered == FALSE)
662 reset_scan_trigger(device);
664 if (device->driver->scan)
665 device->driver->scan(device);
670 int __connman_device_set_blocked(struct connman_device *device,
671 connman_bool_t blocked)
673 connman_bool_t powered;
675 DBG("device %p blocked %d", device, blocked);
677 device->blocked = blocked;
679 if (device->offlinemode == TRUE)
682 connman_info("%s {rfkill} blocked %d", device->interface, blocked);
684 if (blocked == FALSE)
685 powered = device->powered_persistent;
689 return set_powered(device, powered);
692 connman_bool_t __connman_device_get_blocked(struct connman_device *device)
694 return device->blocked;
697 int __connman_device_scan(struct connman_device *device)
699 if (!device->driver || !device->driver->scan)
702 if (device->powered == FALSE)
705 reset_scan_trigger(device);
707 return device->driver->scan(device);
710 int __connman_device_enable_persistent(struct connman_device *device)
714 DBG("device %p", device);
716 device->powered_persistent = TRUE;
718 __connman_storage_save_device(device);
720 err = __connman_device_enable(device);
721 if (err == 0 || err == -EINPROGRESS) {
722 device->offlinemode = FALSE;
723 if (__connman_profile_get_offlinemode() == TRUE) {
724 __connman_profile_set_offlinemode(FALSE, FALSE);
726 __connman_profile_save_default();
733 int __connman_device_disable_persistent(struct connman_device *device)
735 DBG("device %p", device);
737 device->powered_persistent = FALSE;
739 __connman_storage_save_device(device);
741 return __connman_device_disable(device);
744 int __connman_device_disconnect(struct connman_device *device)
749 DBG("device %p", device);
751 connman_device_set_disconnected(device, TRUE);
753 g_hash_table_iter_init(&iter, device->networks);
755 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
756 struct connman_network *network = value;
758 if (__connman_network_get_connecting(network) == TRUE) {
760 * Skip network in the process of connecting.
761 * This is a workaround for WiFi networks serviced
762 * by the supplicant plugin that hold a reference
763 * to the network. If we disconnect the network
764 * here then the referenced object will not be
765 * registered and usage (like launching DHCP client)
766 * will fail. There is nothing to be gained by
767 * removing the network here anyway.
769 connman_warn("Skipping disconnect of %s",
770 connman_network_get_identifier(network));
774 __connman_network_disconnect(network);
780 static void mark_network_unavailable(gpointer key, gpointer value,
783 struct connman_network *network = value;
785 if (connman_network_get_connected(network) == TRUE)
788 connman_network_set_available(network, FALSE);
791 static gboolean remove_unavailable_network(gpointer key, gpointer value,
794 struct connman_network *network = value;
796 if (connman_network_get_connected(network) == TRUE)
799 if (connman_network_get_available(network) == TRUE)
805 void __connman_device_cleanup_networks(struct connman_device *device)
807 g_hash_table_foreach_remove(device->networks,
808 remove_unavailable_network, NULL);
812 * connman_device_set_scanning:
813 * @device: device structure
814 * @scanning: scanning state
816 * Change scanning state of device
818 int connman_device_set_scanning(struct connman_device *device,
819 connman_bool_t scanning)
821 DBG("device %p scanning %d", device, scanning);
823 if (!device->driver || !device->driver->scan)
826 if (device->scanning == scanning)
829 device->scanning = scanning;
831 if (scanning == TRUE) {
832 reset_scan_trigger(device);
834 g_hash_table_foreach(device->networks,
835 mark_network_unavailable, NULL);
840 __connman_device_cleanup_networks(device);
842 if (device->connections > 0)
845 if (device->disconnected == TRUE)
848 __connman_service_auto_connect();
854 * connman_device_set_disconnected:
855 * @device: device structure
856 * @disconnected: disconnected state
858 * Change disconnected state of device (only for device with networks)
860 int connman_device_set_disconnected(struct connman_device *device,
861 connman_bool_t disconnected)
863 DBG("device %p disconnected %d", device, disconnected);
865 if (device->disconnected == disconnected)
868 device->disconnected = disconnected;
870 if (disconnected == TRUE)
871 force_scan_trigger(device);
877 * connman_device_get_disconnected:
878 * @device: device structure
880 * Get device disconnected state
882 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
884 return device->disconnected;
888 * connman_device_set_string:
889 * @device: device structure
890 * @key: unique identifier
891 * @value: string value
893 * Set string value for specific key
895 int connman_device_set_string(struct connman_device *device,
896 const char *key, const char *value)
898 DBG("device %p key %s value %s", device, key, value);
900 if (g_str_equal(key, "Address") == TRUE) {
901 g_free(device->address);
902 device->address = g_strdup(value);
903 } else if (g_str_equal(key, "Name") == TRUE) {
904 g_free(device->name);
905 device->name = g_strdup(value);
906 } else if (g_str_equal(key, "Node") == TRUE) {
907 g_free(device->node);
908 device->node = g_strdup(value);
911 return connman_element_set_string(&device->element, key, value);
915 * connman_device_get_string:
916 * @device: device structure
917 * @key: unique identifier
919 * Get string value for specific key
921 const char *connman_device_get_string(struct connman_device *device,
924 DBG("device %p key %s", device, key);
926 if (g_str_equal(key, "Address") == TRUE)
927 return device->address;
928 else if (g_str_equal(key, "Name") == TRUE)
930 else if (g_str_equal(key, "Node") == TRUE)
932 else if (g_str_equal(key, "Interface") == TRUE)
933 return device->interface;
935 return connman_element_get_string(&device->element, key);
938 static void set_offlinemode(struct connman_element *element, gpointer user_data)
940 struct connman_device *device = element->device;
941 connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
942 connman_bool_t powered;
944 DBG("element %p name %s", element, element->name);
949 device->offlinemode = offlinemode;
951 if (device->blocked == TRUE)
954 powered = (offlinemode == TRUE) ? FALSE : TRUE;
956 if (device->powered == powered)
959 if (device->powered_persistent == FALSE)
962 set_powered(device, powered);
965 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
967 DBG("offlinmode %d", offlinemode);
969 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
970 set_offlinemode, GUINT_TO_POINTER(offlinemode));
972 __connman_notifier_offlinemode(offlinemode);
977 void __connman_device_increase_connections(struct connman_device *device)
982 device->connections++;
985 void __connman_device_decrease_connections(struct connman_device *device)
990 device->connections--;
994 * connman_device_add_network:
995 * @device: device structure
996 * @network: network structure
998 * Add new network to the device
1000 int connman_device_add_network(struct connman_device *device,
1001 struct connman_network *network)
1003 const char *identifier = connman_network_get_identifier(network);
1006 DBG("device %p network %p", device, network);
1008 if (identifier == NULL)
1011 __connman_network_set_device(network, device);
1013 err = connman_element_register((struct connman_element *) network,
1016 __connman_network_set_device(network, NULL);
1020 g_hash_table_insert(device->networks, g_strdup(identifier),
1027 * connman_device_get_network:
1028 * @device: device structure
1029 * @identifier: network identifier
1031 * Get network for given identifier
1033 struct connman_network *connman_device_get_network(struct connman_device *device,
1034 const char *identifier)
1036 DBG("device %p identifier %s", device, identifier);
1038 return g_hash_table_lookup(device->networks, identifier);
1042 * connman_device_remove_network:
1043 * @device: device structure
1044 * @identifier: network identifier
1046 * Remove network for given identifier
1048 int connman_device_remove_network(struct connman_device *device,
1049 const char *identifier)
1051 DBG("device %p identifier %s", device, identifier);
1053 g_hash_table_remove(device->networks, identifier);
1058 void connman_device_remove_all_networks(struct connman_device *device)
1060 g_hash_table_remove_all(device->networks);
1063 void __connman_device_set_network(struct connman_device *device,
1064 struct connman_network *network)
1071 if (device->network == network)
1074 if (device->network != NULL)
1075 connman_network_unref(device->network);
1077 if (network != NULL) {
1078 name = connman_network_get_string(network,
1079 CONNMAN_PROPERTY_ID_NAME);
1080 g_free(device->last_network);
1081 device->last_network = g_strdup(name);
1083 device->network = connman_network_ref(network);
1085 g_free(device->last_network);
1086 device->last_network = NULL;
1088 device->network = NULL;
1092 void __connman_device_set_reconnect(struct connman_device *device,
1093 connman_bool_t reconnect)
1095 device->reconnect = reconnect;
1098 connman_bool_t __connman_device_get_reconnect(
1099 struct connman_device *device)
1101 return device->reconnect;
1105 * connman_device_register:
1106 * @device: device structure
1108 * Register device with the system
1110 int connman_device_register(struct connman_device *device)
1112 __connman_storage_load_device(device);
1114 device->offlinemode = __connman_profile_get_offlinemode();
1116 return connman_element_register(&device->element, NULL);
1120 * connman_device_unregister:
1121 * @device: device structure
1123 * Unregister device with the system
1125 void connman_device_unregister(struct connman_device *device)
1127 __connman_storage_save_device(device);
1129 connman_element_unregister(&device->element);
1133 * connman_device_get_data:
1134 * @device: device structure
1136 * Get private device data pointer
1138 void *connman_device_get_data(struct connman_device *device)
1140 return device->driver_data;
1144 * connman_device_set_data:
1145 * @device: device structure
1146 * @data: data pointer
1148 * Set private device data pointer
1150 void connman_device_set_data(struct connman_device *device, void *data)
1152 device->driver_data = data;
1155 static gboolean match_driver(struct connman_device *device,
1156 struct connman_device_driver *driver)
1158 if (device->type == driver->type ||
1159 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1165 static int device_probe(struct connman_element *element)
1167 struct connman_device *device = element->device;
1170 DBG("element %p name %s", element, element->name);
1175 if (device->driver != NULL)
1178 for (list = driver_list; list; list = list->next) {
1179 struct connman_device_driver *driver = list->data;
1181 if (match_driver(device, driver) == FALSE)
1184 DBG("driver %p name %s", driver, driver->name);
1186 if (driver->probe(device) == 0) {
1187 device->driver = driver;
1192 if (device->driver == NULL)
1195 return setup_device(device);
1198 static void device_remove(struct connman_element *element)
1200 struct connman_device *device = element->device;
1202 DBG("element %p name %s", element, element->name);
1207 if (device->driver == NULL)
1210 remove_device(device);
1213 static struct connman_driver device_driver = {
1215 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
1216 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1217 .probe = device_probe,
1218 .remove = device_remove,
1221 static int device_load(struct connman_device *device)
1223 const char *ident = __connman_profile_active_ident();
1225 GError *error = NULL;
1227 connman_bool_t powered;
1230 DBG("device %p", device);
1232 keyfile = __connman_storage_open_profile(ident);
1233 if (keyfile == NULL)
1236 identifier = g_strdup_printf("device_%s", device->element.name);
1237 if (identifier == NULL)
1240 powered = g_key_file_get_boolean(keyfile, identifier,
1243 device->powered_persistent = powered;
1244 g_clear_error(&error);
1246 val = g_key_file_get_integer(keyfile, identifier,
1247 "ScanInterval", &error);
1249 device->scan_interval = val;
1250 g_clear_error(&error);
1255 __connman_storage_close_profile(ident, keyfile, FALSE);
1260 static int device_save(struct connman_device *device)
1262 const char *ident = __connman_profile_active_ident();
1266 DBG("device %p", device);
1268 keyfile = __connman_storage_open_profile(ident);
1269 if (keyfile == NULL)
1272 identifier = g_strdup_printf("device_%s", device->element.name);
1273 if (identifier == NULL)
1276 g_key_file_set_boolean(keyfile, identifier,
1277 "Powered", device->powered_persistent);
1279 g_key_file_set_integer(keyfile, identifier,
1280 "ScanInterval", device->scan_interval);
1285 __connman_storage_close_profile(ident, keyfile, TRUE);
1290 static struct connman_storage device_storage = {
1292 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
1293 .device_load = device_load,
1294 .device_save = device_save,
1297 int __connman_device_init(void)
1301 if (connman_storage_register(&device_storage) < 0)
1302 connman_error("Failed to register device storage");
1304 return connman_driver_register(&device_driver);
1307 void __connman_device_cleanup(void)
1311 connman_driver_unregister(&device_driver);
1313 connman_storage_unregister(&device_storage);