Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble/gatts: Add check for RFU bits #1660

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nimble/host/include/host/ble_att.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ struct os_mbuf;
/**Insufficient Resources to complete the request. */
#define BLE_ATT_ERR_INSUFFICIENT_RES 0x11

/**Requested value is not allowed. */
#define BLE_ATT_ERR_VALUE_NOT_ALLOWED 0x13

/** @} */

/**
Expand Down
5 changes: 5 additions & 0 deletions nimble/host/src/ble_gatt_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ extern STATS_SECT_DECL(ble_gatts_stats) ble_gatts_stats;
#define BLE_GATT_CHR_DECL_SZ_16 5
#define BLE_GATT_CHR_DECL_SZ_128 19
#define BLE_GATT_CHR_CLI_SUP_FEAT_SZ 1
/**
* For now only 3 bits in first octet are defined
*
*/
#define BLE_GATT_CHR_CLI_SUP_FEAT_MASK 7

typedef uint8_t ble_gatts_conn_flags;

Expand Down
13 changes: 9 additions & 4 deletions nimble/host/src/ble_gatts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1591,20 +1591,20 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
BLE_HS_LOG(DEBUG, "");

if (!om) {
return BLE_HS_EINVAL;
return BLE_ATT_ERR_INSUFFICIENT_RES;
}

ble_hs_lock();
conn = ble_hs_conn_find(conn_handle);
if (conn == NULL) {
rc = BLE_HS_ENOTCONN;
rc = BLE_ATT_ERR_UNLIKELY;
goto done;
}
if (om->om_len == 0) {
/* Nothing to do */
goto done;
} else if (os_mbuf_len(om) > BLE_ATT_ATTR_MAX_LEN) {
rc = BLE_HS_ENOMEM;
rc = BLE_ATT_ERR_INSUFFICIENT_RES;
goto done;
}

Expand All @@ -1618,10 +1618,15 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
*/
if (conn->bhc_gatt_svr.peer_cl_sup_feat[feat_idx] >
om->om_data[i]) {
rc = BLE_HS_EINVAL;
rc = BLE_ATT_ERR_VALUE_NOT_ALLOWED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this looks odd as now this function return either BLE_HS_ errors or BLE_ATT_ERR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning all att errors should work. Could you take a look again? I converted all the HS errors to ATT.

goto done;
}

/* All RFU bits should be unset */
if (feat_idx == 0) {
om->om_data[i] &= BLE_GATT_CHR_CLI_SUP_FEAT_MASK;
}

conn->bhc_gatt_svr.peer_cl_sup_feat[feat_idx] |= om->om_data[i];

feat_idx++;
Expand Down
Loading