#define SCAN_INTERVAL 0x0060
#define SCAN_WINDOW 0x0030
+#define SERVER_REQUIRES_REFRESH 0x00
struct scan {
struct btd_device *device;
guint attioid;
uint16_t interval;
uint16_t window;
+ uint16_t iwhandle;
uint16_t refresh_handle;
uint16_t refresh_cb_id;
};
return (device == scan->device ? 0 : -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)
{
return;
DBG("Server requires refresh: %d", pdu[3]);
+
+ if (pdu[3] == SERVER_REQUIRES_REFRESH)
+ write_scan_params(scan->attrib, scan->iwhandle);
}
static void ccc_written_cb(guint8 status, const guint8 *pdu,
{
struct scan *scan = user_data;
struct gatt_char *chr;
- uint8_t value[4];
if (status) {
error("Discover Scan Interval Window: %s",
}
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)