Bluetooth: Fix persisting CCC config for non-bonded devices

The spec says that CCC shall only be persistent accross connection for
bonded devices:

  'The Client Characteristic Configuration descriptor value shall be
  persistent across connections for bonded devices. The Client Characteristic
  Configuration descriptor value shall be set to the default value at each
  connection with non-bonded devices'.

To handle this now each configuration has a valid field indicating if the
configuration is valid.

Change-Id: Id74ac54f5e23a7a0b286f90dbc9af4e9ee966dd4
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-06-05 10:57:32 +03:00 committed by Anas Nashif
commit aa1260999e
2 changed files with 11 additions and 2 deletions

View file

@ -310,6 +310,7 @@ int bt_gatt_attr_read_chrc(const bt_addr_le_t *peer,
struct bt_gatt_ccc_cfg {
bt_addr_le_t peer;
uint16_t value;
uint8_t valid;
};
struct _bt_gatt_ccc {

View file

@ -227,6 +227,7 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
uint8_t len, uint16_t offset)
{
struct _bt_gatt_ccc *ccc = attr->user_data;
struct bt_conn *conn;
const uint16_t *data = buf;
size_t i;
@ -234,6 +235,12 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
return -EINVAL;
}
conn = bt_conn_lookup_addr_le(peer);
if (!conn) {
BT_WARN("%s not connected", bt_addr_le_str(peer));
return -ENOTCONN;
}
for (i = 0; i < ccc->cfg_len; i++) {
/* Check for existing configuration */
if (!bt_addr_le_cmp(&ccc->cfg[i].peer, peer)) {
@ -244,9 +251,10 @@ int bt_gatt_attr_write_ccc(const bt_addr_le_t *peer,
if (i == ccc->cfg_len) {
for (i = 0; i < ccc->cfg_len; i++) {
/* Check for unused configuration */
if (!bt_addr_le_cmp(&ccc->cfg[i].peer,
BT_ADDR_LE_ANY)) {
if (!ccc->cfg[i].valid) {
bt_addr_le_copy(&ccc->cfg[i].peer, peer);
/* Only set valid if bonded */
ccc->cfg[i].valid = conn->keys ? 1 : 0;
break;
}
}