5 * Copyright (C) 2007-2014 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 #include <sys/ioctl.h>
32 #include <net/ethernet.h>
37 static GSList *device_list = NULL;
38 static gchar **device_filter = NULL;
39 static gchar **nodevice_filter = NULL;
41 enum connman_pending_type {
47 struct connman_device {
49 enum connman_device_type type;
50 enum connman_pending_type powered_pending; /* Indicates a pending
64 guint pending_timeout;
66 struct connman_device_driver *driver;
70 struct connman_network *network;
74 static void clear_pending_trigger(struct connman_device *device)
76 if (device->pending_timeout > 0) {
77 g_source_remove(device->pending_timeout);
78 device->pending_timeout = 0;
82 static const char *type2description(enum connman_device_type type)
85 case CONNMAN_DEVICE_TYPE_UNKNOWN:
86 case CONNMAN_DEVICE_TYPE_VENDOR:
88 case CONNMAN_DEVICE_TYPE_ETHERNET:
90 case CONNMAN_DEVICE_TYPE_WIFI:
92 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
94 case CONNMAN_DEVICE_TYPE_GPS:
96 case CONNMAN_DEVICE_TYPE_CELLULAR:
98 case CONNMAN_DEVICE_TYPE_GADGET:
106 static const char *type2string(enum connman_device_type type)
109 case CONNMAN_DEVICE_TYPE_UNKNOWN:
110 case CONNMAN_DEVICE_TYPE_VENDOR:
112 case CONNMAN_DEVICE_TYPE_ETHERNET:
114 case CONNMAN_DEVICE_TYPE_WIFI:
116 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
118 case CONNMAN_DEVICE_TYPE_GPS:
120 case CONNMAN_DEVICE_TYPE_CELLULAR:
122 case CONNMAN_DEVICE_TYPE_GADGET:
130 enum connman_service_type __connman_device_get_service_type(
131 struct connman_device *device)
133 enum connman_device_type type = connman_device_get_type(device);
136 case CONNMAN_DEVICE_TYPE_UNKNOWN:
137 case CONNMAN_DEVICE_TYPE_VENDOR:
138 case CONNMAN_DEVICE_TYPE_GPS:
140 case CONNMAN_DEVICE_TYPE_ETHERNET:
141 return CONNMAN_SERVICE_TYPE_ETHERNET;
142 case CONNMAN_DEVICE_TYPE_WIFI:
143 return CONNMAN_SERVICE_TYPE_WIFI;
144 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
145 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
146 case CONNMAN_DEVICE_TYPE_CELLULAR:
147 return CONNMAN_SERVICE_TYPE_CELLULAR;
148 case CONNMAN_DEVICE_TYPE_GADGET:
149 return CONNMAN_SERVICE_TYPE_GADGET;
153 return CONNMAN_SERVICE_TYPE_UNKNOWN;
156 static gboolean device_pending_reset(gpointer user_data)
158 struct connman_device *device = user_data;
160 DBG("device %p", device);
162 /* Power request timedout, reset power pending state. */
163 device->pending_timeout = 0;
164 device->powered_pending = PENDING_NONE;
169 int __connman_device_enable(struct connman_device *device)
173 DBG("device %p", device);
175 if (!device->driver || !device->driver->enable)
178 /* There is an ongoing power disable request. */
179 if (device->powered_pending == PENDING_DISABLE)
182 if (device->powered_pending == PENDING_ENABLE)
185 if (device->powered_pending == PENDING_NONE && device->powered)
188 device->powered_pending = PENDING_ENABLE;
190 err = device->driver->enable(device);
192 * device gets enabled right away.
193 * Invoke the callback
196 connman_device_set_powered(device, true);
200 if (err == -EALREADY) {
201 /* If device is already powered, but connman is not updated */
202 connman_device_set_powered(device, true);
206 * if err == -EINPROGRESS, then the DBus call to the respective daemon
207 * was successful. We set a 4 sec timeout so if the daemon never
208 * returns a reply, we would reset the pending request.
210 if (err == -EINPROGRESS)
211 device->pending_timeout = g_timeout_add_seconds(4,
212 device_pending_reset, device);
217 int __connman_device_disable(struct connman_device *device)
221 DBG("device %p", device);
223 /* Ongoing power enable request */
224 if (device->powered_pending == PENDING_ENABLE)
227 if (device->powered_pending == PENDING_DISABLE)
230 if (device->powered_pending == PENDING_NONE && !device->powered)
233 device->powered_pending = PENDING_DISABLE;
235 if (device->network) {
236 struct connman_service *service =
237 connman_service_lookup_from_network(device->network);
240 __connman_service_disconnect(service);
242 connman_network_set_connected(device->network, false);
245 if (!device->driver || !device->driver->disable)
248 err = device->driver->disable(device);
249 if (err == 0 || err == -EALREADY) {
250 connman_device_set_powered(device, false);
254 if (err == -EINPROGRESS)
255 device->pending_timeout = g_timeout_add_seconds(4,
256 device_pending_reset, device);
261 static void probe_driver(struct connman_device_driver *driver)
265 DBG("driver %p name %s", driver, driver->name);
267 for (list = device_list; list; list = list->next) {
268 struct connman_device *device = list->data;
273 if (driver->type != device->type)
276 if (driver->probe(device) < 0)
279 device->driver = driver;
281 __connman_technology_add_device(device);
285 static void remove_device(struct connman_device *device)
287 DBG("device %p", device);
289 __connman_device_disable(device);
291 __connman_technology_remove_device(device);
293 if (device->driver->remove)
294 device->driver->remove(device);
296 device->driver = NULL;
299 static void remove_driver(struct connman_device_driver *driver)
303 DBG("driver %p name %s", driver, driver->name);
305 for (list = device_list; list; list = list->next) {
306 struct connman_device *device = list->data;
308 if (device->driver == driver)
309 remove_device(device);
313 bool __connman_device_has_driver(struct connman_device *device)
315 if (!device || !device->driver)
321 static GSList *driver_list = NULL;
323 static gint compare_priority(gconstpointer a, gconstpointer b)
325 const struct connman_device_driver *driver1 = a;
326 const struct connman_device_driver *driver2 = b;
328 return driver2->priority - driver1->priority;
332 * connman_device_driver_register:
333 * @driver: device driver definition
335 * Register a new device driver
337 * Returns: %0 on success
339 int connman_device_driver_register(struct connman_device_driver *driver)
341 DBG("driver %p name %s", driver, driver->name);
343 driver_list = g_slist_insert_sorted(driver_list, driver,
345 probe_driver(driver);
351 * connman_device_driver_unregister:
352 * @driver: device driver definition
354 * Remove a previously registered device driver
356 void connman_device_driver_unregister(struct connman_device_driver *driver)
358 DBG("driver %p name %s", driver, driver->name);
360 driver_list = g_slist_remove(driver_list, driver);
362 remove_driver(driver);
365 static void free_network(gpointer data)
367 struct connman_network *network = data;
369 DBG("network %p", network);
371 __connman_network_set_device(network, NULL);
373 connman_network_unref(network);
376 static void device_destruct(struct connman_device *device)
378 DBG("device %p name %s", device, device->name);
380 clear_pending_trigger(device);
382 g_free(device->ident);
383 g_free(device->node);
384 g_free(device->name);
385 g_free(device->address);
386 g_free(device->interface);
387 g_free(device->path);
389 g_free(device->last_network);
391 g_hash_table_destroy(device->networks);
392 device->networks = NULL;
398 * connman_device_create:
399 * @node: device node name (for example an address)
402 * Allocate a new device of given #type and assign the #node name to it.
404 * Returns: a newly-allocated #connman_device structure
406 struct connman_device *connman_device_create(const char *node,
407 enum connman_device_type type)
409 struct connman_device *device;
411 DBG("node %s type %d", node, type);
413 device = g_try_new0(struct connman_device, 1);
417 DBG("device %p", device);
419 device->refcount = 1;
422 device->name = g_strdup(type2description(device->type));
424 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
425 g_free, free_network);
427 device_list = g_slist_prepend(device_list, device);
433 * connman_device_ref:
434 * @device: device structure
436 * Increase reference counter of device
438 struct connman_device *connman_device_ref_debug(struct connman_device *device,
439 const char *file, int line, const char *caller)
441 DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
444 __sync_fetch_and_add(&device->refcount, 1);
450 * connman_device_unref:
451 * @device: device structure
453 * Decrease reference counter of device
455 void connman_device_unref_debug(struct connman_device *device,
456 const char *file, int line, const char *caller)
458 DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1,
461 if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
464 if (device->driver) {
465 device->driver->remove(device);
466 device->driver = NULL;
469 device_list = g_slist_remove(device_list, device);
471 device_destruct(device);
474 const char *__connman_device_get_type(struct connman_device *device)
476 return type2string(device->type);
480 * connman_device_get_type:
481 * @device: device structure
485 enum connman_device_type connman_device_get_type(struct connman_device *device)
491 * connman_device_set_index:
492 * @device: device structure
493 * @index: index number
495 * Set index number of device
497 void connman_device_set_index(struct connman_device *device, int index)
499 device->index = index;
503 * connman_device_get_index:
504 * @device: device structure
506 * Get index number of device
508 int connman_device_get_index(struct connman_device *device)
510 return device->index;
514 * connman_device_set_interface:
515 * @device: device structure
516 * @interface: interface name
518 * Set interface name of device
520 void connman_device_set_interface(struct connman_device *device,
521 const char *interface)
523 g_free(device->interface);
524 device->interface = g_strdup(interface);
527 const char *str = type2description(device->type);
528 if (str && device->interface)
529 device->name = g_strdup_printf("%s (%s)", str,
535 * connman_device_set_ident:
536 * @device: device structure
537 * @ident: unique identifier
539 * Set unique identifier of device
541 void connman_device_set_ident(struct connman_device *device,
544 g_free(device->ident);
545 device->ident = g_strdup(ident);
548 const char *connman_device_get_ident(struct connman_device *device)
550 return device->ident;
554 * connman_device_set_powered:
555 * @device: device structure
556 * @powered: powered state
558 * Change power state of device
560 int connman_device_set_powered(struct connman_device *device,
563 enum connman_service_type type;
565 DBG("driver %p powered %d", device, powered);
567 if (device->powered == powered)
570 clear_pending_trigger(device);
572 device->powered_pending = PENDING_NONE;
574 device->powered = powered;
576 type = __connman_device_get_service_type(device);
578 if (!device->powered) {
579 __connman_technology_disabled(type);
583 __connman_technology_enabled(type);
585 connman_device_set_disconnected(device, false);
586 device->scanning = false;
588 if (device->driver && device->driver->scan)
589 device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN, device,
590 NULL, 0, NULL, NULL, NULL, NULL);
595 bool connman_device_get_powered(struct connman_device *device)
597 return device->powered;
600 static int device_scan(enum connman_service_type type,
601 struct connman_device *device)
603 if (!device->driver || !device->driver->scan)
606 if (!device->powered)
609 return device->driver->scan(type, device, NULL, 0,
610 NULL, NULL, NULL, NULL);
613 int __connman_device_disconnect(struct connman_device *device)
618 DBG("device %p", device);
620 connman_device_set_disconnected(device, true);
622 g_hash_table_iter_init(&iter, device->networks);
624 while (g_hash_table_iter_next(&iter, &key, &value)) {
625 struct connman_network *network = value;
627 if (connman_network_get_connecting(network)) {
629 * Skip network in the process of connecting.
630 * This is a workaround for WiFi networks serviced
631 * by the supplicant plugin that hold a reference
632 * to the network. If we disconnect the network
633 * here then the referenced object will not be
634 * registered and usage (like launching DHCP client)
635 * will fail. There is nothing to be gained by
636 * removing the network here anyway.
638 connman_warn("Skipping disconnect of %s, network is connecting.",
639 connman_network_get_identifier(network));
643 __connman_network_disconnect(network);
649 int connman_device_reconnect_service(struct connman_device *device)
651 DBG("device %p", device);
653 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
658 static void mark_network_available(gpointer key, gpointer value,
661 struct connman_network *network = value;
663 connman_network_set_available(network, true);
666 static void mark_network_unavailable(gpointer key, gpointer value,
669 struct connman_network *network = value;
671 if (connman_network_get_connected(network) ||
672 connman_network_get_connecting(network))
675 connman_network_set_available(network, false);
678 static gboolean remove_unavailable_network(gpointer key, gpointer value,
681 struct connman_network *network = value;
683 if (connman_network_get_connected(network))
686 if (connman_network_get_available(network))
692 void __connman_device_cleanup_networks(struct connman_device *device)
694 g_hash_table_foreach_remove(device->networks,
695 remove_unavailable_network, NULL);
698 bool connman_device_get_scanning(struct connman_device *device)
700 return device->scanning;
703 void connman_device_reset_scanning(struct connman_device *device)
705 g_hash_table_foreach(device->networks,
706 mark_network_available, NULL);
710 * connman_device_set_scanning:
711 * @device: device structure
712 * @scanning: scanning state
714 * Change scanning state of device
716 int connman_device_set_scanning(struct connman_device *device,
717 enum connman_service_type type, bool scanning)
719 DBG("device %p scanning %d", device, scanning);
721 if (!device->driver || !device->driver->scan)
724 if (device->scanning == scanning)
727 device->scanning = scanning;
730 __connman_technology_scan_started(device);
732 g_hash_table_foreach(device->networks,
733 mark_network_unavailable, NULL);
738 __connman_device_cleanup_networks(device);
740 __connman_technology_scan_stopped(device, type);
742 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
748 * connman_device_set_disconnected:
749 * @device: device structure
750 * @disconnected: disconnected state
752 * Change disconnected state of device (only for device with networks)
754 int connman_device_set_disconnected(struct connman_device *device,
757 DBG("device %p disconnected %d", device, disconnected);
759 if (device->disconnected == disconnected)
762 device->disconnected = disconnected;
768 * connman_device_get_disconnected:
769 * @device: device structure
771 * Get device disconnected state
773 bool connman_device_get_disconnected(struct connman_device *device)
775 return device->disconnected;
779 * connman_device_set_string:
780 * @device: device structure
781 * @key: unique identifier
782 * @value: string value
784 * Set string value for specific key
786 int connman_device_set_string(struct connman_device *device,
787 const char *key, const char *value)
789 DBG("device %p key %s value %s", device, key, value);
791 if (g_str_equal(key, "Address")) {
792 g_free(device->address);
793 device->address = g_strdup(value);
794 } else if (g_str_equal(key, "Name")) {
795 g_free(device->name);
796 device->name = g_strdup(value);
797 } else if (g_str_equal(key, "Node")) {
798 g_free(device->node);
799 device->node = g_strdup(value);
800 } else if (g_str_equal(key, "Path")) {
801 g_free(device->path);
802 device->path = g_strdup(value);
811 * connman_device_get_string:
812 * @device: device structure
813 * @key: unique identifier
815 * Get string value for specific key
817 const char *connman_device_get_string(struct connman_device *device,
820 DBG("device %p key %s", device, key);
822 if (g_str_equal(key, "Address"))
823 return device->address;
824 else if (g_str_equal(key, "Name"))
826 else if (g_str_equal(key, "Node"))
828 else if (g_str_equal(key, "Interface"))
829 return device->interface;
830 else if (g_str_equal(key, "Path"))
837 * connman_device_add_network:
838 * @device: device structure
839 * @network: network structure
841 * Add new network to the device
843 int connman_device_add_network(struct connman_device *device,
844 struct connman_network *network)
846 const char *identifier = connman_network_get_identifier(network);
848 DBG("device %p network %p", device, network);
853 connman_network_ref(network);
855 __connman_network_set_device(network, device);
857 g_hash_table_replace(device->networks, g_strdup(identifier),
864 * connman_device_get_network:
865 * @device: device structure
866 * @identifier: network identifier
868 * Get network for given identifier
870 struct connman_network *connman_device_get_network(struct connman_device *device,
871 const char *identifier)
873 DBG("device %p identifier %s", device, identifier);
875 return g_hash_table_lookup(device->networks, identifier);
879 * connman_device_remove_network:
880 * @device: device structure
881 * @identifier: network identifier
883 * Remove network for given identifier
885 int connman_device_remove_network(struct connman_device *device,
886 struct connman_network *network)
888 const char *identifier;
890 DBG("device %p network %p", device, network);
895 identifier = connman_network_get_identifier(network);
896 g_hash_table_remove(device->networks, identifier);
901 void __connman_device_set_network(struct connman_device *device,
902 struct connman_network *network)
909 if (device->network == network)
913 name = connman_network_get_string(network, "Name");
914 g_free(device->last_network);
915 device->last_network = g_strdup(name);
917 device->network = network;
919 g_free(device->last_network);
920 device->last_network = NULL;
922 device->network = NULL;
926 static bool match_driver(struct connman_device *device,
927 struct connman_device_driver *driver)
929 if (device->type == driver->type ||
930 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
937 * connman_device_register:
938 * @device: device structure
940 * Register device with the system
942 int connman_device_register(struct connman_device *device)
946 DBG("device %p name %s", device, device->name);
951 for (list = driver_list; list; list = list->next) {
952 struct connman_device_driver *driver = list->data;
954 if (!match_driver(device, driver))
957 DBG("driver %p name %s", driver, driver->name);
959 if (driver->probe(device) == 0) {
960 device->driver = driver;
968 return __connman_technology_add_device(device);
972 * connman_device_unregister:
973 * @device: device structure
975 * Unregister device with the system
977 void connman_device_unregister(struct connman_device *device)
979 DBG("device %p name %s", device, device->name);
984 remove_device(device);
988 * connman_device_get_data:
989 * @device: device structure
991 * Get private device data pointer
993 void *connman_device_get_data(struct connman_device *device)
995 return device->driver_data;
999 * connman_device_set_data:
1000 * @device: device structure
1001 * @data: data pointer
1003 * Set private device data pointer
1005 void connman_device_set_data(struct connman_device *device, void *data)
1007 device->driver_data = data;
1010 struct connman_device *__connman_device_find_device(
1011 enum connman_service_type type)
1015 for (list = device_list; list; list = list->next) {
1016 struct connman_device *device = list->data;
1017 enum connman_service_type service_type =
1018 __connman_device_get_service_type(device);
1020 if (service_type != type)
1029 struct connman_device *connman_device_find_by_index(int index)
1033 for (list = device_list; list; list = list->next) {
1034 struct connman_device *device = list->data;
1035 if (device->index == index)
1043 * connman_device_set_regdom
1044 * @device: device structure
1045 * @alpha2: string representing regulatory domain
1047 * Set regulatory domain on device basis
1049 int connman_device_set_regdom(struct connman_device *device,
1052 if (!device->driver || !device->driver->set_regdom)
1055 if (!device->powered)
1058 return device->driver->set_regdom(device, alpha2);
1062 * connman_device_regdom_notify
1063 * @device: device structure
1064 * @alpha2: string representing regulatory domain
1066 * Notify on setting regulatory domain on device basis
1068 void connman_device_regdom_notify(struct connman_device *device,
1069 int result, const char *alpha2)
1071 __connman_technology_notify_regdom_by_device(device, result, alpha2);
1074 int __connman_device_request_scan(enum connman_service_type type)
1076 bool success = false;
1077 int last_err = -ENOSYS;
1082 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1083 case CONNMAN_SERVICE_TYPE_SYSTEM:
1084 case CONNMAN_SERVICE_TYPE_ETHERNET:
1085 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1086 case CONNMAN_SERVICE_TYPE_CELLULAR:
1087 case CONNMAN_SERVICE_TYPE_GPS:
1088 case CONNMAN_SERVICE_TYPE_VPN:
1089 case CONNMAN_SERVICE_TYPE_GADGET:
1091 case CONNMAN_SERVICE_TYPE_WIFI:
1092 case CONNMAN_SERVICE_TYPE_P2P:
1096 for (list = device_list; list; list = list->next) {
1097 struct connman_device *device = list->data;
1098 enum connman_service_type service_type =
1099 __connman_device_get_service_type(device);
1101 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1102 if (type == CONNMAN_SERVICE_TYPE_P2P) {
1103 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1105 } else if (service_type != type)
1109 err = device_scan(type, device);
1110 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1114 DBG("device %p err %d", device, err);
1124 int __connman_device_request_hidden_scan(struct connman_device *device,
1125 const char *ssid, unsigned int ssid_len,
1126 const char *identity, const char *passphrase,
1127 const char *security, void *user_data)
1129 DBG("device %p", device);
1131 if (!device || !device->driver ||
1132 !device->driver->scan)
1135 return device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN,
1136 device, ssid, ssid_len, identity,
1137 passphrase, security, user_data);
1140 static char *index2ident(int index, const char *prefix)
1143 struct ether_addr eth;
1150 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1154 memset(&ifr, 0, sizeof(ifr));
1155 ifr.ifr_ifindex = index;
1157 err = ioctl(sk, SIOCGIFNAME, &ifr);
1160 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1167 len = prefix ? strlen(prefix) + 18 : 18;
1169 str = g_malloc(len);
1173 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1174 snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
1175 prefix ? prefix : "",
1176 eth.ether_addr_octet[0],
1177 eth.ether_addr_octet[1],
1178 eth.ether_addr_octet[2],
1179 eth.ether_addr_octet[3],
1180 eth.ether_addr_octet[4],
1181 eth.ether_addr_octet[5]);
1186 static char *index2addr(int index)
1189 struct ether_addr eth;
1196 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1200 memset(&ifr, 0, sizeof(ifr));
1201 ifr.ifr_ifindex = index;
1203 err = ioctl(sk, SIOCGIFNAME, &ifr);
1206 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1217 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1218 snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
1219 eth.ether_addr_octet[0],
1220 eth.ether_addr_octet[1],
1221 eth.ether_addr_octet[2],
1222 eth.ether_addr_octet[3],
1223 eth.ether_addr_octet[4],
1224 eth.ether_addr_octet[5]);
1229 struct connman_device *connman_device_create_from_index(int index)
1231 enum connman_device_type type;
1232 struct connman_device *device;
1233 char *devname, *ident = NULL;
1234 char *addr = NULL, *name = NULL;
1239 devname = connman_inet_ifname(index);
1243 if (__connman_device_isfiltered(devname)) {
1244 connman_info("Ignoring interface %s (filtered)", devname);
1249 type = __connman_rtnl_get_device_type(index);
1252 case CONNMAN_DEVICE_TYPE_UNKNOWN:
1253 connman_info("Ignoring interface %s (type unknown)", devname);
1256 case CONNMAN_DEVICE_TYPE_ETHERNET:
1257 case CONNMAN_DEVICE_TYPE_GADGET:
1258 case CONNMAN_DEVICE_TYPE_WIFI:
1259 name = index2ident(index, "");
1260 addr = index2addr(index);
1262 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
1263 case CONNMAN_DEVICE_TYPE_CELLULAR:
1264 case CONNMAN_DEVICE_TYPE_GPS:
1265 case CONNMAN_DEVICE_TYPE_VENDOR:
1266 name = g_strdup(devname);
1270 device = connman_device_create(name, type);
1275 case CONNMAN_DEVICE_TYPE_UNKNOWN:
1276 case CONNMAN_DEVICE_TYPE_VENDOR:
1277 case CONNMAN_DEVICE_TYPE_GPS:
1279 case CONNMAN_DEVICE_TYPE_ETHERNET:
1280 case CONNMAN_DEVICE_TYPE_GADGET:
1281 ident = index2ident(index, NULL);
1283 case CONNMAN_DEVICE_TYPE_WIFI:
1284 ident = index2ident(index, NULL);
1286 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
1288 case CONNMAN_DEVICE_TYPE_CELLULAR:
1289 ident = index2ident(index, NULL);
1293 connman_device_set_index(device, index);
1294 connman_device_set_interface(device, devname);
1297 connman_device_set_ident(device, ident);
1301 connman_device_set_string(device, "Address", addr);
1311 bool __connman_device_isfiltered(const char *devname)
1314 char **blacklisted_interfaces;
1320 for (pattern = device_filter, match = false; *pattern; pattern++) {
1321 if (g_pattern_match_simple(*pattern, devname)) {
1328 DBG("ignoring device %s (match)", devname);
1333 if (g_pattern_match_simple("dummy*", devname)) {
1334 DBG("ignoring dummy networking devices");
1338 if (!nodevice_filter)
1341 for (pattern = nodevice_filter; *pattern; pattern++) {
1342 if (g_pattern_match_simple(*pattern, devname)) {
1343 DBG("ignoring device %s (no match)", devname);
1349 blacklisted_interfaces =
1350 connman_setting_get_string_list("NetworkInterfaceBlacklist");
1351 if (!blacklisted_interfaces)
1354 for (pattern = blacklisted_interfaces; *pattern; pattern++) {
1355 if (g_str_has_prefix(devname, *pattern)) {
1356 DBG("ignoring device %s (blacklist)", devname);
1364 static void cleanup_devices(void)
1367 * Check what interfaces are currently up and if connman is
1368 * suppose to handle the interface, then cleanup the mess
1369 * related to that interface. There might be weird routes etc
1370 * that are related to that interface and that might confuse
1371 * connmand. So in this case we just turn the interface down
1372 * so that kernel removes routes/addresses automatically and
1373 * then proceed the startup.
1375 * Note that this cleanup must be done before rtnl/detect code
1376 * has activated interface watches.
1382 interfaces = __connman_inet_get_running_interfaces();
1387 for (i = 0; interfaces[i]; i++) {
1390 struct sockaddr_in sin_addr, sin_mask;
1392 filtered = __connman_device_isfiltered(interfaces[i]);
1396 index = connman_inet_ifindex(interfaces[i]);
1400 if (!__connman_inet_get_address_netmask(index, &sin_addr,
1402 char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
1403 char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
1405 if (__connman_config_address_provisioned(address,
1407 DBG("Skip %s which is already provisioned "
1408 "with %s/%s", interfaces[i], address,
1419 DBG("cleaning up %s index %d", interfaces[i], index);
1421 connman_inet_ifdown(index);
1424 * ConnMan will turn the interface UP automatically so
1425 * no need to do it here.
1429 g_strfreev(interfaces);
1432 int __connman_device_init(const char *device, const char *nodevice)
1437 device_filter = g_strsplit(device, ",", -1);
1440 nodevice_filter = g_strsplit(nodevice, ",", -1);
1447 void __connman_device_cleanup(void)
1451 g_strfreev(nodevice_filter);
1452 g_strfreev(device_filter);