Skip to content

Commit 0f8d13c

Browse files
nimble/host: store client supported features value
This adds support for storing client supported features for clients with a trusted relationship. Fixes Host qualification test case GATT/SR/GAS/BV-04-C
1 parent 7e4e7ee commit 0f8d13c

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

nimble/host/src/ble_gatts.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,8 @@ int
16121612
ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat, uint8_t len)
16131613
{
16141614
struct ble_hs_conn *conn;
1615+
struct ble_store_key_cl_sup_feat feat_key;
1616+
struct ble_store_value_cl_sup_feat feat_val;
16151617
int rc = 0;
16161618

16171619
if (out_supported_feat == NULL) {
@@ -1629,8 +1631,15 @@ ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat
16291631
len = BLE_GATT_CHR_CLI_SUP_FEAT_SZ;
16301632
}
16311633

1632-
memcpy(out_supported_feat, conn->bhc_gatt_svr.peer_cl_sup_feat,
1633-
sizeof(uint8_t) * len);
1634+
if (conn->bhc_sec_state.bonded) {
1635+
feat_key.peer_addr = conn->bhc_peer_addr;
1636+
feat_key.idx = 0;
1637+
ble_store_read_peer_cl_sup_feat(&feat_key, &feat_val);
1638+
memcpy(out_supported_feat, feat_val.peer_cl_sup_feat, sizeof(uint8_t) * len);
1639+
} else {
1640+
memcpy(out_supported_feat, conn->bhc_gatt_svr.peer_cl_sup_feat,
1641+
sizeof(uint8_t) * len);
1642+
}
16341643

16351644
done:
16361645
ble_hs_unlock();
@@ -1641,6 +1650,9 @@ int
16411650
ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
16421651
{
16431652
struct ble_hs_conn *conn;
1653+
struct ble_store_value_cl_sup_feat store_feat;
1654+
struct ble_store_key_cl_sup_feat feat_key;
1655+
struct ble_store_value_cl_sup_feat feat_val;
16441656
uint8_t feat[BLE_GATT_CHR_CLI_SUP_FEAT_SZ] = {};
16451657
uint16_t len;
16461658
int rc = 0;
@@ -1686,6 +1698,32 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
16861698

16871699
memcpy(conn->bhc_gatt_svr.peer_cl_sup_feat, feat, BLE_GATT_CHR_CLI_SUP_FEAT_SZ);
16881700

1701+
if (conn->bhc_sec_state.bonded) {
1702+
feat_key.peer_addr = conn->bhc_peer_addr;
1703+
rc = ble_store_read_peer_cl_sup_feat(&feat_key, &feat_val);
1704+
if (rc == BLE_HS_ENOENT) {
1705+
/* Assume the values were not stored yet */
1706+
store_feat.peer_addr = conn->bhc_peer_addr;
1707+
memcpy(store_feat.peer_cl_sup_feat, feat, BLE_GATT_CHR_CLI_SUP_FEAT_SZ);
1708+
if (ble_store_write_peer_cl_sup_feat(&store_feat)) {
1709+
/* XXX: Should error get reported? */
1710+
}
1711+
rc = 0;
1712+
goto done;
1713+
}
1714+
if (rc == 0) {
1715+
/* Found cl_sup_feat for this peer, check for disabling already
1716+
* enabled features */
1717+
for (i = 0; i < BLE_GATT_CHR_CLI_SUP_FEAT_SZ; i++) {
1718+
if ((feat_val.peer_cl_sup_feat[i] & feat[i]) !=
1719+
feat_val.peer_cl_sup_feat[i]) {
1720+
rc = BLE_ATT_ERR_VALUE_NOT_ALLOWED;
1721+
goto done;
1722+
}
1723+
}
1724+
}
1725+
}
1726+
16891727
done:
16901728
ble_hs_unlock();
16911729
return rc;

0 commit comments

Comments
 (0)