mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-07 16:20:19 +00:00
change att write callback API to allow for invalid offset error
This commit is contained in:
parent
617cd07ca8
commit
a0ae0a6911
@ -855,9 +855,9 @@ static uint16_t handle_prepare_write_request(att_connection_t * att_connection,
|
|||||||
return setup_error(response_buffer, ATT_PREPARE_WRITE_REQUEST, handle, error_code);
|
return setup_error(response_buffer, ATT_PREPARE_WRITE_REQUEST, handle, error_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = (*att_write_callback)(handle, ATT_TRANSACTION_MODE_ACTIVE, offset, request_buffer + 3, request_len - 3, NULL);
|
int result = (*att_write_callback)(handle, ATT_TRANSACTION_MODE_ACTIVE, offset, request_buffer + 3, request_len - 3, NULL);
|
||||||
if (!ok){
|
if (result){
|
||||||
return setup_error(response_buffer, ATT_PREPARE_WRITE_REQUEST, handle, ATT_ERROR_PREPARE_QUEUE_FULL);
|
return setup_error(response_buffer, ATT_PREPARE_WRITE_REQUEST, handle, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// response: echo request
|
// response: echo request
|
||||||
|
@ -161,7 +161,7 @@ typedef uint16_t (*att_read_callback_t)(uint16_t handle, uint16_t offset, uint8_
|
|||||||
// @param buffer
|
// @param buffer
|
||||||
// @param buffer_size
|
// @param buffer_size
|
||||||
// @param signature used for signed write commmands
|
// @param signature used for signed write commmands
|
||||||
// @returns 1 if request could be queue for ATT_TRANSACTION_MODE_ACTIVE
|
// @returns 0 if write was ok, ATT_ERROR_PREPARE_QUEUE_FULL if no space in queue, ATT_ERROR_INVALID_OFFSET if offset is larger than max buffer
|
||||||
typedef int (*att_write_callback_t)(uint16_t handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size, signature_t * signature);
|
typedef int (*att_write_callback_t)(uint16_t handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size, signature_t * signature);
|
||||||
|
|
||||||
// MARK: ATT Operations
|
// MARK: ATT Operations
|
||||||
|
@ -299,7 +299,7 @@ static int att_write_callback(uint16_t handle, uint16_t transaction_mode, uint16
|
|||||||
client_configuration = buffer[0];
|
client_configuration = buffer[0];
|
||||||
client_configuration_handle = handle;
|
client_configuration_handle = handle;
|
||||||
printf("Client Configuration set to %u for handle %04x\n", client_configuration, handle);
|
printf("Client Configuration set to %u for handle %04x\n", client_configuration, handle);
|
||||||
return 1;
|
return 0; // ok
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ static int att_write_callback(uint16_t handle, uint16_t transaction_mode, uint16
|
|||||||
attributes_index = att_attribute_for_handle(handle);
|
attributes_index = att_attribute_for_handle(handle);
|
||||||
if (attributes_index < 0){
|
if (attributes_index < 0){
|
||||||
attributes_index = att_attribute_for_handle(0);
|
attributes_index = att_attribute_for_handle(0);
|
||||||
if (attributes_index < 0) return 0; // fail
|
if (attributes_index < 0) return 0; // ok, but we couldn't store it (our fault)
|
||||||
att_attributes[attributes_index].handle = handle;
|
att_attributes[attributes_index].handle = handle;
|
||||||
}
|
}
|
||||||
att_attributes[attributes_index].len = buffer_size;
|
att_attributes[attributes_index].len = buffer_size;
|
||||||
@ -320,30 +320,35 @@ static int att_write_callback(uint16_t handle, uint16_t transaction_mode, uint16
|
|||||||
break;
|
break;
|
||||||
case ATT_TRANSACTION_MODE_ACTIVE:
|
case ATT_TRANSACTION_MODE_ACTIVE:
|
||||||
writes_index = att_write_queue_for_handle(handle);
|
writes_index = att_write_queue_for_handle(handle);
|
||||||
if (writes_index < 0) return 0;
|
if (writes_index < 0) return ATT_ERROR_PREPARE_QUEUE_FULL;
|
||||||
if (buffer_size + offset > ATT_VALUE_MAX_LEN) return 0;
|
if (offset > ATT_VALUE_MAX_LEN) return ATT_ERROR_INVALID_OFFSET;
|
||||||
|
if (buffer_size + offset > ATT_VALUE_MAX_LEN) {
|
||||||
|
// truncat value
|
||||||
|
buffer_size = ATT_VALUE_MAX_LEN - offset;
|
||||||
|
}
|
||||||
att_write_queues[writes_index].len = buffer_size + offset;
|
att_write_queues[writes_index].len = buffer_size + offset;
|
||||||
memcpy(&(att_write_queues[writes_index].value[offset]), buffer, buffer_size);
|
memcpy(&(att_write_queues[writes_index].value[offset]), buffer, buffer_size);
|
||||||
break;
|
break;
|
||||||
case ATT_TRANSACTION_MODE_EXECUTE:
|
case ATT_TRANSACTION_MODE_EXECUTE:
|
||||||
for (writes_index=0;writes_index<ATT_NUM_WRITE_QUEUES;writes_index++){
|
for (writes_index=0 ; writes_index<ATT_NUM_WRITE_QUEUES ; writes_index++){
|
||||||
handle = att_write_queues[writes_index].handle;
|
handle = att_write_queues[writes_index].handle;
|
||||||
if (handle == 0) continue;
|
if (handle == 0) continue;
|
||||||
attributes_index = att_attribute_for_handle(handle);
|
attributes_index = att_attribute_for_handle(handle);
|
||||||
if (attributes_index < 0){
|
if (attributes_index < 0){
|
||||||
attributes_index = att_attribute_for_handle(0);
|
attributes_index = att_attribute_for_handle(0);
|
||||||
if (attributes_index < 0) return 0; // fail
|
if (attributes_index < 0) continue;
|
||||||
att_attributes[attributes_index].handle = handle;
|
att_attributes[attributes_index].handle = handle;
|
||||||
}
|
}
|
||||||
att_attributes[attributes_index].len = att_write_queues[writes_index].len;
|
att_attributes[attributes_index].len = att_write_queues[writes_index].len;
|
||||||
memcpy(att_attributes[attributes_index].value, att_write_queues[writes_index].value, att_write_queues[writes_index].len);
|
memcpy(att_attributes[attributes_index].value, att_write_queues[writes_index].value, att_write_queues[writes_index].len);
|
||||||
}
|
}
|
||||||
|
att_write_queue_init();
|
||||||
break;
|
break;
|
||||||
case ATT_TRANSACTION_MODE_CANCEL:
|
case ATT_TRANSACTION_MODE_CANCEL:
|
||||||
att_write_queue_init();
|
att_write_queue_init();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SKIP_ADVERTISEMENT_PARAMAS_UPDATE
|
#ifndef SKIP_ADVERTISEMENT_PARAMAS_UPDATE
|
||||||
@ -454,6 +459,8 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
|||||||
if (!advertisements_enabled == 0 && gap_discoverable){
|
if (!advertisements_enabled == 0 && gap_discoverable){
|
||||||
todos = ENABLE_ADVERTISEMENTS;
|
todos = ENABLE_ADVERTISEMENTS;
|
||||||
}
|
}
|
||||||
|
att_attributes_init();
|
||||||
|
att_write_queue_init();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SM_PASSKEY_INPUT_NUMBER: {
|
case SM_PASSKEY_INPUT_NUMBER: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user