3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011 Nokia Corporation
6 * Copyright (C) 2011 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <bluetooth/uuid.h>
42 static DBusConnection *connection = NULL;
44 static struct enabled enabled = {
50 static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
52 const struct gatt_primary *prim = a;
55 return g_strcmp0(prim->uuid, uuid);
58 static int attio_device_probe(struct btd_device *device, GSList *uuids)
60 struct gatt_primary *linkloss, *txpower, *immediate;
61 GSList *l, *primaries;
63 primaries = btd_device_get_primaries(device);
65 l = g_slist_find_custom(primaries, IMMEDIATE_ALERT_UUID,
67 immediate = (l ? l->data : NULL);
69 l = g_slist_find_custom(primaries, TX_POWER_UUID, primary_uuid_cmp);
70 txpower = (l ? l->data : NULL);
72 l = g_slist_find_custom(primaries, LINK_LOSS_UUID, primary_uuid_cmp);
73 linkloss = (l ? l->data : NULL);
75 return monitor_register(connection, device, linkloss, txpower,
79 static void attio_device_remove(struct btd_device *device)
81 monitor_unregister(connection, device);
84 static struct btd_device_driver monitor_driver = {
85 .name = "Proximity GATT Monitor Driver",
86 .uuids = BTD_UUIDS(IMMEDIATE_ALERT_UUID, LINK_LOSS_UUID, TX_POWER_UUID),
87 .probe = attio_device_probe,
88 .remove = attio_device_remove,
91 static struct btd_adapter_driver reporter_server_driver = {
92 .name = "Proximity GATT Reporter Driver",
93 .probe = reporter_init,
94 .remove = reporter_exit,
97 static void load_config_file(GKeyFile *config)
105 list = g_key_file_get_string_list(config, "General", "Disable",
107 for (i = 0; list && list[i] != NULL; i++) {
108 if (g_str_equal(list[i], "FindMe"))
109 enabled.findme = FALSE;
110 else if (g_str_equal(list[i], "LinkLoss"))
111 enabled.linkloss = FALSE;
112 else if (g_str_equal(list[i], "PathLoss"))
113 enabled.pathloss = FALSE;
119 int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
123 load_config_file(config);
125 connection = dbus_connection_ref(conn);
127 ret = btd_register_device_driver(&monitor_driver);
131 ret = btd_register_adapter_driver(&reporter_server_driver);
138 btd_unregister_device_driver(&monitor_driver);
141 dbus_connection_unref(connection);
145 void proximity_manager_exit(void)
147 btd_unregister_device_driver(&monitor_driver);
148 btd_unregister_adapter_driver(&reporter_server_driver);
149 dbus_connection_unref(connection);