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);
105 if (dbus_message_get_args(reply, &error,
106 DBUS_TYPE_STRING, &interface,
107 DBUS_TYPE_INVALID) == FALSE) {
108 if (dbus_error_is_set(&error) == TRUE) {
109 connman_error("%s", error.message);
110 dbus_error_free(&error);
112 connman_error("Wrong arguments for connect");
116 if (interface == NULL)
119 DBG("interface %s", interface);
121 index = connman_inet_ifindex(interface);
123 connman_network_set_index(network, index);
125 connman_network_set_connected(network, TRUE);
128 dbus_message_unref(reply);
130 dbus_pending_call_unref(call);
133 static int pan_connect(struct connman_network *network)
135 const char *path = connman_network_get_string(network, "Path");
136 const char *uuid = "nap";
137 DBusMessage *message;
138 DBusPendingCall *call;
140 DBG("network %p", network);
145 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
146 BLUEZ_NETWORK_INTERFACE, CONNECT);
150 dbus_message_set_auto_start(message, FALSE);
152 dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
155 if (dbus_connection_send_with_reply(connection, message,
156 &call, TIMEOUT * 10) == FALSE) {
157 connman_error("Failed to connect service");
158 dbus_message_unref(message);
163 connman_error("D-Bus connection not available");
164 dbus_message_unref(message);
168 dbus_pending_call_set_notify(call, connect_reply, network, NULL);
170 dbus_message_unref(message);
175 static void disconnect_reply(DBusPendingCall *call, void *user_data)
177 struct connman_network *network = user_data;
181 DBG("network %p", network);
183 reply = dbus_pending_call_steal_reply(call);
185 dbus_error_init(&error);
187 if (dbus_set_error_from_message(&error, reply) == TRUE) {
188 connman_error("%s", error.message);
189 dbus_error_free(&error);
193 if (dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) == FALSE) {
194 if (dbus_error_is_set(&error) == TRUE) {
195 connman_error("%s", error.message);
196 dbus_error_free(&error);
198 connman_error("Wrong arguments for disconnect");
202 connman_network_set_connected(network, FALSE);
205 dbus_message_unref(reply);
207 dbus_pending_call_unref(call);
209 connman_network_unref(network);
212 static int pan_disconnect(struct connman_network *network)
214 const char *path = connman_network_get_string(network, "Path");
215 DBusMessage *message;
216 DBusPendingCall *call;
218 DBG("network %p", network);
223 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
224 BLUEZ_NETWORK_INTERFACE, DISCONNECT);
228 dbus_message_set_auto_start(message, FALSE);
230 dbus_message_append_args(message, DBUS_TYPE_INVALID);
232 if (dbus_connection_send_with_reply(connection, message,
233 &call, TIMEOUT) == FALSE) {
234 connman_error("Failed to disconnect service");
235 dbus_message_unref(message);
240 connman_error("D-Bus connection not available");
241 dbus_message_unref(message);
245 connman_network_ref(network);
247 connman_network_set_associating(network, FALSE);
249 dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
251 dbus_message_unref(message);
256 static struct connman_network_driver pan_driver = {
257 .name = "bluetooth-pan",
258 .type = CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
260 .remove = pan_remove,
261 .connect = pan_connect,
262 .disconnect = pan_disconnect,
265 static gboolean network_changed(DBusConnection *connection,
266 DBusMessage *message, void *user_data)
268 const char *path = dbus_message_get_path(message);
269 struct connman_network *network;
270 DBusMessageIter iter, value;
273 DBG("path %s", path);
275 network = g_hash_table_lookup(bluetooth_networks, path);
279 if (dbus_message_iter_init(message, &iter) == FALSE)
282 dbus_message_iter_get_basic(&iter, &key);
284 dbus_message_iter_next(&iter);
285 dbus_message_iter_recurse(&iter, &value);
287 if (g_str_equal(key, "Connected") == TRUE) {
288 dbus_bool_t connected;
290 dbus_message_iter_get_basic(&value, &connected);
292 if (connected == TRUE)
295 connman_network_set_associating(network, FALSE);
296 connman_network_set_connected(network, FALSE);
302 static void extract_properties(DBusMessage *reply, const char **parent,
303 const char **address,
306 dbus_bool_t *powered,
307 dbus_bool_t *scanning,
308 DBusMessageIter *uuids,
309 DBusMessageIter *networks)
311 DBusMessageIter array, dict;
313 if (dbus_message_iter_init(reply, &array) == FALSE)
316 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
319 dbus_message_iter_recurse(&array, &dict);
321 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
322 DBusMessageIter entry, value;
325 dbus_message_iter_recurse(&dict, &entry);
326 dbus_message_iter_get_basic(&entry, &key);
328 dbus_message_iter_next(&entry);
329 dbus_message_iter_recurse(&entry, &value);
331 if (g_str_equal(key, "Adapter") == TRUE) {
333 dbus_message_iter_get_basic(&value, parent);
334 } else if (g_str_equal(key, "Address") == TRUE) {
336 dbus_message_iter_get_basic(&value, address);
337 } else if (g_str_equal(key, "Name") == TRUE) {
339 dbus_message_iter_get_basic(&value, name);
340 } else if (g_str_equal(key, "Alias") == TRUE) {
342 dbus_message_iter_get_basic(&value, alias);
343 } else if (g_str_equal(key, "Powered") == TRUE) {
345 dbus_message_iter_get_basic(&value, powered);
346 } else if (g_str_equal(key, "Discovering") == TRUE) {
347 if (scanning != NULL)
348 dbus_message_iter_get_basic(&value, scanning);
349 } else if (g_str_equal(key, "Devices") == TRUE) {
350 if (networks != NULL)
351 memcpy(networks, &value, sizeof(value));
352 } else if (g_str_equal(key, "UUIDs") == TRUE) {
354 memcpy(uuids, &value, sizeof(value));
357 dbus_message_iter_next(&dict);
361 static dbus_bool_t has_pan(DBusMessageIter *array)
363 DBusMessageIter value;
365 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
368 dbus_message_iter_recurse(array, &value);
370 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
373 dbus_message_iter_get_basic(&value, &uuid);
375 if (g_strcmp0(uuid, UUID_NAP) == 0)
378 dbus_message_iter_next(&value);
384 static void network_properties_reply(DBusPendingCall *call, void *user_data)
386 char *path = user_data;
387 struct connman_device *device;
388 struct connman_network *network;
390 DBusMessageIter uuids;
391 const char *parent = NULL, *address = NULL, *name = NULL;
392 struct ether_addr addr;
395 reply = dbus_pending_call_steal_reply(call);
397 extract_properties(reply, &parent, &address, NULL, &name,
398 NULL, NULL, &uuids, NULL);
403 device = g_hash_table_lookup(bluetooth_devices, parent);
410 ether_aton_r(address, &addr);
412 snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
413 addr.ether_addr_octet[0],
414 addr.ether_addr_octet[1],
415 addr.ether_addr_octet[2],
416 addr.ether_addr_octet[3],
417 addr.ether_addr_octet[4],
418 addr.ether_addr_octet[5]);
420 if (has_pan(&uuids) == FALSE)
423 network = connman_device_get_network(device, ident);
427 network = connman_network_create(ident,
428 CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
432 connman_network_set_string(network, "Path", path);
434 connman_network_set_name(network, name);
436 connman_device_add_network(device, network);
438 connman_network_set_group(network, ident);
440 g_hash_table_insert(bluetooth_networks, g_strdup(path), network);
443 dbus_message_unref(reply);
445 dbus_pending_call_unref(call);
448 static void add_network(struct connman_device *device, const char *path)
450 DBusMessage *message;
451 DBusPendingCall *call;
453 DBG("path %s", path);
455 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
456 BLUEZ_DEVICE_INTERFACE, GET_PROPERTIES);
460 dbus_message_set_auto_start(message, FALSE);
462 if (dbus_connection_send_with_reply(connection, message,
463 &call, TIMEOUT) == FALSE) {
464 connman_error("Failed to get network properties for %s", path);
469 connman_error("D-Bus connection not available");
473 dbus_pending_call_set_notify(call, network_properties_reply,
474 g_strdup(path), g_free);
477 dbus_message_unref(message);
480 static void check_networks(struct connman_device *device,
481 DBusMessageIter *array)
483 DBusMessageIter value;
485 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
488 dbus_message_iter_recurse(array, &value);
490 while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) {
493 dbus_message_iter_get_basic(&value, &path);
495 add_network(device, path);
497 dbus_message_iter_next(&value);
501 static gboolean adapter_changed(DBusConnection *connection,
502 DBusMessage *message, void *user_data)
504 const char *path = dbus_message_get_path(message);
505 struct connman_device *device;
506 DBusMessageIter iter, value;
509 DBG("path %s", path);
511 device = g_hash_table_lookup(bluetooth_devices, path);
515 if (dbus_message_iter_init(message, &iter) == FALSE)
518 dbus_message_iter_get_basic(&iter, &key);
520 dbus_message_iter_next(&iter);
521 dbus_message_iter_recurse(&iter, &value);
523 if (g_str_equal(key, "Powered") == TRUE) {
526 dbus_message_iter_get_basic(&value, &val);
527 connman_device_set_powered(device, val);
528 } else if (g_str_equal(key, "Discovering") == TRUE) {
531 dbus_message_iter_get_basic(&value, &val);
532 connman_device_set_scanning(device, val);
533 } else if (g_str_equal(key, "Devices") == TRUE) {
534 check_networks(device, &value);
540 static gboolean device_removed(DBusConnection *connection,
541 DBusMessage *message, void *user_data)
543 const char *network_path, *identifier;
544 struct connman_network *network;
545 struct connman_device *device;
546 DBusMessageIter iter;
550 if (dbus_message_iter_init(message, &iter) == FALSE)
553 dbus_message_iter_get_basic(&iter, &network_path);
555 network = g_hash_table_lookup(bluetooth_networks, network_path);
559 device = connman_network_get_device(network);
563 identifier = connman_network_get_identifier(network);
565 g_hash_table_remove(bluetooth_networks, network_path);
567 connman_device_remove_network(device, identifier);
572 static gboolean device_changed(DBusConnection *connection,
573 DBusMessage *message, void *user_data)
575 const char *path = dbus_message_get_path(message);
576 DBusMessageIter iter, value;
579 DBG("path %s", path);
581 if (dbus_message_iter_init(message, &iter) == FALSE)
584 dbus_message_iter_get_basic(&iter, &key);
586 dbus_message_iter_next(&iter);
587 dbus_message_iter_recurse(&iter, &value);
591 if (g_str_equal(key, "UUIDs") == TRUE)
592 add_network(NULL, path);
597 static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
599 char *path = user_data;
600 struct connman_device *device;
602 DBusMessageIter networks;
603 const char *address = NULL, *name = NULL;
604 dbus_bool_t powered = FALSE, scanning = FALSE;
605 struct ether_addr addr;
608 DBG("path %s", path);
610 reply = dbus_pending_call_steal_reply(call);
615 extract_properties(reply, NULL, &address, &name, NULL,
616 &powered, &scanning, NULL, &networks);
621 if (g_strcmp0(address, "00:00:00:00:00:00") == 0)
624 device = g_hash_table_lookup(bluetooth_devices, path);
628 ether_aton_r(address, &addr);
630 snprintf(ident, 13, "%02x%02x%02x%02x%02x%02x",
631 addr.ether_addr_octet[0],
632 addr.ether_addr_octet[1],
633 addr.ether_addr_octet[2],
634 addr.ether_addr_octet[3],
635 addr.ether_addr_octet[4],
636 addr.ether_addr_octet[5]);
638 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_BLUETOOTH);
642 connman_device_set_ident(device, ident);
644 connman_device_set_string(device, "Path", path);
646 if (connman_device_register(device) < 0) {
647 connman_device_unref(device);
651 g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
654 connman_device_set_string(device, "Address", address);
655 connman_device_set_string(device, "Name", name);
656 connman_device_set_string(device, "Path", path);
658 connman_device_set_powered(device, powered);
659 connman_device_set_scanning(device, scanning);
662 check_networks(device, &networks);
665 dbus_message_unref(reply);
667 dbus_pending_call_unref(call);
670 static void add_adapter(DBusConnection *connection, const char *path)
672 DBusMessage *message;
673 DBusPendingCall *call;
675 DBG("path %s", path);
677 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
678 BLUEZ_ADAPTER_INTERFACE, GET_PROPERTIES);
682 dbus_message_set_auto_start(message, FALSE);
684 if (dbus_connection_send_with_reply(connection, message,
685 &call, TIMEOUT) == FALSE) {
686 connman_error("Failed to get adapter properties for %s", path);
691 connman_error("D-Bus connection not available");
695 dbus_pending_call_set_notify(call, adapter_properties_reply,
696 g_strdup(path), g_free);
699 dbus_message_unref(message);
702 static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
707 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
709 add_adapter(connection, path);
713 static void remove_adapter(DBusConnection *connection, const char *path)
715 DBG("path %s", path);
717 g_hash_table_remove(bluetooth_devices, path);
720 static gboolean adapter_removed(DBusConnection *connection, DBusMessage *message,
725 dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
727 remove_adapter(connection, path);
731 static void list_adapters_reply(DBusPendingCall *call, void *user_data)
740 reply = dbus_pending_call_steal_reply(call);
742 dbus_error_init(&error);
744 if (dbus_set_error_from_message(&error, reply) == TRUE) {
745 connman_error("%s", error.message);
746 dbus_error_free(&error);
750 if (dbus_message_get_args(reply, &error,
751 DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH,
752 &adapters, &num_adapters,
753 DBUS_TYPE_INVALID) == FALSE) {
754 if (dbus_error_is_set(&error) == TRUE) {
755 connman_error("%s", error.message);
756 dbus_error_free(&error);
758 connman_error("Wrong arguments for adapter list");
762 for (i = 0; i < num_adapters; i++)
763 add_adapter(connection, adapters[i]);
765 g_strfreev(adapters);
768 dbus_message_unref(reply);
770 dbus_pending_call_unref(call);
773 static void unregister_device(gpointer data)
775 struct connman_device *device = data;
779 connman_device_unregister(device);
780 connman_device_unref(device);
783 static void bluetooth_connect(DBusConnection *connection, void *user_data)
785 DBusMessage *message;
786 DBusPendingCall *call;
788 DBG("connection %p", connection);
790 bluetooth_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
791 g_free, unregister_device);
793 bluetooth_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
796 message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
797 BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
801 dbus_message_set_auto_start(message, FALSE);
803 if (dbus_connection_send_with_reply(connection, message,
804 &call, TIMEOUT) == FALSE) {
805 connman_error("Failed to get Bluetooth adapters");
810 connman_error("D-Bus connection not available");
814 dbus_pending_call_set_notify(call, list_adapters_reply, NULL, NULL);
817 dbus_message_unref(message);
820 static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
822 DBG("connection %p", connection);
824 if (bluetooth_devices == NULL)
827 g_hash_table_destroy(bluetooth_networks);
828 g_hash_table_destroy(bluetooth_devices);
829 bluetooth_devices = NULL;
832 static int bluetooth_probe(struct connman_device *device)
834 DBG("device %p", device);
839 static void bluetooth_remove(struct connman_device *device)
841 DBG("device %p", device);
844 static void powered_reply(DBusPendingCall *call, void *user_data)
851 reply = dbus_pending_call_steal_reply(call);
853 dbus_error_init(&error);
855 if (dbus_set_error_from_message(&error, reply) == TRUE) {
856 connman_error("%s", error.message);
857 dbus_error_free(&error);
858 dbus_message_unref(reply);
859 dbus_pending_call_unref(call);
863 dbus_message_unref(reply);
864 dbus_pending_call_unref(call);
866 add_adapter(connection, user_data);
869 static int change_powered(DBusConnection *connection, const char *path,
872 DBusMessage *message;
873 DBusMessageIter iter;
874 DBusPendingCall *call;
881 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
882 BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
886 dbus_message_set_auto_start(message, FALSE);
888 dbus_message_iter_init_append(message, &iter);
889 connman_dbus_property_append_basic(&iter, "Powered",
890 DBUS_TYPE_BOOLEAN, &powered);
892 if (dbus_connection_send_with_reply(connection, message,
893 &call, TIMEOUT) == FALSE) {
894 connman_error("Failed to change Powered property");
895 dbus_message_unref(message);
900 connman_error("D-Bus connection not available");
901 dbus_message_unref(message);
905 dbus_pending_call_set_notify(call, powered_reply,
906 g_strdup(path), g_free);
908 dbus_message_unref(message);
913 static int bluetooth_enable(struct connman_device *device)
915 const char *path = connman_device_get_string(device, "Path");
917 DBG("device %p", device);
919 return change_powered(connection, path, TRUE);
922 static int bluetooth_disable(struct connman_device *device)
924 const char *path = connman_device_get_string(device, "Path");
926 DBG("device %p", device);
928 return change_powered(connection, path, FALSE);
931 static struct connman_device_driver bluetooth_driver = {
933 .type = CONNMAN_DEVICE_TYPE_BLUETOOTH,
934 .probe = bluetooth_probe,
935 .remove = bluetooth_remove,
936 .enable = bluetooth_enable,
937 .disable = bluetooth_disable,
940 static int tech_probe(struct connman_technology *technology)
945 static void tech_remove(struct connman_technology *technology)
949 static void server_register_reply(DBusPendingCall *call, void *user_data)
951 struct connman_technology *technology = 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_technology_tethering_notify(technology, TRUE);
975 static void server_unregister_reply(DBusPendingCall *call, void *user_data)
977 struct connman_technology *technology = user_data;
983 reply = dbus_pending_call_steal_reply(call);
985 dbus_error_init(&error);
987 if (dbus_set_error_from_message(&error, reply) == TRUE) {
988 connman_error("%s", error.message);
989 dbus_error_free(&error);
990 dbus_message_unref(reply);
991 dbus_pending_call_unref(call);
995 dbus_message_unref(reply);
996 dbus_pending_call_unref(call);
998 connman_technology_tethering_notify(technology, FALSE);
1002 static void server_register(const char *path, const char *uuid,
1003 struct connman_technology *technology,
1004 const char *bridge, connman_bool_t enabled)
1006 DBusMessage *message;
1007 DBusPendingCall *call;
1010 DBG("path %s enabled %d", path, enabled);
1012 command = enabled ? REGISTER : UNREGISTER;
1014 message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
1015 BLUEZ_NETWORK_SERVER, command);
1016 if (message == NULL)
1019 dbus_message_set_auto_start(message, FALSE);
1021 dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
1024 if (enabled == TRUE)
1025 dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
1028 if (dbus_connection_send_with_reply(connection, message,
1029 &call, TIMEOUT) == FALSE) {
1030 connman_error("Failed to enable PAN server");
1031 dbus_message_unref(message);
1036 connman_error("D-Bus connection not available");
1037 dbus_message_unref(message);
1041 if (enabled == TRUE)
1042 dbus_pending_call_set_notify(call, server_register_reply,
1045 dbus_pending_call_set_notify(call, server_unregister_reply,
1048 dbus_message_unref(message);
1051 struct tethering_info {
1052 struct connman_technology *technology;
1056 static void enable_nap(gpointer key, gpointer value, gpointer user_data)
1058 struct tethering_info *info = user_data;
1059 struct connman_device *device = value;
1064 path = connman_device_get_string(device, "Path");
1066 server_register(path, "nap", info->technology, info->bridge, TRUE);
1069 static void disable_nap(gpointer key, gpointer value, gpointer user_data)
1071 struct tethering_info *info = user_data;
1072 struct connman_device *device = value;
1077 path = connman_device_get_string(device, "Path");
1079 server_register(path, "nap", info->technology, info->bridge, FALSE);
1082 static int tech_set_tethering(struct connman_technology *technology,
1083 const char *bridge, connman_bool_t enabled)
1085 struct tethering_info info = {
1086 .technology = technology,
1090 DBG("bridge %s", bridge);
1093 g_hash_table_foreach(bluetooth_devices, enable_nap, &info);
1095 g_hash_table_foreach(bluetooth_devices, disable_nap, &info);
1100 static struct connman_technology_driver tech_driver = {
1101 .name = "bluetooth",
1102 .type = CONNMAN_SERVICE_TYPE_BLUETOOTH,
1103 .probe = tech_probe,
1104 .remove = tech_remove,
1105 .set_tethering = tech_set_tethering,
1109 static guint added_watch;
1110 static guint removed_watch;
1111 static guint adapter_watch;
1112 static guint device_watch;
1113 static guint device_removed_watch;
1114 static guint network_watch;
1116 static int bluetooth_init(void)
1120 connection = connman_dbus_get_connection();
1121 if (connection == NULL)
1124 watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
1125 bluetooth_connect, bluetooth_disconnect, NULL, NULL);
1127 added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1128 BLUEZ_MANAGER_INTERFACE,
1129 ADAPTER_ADDED, adapter_added,
1132 removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1133 BLUEZ_MANAGER_INTERFACE,
1134 ADAPTER_REMOVED, adapter_removed,
1137 adapter_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1138 BLUEZ_ADAPTER_INTERFACE,
1139 PROPERTY_CHANGED, adapter_changed,
1142 device_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1143 BLUEZ_ADAPTER_INTERFACE,
1144 DEVICE_REMOVED, device_removed,
1147 device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1148 BLUEZ_DEVICE_INTERFACE,
1149 PROPERTY_CHANGED, device_changed,
1152 network_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1153 BLUEZ_NETWORK_INTERFACE,
1154 PROPERTY_CHANGED, network_changed,
1157 if (watch == 0 || added_watch == 0 || removed_watch == 0
1158 || adapter_watch == 0 || network_watch == 0
1159 || device_watch == 0
1160 || device_removed_watch == 0) {
1165 err = connman_network_driver_register(&pan_driver);
1169 err = connman_device_driver_register(&bluetooth_driver);
1171 connman_network_driver_unregister(&pan_driver);
1175 err = connman_technology_driver_register(&tech_driver);
1177 connman_device_driver_unregister(&bluetooth_driver);
1178 connman_network_driver_unregister(&pan_driver);
1185 g_dbus_remove_watch(connection, watch);
1186 g_dbus_remove_watch(connection, added_watch);
1187 g_dbus_remove_watch(connection, removed_watch);
1188 g_dbus_remove_watch(connection, adapter_watch);
1189 g_dbus_remove_watch(connection, device_removed_watch);
1190 g_dbus_remove_watch(connection, device_watch);
1191 g_dbus_remove_watch(connection, network_watch);
1193 dbus_connection_unref(connection);
1198 static void bluetooth_exit(void)
1200 g_dbus_remove_watch(connection, watch);
1201 g_dbus_remove_watch(connection, added_watch);
1202 g_dbus_remove_watch(connection, removed_watch);
1203 g_dbus_remove_watch(connection, adapter_watch);
1204 g_dbus_remove_watch(connection, device_removed_watch);
1205 g_dbus_remove_watch(connection, device_watch);
1206 g_dbus_remove_watch(connection, network_watch);
1208 bluetooth_disconnect(connection, NULL);
1210 connman_technology_driver_unregister(&tech_driver);
1212 connman_device_driver_unregister(&bluetooth_driver);
1213 connman_network_driver_unregister(&pan_driver);
1215 dbus_connection_unref(connection);
1218 CONNMAN_PLUGIN_DEFINE(bluetooth, "Bluetooth technology plugin", VERSION,
1219 CONNMAN_PLUGIN_PRIORITY_DEFAULT, bluetooth_init, bluetooth_exit)