5 * Copyright (C) 2007-2009 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
33 static DBusConnection *connection = NULL;
35 struct connman_device {
36 struct connman_element element;
37 enum connman_device_type type;
38 enum connman_device_mode mode;
39 connman_bool_t secondary;
40 connman_bool_t powered;
41 connman_bool_t carrier;
42 connman_bool_t scanning;
43 connman_bool_t disconnected;
44 connman_uint16_t scan_interval;
51 unsigned int connections;
53 struct connman_ipconfig *ipconfig;
55 struct connman_device_driver *driver;
58 connman_bool_t registered;
61 struct connman_network *network;
68 static gboolean device_scan_trigger(gpointer user_data)
70 struct connman_device *device = user_data;
72 DBG("device %p", device);
74 if (device->driver == NULL) {
75 device->scan_timeout = 0;
79 if (device->driver->scan)
80 device->driver->scan(device);
85 static const char *type2description(enum connman_device_type type)
88 case CONNMAN_DEVICE_TYPE_UNKNOWN:
89 case CONNMAN_DEVICE_TYPE_VENDOR:
91 case CONNMAN_DEVICE_TYPE_ETHERNET:
93 case CONNMAN_DEVICE_TYPE_WIFI:
95 case CONNMAN_DEVICE_TYPE_WIMAX:
97 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
99 case CONNMAN_DEVICE_TYPE_GPS:
101 case CONNMAN_DEVICE_TYPE_MBM:
102 case CONNMAN_DEVICE_TYPE_HSO:
103 case CONNMAN_DEVICE_TYPE_NOZOMI:
104 case CONNMAN_DEVICE_TYPE_HUAWEI:
105 case CONNMAN_DEVICE_TYPE_NOVATEL:
112 static const char *type2string(enum connman_device_type type)
115 case CONNMAN_DEVICE_TYPE_UNKNOWN:
116 case CONNMAN_DEVICE_TYPE_VENDOR:
118 case CONNMAN_DEVICE_TYPE_ETHERNET:
120 case CONNMAN_DEVICE_TYPE_WIFI:
122 case CONNMAN_DEVICE_TYPE_WIMAX:
124 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
126 case CONNMAN_DEVICE_TYPE_GPS:
128 case CONNMAN_DEVICE_TYPE_MBM:
129 case CONNMAN_DEVICE_TYPE_HSO:
130 case CONNMAN_DEVICE_TYPE_HUAWEI:
131 case CONNMAN_DEVICE_TYPE_NOZOMI:
132 case CONNMAN_DEVICE_TYPE_NOVATEL:
139 static int set_connected(struct connman_device *device,
140 connman_bool_t connected)
142 if (connected == TRUE) {
143 enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
144 struct connman_element *element;
146 device->disconnected = TRUE;
148 switch (device->element.ipv4.method) {
149 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
150 case CONNMAN_IPCONFIG_METHOD_OFF:
152 case CONNMAN_IPCONFIG_METHOD_STATIC:
153 type = CONNMAN_ELEMENT_TYPE_IPV4;
155 case CONNMAN_IPCONFIG_METHOD_DHCP:
156 type = CONNMAN_ELEMENT_TYPE_DHCP;
160 element = connman_element_create(NULL);
161 if (element != NULL) {
162 struct connman_service *service;
164 element->type = type;
165 element->index = device->element.index;
167 if (connman_element_register(element,
168 &device->element) < 0)
169 connman_element_unref(element);
171 device->disconnected = FALSE;
173 service = __connman_service_lookup_from_device(device);
174 __connman_service_indicate_state(service,
175 CONNMAN_SERVICE_STATE_CONFIGURATION);
178 struct connman_service *service;
180 connman_element_unregister_children(&device->element);
182 device->disconnected = TRUE;
184 service = __connman_service_lookup_from_device(device);
185 __connman_service_indicate_state(service,
186 CONNMAN_SERVICE_STATE_IDLE);
192 static int set_carrier(struct connman_device *device, connman_bool_t carrier)
194 struct connman_service *service;
196 service = __connman_service_lookup_from_device(device);
197 __connman_service_set_carrier(service, carrier);
199 return set_connected(device, carrier);
202 static int set_powered(struct connman_device *device, connman_bool_t powered)
204 struct connman_device_driver *driver = device->driver;
207 DBG("device %p powered %d", device, powered);
212 if (powered == TRUE) {
213 if (driver->enable) {
214 err = driver->enable(device);
215 __connman_notifier_device_type_increase(device->type);
219 g_hash_table_remove_all(device->networks);
221 set_carrier(device, FALSE);
223 if (driver->disable) {
224 err = driver->disable(device);
225 __connman_notifier_device_type_decrease(device->type);
231 device->powered = powered;
236 static void append_path(gpointer key, gpointer value, gpointer user_data)
238 struct connman_element *element = value;
239 DBusMessageIter *iter = user_data;
241 dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
245 static void append_networks(struct connman_device *device,
246 DBusMessageIter *entry)
248 DBusMessageIter value, iter;
249 const char *key = "Networks";
251 dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
253 dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
254 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
257 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
258 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
259 g_hash_table_foreach(device->networks, append_path, &iter);
260 dbus_message_iter_close_container(&value, &iter);
262 dbus_message_iter_close_container(entry, &value);
265 static DBusMessage *get_properties(DBusConnection *conn,
266 DBusMessage *msg, void *data)
268 struct connman_device *device = data;
270 DBusMessageIter array, dict, entry;
273 DBG("conn %p", conn);
275 if (__connman_security_check_privilege(msg,
276 CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
277 return __connman_error_permission_denied(msg);
279 reply = dbus_message_new_method_return(msg);
283 dbus_message_iter_init_append(reply, &array);
285 dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
286 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
287 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
288 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
290 if (device->name != NULL)
291 connman_dbus_dict_append_variant(&dict, "Name",
292 DBUS_TYPE_STRING, &device->name);
294 str = type2string(device->type);
296 connman_dbus_dict_append_variant(&dict, "Type",
297 DBUS_TYPE_STRING, &str);
299 if (device->address != NULL)
300 connman_dbus_dict_append_variant(&dict, "Address",
301 DBUS_TYPE_STRING, &device->address);
303 if (device->interface != NULL)
304 connman_dbus_dict_append_variant(&dict, "Interface",
305 DBUS_TYPE_STRING, &device->interface);
307 connman_dbus_dict_append_variant(&dict, "Powered",
308 DBUS_TYPE_BOOLEAN, &device->powered);
310 if (device->driver && device->driver->scan)
311 connman_dbus_dict_append_variant(&dict, "Scanning",
312 DBUS_TYPE_BOOLEAN, &device->scanning);
314 switch (device->mode) {
315 case CONNMAN_DEVICE_MODE_UNKNOWN:
317 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
318 __connman_element_append_ipv4(&device->element, &dict);
320 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
321 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
322 if (device->scan_interval > 0)
323 connman_dbus_dict_append_variant(&dict, "ScanInterval",
324 DBUS_TYPE_UINT16, &device->scan_interval);
326 dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY,
328 append_networks(device, &entry);
329 dbus_message_iter_close_container(&dict, &entry);
333 dbus_message_iter_close_container(&array, &dict);
338 static gboolean powered_timeout(gpointer user_data)
340 struct connman_device *device = user_data;
342 DBG("device %p", device);
346 if (device->pending != NULL) {
349 reply = __connman_error_operation_timeout(device->pending);
351 g_dbus_send_message(connection, reply);
353 dbus_message_unref(device->pending);
354 device->pending = NULL;
360 static DBusMessage *set_property(DBusConnection *conn,
361 DBusMessage *msg, void *data)
363 struct connman_device *device = data;
364 DBusMessageIter iter, value;
368 DBG("conn %p", conn);
370 if (dbus_message_iter_init(msg, &iter) == FALSE)
371 return __connman_error_invalid_arguments(msg);
373 dbus_message_iter_get_basic(&iter, &name);
374 dbus_message_iter_next(&iter);
375 dbus_message_iter_recurse(&iter, &value);
377 if (__connman_security_check_privilege(msg,
378 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
379 return __connman_error_permission_denied(msg);
381 type = dbus_message_iter_get_arg_type(&value);
383 if (g_str_equal(name, "Powered") == TRUE) {
384 connman_bool_t powered;
387 if (type != DBUS_TYPE_BOOLEAN)
388 return __connman_error_invalid_arguments(msg);
390 dbus_message_iter_get_basic(&value, &powered);
392 if (device->powered == powered)
393 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
395 if (device->pending != NULL)
396 return __connman_error_in_progress(msg);
398 err = set_powered(device, powered);
400 if (err != -EINPROGRESS)
401 return __connman_error_failed(msg, -err);
403 device->pending = dbus_message_ref(msg);
405 device->timeout = g_timeout_add_seconds(15,
406 powered_timeout, device);
410 } else if (g_str_equal(name, "ScanInterval") == TRUE) {
411 connman_uint16_t interval;
413 switch (device->mode) {
414 case CONNMAN_DEVICE_MODE_UNKNOWN:
415 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
416 return __connman_error_invalid_arguments(msg);
417 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
418 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
422 if (type != DBUS_TYPE_UINT16)
423 return __connman_error_invalid_arguments(msg);
425 dbus_message_iter_get_basic(&value, &interval);
427 device->scan_interval = interval;
429 if (device->scan_timeout > 0) {
430 g_source_remove(device->scan_timeout);
431 device->scan_timeout = 0;
434 if (device->scan_interval > 0) {
435 guint interval = device->scan_interval;
436 device->scan_timeout = g_timeout_add_seconds(interval,
437 device_scan_trigger, device);
439 } else if (g_str_has_prefix(name, "IPv4.") == TRUE) {
442 switch (device->mode) {
443 case CONNMAN_DEVICE_MODE_UNKNOWN:
444 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
445 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
446 return __connman_error_invalid_arguments(msg);
447 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
451 err = __connman_ipconfig_set_ipv4(device->ipconfig,
454 return __connman_error_failed(msg, -err);
456 return __connman_error_invalid_property(msg);
458 __connman_storage_save_device(device);
460 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
463 static char *build_group(const unsigned char *ssid, unsigned int ssid_len,
464 const char *mode, const char *security)
469 str = g_string_sized_new((ssid_len * 2) + 24);
473 if (ssid_len > 0 && ssid[0] != '\0') {
474 for (i = 0; i < ssid_len; i++)
475 g_string_append_printf(str, "%02x", ssid[i]);
478 g_string_append_printf(str, "_%s_%s", mode, security);
480 return g_string_free(str, FALSE);
483 static void convert_name(const char *ssid, char *name,
484 unsigned int ssid_len)
488 for (i = 0; i < ssid_len; i++) {
489 if (g_ascii_isprint(ssid[i]))
496 static struct connman_network *find_network(struct connman_device *device,
497 const void *ssid, const char *address,
498 const char *security, const char *mode)
500 GHashTableIter network_iter;
506 g_hash_table_iter_init(&network_iter, device->networks);
507 while (g_hash_table_iter_next(&network_iter, &key, &value) == TRUE) {
508 const void *tmp_ssid;
509 const char *tmp_security, *tmp_mode, *tmp_address;
510 unsigned int tmp_ssid_size;
512 tmp_ssid = connman_network_get_blob(value, "WiFi.SSID",
514 tmp_security = connman_network_get_string(value,
516 tmp_mode = connman_network_get_string(value, "WiFi.Mode");
517 tmp_address = connman_network_get_string(value, "Address");
519 if (tmp_ssid_size < 1)
522 if (tmp_ssid && memcmp(ssid, tmp_ssid, tmp_ssid_size))
525 if (security && tmp_security &&
526 g_strcmp0(security, tmp_security) != 0)
529 if (mode && tmp_mode && g_strcmp0(mode, tmp_mode) != 0)
532 if (address && tmp_address &&
533 g_strcmp0(address, tmp_address) != 0)
536 return connman_network_ref(value);
542 static DBusMessage *join_network(DBusConnection *conn,
543 DBusMessage *msg, void *data)
545 struct connman_device *device = data;
546 struct connman_network *network, *found_network;
547 enum connman_network_type type;
548 unsigned int ssid_size;
549 const char *group, *mode, *security, *address;
551 DBusMessageIter iter, array;
554 DBG("conn %p", conn);
556 if (__connman_security_check_privilege(msg,
557 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
558 return __connman_error_permission_denied(msg);
560 if (!device->driver || !device->driver->join)
561 return __connman_error_not_supported(msg);
563 dbus_message_iter_init(msg, &iter);
564 dbus_message_iter_recurse(&iter, &array);
566 switch (device->type) {
567 case CONNMAN_DEVICE_TYPE_WIFI:
568 type = CONNMAN_NETWORK_TYPE_WIFI;
571 return __connman_error_not_supported(msg);
574 network = connman_network_create("00_00_00_00_00_00", type);
576 return __connman_error_failed(msg, ENOMEM);
578 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
579 DBusMessageIter entry, value;
580 const char *key, *str;
582 dbus_message_iter_recurse(&array, &entry);
583 dbus_message_iter_get_basic(&entry, &key);
585 dbus_message_iter_next(&entry);
586 dbus_message_iter_recurse(&entry, &value);
588 switch (dbus_message_iter_get_arg_type(&value)) {
589 case DBUS_TYPE_STRING:
590 dbus_message_iter_get_basic(&value, &str);
591 if (g_str_equal(key, "WiFi.SSID") == TRUE) {
594 connman_network_set_blob(network, key,
596 name = g_try_malloc0(strlen(str) + 1);
598 return __connman_error_failed(msg,
601 convert_name((char *) str, name, strlen(str));
602 connman_network_set_name(network, name);
606 connman_network_set_string(network, key, str);
610 dbus_message_iter_next(&array);
613 ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_size);
614 security = connman_network_get_string(network, "WiFi.Security");
615 mode = connman_network_get_string(network, "WiFi.Mode");
616 address = connman_network_get_string(network, "Address");
618 found_network = find_network(device, ssid, address, security, mode);
619 if (found_network != NULL) {
620 const char* passphrase;
622 passphrase = connman_network_get_string(network,
624 if (passphrase != NULL)
625 connman_network_set_string(found_network,
628 connman_network_unref(network);
629 network = found_network;
631 err = __connman_network_connect(found_network);
633 connman_network_unref(found_network);
636 return __connman_error_failed(msg, -err);
638 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
641 group = build_group(ssid, ssid_size, mode, security);
643 index = connman_device_get_index(device);
644 connman_network_set_index(network, index);
646 connman_network_set_protocol(network, CONNMAN_NETWORK_PROTOCOL_IP);
648 if (connman_device_get_disconnected(device) == FALSE)
649 __connman_device_disconnect(device);
651 err = device->driver->join(device, network);
653 connman_network_unref(network);
656 return __connman_error_failed(msg, -err);
658 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
661 static DBusMessage *create_network(DBusConnection *conn,
662 DBusMessage *msg, void *data)
664 DBG("conn %p", conn);
666 if (__connman_security_check_privilege(msg,
667 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
668 return __connman_error_permission_denied(msg);
670 return __connman_error_invalid_arguments(msg);
673 static DBusMessage *remove_network(DBusConnection *conn,
674 DBusMessage *msg, void *data)
676 DBG("conn %p", conn);
678 if (__connman_security_check_privilege(msg,
679 CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
680 return __connman_error_permission_denied(msg);
682 return __connman_error_invalid_arguments(msg);
685 static DBusMessage *propose_scan(DBusConnection *conn,
686 DBusMessage *msg, void *data)
688 struct connman_device *device = data;
691 DBG("conn %p", conn);
693 switch (device->mode) {
694 case CONNMAN_DEVICE_MODE_UNKNOWN:
695 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
696 return __connman_error_not_supported(msg);
697 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
698 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
702 if (!device->driver || !device->driver->scan)
703 return __connman_error_not_supported(msg);
705 if (device->powered == FALSE)
706 return __connman_error_failed(msg, EINVAL);
708 err = device->driver->scan(device);
710 return __connman_error_failed(msg, -err);
712 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
715 static GDBusMethodTable device_methods[] = {
716 { "GetProperties", "", "a{sv}", get_properties },
717 { "SetProperty", "sv", "", set_property,
718 G_DBUS_METHOD_FLAG_ASYNC },
719 { "JoinNetwork", "a{sv}", "", join_network },
720 { "CreateNetwork", "a{sv}", "o", create_network },
721 { "RemoveNetwork", "o", "", remove_network },
722 { "ProposeScan", "", "", propose_scan },
726 static GDBusSignalTable device_signals[] = {
727 { "PropertyChanged", "sv" },
731 static void append_devices(DBusMessageIter *entry)
733 DBusMessageIter value, iter;
734 const char *key = "Devices";
736 dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
738 dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
739 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
742 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
743 DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
744 __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_DEVICE, &iter);
745 dbus_message_iter_close_container(&value, &iter);
747 dbus_message_iter_close_container(entry, &value);
750 static void emit_devices_signal(void)
753 DBusMessageIter entry;
755 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
756 CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
760 dbus_message_iter_init_append(signal, &entry);
762 append_devices(&entry);
764 g_dbus_send_message(connection, signal);
767 static int register_interface(struct connman_element *element)
769 struct connman_device *device = element->device;
771 DBG("element %p name %s", element, element->name);
773 if (g_dbus_register_interface(connection, element->path,
774 CONNMAN_DEVICE_INTERFACE,
775 device_methods, device_signals,
776 NULL, device, NULL) == FALSE) {
777 connman_error("Failed to register %s device", element->path);
781 device->registered = TRUE;
783 emit_devices_signal();
788 static void unregister_interface(struct connman_element *element)
790 struct connman_device *device = element->device;
792 DBG("element %p name %s", element, element->name);
794 device->registered = FALSE;
796 emit_devices_signal();
798 g_dbus_unregister_interface(connection, element->path,
799 CONNMAN_DEVICE_INTERFACE);
802 static void device_enable(struct connman_device *device)
804 DBG("device %p", device);
806 if (device->powered == TRUE)
809 if (device->driver->enable) {
810 if (device->driver->enable(device) == 0)
811 device->powered = TRUE;
812 __connman_notifier_device_type_increase(device->type);
816 static void device_disable(struct connman_device *device)
818 DBG("device %p", device);
820 if (device->powered == FALSE)
823 g_hash_table_remove_all(device->networks);
825 if (device->driver->disable) {
826 if (device->driver->disable(device) == 0)
827 device->powered = FALSE;
828 __connman_notifier_device_type_decrease(device->type);
832 static int setup_device(struct connman_device *device)
836 DBG("device %p", device);
838 err = register_interface(&device->element);
840 if (device->driver->remove)
841 device->driver->remove(device);
842 device->driver = NULL;
846 switch (device->mode) {
847 case CONNMAN_DEVICE_MODE_UNKNOWN:
848 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
849 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
851 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
852 if (device->secondary == FALSE)
853 __connman_profile_add_device(device);
857 device_enable(device);
862 static void probe_driver(struct connman_element *element, gpointer user_data)
864 struct connman_device_driver *driver = user_data;
866 DBG("element %p name %s", element, element->name);
868 if (element->device == NULL)
871 if (element->device->driver != NULL)
874 if (driver->type != element->device->type)
877 if (driver->probe(element->device) < 0)
880 element->device->driver = driver;
882 setup_device(element->device);
885 static void remove_device(struct connman_device *device)
887 DBG("device %p", device);
889 device_disable(device);
891 switch (device->mode) {
892 case CONNMAN_DEVICE_MODE_UNKNOWN:
893 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
894 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
896 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
897 if (device->secondary == FALSE)
898 __connman_profile_remove_device(device);
902 unregister_interface(&device->element);
904 if (device->driver->remove)
905 device->driver->remove(device);
907 device->driver = NULL;
910 static void remove_driver(struct connman_element *element, gpointer user_data)
912 struct connman_device_driver *driver = user_data;
914 DBG("element %p name %s", element, element->name);
916 if (element->device == NULL)
919 if (element->device->driver == driver)
920 remove_device(element->device);
923 connman_bool_t __connman_device_has_driver(struct connman_device *device)
925 if (device == NULL || device->driver == NULL)
928 return device->registered;
931 static GSList *driver_list = NULL;
933 static gint compare_priority(gconstpointer a, gconstpointer b)
935 const struct connman_device_driver *driver1 = a;
936 const struct connman_device_driver *driver2 = b;
938 return driver2->priority - driver1->priority;
942 * connman_device_driver_register:
943 * @driver: device driver definition
945 * Register a new device driver
947 * Returns: %0 on success
949 int connman_device_driver_register(struct connman_device_driver *driver)
951 DBG("driver %p name %s", driver, driver->name);
953 driver_list = g_slist_insert_sorted(driver_list, driver,
956 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
957 probe_driver, driver);
963 * connman_device_driver_unregister:
964 * @driver: device driver definition
966 * Remove a previously registered device driver
968 void connman_device_driver_unregister(struct connman_device_driver *driver)
970 DBG("driver %p name %s", driver, driver->name);
972 driver_list = g_slist_remove(driver_list, driver);
974 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
975 remove_driver, driver);
978 static void unregister_network(gpointer data)
980 struct connman_network *network = data;
982 DBG("network %p", network);
984 connman_element_unregister((struct connman_element *) network);
986 connman_network_unref(network);
989 static void device_destruct(struct connman_element *element)
991 struct connman_device *device = element->device;
993 DBG("element %p name %s", element, element->name);
995 if (device->timeout > 0) {
996 g_source_remove(device->timeout);
1000 if (device->pending != NULL) {
1001 dbus_message_unref(device->pending);
1002 device->pending = NULL;
1005 g_free(device->ident);
1006 g_free(device->node);
1007 g_free(device->name);
1008 g_free(device->address);
1009 g_free(device->control);
1010 g_free(device->interface);
1012 connman_ipconfig_unref(device->ipconfig);
1014 g_free(device->last_network);
1016 g_hash_table_destroy(device->networks);
1017 device->networks = NULL;
1021 * connman_device_create:
1022 * @node: device node name (for example an address)
1023 * @type: device type
1025 * Allocate a new device of given #type and assign the #node name to it.
1027 * Returns: a newly-allocated #connman_device structure
1029 struct connman_device *connman_device_create(const char *node,
1030 enum connman_device_type type)
1032 struct connman_device *device;
1035 DBG("node %s type %d", node, type);
1037 device = g_try_new0(struct connman_device, 1);
1041 DBG("device %p", device);
1043 __connman_element_initialize(&device->element);
1045 device->element.name = g_strdup(node);
1046 device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
1048 device->element.device = device;
1049 device->element.destruct = device_destruct;
1051 str = type2string(type);
1053 connman_element_set_string(&device->element,
1054 CONNMAN_PROPERTY_ID_TYPE, str);
1056 device->element.ipv4.method = CONNMAN_IPCONFIG_METHOD_DHCP;
1058 device->type = type;
1059 device->name = g_strdup(type2description(device->type));
1060 device->mode = CONNMAN_DEVICE_MODE_UNKNOWN;
1061 device->secondary = FALSE;
1064 case CONNMAN_DEVICE_TYPE_UNKNOWN:
1065 case CONNMAN_DEVICE_TYPE_VENDOR:
1066 device->scan_interval = 0;
1068 case CONNMAN_DEVICE_TYPE_ETHERNET:
1069 case CONNMAN_DEVICE_TYPE_WIFI:
1070 device->scan_interval = 300;
1072 case CONNMAN_DEVICE_TYPE_WIMAX:
1073 device->scan_interval = 0;
1075 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
1076 device->scan_interval = 0;
1078 case CONNMAN_DEVICE_TYPE_GPS:
1079 device->scan_interval = 0;
1081 case CONNMAN_DEVICE_TYPE_MBM:
1082 case CONNMAN_DEVICE_TYPE_HSO:
1083 case CONNMAN_DEVICE_TYPE_NOZOMI:
1084 case CONNMAN_DEVICE_TYPE_HUAWEI:
1085 case CONNMAN_DEVICE_TYPE_NOVATEL:
1086 device->scan_interval = 0;
1090 device->ipconfig = connman_ipconfig_create();
1091 if (device->ipconfig == NULL) {
1092 connman_device_unref(device);
1096 device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
1097 g_free, unregister_network);
1103 * connman_device_ref:
1104 * @device: device structure
1106 * Increase reference counter of device
1108 struct connman_device *connman_device_ref(struct connman_device *device)
1110 if (connman_element_ref(&device->element) == NULL)
1117 * connman_device_unref:
1118 * @device: device structure
1120 * Decrease reference counter of device
1122 void connman_device_unref(struct connman_device *device)
1124 connman_element_unref(&device->element);
1127 const char *__connman_device_get_type(struct connman_device *device)
1129 return type2string(device->type);
1133 * connman_device_get_type:
1134 * @device: device structure
1136 * Get type of device
1138 enum connman_device_type connman_device_get_type(struct connman_device *device)
1140 return device->type;
1144 * connman_device_get_name:
1145 * @device: device structure
1147 * Get unique name of device
1149 const char *connman_device_get_name(struct connman_device *device)
1151 return device->element.name;
1155 * connman_device_get_path:
1156 * @device: device structure
1158 * Get path name of device
1160 const char *connman_device_get_path(struct connman_device *device)
1162 return device->element.path;
1166 * connman_device_set_index:
1167 * @device: device structure
1168 * @index: index number
1170 * Set index number of device
1172 void connman_device_set_index(struct connman_device *device, int index)
1174 device->element.index = index;
1178 * connman_device_get_index:
1179 * @device: device structure
1181 * Get index number of device
1183 int connman_device_get_index(struct connman_device *device)
1185 return device->element.index;
1189 * connman_device_set_interface:
1190 * @device: device structure
1191 * @interface: interface name
1192 * @control: control interface
1194 * Set interface name of device
1196 void connman_device_set_interface(struct connman_device *device,
1197 const char *interface, const char *control)
1199 g_free(device->element.devname);
1200 device->element.devname = g_strdup(interface);
1202 g_free(device->interface);
1203 device->interface = g_strdup(interface);
1205 g_free(device->control);
1206 device->control = g_strdup(control);
1208 if (device->name == NULL) {
1209 const char *str = type2description(device->type);
1210 if (str != NULL && device->interface != NULL)
1211 device->name = g_strdup_printf("%s (%s)", str,
1217 * connman_device_set_ident:
1218 * @device: device structure
1219 * @ident: unique identifier
1221 * Set unique identifier of device
1223 void connman_device_set_ident(struct connman_device *device,
1226 g_free(device->ident);
1227 device->ident = g_strdup(ident);
1230 const char *__connman_device_get_ident(struct connman_device *device)
1232 return device->ident;
1236 * connman_device_set_mode:
1237 * @device: device structure
1238 * @mode: network mode
1240 * Change network mode of device
1242 void connman_device_set_mode(struct connman_device *device,
1243 enum connman_device_mode mode)
1245 device->mode = mode;
1249 * connman_device_get_mode:
1250 * @device: device structure
1252 * Get network mode of device
1254 enum connman_device_mode connman_device_get_mode(struct connman_device *device)
1256 return device->mode;
1260 * connman_device_set_secondary:
1261 * @device: device structure
1262 * @secondary: secondary value
1264 * Change secondary value of device
1266 void connman_device_set_secondary(struct connman_device *device,
1267 connman_bool_t secondary)
1269 device->secondary = secondary;
1273 * connman_device_get_secondary:
1274 * @device: device structure
1276 * Get secondary value of device
1278 connman_bool_t connman_device_get_secondary(struct connman_device *device)
1280 return device->secondary;
1284 * connman_device_set_powered:
1285 * @device: device structure
1286 * @powered: powered state
1288 * Change power state of device
1290 int connman_device_set_powered(struct connman_device *device,
1291 connman_bool_t powered)
1293 DBusMessage *signal;
1294 DBusMessageIter entry, value;
1295 const char *key = "Powered";
1297 DBG("driver %p powered %d", device, powered);
1299 if (device->timeout > 0) {
1300 g_source_remove(device->timeout);
1301 device->timeout = 0;
1304 if (device->pending != NULL) {
1305 g_dbus_send_reply(connection, device->pending,
1308 dbus_message_unref(device->pending);
1309 device->pending = NULL;
1312 if (device->powered == powered)
1315 device->powered = powered;
1317 if (device->registered == FALSE)
1320 signal = dbus_message_new_signal(device->element.path,
1321 CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
1325 dbus_message_iter_init_append(signal, &entry);
1327 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
1329 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
1330 DBUS_TYPE_BOOLEAN_AS_STRING, &value);
1331 dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &powered);
1332 dbus_message_iter_close_container(&entry, &value);
1334 g_dbus_send_message(connection, signal);
1336 if (powered == FALSE)
1339 if (device->scan_timeout > 0) {
1340 g_source_remove(device->scan_timeout);
1341 device->scan_timeout = 0;
1344 if (device->scan_interval > 0) {
1345 guint interval = device->scan_interval;
1346 device->scan_timeout = g_timeout_add_seconds(interval,
1347 device_scan_trigger, device);
1350 if (device->driver->scan)
1351 device->driver->scan(device);
1357 * connman_device_set_carrier:
1358 * @device: device structure
1359 * @carrier: carrier state
1361 * Change carrier state of device (only for device without scanning)
1363 int connman_device_set_carrier(struct connman_device *device,
1364 connman_bool_t carrier)
1366 DBG("device %p carrier %d", device, carrier);
1368 switch (device->mode) {
1369 case CONNMAN_DEVICE_MODE_UNKNOWN:
1370 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1371 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1373 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1377 if (device->carrier == carrier)
1380 device->carrier = carrier;
1382 return set_carrier(device, device->carrier);
1385 int __connman_device_connect(struct connman_device *device)
1387 DBG("device %p", device);
1389 if (device->disconnected == FALSE)
1392 if (device->driver && device->driver->connect)
1393 device->driver->connect(device);
1398 int __connman_device_disconnect(struct connman_device *device)
1400 GHashTableIter iter;
1401 gpointer key, value;
1403 DBG("device %p", device);
1405 connman_device_set_disconnected(device, TRUE);
1407 g_hash_table_iter_init(&iter, device->networks);
1409 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
1410 struct connman_network *network = value;
1412 if (connman_network_get_connected(network) == TRUE)
1413 __connman_network_disconnect(network);
1416 if (device->driver && device->driver->disconnect)
1417 device->driver->disconnect(device);
1422 static void mark_network_unavailable(gpointer key, gpointer value,
1425 struct connman_network *network = value;
1427 if (connman_network_get_connected(network) == TRUE)
1430 connman_network_set_available(network, FALSE);
1433 static gboolean remove_unavailable_network(gpointer key, gpointer value,
1436 struct connman_network *network = value;
1438 if (connman_network_get_connected(network) == TRUE)
1441 if (connman_network_get_available(network) == TRUE)
1448 * connman_device_set_scanning:
1449 * @device: device structure
1450 * @scanning: scanning state
1452 * Change scanning state of device
1454 int connman_device_set_scanning(struct connman_device *device,
1455 connman_bool_t scanning)
1457 DBusMessage *signal;
1458 DBusMessageIter entry, value;
1459 const char *key = "Scanning";
1461 DBG("device %p scanning %d", device, scanning);
1463 if (!device->driver || !device->driver->scan)
1466 if (device->scanning == scanning)
1469 device->scanning = scanning;
1471 signal = dbus_message_new_signal(device->element.path,
1472 CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
1476 dbus_message_iter_init_append(signal, &entry);
1478 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
1480 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
1481 DBUS_TYPE_BOOLEAN_AS_STRING, &value);
1482 dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &scanning);
1483 dbus_message_iter_close_container(&entry, &value);
1485 g_dbus_send_message(connection, signal);
1487 if (scanning == TRUE) {
1488 if (device->scan_timeout > 0) {
1489 g_source_remove(device->scan_timeout);
1490 device->scan_timeout = 0;
1493 if (device->scan_interval > 0) {
1494 guint interval = device->scan_interval;
1495 device->scan_timeout = g_timeout_add_seconds(interval,
1496 device_scan_trigger, device);
1499 g_hash_table_foreach(device->networks,
1500 mark_network_unavailable, NULL);
1504 g_hash_table_foreach_remove(device->networks,
1505 remove_unavailable_network, NULL);
1507 if (device->connections > 0)
1510 if (device->disconnected == TRUE)
1517 * connman_device_set_disconnected:
1518 * @device: device structure
1519 * @disconnected: disconnected state
1521 * Change disconnected state of device (only for device with networks)
1523 int connman_device_set_disconnected(struct connman_device *device,
1524 connman_bool_t disconnected)
1526 DBG("device %p disconnected %d", device, disconnected);
1528 switch (device->mode) {
1529 case CONNMAN_DEVICE_MODE_UNKNOWN:
1530 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1532 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1533 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1537 if (device->disconnected == disconnected)
1540 device->disconnected = disconnected;
1546 * connman_device_get_disconnected:
1547 * @device: device structure
1549 * Get device disconnected state
1551 connman_bool_t connman_device_get_disconnected(struct connman_device *device)
1553 return device->disconnected;
1557 * connman_device_set_connected:
1558 * @device: device structure
1559 * @connected: connected state
1561 * Change connected state of device (for Ethernet like devices)
1563 int connman_device_set_connected(struct connman_device *device,
1564 connman_bool_t connected)
1566 DBG("device %p connected %d", device, connected);
1568 switch (device->mode) {
1569 case CONNMAN_DEVICE_MODE_UNKNOWN:
1570 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1571 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1573 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1577 if (device->carrier == FALSE)
1580 return set_connected(device, connected);
1584 * connman_device_set_string:
1585 * @device: device structure
1586 * @key: unique identifier
1587 * @value: string value
1589 * Set string value for specific key
1591 int connman_device_set_string(struct connman_device *device,
1592 const char *key, const char *value)
1594 DBG("device %p key %s value %s", device, key, value);
1596 if (g_str_equal(key, "Address") == TRUE) {
1597 g_free(device->address);
1598 device->address = g_strdup(value);
1599 } else if (g_str_equal(key, "Name") == TRUE) {
1600 g_free(device->name);
1601 device->name = g_strdup(value);
1602 } else if (g_str_equal(key, "Node") == TRUE) {
1603 g_free(device->node);
1604 device->node = g_strdup(value);
1607 return connman_element_set_string(&device->element, key, value);
1611 * connman_device_get_string:
1612 * @device: device structure
1613 * @key: unique identifier
1615 * Get string value for specific key
1617 const char *connman_device_get_string(struct connman_device *device,
1620 DBG("device %p key %s", device, key);
1622 if (g_str_equal(key, "Address") == TRUE)
1623 return device->address;
1624 else if (g_str_equal(key, "Name") == TRUE)
1625 return device->name;
1626 else if (g_str_equal(key, "Node") == TRUE)
1627 return device->node;
1629 return connman_element_get_string(&device->element, key);
1632 static void set_offlinemode(struct connman_element *element, gpointer user_data)
1634 struct connman_device *device = element->device;
1635 connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
1636 connman_bool_t powered;
1638 DBG("element %p name %s", element, element->name);
1643 powered = (offlinemode == TRUE) ? FALSE : TRUE;
1645 if (device->powered == powered)
1648 set_powered(device, powered);
1651 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
1653 DBG("offlinmode %d", offlinemode);
1655 __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
1656 set_offlinemode, GUINT_TO_POINTER(offlinemode));
1658 __connman_notifier_offline_mode(offlinemode);
1663 void __connman_device_increase_connections(struct connman_device *device)
1665 device->connections++;
1668 void __connman_device_decrease_connections(struct connman_device *device)
1670 device->connections--;
1674 * connman_device_add_network:
1675 * @device: device structure
1676 * @network: network structure
1678 * Add new network to the device
1680 int connman_device_add_network(struct connman_device *device,
1681 struct connman_network *network)
1683 const char *identifier = connman_network_get_identifier(network);
1686 DBG("device %p network %p", device, network);
1688 switch (device->mode) {
1689 case CONNMAN_DEVICE_MODE_UNKNOWN:
1690 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1692 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1693 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1697 __connman_network_set_device(network, device);
1699 __connman_storage_load_network(network);
1701 err = connman_element_register((struct connman_element *) network,
1704 __connman_network_set_device(network, NULL);
1708 g_hash_table_insert(device->networks, g_strdup(identifier),
1715 * connman_device_get_network:
1716 * @device: device structure
1717 * @identifier: network identifier
1719 * Get network for given identifier
1721 struct connman_network *connman_device_get_network(struct connman_device *device,
1722 const char *identifier)
1724 DBG("device %p identifier %s", device, identifier);
1726 return g_hash_table_lookup(device->networks, identifier);
1730 * connman_device_remove_network:
1731 * @device: device structure
1732 * @identifier: network identifier
1734 * Remove network for given identifier
1736 int connman_device_remove_network(struct connman_device *device,
1737 const char *identifier)
1739 DBG("device %p identifier %s", device, identifier);
1741 g_hash_table_remove(device->networks, identifier);
1746 void __connman_device_set_network(struct connman_device *device,
1747 struct connman_network *network)
1751 if (device->network == network)
1754 if (device->network != NULL)
1755 connman_network_unref(device->network);
1757 if (network != NULL) {
1758 name = connman_network_get_string(network,
1759 CONNMAN_PROPERTY_ID_NAME);
1760 g_free(device->last_network);
1761 device->last_network = g_strdup(name);
1763 device->network = connman_network_ref(network);
1765 g_free(device->last_network);
1766 device->last_network = NULL;
1768 device->network = NULL;
1773 * connman_device_register:
1774 * @device: device structure
1776 * Register device with the system
1778 int connman_device_register(struct connman_device *device)
1780 __connman_storage_load_device(device);
1782 switch (device->mode) {
1783 case CONNMAN_DEVICE_MODE_UNKNOWN:
1784 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1786 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1787 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1788 __connman_storage_init_network(device);
1792 return connman_element_register(&device->element, NULL);
1796 * connman_device_unregister:
1797 * @device: device structure
1799 * Unregister device with the system
1801 void connman_device_unregister(struct connman_device *device)
1803 __connman_storage_save_device(device);
1805 connman_element_unregister(&device->element);
1809 * connman_device_get_data:
1810 * @device: device structure
1812 * Get private device data pointer
1814 void *connman_device_get_data(struct connman_device *device)
1816 return device->driver_data;
1820 * connman_device_set_data:
1821 * @device: device structure
1822 * @data: data pointer
1824 * Set private device data pointer
1826 void connman_device_set_data(struct connman_device *device, void *data)
1828 device->driver_data = data;
1831 static gboolean match_driver(struct connman_device *device,
1832 struct connman_device_driver *driver)
1834 if (device->type == driver->type ||
1835 driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
1841 static int device_probe(struct connman_element *element)
1843 struct connman_device *device = element->device;
1846 DBG("element %p name %s", element, element->name);
1851 if (device->driver != NULL)
1854 for (list = driver_list; list; list = list->next) {
1855 struct connman_device_driver *driver = list->data;
1857 if (match_driver(device, driver) == FALSE)
1860 DBG("driver %p name %s", driver, driver->name);
1862 if (driver->probe(device) == 0) {
1863 device->driver = driver;
1868 if (device->driver == NULL)
1871 return setup_device(device);
1874 static void device_remove(struct connman_element *element)
1876 struct connman_device *device = element->device;
1878 DBG("element %p name %s", element, element->name);
1883 if (device->driver == NULL)
1886 remove_device(device);
1889 static struct connman_driver device_driver = {
1891 .type = CONNMAN_ELEMENT_TYPE_DEVICE,
1892 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
1893 .probe = device_probe,
1894 .remove = device_remove,
1897 static int device_load(struct connman_device *device)
1900 gchar *pathname, *identifier, *data = NULL;
1904 DBG("device %p", device);
1906 pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
1907 __connman_profile_active_ident());
1908 if (pathname == NULL)
1911 keyfile = g_key_file_new();
1913 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
1920 if (g_key_file_load_from_data(keyfile, data, length,
1921 0, NULL) == FALSE) {
1928 identifier = g_strdup_printf("device_%s", device->element.name);
1929 if (identifier == NULL)
1932 switch (device->mode) {
1933 case CONNMAN_DEVICE_MODE_UNKNOWN:
1934 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1936 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1937 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1938 val = g_key_file_get_integer(keyfile, identifier,
1939 "ScanInterval", NULL);
1941 device->scan_interval = val;
1946 g_key_file_free(keyfile);
1953 static int device_save(struct connman_device *device)
1956 gchar *pathname, *identifier = NULL, *data = NULL;
1959 DBG("device %p", device);
1961 pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
1962 __connman_profile_active_ident());
1963 if (pathname == NULL)
1966 keyfile = g_key_file_new();
1968 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
1972 if (g_key_file_load_from_data(keyfile, data, length,
1980 identifier = g_strdup_printf("device_%s", device->element.name);
1981 if (identifier == NULL)
1984 switch (device->mode) {
1985 case CONNMAN_DEVICE_MODE_UNKNOWN:
1986 case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
1988 case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
1989 case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
1990 if (device->scan_interval > 0)
1991 g_key_file_set_integer(keyfile, identifier,
1992 "ScanInterval", device->scan_interval);
1996 data = g_key_file_to_data(keyfile, &length, NULL);
1998 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
1999 connman_error("Failed to store device information");
2004 g_key_file_free(keyfile);
2012 static struct connman_storage device_storage = {
2014 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
2015 .device_load = device_load,
2016 .device_save = device_save,
2019 int __connman_device_init(void)
2023 connection = connman_dbus_get_connection();
2025 if (connman_storage_register(&device_storage) < 0)
2026 connman_error("Failed to register device storage");
2028 return connman_driver_register(&device_driver);
2031 void __connman_device_cleanup(void)
2035 connman_driver_unregister(&device_driver);
2037 connman_storage_unregister(&device_storage);
2039 dbus_connection_unref(connection);