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
63 guint pending_timeout;
65 struct connman_device_driver *driver;
69 struct connman_network *network;
73 static void clear_pending_trigger(struct connman_device *device)
75 if (device->pending_timeout > 0) {
76 g_source_remove(device->pending_timeout);
77 device->pending_timeout = 0;
81 static const char *type2description(enum connman_device_type type)
84 case CONNMAN_DEVICE_TYPE_UNKNOWN:
85 case CONNMAN_DEVICE_TYPE_VENDOR:
87 case CONNMAN_DEVICE_TYPE_ETHERNET:
89 case CONNMAN_DEVICE_TYPE_WIFI:
91 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
93 case CONNMAN_DEVICE_TYPE_GPS:
95 case CONNMAN_DEVICE_TYPE_CELLULAR:
97 case CONNMAN_DEVICE_TYPE_GADGET:
105 static const char *type2string(enum connman_device_type type)
108 case CONNMAN_DEVICE_TYPE_UNKNOWN:
109 case CONNMAN_DEVICE_TYPE_VENDOR:
111 case CONNMAN_DEVICE_TYPE_ETHERNET:
113 case CONNMAN_DEVICE_TYPE_WIFI:
115 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
117 case CONNMAN_DEVICE_TYPE_GPS:
119 case CONNMAN_DEVICE_TYPE_CELLULAR:
121 case CONNMAN_DEVICE_TYPE_GADGET:
129 enum connman_service_type __connman_device_get_service_type(
130 struct connman_device *device)
132 enum connman_device_type type = connman_device_get_type(device);
135 case CONNMAN_DEVICE_TYPE_UNKNOWN:
136 case CONNMAN_DEVICE_TYPE_VENDOR:
137 case CONNMAN_DEVICE_TYPE_GPS:
139 case CONNMAN_DEVICE_TYPE_ETHERNET:
140 return CONNMAN_SERVICE_TYPE_ETHERNET;
141 case CONNMAN_DEVICE_TYPE_WIFI:
142 return CONNMAN_SERVICE_TYPE_WIFI;
143 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
144 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
145 case CONNMAN_DEVICE_TYPE_CELLULAR:
146 return CONNMAN_SERVICE_TYPE_CELLULAR;
147 case CONNMAN_DEVICE_TYPE_GADGET:
148 return CONNMAN_SERVICE_TYPE_GADGET;
152 return CONNMAN_SERVICE_TYPE_UNKNOWN;
155 static gboolean device_pending_reset(gpointer user_data)
157 struct connman_device *device = user_data;
159 DBG("device %p", device);
161 /* Power request timedout, reset power pending state. */
162 device->pending_timeout = 0;
163 device->powered_pending = PENDING_NONE;
168 int __connman_device_enable(struct connman_device *device)
172 DBG("device %p", device);
174 if (!device->driver || !device->driver->enable)
177 /* There is an ongoing power disable request. */
178 if (device->powered_pending == PENDING_DISABLE)
181 if (device->powered_pending == PENDING_ENABLE)
184 if (device->powered_pending == PENDING_NONE && device->powered)
187 if (device->index > 0) {
188 err = connman_inet_ifup(device->index);
189 if (err < 0 && err != -EALREADY)
193 device->powered_pending = PENDING_ENABLE;
195 err = device->driver->enable(device);
197 * device gets enabled right away.
198 * Invoke the callback
201 connman_device_set_powered(device, true);
205 if (err == -EALREADY) {
206 /* If device is already powered, but connman is not updated */
207 connman_device_set_powered(device, true);
211 * if err == -EINPROGRESS, then the DBus call to the respective daemon
212 * was successful. We set a 4 sec timeout so if the daemon never
213 * returns a reply, we would reset the pending request.
215 if (err == -EINPROGRESS)
216 device->pending_timeout = g_timeout_add_seconds(4,
217 device_pending_reset, device);
222 int __connman_device_disable(struct connman_device *device)
226 DBG("device %p", device);
228 /* Ongoing power enable request */
229 if (device->powered_pending == PENDING_ENABLE)
232 if (device->powered_pending == PENDING_DISABLE)
235 if (device->powered_pending == PENDING_NONE && !device->powered)
238 device->powered_pending = PENDING_DISABLE;
240 if (device->network) {
241 struct connman_service *service =
242 connman_service_lookup_from_network(device->network);
245 __connman_service_disconnect(service);
247 connman_network_set_connected(device->network, false);
250 if (!device->driver || !device->driver->disable)
253 err = device->driver->disable(device);
254 if (err == 0 || err == -EALREADY) {
255 connman_device_set_powered(device, false);
259 if (err == -EINPROGRESS)
260 device->pending_timeout = g_timeout_add_seconds(4,
261 device_pending_reset, device);
266 static void probe_driver(struct connman_device_driver *driver)
270 DBG("driver %p name %s", driver, driver->name);
272 for (list = device_list; list; list = list->next) {
273 struct connman_device *device = list->data;
278 if (driver->type != device->type)
281 if (driver->probe(device) < 0)
284 device->driver = driver;
286 __connman_technology_add_device(device);
290 static void remove_device(struct connman_device *device)
292 DBG("device %p", device);
294 __connman_device_disable(device);
296 __connman_technology_remove_device(device);
298 if (device->driver->remove)
299 device->driver->remove(device);
301 device->driver = NULL;
304 static void remove_driver(struct connman_device_driver *driver)
308 DBG("driver %p name %s", driver, driver->name);
310 for (list = device_list; list; list = list->next) {
311 struct connman_device *device = list->data;
313 if (device->driver == driver)
314 remove_device(device);
318 bool __connman_device_has_driver(struct connman_device *device)
320 if (!device || !device->driver)
326 static GSList *driver_list = NULL;
328 static gint compare_priority(gconstpointer a, gconstpointer b)
330 const struct connman_device_driver *driver1 = a;
331 const struct connman_device_driver *driver2 = b;
333 return driver2->priority - driver1->priority;
337 * connman_device_driver_register:
338 * @driver: device driver definition
340 * Register a new device driver
342 * Returns: %0 on success
344 int connman_device_driver_register(struct connman_device_driver *driver)
346 DBG("driver %p name %s", driver, driver->name);
348 driver_list = g_slist_insert_sorted(driver_list, driver,
350 probe_driver(driver);
356 * connman_device_driver_unregister:
357 * @driver: device driver definition
359 * Remove a previously registered device driver
361 void connman_device_driver_unregister(struct connman_device_driver *driver)
363 DBG("driver %p name %s", driver, driver->name);
365 driver_list = g_slist_remove(driver_list, driver);
367 remove_driver(driver);
370 static void free_network(gpointer data)
372 struct connman_network *network = data;
374 DBG("network %p", network);
376 __connman_network_set_device(network, NULL);
378 connman_network_unref(network);
381 static void device_destruct(struct connman_device *device)
383 DBG("device %p name %s", device, device->name);
385 clear_pending_trigger(device);
387 g_hash_table_destroy(device->networks);
388 device->networks = NULL;
390 g_free(device->ident);
391 g_free(device->node);
392 g_free(device->name);
393 g_free(device->address);
394 g_free(device->interface);
395 g_free(device->path);
397 g_free(device->last_network);
403 * connman_device_create:
404 * @node: device node name (for example an address)
407 * Allocate a new device of given #type and assign the #node name to it.
409 * Returns: a newly-allocated #connman_device structure
411 struct connman_device *connman_device_create(const char *node,
412 enum connman_device_type type)
414 struct connman_device *device;
416 DBG("node %s type %d", node, type);
418 device = g_try_new0(struct connman_device, 1);
422 DBG("device %p", device);
424 device->refcount = 1;
427 device->name = g_strdup(type2description(device->type));
429 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
430 g_free, free_network);
432 device_list = g_slist_prepend(device_list, device);
438 * connman_device_ref:
439 * @device: device structure
441 * Increase reference counter of device
443 struct connman_device *connman_device_ref_debug(struct connman_device *device,
444 const char *file, int line, const char *caller)
446 DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
449 __sync_fetch_and_add(&device->refcount, 1);
455 * connman_device_unref:
456 * @device: device structure
458 * Decrease reference counter of device
460 void connman_device_unref_debug(struct connman_device *device,
461 const char *file, int line, const char *caller)
463 DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1,
466 if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
469 if (device->driver) {
470 device->driver->remove(device);
471 device->driver = NULL;
474 device_list = g_slist_remove(device_list, device);
476 device_destruct(device);
479 const char *__connman_device_get_type(struct connman_device *device)
481 return type2string(device->type);
485 * connman_device_get_type:
486 * @device: device structure
490 enum connman_device_type connman_device_get_type(struct connman_device *device)
496 * connman_device_set_index:
497 * @device: device structure
498 * @index: index number
500 * Set index number of device
502 void connman_device_set_index(struct connman_device *device, int index)
504 device->index = index;
508 * connman_device_get_index:
509 * @device: device structure
511 * Get index number of device
513 int connman_device_get_index(struct connman_device *device)
515 return device->index;
519 * connman_device_set_interface:
520 * @device: device structure
521 * @interface: interface name
523 * Set interface name of device
525 void connman_device_set_interface(struct connman_device *device,
526 const char *interface)
528 g_free(device->interface);
529 device->interface = g_strdup(interface);
532 const char *str = type2description(device->type);
533 if (str && device->interface)
534 device->name = g_strdup_printf("%s (%s)", str,
540 * connman_device_set_ident:
541 * @device: device structure
542 * @ident: unique identifier
544 * Set unique identifier of device
546 void connman_device_set_ident(struct connman_device *device,
549 g_free(device->ident);
550 device->ident = g_strdup(ident);
553 const char *connman_device_get_ident(struct connman_device *device)
555 return device->ident;
559 * connman_device_set_powered:
560 * @device: device structure
561 * @powered: powered state
563 * Change power state of device
565 int connman_device_set_powered(struct connman_device *device,
568 enum connman_service_type type;
570 DBG("device %p powered %d", device, powered);
572 if (device->powered == powered)
575 clear_pending_trigger(device);
577 device->powered_pending = PENDING_NONE;
579 device->powered = powered;
581 type = __connman_device_get_service_type(device);
583 if (!device->powered) {
584 __connman_technology_disabled(type);
588 __connman_technology_enabled(type);
590 device->scanning = false;
592 if (device->driver && device->driver->scan)
593 device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN, device,
594 NULL, 0, NULL, NULL, NULL, NULL);
599 bool connman_device_get_powered(struct connman_device *device)
601 return device->powered;
604 static int device_scan(enum connman_service_type type,
605 struct connman_device *device)
607 if (!device->driver || !device->driver->scan)
610 if (!device->powered)
613 return device->driver->scan(type, device, NULL, 0,
614 NULL, NULL, NULL, NULL);
617 int __connman_device_disconnect(struct connman_device *device)
622 DBG("device %p", device);
624 g_hash_table_iter_init(&iter, device->networks);
626 while (g_hash_table_iter_next(&iter, &key, &value)) {
627 struct connman_network *network = value;
629 if (connman_network_get_connecting(network)) {
631 * Skip network in the process of connecting.
632 * This is a workaround for WiFi networks serviced
633 * by the supplicant plugin that hold a reference
634 * to the network. If we disconnect the network
635 * here then the referenced object will not be
636 * registered and usage (like launching DHCP client)
637 * will fail. There is nothing to be gained by
638 * removing the network here anyway.
640 connman_warn("Skipping disconnect of %s, network is connecting.",
641 connman_network_get_identifier(network));
645 __connman_network_disconnect(network);
651 int connman_device_reconnect_service(struct connman_device *device)
653 DBG("device %p", device);
655 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
660 static void mark_network_available(gpointer key, gpointer value,
663 struct connman_network *network = value;
665 connman_network_set_available(network, true);
668 static void mark_network_unavailable(gpointer key, gpointer value,
671 struct connman_network *network = value;
673 if (connman_network_get_connected(network) ||
674 connman_network_get_connecting(network))
677 connman_network_set_available(network, false);
680 static gboolean remove_unavailable_network(gpointer key, gpointer value,
683 struct connman_network *network = value;
685 if (connman_network_get_connected(network))
688 if (connman_network_get_available(network))
694 void __connman_device_cleanup_networks(struct connman_device *device)
696 g_hash_table_foreach_remove(device->networks,
697 remove_unavailable_network, NULL);
700 bool connman_device_get_scanning(struct connman_device *device)
702 return device->scanning;
705 void connman_device_reset_scanning(struct connman_device *device)
707 g_hash_table_foreach(device->networks,
708 mark_network_available, NULL);
712 * connman_device_set_scanning:
713 * @device: device structure
714 * @scanning: scanning state
716 * Change scanning state of device
718 int connman_device_set_scanning(struct connman_device *device,
719 enum connman_service_type type, bool scanning)
721 DBG("device %p scanning %d", device, scanning);
723 if (!device->driver || !device->driver->scan)
726 if (device->scanning == scanning)
729 device->scanning = scanning;
732 __connman_technology_scan_started(device);
734 g_hash_table_foreach(device->networks,
735 mark_network_unavailable, NULL);
740 __connman_device_cleanup_networks(device);
742 __connman_technology_scan_stopped(device, type);
744 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
746 #if defined TIZEN_EXT_WIFI_MESH
747 if (type == CONNMAN_SERVICE_TYPE_MESH)
748 __connman_mesh_auto_connect();
755 * connman_device_set_string:
756 * @device: device structure
757 * @key: unique identifier
758 * @value: string value
760 * Set string value for specific key
762 int connman_device_set_string(struct connman_device *device,
763 const char *key, const char *value)
765 DBG("device %p key %s value %s", device, key, value);
767 if (g_str_equal(key, "Address")) {
768 g_free(device->address);
769 device->address = g_strdup(value);
770 } else if (g_str_equal(key, "Name")) {
771 g_free(device->name);
772 device->name = g_strdup(value);
773 } else if (g_str_equal(key, "Node")) {
774 g_free(device->node);
775 device->node = g_strdup(value);
776 } else if (g_str_equal(key, "Path")) {
777 g_free(device->path);
778 device->path = g_strdup(value);
787 * connman_device_get_string:
788 * @device: device structure
789 * @key: unique identifier
791 * Get string value for specific key
793 const char *connman_device_get_string(struct connman_device *device,
796 DBG("device %p key %s", device, key);
798 if (g_str_equal(key, "Address"))
799 return device->address;
800 else if (g_str_equal(key, "Name"))
802 else if (g_str_equal(key, "Node"))
804 else if (g_str_equal(key, "Interface"))
805 return device->interface;
806 else if (g_str_equal(key, "Path"))
813 * connman_device_add_network:
814 * @device: device structure
815 * @network: network structure
817 * Add new network to the device
819 int connman_device_add_network(struct connman_device *device,
820 struct connman_network *network)
822 const char *identifier = connman_network_get_identifier(network);
824 DBG("device %p network %p", device, network);
829 connman_network_ref(network);
831 __connman_network_set_device(network, device);
833 g_hash_table_replace(device->networks, g_strdup(identifier),
840 * connman_device_get_network:
841 * @device: device structure
842 * @identifier: network identifier
844 * Get network for given identifier
846 struct connman_network *connman_device_get_network(struct connman_device *device,
847 const char *identifier)
849 DBG("device %p identifier %s", device, identifier);
851 return g_hash_table_lookup(device->networks, identifier);
855 * connman_device_remove_network:
856 * @device: device structure
857 * @identifier: network identifier
859 * Remove network for given identifier
861 int connman_device_remove_network(struct connman_device *device,
862 struct connman_network *network)
864 const char *identifier;
866 DBG("device %p network %p", device, network);
871 identifier = connman_network_get_identifier(network);
872 g_hash_table_remove(device->networks, identifier);
877 void __connman_device_set_network(struct connman_device *device,
878 struct connman_network *network)
885 if (device->network == network)
889 name = connman_network_get_string(network, "Name");
890 g_free(device->last_network);
891 device->last_network = g_strdup(name);
893 device->network = network;
895 g_free(device->last_network);
896 device->last_network = NULL;
898 device->network = NULL;
902 static bool match_driver(struct connman_device *device,
903 struct connman_device_driver *driver)
905 if (device->type == driver->type ||
906 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
913 * connman_device_register:
914 * @device: device structure
916 * Register device with the system
918 int connman_device_register(struct connman_device *device)
922 DBG("device %p name %s", device, device->name);
927 for (list = driver_list; list; list = list->next) {
928 struct connman_device_driver *driver = list->data;
930 if (!match_driver(device, driver))
933 DBG("driver %p name %s", driver, driver->name);
935 if (driver->probe(device) == 0) {
936 device->driver = driver;
944 return __connman_technology_add_device(device);
948 * connman_device_unregister:
949 * @device: device structure
951 * Unregister device with the system
953 void connman_device_unregister(struct connman_device *device)
955 DBG("device %p name %s", device, device->name);
960 remove_device(device);
964 * connman_device_get_data:
965 * @device: device structure
967 * Get private device data pointer
969 void *connman_device_get_data(struct connman_device *device)
971 return device->driver_data;
975 * connman_device_set_data:
976 * @device: device structure
977 * @data: data pointer
979 * Set private device data pointer
981 void connman_device_set_data(struct connman_device *device, void *data)
983 device->driver_data = data;
986 struct connman_device *__connman_device_find_device(
987 enum connman_service_type type)
991 for (list = device_list; list; list = list->next) {
992 struct connman_device *device = list->data;
993 enum connman_service_type service_type =
994 __connman_device_get_service_type(device);
996 if (service_type != type)
1005 struct connman_device *connman_device_find_by_index(int index)
1009 for (list = device_list; list; list = list->next) {
1010 struct connman_device *device = list->data;
1011 if (device->index == index)
1019 * connman_device_set_regdom
1020 * @device: device structure
1021 * @alpha2: string representing regulatory domain
1023 * Set regulatory domain on device basis
1025 int connman_device_set_regdom(struct connman_device *device,
1028 if (!device->driver || !device->driver->set_regdom)
1031 if (!device->powered)
1034 return device->driver->set_regdom(device, alpha2);
1038 * connman_device_regdom_notify
1039 * @device: device structure
1040 * @alpha2: string representing regulatory domain
1042 * Notify on setting regulatory domain on device basis
1044 void connman_device_regdom_notify(struct connman_device *device,
1045 int result, const char *alpha2)
1047 __connman_technology_notify_regdom_by_device(device, result, alpha2);
1050 #if defined TIZEN_EXT
1051 static int device_specific_scan(enum connman_service_type type,
1052 struct connman_device *device,
1053 int scan_type, GSList *specific_scan_list)
1055 if (!device->driver || !device->driver->specific_scan)
1058 if (!device->powered)
1061 return device->driver->specific_scan(type, device, scan_type,
1062 specific_scan_list, NULL);
1065 int __connman_device_request_specific_scan(enum connman_service_type type,
1066 int scan_type, GSList *specific_scan_list)
1068 bool success = false;
1069 int last_err = -ENOSYS;
1074 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1075 case CONNMAN_SERVICE_TYPE_SYSTEM:
1076 case CONNMAN_SERVICE_TYPE_ETHERNET:
1077 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1078 case CONNMAN_SERVICE_TYPE_CELLULAR:
1079 case CONNMAN_SERVICE_TYPE_GPS:
1080 case CONNMAN_SERVICE_TYPE_VPN:
1081 case CONNMAN_SERVICE_TYPE_GADGET:
1083 case CONNMAN_SERVICE_TYPE_WIFI:
1084 case CONNMAN_SERVICE_TYPE_P2P:
1085 #if defined TIZEN_EXT_WIFI_MESH
1086 case CONNMAN_SERVICE_TYPE_MESH:
1091 for (list = device_list; list; list = list->next) {
1092 struct connman_device *device = list->data;
1093 enum connman_service_type service_type =
1094 __connman_device_get_service_type(device);
1096 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1097 if (type == CONNMAN_SERVICE_TYPE_P2P) {
1098 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1100 } else if (service_type != type)
1104 err = device_specific_scan(type, device, scan_type, specific_scan_list);
1105 if (err == 0 || err == -EINPROGRESS) {
1109 DBG("device %p err %d", device, err);
1119 #if defined TIZEN_EXT_WIFI_MESH
1120 static int device_abort_scan(enum connman_service_type type,
1121 struct connman_device *device)
1123 if (!device->driver || !device->driver->scan)
1126 if (!device->powered)
1129 return device->driver->abort_scan(type, device);
1132 int __connman_device_abort_scan(enum connman_service_type type)
1137 if (type != CONNMAN_SERVICE_TYPE_MESH)
1140 for (list = device_list; list; list = list->next) {
1141 struct connman_device *device = list->data;
1142 enum connman_service_type service_type =
1143 __connman_device_get_service_type(device);
1145 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1146 if (type == CONNMAN_SERVICE_TYPE_MESH)
1147 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1150 if (!device->scanning) {
1155 err = device_abort_scan(type, device);
1161 static int device_mesh_specific_scan(enum connman_service_type type,
1162 struct connman_device *device, const char *name,
1165 if (!device->driver || !device->driver->mesh_specific_scan)
1168 if (!device->powered)
1171 return device->driver->mesh_specific_scan(type, device, name, freq, NULL);
1174 int __connman_device_request_mesh_specific_scan(enum connman_service_type type,
1178 bool success = false;
1179 int last_err = -ENOSYS;
1183 if (type != CONNMAN_SERVICE_TYPE_MESH)
1186 for (list = device_list; list; list = list->next) {
1187 struct connman_device *device = list->data;
1188 enum connman_service_type service_type =
1189 __connman_device_get_service_type(device);
1191 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1192 if (type == CONNMAN_SERVICE_TYPE_MESH)
1193 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1197 err = device_mesh_specific_scan(type, device, name, freq);
1198 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1202 DBG("device %p err %d", device, err);
1211 #endif /* TIZEN_EXT_WIFI_MESH */
1214 int __connman_device_request_scan(enum connman_service_type type)
1216 bool success = false;
1217 int last_err = -ENOSYS;
1222 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1223 case CONNMAN_SERVICE_TYPE_SYSTEM:
1224 case CONNMAN_SERVICE_TYPE_ETHERNET:
1225 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1226 case CONNMAN_SERVICE_TYPE_CELLULAR:
1227 case CONNMAN_SERVICE_TYPE_GPS:
1228 case CONNMAN_SERVICE_TYPE_VPN:
1229 case CONNMAN_SERVICE_TYPE_GADGET:
1231 case CONNMAN_SERVICE_TYPE_WIFI:
1232 case CONNMAN_SERVICE_TYPE_P2P:
1233 #if defined TIZEN_EXT_WIFI_MESH
1234 case CONNMAN_SERVICE_TYPE_MESH:
1239 for (list = device_list; list; list = list->next) {
1240 struct connman_device *device = list->data;
1241 enum connman_service_type service_type =
1242 __connman_device_get_service_type(device);
1244 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1245 if (type == CONNMAN_SERVICE_TYPE_P2P) {
1246 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1248 #if defined TIZEN_EXT_WIFI_MESH
1249 } else if (type == CONNMAN_SERVICE_TYPE_MESH) {
1250 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1253 } else if (service_type != type)
1257 err = device_scan(type, device);
1258 #if defined TIZEN_EXT
1259 /* When Scan is already in progress then return Error so that
1260 * wifi-manager can block the scan-done signal to be sent to
1261 * application and start requested scan after scan already in progress
1262 * is completed then notify to application about the scan event */
1263 if (err == 0 || err == -EINPROGRESS) {
1265 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1270 DBG("device %p err %d", device, err);
1280 int __connman_device_request_hidden_scan(struct connman_device *device,
1281 const char *ssid, unsigned int ssid_len,
1282 const char *identity, const char *passphrase,
1283 const char *security, void *user_data)
1285 DBG("device %p", device);
1287 if (!device || !device->driver ||
1288 !device->driver->scan)
1291 return device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN,
1292 device, ssid, ssid_len, identity,
1293 passphrase, security, user_data);
1296 #if defined TIZEN_EXT
1297 char *index2ident(int index, const char *prefix)
1299 static char *index2ident(int index, const char *prefix)
1303 struct ether_addr eth;
1310 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1314 memset(&ifr, 0, sizeof(ifr));
1315 ifr.ifr_ifindex = index;
1317 err = ioctl(sk, SIOCGIFNAME, &ifr);
1320 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1327 len = prefix ? strlen(prefix) + 18 : 18;
1329 str = g_malloc(len);
1333 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1334 snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
1335 prefix ? prefix : "",
1336 eth.ether_addr_octet[0],
1337 eth.ether_addr_octet[1],
1338 eth.ether_addr_octet[2],
1339 eth.ether_addr_octet[3],
1340 eth.ether_addr_octet[4],
1341 eth.ether_addr_octet[5]);
1346 #if defined TIZEN_EXT
1347 char *index2addr(int index)
1349 static char *index2addr(int index)
1353 struct ether_addr eth;
1360 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1364 memset(&ifr, 0, sizeof(ifr));
1365 ifr.ifr_ifindex = index;
1367 err = ioctl(sk, SIOCGIFNAME, &ifr);
1370 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1381 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1382 snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
1383 eth.ether_addr_octet[0],
1384 eth.ether_addr_octet[1],
1385 eth.ether_addr_octet[2],
1386 eth.ether_addr_octet[3],
1387 eth.ether_addr_octet[4],
1388 eth.ether_addr_octet[5]);
1393 struct connman_device *connman_device_create_from_index(int index)
1395 enum connman_device_type type;
1396 struct connman_device *device;
1397 char *devname, *ident = NULL;
1398 char *addr = NULL, *name = NULL;
1403 devname = connman_inet_ifname(index);
1407 if (__connman_device_isfiltered(devname)) {
1408 connman_info("Ignoring interface %s (filtered)", devname);
1413 type = __connman_rtnl_get_device_type(index);
1416 case CONNMAN_DEVICE_TYPE_UNKNOWN:
1417 connman_info("Ignoring interface %s (type unknown)", devname);
1420 case CONNMAN_DEVICE_TYPE_ETHERNET:
1421 case CONNMAN_DEVICE_TYPE_GADGET:
1422 case CONNMAN_DEVICE_TYPE_WIFI:
1423 name = index2ident(index, "");
1424 addr = index2addr(index);
1426 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
1427 case CONNMAN_DEVICE_TYPE_CELLULAR:
1428 case CONNMAN_DEVICE_TYPE_GPS:
1429 case CONNMAN_DEVICE_TYPE_VENDOR:
1430 name = g_strdup(devname);
1434 device = connman_device_create(name, type);
1439 case CONNMAN_DEVICE_TYPE_UNKNOWN:
1440 case CONNMAN_DEVICE_TYPE_VENDOR:
1441 case CONNMAN_DEVICE_TYPE_GPS:
1443 case CONNMAN_DEVICE_TYPE_ETHERNET:
1444 case CONNMAN_DEVICE_TYPE_GADGET:
1445 ident = index2ident(index, NULL);
1447 case CONNMAN_DEVICE_TYPE_WIFI:
1448 ident = index2ident(index, NULL);
1450 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
1452 case CONNMAN_DEVICE_TYPE_CELLULAR:
1453 ident = index2ident(index, NULL);
1457 connman_device_set_index(device, index);
1458 connman_device_set_interface(device, devname);
1461 connman_device_set_ident(device, ident);
1465 connman_device_set_string(device, "Address", addr);
1475 bool __connman_device_isfiltered(const char *devname)
1478 char **blacklisted_interfaces;
1484 for (pattern = device_filter, match = false; *pattern; pattern++) {
1485 if (g_pattern_match_simple(*pattern, devname)) {
1492 DBG("ignoring device %s (match)", devname);
1497 if (g_pattern_match_simple("dummy*", devname)) {
1498 DBG("ignoring dummy networking devices");
1502 if (!nodevice_filter)
1505 for (pattern = nodevice_filter; *pattern; pattern++) {
1506 if (g_pattern_match_simple(*pattern, devname)) {
1507 DBG("ignoring device %s (no match)", devname);
1513 if (__connman_inet_isrootnfs_device(devname)) {
1514 DBG("ignoring device %s (rootnfs)", devname);
1518 blacklisted_interfaces =
1519 connman_setting_get_string_list("NetworkInterfaceBlacklist");
1520 if (!blacklisted_interfaces)
1523 for (pattern = blacklisted_interfaces; *pattern; pattern++) {
1524 if (g_str_has_prefix(devname, *pattern)) {
1525 DBG("ignoring device %s (blacklist)", devname);
1533 static void cleanup_devices(void)
1536 * Check what interfaces are currently up and if connman is
1537 * suppose to handle the interface, then cleanup the mess
1538 * related to that interface. There might be weird routes etc
1539 * that are related to that interface and that might confuse
1540 * connmand. So in this case we just turn the interface down
1541 * so that kernel removes routes/addresses automatically and
1542 * then proceed the startup.
1544 * Note that this cleanup must be done before rtnl/detect code
1545 * has activated interface watches.
1551 interfaces = __connman_inet_get_running_interfaces();
1556 for (i = 0; interfaces[i]; i++) {
1559 struct sockaddr_in sin_addr, sin_mask;
1561 filtered = __connman_device_isfiltered(interfaces[i]);
1565 index = connman_inet_ifindex(interfaces[i]);
1569 if (!__connman_inet_get_address_netmask(index, &sin_addr,
1571 char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
1572 char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
1574 if (__connman_config_address_provisioned(address,
1576 DBG("Skip %s which is already provisioned "
1577 "with %s/%s", interfaces[i], address,
1588 DBG("cleaning up %s index %d", interfaces[i], index);
1590 #if defined TIZEN_EXT
1591 if (strcmp(interfaces[i], "wlan0") != 0)
1593 connman_inet_ifdown(index);
1596 * ConnMan will turn the interface UP automatically so
1597 * no need to do it here.
1601 g_strfreev(interfaces);
1604 int __connman_device_init(const char *device, const char *nodevice)
1609 device_filter = g_strsplit(device, ",", -1);
1612 nodevice_filter = g_strsplit(nodevice, ",", -1);
1619 void __connman_device_cleanup(void)
1623 g_strfreev(nodevice_filter);
1624 g_strfreev(device_filter);