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 unsigned int mac_policy;
86 unsigned int preassoc_mac_policy;
87 unsigned int random_mac_lifetime;
92 static void __clear_pending_trigger(gpointer data, gpointer user_data)
94 DBusMessage *msg = (DBusMessage *)data;
95 dbus_message_unref(msg);
99 static void clear_pending_trigger(struct connman_device *device)
101 #if defined TIZEN_EXT
102 if (device->pending_reply_list) {
103 g_list_foreach(device->pending_reply_list, __clear_pending_trigger, NULL);
104 g_list_free(device->pending_reply_list);
105 device->pending_reply_list = NULL;
108 if (device->pending_timeout > 0) {
109 g_source_remove(device->pending_timeout);
110 device->pending_timeout = 0;
114 static const char *type2description(enum connman_device_type type)
117 case CONNMAN_DEVICE_TYPE_UNKNOWN:
118 case CONNMAN_DEVICE_TYPE_VENDOR:
120 case CONNMAN_DEVICE_TYPE_ETHERNET:
122 case CONNMAN_DEVICE_TYPE_WIFI:
124 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
126 case CONNMAN_DEVICE_TYPE_GPS:
128 case CONNMAN_DEVICE_TYPE_CELLULAR:
130 case CONNMAN_DEVICE_TYPE_GADGET:
138 static const char *type2string(enum connman_device_type type)
141 case CONNMAN_DEVICE_TYPE_UNKNOWN:
142 case CONNMAN_DEVICE_TYPE_VENDOR:
144 case CONNMAN_DEVICE_TYPE_ETHERNET:
146 case CONNMAN_DEVICE_TYPE_WIFI:
148 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
150 case CONNMAN_DEVICE_TYPE_GPS:
152 case CONNMAN_DEVICE_TYPE_CELLULAR:
154 case CONNMAN_DEVICE_TYPE_GADGET:
162 enum connman_service_type __connman_device_get_service_type(
163 struct connman_device *device)
165 enum connman_device_type type = connman_device_get_type(device);
168 case CONNMAN_DEVICE_TYPE_UNKNOWN:
169 case CONNMAN_DEVICE_TYPE_VENDOR:
170 case CONNMAN_DEVICE_TYPE_GPS:
172 case CONNMAN_DEVICE_TYPE_ETHERNET:
173 return CONNMAN_SERVICE_TYPE_ETHERNET;
174 case CONNMAN_DEVICE_TYPE_WIFI:
175 return CONNMAN_SERVICE_TYPE_WIFI;
176 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
177 return CONNMAN_SERVICE_TYPE_BLUETOOTH;
178 case CONNMAN_DEVICE_TYPE_CELLULAR:
179 return CONNMAN_SERVICE_TYPE_CELLULAR;
180 case CONNMAN_DEVICE_TYPE_GADGET:
181 return CONNMAN_SERVICE_TYPE_GADGET;
185 return CONNMAN_SERVICE_TYPE_UNKNOWN;
188 static bool device_has_service_type(struct connman_device *device,
189 enum connman_service_type service_type)
191 enum connman_service_type device_service_type =
192 __connman_device_get_service_type(device);
195 * For devices whose device_service_type is unknown we should
196 * allow to decide whether they support specific service_type
199 if (device_service_type == CONNMAN_SERVICE_TYPE_UNKNOWN)
202 #if defined TIZEN_EXT_WIFI_MESH
203 if (device_service_type == CONNMAN_SERVICE_TYPE_MESH)
204 return service_type != CONNMAN_SERVICE_TYPE_MESH;
207 if (device_service_type == CONNMAN_SERVICE_TYPE_WIFI) {
208 return service_type == CONNMAN_SERVICE_TYPE_WIFI ||
209 service_type == CONNMAN_SERVICE_TYPE_P2P;
212 return service_type == device_service_type;
215 #if defined TIZEN_EXT
216 static void __device_pending_reset(gpointer data, gpointer user_data)
218 DBusMessage *msg = (DBusMessage *)data;
221 reply = __connman_error_failed(msg, ETIMEDOUT);
223 g_dbus_send_message(connection, reply);
225 dbus_message_unref(msg);
229 static gboolean device_pending_reset(gpointer user_data)
231 struct connman_device *device = user_data;
233 DBG("device %p", device);
235 #if defined TIZEN_EXT
236 /* Power request timed out, send ETIMEDOUT. */
237 if (device->pending_reply_list) {
238 g_list_foreach(device->pending_reply_list, __device_pending_reset, NULL);
239 g_list_free(device->pending_reply_list);
240 device->pending_reply_list = NULL;
243 /* Power request timedout, reset power pending state. */
244 device->pending_timeout = 0;
245 device->powered_pending = PENDING_NONE;
250 int __connman_device_enable(struct connman_device *device)
254 DBG("device %p", device);
256 if (!device->driver || !device->driver->enable)
259 /* There is an ongoing power disable request. */
260 if (device->powered_pending == PENDING_DISABLE)
263 if (device->powered_pending == PENDING_ENABLE)
266 if (device->powered_pending == PENDING_NONE && device->powered)
269 if (device->index > 0) {
270 err = connman_inet_ifup(device->index);
271 if (err < 0 && err != -EALREADY)
275 device->powered_pending = PENDING_ENABLE;
277 err = device->driver->enable(device);
279 * device gets enabled right away.
280 * Invoke the callback
283 connman_device_set_powered(device, true);
287 if (err == -EALREADY) {
288 /* If device is already powered, but connman is not updated */
289 connman_device_set_powered(device, true);
291 if (device->type == CONNMAN_DEVICE_TYPE_WIFI) {
292 device->driver->set_mac_policy(device, device->mac_policy);
293 device->driver->set_preassoc_mac_policy(device, device->preassoc_mac_policy);
294 device->driver->set_random_mac_lifetime(device, device->random_mac_lifetime);
296 #endif /* TIZEN_EXT */
300 * if err == -EINPROGRESS, then the DBus call to the respective daemon
301 * was successful. We set a 4 sec timeout so if the daemon never
302 * returns a reply, we would reset the pending request.
304 if (err == -EINPROGRESS)
305 device->pending_timeout = g_timeout_add_seconds(4,
306 device_pending_reset, device);
311 int __connman_device_disable(struct connman_device *device)
315 DBG("device %p", device);
317 /* Ongoing power enable request */
318 if (device->powered_pending == PENDING_ENABLE)
321 if (device->powered_pending == PENDING_DISABLE)
324 if (device->powered_pending == PENDING_NONE && !device->powered)
327 device->powered_pending = PENDING_DISABLE;
329 if (device->network) {
330 struct connman_service *service =
331 connman_service_lookup_from_network(device->network);
334 __connman_service_disconnect(service);
336 connman_network_set_connected(device->network, false);
339 if (!device->driver || !device->driver->disable)
342 err = device->driver->disable(device);
343 if (err == 0 || err == -EALREADY) {
344 connman_device_set_powered(device, false);
348 if (err == -EINPROGRESS)
349 device->pending_timeout = g_timeout_add_seconds(4,
350 device_pending_reset, device);
355 static void probe_driver(struct connman_device_driver *driver)
359 DBG("driver %p name %s", driver, driver->name);
361 for (list = device_list; list; list = list->next) {
362 struct connman_device *device = list->data;
367 if (driver->type != device->type)
370 if (driver->probe(device) < 0)
373 device->driver = driver;
375 __connman_technology_add_device(device);
379 static void remove_device(struct connman_device *device)
381 DBG("device %p", device);
383 __connman_device_disable(device);
385 __connman_technology_remove_device(device);
387 if (device->driver->remove)
388 device->driver->remove(device);
390 device->driver = NULL;
393 static void remove_driver(struct connman_device_driver *driver)
397 DBG("driver %p name %s", driver, driver->name);
399 for (list = device_list; list; list = list->next) {
400 struct connman_device *device = list->data;
402 if (device->driver == driver)
403 remove_device(device);
407 bool __connman_device_has_driver(struct connman_device *device)
409 if (!device || !device->driver)
415 static GSList *driver_list = NULL;
417 static gint compare_priority(gconstpointer a, gconstpointer b)
419 const struct connman_device_driver *driver1 = a;
420 const struct connman_device_driver *driver2 = b;
422 return driver2->priority - driver1->priority;
426 * connman_device_driver_register:
427 * @driver: device driver definition
429 * Register a new device driver
431 * Returns: %0 on success
433 int connman_device_driver_register(struct connman_device_driver *driver)
435 DBG("driver %p name %s", driver, driver->name);
437 driver_list = g_slist_insert_sorted(driver_list, driver,
439 probe_driver(driver);
445 * connman_device_driver_unregister:
446 * @driver: device driver definition
448 * Remove a previously registered device driver
450 void connman_device_driver_unregister(struct connman_device_driver *driver)
452 DBG("driver %p name %s", driver, driver->name);
454 driver_list = g_slist_remove(driver_list, driver);
456 remove_driver(driver);
459 static void free_network(gpointer data)
461 struct connman_network *network = data;
463 DBG("network %p", network);
465 __connman_network_set_device(network, NULL);
467 connman_network_unref(network);
470 static void device_destruct(struct connman_device *device)
472 DBG("device %p name %s", device, device->name);
474 clear_pending_trigger(device);
476 g_hash_table_destroy(device->networks);
477 device->networks = NULL;
479 g_free(device->ident);
480 g_free(device->node);
481 g_free(device->name);
482 g_free(device->address);
483 g_free(device->interface);
484 g_free(device->path);
486 g_free(device->last_network);
488 #if defined TIZEN_EXT
489 g_free(device->last_user_selection_ident);
490 g_free(device->last_connected_ident);
496 #if defined TIZEN_EXT
497 static void device_send_changed(const char *ifname, enum connman_service_type type,
498 const char *key, bool state)
501 DBusMessageIter iter, dict;
502 dbus_bool_t value = state;
503 const char *tech_path = connman_techonology_get_path(type);
505 if (!tech_path || !ifname)
508 DBG("%s %s %s", ifname, key, state ? "TRUE" : "FALSE");
510 signal = dbus_message_new_signal(tech_path,
511 CONNMAN_TECHNOLOGY_INTERFACE, "DeviceChanged");
515 dbus_message_iter_init_append(signal, &iter);
517 connman_dbus_dict_open(&iter, &dict);
518 connman_dbus_dict_append_basic(&dict, "Ifname",
521 connman_dbus_dict_append_basic(&dict, key,
524 connman_dbus_dict_close(&iter, &dict);
526 dbus_connection_send(connection, signal, NULL);
527 dbus_message_unref(signal);
530 static void __device_send_reply(gpointer data, gpointer user_data)
532 DBusMessage *msg = (DBusMessage *)data;
533 g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
534 dbus_message_unref(msg);
537 static void device_send_reply(struct connman_device *device)
539 if (device->pending_reply_list) {
540 g_list_foreach(device->pending_reply_list, __device_send_reply, NULL);
541 g_list_free(device->pending_reply_list);
542 device->pending_reply_list = NULL;
548 * connman_device_create:
549 * @node: device node name (for example an address)
552 * Allocate a new device of given #type and assign the #node name to it.
554 * Returns: a newly-allocated #connman_device structure
556 struct connman_device *connman_device_create(const char *node,
557 enum connman_device_type type)
559 struct connman_device *device;
561 DBG("node %s type %d", node, type);
563 device = g_try_new0(struct connman_device, 1);
567 DBG("device %p", device);
569 device->refcount = 1;
572 device->name = g_strdup(type2description(device->type));
574 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
575 g_free, free_network);
577 device_list = g_slist_prepend(device_list, device);
583 * connman_device_ref:
584 * @device: device structure
586 * Increase reference counter of device
588 struct connman_device *connman_device_ref_debug(struct connman_device *device,
589 const char *file, int line, const char *caller)
591 DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
594 __sync_fetch_and_add(&device->refcount, 1);
600 * connman_device_unref:
601 * @device: device structure
603 * Decrease reference counter of device
605 void connman_device_unref_debug(struct connman_device *device,
606 const char *file, int line, const char *caller)
608 DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1,
611 if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
614 if (device->driver) {
615 device->driver->remove(device);
616 device->driver = NULL;
619 device_list = g_slist_remove(device_list, device);
621 device_destruct(device);
624 const char *__connman_device_get_type(struct connman_device *device)
626 return type2string(device->type);
630 * connman_device_get_type:
631 * @device: device structure
635 enum connman_device_type connman_device_get_type(struct connman_device *device)
641 * connman_device_set_index:
642 * @device: device structure
643 * @index: index number
645 * Set index number of device
647 void connman_device_set_index(struct connman_device *device, int index)
649 device->index = index;
653 * connman_device_get_index:
654 * @device: device structure
656 * Get index number of device
658 int connman_device_get_index(struct connman_device *device)
660 return device->index;
664 * connman_device_set_interface:
665 * @device: device structure
666 * @interface: interface name
668 * Set interface name of device
670 void connman_device_set_interface(struct connman_device *device,
671 const char *interface)
673 g_free(device->interface);
674 device->interface = g_strdup(interface);
677 const char *str = type2description(device->type);
678 if (str && device->interface)
679 device->name = g_strdup_printf("%s (%s)", str,
685 * connman_device_set_ident:
686 * @device: device structure
687 * @ident: unique identifier
689 * Set unique identifier of device
691 void connman_device_set_ident(struct connman_device *device,
695 if (device->ident && device->powered)
699 g_free(device->ident);
700 device->ident = g_strdup(ident);
703 const char *connman_device_get_ident(struct connman_device *device)
705 return device->ident;
709 * connman_device_set_powered:
710 * @device: device structure
711 * @powered: powered state
713 * Change power state of device
715 int connman_device_set_powered(struct connman_device *device,
718 struct connman_device_scan_params params;
719 enum connman_service_type type;
722 DBG("device %p powered %d", device, powered);
724 if (device->powered == powered)
727 #if defined TIZEN_EXT
728 device_send_reply(device);
731 clear_pending_trigger(device);
733 device->powered_pending = PENDING_NONE;
735 device->powered = powered;
737 type = __connman_device_get_service_type(device);
739 #if defined TIZEN_EXT
740 device_send_changed(device->interface, type, "Powered", powered);
741 technology_save_device(device);
744 if (!device->powered) {
745 __connman_technology_disabled(type);
749 __connman_technology_enabled(type);
751 for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++)
752 device->scanning[i] = false;
754 if (device->driver && device->driver->scan) {
755 memset(¶ms, 0, sizeof(params));
756 params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
758 device->driver->scan(device, ¶ms);
764 bool connman_device_get_powered(struct connman_device *device)
766 return device->powered;
769 static int device_scan(enum connman_service_type type,
770 struct connman_device *device,
771 bool force_full_scan)
773 struct connman_device_scan_params params;
775 if (!device->driver || !device->driver->scan)
778 if (!device->powered)
781 memset(¶ms, 0, sizeof(params));
783 params.force_full_scan = force_full_scan;
785 return device->driver->scan(device, ¶ms);
788 int __connman_device_disconnect(struct connman_device *device)
793 DBG("device %p", device);
795 g_hash_table_iter_init(&iter, device->networks);
797 while (g_hash_table_iter_next(&iter, &key, &value)) {
798 struct connman_network *network = value;
800 if (connman_network_get_connecting(network)) {
802 * Skip network in the process of connecting.
803 * This is a workaround for WiFi networks serviced
804 * by the supplicant plugin that hold a reference
805 * to the network. If we disconnect the network
806 * here then the referenced object will not be
807 * registered and usage (like launching DHCP client)
808 * will fail. There is nothing to be gained by
809 * removing the network here anyway.
811 connman_warn("Skipping disconnect of %s, network is connecting.",
812 connman_network_get_identifier(network));
816 __connman_network_disconnect(network);
822 int connman_device_reconnect_service(struct connman_device *device)
824 DBG("device %p", device);
826 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
831 #if defined TIZEN_EXT
832 bool connman_device_set_last_user_selection_time(struct connman_device *device,
835 if (device->last_user_selection_time != time) {
836 device->last_user_selection_time = time;
843 time_t connman_device_get_last_user_selection_time(struct connman_device *device)
845 return device->last_user_selection_time;
848 bool connman_device_set_last_user_selection_ident(struct connman_device *device,
851 if (g_strcmp0(device->last_user_selection_ident, ident) != 0) {
852 g_free(device->last_user_selection_ident);
853 device->last_user_selection_ident = g_strdup(ident);
861 const char *connman_device_get_last_user_selection_ident(struct connman_device *device)
863 return device->last_user_selection_ident;
866 bool connman_device_set_last_connected_ident(struct connman_device *device,
869 if (g_strcmp0(device->last_connected_ident, ident) != 0) {
870 g_free(device->last_connected_ident);
871 device->last_connected_ident = g_strdup(ident);
879 const char *connman_device_get_last_connected_ident(struct connman_device *device)
881 return device->last_connected_ident;
885 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
886 void connman_device_save_last_user_selection(struct connman_device *device)
890 gchar *selection_str;
892 keyfile = __connman_storage_load_ins();
894 selection_str = g_strdup_printf("%s:%ld",
895 device->last_user_selection_ident, device->last_user_selection_time);
898 keyfile = g_key_file_new();
900 g_key_file_set_string(keyfile, device->interface, "LastUserSelection", selection_str);
901 DBG("%s", selection_str);
902 __connman_storage_save_ins(keyfile);
905 get_str = g_key_file_get_string(keyfile, device->interface, "LastUserSelection", NULL);
906 if (!get_str || g_strcmp0(get_str, selection_str) != 0) {
907 g_key_file_set_string(keyfile, device->interface, "LastUserSelection", selection_str);
908 DBG("%s -> %s", get_str, selection_str);
909 __connman_storage_save_ins(keyfile);
915 g_free(selection_str);
916 g_key_file_free(keyfile);
919 void connman_device_load_last_user_selection(struct connman_device *device)
923 char **selection_str;
925 keyfile = __connman_storage_load_ins();
929 get_str = g_key_file_get_string(keyfile, device->interface, "LastUserSelection", NULL);
931 selection_str = g_strsplit(get_str, ":", 0);
935 time_t last_user_selection_time;
937 /* Only events that occur within 8 hours are counted. */
938 ref_time = time(NULL);
939 timeinfo = localtime(&ref_time);
940 timeinfo->tm_hour -= 8;
941 ref_time = mktime(timeinfo);
943 last_user_selection_time = strtol(selection_str[1], NULL, 10);
945 if (last_user_selection_time > ref_time) {
946 if (g_strcmp0(selection_str[0], device->last_user_selection_ident) != 0) {
947 g_free(device->last_user_selection_ident);
948 device->last_user_selection_ident = g_strdup(selection_str[0]);
951 device->last_user_selection_time = last_user_selection_time;
953 DBG("%s %ld", device->last_user_selection_ident, device->last_user_selection_time);
956 g_strfreev(selection_str);
962 g_key_file_free(keyfile);
965 void connman_device_save_last_connected(struct connman_device *device)
970 if (!device->last_connected_ident)
973 keyfile = __connman_storage_load_ins();
976 keyfile = g_key_file_new();
978 g_key_file_set_string(keyfile, device->interface, "LastConnected", device->last_connected_ident);
979 DBG("%s", device->last_connected_ident);
980 __connman_storage_save_ins(keyfile);
983 get_str = g_key_file_get_string(keyfile, device->interface, "LastConnected", NULL);
984 if (!get_str || g_strcmp0(get_str, device->last_connected_ident) != 0) {
985 g_key_file_set_string(keyfile, device->interface, "LastConnected", device->last_connected_ident);
986 DBG("%s -> %s", get_str, device->last_connected_ident);
987 __connman_storage_save_ins(keyfile);
993 g_key_file_free(keyfile);
996 void connman_device_load_last_connected(struct connman_device *device)
1001 keyfile = __connman_storage_load_ins();
1005 get_str = g_key_file_get_string(keyfile, device->interface, "LastConnected", NULL);
1007 if (g_strcmp0(get_str, device->last_connected_ident) != 0) {
1008 g_free(device->last_connected_ident);
1009 device->last_connected_ident = g_strdup(get_str);
1012 DBG("%s", device->last_connected_ident);
1017 g_key_file_free(keyfile);
1019 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
1021 static void mark_network_available(gpointer key, gpointer value,
1024 struct connman_network *network = value;
1026 connman_network_set_available(network, true);
1029 static void mark_network_unavailable(gpointer key, gpointer value,
1032 struct connman_network *network = value;
1034 if (connman_network_get_connected(network) ||
1035 connman_network_get_connecting(network))
1038 connman_network_set_available(network, false);
1041 static gboolean remove_unavailable_network(gpointer key, gpointer value,
1044 struct connman_network *network = value;
1046 if (connman_network_get_connected(network) ||
1047 connman_network_get_connecting(network))
1050 if (connman_network_get_available(network))
1056 void __connman_device_cleanup_networks(struct connman_device *device)
1058 g_hash_table_foreach_remove(device->networks,
1059 remove_unavailable_network, NULL);
1062 bool connman_device_get_scanning(struct connman_device *device,
1063 enum connman_service_type type)
1067 if (type != CONNMAN_SERVICE_TYPE_UNKNOWN)
1068 return device->scanning[type];
1070 for (i = 0; i < MAX_CONNMAN_SERVICE_TYPES; i++)
1071 if (device->scanning[i])
1077 void connman_device_reset_scanning(struct connman_device *device)
1079 g_hash_table_foreach(device->networks,
1080 mark_network_available, NULL);
1084 * connman_device_set_scanning:
1085 * @device: device structure
1086 * @scanning: scanning state
1088 * Change scanning state of device
1090 int connman_device_set_scanning(struct connman_device *device,
1091 enum connman_service_type type, bool scanning)
1093 DBG("device %p scanning %d", device, scanning);
1095 if (!device->driver || !device->driver->scan)
1098 if (type == CONNMAN_SERVICE_TYPE_UNKNOWN)
1101 if (device->scanning[type] == scanning)
1104 device->scanning[type] = scanning;
1107 __connman_technology_scan_started(device);
1109 g_hash_table_foreach(device->networks,
1110 mark_network_unavailable, NULL);
1115 __connman_device_cleanup_networks(device);
1117 __connman_technology_scan_stopped(device, type);
1119 __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
1121 #if defined TIZEN_EXT_WIFI_MESH
1122 if (type == CONNMAN_SERVICE_TYPE_MESH)
1123 __connman_mesh_auto_connect();
1130 * connman_device_set_string:
1131 * @device: device structure
1132 * @key: unique identifier
1133 * @value: string value
1135 * Set string value for specific key
1137 int connman_device_set_string(struct connman_device *device,
1138 const char *key, const char *value)
1140 DBG("device %p key %s value %s", device, key, value);
1142 if (g_str_equal(key, "Address")) {
1144 if (device->address && device->powered)
1148 g_free(device->address);
1149 device->address = g_strdup(value);
1150 } else if (g_str_equal(key, "Name")) {
1151 g_free(device->name);
1152 device->name = g_strdup(value);
1153 } else if (g_str_equal(key, "Node")) {
1154 g_free(device->node);
1155 device->node = g_strdup(value);
1156 } else if (g_str_equal(key, "Path")) {
1157 g_free(device->path);
1158 device->path = g_strdup(value);
1167 * connman_device_get_string:
1168 * @device: device structure
1169 * @key: unique identifier
1171 * Get string value for specific key
1173 const char *connman_device_get_string(struct connman_device *device,
1176 #if defined TIZEN_EXT
1177 if (!simplified_log)
1179 DBG("device %p key %s", device, key);
1181 if (g_str_equal(key, "Address"))
1182 return device->address;
1183 else if (g_str_equal(key, "Name"))
1184 return device->name;
1185 else if (g_str_equal(key, "Node"))
1186 return device->node;
1187 else if (g_str_equal(key, "Interface"))
1188 return device->interface;
1189 else if (g_str_equal(key, "Path"))
1190 return device->path;
1196 * connman_device_add_network:
1197 * @device: device structure
1198 * @network: network structure
1200 * Add new network to the device
1202 int connman_device_add_network(struct connman_device *device,
1203 struct connman_network *network)
1205 const char *identifier = connman_network_get_identifier(network);
1206 #if defined TIZEN_EXT
1207 if (!simplified_log)
1209 DBG("device %p network %p", device, network);
1214 connman_network_ref(network);
1216 __connman_network_set_device(network, device);
1218 g_hash_table_replace(device->networks, g_strdup(identifier),
1225 * connman_device_get_network:
1226 * @device: device structure
1227 * @identifier: network identifier
1229 * Get network for given identifier
1231 struct connman_network *connman_device_get_network(struct connman_device *device,
1232 const char *identifier)
1234 #if defined TIZEN_EXT
1235 if (!simplified_log)
1237 DBG("device %p identifier %s", device, identifier);
1239 return g_hash_table_lookup(device->networks, identifier);
1242 #if defined TIZEN_EXT
1243 struct connman_network *connman_device_get_default_network(
1244 struct connman_device *device)
1246 return device->network;
1249 void connman_device_set_pending_reply(struct connman_device *device,
1252 device->pending_reply_list = g_list_prepend(device->pending_reply_list, dbus_message_ref(msg));
1255 void connman_device_send_connected_signal(struct connman_device *device,
1258 enum connman_service_type type;
1263 type = __connman_device_get_service_type(device);
1264 device_send_changed(device->interface, type, "Connected", connected);
1267 void connman_device_set_max_scan_ssids(struct connman_device *device,
1270 device->max_scan_ssids = max_scan_ssids;
1273 int connman_device_get_max_scan_ssids(struct connman_device *device)
1275 return device->max_scan_ssids;
1278 void connman_device_set_wifi_5ghz_supported(struct connman_device *device,
1279 bool is_5_0_ghz_supported)
1281 device->is_5_0_ghz_supported = is_5_0_ghz_supported;
1284 bool connman_device_get_wifi_5ghz_supported(struct connman_device *device)
1286 return device->is_5_0_ghz_supported;
1291 * connman_device_remove_network:
1292 * @device: device structure
1293 * @identifier: network identifier
1295 * Remove network for given identifier
1297 int connman_device_remove_network(struct connman_device *device,
1298 struct connman_network *network)
1300 const char *identifier;
1302 DBG("device %p network %p", device, network);
1307 identifier = connman_network_get_identifier(network);
1308 g_hash_table_remove(device->networks, identifier);
1313 void __connman_device_set_network(struct connman_device *device,
1314 struct connman_network *network)
1321 if (device->network == network)
1325 name = connman_network_get_string(network, "Name");
1326 g_free(device->last_network);
1327 device->last_network = g_strdup(name);
1329 device->network = network;
1331 g_free(device->last_network);
1332 device->last_network = NULL;
1334 device->network = NULL;
1338 static bool match_driver(struct connman_device *device,
1339 struct connman_device_driver *driver)
1341 if (device->type == driver->type ||
1342 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1349 * connman_device_register:
1350 * @device: device structure
1352 * Register device with the system
1354 int connman_device_register(struct connman_device *device)
1358 DBG("device %p name %s", device, device->name);
1363 for (list = driver_list; list; list = list->next) {
1364 struct connman_device_driver *driver = list->data;
1366 if (!match_driver(device, driver))
1369 DBG("driver %p name %s", driver, driver->name);
1371 if (driver->probe(device) == 0) {
1372 device->driver = driver;
1377 if (!device->driver)
1380 return __connman_technology_add_device(device);
1384 * connman_device_unregister:
1385 * @device: device structure
1387 * Unregister device with the system
1389 void connman_device_unregister(struct connman_device *device)
1391 DBG("device %p name %s", device, device->name);
1393 if (!device->driver)
1396 remove_device(device);
1400 * connman_device_get_data:
1401 * @device: device structure
1403 * Get private device data pointer
1405 void *connman_device_get_data(struct connman_device *device)
1407 return device->driver_data;
1411 * connman_device_set_data:
1412 * @device: device structure
1413 * @data: data pointer
1415 * Set private device data pointer
1417 void connman_device_set_data(struct connman_device *device, void *data)
1419 device->driver_data = data;
1422 struct connman_device *__connman_device_find_device(
1423 enum connman_service_type type)
1427 for (list = device_list; list; list = list->next) {
1428 struct connman_device *device = list->data;
1429 enum connman_service_type service_type =
1430 __connman_device_get_service_type(device);
1432 if (service_type != type)
1441 struct connman_device *connman_device_find_by_index(int index)
1445 for (list = device_list; list; list = list->next) {
1446 struct connman_device *device = list->data;
1447 if (device->index == index)
1455 * connman_device_set_regdom
1456 * @device: device structure
1457 * @alpha2: string representing regulatory domain
1459 * Set regulatory domain on device basis
1461 int connman_device_set_regdom(struct connman_device *device,
1464 if (!device->driver || !device->driver->set_regdom)
1467 if (!device->powered)
1470 return device->driver->set_regdom(device, alpha2);
1474 * connman_device_regdom_notify
1475 * @device: device structure
1476 * @alpha2: string representing regulatory domain
1478 * Notify on setting regulatory domain on device basis
1480 void connman_device_regdom_notify(struct connman_device *device,
1481 int result, const char *alpha2)
1483 __connman_technology_notify_regdom_by_device(device, result, alpha2);
1486 #if defined TIZEN_EXT
1487 static int device_specific_scan(enum connman_service_type type,
1488 struct connman_device *device,
1489 int scan_type, GSList *specific_scan_list)
1491 if (!device->driver || !device->driver->specific_scan)
1494 if (!device->powered)
1497 return device->driver->specific_scan(type, device, scan_type,
1498 specific_scan_list, NULL);
1501 int __connman_device_request_specific_scan(enum connman_service_type type,
1502 const char *ifname, int scan_type, GSList *specific_scan_list)
1504 bool success = false;
1505 int last_err = -ENOSYS;
1510 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1511 case CONNMAN_SERVICE_TYPE_SYSTEM:
1512 case CONNMAN_SERVICE_TYPE_ETHERNET:
1513 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1514 case CONNMAN_SERVICE_TYPE_CELLULAR:
1515 case CONNMAN_SERVICE_TYPE_GPS:
1516 case CONNMAN_SERVICE_TYPE_VPN:
1517 case CONNMAN_SERVICE_TYPE_GADGET:
1519 case CONNMAN_SERVICE_TYPE_WIFI:
1520 case CONNMAN_SERVICE_TYPE_P2P:
1521 #if defined TIZEN_EXT_WIFI_MESH
1522 case CONNMAN_SERVICE_TYPE_MESH:
1527 for (list = device_list; list; list = list->next) {
1528 struct connman_device *device = list->data;
1529 enum connman_service_type service_type =
1530 __connman_device_get_service_type(device);
1532 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1533 if (type == CONNMAN_SERVICE_TYPE_P2P) {
1534 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1536 } else if (service_type != type)
1540 if (ifname && g_strcmp0(device->interface, ifname) != 0)
1543 err = device_specific_scan(type, device, scan_type, specific_scan_list);
1544 if (err == 0 || err == -EINPROGRESS) {
1548 DBG("device %p err %d", device, err);
1558 int connman_device_request_device_scan(enum connman_service_type type,
1559 const char * ifname, bool force_full_scan)
1561 bool success = false;
1562 int last_err = -ENOSYS;
1567 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1568 case CONNMAN_SERVICE_TYPE_SYSTEM:
1569 case CONNMAN_SERVICE_TYPE_ETHERNET:
1570 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1571 case CONNMAN_SERVICE_TYPE_CELLULAR:
1572 case CONNMAN_SERVICE_TYPE_GPS:
1573 case CONNMAN_SERVICE_TYPE_VPN:
1574 case CONNMAN_SERVICE_TYPE_GADGET:
1576 case CONNMAN_SERVICE_TYPE_WIFI:
1577 case CONNMAN_SERVICE_TYPE_P2P:
1578 #if defined TIZEN_EXT_WIFI_MESH
1579 case CONNMAN_SERVICE_TYPE_MESH:
1584 for (list = device_list; list; list = list->next) {
1585 struct connman_device *device = list->data;
1587 if (!device_has_service_type(device, type))
1590 if (g_strcmp0(device->interface, ifname) != 0)
1593 err = device_scan(type, device, force_full_scan);
1595 if (err == 0 || err == -EINPROGRESS) {
1599 DBG("device %p err %d", device, err);
1610 #if defined TIZEN_EXT_WIFI_MESH
1611 static int device_abort_scan(enum connman_service_type type,
1612 struct connman_device *device)
1614 if (!device->driver || !device->driver->scan)
1617 if (!device->powered)
1620 return device->driver->abort_scan(type, device);
1623 int __connman_device_abort_scan(enum connman_service_type type)
1628 if (type != CONNMAN_SERVICE_TYPE_MESH)
1631 for (list = device_list; list; list = list->next) {
1632 struct connman_device *device = list->data;
1633 enum connman_service_type service_type =
1634 __connman_device_get_service_type(device);
1636 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1637 if (type == CONNMAN_SERVICE_TYPE_MESH)
1638 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1641 if (!device->scanning) {
1646 err = device_abort_scan(type, device);
1652 static int device_mesh_specific_scan(enum connman_service_type type,
1653 struct connman_device *device, const char *name,
1656 if (!device->driver || !device->driver->mesh_specific_scan)
1659 if (!device->powered)
1662 return device->driver->mesh_specific_scan(type, device, name, freq, NULL);
1665 int __connman_device_request_mesh_specific_scan(enum connman_service_type type,
1669 bool success = false;
1670 int last_err = -ENOSYS;
1674 if (type != CONNMAN_SERVICE_TYPE_MESH)
1677 for (list = device_list; list; list = list->next) {
1678 struct connman_device *device = list->data;
1679 enum connman_service_type service_type =
1680 __connman_device_get_service_type(device);
1682 if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
1683 if (type == CONNMAN_SERVICE_TYPE_MESH)
1684 if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
1688 err = device_mesh_specific_scan(type, device, name, freq);
1689 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1693 DBG("device %p err %d", device, err);
1702 #endif /* TIZEN_EXT_WIFI_MESH */
1705 static int connman_device_request_scan(enum connman_service_type type,
1706 bool force_full_scan)
1708 bool success = false;
1709 int last_err = -ENOSYS;
1714 case CONNMAN_SERVICE_TYPE_UNKNOWN:
1715 case CONNMAN_SERVICE_TYPE_SYSTEM:
1716 case CONNMAN_SERVICE_TYPE_ETHERNET:
1717 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
1718 case CONNMAN_SERVICE_TYPE_CELLULAR:
1719 case CONNMAN_SERVICE_TYPE_GPS:
1720 case CONNMAN_SERVICE_TYPE_VPN:
1721 case CONNMAN_SERVICE_TYPE_GADGET:
1723 case CONNMAN_SERVICE_TYPE_WIFI:
1724 case CONNMAN_SERVICE_TYPE_P2P:
1725 #if defined TIZEN_EXT_WIFI_MESH
1726 case CONNMAN_SERVICE_TYPE_MESH:
1731 for (list = device_list; list; list = list->next) {
1732 struct connman_device *device = list->data;
1734 if (!device_has_service_type(device, type))
1737 err = device_scan(type, device, force_full_scan);
1738 #if defined TIZEN_EXT
1739 /* When Scan is already in progress then return Error so that
1740 * wifi-manager can block the scan-done signal to be sent to
1741 * application and start requested scan after scan already in progress
1742 * is completed then notify to application about the scan event */
1743 if (err == 0 || err == -EINPROGRESS) {
1745 if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
1750 DBG("device %p err %d", device, err);
1760 int __connman_device_request_scan(enum connman_service_type type)
1762 return connman_device_request_scan(type, false);
1765 int __connman_device_request_scan_full(enum connman_service_type type)
1767 return connman_device_request_scan(type, true);
1770 int __connman_device_request_hidden_scan(struct connman_device *device,
1771 const char *ssid, unsigned int ssid_len,
1772 const char *identity, const char *passphrase,
1773 const char *security, void *user_data)
1775 struct connman_device_scan_params params;
1777 DBG("device %p", device);
1779 if (!device || !device->driver ||
1780 !device->driver->scan)
1783 params.type = CONNMAN_SERVICE_TYPE_UNKNOWN;
1785 params.ssid_len = ssid_len;
1786 params.identity = identity;
1787 params.passphrase = passphrase;
1788 params.security = security;
1789 params.user_data = user_data;
1791 return device->driver->scan(device, ¶ms);
1794 void __connman_device_stop_scan(enum connman_service_type type)
1798 for (list = device_list; list; list = list->next) {
1799 struct connman_device *device = list->data;
1801 if (!device_has_service_type(device, type))
1804 if (device->driver && device->driver->stop_scan)
1805 device->driver->stop_scan(type, device);
1809 #if defined TIZEN_EXT
1810 #define WIFI_MAC "/opt/etc/.mac.info"
1811 #define MAC_ADDR_LEN 18
1813 char *_get_wifi_addr(void)
1817 char wifi_mac[MAC_ADDR_LEN + 1];
1820 fp = fopen(WIFI_MAC, "r");
1822 connman_error("[%s] not present", WIFI_MAC);
1826 rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
1828 connman_error("Failed to get wifi mac address");
1833 str = g_try_malloc0(MAC_ADDR_LEN);
1835 connman_error("memory allocation failed");
1840 snprintf(str, MAC_ADDR_LEN, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
1841 g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
1842 g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
1843 g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
1844 g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
1845 g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
1846 g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
1851 char *_get_wifi_ident(void)
1855 char wifi_mac[MAC_ADDR_LEN + 1];
1858 fp = fopen(WIFI_MAC, "r");
1860 connman_error("[%s] not present", WIFI_MAC);
1864 rv = fgets(wifi_mac, MAC_ADDR_LEN, fp);
1866 connman_error("Failed to get wifi mac address");
1871 str = g_try_malloc0(MAC_ADDR_LEN);
1873 connman_error("memory allocation failed");
1878 snprintf(str, MAC_ADDR_LEN, "%c%c%c%c%c%c%c%c%c%c%c%c",
1879 g_ascii_tolower(wifi_mac[0]), g_ascii_tolower(wifi_mac[1]),
1880 g_ascii_tolower(wifi_mac[3]), g_ascii_tolower(wifi_mac[4]),
1881 g_ascii_tolower(wifi_mac[6]), g_ascii_tolower(wifi_mac[7]),
1882 g_ascii_tolower(wifi_mac[9]), g_ascii_tolower(wifi_mac[10]),
1883 g_ascii_tolower(wifi_mac[12]), g_ascii_tolower(wifi_mac[13]),
1884 g_ascii_tolower(wifi_mac[15]), g_ascii_tolower(wifi_mac[16]));
1890 #if defined TIZEN_EXT
1891 char *index2ident(int index, const char *prefix)
1893 static char *index2ident(int index, const char *prefix)
1897 struct ether_addr eth;
1904 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1908 memset(&ifr, 0, sizeof(ifr));
1909 ifr.ifr_ifindex = index;
1911 err = ioctl(sk, SIOCGIFNAME, &ifr);
1914 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1921 len = prefix ? strlen(prefix) + 18 : 18;
1923 str = g_malloc(len);
1927 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1928 snprintf(str, len, "%s%02x%02x%02x%02x%02x%02x",
1929 prefix ? prefix : "",
1930 eth.ether_addr_octet[0],
1931 eth.ether_addr_octet[1],
1932 eth.ether_addr_octet[2],
1933 eth.ether_addr_octet[3],
1934 eth.ether_addr_octet[4],
1935 eth.ether_addr_octet[5]);
1940 #if defined TIZEN_EXT
1941 char *index2addr(int index)
1943 static char *index2addr(int index)
1947 struct ether_addr eth;
1954 sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
1958 memset(&ifr, 0, sizeof(ifr));
1959 ifr.ifr_ifindex = index;
1961 err = ioctl(sk, SIOCGIFNAME, &ifr);
1964 err = ioctl(sk, SIOCGIFHWADDR, &ifr);
1975 memcpy(ð, &ifr.ifr_hwaddr.sa_data, sizeof(eth));
1976 snprintf(str, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
1977 eth.ether_addr_octet[0],
1978 eth.ether_addr_octet[1],
1979 eth.ether_addr_octet[2],
1980 eth.ether_addr_octet[3],
1981 eth.ether_addr_octet[4],
1982 eth.ether_addr_octet[5]);
1987 struct connman_device *connman_device_create_from_index(int index)
1989 enum connman_device_type type;
1990 struct connman_device *device;
1991 char *devname, *ident = NULL;
1992 char *addr = NULL, *name = NULL;
1997 devname = connman_inet_ifname(index);
2001 if (__connman_device_isfiltered(devname)) {
2002 connman_info("Ignoring interface %s (filtered)", devname);
2007 type = __connman_rtnl_get_device_type(index);
2010 case CONNMAN_DEVICE_TYPE_UNKNOWN:
2011 connman_info("Ignoring interface %s (type unknown)", devname);
2014 case CONNMAN_DEVICE_TYPE_ETHERNET:
2015 case CONNMAN_DEVICE_TYPE_GADGET:
2016 case CONNMAN_DEVICE_TYPE_WIFI:
2017 name = index2ident(index, "");
2018 addr = index2addr(index);
2020 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
2021 case CONNMAN_DEVICE_TYPE_CELLULAR:
2022 case CONNMAN_DEVICE_TYPE_GPS:
2023 case CONNMAN_DEVICE_TYPE_VENDOR:
2024 name = g_strdup(devname);
2028 device = connman_device_create(name, type);
2033 case CONNMAN_DEVICE_TYPE_UNKNOWN:
2034 case CONNMAN_DEVICE_TYPE_VENDOR:
2035 case CONNMAN_DEVICE_TYPE_GPS:
2037 case CONNMAN_DEVICE_TYPE_ETHERNET:
2038 case CONNMAN_DEVICE_TYPE_GADGET:
2039 ident = index2ident(index, NULL);
2041 case CONNMAN_DEVICE_TYPE_WIFI:
2042 ident = index2ident(index, NULL);
2044 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
2046 case CONNMAN_DEVICE_TYPE_CELLULAR:
2047 ident = index2ident(index, NULL);
2051 connman_device_set_index(device, index);
2052 connman_device_set_interface(device, devname);
2053 #if defined TIZEN_EXT && defined TIZEN_EXT_INS
2054 connman_device_load_last_connected(device);
2055 connman_device_load_last_user_selection(device);
2056 #endif /* defined TIZEN_EXT && defined TIZEN_EXT_INS */
2059 connman_device_set_ident(device, ident);
2063 connman_device_set_string(device, "Address", addr);
2073 bool __connman_device_isfiltered(const char *devname)
2076 char **blacklisted_interfaces;
2082 for (pattern = device_filter, match = false; *pattern; pattern++) {
2083 if (g_pattern_match_simple(*pattern, devname)) {
2090 DBG("ignoring device %s (match)", devname);
2095 if (g_pattern_match_simple("dummy*", devname)) {
2096 DBG("ignoring dummy networking devices");
2100 if (!nodevice_filter)
2103 for (pattern = nodevice_filter; *pattern; pattern++) {
2104 if (g_pattern_match_simple(*pattern, devname)) {
2105 DBG("ignoring device %s (no match)", devname);
2111 if (__connman_inet_isrootnfs_device(devname)) {
2112 DBG("ignoring device %s (rootnfs)", devname);
2116 blacklisted_interfaces =
2117 connman_setting_get_string_list("NetworkInterfaceBlacklist");
2118 if (!blacklisted_interfaces)
2121 for (pattern = blacklisted_interfaces; *pattern; pattern++) {
2122 if (g_str_has_prefix(devname, *pattern)) {
2123 DBG("ignoring device %s (blacklist)", devname);
2131 static void cleanup_devices(void)
2134 * Check what interfaces are currently up and if connman is
2135 * suppose to handle the interface, then cleanup the mess
2136 * related to that interface. There might be weird routes etc
2137 * that are related to that interface and that might confuse
2138 * connmand. So in this case we just turn the interface down
2139 * so that kernel removes routes/addresses automatically and
2140 * then proceed the startup.
2142 * Note that this cleanup must be done before rtnl/detect code
2143 * has activated interface watches.
2149 interfaces = __connman_inet_get_running_interfaces();
2154 for (i = 0; interfaces[i]; i++) {
2157 struct sockaddr_in sin_addr, sin_mask;
2159 filtered = __connman_device_isfiltered(interfaces[i]);
2163 index = connman_inet_ifindex(interfaces[i]);
2167 if (!__connman_inet_get_address_netmask(index, &sin_addr,
2169 char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
2170 char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
2172 if (__connman_config_address_provisioned(address,
2174 DBG("Skip %s which is already provisioned "
2175 "with %s/%s", interfaces[i], address,
2186 DBG("cleaning up %s index %d", interfaces[i], index);
2188 #if defined TIZEN_EXT
2189 if (strcmp(interfaces[i], "wlan0") != 0)
2191 connman_inet_ifdown(index);
2194 * ConnMan will turn the interface UP automatically so
2195 * no need to do it here.
2199 g_strfreev(interfaces);
2202 int __connman_device_init(const char *device, const char *nodevice)
2206 #if defined TIZEN_EXT
2207 connection = connman_dbus_get_connection();
2211 device_filter = g_strsplit(device, ",", -1);
2214 nodevice_filter = g_strsplit(nodevice, ",", -1);
2221 void __connman_device_cleanup(void)
2225 g_strfreev(nodevice_filter);
2226 g_strfreev(device_filter);
2228 #if defined TIZEN_EXT
2229 dbus_connection_unref(connection);
2234 void connman_device_mac_policy_notify(struct connman_device *device,
2235 int result, unsigned int policy)
2237 device->mac_policy = policy;
2238 __connman_technology_notify_mac_policy_by_device(device, result, policy);
2241 int connman_device_set_mac_policy(struct connman_device *device,
2242 unsigned int policy)
2246 if (!device || !device->driver || !device->driver->set_mac_policy)
2249 device->mac_policy = policy;
2250 err = device->driver->set_mac_policy(device, policy);
2254 unsigned int connman_device_get_mac_policy(struct connman_device *device)
2256 return device->mac_policy;
2259 void connman_device_preassoc_mac_policy_notify(struct connman_device *device,
2260 int result, unsigned int policy)
2262 device->preassoc_mac_policy = policy;
2263 __connman_technology_notify_preassoc_mac_policy_by_device(device, result, policy);
2266 int connman_device_set_preassoc_mac_policy(struct connman_device *device,
2267 unsigned int policy)
2271 if (!device || !device->driver || !device->driver->set_preassoc_mac_policy)
2274 device->preassoc_mac_policy = policy;
2275 err = device->driver->set_preassoc_mac_policy(device, policy);
2279 unsigned int connman_device_get_preassoc_mac_policy(struct connman_device *device)
2281 return device->preassoc_mac_policy;
2284 void connman_device_random_mac_lifetime_notify(struct connman_device *device,
2285 int result, unsigned int lifetime)
2287 device->random_mac_lifetime = lifetime;
2288 __connman_technology_notify_random_mac_lifetime_by_device(device, result, lifetime);
2291 int connman_device_set_random_mac_lifetime(struct connman_device *device,
2292 unsigned int lifetime)
2296 if (!device || !device->driver || !device->driver->set_random_mac_lifetime)
2299 device->random_mac_lifetime = lifetime;
2300 err = device->driver->set_random_mac_lifetime(device, lifetime);
2304 unsigned int connman_device_get_random_mac_lifetime(struct connman_device *device)
2306 return device->random_mac_lifetime;