Diff between 1342e68c296ffa0a78f273ea30f59fc59ef310d2 and 02dd29d72ea220143742f59c16946df3e0c85391

Changed Files

File Additions Deletions Status
Makefile.am +2 -1 modified
profiles/scanparam/manager.c +25 -1 modified
profiles/scanparam/scan.c +105 -0 added
profiles/scanparam/scan.h +26 -0 added

Full Patch

diff --git a/Makefile.am b/Makefile.am
index 6bb0aa1..e3f707b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -244,7 +244,8 @@ builtin_sources += profiles/thermometer/main.c \
 			profiles/gatt/gas.c \
 			profiles/scanparam/main.c \
 			profiles/scanparam/manager.h \
-			profiles/scanparam/manager.c
+			profiles/scanparam/manager.c \
+			profiles/scanparam/scan.h profiles/scanparam/scan.c
 endif
 
 builtin_modules += formfactor
diff --git a/profiles/scanparam/manager.c b/profiles/scanparam/manager.c
index c1ac0bb..24d1e78 100644
--- a/profiles/scanparam/manager.c
+++ b/profiles/scanparam/manager.c
@@ -27,26 +27,50 @@
 #endif
 
 #include <stdbool.h>
+#include <errno.h>
 #include <glib.h>
+#include <bluetooth/uuid.h>
 
 #include "log.h"
 #include "adapter.h"
 #include "device.h"
 #include "profile.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_profile *p, 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_profile *p, struct btd_device *device)
 {
+	scan_unregister(device);
 }
 
 static struct btd_profile scan_profile = {
diff --git a/profiles/scanparam/scan.c b/profiles/scanparam/scan.c
new file mode 100644
index 0000000..c6aaf97
--- /dev/null
+++ b/profiles/scanparam/scan.c
@@ -0,0 +1,105 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012  Nordic Semiconductor Inc.
+ *  Copyright (C) 2012  Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ *  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 <stdbool.h>
+
+#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;
+
+	return (device == scan->device ? 0 : -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/profiles/scanparam/scan.h b/profiles/scanparam/scan.h
new file mode 100644
index 0000000..93f7edd
--- /dev/null
+++ b/profiles/scanparam/scan.h
@@ -0,0 +1,26 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012  Nordic Semiconductor Inc.
+ *  Copyright (C) 2012  Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ *  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);