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/tethering.h>
40 #include <connman/dbus.h>
41 #include <connman/log.h>
43 #define BLUEZ_SERVICE "org.bluez"
44 #define BLUEZ_MANAGER_INTERFACE BLUEZ_SERVICE ".Manager"
45 #define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter"
46 #define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device"
47 #define BLUEZ_NETWORK_INTERFACE BLUEZ_SERVICE ".Network"
48 #define BLUEZ_NETWORK_SERVER BLUEZ_SERVICE ".NetworkServer"
50 #define LIST_ADAPTERS "ListAdapters"
51 #define ADAPTER_ADDED "AdapterAdded"
52 #define ADAPTER_REMOVED "AdapterRemoved"
53 #define DEVICE_REMOVED "DeviceRemoved"
55 #define PROPERTY_CHANGED "PropertyChanged"
56 #define GET_PROPERTIES "GetProperties"
57 #define SET_PROPERTY "SetProperty"
59 #define CONNECT "Connect"
60 #define DISCONNECT "Disconnect"
62 #define REGISTER "Register"
63 #define UNREGISTER "Unregister"
65 #define UUID_NAP "00001116-0000-1000-8000-00805f9b34fb"
69 static DBusConnection *connection;
71 static GHashTable *bluetooth_devices = NULL;
72 static GHashTable *bluetooth_networks = NULL;
74 static int pan_probe(struct connman_network *network)
76 DBG("network %p", network);
81 static void pan_remove(struct connman_network *network)
83 DBG("network %p", network);
86 static void connect_reply(DBusPendingCall *call, void *user_data)
88 struct connman_network *network = user_data;
91 const char *interface = NULL;
94 DBG("network %p", network);
96 reply = dbus_pending_call_steal_reply(call);
98 dbus_error_init(&error);
100 if (dbus_set_error_from_message(&error, reply) == TRUE) {
101 connman_error("%s", error.message);
102 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);
129 dbus_message_unref(reply);
131 dbus_pending_call_unref(call);
134 static int pan_connect(struct connman_network *network)
136 const char *path = connman_network_get_string(network, "Path");
137 const char *uuid = "nap";
138 DBusMessage *message;
139 DBusPendingCall *call;
141 DBG("network %p", network);
146 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
147 BLUEZ_NETWORK_INTERFACE, CONNECT);
151 dbus_message_set_auto_start(message, FALSE);
153 dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
156 if (dbus_connection_send_with_reply(connection, message,
157 &call, TIMEOUT * 10) == FALSE) {
158 connman_error("Failed to connect service");
159 dbus_message_unref(message);
164 connman_error("D-Bus connection not available");
165 dbus_message_unref(message);
169 dbus_pending_call_set_notify(call, connect_reply, network, NULL);
171 dbus_message_unref(message);
176 static void disconnect_reply(DBusPendingCall *call, void *user_data)
178 struct connman_network *network = user_data;
182 DBG("network %p", network);
184 reply = dbus_pending_call_steal_reply(call);
186 dbus_error_init(&error);
188 if (dbus_set_error_from_message(&error, reply) == TRUE) {
189 connman_error("%s", error.message);
190 dbus_error_free(&error);
194 if (dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) == FALSE) {
195 if (dbus_error_is_set(&error) == TRUE) {
196 connman_error("%s", error.message);
197 dbus_error_free(&error);
199 connman_error("Wrong arguments for disconnect");
203 connman_network_set_connected(network, FALSE);
206 dbus_message_unref(reply);
208 dbus_pending_call_unref(call);
210 connman_network_unref(network);
213 static int pan_disconnect(struct connman_network *network)
215 const char *path = connman_network_get_string(network, "Path");
216 DBusMessage *message;
217 DBusPendingCall *call;
219 DBG("network %p", network);
224 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
225 BLUEZ_NETWORK_INTERFACE, DISCONNECT);
229 dbus_message_set_auto_start(message, FALSE);
231 dbus_message_append_args(message, DBUS_TYPE_INVALID);
233 if (dbus_connection_send_with_reply(connection, message,
234 &call, TIMEOUT) == FALSE) {
235 connman_error("Failed to disconnect service");
236 dbus_message_unref(message);
241 connman_error("D-Bus connection not available");
242 dbus_message_unref(message);
246 connman_network_ref(network);
248 connman_network_set_associating(network, FALSE);
250 dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
252 dbus_message_unref(message);
257 static struct connman_network_driver pan_driver = {
258 .name = "bluetooth-pan",
259 .type = CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
261 .remove = pan_remove,
262 .connect = pan_connect,
263 .disconnect = pan_disconnect,
266 static gboolean network_changed(DBusConnection *connection,
267 DBusMessage *message, void *user_data)
269 const char *path = dbus_message_get_path(message);
270 struct connman_network *network;
271 DBusMessageIter iter, value;
274 DBG("path %s", path);
276 network = g_hash_table_lookup(bluetooth_networks, path);
280 if (dbus_message_iter_init(message, &iter) == FALSE)
283 dbus_message_iter_get_basic(&iter, &key);
285 dbus_message_iter_next(&iter);
286 dbus_message_iter_recurse(&iter, &value);
288 if (g_str_equal(key, "Connected") == TRUE) {
289 dbus_bool_t connected;
291 dbus_message_iter_get_basic(&value, &connected);
293 if (connected == TRUE)
296 connman_network_set_associating(network, FALSE);
297 connman_network_set_connected(network, FALSE);
303 static void extract_properties(DBusMessage *reply, const char **parent,
304 const char **address,
307 dbus_bool_t *powered,
308 dbus_bool_t *scanning,
309 DBusMessageIter *uuids,
310 DBusMessageIter *networks)
312 DBusMessageIter array, dict;
314 if (dbus_message_iter_init(reply, &array) == FALSE)
317 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
320 dbus_message_iter_recurse(&array, &dict);
322 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
323 DBusMessageIter entry, value;
326 dbus_message_iter_recurse(&dict, &entry);
327 dbus_message_iter_get_basic(&entry, &key);
329 dbus_message_iter_next(&entry);
330 dbus_message_iter_recurse(&entry, &value);
332 if (g_str_equal(key, "Adapter") == TRUE) {
334 dbus_message_iter_get_basic(&value, parent);
335 } else if (g_str_equal(key, "Address") == TRUE) {
337 dbus_message_iter_get_basic(&value, address);
338 } else if (g_str_equal(key, "Name") == TRUE) {
340 dbus_message_iter_get_basic(&value, name);
341 } else if (g_str_equal(key, "Alias") == TRUE) {
343 dbus_message_iter_get_basic(&value, alias);
344 } else if (g_str_equal(key, "Powered") == TRUE) {
346 dbus_message_iter_get_basic(&value, powered);
347 } else if (g_str_equal(key, "Discovering") == TRUE) {
348 if (scanning != NULL)
349 dbus_message_iter_get_basic(&value, scanning);
350 } else if (g_str_equal(key, "Devices") == TRUE) {
351 if (networks != NULL)
352 memcpy(networks, &value, sizeof(value));
353 } else if (g_str_equal(key, "UUIDs") == TRUE) {
355 memcpy(uuids, &value, sizeof(value));
358 dbus_message_iter_next(&dict);
362 static dbus_bool_t has_pan(DBusMessageIter *array)
364 DBusMessageIter value;
366 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
369 dbus_message_iter_recurse(array, &value);
371 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
374 dbus_message_iter_get_basic(&value, &uuid);
376 if (g_strcmp0(uuid, UUID_NAP) == 0)
379 dbus_message_iter_next(&value);
385 static void network_properties_reply(DBusPendingCall *call, void *user_data)
387 char *path = user_data;
388 struct connman_device *device;
389 struct connman_network *network;
391 DBusMessageIter uuids;
392 const char *parent = NULL, *address = NULL, *name = NULL;
393 struct ether_addr addr;
396 reply = dbus_pending_call_steal_reply(call);
398 extract_properties(reply, &parent, &address, NULL, &name,
399 NULL, NULL, &uuids, NULL);
404 device = g_hash_table_lookup(bluetooth_devices, parent);
411 ether_aton_r(address, &addr);
413 snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
414 addr.ether_addr_octet[0],
415 addr.ether_addr_octet[1],
416 addr.ether_addr_octet[2],
417 addr.ether_addr_octet[3],
418 addr.ether_addr_octet[4],
419 addr.ether_addr_octet[5]);
421 if (has_pan(&uuids) == FALSE)
424 network = connman_device_get_network(device, ident);
428 network = connman_network_create(ident,
429 CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
433 connman_network_set_string(network, "Path", path);
435 connman_network_set_name(network, name);
437 connman_device_add_network(device, network);
439 connman_network_set_group(network, ident);
441 g_hash_table_insert(bluetooth_networks, g_strdup(path), network);
444 dbus_message_unref(reply);
446 dbus_pending_call_unref(call);
449 static void add_network(struct connman_device *device, const char *path)
451 DBusMessage *message;
452 DBusPendingCall *call;
454 DBG("path %s", path);
456 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
457 BLUEZ_DEVICE_INTERFACE, GET_PROPERTIES);
461 dbus_message_set_auto_start(message, FALSE);
463 if (dbus_connection_send_with_reply(connection, message,
464 &call, TIMEOUT) == FALSE) {
465 connman_error("Failed to get network properties for %s", path);
470 connman_error("D-Bus connection not available");
474 dbus_pending_call_set_notify(call, network_properties_reply,
475 g_strdup(path), g_free);
478 dbus_message_unref(message);
481 static void check_networks(struct connman_device *device,
482 DBusMessageIter *array)
484 DBusMessageIter value;
486 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
489 dbus_message_iter_recurse(array, &value);
491 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
494 dbus_message_iter_get_basic(&value, &path);
496 add_network(device, path);
498 dbus_message_iter_next(&value);
502 static gboolean adapter_changed(DBusConnection *connection,
503 DBusMessage *message, void *user_data)
505 const char *path = dbus_message_get_path(message);
506 struct connman_device *device;
507 DBusMessageIter iter, value;
510 DBG("path %s", path);
512 device = g_hash_table_lookup(bluetooth_devices, path);
516 if (dbus_message_iter_init(message, &iter) == FALSE)
519 dbus_message_iter_get_basic(&iter, &key);
521 dbus_message_iter_next(&iter);
522 dbus_message_iter_recurse(&iter, &value);
524 if (g_str_equal(key, "Powered") == TRUE) {
527 dbus_message_iter_get_basic(&value, &val);
528 connman_device_set_powered(device, val);
529 } else if (g_str_equal(key, "Discovering") == TRUE) {
532 dbus_message_iter_get_basic(&value, &val);
533 connman_device_set_scanning(device, val);
534 } else if (g_str_equal(key, "Devices") == TRUE) {
535 check_networks(device, &value);
541 static gboolean device_removed(DBusConnection *connection,
542 DBusMessage *message, void *user_data)
544 const char *network_path, *identifier;
545 struct connman_network *network;
546 struct connman_device *device;
547 DBusMessageIter iter;
551 if (dbus_message_iter_init(message, &iter) == FALSE)
554 dbus_message_iter_get_basic(&iter, &network_path);
556 network = g_hash_table_lookup(bluetooth_networks, network_path);
560 device = connman_network_get_device(network);
564 identifier = connman_network_get_identifier(network);
566 g_hash_table_remove(bluetooth_networks, network_path);
568 connman_device_remove_network(device, identifier);
573 static gboolean device_changed(DBusConnection *connection,
574 DBusMessage *message, void *user_data)
576 const char *path = dbus_message_get_path(message);
577 DBusMessageIter iter, value;
580 DBG("path %s", path);
582 if (dbus_message_iter_init(message, &iter) == FALSE)
585 dbus_message_iter_get_basic(&iter, &key);
587 dbus_message_iter_next(&iter);
588 dbus_message_iter_recurse(&iter, &value);
592 if (g_str_equal(key, "UUIDs") == TRUE)
593 add_network(NULL, path);
598 static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
600 char *path = user_data;
601 struct connman_device *device;
603 DBusMessageIter networks;
604 const char *address = NULL, *name = NULL;
605 dbus_bool_t powered = FALSE, scanning = FALSE;
606 struct ether_addr addr;
609 DBG("path %s", path);
611 reply = dbus_pending_call_steal_reply(call);
616 extract_properties(reply, NULL, &address, &name, NULL,
617 &powered, &scanning, NULL, &networks);
622 if (g_strcmp0(address, "00:00:00:00:00:00") == 0)
625 device = g_hash_table_lookup(bluetooth_devices, path);
629 ether_aton_r(address, &addr);
631 snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
632 addr.ether_addr_octet[0],
633 addr.ether_addr_octet[1],
634 addr.ether_addr_octet[2],
635 addr.ether_addr_octet[3],
636 addr.ether_addr_octet[4],
637 addr.ether_addr_octet[5]);
639 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_BLUETOOTH);
643 connman_device_set_ident(device, ident);
645 connman_device_set_string(device, "Path", path);
647 if (connman_device_register(device) < 0) {
648 connman_device_unref(device);
652 g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
655 connman_device_set_string(device, "Address", address);
656 connman_device_set_string(device, "Name", name);
657 connman_device_set_string(device, "Path", path);
659 connman_device_set_powered(device, powered);
660 connman_device_set_scanning(device, scanning);
663 check_networks(device, &networks);
666 dbus_message_unref(reply);
668 dbus_pending_call_unref(call);
671 static void add_adapter(DBusConnection *connection, const char *path)
673 DBusMessage *message;
674 DBusPendingCall *call;
676 DBG("path %s", path);
678 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
679 BLUEZ_ADAPTER_INTERFACE, GET_PROPERTIES);
683 dbus_message_set_auto_start(message, FALSE);
685 if (dbus_connection_send_with_reply(connection, message,
686 &call, TIMEOUT) == FALSE) {
687 connman_error("Failed to get adapter properties for %s", path);
692 connman_error("D-Bus connection not available");
696 dbus_pending_call_set_notify(call, adapter_properties_reply,
697 g_strdup(path), g_free);
700 dbus_message_unref(message);
703 static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
708 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
710 add_adapter(connection, path);
714 static void remove_adapter(DBusConnection *connection, const char *path)
716 DBG("path %s", path);
718 g_hash_table_remove(bluetooth_devices, path);
721 static gboolean adapter_removed(DBusConnection *connection, DBusMessage *message,
726 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
728 remove_adapter(connection, path);
732 static void list_adapters_reply(DBusPendingCall *call, void *user_data)
741 reply = dbus_pending_call_steal_reply(call);
743 dbus_error_init(&error);
745 if (dbus_set_error_from_message(&error, reply) == TRUE) {
746 connman_error("%s", error.message);
747 dbus_error_free(&error);
751 if (dbus_message_get_args(reply, &error,
752 DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH,
753 &adapters, &num_adapters,
754 DBUS_TYPE_INVALID) == FALSE) {
755 if (dbus_error_is_set(&error) == TRUE) {
756 connman_error("%s", error.message);
757 dbus_error_free(&error);
759 connman_error("Wrong arguments for adapter list");
763 for (i = 0; i < num_adapters; i++)
764 add_adapter(connection, adapters[i]);
766 g_strfreev(adapters);
769 dbus_message_unref(reply);
771 dbus_pending_call_unref(call);
774 static void unregister_device(gpointer data)
776 struct connman_device *device = data;
780 connman_device_unregister(device);
781 connman_device_unref(device);
784 static void bluetooth_connect(DBusConnection *connection, void *user_data)
786 DBusMessage *message;
787 DBusPendingCall *call;
789 DBG("connection %p", connection);
791 bluetooth_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
792 g_free, unregister_device);
794 bluetooth_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
797 message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
798 BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
802 dbus_message_set_auto_start(message, FALSE);
804 if (dbus_connection_send_with_reply(connection, message,
805 &call, TIMEOUT) == FALSE) {
806 connman_error("Failed to get Bluetooth adapters");
811 connman_error("D-Bus connection not available");
815 dbus_pending_call_set_notify(call, list_adapters_reply, NULL, NULL);
818 dbus_message_unref(message);
821 static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
823 DBG("connection %p", connection);
825 if (bluetooth_devices == NULL)
828 g_hash_table_destroy(bluetooth_networks);
829 g_hash_table_destroy(bluetooth_devices);
830 bluetooth_devices = NULL;
833 static int bluetooth_probe(struct connman_device *device)
835 DBG("device %p", device);
840 static void bluetooth_remove(struct connman_device *device)
842 DBG("device %p", device);
845 static void powered_reply(DBusPendingCall *call, void *user_data)
852 reply = dbus_pending_call_steal_reply(call);
854 dbus_error_init(&error);
856 if (dbus_set_error_from_message(&error, reply) == TRUE) {
857 connman_error("%s", error.message);
858 dbus_error_free(&error);
859 dbus_message_unref(reply);
860 dbus_pending_call_unref(call);
864 dbus_message_unref(reply);
865 dbus_pending_call_unref(call);
867 add_adapter(connection, user_data);
870 static int change_powered(DBusConnection *connection, const char *path,
873 DBusMessage *message;
874 DBusMessageIter iter;
875 DBusPendingCall *call;
882 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
883 BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
887 dbus_message_set_auto_start(message, FALSE);
889 dbus_message_iter_init_append(message, &iter);
890 connman_dbus_property_append_basic(&iter, "Powered",
891 DBUS_TYPE_BOOLEAN, &powered);
893 if (dbus_connection_send_with_reply(connection, message,
894 &call, TIMEOUT) == FALSE) {
895 connman_error("Failed to change Powered property");
896 dbus_message_unref(message);
901 connman_error("D-Bus connection not available");
902 dbus_message_unref(message);
906 dbus_pending_call_set_notify(call, powered_reply,
907 g_strdup(path), g_free);
909 dbus_message_unref(message);
914 static int bluetooth_enable(struct connman_device *device)
916 const char *path = connman_device_get_string(device, "Path");
918 DBG("device %p", device);
920 return change_powered(connection, path, TRUE);
923 static int bluetooth_disable(struct connman_device *device)
925 const char *path = connman_device_get_string(device, "Path");
927 DBG("device %p", device);
929 return change_powered(connection, path, FALSE);
932 static struct connman_device_driver bluetooth_driver = {
934 .type = CONNMAN_DEVICE_TYPE_BLUETOOTH,
935 .probe = bluetooth_probe,
936 .remove = bluetooth_remove,
937 .enable = bluetooth_enable,
938 .disable = bluetooth_disable,
941 static int tech_probe(struct connman_technology *technology)
946 static void tech_remove(struct connman_technology *technology)
950 static void server_register_reply(DBusPendingCall *call, void *user_data)
957 reply = dbus_pending_call_steal_reply(call);
959 dbus_error_init(&error);
961 if (dbus_set_error_from_message(&error, reply) == TRUE) {
962 connman_error("%s", error.message);
963 dbus_error_free(&error);
964 dbus_message_unref(reply);
965 dbus_pending_call_unref(call);
969 dbus_message_unref(reply);
970 dbus_pending_call_unref(call);
972 connman_tethering_enabled();
975 static void server_unregister_reply(DBusPendingCall *call, void *user_data)
982 reply = dbus_pending_call_steal_reply(call);
984 dbus_error_init(&error);
986 if (dbus_set_error_from_message(&error, reply) == TRUE) {
987 connman_error("%s", error.message);
988 dbus_error_free(&error);
989 dbus_message_unref(reply);
990 dbus_pending_call_unref(call);
994 dbus_message_unref(reply);
995 dbus_pending_call_unref(call);
997 connman_tethering_disabled();
1001 static void server_register(const char *path, const char *uuid,
1002 const char *bridge, connman_bool_t enabled)
1004 DBusMessage *message;
1005 DBusPendingCall *call;
1008 DBG("path %s enabled %d", path, enabled);
1010 command = enabled ? REGISTER : UNREGISTER;
1012 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
1013 BLUEZ_NETWORK_SERVER, command);
1014 if (message == NULL)
1017 dbus_message_set_auto_start(message, FALSE);
1019 dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
1022 if (enabled == TRUE)
1023 dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
1026 if (dbus_connection_send_with_reply(connection, message,
1027 &call, TIMEOUT) == FALSE) {
1028 connman_error("Failed to enable PAN server");
1029 dbus_message_unref(message);
1034 connman_error("D-Bus connection not available");
1035 dbus_message_unref(message);
1039 if (enabled == TRUE)
1040 dbus_pending_call_set_notify(call, server_register_reply,
1043 dbus_pending_call_set_notify(call, server_unregister_reply,
1046 dbus_message_unref(message);
1049 static void enable_nap(gpointer key, gpointer value,
1052 struct connman_device *device = value;
1053 const char *bridge = user_data;
1058 path = connman_device_get_string(device, "Path");
1060 server_register(path, "nap", bridge, TRUE);
1063 static void disable_nap(gpointer key, gpointer value,
1066 struct connman_device *device = value;
1067 const char *bridge = user_data;
1072 path = connman_device_get_string(device, "Path");
1074 server_register(path, "nap", bridge, FALSE);
1077 static int tech_set_tethering(struct connman_technology *technology,
1078 const char *bridge, connman_bool_t enabled)
1080 char *bridge_name = g_strdup(bridge);
1082 DBG("bridge %s", bridge);
1084 if (bridge_name == NULL)
1088 g_hash_table_foreach(bluetooth_devices,
1089 enable_nap, bridge_name);
1091 g_hash_table_foreach(bluetooth_devices,
1092 disable_nap, bridge_name);
1094 g_free(bridge_name);
1099 static struct connman_technology_driver tech_driver = {
1100 .name = "bluetooth",
1101 .type = CONNMAN_SERVICE_TYPE_BLUETOOTH,
1102 .probe = tech_probe,
1103 .remove = tech_remove,
1104 .set_tethering = tech_set_tethering,
1108 static guint added_watch;
1109 static guint removed_watch;
1110 static guint adapter_watch;
1111 static guint device_watch;
1112 static guint device_removed_watch;
1113 static guint network_watch;
1115 static int bluetooth_init(void)
1119 connection = connman_dbus_get_connection();
1120 if (connection == NULL)
1123 watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
1124 bluetooth_connect, bluetooth_disconnect, NULL, NULL);
1126 added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1127 BLUEZ_MANAGER_INTERFACE,
1128 ADAPTER_ADDED, adapter_added,
1131 removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1132 BLUEZ_MANAGER_INTERFACE,
1133 ADAPTER_REMOVED, adapter_removed,
1136 adapter_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1137 BLUEZ_ADAPTER_INTERFACE,
1138 PROPERTY_CHANGED, adapter_changed,
1141 device_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1142 BLUEZ_ADAPTER_INTERFACE,
1143 DEVICE_REMOVED, device_removed,
1146 device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1147 BLUEZ_DEVICE_INTERFACE,
1148 PROPERTY_CHANGED, device_changed,
1151 network_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1152 BLUEZ_NETWORK_INTERFACE,
1153 PROPERTY_CHANGED, network_changed,
1156 if (watch == 0 || added_watch == 0 || removed_watch == 0
1157 || adapter_watch == 0 || network_watch == 0
1158 || device_watch == 0
1159 || device_removed_watch == 0) {
1164 err = connman_network_driver_register(&pan_driver);
1168 err = connman_device_driver_register(&bluetooth_driver);
1170 connman_network_driver_unregister(&pan_driver);
1174 err = connman_technology_driver_register(&tech_driver);
1176 connman_device_driver_unregister(&bluetooth_driver);
1177 connman_network_driver_unregister(&pan_driver);
1184 g_dbus_remove_watch(connection, watch);
1185 g_dbus_remove_watch(connection, added_watch);
1186 g_dbus_remove_watch(connection, removed_watch);
1187 g_dbus_remove_watch(connection, adapter_watch);
1188 g_dbus_remove_watch(connection, device_removed_watch);
1189 g_dbus_remove_watch(connection, device_watch);
1190 g_dbus_remove_watch(connection, network_watch);
1192 dbus_connection_unref(connection);
1197 static void bluetooth_exit(void)
1199 g_dbus_remove_watch(connection, watch);
1200 g_dbus_remove_watch(connection, added_watch);
1201 g_dbus_remove_watch(connection, removed_watch);
1202 g_dbus_remove_watch(connection, adapter_watch);
1203 g_dbus_remove_watch(connection, device_removed_watch);
1204 g_dbus_remove_watch(connection, device_watch);
1205 g_dbus_remove_watch(connection, network_watch);
1207 bluetooth_disconnect(connection, NULL);
1209 connman_technology_driver_unregister(&tech_driver);
1211 connman_device_driver_unregister(&bluetooth_driver);
1212 connman_network_driver_unregister(&pan_driver);
1214 dbus_connection_unref(connection);
1217 CONNMAN_PLUGIN_DEFINE(bluetooth, "Bluetooth technology plugin", VERSION,
1218 CONNMAN_PLUGIN_PRIORITY_DEFAULT, bluetooth_init, bluetooth_exit)