aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2012-05-01 15:43:41 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-21 18:00:18 -0300
commitb6ec3216d05b7698ff93c5e20a31d9521bc16d63 (patch)
tree25a7d4861e7bc8a28a2dff1e5cf3867946cf2dab
parent822a7d18e09cfdd9327c410b6e49accb54645298 (diff)
downloadbluez-b6ec3216d05b7698ff93c5e20a31d9521bc16d63.tar.gz
bluez-b6ec3216d05b7698ff93c5e20a31d9521bc16d63.tar.xz
bluez-b6ec3216d05b7698ff93c5e20a31d9521bc16d63.zip
scan: Add ATTIO callbacks registration
This patch add the functions to manage ATTIO callbacks. The current registration mechanism is not suitable for this service since it needs to be passive. Scan Parameters should not actively request connections, it needs to be notified if the connections has been established requested by other services.
-rw-r--r--Makefile.am3
-rw-r--r--scanparam/manager.c26
-rw-r--r--scanparam/scan.c106
-rw-r--r--scanparam/scan.h26
4 files changed, 159 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index c95220eb..1e7e855c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -240,7 +240,8 @@ builtin_sources += thermometer/main.c \
deviceinfo/main.c \
deviceinfo/manager.h deviceinfo/manager.c \
deviceinfo/deviceinfo.h deviceinfo/deviceinfo.c \
- scanparam/main.c scanparam/manager.h scanparam/manager.c
+ scanparam/main.c scanparam/manager.h scanparam/manager.c \
+ scanparam/scan.h scanparam/scan.c
endif
diff --git a/scanparam/manager.c b/scanparam/manager.c
index 009cb5d3..5508c2bf 100644
--- a/scanparam/manager.c
+++ b/scanparam/manager.c
@@ -26,24 +26,48 @@
#include <config.h>
#endif
+#include <errno.h>
#include <glib.h>
+#include <bluetooth/uuid.h>
#include "log.h"
#include "adapter.h"
#include "device.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
#include "manager.h"
+#include "scan.h"
#define SCAN_PARAMETERS_UUID "00001813-0000-1000-8000-00805f9b34fb"
+static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct gatt_primary *prim = a;
+ const char *uuid = b;
+
+ return g_strcmp0(prim->uuid, uuid);
+}
+
static int scan_param_probe(struct btd_device *device, GSList *uuids)
{
+ GSList *primaries, *l;
+
DBG("Probing Scan Parameters");
- return 0;
+ primaries = btd_device_get_primaries(device);
+
+ l = g_slist_find_custom(primaries, SCAN_PARAMETERS_UUID,
+ primary_uuid_cmp);
+ if (!l)
+ return -EINVAL;
+
+ return scan_register(device, l->data);
}
static void scan_param_remove(struct btd_device *device)
{
+ scan_unregister(device);
}
static struct btd_device_driver scan_driver = {
diff --git a/scanparam/scan.c b/scanparam/scan.c
new file mode 100644
index 00000000..3071e723
--- /dev/null
+++ b/scanparam/scan.c
@@ -0,0 +1,106 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Instituto Nokia de Tecnologia - INdT
+ * Copyright (C) 2012 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/uuid.h>
+
+#include "adapter.h"
+#include "device.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
+#include "attio.h"
+#include "scan.h"
+
+struct scan {
+ struct btd_device *device;
+ GAttrib *attrib;
+ guint attioid;
+};
+
+GSList *servers = NULL;
+
+static gint scan_device_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct scan *scan = a;
+ const struct btd_device *device = b;
+
+ if (device == scan->device)
+ return 0;
+
+ return -1;
+}
+
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+ struct scan *scan = user_data;
+
+ scan->attrib = g_attrib_ref(attrib);
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+ struct scan *scan = user_data;
+
+ g_attrib_unref(scan->attrib);
+ scan->attrib = NULL;
+}
+
+int scan_register(struct btd_device *device, struct gatt_primary *prim)
+{
+ struct scan *scan;
+
+ scan = g_new0(struct scan, 1);
+ scan->device = btd_device_ref(device);
+ scan->attioid = btd_device_add_attio_callback(device,
+ attio_connected_cb,
+ attio_disconnected_cb,
+ scan);
+
+ servers = g_slist_prepend(servers, scan);
+
+ return 0;
+}
+
+void scan_unregister(struct btd_device *device)
+{
+ struct scan *scan;
+ GSList *l;
+
+ l = g_slist_find_custom(servers, device, scan_device_cmp);
+ if (l == NULL)
+ return;
+
+ scan = l->data;
+ servers = g_slist_remove(servers, scan);
+
+ btd_device_remove_attio_callback(scan->device, scan->attioid);
+ btd_device_unref(scan->device);
+ g_attrib_unref(scan->attrib);
+ g_free(scan);
+}
diff --git a/scanparam/scan.h b/scanparam/scan.h
new file mode 100644
index 00000000..b75264f2
--- /dev/null
+++ b/scanparam/scan.h
@@ -0,0 +1,26 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Instituto Nokia de Tecnologia - INdT
+ * Copyright (C) 2012 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+int scan_register(struct btd_device *device, struct gatt_primary *prim);
+void scan_unregister(struct btd_device *device);