aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2012-05-03 17:55:07 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-21 18:00:18 -0300
commit2e561d0ad2a2c69b86f3fb2d98a4f1d35a2e2163 (patch)
treebbc401ce11c4a4ae56b548c54765ff0ed331d765
parentf419bbde9149d50c476af43646d8702528f7d784 (diff)
downloadbluez-2e561d0ad2a2c69b86f3fb2d98a4f1d35a2e2163.tar.gz
bluez-2e561d0ad2a2c69b86f3fb2d98a4f1d35a2e2163.tar.xz
bluez-2e561d0ad2a2c69b86f3fb2d98a4f1d35a2e2163.zip
scan: Write parameters when requested
This patch implements the update procedure of the scan parameters when the Scan Server requests. The Scan Refresh characteristic is used to inform the Scan Client(BlueZ) that the Scan Server requires the most recent scan settings.
-rw-r--r--scanparam/scan.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/scanparam/scan.c b/scanparam/scan.c
index 721cc6d0..32599fd4 100644
--- a/scanparam/scan.c
+++ b/scanparam/scan.c
@@ -51,6 +51,7 @@ struct scan {
guint attioid;
uint16_t interval;
uint16_t window;
+ uint16_t iwhandle;
uint16_t refresh_handle;
uint16_t refresh_cb_id;
};
@@ -68,6 +69,16 @@ static gint scan_device_cmp(gconstpointer a, gconstpointer b)
return -1;
}
+static void write_scan_params(GAttrib *attrib, uint16_t handle)
+{
+ uint8_t value[4];
+
+ att_put_u16(SCAN_INTERVAL, &value[0]);
+ att_put_u16(SCAN_WINDOW, &value[2]);
+
+ gatt_write_char(attrib, handle, value, sizeof(value), NULL, NULL);
+}
+
static void refresh_value_cb(const uint8_t *pdu, uint16_t len,
gpointer user_data)
{
@@ -85,6 +96,9 @@ static void refresh_value_cb(const uint8_t *pdu, uint16_t len,
return;
DBG("Server requires refresh: %d", pdu[3]);
+
+ if (pdu[3] == 1)
+ write_scan_params(scan->attrib, scan->iwhandle);
}
static void ccc_written_cb(guint8 status, const guint8 *pdu,
@@ -173,7 +187,6 @@ static void iwin_discovered_cb(GSList *chars, guint8 status,
{
struct scan *scan = user_data;
struct gatt_char *chr;
- uint8_t value[4];
if (status) {
error("Discover Scan Interval Window: %s",
@@ -182,15 +195,11 @@ static void iwin_discovered_cb(GSList *chars, guint8 status,
}
chr = chars->data;
+ scan->iwhandle = chr->value_handle;
- DBG("Scan Interval Window handle: 0x%04x",
- chr->value_handle);
-
- att_put_u16(SCAN_INTERVAL, &value[0]);
- att_put_u16(SCAN_WINDOW, &value[2]);
+ DBG("Scan Interval Window handle: 0x%04x", scan->iwhandle);
- gatt_write_char(scan->attrib, chr->value_handle, value,
- sizeof(value), NULL, NULL);
+ write_scan_params(scan->attrib, scan->iwhandle);
}
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)