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 #if defined TIZEN_EXT
392 __connman_technology_notify_device_detected_by_device(device, "", false);
395 device->driver = NULL;
398 static void remove_driver(struct connman_device_driver *driver)
402 DBG("driver %p name %s", driver, driver->name);
404 for (list = device_list; list; list = list->next) {
405 struct connman_device *device = list->data;
407 if (device->driver == driver)
408 remove_device(device);
412 bool __connman_device_has_driver(struct connman_device *device)
414 if (!device || !device->driver)
420 static GSList *driver_list = NULL;
422 static gint compare_priority(gconstpointer a, gconstpointer b)
424 const struct connman_device_driver *driver1 = a;
425 const struct connman_device_driver *driver2 = b;
427 return driver2->priority - driver1->priority;
431 * connman_device_driver_register:
432 * @driver: device driver definition
434 * Register a new device driver
436 * Returns: %0 on success
438 int connman_device_driver_register(struct connman_device_driver *driver)
440 DBG("driver %p name %s", driver, driver->name);
442 driver_list = g_slist_insert_sorted(driver_list, driver,
444 probe_driver(driver);
450 * connman_device_driver_unregister:
451 * @driver: device driver definition
453 * Remove a previously registered device driver
455 void connman_device_driver_unregister(struct connman_device_driver *driver)
457 DBG("driver %p name %s", driver, driver->name);
459 driver_list = g_slist_remove(driver_list, driver);
461 remove_driver(driver);
464 static void free_network(gpointer data)
466 struct connman_network *network = data;
468 DBG("network %p", network);
470 __connman_network_set_device(network, NULL);
472 connman_network_unref(network);
475 static void device_destruct(struct connman_device *device)
477 DBG("device %p name %s", device, device->name);
479 clear_pending_trigger(device);
481 g_hash_table_destroy(device->networks);
482 device->networks = NULL;
484 g_free(device->ident);
485 g_free(device->node);
486 g_free(device->name);
487 g_free(device->address);
488 g_free(device->interface);
489 g_free(device->path);
491 g_free(device->last_network);
493 #if defined TIZEN_EXT
494 g_free(device->last_user_selection_ident);
495 g_free(device->last_connected_ident);
501 #if defined TIZEN_EXT
502 static void device_send_changed(const char *ifname, enum connman_service_type type,
503 const char *key, bool state)
506 DBusMessageIter iter, dict;
507 dbus_bool_t value = state;
508 const char *tech_path = connman_techonology_get_path(type);
510 if (!tech_path || !ifname)
513 DBG("%s %s %s", ifname, key, state ? "TRUE" : "FALSE");
515 signal = dbus_message_new_signal(tech_path,
516 CONNMAN_TECHNOLOGY_INTERFACE, "DeviceChanged");
520 dbus_message_iter_init_append(signal, &iter);
522 connman_dbus_dict_open(&iter, &dict);
523 connman_dbus_dict_append_basic(&dict, "Ifname",
526 connman_dbus_dict_append_basic(&dict, key,
529 connman_dbus_dict_close(&iter, &dict);
531 dbus_connection_send(connection, signal, NULL);
532 dbus_message_unref(signal);
535 static void __device_send_reply(gpointer data, gpointer user_data)
537 DBusMessage *msg = (DBusMessage *)data;
538 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
539 dbus_message_unref(msg);
542 static void device_send_reply(struct connman_device *device)
544 if (device->pending_reply_list) {
545 g_list_foreach(device->pending_reply_list, __device_send_reply, NULL);
546 g_list_free(device->pending_reply_list);
547 device->pending_reply_list = NULL;
553 * connman_device_create:
554 * @node: device node name (for example an address)
557 * Allocate a new device of given #type and assign the #node name to it.
559 * Returns: a newly-allocated #connman_device structure
561 struct connman_device *connman_device_create(const char *node,
562 enum connman_device_type type)
564 struct connman_device *device;
566 DBG("node %s type %d", node, type);
568 device = g_try_new0(struct connman_device, 1);
572 DBG("device %p", device);
574 device->refcount = 1;
577 device->name = g_strdup(type2description(device->type));
579 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
580 g_free, free_network);
582 device_list = g_slist_prepend(device_list, device);
588 * connman_device_ref:
589 * @device: device structure
591 * Increase reference counter of device
593 struct connman_device *connman_device_ref_debug(struct connman_device *device,
594 const char *file, int line, const char *caller)
596 DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
599 __sync_fetch_and_add(&device->refcount, 1);
605 * connman_device_unref:
606 * @device: device structure
608 * Decrease reference counter of device
610 void connman_device_unref_debug(struct connman_device *device,
611 const char *file, int line, const char *caller)
613 DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1,
616 if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
619 if (device->driver) {
620 device->driver->remove(device);
621 device->driver = NULL;
624 device_list = g_slist_remove(device_list, device);
626 device_destruct(device);
629 const char *__connman_device_get_type(struct connman_device *device)
631 return type2string(device->type);
635 * connman_device_get_type:
636 * @device: device structure
640 enum connman_device_type connman_device_get_type(struct connman_device *device)
646 * connman_device_set_index:
647 * @device: device structure
648 * @index: index number
650 * Set index number of device
652 void connman_device_set_index(struct connman_device *device, int index)
654 device->index = index;
658 * connman_device_get_index:
659 * @device: device structure
661 * Get index number of device
663 int connman_device_get_index(struct connman_device *device)
665 return device->index;
669 * connman_device_set_interface:
670 * @device: device structure
671 * @interface: interface name
673 * Set interface name of device
675 void connman_device_set_interface(struct connman_device *device,
676 const char *interface)
678 g_free(device->interface);
679 device->interface = g_strdup(interface);
682 const char *str = type2description(device->type);
683 if (str && device->interface)
684 device->name = g_strdup_printf("%s (%s)", str,
690 * connman_device_set_ident:
691 * @device: device structure
692 * @ident: unique identifier
694 * Set unique identifier of device
696 void connman_device_set_ident(struct connman_device *device,
700 if (device->ident && device->powered)
704 g_free(device->ident);
705 device->ident = g_strdup(ident);
708 const char *connman_device_get_ident(struct connman_device *device)
710 return device->ident;
714 * connman_device_set_powered:
715 * @device: device structure
716 * @powered: powered state
718 * Change power state of device
720 int connman_device_set_powered(struct connman_device *device,
723 struct connman_device_scan_params params;
724 enum connman_service_type type;
727 DBG("device %p powered %d", device, powered);
729 if (device->powered == powered)
732 #if defined TIZEN_EXT
733 device_send_reply(device);
736 clear_pending_trigger(device);
738 device->powered_pending = PENDING_NONE;
740 device->powered = powered;
742 type = __connman_device_get_service_type(device);
744 #if defined TIZEN_EXT
745 device_send_changed(device->interface, type, "Powered", powered);
746 technology_save_device(device);
749 if (!device->powered) {
750 __connman_technology_disabled(type);
754 __connman_technology_enabled(type);
756 for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++)
757 device->scanning[i] = false;
759 if (device->driver && device->driver->scan) {
760 memset(¶ms, 0, sizeof(params));
761 params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
763 device->driver->scan(device, ¶ms);
769 bool connman_device_get_powered(struct connman_device *device)
771 return device->powered;
774 static int device_scan(enum connman_service_type type,
775 struct connman_device *device,
776 bool force_full_scan)
778 struct connman_device_scan_params params;
780 if (!device->driver || !device->driver->scan)
783 if (!device->powered)
786 memset(¶ms, 0, sizeof(params));
788 params.force_full_scan = force_full_scan;
790 return device->driver->scan(device, ¶ms);
793 int __connman_device_disconnect(struct connman_device *device)
798 DBG("device %p", device);
800 g_hash_table_iter_init(&iter, device->networks);
802 while (g_hash_table_iter_next(&iter, &key, &value)) {
803 struct connman_network *network = value;
805 if (connman_network_get_connecting(network)) {
807 * Skip network in the process of connecting.
808 * This is a workaround for WiFi networks serviced
809 * by the supplicant plugin that hold a reference
810 * to the network. If we disconnect the network
811 * here then the referenced object will not be
812 * registered and usage (like launching DHCP client)
813 * will fail. There is nothing to be gained by
814 * removing the network here anyway.
816 connman_warn("Skipping disconnect of %s, network is connecting.",
817 connman_network_get_identifier(network));
821 __connman_network_disconnect(network);
827 int connman_device_reconnect_service(struct connman_device *device)
829 DBG("device %p", device);
831 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
836 #if defined TIZEN_EXT
837 bool connman_device_set_last_user_selection_time(struct connman_device *device,
840 if (device->last_user_selection_time != time) {
841 device->last_user_selection_time = time;
848 time_t connman_device_get_last_user_selection_time(struct connman_device *device)
850 return device->last_user_selection_time;
853 bool connman_device_set_last_user_selection_ident(struct connman_device *device,
856 if (g_strcmp0(device->last_user_selection_ident, ident) != 0) {
857 g_free(device->last_user_selection_ident);
858 device->last_user_selection_ident = g_strdup(ident);
866 const char *connman_device_get_last_user_selection_ident(struct connman_device *device)
868 return device->last_user_selection_ident;
871 bool connman_device_set_last_connected_ident(struct connman_device *device,
874 if (g_strcmp0(device->last_connected_ident, ident) != 0) {
875 g_free(device->last_connected_ident);
876 device->last_connected_ident = g_strdup(ident);
884 const char *connman_device_get_last_connected_ident(struct connman_device *device)
886 return device->last_connected_ident;
890 #if defined TIZEN_EXT
891 void connman_device_save_last_user_selection(struct connman_device *device)
895 gchar *selection_str;
897 keyfile = __connman_storage_load_ins();
899 selection_str = g_strdup_printf("%s:%ld",
900 device->last_user_selection_ident, device->last_user_selection_time);
903 keyfile = g_key_file_new();
905 g_key_file_set_string(keyfile, device->interface, "LastUserSelection", selection_str);
906 DBG("%s", selection_str);
907 __connman_storage_save_ins(keyfile);
910 get_str = g_key_file_get_string(keyfile, device->interface, "LastUserSelection", NULL);
911 if (!get_str || g_strcmp0(get_str, selection_str) != 0) {
912 g_key_file_set_string(keyfile, device->interface, "LastUserSelection", selection_str);
913 DBG("%s -> %s", get_str, selection_str);
914 __connman_storage_save_ins(keyfile);
920 g_free(selection_str);
921 g_key_file_free(keyfile);
924 void connman_device_load_last_user_selection(struct connman_device *device)
928 char **selection_str;
930 keyfile = __connman_storage_load_ins();
934 get_str = g_key_file_get_string(keyfile, device->interface, "LastUserSelection", NULL);
936 selection_str = g_strsplit(get_str, ":", 0);
940 time_t last_user_selection_time;
942 /* Only events that occur within 8 hours are counted. */
943 ref_time = time(NULL);
944 timeinfo = localtime(&ref_time);
945 timeinfo->tm_hour -= 8;
946 ref_time = mktime(timeinfo);
948 last_user_selection_time = strtol(selection_str[1], NULL, 10);
950 if (last_user_selection_time > ref_time) {
951 if (g_strcmp0(selection_str[0], device->last_user_selection_ident) != 0) {
952 g_free(device->last_user_selection_ident);
953 device->last_user_selection_ident = g_strdup(selection_str[0]);
956 device->last_user_selection_time = last_user_selection_time;
958 DBG("%s %ld", device->last_user_selection_ident, device->last_user_selection_time);
961 g_strfreev(selection_str);
967 g_key_file_free(keyfile);
970 void connman_device_save_last_connected(struct connman_device *device)
975 if (!device->last_connected_ident)
978 keyfile = __connman_storage_load_ins();
981 keyfile = g_key_file_new();
983 g_key_file_set_string(keyfile, device->interface, "LastConnected", device->last_connected_ident);
984 DBG("%s", device->last_connected_ident);
985 __connman_storage_save_ins(keyfile);
988 get_str = g_key_file_get_string(keyfile, device->interface, "LastConnected", NULL);
989 if (!get_str || g_strcmp0(get_str, device->last_connected_ident) != 0) {
990 g_key_file_set_string(keyfile, device->interface, "LastConnected", device->last_connected_ident);
991 DBG("%s -> %s", get_str, device->last_connected_ident);
992 __connman_storage_save_ins(keyfile);
998 g_key_file_free(keyfile);
1001 void connman_device_load_last_connected(struct connman_device *device)
1006 keyfile = __connman_storage_load_ins();
1010 get_str = g_key_file_get_string(keyfile, device->interface, "LastConnected", NULL);
1012 if (g_strcmp0(get_str, device->last_connected_ident) != 0) {
1013 g_free(device->last_connected_ident);
1014 device->last_connected_ident = g_strdup(get_str);
1017 DBG("%s", device->last_connected_ident);
1022 g_key_file_free(keyfile);
1024 #endif /* defined TIZEN_EXT */
1026 static void mark_network_available(gpointer key, gpointer value,
1029 struct connman_network *network = value;
1031 connman_network_set_available(network, true);
1034 static void mark_network_unavailable(gpointer key, gpointer value,
1037 struct connman_network *network = value;
1039 if (connman_network_get_connected(network) ||
1040 connman_network_get_connecting(network))
1043 connman_network_set_available(network, false);
1046 static gboolean remove_unavailable_network(gpointer key, gpointer value,
1049 struct connman_network *network = value;
1051 if (connman_network_get_connected(network) ||
1052 connman_network_get_connecting(network))
1055 if (connman_network_get_available(network))
1061 void __connman_device_cleanup_networks(struct connman_device *device)
1063 g_hash_table_foreach_remove(device->networks,
1064 remove_unavailable_network, NULL);
1067 bool connman_device_get_scanning(struct connman_device *device,
1068 enum connman_service_type type)
1072 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN)
1073 return device->scanning[type];
1075 for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++)
1076 if (device->scanning[i])
1082 void connman_device_reset_scanning(struct connman_device *device)
1084 g_hash_table_foreach(device->networks,
1085 mark_network_available, NULL);
1089 * connman_device_set_scanning:
1090 * @device: device structure
1091 * @scanning: scanning state
1093 * Change scanning state of device
1095 int connman_device_set_scanning(struct connman_device *device,
1096 enum connman_service_type type, bool scanning)
1098 DBG("device %p scanning %d", device, scanning);
1100 if (!device->driver || !device->driver->scan)
1103 if (type == CONNMAN_SERVICE_TYPE_UNKNOWN)
1106 if (device->scanning[type] == scanning)
1109 device->scanning[type] = scanning;
1112 __connman_technology_scan_started(device);
1114 g_hash_table_foreach(device->networks,
1115 mark_network_unavailable, NULL);
1120 __connman_device_cleanup_networks(device);
1122 __connman_technology_scan_stopped(device, type);
1124 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
1126 #if defined TIZEN_EXT_WIFI_MESH
1127 if (type == CONNMAN_SERVICE_TYPE_MESH)
1128 __connman_mesh_auto_connect();
1135 * connman_device_set_string:
1136 * @device: device structure
1137 * @key: unique identifier
1138 * @value: string value
1140 * Set string value for specific key
1142 int connman_device_set_string(struct connman_device *device,
1143 const char *key, const char *value)
1145 DBG("device %p key %s value %s", device, key, value);
1147 if (g_str_equal(key, "Address")) {
1149 if (device->address && device->powered)
1153 g_free(device->address);
1154 device->address = g_strdup(value);
1155 } else if (g_str_equal(key, "Name")) {
1156 g_free(device->name);
1157 device->name = g_strdup(value);
1158 } else if (g_str_equal(key, "Node")) {
1159 g_free(device->node);
1160 device->node = g_strdup(value);
1161 } else if (g_str_equal(key, "Path")) {
1162 g_free(device->path);
1163 device->path = g_strdup(value);
1172 * connman_device_get_string:
1173 * @device: device structure
1174 * @key: unique identifier
1176 * Get string value for specific key
1178 const char *connman_device_get_string(struct connman_device *device,
1181 #if defined TIZEN_EXT
1182 if (!simplified_log)
1184 DBG("device %p key %s", device, key);
1186 if (g_str_equal(key, "Address"))
1187 return device->address;
1188 else if (g_str_equal(key, "Name"))
1189 return device->name;
1190 else if (g_str_equal(key, "Node"))
1191 return device->node;
1192 else if (g_str_equal(key, "Interface"))
1193 return device->interface;
1194 else if (g_str_equal(key, "Path"))
1195 return device->path;
1201 * connman_device_add_network:
1202 * @device: device structure
1203 * @network: network structure
1205 * Add new network to the device
1207 int connman_device_add_network(struct connman_device *device,
1208 struct connman_network *network)
1210 const char *identifier = connman_network_get_identifier(network);
1211 #if defined TIZEN_EXT
1212 if (!simplified_log)
1214 DBG("device %p network %p", device, network);
1219 connman_network_ref(network);
1221 __connman_network_set_device(network, device);
1223 g_hash_table_replace(device->networks, g_strdup(identifier),
1230 * connman_device_get_network:
1231 * @device: device structure
1232 * @identifier: network identifier
1234 * Get network for given identifier
1236 struct connman_network *connman_device_get_network(struct connman_device *device,
1237 const char *identifier)
1239 #if defined TIZEN_EXT
1240 if (!simplified_log)
1242 DBG("device %p identifier %s", device, identifier);
1244 return g_hash_table_lookup(device->networks, identifier);
1247 #if defined TIZEN_EXT
1248 struct connman_network *connman_device_get_default_network(
1249 struct connman_device *device)
1251 return device->network;
1254 void connman_device_set_pending_reply(struct connman_device *device,
1257 device->pending_reply_list = g_list_prepend(device->pending_reply_list, dbus_message_ref(msg));
1260 void connman_device_send_connected_signal(struct connman_device *device,
1263 enum connman_service_type type;
1268 type = __connman_device_get_service_type(device);
1269 device_send_changed(device->interface, type, "Connected", connected);
1272 void connman_device_set_max_scan_ssids(struct connman_device *device,
1275 device->max_scan_ssids = max_scan_ssids;
1278 int connman_device_get_max_scan_ssids(struct connman_device *device)
1280 return device->max_scan_ssids;
1283 void connman_device_set_wifi_5ghz_supported(struct connman_device *device,
1284 bool is_5_0_ghz_supported)
1286 device->is_5_0_ghz_supported = is_5_0_ghz_supported;
1289 void connman_device_set_wifi_6ghz_supported(struct connman_device *device,
1290 bool is_6_0_ghz_supported)
1292 device->is_6_0_ghz_supported = is_6_0_ghz_supported;
1295 bool connman_device_get_wifi_5ghz_supported(struct connman_device *device)
1297 return device->is_5_0_ghz_supported;
1300 bool connman_device_get_wifi_6ghz_supported(struct connman_device *device)
1302 return device->is_6_0_ghz_supported;
1307 * connman_device_remove_network:
1308 * @device: device structure
1309 * @identifier: network identifier
1311 * Remove network for given identifier
1313 int connman_device_remove_network(struct connman_device *device,
1314 struct connman_network *network)
1316 const char *identifier;
1318 DBG("device %p network %p", device, network);
1323 identifier = connman_network_get_identifier(network);
1324 g_hash_table_remove(device->networks, identifier);
1329 void __connman_device_set_network(struct connman_device *device,
1330 struct connman_network *network)
1337 if (device->network == network)
1341 name = connman_network_get_string(network, "Name");
1342 g_free(device->last_network);
1343 device->last_network = g_strdup(name);
1345 device->network = network;
1347 g_free(device->last_network);
1348 device->last_network = NULL;
1350 device->network = NULL;
1354 static bool match_driver(struct connman_device *device,
1355 struct connman_device_driver *driver)
1357 if (device->type == driver->type ||
1358 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1365 * connman_device_register:
1366 * @device: device structure
1368 * Register device with the system
1370 int connman_device_register(struct connman_device *device)
1374 DBG("device %p name %s", device, device->name);
1379 for (list = driver_list; list; list = list->next) {
1380 struct connman_device_driver *driver = list->data;
1382 if (!match_driver(device, driver))
1385 DBG("driver %p name %s", driver, driver->name);
1387 if (driver->probe(device) == 0) {
1388 device->driver = driver;
1393 if (!device->driver)
1396 return __connman_technology_add_device(device);
1400 * connman_device_unregister:
1401 * @device: device structure
1403 * Unregister device with the system
1405 void connman_device_unregister(struct connman_device *device)
1407 DBG("device %p name %s", device, device->name);
1409 if (!device->driver)
1412 remove_device(device);
1416 * connman_device_get_data:
1417 * @device: device structure
1419 * Get private device data pointer
1421 void *connman_device_get_data(struct connman_device *device)
1423 return device->driver_data;
1427 * connman_device_set_data:
1428 * @device: device structure
1429 * @data: data pointer
1431 * Set private device data pointer
1433 void connman_device_set_data(struct connman_device *device, void *data)
1435 device->driver_data = data;
1438 struct connman_device *__connman_device_find_device(
1439 enum connman_service_type type)
1443 for (list = device_list; list; list = list->next) {
1444 struct connman_device *device = list->data;
1445 enum connman_service_type service_type =
1446 __connman_device_get_service_type(device);
1448 if (service_type != type)
1457 struct connman_device *connman_device_find_by_index(int index)
1461 for (list = device_list; list; list = list->next) {
1462 struct connman_device *device = list->data;
1463 if (device->index == index)
1471 * connman_device_set_regdom
1472 * @device: device structure
1473 * @alpha2: string representing regulatory domain
1475 * Set regulatory domain on device basis
1477 int connman_device_set_regdom(struct connman_device *device,
1480 if (!device->driver || !device->driver->set_regdom)
1483 if (!device->powered)
1486 return device->driver->set_regdom(device, alpha2);
1490 * connman_device_regdom_notify
1491 * @device: device structure
1492 * @alpha2: string representing regulatory domain
1494 * Notify on setting regulatory domain on device basis
1496 void connman_device_regdom_notify(struct connman_device *device,
1497 int result, const char *alpha2)
1499 __connman_technology_notify_regdom_by_device(device, result, alpha2);
1502 #if defined TIZEN_EXT
1503 static int device_specific_scan(enum connman_service_type type,
1504 struct connman_device *device,
1505 int scan_type, GSList *specific_scan_list)
1507 if (!device->driver || !device->driver->specific_scan)
1510 if (!device->powered)
1513 return device->driver->specific_scan(type, device, scan_type,
1514 specific_scan_list, NULL);
1517 int __connman_device_request_specific_scan(enum connman_service_type type,
1518 const char *ifname, int scan_type, GSList *specific_scan_list)
1520 bool success = false;
1521 int last_err = -ENOSYS;
1526 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1527 case CONNMAN_SERVICE_TYPE_SYSTEM:
1528 case CONNMAN_SERVICE_TYPE_ETHERNET:
1529 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1530 case CONNMAN_SERVICE_TYPE_CELLULAR:
1531 case CONNMAN_SERVICE_TYPE_GPS:
1532 case CONNMAN_SERVICE_TYPE_VPN:
1533 case CONNMAN_SERVICE_TYPE_GADGET:
1535 case CONNMAN_SERVICE_TYPE_WIFI:
1536 case CONNMAN_SERVICE_TYPE_P2P:
1537 #if defined TIZEN_EXT_WIFI_MESH
1538 case CONNMAN_SERVICE_TYPE_MESH:
1543 for (list = device_list; list; list = list->next) {
1544 struct connman_device *device = list->data;
1545 enum connman_service_type service_type =
1546 __connman_device_get_service_type(device);
1548 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1549 if (type == CONNMAN_SERVICE_TYPE_P2P) {
1550 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1552 } else if (service_type != type)
1556 if (ifname && g_strcmp0(device->interface, ifname) != 0)
1559 err = device_specific_scan(type, device, scan_type, specific_scan_list);
1560 if (err == 0 || err == -EINPROGRESS) {
1564 DBG("device %p err %d", device, err);
1574 int connman_device_request_device_scan(enum connman_service_type type,
1575 const char * ifname, bool force_full_scan)
1577 bool success = false;
1578 int last_err = -ENOSYS;
1583 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1584 case CONNMAN_SERVICE_TYPE_SYSTEM:
1585 case CONNMAN_SERVICE_TYPE_ETHERNET:
1586 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1587 case CONNMAN_SERVICE_TYPE_CELLULAR:
1588 case CONNMAN_SERVICE_TYPE_GPS:
1589 case CONNMAN_SERVICE_TYPE_VPN:
1590 case CONNMAN_SERVICE_TYPE_GADGET:
1592 case CONNMAN_SERVICE_TYPE_WIFI:
1593 case CONNMAN_SERVICE_TYPE_P2P:
1594 #if defined TIZEN_EXT_WIFI_MESH
1595 case CONNMAN_SERVICE_TYPE_MESH:
1600 for (list = device_list; list; list = list->next) {
1601 struct connman_device *device = list->data;
1603 if (!device_has_service_type(device, type))
1606 if (g_strcmp0(device->interface, ifname) != 0)
1609 err = device_scan(type, device, force_full_scan);
1611 if (err == 0 || err == -EINPROGRESS) {
1615 DBG("device %p err %d", device, err);
1626 #if defined TIZEN_EXT_WIFI_MESH
1627 static int device_abort_scan(enum connman_service_type type,
1628 struct connman_device *device)
1630 if (!device->driver || !device->driver->scan)
1633 if (!device->powered)
1636 return device->driver->abort_scan(type, device);
1639 int __connman_device_abort_scan(enum connman_service_type type)
1644 if (type != CONNMAN_SERVICE_TYPE_MESH)
1647 for (list = device_list; list; list = list->next) {
1648 struct connman_device *device = list->data;
1649 enum connman_service_type service_type =
1650 __connman_device_get_service_type(device);
1652 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1653 if (type == CONNMAN_SERVICE_TYPE_MESH)
1654 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1657 if (!device->scanning) {
1662 err = device_abort_scan(type, device);
1668 static int device_mesh_specific_scan(enum connman_service_type type,
1669 struct connman_device *device, const char *name,
1672 if (!device->driver || !device->driver->mesh_specific_scan)
1675 if (!device->powered)
1678 return device->driver->mesh_specific_scan(type, device, name, freq, NULL);
1681 int __connman_device_request_mesh_specific_scan(enum connman_service_type type,
1685 bool success = false;
1686 int last_err = -ENOSYS;
1690 if (type != CONNMAN_SERVICE_TYPE_MESH)
1693 for (list = device_list; list; list = list->next) {
1694 struct connman_device *device = list->data;
1695 enum connman_service_type service_type =
1696 __connman_device_get_service_type(device);
1698 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1699 if (type == CONNMAN_SERVICE_TYPE_MESH)
1700 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1704 err = device_mesh_specific_scan(type, device, name, freq);
1705 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1709 DBG("device %p err %d", device, err);
1718 #endif /* TIZEN_EXT_WIFI_MESH */
1721 static int connman_device_request_scan(enum connman_service_type type,
1722 bool force_full_scan)
1724 bool success = false;
1725 int last_err = -ENOSYS;
1730 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1731 case CONNMAN_SERVICE_TYPE_SYSTEM:
1732 case CONNMAN_SERVICE_TYPE_ETHERNET:
1733 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1734 case CONNMAN_SERVICE_TYPE_CELLULAR:
1735 case CONNMAN_SERVICE_TYPE_GPS:
1736 case CONNMAN_SERVICE_TYPE_VPN:
1737 case CONNMAN_SERVICE_TYPE_GADGET:
1739 case CONNMAN_SERVICE_TYPE_WIFI:
1740 case CONNMAN_SERVICE_TYPE_P2P:
1741 #if defined TIZEN_EXT_WIFI_MESH
1742 case CONNMAN_SERVICE_TYPE_MESH:
1747 for (list = device_list; list; list = list->next) {
1748 struct connman_device *device = list->data;
1750 if (!device_has_service_type(device, type))
1753 err = device_scan(type, device, force_full_scan);
1754 #if defined TIZEN_EXT
1755 /* When Scan is already in progress then return Error so that
1756 * wifi-manager can block the scan-done signal to be sent to
1757 * application and start requested scan after scan already in progress
1758 * is completed then notify to application about the scan event */
1759 if (err == 0 || err == -EINPROGRESS) {
1761 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1766 DBG("device %p err %d", device, err);
1776 int __connman_device_request_scan(enum connman_service_type type)
1778 return connman_device_request_scan(type, false);
1781 int __connman_device_request_scan_full(enum connman_service_type type)
1783 return connman_device_request_scan(type, true);
1786 int __connman_device_request_hidden_scan(struct connman_device *device,
1787 const char *ssid, unsigned int ssid_len,
1788 const char *identity, const char *passphrase,
1789 const char *security, void *user_data)
1791 struct connman_device_scan_params params;
1793 DBG("device %p", device);
1795 if (!device || !device->driver ||
1796 !device->driver->scan)
1799 params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
1801 params.ssid_len = ssid_len;
1802 params.identity = identity;
1803 params.passphrase = passphrase;
1804 params.security = security;
1805 params.user_data = user_data;
1807 return device->driver->scan(device, ¶ms);
1810 void __connman_device_stop_scan(enum connman_service_type type)
1814 for (list = device_list; list; list = list->next) {
1815 struct connman_device *device = list->data;
1817 if (!device_has_service_type(device, type))
1820 if (device->driver && device->driver->stop_scan)
1821 device->driver->stop_scan(type, device);
1825 #if defined TIZEN_EXT
1826 #define WIFI_MAC "/opt/etc/.mac.info"
1827 #define MAC_ADDR_LEN 18
1829 char *_get_wifi_addr(void)
1833 char wifi_mac[MAC_ADDR_LEN + 1];
1836 fp = fopen(WIFI_MAC, "r");
1838 connman_error("[%s] not present", WIFI_MAC);
1842 rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
1844 connman_error("Failed to get wifi mac address");
1849 str = g_try_malloc0(MAC_ADDR_LEN);
1851 connman_error("memory allocation failed");
1856 snprintf(str, MAC_ADDR_LEN, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
1857 g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
1858 g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
1859 g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
1860 g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
1861 g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
1862 g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
1867 char *_get_wifi_ident(void)
1871 char wifi_mac[MAC_ADDR_LEN + 1];
1874 fp = fopen(WIFI_MAC, "r");
1876 connman_error("[%s] not present", WIFI_MAC);
1880 rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
1882 connman_error("Failed to get wifi mac address");
1887 str = g_try_malloc0(MAC_ADDR_LEN);
1889 connman_error("memory allocation failed");
1894 snprintf(str, MAC_ADDR_LEN, "%c%c%c%c%c%c%c%c%c%c%c%c",
1895 g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
1896 g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
1897 g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
1898 g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
1899 g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
1900 g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
1906 #if defined TIZEN_EXT
1907 char *index2ident(int index, const char *prefix)
1909 static char *index2ident(int index, const char *prefix)
1913 struct ether_addr eth;
1920 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1924 memset(&ifr, 0, sizeof(ifr));
1925 ifr.ifr_ifindex = index;
1927 err = ioctl(sk, SIOCGIFNAME, &ifr);
1930 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1937 len = prefix ? strlen(prefix) + 18 : 18;
1939 str = g_malloc(len);
1943 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1944 snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
1945 prefix ? prefix : "",
1946 eth.ether_addr_octet[0],
1947 eth.ether_addr_octet[1],
1948 eth.ether_addr_octet[2],
1949 eth.ether_addr_octet[3],
1950 eth.ether_addr_octet[4],
1951 eth.ether_addr_octet[5]);
1956 #if defined TIZEN_EXT
1957 char *index2addr(int index)
1959 static char *index2addr(int index)
1963 struct ether_addr eth;
1970 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1974 memset(&ifr, 0, sizeof(ifr));
1975 ifr.ifr_ifindex = index;
1977 err = ioctl(sk, SIOCGIFNAME, &ifr);
1980 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1991 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1992 snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
1993 eth.ether_addr_octet[0],
1994 eth.ether_addr_octet[1],
1995 eth.ether_addr_octet[2],
1996 eth.ether_addr_octet[3],
1997 eth.ether_addr_octet[4],
1998 eth.ether_addr_octet[5]);
2003 struct connman_device *connman_device_create_from_index(int index)
2005 enum connman_device_type type;
2006 struct connman_device *device;
2007 char *devname, *ident = NULL;
2008 char *addr = NULL, *name = NULL;
2013 devname = connman_inet_ifname(index);
2017 if (__connman_device_isfiltered(devname)) {
2018 connman_info("Ignoring interface %s (filtered)", devname);
2023 type = __connman_rtnl_get_device_type(index);
2026 case CONNMAN_DEVICE_TYPE_UNKNOWN:
2027 connman_info("Ignoring interface %s (type unknown)", devname);
2030 case CONNMAN_DEVICE_TYPE_ETHERNET:
2031 case CONNMAN_DEVICE_TYPE_GADGET:
2032 case CONNMAN_DEVICE_TYPE_WIFI:
2033 name = index2ident(index, "");
2034 addr = index2addr(index);
2036 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
2037 case CONNMAN_DEVICE_TYPE_CELLULAR:
2038 case CONNMAN_DEVICE_TYPE_GPS:
2039 case CONNMAN_DEVICE_TYPE_VENDOR:
2040 name = g_strdup(devname);
2044 device = connman_device_create(name, type);
2049 case CONNMAN_DEVICE_TYPE_UNKNOWN:
2050 case CONNMAN_DEVICE_TYPE_VENDOR:
2051 case CONNMAN_DEVICE_TYPE_GPS:
2053 case CONNMAN_DEVICE_TYPE_ETHERNET:
2054 case CONNMAN_DEVICE_TYPE_GADGET:
2055 ident = index2ident(index, NULL);
2057 case CONNMAN_DEVICE_TYPE_WIFI:
2058 ident = index2ident(index, NULL);
2060 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
2062 case CONNMAN_DEVICE_TYPE_CELLULAR:
2063 ident = index2ident(index, NULL);
2067 connman_device_set_index(device, index);
2068 connman_device_set_interface(device, devname);
2069 #if defined TIZEN_EXT
2070 if (TIZEN_INS_ENABLED) {
2071 connman_device_load_last_connected(device);
2072 connman_device_load_last_user_selection(device);
2074 #endif /* defined TIZEN_EXT */
2077 connman_device_set_ident(device, ident);
2081 connman_device_set_string(device, "Address", addr);
2091 bool __connman_device_isfiltered(const char *devname)
2094 char **blacklisted_interfaces;
2100 for (pattern = device_filter, match = false; *pattern; pattern++) {
2101 if (g_pattern_match_simple(*pattern, devname)) {
2108 DBG("ignoring device %s (match)", devname);
2113 if (g_pattern_match_simple("dummy*", devname)) {
2114 DBG("ignoring dummy networking devices");
2118 if (!nodevice_filter)
2121 for (pattern = nodevice_filter; *pattern; pattern++) {
2122 if (g_pattern_match_simple(*pattern, devname)) {
2123 DBG("ignoring device %s (no match)", devname);
2129 if (__connman_inet_isrootnfs_device(devname)) {
2130 DBG("ignoring device %s (rootnfs)", devname);
2134 blacklisted_interfaces =
2135 connman_setting_get_string_list("NetworkInterfaceBlacklist");
2136 if (!blacklisted_interfaces)
2139 for (pattern = blacklisted_interfaces; *pattern; pattern++) {
2140 if (g_str_has_prefix(devname, *pattern)) {
2141 DBG("ignoring device %s (blacklist)", devname);
2149 static void cleanup_devices(void)
2152 * Check what interfaces are currently up and if connman is
2153 * suppose to handle the interface, then cleanup the mess
2154 * related to that interface. There might be weird routes etc
2155 * that are related to that interface and that might confuse
2156 * connmand. So in this case we just turn the interface down
2157 * so that kernel removes routes/addresses automatically and
2158 * then proceed the startup.
2160 * Note that this cleanup must be done before rtnl/detect code
2161 * has activated interface watches.
2167 interfaces = __connman_inet_get_running_interfaces();
2172 for (i = 0; interfaces[i]; i++) {
2175 struct sockaddr_in sin_addr, sin_mask;
2177 filtered = __connman_device_isfiltered(interfaces[i]);
2181 index = connman_inet_ifindex(interfaces[i]);
2185 if (!__connman_inet_get_address_netmask(index, &sin_addr,
2187 char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
2188 char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
2190 if (__connman_config_address_provisioned(address,
2192 DBG("Skip %s which is already provisioned "
2193 "with %s/%s", interfaces[i], address,
2204 DBG("cleaning up %s index %d", interfaces[i], index);
2206 #if defined TIZEN_EXT
2207 if (strcmp(interfaces[i], "wlan0") != 0)
2209 connman_inet_ifdown(index);
2212 * ConnMan will turn the interface UP automatically so
2213 * no need to do it here.
2217 g_strfreev(interfaces);
2220 int __connman_device_init(const char *device, const char *nodevice)
2224 #if defined TIZEN_EXT
2225 connection = connman_dbus_get_connection();
2229 device_filter = g_strsplit(device, ",", -1);
2232 nodevice_filter = g_strsplit(nodevice, ",", -1);
2239 void __connman_device_cleanup(void)
2243 g_strfreev(nodevice_filter);
2244 g_strfreev(device_filter);
2246 #if defined TIZEN_EXT
2247 dbus_connection_unref(connection);
2252 void connman_device_mac_policy_notify(struct connman_device *device,
2253 int result, unsigned int policy)
2255 device->mac_policy = policy;
2256 __connman_technology_notify_mac_policy_by_device(device, result, policy);
2259 int connman_device_set_mac_policy(struct connman_device *device,
2260 unsigned int policy)
2264 if (!device || !device->driver || !device->driver->set_mac_policy)
2267 device->mac_policy = policy;
2268 err = device->driver->set_mac_policy(device, policy);
2272 unsigned int connman_device_get_mac_policy(struct connman_device *device)
2274 return device->mac_policy;
2277 void connman_device_preassoc_mac_policy_notify(struct connman_device *device,
2278 int result, unsigned int policy)
2280 device->preassoc_mac_policy = policy;
2281 __connman_technology_notify_preassoc_mac_policy_by_device(device, result, policy);
2284 int connman_device_set_preassoc_mac_policy(struct connman_device *device,
2285 unsigned int policy)
2289 if (!device || !device->driver || !device->driver->set_preassoc_mac_policy)
2292 device->preassoc_mac_policy = policy;
2293 err = device->driver->set_preassoc_mac_policy(device, policy);
2297 unsigned int connman_device_get_preassoc_mac_policy(struct connman_device *device)
2299 return device->preassoc_mac_policy;
2302 void connman_device_random_mac_lifetime_notify(struct connman_device *device,
2303 int result, unsigned int lifetime)
2305 device->random_mac_lifetime = lifetime;
2306 __connman_technology_notify_random_mac_lifetime_by_device(device, result, lifetime);
2309 int connman_device_set_random_mac_lifetime(struct connman_device *device,
2310 unsigned int lifetime)
2314 if (!device || !device->driver || !device->driver->set_random_mac_lifetime)
2317 device->random_mac_lifetime = lifetime;
2318 err = device->driver->set_random_mac_lifetime(device, lifetime);
2322 unsigned int connman_device_get_random_mac_lifetime(struct connman_device *device)
2324 return device->random_mac_lifetime;