5 * Copyright (C) 2007-2010 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
30 #include <netinet/ether.h>
34 #define CONNMAN_API_SUBJECT_TO_CHANGE
35 #include <connman/plugin.h>
36 #include <connman/technology.h>
37 #include <connman/device.h>
38 #include <connman/inet.h>
39 #include <connman/dbus.h>
40 #include <connman/log.h>
42 #define BLUEZ_SERVICE "org.bluez"
43 #define BLUEZ_MANAGER_INTERFACE BLUEZ_SERVICE ".Manager"
44 #define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter"
45 #define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device"
46 #define BLUEZ_NETWORK_INTERFACE BLUEZ_SERVICE ".Network"
47 #define BLUEZ_NETWORK_SERVER BLUEZ_SERVICE ".NetworkServer"
49 #define LIST_ADAPTERS "ListAdapters"
50 #define ADAPTER_ADDED "AdapterAdded"
51 #define ADAPTER_REMOVED "AdapterRemoved"
52 #define DEVICE_REMOVED "DeviceRemoved"
54 #define PROPERTY_CHANGED "PropertyChanged"
55 #define GET_PROPERTIES "GetProperties"
56 #define SET_PROPERTY "SetProperty"
58 #define CONNECT "Connect"
59 #define DISCONNECT "Disconnect"
61 #define REGISTER "Register"
62 #define UNREGISTER "Unregister"
64 #define UUID_NAP "00001116-0000-1000-8000-00805f9b34fb"
68 static DBusConnection *connection;
70 static GHashTable *bluetooth_devices = NULL;
71 static GHashTable *bluetooth_networks = NULL;
73 static int pan_probe(struct connman_network *network)
75 DBG("network %p", network);
80 static void pan_remove(struct connman_network *network)
82 DBG("network %p", network);
85 static void connect_reply(DBusPendingCall *call, void *user_data)
87 struct connman_network *network = user_data;
90 const char *interface = NULL;
93 DBG("network %p", network);
95 reply = dbus_pending_call_steal_reply(call);
97 dbus_error_init(&error);
99 if (dbus_set_error_from_message(&error, reply) == TRUE) {
100 connman_error("%s", error.message);
101 dbus_error_free(&error);
106 if (dbus_message_get_args(reply, &error,
107 DBUS_TYPE_STRING, &interface,
108 DBUS_TYPE_INVALID) == FALSE) {
109 if (dbus_error_is_set(&error) == TRUE) {
110 connman_error("%s", error.message);
111 dbus_error_free(&error);
113 connman_error("Wrong arguments for connect");
117 if (interface == NULL)
120 DBG("interface %s", interface);
122 index = connman_inet_ifindex(interface);
124 connman_network_set_index(network, index);
126 connman_network_set_connected(network, TRUE);
128 dbus_message_unref(reply);
130 dbus_pending_call_unref(call);
135 connman_network_set_connected(network, FALSE);
137 dbus_message_unref(reply);
139 dbus_pending_call_unref(call);
142 static int pan_connect(struct connman_network *network)
144 const char *path = connman_network_get_string(network, "Path");
145 const char *uuid = "nap";
146 DBusMessage *message;
147 DBusPendingCall *call;
149 DBG("network %p", network);
154 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
155 BLUEZ_NETWORK_INTERFACE, CONNECT);
159 dbus_message_set_auto_start(message, FALSE);
161 dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
164 if (dbus_connection_send_with_reply(connection, message,
165 &call, TIMEOUT * 10) == FALSE) {
166 connman_error("Failed to connect service");
167 dbus_message_unref(message);
172 connman_error("D-Bus connection not available");
173 dbus_message_unref(message);
177 dbus_pending_call_set_notify(call, connect_reply, network, NULL);
179 dbus_message_unref(message);
184 static void disconnect_reply(DBusPendingCall *call, void *user_data)
186 struct connman_network *network = user_data;
190 DBG("network %p", network);
192 reply = dbus_pending_call_steal_reply(call);
194 dbus_error_init(&error);
196 if (dbus_set_error_from_message(&error, reply) == TRUE) {
197 connman_error("%s", error.message);
198 dbus_error_free(&error);
202 if (dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) == FALSE) {
203 if (dbus_error_is_set(&error) == TRUE) {
204 connman_error("%s", error.message);
205 dbus_error_free(&error);
207 connman_error("Wrong arguments for disconnect");
211 connman_network_set_connected(network, FALSE);
214 dbus_message_unref(reply);
216 dbus_pending_call_unref(call);
218 connman_network_unref(network);
221 static int pan_disconnect(struct connman_network *network)
223 const char *path = connman_network_get_string(network, "Path");
224 DBusMessage *message;
225 DBusPendingCall *call;
227 DBG("network %p", network);
232 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
233 BLUEZ_NETWORK_INTERFACE, DISCONNECT);
237 dbus_message_set_auto_start(message, FALSE);
239 dbus_message_append_args(message, DBUS_TYPE_INVALID);
241 if (dbus_connection_send_with_reply(connection, message,
242 &call, TIMEOUT) == FALSE) {
243 connman_error("Failed to disconnect service");
244 dbus_message_unref(message);
249 connman_error("D-Bus connection not available");
250 dbus_message_unref(message);
254 connman_network_ref(network);
256 connman_network_set_associating(network, FALSE);
258 dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
260 dbus_message_unref(message);
265 static struct connman_network_driver pan_driver = {
266 .name = "bluetooth-pan",
267 .type = CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
269 .remove = pan_remove,
270 .connect = pan_connect,
271 .disconnect = pan_disconnect,
274 static gboolean network_changed(DBusConnection *connection,
275 DBusMessage *message, void *user_data)
277 const char *path = dbus_message_get_path(message);
278 struct connman_network *network;
279 DBusMessageIter iter, value;
282 DBG("path %s", path);
284 network = g_hash_table_lookup(bluetooth_networks, path);
288 if (dbus_message_iter_init(message, &iter) == FALSE)
291 dbus_message_iter_get_basic(&iter, &key);
293 dbus_message_iter_next(&iter);
294 dbus_message_iter_recurse(&iter, &value);
296 if (g_str_equal(key, "Connected") == TRUE) {
297 dbus_bool_t connected;
299 dbus_message_iter_get_basic(&value, &connected);
301 if (connected == TRUE)
304 connman_network_set_associating(network, FALSE);
305 connman_network_set_connected(network, FALSE);
311 static void extract_properties(DBusMessage *reply, const char **parent,
312 const char **address,
315 dbus_bool_t *powered,
316 dbus_bool_t *scanning,
317 DBusMessageIter *uuids,
318 DBusMessageIter *networks)
320 DBusMessageIter array, dict;
322 if (dbus_message_iter_init(reply, &array) == FALSE)
325 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
328 dbus_message_iter_recurse(&array, &dict);
330 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
331 DBusMessageIter entry, value;
334 dbus_message_iter_recurse(&dict, &entry);
335 dbus_message_iter_get_basic(&entry, &key);
337 dbus_message_iter_next(&entry);
338 dbus_message_iter_recurse(&entry, &value);
340 if (g_str_equal(key, "Adapter") == TRUE) {
342 dbus_message_iter_get_basic(&value, parent);
343 } else if (g_str_equal(key, "Address") == TRUE) {
345 dbus_message_iter_get_basic(&value, address);
346 } else if (g_str_equal(key, "Name") == TRUE) {
348 dbus_message_iter_get_basic(&value, name);
349 } else if (g_str_equal(key, "Alias") == TRUE) {
351 dbus_message_iter_get_basic(&value, alias);
352 } else if (g_str_equal(key, "Powered") == TRUE) {
354 dbus_message_iter_get_basic(&value, powered);
355 } else if (g_str_equal(key, "Discovering") == TRUE) {
356 if (scanning != NULL)
357 dbus_message_iter_get_basic(&value, scanning);
358 } else if (g_str_equal(key, "Devices") == TRUE) {
359 if (networks != NULL)
360 memcpy(networks, &value, sizeof(value));
361 } else if (g_str_equal(key, "UUIDs") == TRUE) {
363 memcpy(uuids, &value, sizeof(value));
366 dbus_message_iter_next(&dict);
370 static dbus_bool_t has_pan(DBusMessageIter *array)
372 DBusMessageIter value;
374 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
377 dbus_message_iter_recurse(array, &value);
379 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
382 dbus_message_iter_get_basic(&value, &uuid);
384 if (g_strcmp0(uuid, UUID_NAP) == 0)
387 dbus_message_iter_next(&value);
393 static void network_properties_reply(DBusPendingCall *call, void *user_data)
395 char *path = user_data;
396 struct connman_device *device;
397 struct connman_network *network;
399 DBusMessageIter uuids;
400 const char *parent = NULL, *address = NULL, *name = NULL;
401 struct ether_addr addr;
404 reply = dbus_pending_call_steal_reply(call);
406 extract_properties(reply, &parent, &address, NULL, &name,
407 NULL, NULL, &uuids, NULL);
412 device = g_hash_table_lookup(bluetooth_devices, parent);
419 ether_aton_r(address, &addr);
421 snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
422 addr.ether_addr_octet[0],
423 addr.ether_addr_octet[1],
424 addr.ether_addr_octet[2],
425 addr.ether_addr_octet[3],
426 addr.ether_addr_octet[4],
427 addr.ether_addr_octet[5]);
429 if (has_pan(&uuids) == FALSE)
432 network = connman_device_get_network(device, ident);
436 network = connman_network_create(ident,
437 CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
441 connman_network_set_string(network, "Path", path);
443 connman_network_set_name(network, name);
445 connman_device_add_network(device, network);
447 connman_network_set_group(network, ident);
449 g_hash_table_insert(bluetooth_networks, g_strdup(path), network);
452 dbus_message_unref(reply);
454 dbus_pending_call_unref(call);
457 static void add_network(struct connman_device *device, const char *path)
459 DBusMessage *message;
460 DBusPendingCall *call;
462 DBG("path %s", path);
464 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
465 BLUEZ_DEVICE_INTERFACE, GET_PROPERTIES);
469 dbus_message_set_auto_start(message, FALSE);
471 if (dbus_connection_send_with_reply(connection, message,
472 &call, TIMEOUT) == FALSE) {
473 connman_error("Failed to get network properties for %s", path);
478 connman_error("D-Bus connection not available");
482 dbus_pending_call_set_notify(call, network_properties_reply,
483 g_strdup(path), g_free);
486 dbus_message_unref(message);
489 static void check_networks(struct connman_device *device,
490 DBusMessageIter *array)
492 DBusMessageIter value;
494 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
497 dbus_message_iter_recurse(array, &value);
499 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
502 dbus_message_iter_get_basic(&value, &path);
504 add_network(device, path);
506 dbus_message_iter_next(&value);
510 static gboolean adapter_changed(DBusConnection *connection,
511 DBusMessage *message, void *user_data)
513 const char *path = dbus_message_get_path(message);
514 struct connman_device *device;
515 DBusMessageIter iter, value;
518 DBG("path %s", path);
520 device = g_hash_table_lookup(bluetooth_devices, path);
524 if (dbus_message_iter_init(message, &iter) == FALSE)
527 dbus_message_iter_get_basic(&iter, &key);
529 dbus_message_iter_next(&iter);
530 dbus_message_iter_recurse(&iter, &value);
532 if (g_str_equal(key, "Powered") == TRUE) {
535 dbus_message_iter_get_basic(&value, &val);
536 connman_device_set_powered(device, val);
537 } else if (g_str_equal(key, "Discovering") == TRUE) {
540 dbus_message_iter_get_basic(&value, &val);
541 connman_device_set_scanning(device, val);
542 } else if (g_str_equal(key, "Devices") == TRUE) {
543 check_networks(device, &value);
549 static gboolean device_removed(DBusConnection *connection,
550 DBusMessage *message, void *user_data)
552 const char *network_path;
553 struct connman_network *network;
554 struct connman_device *device;
555 DBusMessageIter iter;
559 if (dbus_message_iter_init(message, &iter) == FALSE)
562 dbus_message_iter_get_basic(&iter, &network_path);
564 network = g_hash_table_lookup(bluetooth_networks, network_path);
568 device = connman_network_get_device(network);
572 g_hash_table_remove(bluetooth_networks, network_path);
577 static gboolean device_changed(DBusConnection *connection,
578 DBusMessage *message, void *user_data)
580 const char *path = dbus_message_get_path(message);
581 DBusMessageIter iter, value;
584 DBG("path %s", path);
586 if (dbus_message_iter_init(message, &iter) == FALSE)
589 dbus_message_iter_get_basic(&iter, &key);
591 dbus_message_iter_next(&iter);
592 dbus_message_iter_recurse(&iter, &value);
596 if (g_str_equal(key, "UUIDs") == TRUE)
597 add_network(NULL, path);
602 static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
604 char *path = user_data;
605 struct connman_device *device;
607 DBusMessageIter networks;
608 const char *address = NULL, *name = NULL;
609 dbus_bool_t powered = FALSE, scanning = FALSE;
610 struct ether_addr addr;
613 DBG("path %s", path);
615 reply = dbus_pending_call_steal_reply(call);
620 extract_properties(reply, NULL, &address, &name, NULL,
621 &powered, &scanning, NULL, &networks);
626 if (g_strcmp0(address, "00:00:00:00:00:00") == 0)
629 device = g_hash_table_lookup(bluetooth_devices, path);
633 ether_aton_r(address, &addr);
635 snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
636 addr.ether_addr_octet[0],
637 addr.ether_addr_octet[1],
638 addr.ether_addr_octet[2],
639 addr.ether_addr_octet[3],
640 addr.ether_addr_octet[4],
641 addr.ether_addr_octet[5]);
643 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_BLUETOOTH);
647 connman_device_set_ident(device, ident);
649 connman_device_set_string(device, "Path", path);
651 if (connman_device_register(device) < 0) {
652 connman_device_unref(device);
656 g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
659 connman_device_set_string(device, "Address", address);
660 connman_device_set_string(device, "Name", name);
661 connman_device_set_string(device, "Path", path);
663 connman_device_set_powered(device, powered);
664 connman_device_set_scanning(device, scanning);
667 check_networks(device, &networks);
670 dbus_message_unref(reply);
672 dbus_pending_call_unref(call);
675 static void add_adapter(DBusConnection *connection, const char *path)
677 DBusMessage *message;
678 DBusPendingCall *call;
680 DBG("path %s", path);
682 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
683 BLUEZ_ADAPTER_INTERFACE, GET_PROPERTIES);
687 dbus_message_set_auto_start(message, FALSE);
689 if (dbus_connection_send_with_reply(connection, message,
690 &call, TIMEOUT) == FALSE) {
691 connman_error("Failed to get adapter properties for %s", path);
696 connman_error("D-Bus connection not available");
700 dbus_pending_call_set_notify(call, adapter_properties_reply,
701 g_strdup(path), g_free);
704 dbus_message_unref(message);
707 static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
712 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
714 add_adapter(connection, path);
718 static void remove_adapter(DBusConnection *connection, const char *path)
720 DBG("path %s", path);
722 g_hash_table_remove(bluetooth_devices, path);
725 static gboolean adapter_removed(DBusConnection *connection, DBusMessage *message,
730 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
732 remove_adapter(connection, path);
736 static void list_adapters_reply(DBusPendingCall *call, void *user_data)
745 reply = dbus_pending_call_steal_reply(call);
747 dbus_error_init(&error);
749 if (dbus_set_error_from_message(&error, reply) == TRUE) {
750 connman_error("%s", error.message);
751 dbus_error_free(&error);
755 if (dbus_message_get_args(reply, &error,
756 DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH,
757 &adapters, &num_adapters,
758 DBUS_TYPE_INVALID) == FALSE) {
759 if (dbus_error_is_set(&error) == TRUE) {
760 connman_error("%s", error.message);
761 dbus_error_free(&error);
763 connman_error("Wrong arguments for adapter list");
767 for (i = 0; i < num_adapters; i++)
768 add_adapter(connection, adapters[i]);
770 g_strfreev(adapters);
773 dbus_message_unref(reply);
775 dbus_pending_call_unref(call);
778 static void unregister_device(gpointer data)
780 struct connman_device *device = data;
784 connman_device_unregister(device);
785 connman_device_unref(device);
788 static void remove_network(gpointer data)
790 struct connman_network *network = data;
791 struct connman_device *device;
793 DBG("network %p", network);
795 device = connman_network_get_device(network);
797 connman_device_remove_network(device, network);
799 connman_network_unref(network);
802 static void bluetooth_connect(DBusConnection *connection, void *user_data)
804 DBusMessage *message;
805 DBusPendingCall *call;
807 DBG("connection %p", connection);
809 bluetooth_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
810 g_free, unregister_device);
812 bluetooth_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
813 g_free, remove_network);
815 message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
816 BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
820 dbus_message_set_auto_start(message, FALSE);
822 if (dbus_connection_send_with_reply(connection, message,
823 &call, TIMEOUT) == FALSE) {
824 connman_error("Failed to get Bluetooth adapters");
829 connman_error("D-Bus connection not available");
833 dbus_pending_call_set_notify(call, list_adapters_reply, NULL, NULL);
836 dbus_message_unref(message);
839 static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
841 DBG("connection %p", connection);
843 if (bluetooth_devices == NULL)
846 g_hash_table_destroy(bluetooth_networks);
847 g_hash_table_destroy(bluetooth_devices);
848 bluetooth_devices = NULL;
851 static int bluetooth_probe(struct connman_device *device)
853 DBG("device %p", device);
858 static void bluetooth_remove(struct connman_device *device)
860 DBG("device %p", device);
863 static void powered_reply(DBusPendingCall *call, void *user_data)
870 reply = dbus_pending_call_steal_reply(call);
872 dbus_error_init(&error);
874 if (dbus_set_error_from_message(&error, reply) == TRUE) {
875 connman_error("%s", error.message);
876 dbus_error_free(&error);
877 dbus_message_unref(reply);
878 dbus_pending_call_unref(call);
882 dbus_message_unref(reply);
883 dbus_pending_call_unref(call);
885 add_adapter(connection, user_data);
888 static int change_powered(DBusConnection *connection, const char *path,
891 DBusMessage *message;
892 DBusMessageIter iter;
893 DBusPendingCall *call;
900 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
901 BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
905 dbus_message_set_auto_start(message, FALSE);
907 dbus_message_iter_init_append(message, &iter);
908 connman_dbus_property_append_basic(&iter, "Powered",
909 DBUS_TYPE_BOOLEAN, &powered);
911 if (dbus_connection_send_with_reply(connection, message,
912 &call, TIMEOUT) == FALSE) {
913 connman_error("Failed to change Powered property");
914 dbus_message_unref(message);
919 connman_error("D-Bus connection not available");
920 dbus_message_unref(message);
924 dbus_pending_call_set_notify(call, powered_reply,
925 g_strdup(path), g_free);
927 dbus_message_unref(message);
932 static int bluetooth_enable(struct connman_device *device)
934 const char *path = connman_device_get_string(device, "Path");
936 DBG("device %p", device);
938 return change_powered(connection, path, TRUE);
941 static int bluetooth_disable(struct connman_device *device)
943 const char *path = connman_device_get_string(device, "Path");
945 DBG("device %p", device);
947 return change_powered(connection, path, FALSE);
950 static struct connman_device_driver bluetooth_driver = {
952 .type = CONNMAN_DEVICE_TYPE_BLUETOOTH,
953 .probe = bluetooth_probe,
954 .remove = bluetooth_remove,
955 .enable = bluetooth_enable,
956 .disable = bluetooth_disable,
959 static int tech_probe(struct connman_technology *technology)
964 static void tech_remove(struct connman_technology *technology)
968 static void server_register_reply(DBusPendingCall *call, void *user_data)
970 struct connman_technology *technology = user_data;
976 reply = dbus_pending_call_steal_reply(call);
978 dbus_error_init(&error);
980 if (dbus_set_error_from_message(&error, reply) == TRUE) {
981 connman_error("%s", error.message);
982 dbus_error_free(&error);
983 dbus_message_unref(reply);
984 dbus_pending_call_unref(call);
988 dbus_message_unref(reply);
989 dbus_pending_call_unref(call);
991 connman_technology_tethering_notify(technology, TRUE);
994 static void server_unregister_reply(DBusPendingCall *call, void *user_data)
996 struct connman_technology *technology = user_data;
1002 reply = dbus_pending_call_steal_reply(call);
1004 dbus_error_init(&error);
1006 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1007 connman_error("%s", error.message);
1008 dbus_error_free(&error);
1009 dbus_message_unref(reply);
1010 dbus_pending_call_unref(call);
1014 dbus_message_unref(reply);
1015 dbus_pending_call_unref(call);
1017 connman_technology_tethering_notify(technology, FALSE);
1021 static void server_register(const char *path, const char *uuid,
1022 struct connman_technology *technology,
1023 const char *bridge, connman_bool_t enabled)
1025 DBusMessage *message;
1026 DBusPendingCall *call;
1029 DBG("path %s enabled %d", path, enabled);
1031 command = enabled ? REGISTER : UNREGISTER;
1033 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
1034 BLUEZ_NETWORK_SERVER, command);
1035 if (message == NULL)
1038 dbus_message_set_auto_start(message, FALSE);
1040 dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
1043 if (enabled == TRUE)
1044 dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
1047 if (dbus_connection_send_with_reply(connection, message,
1048 &call, TIMEOUT) == FALSE) {
1049 connman_error("Failed to enable PAN server");
1050 dbus_message_unref(message);
1055 connman_error("D-Bus connection not available");
1056 dbus_message_unref(message);
1060 if (enabled == TRUE)
1061 dbus_pending_call_set_notify(call, server_register_reply,
1064 dbus_pending_call_set_notify(call, server_unregister_reply,
1067 dbus_message_unref(message);
1070 struct tethering_info {
1071 struct connman_technology *technology;
1075 static void enable_nap(gpointer key, gpointer value, gpointer user_data)
1077 struct tethering_info *info = user_data;
1078 struct connman_device *device = value;
1083 path = connman_device_get_string(device, "Path");
1085 server_register(path, "nap", info->technology, info->bridge, TRUE);
1088 static void disable_nap(gpointer key, gpointer value, gpointer user_data)
1090 struct tethering_info *info = user_data;
1091 struct connman_device *device = value;
1096 path = connman_device_get_string(device, "Path");
1098 server_register(path, "nap", info->technology, info->bridge, FALSE);
1101 static int tech_set_tethering(struct connman_technology *technology,
1102 const char *identifier, const char *passphrase,
1103 const char *bridge, connman_bool_t enabled)
1105 struct tethering_info info = {
1106 .technology = technology,
1110 DBG("bridge %s", bridge);
1113 g_hash_table_foreach(bluetooth_devices, enable_nap, &info);
1115 g_hash_table_foreach(bluetooth_devices, disable_nap, &info);
1120 static struct connman_technology_driver tech_driver = {
1121 .name = "bluetooth",
1122 .type = CONNMAN_SERVICE_TYPE_BLUETOOTH,
1123 .probe = tech_probe,
1124 .remove = tech_remove,
1125 .set_tethering = tech_set_tethering,
1129 static guint added_watch;
1130 static guint removed_watch;
1131 static guint adapter_watch;
1132 static guint device_watch;
1133 static guint device_removed_watch;
1134 static guint network_watch;
1136 static int bluetooth_init(void)
1140 connection = connman_dbus_get_connection();
1141 if (connection == NULL)
1144 watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
1145 bluetooth_connect, bluetooth_disconnect, NULL, NULL);
1147 added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1148 BLUEZ_MANAGER_INTERFACE,
1149 ADAPTER_ADDED, adapter_added,
1152 removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1153 BLUEZ_MANAGER_INTERFACE,
1154 ADAPTER_REMOVED, adapter_removed,
1157 adapter_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1158 BLUEZ_ADAPTER_INTERFACE,
1159 PROPERTY_CHANGED, adapter_changed,
1162 device_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1163 BLUEZ_ADAPTER_INTERFACE,
1164 DEVICE_REMOVED, device_removed,
1167 device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1168 BLUEZ_DEVICE_INTERFACE,
1169 PROPERTY_CHANGED, device_changed,
1172 network_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1173 BLUEZ_NETWORK_INTERFACE,
1174 PROPERTY_CHANGED, network_changed,
1177 if (watch == 0 || added_watch == 0 || removed_watch == 0
1178 || adapter_watch == 0 || network_watch == 0
1179 || device_watch == 0
1180 || device_removed_watch == 0) {
1185 err = connman_network_driver_register(&pan_driver);
1189 err = connman_device_driver_register(&bluetooth_driver);
1191 connman_network_driver_unregister(&pan_driver);
1195 err = connman_technology_driver_register(&tech_driver);
1197 connman_device_driver_unregister(&bluetooth_driver);
1198 connman_network_driver_unregister(&pan_driver);
1205 g_dbus_remove_watch(connection, watch);
1206 g_dbus_remove_watch(connection, added_watch);
1207 g_dbus_remove_watch(connection, removed_watch);
1208 g_dbus_remove_watch(connection, adapter_watch);
1209 g_dbus_remove_watch(connection, device_removed_watch);
1210 g_dbus_remove_watch(connection, device_watch);
1211 g_dbus_remove_watch(connection, network_watch);
1213 dbus_connection_unref(connection);
1218 static void bluetooth_exit(void)
1220 g_dbus_remove_watch(connection, watch);
1221 g_dbus_remove_watch(connection, added_watch);
1222 g_dbus_remove_watch(connection, removed_watch);
1223 g_dbus_remove_watch(connection, adapter_watch);
1224 g_dbus_remove_watch(connection, device_removed_watch);
1225 g_dbus_remove_watch(connection, device_watch);
1226 g_dbus_remove_watch(connection, network_watch);
1228 bluetooth_disconnect(connection, NULL);
1230 connman_technology_driver_unregister(&tech_driver);
1232 connman_device_driver_unregister(&bluetooth_driver);
1233 connman_network_driver_unregister(&pan_driver);
1235 dbus_connection_unref(connection);
1238 CONNMAN_PLUGIN_DEFINE(bluetooth, "Bluetooth technology plugin", VERSION,
1239 CONNMAN_PLUGIN_PRIORITY_DEFAULT, bluetooth_init, bluetooth_exit)