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;
42 static DBusConnection *connection;
45 enum connman_pending_type {
51 struct connman_device {
53 enum connman_device_type type;
54 enum connman_pending_type powered_pending; /* Indicates a pending
59 bool scanning[MAX_CONNMAN_SERVICE_TYPES];
67 guint pending_timeout;
69 struct connman_device_driver *driver;
73 struct connman_network *network;
76 time_t last_user_selection_time;
77 char *last_user_selection_ident;
78 char *last_connected_ident;
79 GList *pending_reply_list; /* List of DBusMessage* for async reply to multiple
80 * device power dbus calls, which are made before
81 * connman_device_set_powered().
84 bool is_5_0_ghz_supported;
85 bool is_6_0_ghz_supported;
86 unsigned int mac_policy;
87 unsigned int preassoc_mac_policy;
88 unsigned int random_mac_lifetime;
93 static void __clear_pending_trigger(gpointer data, gpointer user_data)
95 DBusMessage *msg = (DBusMessage *)data;
96 dbus_message_unref(msg);
100 static void clear_pending_trigger(struct connman_device *device)
102 #if defined TIZEN_EXT
103 if (device->pending_reply_list) {
104 g_list_foreach(device->pending_reply_list, __clear_pending_trigger, NULL);
105 g_list_free(device->pending_reply_list);
106 device->pending_reply_list = NULL;
109 if (device->pending_timeout > 0) {
110 g_source_remove(device->pending_timeout);
111 device->pending_timeout = 0;
115 static const char *type2description(enum connman_device_type type)
118 case CONNMAN_DEVICE_TYPE_UNKNOWN:
119 case CONNMAN_DEVICE_TYPE_VENDOR:
121 case CONNMAN_DEVICE_TYPE_ETHERNET:
123 case CONNMAN_DEVICE_TYPE_WIFI:
125 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
127 case CONNMAN_DEVICE_TYPE_GPS:
129 case CONNMAN_DEVICE_TYPE_CELLULAR:
131 case CONNMAN_DEVICE_TYPE_GADGET:
139 static const char *type2string(enum connman_device_type type)
142 case CONNMAN_DEVICE_TYPE_UNKNOWN:
143 case CONNMAN_DEVICE_TYPE_VENDOR:
145 case CONNMAN_DEVICE_TYPE_ETHERNET:
147 case CONNMAN_DEVICE_TYPE_WIFI:
149 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
151 case CONNMAN_DEVICE_TYPE_GPS:
153 case CONNMAN_DEVICE_TYPE_CELLULAR:
155 case CONNMAN_DEVICE_TYPE_GADGET:
163 enum connman_service_type __connman_device_get_service_type(
164 struct connman_device *device)
166 enum connman_device_type type = connman_device_get_type(device);
169 case CONNMAN_DEVICE_TYPE_UNKNOWN:
170 case CONNMAN_DEVICE_TYPE_VENDOR:
171 case CONNMAN_DEVICE_TYPE_GPS:
173 case CONNMAN_DEVICE_TYPE_ETHERNET:
174 return CONNMAN_SERVICE_TYPE_ETHERNET;
175 case CONNMAN_DEVICE_TYPE_WIFI:
176 return CONNMAN_SERVICE_TYPE_WIFI;
177 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
178 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
179 case CONNMAN_DEVICE_TYPE_CELLULAR:
180 return CONNMAN_SERVICE_TYPE_CELLULAR;
181 case CONNMAN_DEVICE_TYPE_GADGET:
182 return CONNMAN_SERVICE_TYPE_GADGET;
186 return CONNMAN_SERVICE_TYPE_UNKNOWN;
189 static bool device_has_service_type(struct connman_device *device,
190 enum connman_service_type service_type)
192 enum connman_service_type device_service_type =
193 __connman_device_get_service_type(device);
196 * For devices whose device_service_type is unknown we should
197 * allow to decide whether they support specific service_type
200 if (device_service_type == CONNMAN_SERVICE_TYPE_UNKNOWN)
203 #if defined TIZEN_EXT_WIFI_MESH
204 if (device_service_type == CONNMAN_SERVICE_TYPE_MESH)
205 return service_type != CONNMAN_SERVICE_TYPE_MESH;
208 if (device_service_type == CONNMAN_SERVICE_TYPE_WIFI) {
209 return service_type == CONNMAN_SERVICE_TYPE_WIFI ||
210 service_type == CONNMAN_SERVICE_TYPE_P2P;
213 return service_type == device_service_type;
216 #if defined TIZEN_EXT
217 static void __device_pending_reset(gpointer data, gpointer user_data)
219 DBusMessage *msg = (DBusMessage *)data;
222 reply = __connman_error_failed(msg, ETIMEDOUT);
224 g_dbus_send_message(connection, reply);
226 dbus_message_unref(msg);
230 static gboolean device_pending_reset(gpointer user_data)
232 struct connman_device *device = user_data;
234 DBG("device %p", device);
236 #if defined TIZEN_EXT
237 /* Power request timed out, send ETIMEDOUT. */
238 if (device->pending_reply_list) {
239 g_list_foreach(device->pending_reply_list, __device_pending_reset, NULL);
240 g_list_free(device->pending_reply_list);
241 device->pending_reply_list = NULL;
244 /* Power request timedout, reset power pending state. */
245 device->pending_timeout = 0;
246 device->powered_pending = PENDING_NONE;
251 int __connman_device_enable(struct connman_device *device)
255 DBG("device %p", device);
257 if (!device->driver || !device->driver->enable)
260 /* There is an ongoing power disable request. */
261 if (device->powered_pending == PENDING_DISABLE)
264 if (device->powered_pending == PENDING_ENABLE)
267 if (device->powered_pending == PENDING_NONE && device->powered)
270 if (device->index > 0) {
271 err = connman_inet_ifup(device->index);
272 if (err < 0 && err != -EALREADY)
276 device->powered_pending = PENDING_ENABLE;
278 err = device->driver->enable(device);
280 * device gets enabled right away.
281 * Invoke the callback
284 connman_device_set_powered(device, true);
288 if (err == -EALREADY) {
289 /* If device is already powered, but connman is not updated */
290 connman_device_set_powered(device, true);
292 if (device->type == CONNMAN_DEVICE_TYPE_WIFI) {
293 device->driver->set_mac_policy(device, device->mac_policy);
294 device->driver->set_preassoc_mac_policy(device, device->preassoc_mac_policy);
295 device->driver->set_random_mac_lifetime(device, device->random_mac_lifetime);
297 #endif /* TIZEN_EXT */
301 * if err == -EINPROGRESS, then the DBus call to the respective daemon
302 * was successful. We set a 4 sec timeout so if the daemon never
303 * returns a reply, we would reset the pending request.
305 if (err == -EINPROGRESS)
306 device->pending_timeout = g_timeout_add_seconds(4,
307 device_pending_reset, device);
312 int __connman_device_disable(struct connman_device *device)
316 DBG("device %p", device);
318 /* Ongoing power enable request */
319 if (device->powered_pending == PENDING_ENABLE)
322 if (device->powered_pending == PENDING_DISABLE)
325 if (device->powered_pending == PENDING_NONE && !device->powered)
328 device->powered_pending = PENDING_DISABLE;
330 if (device->network) {
331 struct connman_service *service =
332 connman_service_lookup_from_network(device->network);
335 __connman_service_disconnect(service);
337 connman_network_set_connected(device->network, false);
340 if (!device->driver || !device->driver->disable)
343 err = device->driver->disable(device);
344 if (err == 0 || err == -EALREADY) {
345 connman_device_set_powered(device, false);
349 if (err == -EINPROGRESS)
350 device->pending_timeout = g_timeout_add_seconds(4,
351 device_pending_reset, device);
356 static void probe_driver(struct connman_device_driver *driver)
360 DBG("driver %p name %s", driver, driver->name);
362 for (list = device_list; list; list = list->next) {
363 struct connman_device *device = list->data;
368 if (driver->type != device->type)
371 if (driver->probe(device) < 0)
374 device->driver = driver;
376 __connman_technology_add_device(device);
380 static void remove_device(struct connman_device *device)
382 DBG("device %p", device);
384 __connman_device_disable(device);
386 __connman_technology_remove_device(device);
388 if (device->driver->remove)
389 device->driver->remove(device);
391 device->driver = NULL;
394 static void remove_driver(struct connman_device_driver *driver)
398 DBG("driver %p name %s", driver, driver->name);
400 for (list = device_list; list; list = list->next) {
401 struct connman_device *device = list->data;
403 if (device->driver == driver)
404 remove_device(device);
408 bool __connman_device_has_driver(struct connman_device *device)
410 if (!device || !device->driver)
416 static GSList *driver_list = NULL;
418 static gint compare_priority(gconstpointer a, gconstpointer b)
420 const struct connman_device_driver *driver1 = a;
421 const struct connman_device_driver *driver2 = b;
423 return driver2->priority - driver1->priority;
427 * connman_device_driver_register:
428 * @driver: device driver definition
430 * Register a new device driver
432 * Returns: %0 on success
434 int connman_device_driver_register(struct connman_device_driver *driver)
436 DBG("driver %p name %s", driver, driver->name);
438 driver_list = g_slist_insert_sorted(driver_list, driver,
440 probe_driver(driver);
446 * connman_device_driver_unregister:
447 * @driver: device driver definition
449 * Remove a previously registered device driver
451 void connman_device_driver_unregister(struct connman_device_driver *driver)
453 DBG("driver %p name %s", driver, driver->name);
455 driver_list = g_slist_remove(driver_list, driver);
457 remove_driver(driver);
460 static void free_network(gpointer data)
462 struct connman_network *network = data;
464 DBG("network %p", network);
466 __connman_network_set_device(network, NULL);
468 connman_network_unref(network);
471 static void device_destruct(struct connman_device *device)
473 DBG("device %p name %s", device, device->name);
475 clear_pending_trigger(device);
477 g_hash_table_destroy(device->networks);
478 device->networks = NULL;
480 g_free(device->ident);
481 g_free(device->node);
482 g_free(device->name);
483 g_free(device->address);
484 g_free(device->interface);
485 g_free(device->path);
487 g_free(device->last_network);
489 #if defined TIZEN_EXT
490 g_free(device->last_user_selection_ident);
491 g_free(device->last_connected_ident);
497 #if defined TIZEN_EXT
498 static void device_send_changed(const char *ifname, enum connman_service_type type,
499 const char *key, bool state)
502 DBusMessageIter iter, dict;
503 dbus_bool_t value = state;
504 const char *tech_path = connman_techonology_get_path(type);
506 if (!tech_path || !ifname)
509 DBG("%s %s %s", ifname, key, state ? "TRUE" : "FALSE");
511 signal = dbus_message_new_signal(tech_path,
512 CONNMAN_TECHNOLOGY_INTERFACE, "DeviceChanged");
516 dbus_message_iter_init_append(signal, &iter);
518 connman_dbus_dict_open(&iter, &dict);
519 connman_dbus_dict_append_basic(&dict, "Ifname",
522 connman_dbus_dict_append_basic(&dict, key,
525 connman_dbus_dict_close(&iter, &dict);
527 dbus_connection_send(connection, signal, NULL);
528 dbus_message_unref(signal);
531 static void __device_send_reply(gpointer data, gpointer user_data)
533 DBusMessage *msg = (DBusMessage *)data;
534 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
535 dbus_message_unref(msg);
538 static void device_send_reply(struct connman_device *device)
540 if (device->pending_reply_list) {
541 g_list_foreach(device->pending_reply_list, __device_send_reply, NULL);
542 g_list_free(device->pending_reply_list);
543 device->pending_reply_list = NULL;
549 * connman_device_create:
550 * @node: device node name (for example an address)
553 * Allocate a new device of given #type and assign the #node name to it.
555 * Returns: a newly-allocated #connman_device structure
557 struct connman_device *connman_device_create(const char *node,
558 enum connman_device_type type)
560 struct connman_device *device;
562 DBG("node %s type %d", node, type);
564 device = g_try_new0(struct connman_device, 1);
568 DBG("device %p", device);
570 device->refcount = 1;
573 device->name = g_strdup(type2description(device->type));
575 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
576 g_free, free_network);
578 device_list = g_slist_prepend(device_list, device);
584 * connman_device_ref:
585 * @device: device structure
587 * Increase reference counter of device
589 struct connman_device *connman_device_ref_debug(struct connman_device *device,
590 const char *file, int line, const char *caller)
592 DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
595 __sync_fetch_and_add(&device->refcount, 1);
601 * connman_device_unref:
602 * @device: device structure
604 * Decrease reference counter of device
606 void connman_device_unref_debug(struct connman_device *device,
607 const char *file, int line, const char *caller)
609 DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1,
612 if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
615 if (device->driver) {
616 device->driver->remove(device);
617 device->driver = NULL;
620 device_list = g_slist_remove(device_list, device);
622 device_destruct(device);
625 const char *__connman_device_get_type(struct connman_device *device)
627 return type2string(device->type);
631 * connman_device_get_type:
632 * @device: device structure
636 enum connman_device_type connman_device_get_type(struct connman_device *device)
642 * connman_device_set_index:
643 * @device: device structure
644 * @index: index number
646 * Set index number of device
648 void connman_device_set_index(struct connman_device *device, int index)
650 device->index = index;
654 * connman_device_get_index:
655 * @device: device structure
657 * Get index number of device
659 int connman_device_get_index(struct connman_device *device)
661 return device->index;
665 * connman_device_set_interface:
666 * @device: device structure
667 * @interface: interface name
669 * Set interface name of device
671 void connman_device_set_interface(struct connman_device *device,
672 const char *interface)
674 g_free(device->interface);
675 device->interface = g_strdup(interface);
678 const char *str = type2description(device->type);
679 if (str && device->interface)
680 device->name = g_strdup_printf("%s (%s)", str,
686 * connman_device_set_ident:
687 * @device: device structure
688 * @ident: unique identifier
690 * Set unique identifier of device
692 void connman_device_set_ident(struct connman_device *device,
696 if (device->ident && device->powered)
700 g_free(device->ident);
701 device->ident = g_strdup(ident);
704 const char *connman_device_get_ident(struct connman_device *device)
706 return device->ident;
710 * connman_device_set_powered:
711 * @device: device structure
712 * @powered: powered state
714 * Change power state of device
716 int connman_device_set_powered(struct connman_device *device,
719 struct connman_device_scan_params params;
720 enum connman_service_type type;
723 DBG("device %p powered %d", device, powered);
725 if (device->powered == powered)
728 #if defined TIZEN_EXT
729 device_send_reply(device);
732 clear_pending_trigger(device);
734 device->powered_pending = PENDING_NONE;
736 device->powered = powered;
738 type = __connman_device_get_service_type(device);
740 #if defined TIZEN_EXT
741 device_send_changed(device->interface, type, "Powered", powered);
742 technology_save_device(device);
745 if (!device->powered) {
746 __connman_technology_disabled(type);
750 __connman_technology_enabled(type);
752 for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++)
753 device->scanning[i] = false;
755 if (device->driver && device->driver->scan) {
756 memset(¶ms, 0, sizeof(params));
757 params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
759 device->driver->scan(device, ¶ms);
765 bool connman_device_get_powered(struct connman_device *device)
767 return device->powered;
770 static int device_scan(enum connman_service_type type,
771 struct connman_device *device,
772 bool force_full_scan)
774 struct connman_device_scan_params params;
776 if (!device->driver || !device->driver->scan)
779 if (!device->powered)
782 memset(¶ms, 0, sizeof(params));
784 params.force_full_scan = force_full_scan;
786 return device->driver->scan(device, ¶ms);
789 int __connman_device_disconnect(struct connman_device *device)
794 DBG("device %p", device);
796 g_hash_table_iter_init(&iter, device->networks);
798 while (g_hash_table_iter_next(&iter, &key, &value)) {
799 struct connman_network *network = value;
801 if (connman_network_get_connecting(network)) {
803 * Skip network in the process of connecting.
804 * This is a workaround for WiFi networks serviced
805 * by the supplicant plugin that hold a reference
806 * to the network. If we disconnect the network
807 * here then the referenced object will not be
808 * registered and usage (like launching DHCP client)
809 * will fail. There is nothing to be gained by
810 * removing the network here anyway.
812 connman_warn("Skipping disconnect of %s, network is connecting.",
813 connman_network_get_identifier(network));
817 __connman_network_disconnect(network);
823 int connman_device_reconnect_service(struct connman_device *device)
825 DBG("device %p", device);
827 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
832 #if defined TIZEN_EXT
833 bool connman_device_set_last_user_selection_time(struct connman_device *device,
836 if (device->last_user_selection_time != time) {
837 device->last_user_selection_time = time;
844 time_t connman_device_get_last_user_selection_time(struct connman_device *device)
846 return device->last_user_selection_time;
849 bool connman_device_set_last_user_selection_ident(struct connman_device *device,
852 if (g_strcmp0(device->last_user_selection_ident, ident) != 0) {
853 g_free(device->last_user_selection_ident);
854 device->last_user_selection_ident = g_strdup(ident);
862 const char *connman_device_get_last_user_selection_ident(struct connman_device *device)
864 return device->last_user_selection_ident;
867 bool connman_device_set_last_connected_ident(struct connman_device *device,
870 if (g_strcmp0(device->last_connected_ident, ident) != 0) {
871 g_free(device->last_connected_ident);
872 device->last_connected_ident = g_strdup(ident);
880 const char *connman_device_get_last_connected_ident(struct connman_device *device)
882 return device->last_connected_ident;
886 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
887 void connman_device_save_last_user_selection(struct connman_device *device)
891 gchar *selection_str;
893 keyfile = __connman_storage_load_ins();
895 selection_str = g_strdup_printf("%s:%ld",
896 device->last_user_selection_ident, device->last_user_selection_time);
899 keyfile = g_key_file_new();
901 g_key_file_set_string(keyfile, device->interface, "LastUserSelection", selection_str);
902 DBG("%s", selection_str);
903 __connman_storage_save_ins(keyfile);
906 get_str = g_key_file_get_string(keyfile, device->interface, "LastUserSelection", NULL);
907 if (!get_str || g_strcmp0(get_str, selection_str) != 0) {
908 g_key_file_set_string(keyfile, device->interface, "LastUserSelection", selection_str);
909 DBG("%s -> %s", get_str, selection_str);
910 __connman_storage_save_ins(keyfile);
916 g_free(selection_str);
917 g_key_file_free(keyfile);
920 void connman_device_load_last_user_selection(struct connman_device *device)
924 char **selection_str;
926 keyfile = __connman_storage_load_ins();
930 get_str = g_key_file_get_string(keyfile, device->interface, "LastUserSelection", NULL);
932 selection_str = g_strsplit(get_str, ":", 0);
936 time_t last_user_selection_time;
938 /* Only events that occur within 8 hours are counted. */
939 ref_time = time(NULL);
940 timeinfo = localtime(&ref_time);
941 timeinfo->tm_hour -= 8;
942 ref_time = mktime(timeinfo);
944 last_user_selection_time = strtol(selection_str[1], NULL, 10);
946 if (last_user_selection_time > ref_time) {
947 if (g_strcmp0(selection_str[0], device->last_user_selection_ident) != 0) {
948 g_free(device->last_user_selection_ident);
949 device->last_user_selection_ident = g_strdup(selection_str[0]);
952 device->last_user_selection_time = last_user_selection_time;
954 DBG("%s %ld", device->last_user_selection_ident, device->last_user_selection_time);
957 g_strfreev(selection_str);
963 g_key_file_free(keyfile);
966 void connman_device_save_last_connected(struct connman_device *device)
971 if (!device->last_connected_ident)
974 keyfile = __connman_storage_load_ins();
977 keyfile = g_key_file_new();
979 g_key_file_set_string(keyfile, device->interface, "LastConnected", device->last_connected_ident);
980 DBG("%s", device->last_connected_ident);
981 __connman_storage_save_ins(keyfile);
984 get_str = g_key_file_get_string(keyfile, device->interface, "LastConnected", NULL);
985 if (!get_str || g_strcmp0(get_str, device->last_connected_ident) != 0) {
986 g_key_file_set_string(keyfile, device->interface, "LastConnected", device->last_connected_ident);
987 DBG("%s -> %s", get_str, device->last_connected_ident);
988 __connman_storage_save_ins(keyfile);
994 g_key_file_free(keyfile);
997 void connman_device_load_last_connected(struct connman_device *device)
1002 keyfile = __connman_storage_load_ins();
1006 get_str = g_key_file_get_string(keyfile, device->interface, "LastConnected", NULL);
1008 if (g_strcmp0(get_str, device->last_connected_ident) != 0) {
1009 g_free(device->last_connected_ident);
1010 device->last_connected_ident = g_strdup(get_str);
1013 DBG("%s", device->last_connected_ident);
1018 g_key_file_free(keyfile);
1020 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
1022 static void mark_network_available(gpointer key, gpointer value,
1025 struct connman_network *network = value;
1027 connman_network_set_available(network, true);
1030 static void mark_network_unavailable(gpointer key, gpointer value,
1033 struct connman_network *network = value;
1035 if (connman_network_get_connected(network) ||
1036 connman_network_get_connecting(network))
1039 connman_network_set_available(network, false);
1042 static gboolean remove_unavailable_network(gpointer key, gpointer value,
1045 struct connman_network *network = value;
1047 if (connman_network_get_connected(network) ||
1048 connman_network_get_connecting(network))
1051 if (connman_network_get_available(network))
1057 void __connman_device_cleanup_networks(struct connman_device *device)
1059 g_hash_table_foreach_remove(device->networks,
1060 remove_unavailable_network, NULL);
1063 bool connman_device_get_scanning(struct connman_device *device,
1064 enum connman_service_type type)
1068 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN)
1069 return device->scanning[type];
1071 for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++)
1072 if (device->scanning[i])
1078 void connman_device_reset_scanning(struct connman_device *device)
1080 g_hash_table_foreach(device->networks,
1081 mark_network_available, NULL);
1085 * connman_device_set_scanning:
1086 * @device: device structure
1087 * @scanning: scanning state
1089 * Change scanning state of device
1091 int connman_device_set_scanning(struct connman_device *device,
1092 enum connman_service_type type, bool scanning)
1094 DBG("device %p scanning %d", device, scanning);
1096 if (!device->driver || !device->driver->scan)
1099 if (type == CONNMAN_SERVICE_TYPE_UNKNOWN)
1102 if (device->scanning[type] == scanning)
1105 device->scanning[type] = scanning;
1108 __connman_technology_scan_started(device);
1110 g_hash_table_foreach(device->networks,
1111 mark_network_unavailable, NULL);
1116 __connman_device_cleanup_networks(device);
1118 __connman_technology_scan_stopped(device, type);
1120 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
1122 #if defined TIZEN_EXT_WIFI_MESH
1123 if (type == CONNMAN_SERVICE_TYPE_MESH)
1124 __connman_mesh_auto_connect();
1131 * connman_device_set_string:
1132 * @device: device structure
1133 * @key: unique identifier
1134 * @value: string value
1136 * Set string value for specific key
1138 int connman_device_set_string(struct connman_device *device,
1139 const char *key, const char *value)
1141 DBG("device %p key %s value %s", device, key, value);
1143 if (g_str_equal(key, "Address")) {
1145 if (device->address && device->powered)
1149 g_free(device->address);
1150 device->address = g_strdup(value);
1151 } else if (g_str_equal(key, "Name")) {
1152 g_free(device->name);
1153 device->name = g_strdup(value);
1154 } else if (g_str_equal(key, "Node")) {
1155 g_free(device->node);
1156 device->node = g_strdup(value);
1157 } else if (g_str_equal(key, "Path")) {
1158 g_free(device->path);
1159 device->path = g_strdup(value);
1168 * connman_device_get_string:
1169 * @device: device structure
1170 * @key: unique identifier
1172 * Get string value for specific key
1174 const char *connman_device_get_string(struct connman_device *device,
1177 #if defined TIZEN_EXT
1178 if (!simplified_log)
1180 DBG("device %p key %s", device, key);
1182 if (g_str_equal(key, "Address"))
1183 return device->address;
1184 else if (g_str_equal(key, "Name"))
1185 return device->name;
1186 else if (g_str_equal(key, "Node"))
1187 return device->node;
1188 else if (g_str_equal(key, "Interface"))
1189 return device->interface;
1190 else if (g_str_equal(key, "Path"))
1191 return device->path;
1197 * connman_device_add_network:
1198 * @device: device structure
1199 * @network: network structure
1201 * Add new network to the device
1203 int connman_device_add_network(struct connman_device *device,
1204 struct connman_network *network)
1206 const char *identifier = connman_network_get_identifier(network);
1207 #if defined TIZEN_EXT
1208 if (!simplified_log)
1210 DBG("device %p network %p", device, network);
1215 connman_network_ref(network);
1217 __connman_network_set_device(network, device);
1219 g_hash_table_replace(device->networks, g_strdup(identifier),
1226 * connman_device_get_network:
1227 * @device: device structure
1228 * @identifier: network identifier
1230 * Get network for given identifier
1232 struct connman_network *connman_device_get_network(struct connman_device *device,
1233 const char *identifier)
1235 #if defined TIZEN_EXT
1236 if (!simplified_log)
1238 DBG("device %p identifier %s", device, identifier);
1240 return g_hash_table_lookup(device->networks, identifier);
1243 #if defined TIZEN_EXT
1244 struct connman_network *connman_device_get_default_network(
1245 struct connman_device *device)
1247 return device->network;
1250 void connman_device_set_pending_reply(struct connman_device *device,
1253 device->pending_reply_list = g_list_prepend(device->pending_reply_list, dbus_message_ref(msg));
1256 void connman_device_send_connected_signal(struct connman_device *device,
1259 enum connman_service_type type;
1264 type = __connman_device_get_service_type(device);
1265 device_send_changed(device->interface, type, "Connected", connected);
1268 void connman_device_set_max_scan_ssids(struct connman_device *device,
1271 device->max_scan_ssids = max_scan_ssids;
1274 int connman_device_get_max_scan_ssids(struct connman_device *device)
1276 return device->max_scan_ssids;
1279 void connman_device_set_wifi_5ghz_supported(struct connman_device *device,
1280 bool is_5_0_ghz_supported)
1282 device->is_5_0_ghz_supported = is_5_0_ghz_supported;
1285 void connman_device_set_wifi_6ghz_supported(struct connman_device *device,
1286 bool is_6_0_ghz_supported)
1288 device->is_6_0_ghz_supported = is_6_0_ghz_supported;
1291 bool connman_device_get_wifi_5ghz_supported(struct connman_device *device)
1293 return device->is_5_0_ghz_supported;
1296 bool connman_device_get_wifi_6ghz_supported(struct connman_device *device)
1298 return device->is_6_0_ghz_supported;
1303 * connman_device_remove_network:
1304 * @device: device structure
1305 * @identifier: network identifier
1307 * Remove network for given identifier
1309 int connman_device_remove_network(struct connman_device *device,
1310 struct connman_network *network)
1312 const char *identifier;
1314 DBG("device %p network %p", device, network);
1319 identifier = connman_network_get_identifier(network);
1320 g_hash_table_remove(device->networks, identifier);
1325 void __connman_device_set_network(struct connman_device *device,
1326 struct connman_network *network)
1333 if (device->network == network)
1337 name = connman_network_get_string(network, "Name");
1338 g_free(device->last_network);
1339 device->last_network = g_strdup(name);
1341 device->network = network;
1343 g_free(device->last_network);
1344 device->last_network = NULL;
1346 device->network = NULL;
1350 static bool match_driver(struct connman_device *device,
1351 struct connman_device_driver *driver)
1353 if (device->type == driver->type ||
1354 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1361 * connman_device_register:
1362 * @device: device structure
1364 * Register device with the system
1366 int connman_device_register(struct connman_device *device)
1370 DBG("device %p name %s", device, device->name);
1375 for (list = driver_list; list; list = list->next) {
1376 struct connman_device_driver *driver = list->data;
1378 if (!match_driver(device, driver))
1381 DBG("driver %p name %s", driver, driver->name);
1383 if (driver->probe(device) == 0) {
1384 device->driver = driver;
1389 if (!device->driver)
1392 return __connman_technology_add_device(device);
1396 * connman_device_unregister:
1397 * @device: device structure
1399 * Unregister device with the system
1401 void connman_device_unregister(struct connman_device *device)
1403 DBG("device %p name %s", device, device->name);
1405 if (!device->driver)
1408 remove_device(device);
1412 * connman_device_get_data:
1413 * @device: device structure
1415 * Get private device data pointer
1417 void *connman_device_get_data(struct connman_device *device)
1419 return device->driver_data;
1423 * connman_device_set_data:
1424 * @device: device structure
1425 * @data: data pointer
1427 * Set private device data pointer
1429 void connman_device_set_data(struct connman_device *device, void *data)
1431 device->driver_data = data;
1434 struct connman_device *__connman_device_find_device(
1435 enum connman_service_type type)
1439 for (list = device_list; list; list = list->next) {
1440 struct connman_device *device = list->data;
1441 enum connman_service_type service_type =
1442 __connman_device_get_service_type(device);
1444 if (service_type != type)
1453 struct connman_device *connman_device_find_by_index(int index)
1457 for (list = device_list; list; list = list->next) {
1458 struct connman_device *device = list->data;
1459 if (device->index == index)
1467 * connman_device_set_regdom
1468 * @device: device structure
1469 * @alpha2: string representing regulatory domain
1471 * Set regulatory domain on device basis
1473 int connman_device_set_regdom(struct connman_device *device,
1476 if (!device->driver || !device->driver->set_regdom)
1479 if (!device->powered)
1482 return device->driver->set_regdom(device, alpha2);
1486 * connman_device_regdom_notify
1487 * @device: device structure
1488 * @alpha2: string representing regulatory domain
1490 * Notify on setting regulatory domain on device basis
1492 void connman_device_regdom_notify(struct connman_device *device,
1493 int result, const char *alpha2)
1495 __connman_technology_notify_regdom_by_device(device, result, alpha2);
1498 #if defined TIZEN_EXT
1499 static int device_specific_scan(enum connman_service_type type,
1500 struct connman_device *device,
1501 int scan_type, GSList *specific_scan_list)
1503 if (!device->driver || !device->driver->specific_scan)
1506 if (!device->powered)
1509 return device->driver->specific_scan(type, device, scan_type,
1510 specific_scan_list, NULL);
1513 int __connman_device_request_specific_scan(enum connman_service_type type,
1514 const char *ifname, int scan_type, GSList *specific_scan_list)
1516 bool success = false;
1517 int last_err = -ENOSYS;
1522 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1523 case CONNMAN_SERVICE_TYPE_SYSTEM:
1524 case CONNMAN_SERVICE_TYPE_ETHERNET:
1525 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1526 case CONNMAN_SERVICE_TYPE_CELLULAR:
1527 case CONNMAN_SERVICE_TYPE_GPS:
1528 case CONNMAN_SERVICE_TYPE_VPN:
1529 case CONNMAN_SERVICE_TYPE_GADGET:
1531 case CONNMAN_SERVICE_TYPE_WIFI:
1532 case CONNMAN_SERVICE_TYPE_P2P:
1533 #if defined TIZEN_EXT_WIFI_MESH
1534 case CONNMAN_SERVICE_TYPE_MESH:
1539 for (list = device_list; list; list = list->next) {
1540 struct connman_device *device = list->data;
1541 enum connman_service_type service_type =
1542 __connman_device_get_service_type(device);
1544 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1545 if (type == CONNMAN_SERVICE_TYPE_P2P) {
1546 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1548 } else if (service_type != type)
1552 if (ifname && g_strcmp0(device->interface, ifname) != 0)
1555 err = device_specific_scan(type, device, scan_type, specific_scan_list);
1556 if (err == 0 || err == -EINPROGRESS) {
1560 DBG("device %p err %d", device, err);
1570 int connman_device_request_device_scan(enum connman_service_type type,
1571 const char * ifname, bool force_full_scan)
1573 bool success = false;
1574 int last_err = -ENOSYS;
1579 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1580 case CONNMAN_SERVICE_TYPE_SYSTEM:
1581 case CONNMAN_SERVICE_TYPE_ETHERNET:
1582 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1583 case CONNMAN_SERVICE_TYPE_CELLULAR:
1584 case CONNMAN_SERVICE_TYPE_GPS:
1585 case CONNMAN_SERVICE_TYPE_VPN:
1586 case CONNMAN_SERVICE_TYPE_GADGET:
1588 case CONNMAN_SERVICE_TYPE_WIFI:
1589 case CONNMAN_SERVICE_TYPE_P2P:
1590 #if defined TIZEN_EXT_WIFI_MESH
1591 case CONNMAN_SERVICE_TYPE_MESH:
1596 for (list = device_list; list; list = list->next) {
1597 struct connman_device *device = list->data;
1599 if (!device_has_service_type(device, type))
1602 if (g_strcmp0(device->interface, ifname) != 0)
1605 err = device_scan(type, device, force_full_scan);
1607 if (err == 0 || err == -EINPROGRESS) {
1611 DBG("device %p err %d", device, err);
1622 #if defined TIZEN_EXT_WIFI_MESH
1623 static int device_abort_scan(enum connman_service_type type,
1624 struct connman_device *device)
1626 if (!device->driver || !device->driver->scan)
1629 if (!device->powered)
1632 return device->driver->abort_scan(type, device);
1635 int __connman_device_abort_scan(enum connman_service_type type)
1640 if (type != CONNMAN_SERVICE_TYPE_MESH)
1643 for (list = device_list; list; list = list->next) {
1644 struct connman_device *device = list->data;
1645 enum connman_service_type service_type =
1646 __connman_device_get_service_type(device);
1648 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1649 if (type == CONNMAN_SERVICE_TYPE_MESH)
1650 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1653 if (!device->scanning) {
1658 err = device_abort_scan(type, device);
1664 static int device_mesh_specific_scan(enum connman_service_type type,
1665 struct connman_device *device, const char *name,
1668 if (!device->driver || !device->driver->mesh_specific_scan)
1671 if (!device->powered)
1674 return device->driver->mesh_specific_scan(type, device, name, freq, NULL);
1677 int __connman_device_request_mesh_specific_scan(enum connman_service_type type,
1681 bool success = false;
1682 int last_err = -ENOSYS;
1686 if (type != CONNMAN_SERVICE_TYPE_MESH)
1689 for (list = device_list; list; list = list->next) {
1690 struct connman_device *device = list->data;
1691 enum connman_service_type service_type =
1692 __connman_device_get_service_type(device);
1694 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1695 if (type == CONNMAN_SERVICE_TYPE_MESH)
1696 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1700 err = device_mesh_specific_scan(type, device, name, freq);
1701 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1705 DBG("device %p err %d", device, err);
1714 #endif /* TIZEN_EXT_WIFI_MESH */
1717 static int connman_device_request_scan(enum connman_service_type type,
1718 bool force_full_scan)
1720 bool success = false;
1721 int last_err = -ENOSYS;
1726 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1727 case CONNMAN_SERVICE_TYPE_SYSTEM:
1728 case CONNMAN_SERVICE_TYPE_ETHERNET:
1729 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1730 case CONNMAN_SERVICE_TYPE_CELLULAR:
1731 case CONNMAN_SERVICE_TYPE_GPS:
1732 case CONNMAN_SERVICE_TYPE_VPN:
1733 case CONNMAN_SERVICE_TYPE_GADGET:
1735 case CONNMAN_SERVICE_TYPE_WIFI:
1736 case CONNMAN_SERVICE_TYPE_P2P:
1737 #if defined TIZEN_EXT_WIFI_MESH
1738 case CONNMAN_SERVICE_TYPE_MESH:
1743 for (list = device_list; list; list = list->next) {
1744 struct connman_device *device = list->data;
1746 if (!device_has_service_type(device, type))
1749 err = device_scan(type, device, force_full_scan);
1750 #if defined TIZEN_EXT
1751 /* When Scan is already in progress then return Error so that
1752 * wifi-manager can block the scan-done signal to be sent to
1753 * application and start requested scan after scan already in progress
1754 * is completed then notify to application about the scan event */
1755 if (err == 0 || err == -EINPROGRESS) {
1757 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1762 DBG("device %p err %d", device, err);
1772 int __connman_device_request_scan(enum connman_service_type type)
1774 return connman_device_request_scan(type, false);
1777 int __connman_device_request_scan_full(enum connman_service_type type)
1779 return connman_device_request_scan(type, true);
1782 int __connman_device_request_hidden_scan(struct connman_device *device,
1783 const char *ssid, unsigned int ssid_len,
1784 const char *identity, const char *passphrase,
1785 const char *security, void *user_data)
1787 struct connman_device_scan_params params;
1789 DBG("device %p", device);
1791 if (!device || !device->driver ||
1792 !device->driver->scan)
1795 params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
1797 params.ssid_len = ssid_len;
1798 params.identity = identity;
1799 params.passphrase = passphrase;
1800 params.security = security;
1801 params.user_data = user_data;
1803 return device->driver->scan(device, ¶ms);
1806 void __connman_device_stop_scan(enum connman_service_type type)
1810 for (list = device_list; list; list = list->next) {
1811 struct connman_device *device = list->data;
1813 if (!device_has_service_type(device, type))
1816 if (device->driver && device->driver->stop_scan)
1817 device->driver->stop_scan(type, device);
1821 #if defined TIZEN_EXT
1822 #define WIFI_MAC "/opt/etc/.mac.info"
1823 #define MAC_ADDR_LEN 18
1825 char *_get_wifi_addr(void)
1829 char wifi_mac[MAC_ADDR_LEN + 1];
1832 fp = fopen(WIFI_MAC, "r");
1834 connman_error("[%s] not present", WIFI_MAC);
1838 rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
1840 connman_error("Failed to get wifi mac address");
1845 str = g_try_malloc0(MAC_ADDR_LEN);
1847 connman_error("memory allocation failed");
1852 snprintf(str, MAC_ADDR_LEN, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
1853 g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
1854 g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
1855 g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
1856 g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
1857 g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
1858 g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
1863 char *_get_wifi_ident(void)
1867 char wifi_mac[MAC_ADDR_LEN + 1];
1870 fp = fopen(WIFI_MAC, "r");
1872 connman_error("[%s] not present", WIFI_MAC);
1876 rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
1878 connman_error("Failed to get wifi mac address");
1883 str = g_try_malloc0(MAC_ADDR_LEN);
1885 connman_error("memory allocation failed");
1890 snprintf(str, MAC_ADDR_LEN, "%c%c%c%c%c%c%c%c%c%c%c%c",
1891 g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
1892 g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
1893 g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
1894 g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
1895 g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
1896 g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
1902 #if defined TIZEN_EXT
1903 char *index2ident(int index, const char *prefix)
1905 static char *index2ident(int index, const char *prefix)
1909 struct ether_addr eth;
1916 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1920 memset(&ifr, 0, sizeof(ifr));
1921 ifr.ifr_ifindex = index;
1923 err = ioctl(sk, SIOCGIFNAME, &ifr);
1926 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1933 len = prefix ? strlen(prefix) + 18 : 18;
1935 str = g_malloc(len);
1939 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1940 snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
1941 prefix ? prefix : "",
1942 eth.ether_addr_octet[0],
1943 eth.ether_addr_octet[1],
1944 eth.ether_addr_octet[2],
1945 eth.ether_addr_octet[3],
1946 eth.ether_addr_octet[4],
1947 eth.ether_addr_octet[5]);
1952 #if defined TIZEN_EXT
1953 char *index2addr(int index)
1955 static char *index2addr(int index)
1959 struct ether_addr eth;
1966 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1970 memset(&ifr, 0, sizeof(ifr));
1971 ifr.ifr_ifindex = index;
1973 err = ioctl(sk, SIOCGIFNAME, &ifr);
1976 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1987 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1988 snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
1989 eth.ether_addr_octet[0],
1990 eth.ether_addr_octet[1],
1991 eth.ether_addr_octet[2],
1992 eth.ether_addr_octet[3],
1993 eth.ether_addr_octet[4],
1994 eth.ether_addr_octet[5]);
1999 struct connman_device *connman_device_create_from_index(int index)
2001 enum connman_device_type type;
2002 struct connman_device *device;
2003 char *devname, *ident = NULL;
2004 char *addr = NULL, *name = NULL;
2009 devname = connman_inet_ifname(index);
2013 if (__connman_device_isfiltered(devname)) {
2014 connman_info("Ignoring interface %s (filtered)", devname);
2019 type = __connman_rtnl_get_device_type(index);
2022 case CONNMAN_DEVICE_TYPE_UNKNOWN:
2023 connman_info("Ignoring interface %s (type unknown)", devname);
2026 case CONNMAN_DEVICE_TYPE_ETHERNET:
2027 case CONNMAN_DEVICE_TYPE_GADGET:
2028 case CONNMAN_DEVICE_TYPE_WIFI:
2029 name = index2ident(index, "");
2030 addr = index2addr(index);
2032 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
2033 case CONNMAN_DEVICE_TYPE_CELLULAR:
2034 case CONNMAN_DEVICE_TYPE_GPS:
2035 case CONNMAN_DEVICE_TYPE_VENDOR:
2036 name = g_strdup(devname);
2040 device = connman_device_create(name, type);
2045 case CONNMAN_DEVICE_TYPE_UNKNOWN:
2046 case CONNMAN_DEVICE_TYPE_VENDOR:
2047 case CONNMAN_DEVICE_TYPE_GPS:
2049 case CONNMAN_DEVICE_TYPE_ETHERNET:
2050 case CONNMAN_DEVICE_TYPE_GADGET:
2051 ident = index2ident(index, NULL);
2053 case CONNMAN_DEVICE_TYPE_WIFI:
2054 ident = index2ident(index, NULL);
2056 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
2058 case CONNMAN_DEVICE_TYPE_CELLULAR:
2059 ident = index2ident(index, NULL);
2063 connman_device_set_index(device, index);
2064 connman_device_set_interface(device, devname);
2065 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
2066 connman_device_load_last_connected(device);
2067 connman_device_load_last_user_selection(device);
2068 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
2071 connman_device_set_ident(device, ident);
2075 connman_device_set_string(device, "Address", addr);
2085 bool __connman_device_isfiltered(const char *devname)
2088 char **blacklisted_interfaces;
2094 for (pattern = device_filter, match = false; *pattern; pattern++) {
2095 if (g_pattern_match_simple(*pattern, devname)) {
2102 DBG("ignoring device %s (match)", devname);
2107 if (g_pattern_match_simple("dummy*", devname)) {
2108 DBG("ignoring dummy networking devices");
2112 if (!nodevice_filter)
2115 for (pattern = nodevice_filter; *pattern; pattern++) {
2116 if (g_pattern_match_simple(*pattern, devname)) {
2117 DBG("ignoring device %s (no match)", devname);
2123 if (__connman_inet_isrootnfs_device(devname)) {
2124 DBG("ignoring device %s (rootnfs)", devname);
2128 blacklisted_interfaces =
2129 connman_setting_get_string_list("NetworkInterfaceBlacklist");
2130 if (!blacklisted_interfaces)
2133 for (pattern = blacklisted_interfaces; *pattern; pattern++) {
2134 if (g_str_has_prefix(devname, *pattern)) {
2135 DBG("ignoring device %s (blacklist)", devname);
2143 static void cleanup_devices(void)
2146 * Check what interfaces are currently up and if connman is
2147 * suppose to handle the interface, then cleanup the mess
2148 * related to that interface. There might be weird routes etc
2149 * that are related to that interface and that might confuse
2150 * connmand. So in this case we just turn the interface down
2151 * so that kernel removes routes/addresses automatically and
2152 * then proceed the startup.
2154 * Note that this cleanup must be done before rtnl/detect code
2155 * has activated interface watches.
2161 interfaces = __connman_inet_get_running_interfaces();
2166 for (i = 0; interfaces[i]; i++) {
2169 struct sockaddr_in sin_addr, sin_mask;
2171 filtered = __connman_device_isfiltered(interfaces[i]);
2175 index = connman_inet_ifindex(interfaces[i]);
2179 if (!__connman_inet_get_address_netmask(index, &sin_addr,
2181 char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
2182 char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
2184 if (__connman_config_address_provisioned(address,
2186 DBG("Skip %s which is already provisioned "
2187 "with %s/%s", interfaces[i], address,
2198 DBG("cleaning up %s index %d", interfaces[i], index);
2200 #if defined TIZEN_EXT
2201 if (strcmp(interfaces[i], "wlan0") != 0)
2203 connman_inet_ifdown(index);
2206 * ConnMan will turn the interface UP automatically so
2207 * no need to do it here.
2211 g_strfreev(interfaces);
2214 int __connman_device_init(const char *device, const char *nodevice)
2218 #if defined TIZEN_EXT
2219 connection = connman_dbus_get_connection();
2223 device_filter = g_strsplit(device, ",", -1);
2226 nodevice_filter = g_strsplit(nodevice, ",", -1);
2233 void __connman_device_cleanup(void)
2237 g_strfreev(nodevice_filter);
2238 g_strfreev(device_filter);
2240 #if defined TIZEN_EXT
2241 dbus_connection_unref(connection);
2246 void connman_device_mac_policy_notify(struct connman_device *device,
2247 int result, unsigned int policy)
2249 device->mac_policy = policy;
2250 __connman_technology_notify_mac_policy_by_device(device, result, policy);
2253 int connman_device_set_mac_policy(struct connman_device *device,
2254 unsigned int policy)
2258 if (!device || !device->driver || !device->driver->set_mac_policy)
2261 device->mac_policy = policy;
2262 err = device->driver->set_mac_policy(device, policy);
2266 unsigned int connman_device_get_mac_policy(struct connman_device *device)
2268 return device->mac_policy;
2271 void connman_device_preassoc_mac_policy_notify(struct connman_device *device,
2272 int result, unsigned int policy)
2274 device->preassoc_mac_policy = policy;
2275 __connman_technology_notify_preassoc_mac_policy_by_device(device, result, policy);
2278 int connman_device_set_preassoc_mac_policy(struct connman_device *device,
2279 unsigned int policy)
2283 if (!device || !device->driver || !device->driver->set_preassoc_mac_policy)
2286 device->preassoc_mac_policy = policy;
2287 err = device->driver->set_preassoc_mac_policy(device, policy);
2291 unsigned int connman_device_get_preassoc_mac_policy(struct connman_device *device)
2293 return device->preassoc_mac_policy;
2296 void connman_device_random_mac_lifetime_notify(struct connman_device *device,
2297 int result, unsigned int lifetime)
2299 device->random_mac_lifetime = lifetime;
2300 __connman_technology_notify_random_mac_lifetime_by_device(device, result, lifetime);
2303 int connman_device_set_random_mac_lifetime(struct connman_device *device,
2304 unsigned int lifetime)
2308 if (!device || !device->driver || !device->driver->set_random_mac_lifetime)
2311 device->random_mac_lifetime = lifetime;
2312 err = device->driver->set_random_mac_lifetime(device, lifetime);
2316 unsigned int connman_device_get_random_mac_lifetime(struct connman_device *device)
2318 return device->random_mac_lifetime;