uint8_t bdaddr_type;
unsigned int disc_id;
uint8_t cli_feat[1];
+ bool change_aware;
+ bool out_of_sync;
struct queue *ccc_states;
struct notify *pending;
};
DBG("");
state->disc_id = 0;
+ state->out_of_sync = false;
device = btd_adapter_find_device(state->db->adapter, &state->bdaddr,
state->bdaddr_type);
/* Shall we reallocate the feat array if bigger? */
len = MIN(sizeof(state->cli_feat), len);
while (len) {
- state->cli_feat[len - 1] |= value[len -1];
+ state->cli_feat[len - 1] |= value[len - 1];
len--;
}
+ state->cli_feat[0] &= BT_GATT_CHRC_CLI_FEAT_ROBUST_CACHING;
+ state->change_aware = true;
+
done:
gatt_db_attribute_write_result(attrib, id, ecode);
}
{
struct btd_gatt_database *database = user_data;
const uint8_t *hash;
+ struct device_state *state;
+ bdaddr_t bdaddr;
+ uint8_t bdaddr_type;
DBG("Database Hash read");
hash = gatt_db_get_hash(database->db);
gatt_db_attribute_read_result(attrib, id, 0, hash, 16);
+
+ if (!get_dst_info(att, &bdaddr, &bdaddr_type))
+ return;
+
+ state = find_device_state(database, &bdaddr, bdaddr_type);
+ if (state)
+ state->change_aware = true;
}
static void populate_gatt_service(struct btd_gatt_database *database)
static void service_changed_conf(void *user_data)
{
+ struct device_state *state = user_data;
+
DBG("");
+
+ if (!state)
+ return;
+
+ state->change_aware = true;
}
static void state_set_pending(struct device_state *state, struct notify *notify)
struct btd_device *device;
struct bt_gatt_server *server;
+ if (notify->conf == service_changed_conf) {
+ if (device_state->cli_feat[0] &
+ BT_GATT_CHRC_CLI_FEAT_ROBUST_CACHING) {
+ device_state->change_aware = false;
+ notify->user_data = device_state;
+ }
+ }
+
ccc = find_ccc_state(device_state, notify->ccc_handle);
if (!ccc)
return;
{ }
};
+static uint8_t server_authorize(struct bt_att *att, uint8_t opcode,
+ uint16_t handle, void *user_data)
+{
+ struct btd_gatt_database *database = user_data;
+ struct device_state *state;
+ bdaddr_t bdaddr;
+ uint8_t bdaddr_type;
+
+ if (!get_dst_info(att, &bdaddr, &bdaddr_type))
+ return 0;
+
+ /* Skip if there is no device state */
+ state = find_device_state(database, &bdaddr, bdaddr_type);
+ if (!state)
+ return 0;
+
+ /* Skip if client doesn't support Robust Caching */
+ if (!(state->cli_feat[0] & BT_GATT_CHRC_CLI_FEAT_ROBUST_CACHING))
+ return 0;
+
+ if (state->change_aware)
+ return 0;
+
+ if (state->out_of_sync) {
+ state->out_of_sync = false;
+ state->change_aware = true;
+ return 0;
+ }
+
+ state->out_of_sync = true;
+
+ return BT_ATT_ERROR_DB_OUT_OF_SYNC;
+}
+
struct btd_gatt_database *btd_gatt_database_new(struct btd_adapter *adapter)
{
struct btd_gatt_database *database;
return database->db;
}
-void btd_gatt_database_att_connected(struct btd_gatt_database *database,
- struct bt_att *att)
+void btd_gatt_database_server_connected(struct btd_gatt_database *database,
+ struct bt_gatt_server *server)
{
+ struct bt_att *att = bt_gatt_server_get_att(server);
struct device_state *state;
bdaddr_t bdaddr;
uint8_t bdaddr_type;
if (!get_dst_info(att, &bdaddr, &bdaddr_type))
return;
+ bt_gatt_server_set_authorize(server, server_authorize, database);
+
state = find_device_state(database, &bdaddr, bdaddr_type);
if (!state || !state->pending)
return;