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 static GSList *device_list = NULL;
32 static gchar **device_filter = NULL;
33 static gchar **nodevice_filter = NULL;
35 enum connman_pending_type {
41 struct connman_device {
43 enum connman_device_type type;
44 enum connman_pending_type powered_pending; /* Indicates a pending
45 enable/disable request */
46 connman_bool_t offlinemode;
47 connman_bool_t powered;
48 connman_bool_t powered_persistent;
49 connman_bool_t scanning;
50 connman_bool_t disconnected;
51 connman_bool_t reconnect;
52 connman_uint16_t scan_interval;
53 connman_uint16_t backoff_interval;
63 unsigned int connections;
65 guint pending_timeout;
67 struct connman_device_driver *driver;
71 struct connman_network *network;
75 #define SCAN_INITIAL_DELAY 10
77 static gboolean device_scan_trigger(gpointer user_data)
79 struct connman_device *device = user_data;
81 DBG("device %p", device);
83 if (device->driver == NULL) {
84 device->scan_timeout = 0;
88 if (device->driver->scan)
89 device->driver->scan(device);
94 static void clear_scan_trigger(struct connman_device *device)
96 if (device->scan_timeout > 0) {
97 g_source_remove(device->scan_timeout);
98 device->scan_timeout = 0;
102 static void reset_scan_trigger(struct connman_device *device)
104 clear_scan_trigger(device);
106 if (device->scan_interval > 0) {
109 if (g_hash_table_size(device->networks) == 0) {
110 if (device->backoff_interval >= device->scan_interval)
111 device->backoff_interval = SCAN_INITIAL_DELAY;
112 interval = device->backoff_interval;
114 interval = device->scan_interval;
116 DBG("interval %d", interval);
118 device->scan_timeout = g_timeout_add_seconds(interval,
119 device_scan_trigger, device);
121 device->backoff_interval *= 2;
122 if (device->backoff_interval > device->scan_interval)
123 device->backoff_interval = device->scan_interval;
127 static void force_scan_trigger(struct connman_device *device)
129 clear_scan_trigger(device);
131 device->scan_timeout = g_timeout_add_seconds(5,
132 device_scan_trigger, device);
135 void connman_device_schedule_scan(struct connman_device *device)
137 reset_scan_trigger(device);
140 static const char *type2description(enum connman_device_type type)
143 case CONNMAN_DEVICE_TYPE_UNKNOWN:
144 case CONNMAN_DEVICE_TYPE_VENDOR:
146 case CONNMAN_DEVICE_TYPE_ETHERNET:
148 case CONNMAN_DEVICE_TYPE_WIFI:
150 case CONNMAN_DEVICE_TYPE_WIMAX:
152 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
154 case CONNMAN_DEVICE_TYPE_GPS:
156 case CONNMAN_DEVICE_TYPE_CELLULAR:
158 case CONNMAN_DEVICE_TYPE_GADGET:
166 static const char *type2string(enum connman_device_type type)
169 case CONNMAN_DEVICE_TYPE_UNKNOWN:
170 case CONNMAN_DEVICE_TYPE_VENDOR:
172 case CONNMAN_DEVICE_TYPE_ETHERNET:
174 case CONNMAN_DEVICE_TYPE_WIFI:
176 case CONNMAN_DEVICE_TYPE_WIMAX:
178 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
180 case CONNMAN_DEVICE_TYPE_GPS:
182 case CONNMAN_DEVICE_TYPE_CELLULAR:
184 case CONNMAN_DEVICE_TYPE_GADGET:
192 enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
194 enum connman_device_type type = connman_device_get_type(device);
197 case CONNMAN_DEVICE_TYPE_UNKNOWN:
198 case CONNMAN_DEVICE_TYPE_VENDOR:
199 case CONNMAN_DEVICE_TYPE_GPS:
201 case CONNMAN_DEVICE_TYPE_ETHERNET:
202 return CONNMAN_SERVICE_TYPE_ETHERNET;
203 case CONNMAN_DEVICE_TYPE_WIFI:
204 return CONNMAN_SERVICE_TYPE_WIFI;
205 case CONNMAN_DEVICE_TYPE_WIMAX:
206 return CONNMAN_SERVICE_TYPE_WIMAX;
207 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
208 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
209 case CONNMAN_DEVICE_TYPE_CELLULAR:
210 return CONNMAN_SERVICE_TYPE_CELLULAR;
211 case CONNMAN_DEVICE_TYPE_GADGET:
212 return CONNMAN_SERVICE_TYPE_GADGET;
216 return CONNMAN_SERVICE_TYPE_UNKNOWN;
219 static gboolean device_pending_reset(gpointer user_data)
221 struct connman_device *device = user_data;
223 DBG("device %p", device);
225 /* Power request timedout, reset power pending state. */
226 if (device->pending_timeout > 0) {
227 g_source_remove(device->pending_timeout);
228 device->pending_timeout = 0;
229 device->powered_pending = PENDING_NONE;
235 int __connman_device_enable(struct connman_device *device)
239 DBG("device %p", device);
241 if (!device->driver || !device->driver->enable)
244 /* There is an ongoing power disable request. */
245 if (device->powered_pending == PENDING_DISABLE)
248 if (device->powered_pending == PENDING_ENABLE)
251 if (device->powered_pending == PENDING_NONE && device->powered == TRUE)
254 device->powered_pending = PENDING_ENABLE;
256 err = device->driver->enable(device);
258 * device gets enabled right away.
259 * Invoke the callback
262 connman_device_set_powered(device, TRUE);
266 if (err == -EALREADY) {
267 /* If device is already powered, but connman is not updated */
268 connman_device_set_powered(device, TRUE);
272 * if err == -EINPROGRESS, then the DBus call to the respective daemon
273 * was successful. We set a 4 sec timeout so if the daemon never
274 * returns a reply, we would reset the pending request.
276 if (err == -EINPROGRESS)
277 device->pending_timeout = g_timeout_add_seconds(4,
278 device_pending_reset, device);
283 int __connman_device_disable(struct connman_device *device)
287 DBG("device %p", device);
289 if (!device->driver || !device->driver->disable)
292 /* Ongoing power enable request */
293 if (device->powered_pending == PENDING_ENABLE)
296 if (device->powered_pending == PENDING_DISABLE)
299 if (device->powered_pending == PENDING_NONE && device->powered == FALSE)
302 device->reconnect = FALSE;
304 clear_scan_trigger(device);
306 err = device->driver->disable(device);
308 connman_device_set_powered(device, FALSE);
312 if (err == -EALREADY) {
313 connman_device_set_powered(device, FALSE);
317 if (err == -EINPROGRESS)
318 device->pending_timeout = g_timeout_add_seconds(4,
319 device_pending_reset, device);
324 static void probe_driver(struct connman_device_driver *driver)
328 DBG("driver %p name %s", driver, driver->name);
330 for (list = device_list; list != NULL; list = list->next) {
331 struct connman_device *device = list->data;
333 if (device->driver != NULL)
336 if (driver->type != device->type)
339 if (driver->probe(device) < 0)
342 device->driver = driver;
344 __connman_technology_add_device(device);
348 static void remove_device(struct connman_device *device)
350 DBG("device %p", device);
352 __connman_device_disable(device);
354 __connman_technology_remove_device(device);
356 if (device->driver->remove)
357 device->driver->remove(device);
359 device->driver = NULL;
362 static void remove_driver(struct connman_device_driver *driver)
366 DBG("driver %p name %s", driver, driver->name);
368 for (list = device_list; list != NULL; list = list->next) {
369 struct connman_device *device = list->data;
371 if (device->driver == driver)
372 remove_device(device);
376 connman_bool_t __connman_device_has_driver(struct connman_device *device)
378 if (device == NULL || device->driver == NULL)
384 static GSList *driver_list = NULL;
386 static gint compare_priority(gconstpointer a, gconstpointer b)
388 const struct connman_device_driver *driver1 = a;
389 const struct connman_device_driver *driver2 = b;
391 return driver2->priority - driver1->priority;
395 * connman_device_driver_register:
396 * @driver: device driver definition
398 * Register a new device driver
400 * Returns: %0 on success
402 int connman_device_driver_register(struct connman_device_driver *driver)
404 DBG("driver %p name %s", driver, driver->name);
406 driver_list = g_slist_insert_sorted(driver_list, driver,
408 probe_driver(driver);
414 * connman_device_driver_unregister:
415 * @driver: device driver definition
417 * Remove a previously registered device driver
419 void connman_device_driver_unregister(struct connman_device_driver *driver)
421 DBG("driver %p name %s", driver, driver->name);
423 driver_list = g_slist_remove(driver_list, driver);
425 remove_driver(driver);
428 static void free_network(gpointer data)
430 struct connman_network *network = data;
432 DBG("network %p", network);
434 __connman_network_set_device(network, NULL);
436 connman_network_unref(network);
439 static void device_destruct(struct connman_device *device)
441 DBG("device %p name %s", device, device->name);
443 clear_scan_trigger(device);
445 g_free(device->ident);
446 g_free(device->node);
447 g_free(device->name);
448 g_free(device->address);
449 g_free(device->interface);
450 g_free(device->path);
451 g_free(device->devname);
453 g_free(device->last_network);
455 g_hash_table_destroy(device->networks);
456 device->networks = NULL;
462 * connman_device_create:
463 * @node: device node name (for example an address)
466 * Allocate a new device of given #type and assign the #node name to it.
468 * Returns: a newly-allocated #connman_device structure
470 struct connman_device *connman_device_create(const char *node,
471 enum connman_device_type type)
473 struct connman_device *device;
474 connman_bool_t bg_scan;
476 DBG("node %s type %d", node, type);
478 device = g_try_new0(struct connman_device, 1);
482 DBG("device %p", device);
484 device->refcount = 1;
486 bg_scan = connman_setting_get_bool("BackgroundScanning");
489 device->name = g_strdup(type2description(device->type));
491 device->powered_persistent = TRUE;
493 device->phyindex = -1;
495 device->backoff_interval = SCAN_INITIAL_DELAY;
498 case CONNMAN_DEVICE_TYPE_UNKNOWN:
499 case CONNMAN_DEVICE_TYPE_ETHERNET:
500 case CONNMAN_DEVICE_TYPE_WIMAX:
501 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
502 case CONNMAN_DEVICE_TYPE_CELLULAR:
503 case CONNMAN_DEVICE_TYPE_GPS:
504 case CONNMAN_DEVICE_TYPE_GADGET:
505 case CONNMAN_DEVICE_TYPE_VENDOR:
506 device->scan_interval = 0;
508 case CONNMAN_DEVICE_TYPE_WIFI:
510 device->scan_interval = 300;
512 device->scan_interval = 0;
516 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
517 g_free, free_network);
519 device_list = g_slist_append(device_list, device);
525 * connman_device_ref:
526 * @device: device structure
528 * Increase reference counter of device
530 struct connman_device *connman_device_ref(struct connman_device *device)
534 g_atomic_int_inc(&device->refcount);
540 * connman_device_unref:
541 * @device: device structure
543 * Decrease reference counter of device
545 void connman_device_unref(struct connman_device *device)
547 if (g_atomic_int_dec_and_test(&device->refcount) == FALSE)
550 if (device->driver) {
551 device->driver->remove(device);
552 device->driver = NULL;
555 device_list = g_slist_remove(device_list, device);
557 device_destruct(device);
560 const char *__connman_device_get_type(struct connman_device *device)
562 return type2string(device->type);
566 * connman_device_get_type:
567 * @device: device structure
571 enum connman_device_type connman_device_get_type(struct connman_device *device)
577 * connman_device_set_index:
578 * @device: device structure
579 * @index: index number
581 * Set index number of device
583 void connman_device_set_index(struct connman_device *device, int index)
585 device->index = index;
589 * connman_device_get_index:
590 * @device: device structure
592 * Get index number of device
594 int connman_device_get_index(struct connman_device *device)
596 return device->index;
599 int __connman_device_get_phyindex(struct connman_device *device)
601 return device->phyindex;
604 void __connman_device_set_phyindex(struct connman_device *device,
607 device->phyindex = phyindex;
611 * connman_device_set_interface:
612 * @device: device structure
613 * @interface: interface name
615 * Set interface name of device
617 void connman_device_set_interface(struct connman_device *device,
618 const char *interface)
620 g_free(device->devname);
621 device->devname = g_strdup(interface);
623 g_free(device->interface);
624 device->interface = g_strdup(interface);
626 if (device->name == NULL) {
627 const char *str = type2description(device->type);
628 if (str != NULL && device->interface != NULL)
629 device->name = g_strdup_printf("%s (%s)", str,
635 * connman_device_set_ident:
636 * @device: device structure
637 * @ident: unique identifier
639 * Set unique identifier of device
641 void connman_device_set_ident(struct connman_device *device,
644 g_free(device->ident);
645 device->ident = g_strdup(ident);
648 const char *connman_device_get_ident(struct connman_device *device)
650 return device->ident;
654 * connman_device_set_powered:
655 * @device: device structure
656 * @powered: powered state
658 * Change power state of device
660 int connman_device_set_powered(struct connman_device *device,
661 connman_bool_t powered)
663 enum connman_service_type type;
665 DBG("driver %p powered %d", device, powered);
667 if (device->powered == powered)
670 /* Reset pending request */
671 g_source_remove(device->pending_timeout);
672 device->pending_timeout = 0;
673 device->powered_pending = PENDING_NONE;
675 if (device->offlinemode == TRUE && powered == TRUE)
676 return __connman_device_disable(device);
678 device->powered = powered;
680 type = __connman_device_get_service_type(device);
682 if (device->powered == TRUE)
683 __connman_technology_enabled(type);
685 __connman_technology_disabled(type);
687 if (powered == FALSE) {
688 device->connections = 0;
692 connman_device_set_disconnected(device, FALSE);
693 device->scanning = FALSE;
695 reset_scan_trigger(device);
697 if (device->driver && device->driver->scan)
698 device->driver->scan(device);
703 static int device_scan(struct connman_device *device)
705 if (!device->driver || !device->driver->scan)
708 if (device->powered == FALSE)
711 reset_scan_trigger(device);
713 return device->driver->scan(device);
716 int __connman_device_enable_persistent(struct connman_device *device)
718 DBG("device %p", device);
720 device->powered_persistent = TRUE;
722 __connman_storage_save_device(device);
724 return __connman_device_enable(device);
727 int __connman_device_disable_persistent(struct connman_device *device)
729 DBG("device %p", device);
731 device->powered_persistent = FALSE;
733 __connman_storage_save_device(device);
735 return __connman_device_disable(device);
738 int __connman_device_disconnect(struct connman_device *device)
743 DBG("device %p", device);
745 connman_device_set_disconnected(device, TRUE);
747 g_hash_table_iter_init(&iter, device->networks);
749 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
750 struct connman_network *network = value;
752 if (connman_network_get_connecting(network) == TRUE) {
754 * Skip network in the process of connecting.
755 * This is a workaround for WiFi networks serviced
756 * by the supplicant plugin that hold a reference
757 * to the network. If we disconnect the network
758 * here then the referenced object will not be
759 * registered and usage (like launching DHCP client)
760 * will fail. There is nothing to be gained by
761 * removing the network here anyway.
763 connman_warn("Skipping disconnect of %s, network is connecting.",
764 connman_network_get_identifier(network));
768 __connman_network_disconnect(network);
774 static void mark_network_available(gpointer key, gpointer value,
777 struct connman_network *network = value;
779 connman_network_set_available(network, TRUE);
782 static void mark_network_unavailable(gpointer key, gpointer value,
785 struct connman_network *network = value;
787 if (connman_network_get_connected(network) == TRUE)
790 connman_network_set_available(network, FALSE);
793 static gboolean remove_unavailable_network(gpointer key, gpointer value,
796 struct connman_network *network = value;
798 if (connman_network_get_connected(network) == TRUE)
801 if (connman_network_get_available(network) == TRUE)
807 void __connman_device_cleanup_networks(struct connman_device *device)
809 g_hash_table_foreach_remove(device->networks,
810 remove_unavailable_network, NULL);
813 connman_bool_t __connman_device_scanning(struct connman_device *device)
815 return device->scanning;
818 void connman_device_reset_scanning(struct connman_device *device)
820 device->scanning = FALSE;
822 g_hash_table_foreach(device->networks,
823 mark_network_available, NULL);
828 * connman_device_set_scanning:
829 * @device: device structure
830 * @scanning: scanning state
832 * Change scanning state of device
834 int connman_device_set_scanning(struct connman_device *device,
835 connman_bool_t scanning)
837 DBG("device %p scanning %d", device, scanning);
839 if (!device->driver || !device->driver->scan)
842 if (device->scanning == scanning)
845 device->scanning = scanning;
847 if (scanning == TRUE) {
848 reset_scan_trigger(device);
850 g_hash_table_foreach(device->networks,
851 mark_network_unavailable, NULL);
856 __connman_device_cleanup_networks(device);
858 if (device->connections > 0)
861 __connman_service_auto_connect();
867 * connman_device_set_disconnected:
868 * @device: device structure
869 * @disconnected: disconnected state
871 * Change disconnected state of device (only for device with networks)
873 int connman_device_set_disconnected(struct connman_device *device,
874 connman_bool_t disconnected)
876 DBG("device %p disconnected %d", device, disconnected);
878 if (device->disconnected == disconnected)
881 device->disconnected = disconnected;
883 if (disconnected == TRUE)
884 force_scan_trigger(device);
890 * connman_device_get_disconnected:
891 * @device: device structure
893 * Get device disconnected state
895 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
897 return device->disconnected;
901 * connman_device_set_string:
902 * @device: device structure
903 * @key: unique identifier
904 * @value: string value
906 * Set string value for specific key
908 int connman_device_set_string(struct connman_device *device,
909 const char *key, const char *value)
911 DBG("device %p key %s value %s", device, key, value);
913 if (g_str_equal(key, "Address") == TRUE) {
914 g_free(device->address);
915 device->address = g_strdup(value);
916 } else if (g_str_equal(key, "Name") == TRUE) {
917 g_free(device->name);
918 device->name = g_strdup(value);
919 } else if (g_str_equal(key, "Node") == TRUE) {
920 g_free(device->node);
921 device->node = g_strdup(value);
922 } else if (g_str_equal(key, "Path") == TRUE) {
923 g_free(device->path);
924 device->path = g_strdup(value);
933 * connman_device_get_string:
934 * @device: device structure
935 * @key: unique identifier
937 * Get string value for specific key
939 const char *connman_device_get_string(struct connman_device *device,
942 DBG("device %p key %s", device, key);
944 if (g_str_equal(key, "Address") == TRUE)
945 return device->address;
946 else if (g_str_equal(key, "Name") == TRUE)
948 else if (g_str_equal(key, "Node") == TRUE)
950 else if (g_str_equal(key, "Interface") == TRUE)
951 return device->interface;
952 else if (g_str_equal(key, "Path") == TRUE)
958 void __connman_device_increase_connections(struct connman_device *device)
963 device->connections++;
966 void __connman_device_decrease_connections(struct connman_device *device)
971 device->connections--;
973 if (device->connections == 0)
974 device->backoff_interval = SCAN_INITIAL_DELAY;
978 * connman_device_add_network:
979 * @device: device structure
980 * @network: network structure
982 * Add new network to the device
984 int connman_device_add_network(struct connman_device *device,
985 struct connman_network *network)
987 const char *identifier = connman_network_get_identifier(network);
989 DBG("device %p network %p", device, network);
991 if (identifier == NULL)
994 connman_network_ref(network);
996 __connman_network_set_device(network, device);
998 g_hash_table_insert(device->networks, g_strdup(identifier),
1005 * connman_device_get_network:
1006 * @device: device structure
1007 * @identifier: network identifier
1009 * Get network for given identifier
1011 struct connman_network *connman_device_get_network(struct connman_device *device,
1012 const char *identifier)
1014 DBG("device %p identifier %s", device, identifier);
1016 return g_hash_table_lookup(device->networks, identifier);
1020 * connman_device_remove_network:
1021 * @device: device structure
1022 * @identifier: network identifier
1024 * Remove network for given identifier
1026 int connman_device_remove_network(struct connman_device *device,
1027 struct connman_network *network)
1029 const char *identifier;
1031 DBG("device %p network %p", device, network);
1033 if (network == NULL)
1036 identifier = connman_network_get_identifier(network);
1037 g_hash_table_remove(device->networks, identifier);
1042 void connman_device_remove_all_networks(struct connman_device *device)
1044 g_hash_table_remove_all(device->networks);
1047 void __connman_device_set_network(struct connman_device *device,
1048 struct connman_network *network)
1055 if (device->network == network)
1058 if (network != NULL) {
1059 name = connman_network_get_string(network, "Name");
1060 g_free(device->last_network);
1061 device->last_network = g_strdup(name);
1063 device->network = network;
1065 g_free(device->last_network);
1066 device->last_network = NULL;
1068 device->network = NULL;
1072 void __connman_device_set_reconnect(struct connman_device *device,
1073 connman_bool_t reconnect)
1075 device->reconnect = reconnect;
1078 connman_bool_t __connman_device_get_reconnect(
1079 struct connman_device *device)
1081 return device->reconnect;
1084 static gboolean match_driver(struct connman_device *device,
1085 struct connman_device_driver *driver)
1087 if (device->type == driver->type ||
1088 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1094 static int device_probe(struct connman_device *device)
1098 DBG("device %p name %s", device, device->name);
1100 if (device->driver != NULL)
1103 for (list = driver_list; list; list = list->next) {
1104 struct connman_device_driver *driver = list->data;
1106 if (match_driver(device, driver) == FALSE)
1109 DBG("driver %p name %s", driver, driver->name);
1111 if (driver->probe(device) == 0) {
1112 device->driver = driver;
1117 if (device->driver == NULL)
1120 return __connman_technology_add_device(device);
1123 static void device_remove(struct connman_device *device)
1125 DBG("device %p name %s", device, device->name);
1127 if (device->driver == NULL)
1130 remove_device(device);
1134 * connman_device_register:
1135 * @device: device structure
1137 * Register device with the system
1139 int connman_device_register(struct connman_device *device)
1141 __connman_storage_load_device(device);
1143 device->offlinemode = __connman_profile_get_offlinemode();
1145 return device_probe(device);
1149 * connman_device_unregister:
1150 * @device: device structure
1152 * Unregister device with the system
1154 void connman_device_unregister(struct connman_device *device)
1156 __connman_storage_save_device(device);
1158 device_remove(device);
1162 * connman_device_get_data:
1163 * @device: device structure
1165 * Get private device data pointer
1167 void *connman_device_get_data(struct connman_device *device)
1169 return device->driver_data;
1173 * connman_device_set_data:
1174 * @device: device structure
1175 * @data: data pointer
1177 * Set private device data pointer
1179 void connman_device_set_data(struct connman_device *device, void *data)
1181 device->driver_data = data;
1184 struct connman_device *__connman_device_find_device(
1185 enum connman_service_type type)
1189 for (list = device_list; list != NULL; list = list->next) {
1190 struct connman_device *device = list->data;
1191 enum connman_service_type service_type =
1192 __connman_device_get_service_type(device);
1194 if (service_type != type)
1203 int __connman_device_request_scan(enum connman_service_type type)
1209 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1210 case CONNMAN_SERVICE_TYPE_SYSTEM:
1211 case CONNMAN_SERVICE_TYPE_ETHERNET:
1212 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1213 case CONNMAN_SERVICE_TYPE_CELLULAR:
1214 case CONNMAN_SERVICE_TYPE_GPS:
1215 case CONNMAN_SERVICE_TYPE_VPN:
1216 case CONNMAN_SERVICE_TYPE_GADGET:
1218 case CONNMAN_SERVICE_TYPE_WIFI:
1219 case CONNMAN_SERVICE_TYPE_WIMAX:
1223 for (list = device_list; list != NULL; list = list->next) {
1224 struct connman_device *device = list->data;
1225 enum connman_service_type service_type =
1226 __connman_device_get_service_type(device);
1228 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
1229 service_type != type) {
1233 err = device_scan(device);
1234 if (err < 0 && err != -EINPROGRESS) {
1236 /* XXX maybe only a continue? */
1244 connman_bool_t __connman_device_isfiltered(const char *devname)
1248 if (device_filter == NULL)
1251 for (pattern = device_filter; *pattern; pattern++) {
1252 if (g_pattern_match_simple(*pattern, devname) == FALSE) {
1253 DBG("ignoring device %s (match)", devname);
1259 if (g_pattern_match_simple("dummy*", devname) == TRUE) {
1260 DBG("ignoring dummy networking devices");
1264 if (nodevice_filter == NULL)
1267 for (pattern = nodevice_filter; *pattern; pattern++) {
1268 if (g_pattern_match_simple(*pattern, devname) == TRUE) {
1269 DBG("ignoring device %s (no match)", devname);
1277 static int device_load(struct connman_device *device)
1279 const char *ident = __connman_profile_active_ident();
1281 GError *error = NULL;
1283 connman_bool_t powered;
1285 DBG("device %p", device);
1287 keyfile = __connman_storage_open_profile(ident);
1288 if (keyfile == NULL)
1291 identifier = g_strdup_printf("device_%s", device->name);
1292 if (identifier == NULL)
1295 powered = g_key_file_get_boolean(keyfile, identifier,
1298 device->powered_persistent = powered;
1299 g_clear_error(&error);
1304 __connman_storage_close_profile(ident, keyfile, FALSE);
1309 static int device_save(struct connman_device *device)
1311 const char *ident = __connman_profile_active_ident();
1315 DBG("device %p", device);
1317 keyfile = __connman_storage_open_profile(ident);
1318 if (keyfile == NULL)
1321 identifier = g_strdup_printf("device_%s", device->name);
1322 if (identifier == NULL)
1325 g_key_file_set_boolean(keyfile, identifier,
1326 "Powered", device->powered_persistent);
1331 __connman_storage_close_profile(ident, keyfile, TRUE);
1336 static struct connman_storage device_storage = {
1338 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
1339 .device_load = device_load,
1340 .device_save = device_save,
1343 int __connman_device_init(const char *device, const char *nodevice)
1348 device_filter = g_strsplit(device, ",", -1);
1350 if (nodevice != NULL)
1351 nodevice_filter = g_strsplit(nodevice, ",", -1);
1353 return connman_storage_register(&device_storage);
1356 void __connman_device_cleanup(void)
1360 g_strfreev(nodevice_filter);
1361 g_strfreev(device_filter);
1363 connman_storage_unregister(&device_storage);