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 struct connman_device {
37 enum connman_device_type type;
38 connman_bool_t offlinemode;
39 connman_bool_t blocked;
40 connman_bool_t powered;
41 connman_bool_t powered_pending;
42 connman_bool_t powered_persistent;
43 connman_bool_t scanning;
44 connman_bool_t disconnected;
45 connman_bool_t reconnect;
46 connman_uint16_t scan_interval;
47 connman_uint16_t backoff_interval;
57 unsigned int connections;
60 struct connman_device_driver *driver;
64 struct connman_network *network;
68 #define SCAN_INITIAL_DELAY 10
70 static gboolean device_scan_trigger(gpointer user_data)
72 struct connman_device *device = user_data;
74 DBG("device %p", device);
76 if (device->driver == NULL) {
77 device->scan_timeout = 0;
81 if (device->driver->scan)
82 device->driver->scan(device);
87 static void clear_scan_trigger(struct connman_device *device)
89 if (device->scan_timeout > 0) {
90 g_source_remove(device->scan_timeout);
91 device->scan_timeout = 0;
95 static void reset_scan_trigger(struct connman_device *device)
97 clear_scan_trigger(device);
99 if (device->scan_interval > 0) {
102 if (g_hash_table_size(device->networks) == 0) {
103 if (device->backoff_interval >= device->scan_interval)
104 device->backoff_interval = SCAN_INITIAL_DELAY;
105 interval = device->backoff_interval;
107 interval = device->scan_interval;
109 DBG("interval %d", interval);
111 device->scan_timeout = g_timeout_add_seconds(interval,
112 device_scan_trigger, device);
114 device->backoff_interval *= 2;
115 if (device->backoff_interval > device->scan_interval)
116 device->backoff_interval = device->scan_interval;
120 static void force_scan_trigger(struct connman_device *device)
122 clear_scan_trigger(device);
124 device->scan_timeout = g_timeout_add_seconds(5,
125 device_scan_trigger, device);
128 void connman_device_schedule_scan(struct connman_device *device)
130 reset_scan_trigger(device);
133 static const char *type2description(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:
151 case CONNMAN_DEVICE_TYPE_GADGET:
159 static const char *type2string(enum connman_device_type type)
162 case CONNMAN_DEVICE_TYPE_UNKNOWN:
163 case CONNMAN_DEVICE_TYPE_VENDOR:
165 case CONNMAN_DEVICE_TYPE_ETHERNET:
167 case CONNMAN_DEVICE_TYPE_WIFI:
169 case CONNMAN_DEVICE_TYPE_WIMAX:
171 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
173 case CONNMAN_DEVICE_TYPE_GPS:
175 case CONNMAN_DEVICE_TYPE_CELLULAR:
177 case CONNMAN_DEVICE_TYPE_GADGET:
185 enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
187 enum connman_device_type type = connman_device_get_type(device);
190 case CONNMAN_DEVICE_TYPE_UNKNOWN:
191 case CONNMAN_DEVICE_TYPE_VENDOR:
192 case CONNMAN_DEVICE_TYPE_GPS:
194 case CONNMAN_DEVICE_TYPE_ETHERNET:
195 return CONNMAN_SERVICE_TYPE_ETHERNET;
196 case CONNMAN_DEVICE_TYPE_WIFI:
197 return CONNMAN_SERVICE_TYPE_WIFI;
198 case CONNMAN_DEVICE_TYPE_WIMAX:
199 return CONNMAN_SERVICE_TYPE_WIMAX;
200 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
201 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
202 case CONNMAN_DEVICE_TYPE_CELLULAR:
203 return CONNMAN_SERVICE_TYPE_CELLULAR;
204 case CONNMAN_DEVICE_TYPE_GADGET:
205 return CONNMAN_SERVICE_TYPE_GADGET;
209 return CONNMAN_SERVICE_TYPE_UNKNOWN;
212 int __connman_device_enable(struct connman_device *device)
215 enum connman_service_type type;
217 DBG("device %p %d", device, device->blocked);
219 if (!device->driver || !device->driver->enable)
222 if (device->powered_pending == TRUE)
225 if (device->blocked == TRUE)
228 connman_device_set_disconnected(device, FALSE);
229 device->scanning = FALSE;
231 err = device->driver->enable(device);
232 if (err < 0 && err != -EALREADY) {
233 if (err == -EINPROGRESS) {
234 device->powered_pending = TRUE;
235 device->offlinemode = FALSE;
236 if (__connman_profile_get_offlinemode() == TRUE)
237 __connman_profile_set_offlinemode(FALSE, FALSE);
242 device->powered_pending = TRUE;
243 device->powered = TRUE;
244 device->offlinemode = FALSE;
245 if (__connman_profile_get_offlinemode() == TRUE)
246 __connman_profile_set_offlinemode(FALSE, FALSE);
248 type = __connman_device_get_service_type(device);
249 __connman_technology_enabled(type);
254 int __connman_device_disable(struct connman_device *device)
257 enum connman_service_type type;
259 DBG("device %p", device);
261 if (!device->driver || !device->driver->disable)
264 if (device->powered == FALSE)
267 if (device->powered_pending == FALSE)
270 device->reconnect = FALSE;
272 clear_scan_trigger(device);
274 err = device->driver->disable(device);
275 if (err < 0 && err != -EALREADY) {
276 if (err == -EINPROGRESS)
277 device->powered_pending = FALSE;
281 g_hash_table_remove_all(device->networks);
283 device->connections = 0;
285 device->powered_pending = FALSE;
286 device->powered = FALSE;
288 type = __connman_device_get_service_type(device);
289 __connman_technology_disabled(type);
294 static int set_powered(struct connman_device *device, connman_bool_t powered)
296 DBG("device %p powered %d", device, powered);
299 return __connman_device_enable(device);
301 return __connman_device_disable(device);
304 static int setup_device(struct connman_device *device)
306 DBG("device %p", device);
308 __connman_technology_add_device(device);
310 if (device->offlinemode == FALSE &&
311 device->powered_persistent == TRUE)
312 __connman_device_enable(device);
317 static void probe_driver(struct connman_device_driver *driver)
321 DBG("driver %p name %s", driver, driver->name);
323 for (list = device_list; list != NULL; list = list->next) {
324 struct connman_device *device = list->data;
326 if (device->driver != NULL)
329 if (driver->type != device->type)
332 if (driver->probe(device) < 0)
335 device->driver = driver;
337 setup_device(device);
341 static void remove_device(struct connman_device *device)
343 DBG("device %p", device);
345 __connman_device_disable(device);
347 __connman_technology_remove_device(device);
349 if (device->driver->remove)
350 device->driver->remove(device);
352 device->driver = NULL;
355 static void remove_driver(struct connman_device_driver *driver)
359 DBG("driver %p name %s", driver, driver->name);
361 for (list = device_list; list != NULL; list = list->next) {
362 struct connman_device *device = list->data;
364 if (device->driver == driver)
365 remove_device(device);
369 connman_bool_t __connman_device_has_driver(struct connman_device *device)
371 if (device == NULL || device->driver == NULL)
377 static GSList *driver_list = NULL;
379 static gint compare_priority(gconstpointer a, gconstpointer b)
381 const struct connman_device_driver *driver1 = a;
382 const struct connman_device_driver *driver2 = b;
384 return driver2->priority - driver1->priority;
388 * connman_device_driver_register:
389 * @driver: device driver definition
391 * Register a new device driver
393 * Returns: %0 on success
395 int connman_device_driver_register(struct connman_device_driver *driver)
397 DBG("driver %p name %s", driver, driver->name);
399 driver_list = g_slist_insert_sorted(driver_list, driver,
401 probe_driver(driver);
407 * connman_device_driver_unregister:
408 * @driver: device driver definition
410 * Remove a previously registered device driver
412 void connman_device_driver_unregister(struct connman_device_driver *driver)
414 DBG("driver %p name %s", driver, driver->name);
416 driver_list = g_slist_remove(driver_list, driver);
418 remove_driver(driver);
421 static void free_network(gpointer data)
423 struct connman_network *network = data;
425 DBG("network %p", network);
427 __connman_network_set_device(network, NULL);
429 connman_network_unref(network);
432 static void device_destruct(struct connman_device *device)
434 DBG("device %p name %s", device, device->name);
436 clear_scan_trigger(device);
438 g_free(device->ident);
439 g_free(device->node);
440 g_free(device->name);
441 g_free(device->address);
442 g_free(device->interface);
443 g_free(device->path);
444 g_free(device->devname);
446 g_free(device->last_network);
448 g_hash_table_destroy(device->networks);
449 device->networks = NULL;
455 * connman_device_create:
456 * @node: device node name (for example an address)
459 * Allocate a new device of given #type and assign the #node name to it.
461 * Returns: a newly-allocated #connman_device structure
463 struct connman_device *connman_device_create(const char *node,
464 enum connman_device_type type)
466 struct connman_device *device;
467 enum connman_service_type service_type;
468 connman_bool_t bg_scan;
470 DBG("node %s type %d", node, type);
472 device = g_try_new0(struct connman_device, 1);
476 DBG("device %p", device);
478 device->refcount = 1;
480 bg_scan = connman_setting_get_bool("BackgroundScanning");
483 device->name = g_strdup(type2description(device->type));
485 device->powered_persistent = TRUE;
487 device->phyindex = -1;
489 service_type = __connman_device_get_service_type(device);
490 device->blocked = __connman_technology_get_blocked(service_type);
491 device->backoff_interval = SCAN_INITIAL_DELAY;
494 case CONNMAN_DEVICE_TYPE_UNKNOWN:
495 case CONNMAN_DEVICE_TYPE_ETHERNET:
496 case CONNMAN_DEVICE_TYPE_WIMAX:
497 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
498 case CONNMAN_DEVICE_TYPE_CELLULAR:
499 case CONNMAN_DEVICE_TYPE_GPS:
500 case CONNMAN_DEVICE_TYPE_GADGET:
501 case CONNMAN_DEVICE_TYPE_VENDOR:
502 device->scan_interval = 0;
504 case CONNMAN_DEVICE_TYPE_WIFI:
506 device->scan_interval = 300;
508 device->scan_interval = 0;
512 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
513 g_free, free_network);
515 device_list = g_slist_append(device_list, device);
521 * connman_device_ref:
522 * @device: device structure
524 * Increase reference counter of device
526 struct connman_device *connman_device_ref(struct connman_device *device)
530 g_atomic_int_inc(&device->refcount);
536 * connman_device_unref:
537 * @device: device structure
539 * Decrease reference counter of device
541 void connman_device_unref(struct connman_device *device)
543 if (g_atomic_int_dec_and_test(&device->refcount) == FALSE)
546 if (device->driver) {
547 device->driver->remove(device);
548 device->driver = NULL;
551 device_list = g_slist_remove(device_list, device);
553 device_destruct(device);
556 const char *__connman_device_get_type(struct connman_device *device)
558 return type2string(device->type);
562 * connman_device_get_type:
563 * @device: device structure
567 enum connman_device_type connman_device_get_type(struct connman_device *device)
573 * connman_device_set_index:
574 * @device: device structure
575 * @index: index number
577 * Set index number of device
579 void connman_device_set_index(struct connman_device *device, int index)
581 device->index = index;
585 * connman_device_get_index:
586 * @device: device structure
588 * Get index number of device
590 int connman_device_get_index(struct connman_device *device)
592 return device->index;
595 int __connman_device_get_phyindex(struct connman_device *device)
597 return device->phyindex;
600 void __connman_device_set_phyindex(struct connman_device *device,
603 device->phyindex = phyindex;
607 * connman_device_set_interface:
608 * @device: device structure
609 * @interface: interface name
611 * Set interface name of device
613 void connman_device_set_interface(struct connman_device *device,
614 const char *interface)
616 g_free(device->devname);
617 device->devname = g_strdup(interface);
619 g_free(device->interface);
620 device->interface = g_strdup(interface);
622 if (device->name == NULL) {
623 const char *str = type2description(device->type);
624 if (str != NULL && device->interface != NULL)
625 device->name = g_strdup_printf("%s (%s)", str,
631 * connman_device_set_ident:
632 * @device: device structure
633 * @ident: unique identifier
635 * Set unique identifier of device
637 void connman_device_set_ident(struct connman_device *device,
640 g_free(device->ident);
641 device->ident = g_strdup(ident);
644 const char *connman_device_get_ident(struct connman_device *device)
646 return device->ident;
650 * connman_device_set_powered:
651 * @device: device structure
652 * @powered: powered state
654 * Change power state of device
656 int connman_device_set_powered(struct connman_device *device,
657 connman_bool_t powered)
660 enum connman_service_type type;
662 DBG("driver %p powered %d", device, powered);
664 if (device->powered == powered) {
665 device->powered_pending = powered;
670 err = __connman_device_enable(device);
672 err = __connman_device_disable(device);
674 if (err < 0 && err != -EINPROGRESS && err != -EALREADY)
677 device->powered = powered;
678 device->powered_pending = 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 (device->offlinemode == TRUE && powered == TRUE)
688 return connman_device_set_powered(device, FALSE);
690 if (powered == FALSE)
693 reset_scan_trigger(device);
695 if (device->driver && device->driver->scan)
696 device->driver->scan(device);
701 int __connman_device_set_blocked(struct connman_device *device,
702 connman_bool_t blocked)
704 connman_bool_t powered;
706 DBG("device %p blocked %d", device, blocked);
708 device->blocked = blocked;
710 if (device->offlinemode == TRUE)
713 connman_info("%s {rfkill} blocked %d", device->interface, blocked);
715 if (blocked == FALSE)
716 powered = device->powered_persistent;
720 return set_powered(device, powered);
723 connman_bool_t __connman_device_get_blocked(struct connman_device *device)
725 return device->blocked;
728 static int device_scan(struct connman_device *device)
730 if (!device->driver || !device->driver->scan)
733 if (device->powered == FALSE)
736 reset_scan_trigger(device);
738 return device->driver->scan(device);
741 int __connman_device_enable_persistent(struct connman_device *device)
743 DBG("device %p", device);
745 device->powered_persistent = TRUE;
747 __connman_storage_save_device(device);
749 return __connman_device_enable(device);
752 int __connman_device_disable_persistent(struct connman_device *device)
754 DBG("device %p", device);
756 device->powered_persistent = FALSE;
758 __connman_storage_save_device(device);
760 return __connman_device_disable(device);
763 int __connman_device_disconnect(struct connman_device *device)
768 DBG("device %p", device);
770 connman_device_set_disconnected(device, TRUE);
772 g_hash_table_iter_init(&iter, device->networks);
774 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
775 struct connman_network *network = value;
777 if (connman_network_get_connecting(network) == TRUE) {
779 * Skip network in the process of connecting.
780 * This is a workaround for WiFi networks serviced
781 * by the supplicant plugin that hold a reference
782 * to the network. If we disconnect the network
783 * here then the referenced object will not be
784 * registered and usage (like launching DHCP client)
785 * will fail. There is nothing to be gained by
786 * removing the network here anyway.
788 connman_warn("Skipping disconnect of %s, network is connecting.",
789 connman_network_get_identifier(network));
793 __connman_network_disconnect(network);
799 static void mark_network_available(gpointer key, gpointer value,
802 struct connman_network *network = value;
804 connman_network_set_available(network, TRUE);
807 static void mark_network_unavailable(gpointer key, gpointer value,
810 struct connman_network *network = value;
812 if (connman_network_get_connected(network) == TRUE)
815 connman_network_set_available(network, FALSE);
818 static gboolean remove_unavailable_network(gpointer key, gpointer value,
821 struct connman_network *network = value;
823 if (connman_network_get_connected(network) == TRUE)
826 if (connman_network_get_available(network) == TRUE)
832 void __connman_device_cleanup_networks(struct connman_device *device)
834 g_hash_table_foreach_remove(device->networks,
835 remove_unavailable_network, NULL);
838 connman_bool_t __connman_device_scanning(struct connman_device *device)
840 return device->scanning;
843 void connman_device_reset_scanning(struct connman_device *device)
845 device->scanning = FALSE;
847 g_hash_table_foreach(device->networks,
848 mark_network_available, NULL);
853 * connman_device_set_scanning:
854 * @device: device structure
855 * @scanning: scanning state
857 * Change scanning state of device
859 int connman_device_set_scanning(struct connman_device *device,
860 connman_bool_t scanning)
862 DBG("device %p scanning %d", device, scanning);
864 if (!device->driver || !device->driver->scan)
867 if (device->scanning == scanning)
870 device->scanning = scanning;
872 if (scanning == TRUE) {
873 reset_scan_trigger(device);
875 g_hash_table_foreach(device->networks,
876 mark_network_unavailable, NULL);
881 __connman_device_cleanup_networks(device);
883 if (device->connections > 0)
886 __connman_service_auto_connect();
892 * connman_device_set_disconnected:
893 * @device: device structure
894 * @disconnected: disconnected state
896 * Change disconnected state of device (only for device with networks)
898 int connman_device_set_disconnected(struct connman_device *device,
899 connman_bool_t disconnected)
901 DBG("device %p disconnected %d", device, disconnected);
903 if (device->disconnected == disconnected)
906 device->disconnected = disconnected;
908 if (disconnected == TRUE)
909 force_scan_trigger(device);
915 * connman_device_get_disconnected:
916 * @device: device structure
918 * Get device disconnected state
920 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
922 return device->disconnected;
926 * connman_device_set_string:
927 * @device: device structure
928 * @key: unique identifier
929 * @value: string value
931 * Set string value for specific key
933 int connman_device_set_string(struct connman_device *device,
934 const char *key, const char *value)
936 DBG("device %p key %s value %s", device, key, value);
938 if (g_str_equal(key, "Address") == TRUE) {
939 g_free(device->address);
940 device->address = g_strdup(value);
941 } else if (g_str_equal(key, "Name") == TRUE) {
942 g_free(device->name);
943 device->name = g_strdup(value);
944 } else if (g_str_equal(key, "Node") == TRUE) {
945 g_free(device->node);
946 device->node = g_strdup(value);
947 } else if (g_str_equal(key, "Path") == TRUE) {
948 g_free(device->path);
949 device->path = g_strdup(value);
958 * connman_device_get_string:
959 * @device: device structure
960 * @key: unique identifier
962 * Get string value for specific key
964 const char *connman_device_get_string(struct connman_device *device,
967 DBG("device %p key %s", device, key);
969 if (g_str_equal(key, "Address") == TRUE)
970 return device->address;
971 else if (g_str_equal(key, "Name") == TRUE)
973 else if (g_str_equal(key, "Node") == TRUE)
975 else if (g_str_equal(key, "Interface") == TRUE)
976 return device->interface;
977 else if (g_str_equal(key, "Path") == TRUE)
983 static void set_offlinemode(struct connman_device *device,
984 connman_bool_t offlinemode)
986 connman_bool_t powered;
988 DBG("device %p name %s", device, device->name);
993 device->offlinemode = offlinemode;
995 if (device->blocked == TRUE)
998 powered = (offlinemode == TRUE) ? FALSE : TRUE;
1000 if (device->powered == powered)
1003 if (device->powered_persistent == FALSE)
1006 set_powered(device, powered);
1009 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
1013 DBG("offlinmode %d", offlinemode);
1015 for (list = device_list; list != NULL; list = list->next) {
1016 struct connman_device *device = list->data;
1018 set_offlinemode(device, offlinemode);
1021 __connman_notifier_offlinemode(offlinemode);
1026 void __connman_device_increase_connections(struct connman_device *device)
1031 device->connections++;
1034 void __connman_device_decrease_connections(struct connman_device *device)
1039 device->connections--;
1041 if (device->connections == 0)
1042 device->backoff_interval = SCAN_INITIAL_DELAY;
1046 * connman_device_add_network:
1047 * @device: device structure
1048 * @network: network structure
1050 * Add new network to the device
1052 int connman_device_add_network(struct connman_device *device,
1053 struct connman_network *network)
1055 const char *identifier = connman_network_get_identifier(network);
1057 DBG("device %p network %p", device, network);
1059 if (identifier == NULL)
1062 connman_network_ref(network);
1064 __connman_network_set_device(network, device);
1066 g_hash_table_insert(device->networks, g_strdup(identifier),
1073 * connman_device_get_network:
1074 * @device: device structure
1075 * @identifier: network identifier
1077 * Get network for given identifier
1079 struct connman_network *connman_device_get_network(struct connman_device *device,
1080 const char *identifier)
1082 DBG("device %p identifier %s", device, identifier);
1084 return g_hash_table_lookup(device->networks, identifier);
1088 * connman_device_remove_network:
1089 * @device: device structure
1090 * @identifier: network identifier
1092 * Remove network for given identifier
1094 int connman_device_remove_network(struct connman_device *device,
1095 struct connman_network *network)
1097 const char *identifier;
1099 DBG("device %p network %p", device, network);
1101 if (network == NULL)
1104 identifier = connman_network_get_identifier(network);
1105 g_hash_table_remove(device->networks, identifier);
1110 void connman_device_remove_all_networks(struct connman_device *device)
1112 g_hash_table_remove_all(device->networks);
1115 void __connman_device_set_network(struct connman_device *device,
1116 struct connman_network *network)
1123 if (device->network == network)
1126 if (network != NULL) {
1127 name = connman_network_get_string(network, "Name");
1128 g_free(device->last_network);
1129 device->last_network = g_strdup(name);
1131 device->network = network;
1133 g_free(device->last_network);
1134 device->last_network = NULL;
1136 device->network = NULL;
1140 void __connman_device_set_reconnect(struct connman_device *device,
1141 connman_bool_t reconnect)
1143 device->reconnect = reconnect;
1146 connman_bool_t __connman_device_get_reconnect(
1147 struct connman_device *device)
1149 return device->reconnect;
1152 static gboolean match_driver(struct connman_device *device,
1153 struct connman_device_driver *driver)
1155 if (device->type == driver->type ||
1156 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1162 static int device_probe(struct connman_device *device)
1166 DBG("device %p name %s", device, device->name);
1168 if (device->driver != NULL)
1171 for (list = driver_list; list; list = list->next) {
1172 struct connman_device_driver *driver = list->data;
1174 if (match_driver(device, driver) == FALSE)
1177 DBG("driver %p name %s", driver, driver->name);
1179 if (driver->probe(device) == 0) {
1180 device->driver = driver;
1185 if (device->driver == NULL)
1188 return setup_device(device);
1191 static void device_remove(struct connman_device *device)
1193 DBG("device %p name %s", device, device->name);
1195 if (device->driver == NULL)
1198 remove_device(device);
1202 * connman_device_register:
1203 * @device: device structure
1205 * Register device with the system
1207 int connman_device_register(struct connman_device *device)
1209 __connman_storage_load_device(device);
1211 device->offlinemode = __connman_profile_get_offlinemode();
1213 return device_probe(device);
1217 * connman_device_unregister:
1218 * @device: device structure
1220 * Unregister device with the system
1222 void connman_device_unregister(struct connman_device *device)
1224 __connman_storage_save_device(device);
1226 device_remove(device);
1230 * connman_device_get_data:
1231 * @device: device structure
1233 * Get private device data pointer
1235 void *connman_device_get_data(struct connman_device *device)
1237 return device->driver_data;
1241 * connman_device_set_data:
1242 * @device: device structure
1243 * @data: data pointer
1245 * Set private device data pointer
1247 void connman_device_set_data(struct connman_device *device, void *data)
1249 device->driver_data = data;
1252 struct connman_device *__connman_device_find_device(
1253 enum connman_service_type type)
1257 for (list = device_list; list != NULL; list = list->next) {
1258 struct connman_device *device = list->data;
1259 enum connman_service_type service_type =
1260 __connman_device_get_service_type(device);
1262 if (service_type != type)
1271 int __connman_device_request_scan(enum connman_service_type type)
1277 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1278 case CONNMAN_SERVICE_TYPE_SYSTEM:
1279 case CONNMAN_SERVICE_TYPE_ETHERNET:
1280 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1281 case CONNMAN_SERVICE_TYPE_CELLULAR:
1282 case CONNMAN_SERVICE_TYPE_GPS:
1283 case CONNMAN_SERVICE_TYPE_VPN:
1284 case CONNMAN_SERVICE_TYPE_GADGET:
1286 case CONNMAN_SERVICE_TYPE_WIFI:
1287 case CONNMAN_SERVICE_TYPE_WIMAX:
1291 for (list = device_list; list != NULL; list = list->next) {
1292 struct connman_device *device = list->data;
1293 enum connman_service_type service_type =
1294 __connman_device_get_service_type(device);
1296 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
1297 service_type != type) {
1301 err = device_scan(device);
1302 if (err < 0 && err != -EINPROGRESS) {
1304 /* XXX maybe only a continue? */
1312 connman_bool_t __connman_device_isfiltered(const char *devname)
1316 if (device_filter == NULL)
1319 for (pattern = device_filter; *pattern; pattern++) {
1320 if (g_pattern_match_simple(*pattern, devname) == FALSE) {
1321 DBG("ignoring device %s (match)", devname);
1327 if (g_pattern_match_simple("dummy*", devname) == TRUE) {
1328 DBG("ignoring dummy networking devices");
1332 if (nodevice_filter == NULL)
1335 for (pattern = nodevice_filter; *pattern; pattern++) {
1336 if (g_pattern_match_simple(*pattern, devname) == TRUE) {
1337 DBG("ignoring device %s (no match)", devname);
1345 static int device_load(struct connman_device *device)
1347 const char *ident = __connman_profile_active_ident();
1349 GError *error = NULL;
1351 connman_bool_t powered;
1353 DBG("device %p", device);
1355 keyfile = __connman_storage_open_profile(ident);
1356 if (keyfile == NULL)
1359 identifier = g_strdup_printf("device_%s", device->name);
1360 if (identifier == NULL)
1363 powered = g_key_file_get_boolean(keyfile, identifier,
1366 device->powered_persistent = powered;
1367 g_clear_error(&error);
1372 __connman_storage_close_profile(ident, keyfile, FALSE);
1377 static int device_save(struct connman_device *device)
1379 const char *ident = __connman_profile_active_ident();
1383 DBG("device %p", device);
1385 keyfile = __connman_storage_open_profile(ident);
1386 if (keyfile == NULL)
1389 identifier = g_strdup_printf("device_%s", device->name);
1390 if (identifier == NULL)
1393 g_key_file_set_boolean(keyfile, identifier,
1394 "Powered", device->powered_persistent);
1399 __connman_storage_close_profile(ident, keyfile, TRUE);
1404 static struct connman_storage device_storage = {
1406 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
1407 .device_load = device_load,
1408 .device_save = device_save,
1411 int __connman_device_init(const char *device, const char *nodevice)
1416 device_filter = g_strsplit(device, ",", -1);
1418 if (nodevice != NULL)
1419 nodevice_filter = g_strsplit(nodevice, ",", -1);
1421 return connman_storage_register(&device_storage);
1424 void __connman_device_cleanup(void)
1428 g_strfreev(nodevice_filter);
1429 g_strfreev(device_filter);
1431 connman_storage_unregister(&device_storage);