diff --git a/ble/att.c b/ble/att.c index 9a024959b..d511fe406 100644 --- a/ble/att.c +++ b/ble/att.c @@ -930,7 +930,7 @@ static void handle_write_command(att_connection_t * att_connection, uint8_t * re if (!ok) return; if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) return; if ((it.flags & ATT_PROPERTY_WRITE_WITHOUT_RESPONSE) == 0) return; - if (att_validate_security(att_connection, &it)) return 0; + if (att_validate_security(att_connection, &it)) return; (*att_write_callback)(handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3, NULL); } @@ -948,7 +948,7 @@ static void handle_signed_write_command(att_connection_t * att_connection, uint8 if (!ok) return; if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) return; if ((it.flags & ATT_PROPERTY_AUTHENTICATED_SIGNED_WRITE) == 0) return; - if (att_validate_security(att_connection, &it)) return 0; + if (att_validate_security(att_connection, &it)) return; (*att_write_callback)(handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3 - 12, (signature_t *) request_buffer + request_len - 12); } diff --git a/ble/att_server.c b/ble/att_server.c index 2d5702414..2c0c75378 100644 --- a/ble/att_server.c +++ b/ble/att_server.c @@ -67,6 +67,7 @@ typedef enum { ATT_SERVER_IDLE, ATT_SERVER_REQUEST_RECEIVED, ATT_SERVER_W4_SIGNED_WRITE_VALIDATION, + ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED, } att_server_state_t; static att_connection_t att_connection; @@ -195,10 +196,7 @@ static void att_signed_write_handle_cmac_result(uint8_t hash[8]){ // update sequence number uint32_t counter_packet = READ_BT_32(att_request_buffer, att_request_size-12); central_device_db_counter_set(att_ir_central_device_db_index, counter_packet+1); - // just treat signed write command as simple write command after validation - att_request_buffer[0] = ATT_WRITE_COMMAND; - att_request_size -= 12; - att_server_state = ATT_SERVER_REQUEST_RECEIVED; + att_server_state = ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED; att_run(); } @@ -246,7 +244,9 @@ static void att_run(void){ sm_cmac_start(csrk, att_request_size - 8, att_request_buffer, att_signed_write_handle_cmac_result); return; } + // NOTE: fall through for regular commands + case ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED: if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)) return; uint8_t att_response_buffer[28];