aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2012-05-02 11:42:27 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-21 18:00:18 -0300
commit046bedecc1bb15c62722db4f452a902ca2998860 (patch)
treec831d85292bb2585f7316a466ec745cabcc6ddf9
parentb6ec3216d05b7698ff93c5e20a31d9521bc16d63 (diff)
downloadbluez-046bedecc1bb15c62722db4f452a902ca2998860.tar.gz
bluez-046bedecc1bb15c62722db4f452a902ca2998860.tar.xz
bluez-046bedecc1bb15c62722db4f452a902ca2998860.zip
scan: Add write scan interval window
This patch adds the handle discovery of the Scan Interval Window Characteristic and write the default value (hard-coded in the kernel) of the scan interval, and scan window in the remote's characteristic.
-rw-r--r--scanparam/scan.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/scanparam/scan.c b/scanparam/scan.c
index 3071e723..84feb1bd 100644
--- a/scanparam/scan.c
+++ b/scanparam/scan.c
@@ -29,6 +29,7 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
+#include "log.h"
#include "adapter.h"
#include "device.h"
#include "att.h"
@@ -37,10 +38,18 @@
#include "attio.h"
#include "scan.h"
+#define SCAN_INTERVAL_WIN_UUID 0x2A4F
+
+#define SCAN_INTERVAL 0x0060
+#define SCAN_WINDOW 0x0030
+
struct scan {
struct btd_device *device;
GAttrib *attrib;
+ struct att_range range;
guint attioid;
+ uint16_t interval;
+ uint16_t window;
};
GSList *servers = NULL;
@@ -56,11 +65,42 @@ static gint scan_device_cmp(gconstpointer a, gconstpointer b)
return -1;
}
+static void iwin_discovered_cb(GSList *chars, guint8 status,
+ gpointer user_data)
+{
+ struct scan *scan = user_data;
+ struct gatt_char *chr;
+ uint8_t value[4];
+
+ if (status) {
+ error("Discover Scan Interval Window: %s",
+ att_ecode2str(status));
+ return;
+ }
+
+ chr = chars->data;
+
+ DBG("Scan Interval Window handle: 0x%04x",
+ chr->value_handle);
+
+ att_put_u16(SCAN_INTERVAL, &value[0]);
+ att_put_u16(SCAN_WINDOW, &value[2]);
+
+ gatt_write_char(scan->attrib, chr->value_handle, value,
+ sizeof(value), NULL, NULL);
+}
+
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
{
struct scan *scan = user_data;
+ bt_uuid_t iwin_uuid;
+
+ bt_uuid16_create(&iwin_uuid, SCAN_INTERVAL_WIN_UUID);
scan->attrib = g_attrib_ref(attrib);
+
+ gatt_discover_char(scan->attrib, scan->range.start, scan->range.end,
+ &iwin_uuid, iwin_discovered_cb, scan);
}
static void attio_disconnected_cb(gpointer user_data)
@@ -77,6 +117,7 @@ int scan_register(struct btd_device *device, struct gatt_primary *prim)
scan = g_new0(struct scan, 1);
scan->device = btd_device_ref(device);
+ scan->range = prim->range;
scan->attioid = btd_device_add_attio_callback(device,
attio_connected_cb,
attio_disconnected_cb,