From b444aa754d6b3b6ca8204418555d78e2ea93c4a5 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 27 Aug 2024 11:53:48 +0200 Subject: [PATCH] gatt_client: add gatt_client_write_value_of_characteristic_with_context --- src/ble/gatt_client.c | 9 +++++++-- src/ble/gatt_client.h | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 57a0f6574..1645b7dbd 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -2817,8 +2817,8 @@ uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handl return att_write_request(gatt_client, ATT_WRITE_COMMAND, value_handle, value_length, value); } - -uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){ +uint8_t gatt_client_write_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, + uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id){ gatt_client_t * gatt_client; uint8_t status = gatt_client_provide_context_for_request(con_handle, &gatt_client); if (status != ERROR_CODE_SUCCESS){ @@ -2826,6 +2826,8 @@ uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callb } gatt_client->callback = callback; + gatt_client->service_id = service_id; + gatt_client->connection_id = connection_id; gatt_client->attribute_handle = value_handle; gatt_client->attribute_length = value_length; gatt_client->attribute_value = value; @@ -2833,6 +2835,9 @@ uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callb gatt_client_run(); return ERROR_CODE_SUCCESS; } +uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value) { + return gatt_client_write_value_of_characteristic_with_context(callback, con_handle, value_handle, value_length, value, 0, 0); +} uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t offset, uint16_t value_length, uint8_t * value){ gatt_client_t * gatt_client; diff --git a/src/ble/gatt_client.h b/src/ble/gatt_client.h index d650282e4..d74ece190 100644 --- a/src/ble/gatt_client.h +++ b/src/ble/gatt_client.h @@ -779,12 +779,13 @@ uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handl * @param value_handle * @param message_len * @param message is not copied, make sure memory is accessible until write is done - * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found + * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready * ERROR_CODE_SUCCESS if query is successfully registered */ -uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t message_len, uint8_t * message); +uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, + uint16_t message_len, uint8_t * message); /** * @brief Writes the characteristic value using the characteristic's value handle. @@ -804,6 +805,26 @@ uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callb uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value); /** + * @brief Writes the characteristic value using the characteristic's value handle. + * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. + * The write is successfully performed, if the event's att_status field is set to + * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). + * @param callback + * @param con_handle + * @param value_handle + * @param value_length + * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received + * @param service_id + * @param connection_id + * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found + * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated + * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready + * ERROR_CODE_SUCCESS if query is successfully registered + */ +uint8_t gatt_client_write_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, + uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id); + +/** * @brief Writes the characteristic value using the characteristic's value handle. * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).