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
32 #define CONNMAN_SIG_WIFI_REFCOUNT_GROUP_NAME "connman_significant_wifi_profile_refcount"
35 static GSList *device_list = NULL;
36 static gchar **device_filter = NULL;
37 static gchar **nodevice_filter = NULL;
39 enum connman_pending_type {
45 struct connman_device {
47 enum connman_device_type type;
48 enum connman_pending_type powered_pending; /* Indicates a pending
49 enable/disable request */
50 connman_bool_t powered;
51 connman_bool_t scanning;
52 connman_bool_t disconnected;
53 connman_bool_t reconnect;
54 connman_uint16_t scan_interval;
55 connman_uint16_t backoff_interval;
66 guint pending_timeout;
68 struct connman_device_driver *driver;
72 struct connman_network *network;
76 /* It contains number of favorite Wi-Fi profile.
77 * If significant wifi profile is 0, Wi-Fi device does not trigger scan. */
78 gint significant_wifi_profile_refcount;
82 #define SCAN_INITIAL_DELAY 10
85 static void __connman_device_set_significant_wifi_profile_refcount(struct connman_device *device, gint refcount)
87 g_atomic_int_set(&device->significant_wifi_profile_refcount, refcount);
90 void connman_device_significant_wifi_profile_ref(struct connman_device *device)
92 g_atomic_int_inc(&device->significant_wifi_profile_refcount);
95 connman_bool_t connman_device_significant_wifi_profile_unref_and_test(struct connman_device *device)
97 if (device->significant_wifi_profile_refcount > 0)
98 return (connman_bool_t)g_atomic_int_dec_and_test(&device->significant_wifi_profile_refcount);
104 static gboolean device_scan_trigger(gpointer user_data)
106 struct connman_device *device = user_data;
108 DBG("device %p", device);
110 if (device->driver == NULL) {
111 device->scan_timeout = 0;
115 if (device->driver->scan)
116 device->driver->scan(device);
121 static void clear_scan_trigger(struct connman_device *device)
123 if (device->scan_timeout > 0) {
124 g_source_remove(device->scan_timeout);
125 device->scan_timeout = 0;
129 static void clear_pending_trigger(struct connman_device *device)
131 if (device->pending_timeout > 0) {
132 g_source_remove(device->pending_timeout);
133 device->pending_timeout = 0;
137 static void reset_scan_trigger(struct connman_device *device)
139 clear_scan_trigger(device);
141 if (device->scan_interval > 0) {
144 if (g_hash_table_size(device->networks) == 0) {
145 if (device->backoff_interval >= device->scan_interval)
146 device->backoff_interval = SCAN_INITIAL_DELAY;
147 interval = device->backoff_interval;
149 interval = device->scan_interval;
151 DBG("interval %d", interval);
153 device->scan_timeout = g_timeout_add_seconds(interval,
154 device_scan_trigger, device);
156 device->backoff_interval *= 2;
157 if (device->backoff_interval > device->scan_interval)
158 device->backoff_interval = device->scan_interval;
162 static void force_scan_trigger(struct connman_device *device)
164 clear_scan_trigger(device);
166 device->scan_timeout = g_timeout_add_seconds(5,
167 device_scan_trigger, device);
170 void connman_device_schedule_scan(struct connman_device *device)
172 reset_scan_trigger(device);
175 static const char *type2description(enum connman_device_type type)
178 case CONNMAN_DEVICE_TYPE_UNKNOWN:
179 case CONNMAN_DEVICE_TYPE_VENDOR:
181 case CONNMAN_DEVICE_TYPE_ETHERNET:
183 case CONNMAN_DEVICE_TYPE_WIFI:
185 case CONNMAN_DEVICE_TYPE_WIMAX:
187 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
189 case CONNMAN_DEVICE_TYPE_GPS:
191 case CONNMAN_DEVICE_TYPE_CELLULAR:
193 case CONNMAN_DEVICE_TYPE_GADGET:
201 static const char *type2string(enum connman_device_type type)
204 case CONNMAN_DEVICE_TYPE_UNKNOWN:
205 case CONNMAN_DEVICE_TYPE_VENDOR:
207 case CONNMAN_DEVICE_TYPE_ETHERNET:
209 case CONNMAN_DEVICE_TYPE_WIFI:
211 case CONNMAN_DEVICE_TYPE_WIMAX:
213 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
215 case CONNMAN_DEVICE_TYPE_GPS:
217 case CONNMAN_DEVICE_TYPE_CELLULAR:
219 case CONNMAN_DEVICE_TYPE_GADGET:
227 enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
229 enum connman_device_type type = connman_device_get_type(device);
232 case CONNMAN_DEVICE_TYPE_UNKNOWN:
233 case CONNMAN_DEVICE_TYPE_VENDOR:
234 case CONNMAN_DEVICE_TYPE_GPS:
236 case CONNMAN_DEVICE_TYPE_ETHERNET:
237 return CONNMAN_SERVICE_TYPE_ETHERNET;
238 case CONNMAN_DEVICE_TYPE_WIFI:
239 return CONNMAN_SERVICE_TYPE_WIFI;
240 case CONNMAN_DEVICE_TYPE_WIMAX:
241 return CONNMAN_SERVICE_TYPE_WIMAX;
242 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
243 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
244 case CONNMAN_DEVICE_TYPE_CELLULAR:
245 return CONNMAN_SERVICE_TYPE_CELLULAR;
246 case CONNMAN_DEVICE_TYPE_GADGET:
247 return CONNMAN_SERVICE_TYPE_GADGET;
251 return CONNMAN_SERVICE_TYPE_UNKNOWN;
254 static gboolean device_pending_reset(gpointer user_data)
256 struct connman_device *device = user_data;
258 DBG("device %p", device);
260 /* Power request timedout, reset power pending state. */
261 device->pending_timeout = 0;
262 device->powered_pending = PENDING_NONE;
267 int __connman_device_enable(struct connman_device *device)
271 DBG("device %p", device);
273 if (!device->driver || !device->driver->enable)
276 /* There is an ongoing power disable request. */
277 if (device->powered_pending == PENDING_DISABLE)
280 if (device->powered_pending == PENDING_ENABLE)
283 if (device->powered_pending == PENDING_NONE && device->powered == TRUE)
286 device->powered_pending = PENDING_ENABLE;
288 err = device->driver->enable(device);
290 * device gets enabled right away.
291 * Invoke the callback
294 connman_device_set_powered(device, TRUE);
298 if (err == -EALREADY) {
299 /* If device is already powered, but connman is not updated */
300 connman_device_set_powered(device, TRUE);
304 * if err == -EINPROGRESS, then the DBus call to the respective daemon
305 * was successful. We set a 4 sec timeout so if the daemon never
306 * returns a reply, we would reset the pending request.
308 if (err == -EINPROGRESS)
309 device->pending_timeout = g_timeout_add_seconds(4,
310 device_pending_reset, device);
315 int __connman_device_disable(struct connman_device *device)
319 DBG("device %p", device);
321 if (!device->driver || !device->driver->disable)
324 /* Ongoing power enable request */
325 if (device->powered_pending == PENDING_ENABLE)
328 if (device->powered_pending == PENDING_DISABLE)
331 if (device->powered_pending == PENDING_NONE && device->powered == FALSE)
334 device->powered_pending = PENDING_DISABLE;
335 device->reconnect = FALSE;
337 clear_scan_trigger(device);
339 if (device->network) {
340 struct connman_service *service =
341 __connman_service_lookup_from_network(device->network);
344 __connman_service_disconnect(service);
346 connman_network_set_connected(device->network, FALSE);
349 err = device->driver->disable(device);
351 connman_device_set_powered(device, FALSE);
355 if (err == -EALREADY) {
356 connman_device_set_powered(device, FALSE);
360 if (err == -EINPROGRESS)
361 device->pending_timeout = g_timeout_add_seconds(4,
362 device_pending_reset, device);
367 static void probe_driver(struct connman_device_driver *driver)
371 DBG("driver %p name %s", driver, driver->name);
373 for (list = device_list; list != NULL; list = list->next) {
374 struct connman_device *device = list->data;
376 if (device->driver != NULL)
379 if (driver->type != device->type)
382 if (driver->probe(device) < 0)
385 device->driver = driver;
387 __connman_technology_add_device(device);
391 static void remove_device(struct connman_device *device)
393 DBG("device %p", device);
395 __connman_device_disable(device);
397 __connman_technology_remove_device(device);
399 if (device->driver->remove)
400 device->driver->remove(device);
402 device->driver = NULL;
405 static void remove_driver(struct connman_device_driver *driver)
409 DBG("driver %p name %s", driver, driver->name);
411 for (list = device_list; list != NULL; list = list->next) {
412 struct connman_device *device = list->data;
414 if (device->driver == driver)
415 remove_device(device);
419 connman_bool_t __connman_device_has_driver(struct connman_device *device)
421 if (device == NULL || device->driver == NULL)
427 static GSList *driver_list = NULL;
429 static gint compare_priority(gconstpointer a, gconstpointer b)
431 const struct connman_device_driver *driver1 = a;
432 const struct connman_device_driver *driver2 = b;
434 return driver2->priority - driver1->priority;
438 * connman_device_driver_register:
439 * @driver: device driver definition
441 * Register a new device driver
443 * Returns: %0 on success
445 int connman_device_driver_register(struct connman_device_driver *driver)
447 DBG("driver %p name %s", driver, driver->name);
449 driver_list = g_slist_insert_sorted(driver_list, driver,
451 probe_driver(driver);
457 * connman_device_driver_unregister:
458 * @driver: device driver definition
460 * Remove a previously registered device driver
462 void connman_device_driver_unregister(struct connman_device_driver *driver)
464 DBG("driver %p name %s", driver, driver->name);
466 driver_list = g_slist_remove(driver_list, driver);
468 remove_driver(driver);
471 static void free_network(gpointer data)
473 struct connman_network *network = data;
475 DBG("network %p", network);
477 __connman_network_set_device(network, NULL);
479 connman_network_unref(network);
482 static void device_destruct(struct connman_device *device)
484 DBG("device %p name %s", device, device->name);
486 clear_pending_trigger(device);
487 clear_scan_trigger(device);
489 g_free(device->ident);
490 g_free(device->node);
491 g_free(device->name);
492 g_free(device->address);
493 g_free(device->interface);
494 g_free(device->path);
495 g_free(device->devname);
497 g_free(device->last_network);
499 g_hash_table_destroy(device->networks);
500 device->networks = NULL;
505 #if defined TIZEN_EXT
506 connman_bool_t connman_device_load_significant_wifi_profile_refcount_from_storage(struct connman_device *device)
508 GKeyFile *keyfile = NULL;
510 keyfile = __connman_storage_load_global();
512 if (g_key_file_has_group(keyfile, CONNMAN_SIG_WIFI_REFCOUNT_GROUP_NAME) == FALSE) {
513 g_key_file_free(keyfile);
517 __connman_device_set_significant_wifi_profile_refcount(device,
518 g_key_file_get_integer(keyfile, CONNMAN_SIG_WIFI_REFCOUNT_GROUP_NAME, "ReferenceCount", NULL));
520 g_key_file_free(keyfile);
524 connman_bool_t connman_device_save_significant_wifi_profile_refcount_to_storage(struct connman_device *device)
526 GKeyFile *keyfile = NULL;
528 keyfile = __connman_storage_load_global();
530 g_key_file_set_integer(keyfile, CONNMAN_SIG_WIFI_REFCOUNT_GROUP_NAME, "ReferenceCount",
531 device->significant_wifi_profile_refcount);
533 __connman_storage_save_global(keyfile);
535 g_key_file_free(keyfile);
541 * connman_device_create:
542 * @node: device node name (for example an address)
545 * Allocate a new device of given #type and assign the #node name to it.
547 * Returns: a newly-allocated #connman_device structure
549 struct connman_device *connman_device_create(const char *node,
550 enum connman_device_type type)
552 struct connman_device *device;
553 connman_bool_t bg_scan;
555 DBG("node %s type %d", node, type);
557 device = g_try_new0(struct connman_device, 1);
561 DBG("device %p", device);
563 device->refcount = 1;
565 bg_scan = connman_setting_get_bool("BackgroundScanning");
567 #if defined TIZEN_EXT
568 if (type == CONNMAN_DEVICE_TYPE_WIFI) {
569 /* Load significant_wifi_profile_refcount */
570 if (connman_device_load_significant_wifi_profile_refcount_from_storage(device) == FALSE) {
571 __connman_device_set_significant_wifi_profile_refcount(device, 0);
572 connman_device_save_significant_wifi_profile_refcount_to_storage(device);
575 __connman_device_set_significant_wifi_profile_refcount(device, 0);
578 device->name = g_strdup(type2description(device->type));
580 device->phyindex = -1;
582 device->backoff_interval = SCAN_INITIAL_DELAY;
585 case CONNMAN_DEVICE_TYPE_UNKNOWN:
586 case CONNMAN_DEVICE_TYPE_ETHERNET:
587 case CONNMAN_DEVICE_TYPE_WIMAX:
588 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
589 case CONNMAN_DEVICE_TYPE_CELLULAR:
590 case CONNMAN_DEVICE_TYPE_GPS:
591 case CONNMAN_DEVICE_TYPE_GADGET:
592 case CONNMAN_DEVICE_TYPE_VENDOR:
593 device->scan_interval = 0;
595 case CONNMAN_DEVICE_TYPE_WIFI:
597 device->scan_interval = 300;
599 device->scan_interval = 0;
603 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
604 g_free, free_network);
606 device_list = g_slist_append(device_list, device);
612 * connman_device_ref:
613 * @device: device structure
615 * Increase reference counter of device
617 struct connman_device *connman_device_ref(struct connman_device *device)
621 __sync_fetch_and_add(&device->refcount, 1);
627 * connman_device_unref:
628 * @device: device structure
630 * Decrease reference counter of device
632 void connman_device_unref(struct connman_device *device)
634 if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
637 if (device->driver) {
638 device->driver->remove(device);
639 device->driver = NULL;
642 device_list = g_slist_remove(device_list, device);
644 device_destruct(device);
647 const char *__connman_device_get_type(struct connman_device *device)
649 return type2string(device->type);
653 * connman_device_get_type:
654 * @device: device structure
658 enum connman_device_type connman_device_get_type(struct connman_device *device)
664 * connman_device_set_index:
665 * @device: device structure
666 * @index: index number
668 * Set index number of device
670 void connman_device_set_index(struct connman_device *device, int index)
672 device->index = index;
676 * connman_device_get_index:
677 * @device: device structure
679 * Get index number of device
681 int connman_device_get_index(struct connman_device *device)
683 return device->index;
686 int __connman_device_get_phyindex(struct connman_device *device)
688 return device->phyindex;
691 void __connman_device_set_phyindex(struct connman_device *device,
694 device->phyindex = phyindex;
698 * connman_device_set_interface:
699 * @device: device structure
700 * @interface: interface name
702 * Set interface name of device
704 void connman_device_set_interface(struct connman_device *device,
705 const char *interface)
707 g_free(device->devname);
708 device->devname = g_strdup(interface);
710 g_free(device->interface);
711 device->interface = g_strdup(interface);
713 if (device->name == NULL) {
714 const char *str = type2description(device->type);
715 if (str != NULL && device->interface != NULL)
716 device->name = g_strdup_printf("%s (%s)", str,
722 * connman_device_set_ident:
723 * @device: device structure
724 * @ident: unique identifier
726 * Set unique identifier of device
728 void connman_device_set_ident(struct connman_device *device,
731 g_free(device->ident);
732 device->ident = g_strdup(ident);
735 const char *connman_device_get_ident(struct connman_device *device)
737 return device->ident;
741 * connman_device_set_powered:
742 * @device: device structure
743 * @powered: powered state
745 * Change power state of device
747 int connman_device_set_powered(struct connman_device *device,
748 connman_bool_t powered)
750 enum connman_service_type type;
752 DBG("driver %p powered %d", device, powered);
754 if (device->powered == powered)
757 clear_pending_trigger(device);
759 device->powered_pending = PENDING_NONE;
761 device->powered = powered;
763 type = __connman_device_get_service_type(device);
765 if (device->powered == TRUE)
766 __connman_technology_enabled(type);
768 __connman_technology_disabled(type);
770 if (powered == FALSE)
773 connman_device_set_disconnected(device, FALSE);
774 device->scanning = FALSE;
776 reset_scan_trigger(device);
778 if (device->driver && device->driver->scan_fast)
779 device->driver->scan_fast(device);
780 else if (device->driver && device->driver->scan)
781 device->driver->scan(device);
786 static int device_scan(struct connman_device *device)
788 if (!device->driver || !device->driver->scan)
791 if (device->powered == FALSE)
794 #if defined TIZEN_EXT
798 g_hash_table_iter_init(&iter, device->networks);
800 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
801 struct connman_network *network = value;
803 DBG("network type %s", __connman_network_get_type(network));
804 if (connman_network_get_type(network) != CONNMAN_NETWORK_TYPE_WIFI)
807 /* If there is connecting network, don't try to scan. */
808 if (connman_network_get_connecting(network) == TRUE ||
809 connman_network_get_associating(network) == TRUE) {
810 DBG("network(%s) is connecting", connman_network_get_string(network, "Name"));
816 reset_scan_trigger(device);
818 return device->driver->scan(device);
821 int __connman_device_disconnect(struct connman_device *device)
826 DBG("device %p", device);
828 connman_device_set_disconnected(device, TRUE);
830 g_hash_table_iter_init(&iter, device->networks);
832 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
833 struct connman_network *network = value;
835 if (connman_network_get_connecting(network) == TRUE) {
837 * Skip network in the process of connecting.
838 * This is a workaround for WiFi networks serviced
839 * by the supplicant plugin that hold a reference
840 * to the network. If we disconnect the network
841 * here then the referenced object will not be
842 * registered and usage (like launching DHCP client)
843 * will fail. There is nothing to be gained by
844 * removing the network here anyway.
846 connman_warn("Skipping disconnect of %s, network is connecting.",
847 connman_network_get_identifier(network));
851 __connman_network_disconnect(network);
857 static void mark_network_available(gpointer key, gpointer value,
860 struct connman_network *network = value;
862 connman_network_set_available(network, TRUE);
865 static void mark_network_unavailable(gpointer key, gpointer value,
868 struct connman_network *network = value;
870 if (connman_network_get_connected(network) == TRUE)
873 connman_network_set_available(network, FALSE);
876 static gboolean remove_unavailable_network(gpointer key, gpointer value,
879 struct connman_network *network = value;
881 if (connman_network_get_connected(network) == TRUE)
884 if (connman_network_get_available(network) == TRUE)
890 void __connman_device_cleanup_networks(struct connman_device *device)
892 g_hash_table_foreach_remove(device->networks,
893 remove_unavailable_network, NULL);
896 connman_bool_t connman_device_get_scanning(struct connman_device *device)
898 return device->scanning;
901 void connman_device_reset_scanning(struct connman_device *device)
903 device->scanning = FALSE;
905 g_hash_table_foreach(device->networks,
906 mark_network_available, NULL);
908 #if defined TIZEN_EXT
910 * August 22nd, 2011. TIZEN
912 * This part is added to send a DBus signal which means scan is completed
913 * because scan UX of a Wi-Fi setting application has an active scan procedure
914 * and it needs scan complete signal whether success or not
916 __connman_notifier_scan_completed(FALSE);
921 * connman_device_set_scanning:
922 * @device: device structure
923 * @scanning: scanning state
925 * Change scanning state of device
927 int connman_device_set_scanning(struct connman_device *device,
928 connman_bool_t scanning)
930 DBG("device %p scanning %d", device, scanning);
932 if (!device->driver || !device->driver->scan)
935 if (device->scanning == scanning)
938 device->scanning = scanning;
940 if (scanning == TRUE) {
941 reset_scan_trigger(device);
943 g_hash_table_foreach(device->networks,
944 mark_network_unavailable, NULL);
949 __connman_device_cleanup_networks(device);
951 #if defined TIZEN_EXT
953 * August 22nd, 2011. TIZEN
955 * This part is added to send a DBus signal which means scan is completed
956 * because scan UX of a Wi-Fi setting application has an active scan procedure
957 * and it needs scan complete signal whether success or not
959 __connman_notifier_scan_completed(TRUE);
962 __connman_service_auto_connect();
968 * connman_device_set_disconnected:
969 * @device: device structure
970 * @disconnected: disconnected state
972 * Change disconnected state of device (only for device with networks)
974 int connman_device_set_disconnected(struct connman_device *device,
975 connman_bool_t disconnected)
977 DBG("device %p disconnected %d", device, disconnected);
979 if (device->disconnected == disconnected)
982 device->disconnected = disconnected;
984 #if defined TIZEN_EXT
985 if (device->type == CONNMAN_DEVICE_TYPE_CELLULAR)
987 DBG("Cellular device does not need to scan.");
992 if (disconnected == TRUE)
994 force_scan_trigger(device);
995 device->backoff_interval = SCAN_INITIAL_DELAY;
1002 * connman_device_get_disconnected:
1003 * @device: device structure
1005 * Get device disconnected state
1007 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
1009 return device->disconnected;
1013 * connman_device_set_string:
1014 * @device: device structure
1015 * @key: unique identifier
1016 * @value: string value
1018 * Set string value for specific key
1020 int connman_device_set_string(struct connman_device *device,
1021 const char *key, const char *value)
1023 DBG("device %p key %s value %s", device, key, value);
1025 if (g_str_equal(key, "Address") == TRUE) {
1026 g_free(device->address);
1027 device->address = g_strdup(value);
1028 } else if (g_str_equal(key, "Name") == TRUE) {
1029 g_free(device->name);
1030 device->name = g_strdup(value);
1031 } else if (g_str_equal(key, "Node") == TRUE) {
1032 g_free(device->node);
1033 device->node = g_strdup(value);
1034 } else if (g_str_equal(key, "Path") == TRUE) {
1035 g_free(device->path);
1036 device->path = g_strdup(value);
1045 * connman_device_get_string:
1046 * @device: device structure
1047 * @key: unique identifier
1049 * Get string value for specific key
1051 const char *connman_device_get_string(struct connman_device *device,
1054 DBG("device %p key %s", device, key);
1056 if (g_str_equal(key, "Address") == TRUE)
1057 return device->address;
1058 else if (g_str_equal(key, "Name") == TRUE)
1059 return device->name;
1060 else if (g_str_equal(key, "Node") == TRUE)
1061 return device->node;
1062 else if (g_str_equal(key, "Interface") == TRUE)
1063 return device->interface;
1064 else if (g_str_equal(key, "Path") == TRUE)
1065 return device->path;
1071 * connman_device_add_network:
1072 * @device: device structure
1073 * @network: network structure
1075 * Add new network to the device
1077 int connman_device_add_network(struct connman_device *device,
1078 struct connman_network *network)
1080 const char *identifier = connman_network_get_identifier(network);
1082 DBG("device %p network %p", device, network);
1084 if (identifier == NULL)
1087 connman_network_ref(network);
1089 __connman_network_set_device(network, device);
1091 g_hash_table_insert(device->networks, g_strdup(identifier),
1098 * connman_device_get_network:
1099 * @device: device structure
1100 * @identifier: network identifier
1102 * Get network for given identifier
1104 struct connman_network *connman_device_get_network(struct connman_device *device,
1105 const char *identifier)
1107 DBG("device %p identifier %s", device, identifier);
1109 return g_hash_table_lookup(device->networks, identifier);
1113 * connman_device_remove_network:
1114 * @device: device structure
1115 * @identifier: network identifier
1117 * Remove network for given identifier
1119 int connman_device_remove_network(struct connman_device *device,
1120 struct connman_network *network)
1122 const char *identifier;
1124 DBG("device %p network %p", device, network);
1126 if (network == NULL)
1129 identifier = connman_network_get_identifier(network);
1130 g_hash_table_remove(device->networks, identifier);
1135 void connman_device_remove_all_networks(struct connman_device *device)
1137 g_hash_table_remove_all(device->networks);
1140 void __connman_device_set_network(struct connman_device *device,
1141 struct connman_network *network)
1148 if (device->network == network)
1151 if (network != NULL) {
1152 name = connman_network_get_string(network, "Name");
1153 g_free(device->last_network);
1154 device->last_network = g_strdup(name);
1156 device->network = network;
1158 g_free(device->last_network);
1159 device->last_network = NULL;
1161 device->network = NULL;
1165 void __connman_device_set_reconnect(struct connman_device *device,
1166 connman_bool_t reconnect)
1168 device->reconnect = reconnect;
1171 connman_bool_t __connman_device_get_reconnect(
1172 struct connman_device *device)
1174 return device->reconnect;
1177 static gboolean match_driver(struct connman_device *device,
1178 struct connman_device_driver *driver)
1180 if (device->type == driver->type ||
1181 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1188 * connman_device_register:
1189 * @device: device structure
1191 * Register device with the system
1193 int connman_device_register(struct connman_device *device)
1197 DBG("device %p name %s", device, device->name);
1199 if (device->driver != NULL)
1202 for (list = driver_list; list; list = list->next) {
1203 struct connman_device_driver *driver = list->data;
1205 if (match_driver(device, driver) == FALSE)
1208 DBG("driver %p name %s", driver, driver->name);
1210 if (driver->probe(device) == 0) {
1211 device->driver = driver;
1216 if (device->driver == NULL)
1219 return __connman_technology_add_device(device);
1223 * connman_device_unregister:
1224 * @device: device structure
1226 * Unregister device with the system
1228 void connman_device_unregister(struct connman_device *device)
1230 DBG("device %p name %s", device, device->name);
1232 if (device->driver == NULL)
1235 remove_device(device);
1239 * connman_device_get_data:
1240 * @device: device structure
1242 * Get private device data pointer
1244 void *connman_device_get_data(struct connman_device *device)
1246 return device->driver_data;
1250 * connman_device_set_data:
1251 * @device: device structure
1252 * @data: data pointer
1254 * Set private device data pointer
1256 void connman_device_set_data(struct connman_device *device, void *data)
1258 device->driver_data = data;
1261 struct connman_device *__connman_device_find_device(
1262 enum connman_service_type type)
1266 for (list = device_list; list != NULL; list = list->next) {
1267 struct connman_device *device = list->data;
1268 enum connman_service_type service_type =
1269 __connman_device_get_service_type(device);
1271 if (service_type != type)
1280 int __connman_device_request_scan(enum connman_service_type type)
1286 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1287 case CONNMAN_SERVICE_TYPE_SYSTEM:
1288 case CONNMAN_SERVICE_TYPE_ETHERNET:
1289 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1290 case CONNMAN_SERVICE_TYPE_CELLULAR:
1291 case CONNMAN_SERVICE_TYPE_GPS:
1292 case CONNMAN_SERVICE_TYPE_VPN:
1293 case CONNMAN_SERVICE_TYPE_GADGET:
1295 case CONNMAN_SERVICE_TYPE_WIFI:
1296 case CONNMAN_SERVICE_TYPE_WIMAX:
1300 for (list = device_list; list != NULL; list = list->next) {
1301 struct connman_device *device = list->data;
1302 enum connman_service_type service_type =
1303 __connman_device_get_service_type(device);
1305 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
1306 service_type != type) {
1310 err = device_scan(device);
1311 if (err < 0 && err != -EINPROGRESS) {
1313 /* XXX maybe only a continue? */
1321 connman_bool_t __connman_device_isfiltered(const char *devname)
1325 if (device_filter == NULL)
1328 for (pattern = device_filter; *pattern; pattern++) {
1329 if (g_pattern_match_simple(*pattern, devname) == FALSE) {
1330 DBG("ignoring device %s (match)", devname);
1336 if (g_pattern_match_simple("dummy*", devname) == TRUE) {
1337 DBG("ignoring dummy networking devices");
1341 if (nodevice_filter == NULL)
1344 for (pattern = nodevice_filter; *pattern; pattern++) {
1345 if (g_pattern_match_simple(*pattern, devname) == TRUE) {
1346 DBG("ignoring device %s (no match)", devname);
1354 int __connman_device_init(const char *device, const char *nodevice)
1359 device_filter = g_strsplit(device, ",", -1);
1361 if (nodevice != NULL)
1362 nodevice_filter = g_strsplit(nodevice, ",", -1);
1367 void __connman_device_cleanup(void)
1371 g_strfreev(nodevice_filter);
1372 g_strfreev(device_filter);