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);
195 if (err < 0 && err != -EALREADY) {
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);
238 if (err < 0 && err != -EALREADY) {
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)
623 DBG("driver %p powered %d", device, powered);
625 if (device->powered == powered) {
626 device->powered_pending = powered;
631 err = __connman_device_enable(device);
633 err = __connman_device_disable(device);
635 if (err < 0 && err != -EINPROGRESS)
638 device->powered = powered;
639 device->powered_pending = powered;
641 if (device->powered == TRUE)
642 __connman_technology_enable_device(device);
644 __connman_technology_disable_device(device);
646 if (device->offlinemode == TRUE && powered == TRUE)
647 return connman_device_set_powered(device, FALSE);
649 if (powered == FALSE)
652 reset_scan_trigger(device);
654 if (device->driver && device->driver->scan)
655 device->driver->scan(device);
660 int __connman_device_set_blocked(struct connman_device *device,
661 connman_bool_t blocked)
663 connman_bool_t powered;
665 DBG("device %p blocked %d", device, blocked);
667 device->blocked = blocked;
669 if (device->offlinemode == TRUE)
672 connman_info("%s {rfkill} blocked %d", device->interface, blocked);
674 if (blocked == FALSE)
675 powered = device->powered_persistent;
679 return set_powered(device, powered);
682 connman_bool_t __connman_device_get_blocked(struct connman_device *device)
684 return device->blocked;
687 int __connman_device_scan(struct connman_device *device)
689 if (!device->driver || !device->driver->scan)
692 if (device->powered == FALSE)
695 reset_scan_trigger(device);
697 return device->driver->scan(device);
700 int __connman_device_enable_persistent(struct connman_device *device)
704 DBG("device %p", device);
706 device->powered_persistent = TRUE;
708 __connman_storage_save_device(device);
710 err = __connman_device_enable(device);
711 if (err == 0 || err == -EINPROGRESS) {
712 device->offlinemode = FALSE;
713 if (__connman_profile_get_offlinemode() == TRUE) {
714 __connman_profile_set_offlinemode(FALSE, FALSE);
716 __connman_profile_save_default();
723 int __connman_device_disable_persistent(struct connman_device *device)
725 DBG("device %p", device);
727 device->powered_persistent = FALSE;
729 __connman_storage_save_device(device);
731 return __connman_device_disable(device);
734 int __connman_device_disconnect(struct connman_device *device)
739 DBG("device %p", device);
741 connman_device_set_disconnected(device, TRUE);
743 g_hash_table_iter_init(&iter, device->networks);
745 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
746 struct connman_network *network = value;
748 if (__connman_network_get_connecting(network) == TRUE) {
750 * Skip network in the process of connecting.
751 * This is a workaround for WiFi networks serviced
752 * by the supplicant plugin that hold a reference
753 * to the network. If we disconnect the network
754 * here then the referenced object will not be
755 * registered and usage (like launching DHCP client)
756 * will fail. There is nothing to be gained by
757 * removing the network here anyway.
759 connman_warn("Skipping disconnect of %s",
760 connman_network_get_identifier(network));
764 __connman_network_disconnect(network);
770 static void mark_network_unavailable(gpointer key, gpointer value,
773 struct connman_network *network = value;
775 if (connman_network_get_connected(network) == TRUE)
778 connman_network_set_available(network, FALSE);
781 static gboolean remove_unavailable_network(gpointer key, gpointer value,
784 struct connman_network *network = value;
786 if (connman_network_get_connected(network) == TRUE)
789 if (connman_network_get_available(network) == TRUE)
795 void __connman_device_cleanup_networks(struct connman_device *device)
797 g_hash_table_foreach_remove(device->networks,
798 remove_unavailable_network, NULL);
802 * connman_device_set_scanning:
803 * @device: device structure
804 * @scanning: scanning state
806 * Change scanning state of device
808 int connman_device_set_scanning(struct connman_device *device,
809 connman_bool_t scanning)
811 DBG("device %p scanning %d", device, scanning);
813 if (!device->driver || !device->driver->scan)
816 if (device->scanning == scanning)
819 device->scanning = scanning;
821 if (scanning == TRUE) {
822 reset_scan_trigger(device);
824 g_hash_table_foreach(device->networks,
825 mark_network_unavailable, NULL);
830 __connman_device_cleanup_networks(device);
832 if (device->connections > 0)
835 if (device->disconnected == TRUE)
838 __connman_service_auto_connect();
844 * connman_device_set_disconnected:
845 * @device: device structure
846 * @disconnected: disconnected state
848 * Change disconnected state of device (only for device with networks)
850 int connman_device_set_disconnected(struct connman_device *device,
851 connman_bool_t disconnected)
853 DBG("device %p disconnected %d", device, disconnected);
855 if (device->disconnected == disconnected)
858 device->disconnected = disconnected;
860 if (disconnected == TRUE)
861 force_scan_trigger(device);
867 * connman_device_get_disconnected:
868 * @device: device structure
870 * Get device disconnected state
872 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
874 return device->disconnected;
878 * connman_device_set_string:
879 * @device: device structure
880 * @key: unique identifier
881 * @value: string value
883 * Set string value for specific key
885 int connman_device_set_string(struct connman_device *device,
886 const char *key, const char *value)
888 DBG("device %p key %s value %s", device, key, value);
890 if (g_str_equal(key, "Address") == TRUE) {
891 g_free(device->address);
892 device->address = g_strdup(value);
893 } else if (g_str_equal(key, "Name") == TRUE) {
894 g_free(device->name);
895 device->name = g_strdup(value);
896 } else if (g_str_equal(key, "Node") == TRUE) {
897 g_free(device->node);
898 device->node = g_strdup(value);
901 return connman_element_set_string(&device->element, key, value);
905 * connman_device_get_string:
906 * @device: device structure
907 * @key: unique identifier
909 * Get string value for specific key
911 const char *connman_device_get_string(struct connman_device *device,
914 DBG("device %p key %s", device, key);
916 if (g_str_equal(key, "Address") == TRUE)
917 return device->address;
918 else if (g_str_equal(key, "Name") == TRUE)
920 else if (g_str_equal(key, "Node") == TRUE)
922 else if (g_str_equal(key, "Interface") == TRUE)
923 return device->interface;
925 return connman_element_get_string(&device->element, key);
928 static void set_offlinemode(struct connman_element *element, gpointer user_data)
930 struct connman_device *device = element->device;
931 connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
932 connman_bool_t powered;
934 DBG("element %p name %s", element, element->name);
939 device->offlinemode = offlinemode;
941 if (device->blocked == TRUE)
944 powered = (offlinemode == TRUE) ? FALSE : TRUE;
946 if (device->powered == powered)
949 if (device->powered_persistent == FALSE)
952 set_powered(device, powered);
955 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
957 DBG("offlinmode %d", offlinemode);
959 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
960 set_offlinemode, GUINT_TO_POINTER(offlinemode));
962 __connman_notifier_offlinemode(offlinemode);
967 void __connman_device_increase_connections(struct connman_device *device)
972 device->connections++;
975 void __connman_device_decrease_connections(struct connman_device *device)
980 device->connections--;
984 * connman_device_add_network:
985 * @device: device structure
986 * @network: network structure
988 * Add new network to the device
990 int connman_device_add_network(struct connman_device *device,
991 struct connman_network *network)
993 const char *identifier = connman_network_get_identifier(network);
996 DBG("device %p network %p", device, network);
998 if (identifier == NULL)
1001 __connman_network_set_device(network, device);
1003 err = connman_element_register((struct connman_element *) network,
1006 __connman_network_set_device(network, NULL);
1010 g_hash_table_insert(device->networks, g_strdup(identifier),
1017 * connman_device_get_network:
1018 * @device: device structure
1019 * @identifier: network identifier
1021 * Get network for given identifier
1023 struct connman_network *connman_device_get_network(struct connman_device *device,
1024 const char *identifier)
1026 DBG("device %p identifier %s", device, identifier);
1028 return g_hash_table_lookup(device->networks, identifier);
1032 * connman_device_remove_network:
1033 * @device: device structure
1034 * @identifier: network identifier
1036 * Remove network for given identifier
1038 int connman_device_remove_network(struct connman_device *device,
1039 const char *identifier)
1041 DBG("device %p identifier %s", device, identifier);
1043 g_hash_table_remove(device->networks, identifier);
1048 void connman_device_remove_all_networks(struct connman_device *device)
1050 g_hash_table_remove_all(device->networks);
1053 void __connman_device_set_network(struct connman_device *device,
1054 struct connman_network *network)
1061 if (device->network == network)
1064 if (device->network != NULL)
1065 connman_network_unref(device->network);
1067 if (network != NULL) {
1068 name = connman_network_get_string(network,
1069 CONNMAN_PROPERTY_ID_NAME);
1070 g_free(device->last_network);
1071 device->last_network = g_strdup(name);
1073 device->network = connman_network_ref(network);
1075 g_free(device->last_network);
1076 device->last_network = NULL;
1078 device->network = NULL;
1082 void __connman_device_set_reconnect(struct connman_device *device,
1083 connman_bool_t reconnect)
1085 device->reconnect = reconnect;
1088 connman_bool_t __connman_device_get_reconnect(
1089 struct connman_device *device)
1091 return device->reconnect;
1095 * connman_device_register:
1096 * @device: device structure
1098 * Register device with the system
1100 int connman_device_register(struct connman_device *device)
1102 __connman_storage_load_device(device);
1104 device->offlinemode = __connman_profile_get_offlinemode();
1106 return connman_element_register(&device->element, NULL);
1110 * connman_device_unregister:
1111 * @device: device structure
1113 * Unregister device with the system
1115 void connman_device_unregister(struct connman_device *device)
1117 __connman_storage_save_device(device);
1119 connman_element_unregister(&device->element);
1123 * connman_device_get_data:
1124 * @device: device structure
1126 * Get private device data pointer
1128 void *connman_device_get_data(struct connman_device *device)
1130 return device->driver_data;
1134 * connman_device_set_data:
1135 * @device: device structure
1136 * @data: data pointer
1138 * Set private device data pointer
1140 void connman_device_set_data(struct connman_device *device, void *data)
1142 device->driver_data = data;
1145 static gboolean match_driver(struct connman_device *device,
1146 struct connman_device_driver *driver)
1148 if (device->type == driver->type ||
1149 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1155 static int device_probe(struct connman_element *element)
1157 struct connman_device *device = element->device;
1160 DBG("element %p name %s", element, element->name);
1165 if (device->driver != NULL)
1168 for (list = driver_list; list; list = list->next) {
1169 struct connman_device_driver *driver = list->data;
1171 if (match_driver(device, driver) == FALSE)
1174 DBG("driver %p name %s", driver, driver->name);
1176 if (driver->probe(device) == 0) {
1177 device->driver = driver;
1182 if (device->driver == NULL)
1185 return setup_device(device);
1188 static void device_remove(struct connman_element *element)
1190 struct connman_device *device = element->device;
1192 DBG("element %p name %s", element, element->name);
1197 if (device->driver == NULL)
1200 remove_device(device);
1203 static struct connman_driver device_driver = {
1205 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
1206 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1207 .probe = device_probe,
1208 .remove = device_remove,
1211 static int device_load(struct connman_device *device)
1213 const char *ident = __connman_profile_active_ident();
1215 GError *error = NULL;
1217 connman_bool_t powered;
1220 DBG("device %p", device);
1222 keyfile = __connman_storage_open_profile(ident);
1223 if (keyfile == NULL)
1226 identifier = g_strdup_printf("device_%s", device->element.name);
1227 if (identifier == NULL)
1230 powered = g_key_file_get_boolean(keyfile, identifier,
1233 device->powered_persistent = powered;
1234 g_clear_error(&error);
1236 val = g_key_file_get_integer(keyfile, identifier,
1237 "ScanInterval", &error);
1239 device->scan_interval = val;
1240 g_clear_error(&error);
1245 __connman_storage_close_profile(ident, keyfile, FALSE);
1250 static int device_save(struct connman_device *device)
1252 const char *ident = __connman_profile_active_ident();
1256 DBG("device %p", device);
1258 keyfile = __connman_storage_open_profile(ident);
1259 if (keyfile == NULL)
1262 identifier = g_strdup_printf("device_%s", device->element.name);
1263 if (identifier == NULL)
1266 g_key_file_set_boolean(keyfile, identifier,
1267 "Powered", device->powered_persistent);
1269 g_key_file_set_integer(keyfile, identifier,
1270 "ScanInterval", device->scan_interval);
1275 __connman_storage_close_profile(ident, keyfile, TRUE);
1280 static struct connman_storage device_storage = {
1282 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
1283 .device_load = device_load,
1284 .device_save = device_save,
1287 int __connman_device_init(void)
1291 if (connman_storage_register(&device_storage) < 0)
1292 connman_error("Failed to register device storage");
1294 return connman_driver_register(&device_driver);
1297 void __connman_device_cleanup(void)
1301 connman_driver_unregister(&device_driver);
1303 connman_storage_unregister(&device_storage);