att_db: allow ATT Read Callback to return custom ATT Error Code

This commit is contained in:
Matthias Ringwald 2021-04-29 22:50:22 +02:00
parent 1676a2b8fd
commit 0ff1f3d8cf
3 changed files with 29 additions and 1 deletions

View File

@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- GATT Client: Device Information Service Client
- GATT Client: HID-over-GATT (HOG) Client, Report and Boot Host
- GATT Client: Scan Parameters Service Client
- GATT Server: Scan Parameters Service Server
- GATT Server: Scan Parameters Service Server
- GAP: support scan page configuration with `gap_set_page_scan_activity` and `gap_set_page_scan_type`
- GAP: support sniff subrating with `gap_sniff_subrating_configure
- GAP: support QoS setup with `gap_qos_set`
@ -72,6 +72,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- HFP: provide acl_handle in events to identify connection
- HCI Transport: extract convenience function declaration for h4, h5, em9304_spi, and usb into separate hci_transport_{type}.h
- GATT Client: Use ATT_READ_REQUEST for first blob of Read Long Characteristic and Read Long Characteristic Descriptor
- GATT Server: Allow ATT Read Callback to return custom ATT Error Code
- HID: Move `src/classic/hid.h` into `src` and prefix with `btstack_` to use it with BLE and avoid name clashes
## Release v1.3.2

View File

@ -587,6 +587,12 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection,
}
#endif
// allow to return ATT Error Code in ATT Read Callback
if (it.value_len > ATT_READ_ERROR_CODE_OFFSET){
error_code = it.value_len - ATT_READ_ERROR_CODE_OFFSET;
break;
}
// check if value has same len as last one
uint16_t this_pair_len = 2u + it.value_len;
if ((offset > 1u) && (pair_len != this_pair_len)) {
@ -685,6 +691,12 @@ static uint16_t handle_read_request2(att_connection_t * att_connection, uint8_t
if (it.value_len == ATT_READ_RESPONSE_PENDING) return ATT_READ_RESPONSE_PENDING;
#endif
// allow to return ATT Error Code in ATT Read Callback
if (it.value_len > ATT_READ_ERROR_CODE_OFFSET){
error_code = it.value_len - ATT_READ_ERROR_CODE_OFFSET;
return setup_error(response_buffer, request_type, handle, error_code);
}
// store
uint16_t offset = 1;
uint16_t bytes_copied = att_copy_value(&it, 0, response_buffer + offset, response_buffer_size - offset, att_connection->con_handle);
@ -733,6 +745,12 @@ static uint16_t handle_read_blob_request2(att_connection_t * att_connection, uin
if (it.value_len == ATT_READ_RESPONSE_PENDING) return ATT_READ_RESPONSE_PENDING;
#endif
// allow to return ATT Error Code in ATT Read Callback
if (it.value_len > ATT_READ_ERROR_CODE_OFFSET){
error_code = it.value_len - ATT_READ_ERROR_CODE_OFFSET;
return setup_error(response_buffer, request_type, handle, error_code);
}
if (value_offset > it.value_len){
return setup_error_invalid_offset(response_buffer, request_type, handle);
}
@ -809,6 +827,12 @@ static uint16_t handle_read_multiple_request2(att_connection_t * att_connection,
if (read_request_pending) continue;
#endif
// allow to return ATT Error Code in ATT Read Callback
if (it.value_len > ATT_READ_ERROR_CODE_OFFSET){
error_code = it.value_len -ATT_READ_ERROR_CODE_OFFSET;
break;
}
// store
uint16_t bytes_copied = att_copy_value(&it, 0, response_buffer + offset, response_buffer_size - offset, att_connection->con_handle);
offset += bytes_copied;

View File

@ -87,6 +87,9 @@ extern "C" {
#define ATT_WRITE_COMMAND 0x52
#define ATT_SIGNED_WRITE_COMMAND 0xD2
// map ATT ERROR CODES on to att_read_callback length
#define ATT_READ_ERROR_CODE_OFFSET 0xfe00
// custom BTstack ATT Response Pending for att_read_callback
#define ATT_READ_RESPONSE_PENDING 0xffff