Merge branch 'backport/fix_ble_prepare_write_v4.4' into 'release/v4.4'

Backport/fix ble prepare write v4.4

See merge request espressif/esp-idf!27907
This commit is contained in:
Island 2023-12-20 21:46:07 +08:00
commit 11f9081a0e
10 changed files with 111 additions and 91 deletions

View File

@ -1241,15 +1241,18 @@ tGATT_STATUS gatts_write_attr_perm_check (tGATT_SVC_DB *p_db, UINT8 op_code,
// btla-specific ++ // btla-specific ++
else if ( (p_attr->uuid_type == GATT_ATTR_UUID_TYPE_16) && else if ( (p_attr->uuid_type == GATT_ATTR_UUID_TYPE_16) &&
(p_attr->uuid == GATT_UUID_CHAR_CLIENT_CONFIG || (p_attr->uuid == GATT_UUID_CHAR_CLIENT_CONFIG ||
p_attr->uuid == GATT_UUID_CHAR_SRVR_CONFIG) ) p_attr->uuid == GATT_UUID_CHAR_SRVR_CONFIG ||
p_attr->uuid == GATT_UUID_CLIENT_SUP_FEAT ||
p_attr->uuid == GATT_UUID_GAP_ICON
) )
// btla-specific -- // btla-specific --
{ {
if (op_code == GATT_REQ_PREPARE_WRITE && offset != 0) { /* does not allow write blob */ if (op_code == GATT_REQ_PREPARE_WRITE) { /* does not allow write blob */
status = GATT_NOT_LONG; status = GATT_REQ_NOT_SUPPORTED;
GATT_TRACE_ERROR( "gatts_write_attr_perm_check - GATT_NOT_LONG,handle:0x%04x",handle); GATT_TRACE_ERROR( "gatts_write_attr_perm_check - GATT_REQ_NOT_SUPPORTED,handle:0x%04x",handle);
} else if (len != max_size) { /* data does not match the required format */ } else if (len != max_size) { /* data does not match the required format */
status = GATT_INVALID_ATTR_LEN; status = GATT_INVALID_ATTR_LEN;
GATT_TRACE_ERROR( "gatts_write_attr_perm_check - GATT_INVALID_PDU,handle:0x%04x",handle); GATT_TRACE_ERROR( "gatts_write_attr_perm_check - GATT_INVALID_ATTR_LEN,handle:0x%04x",handle);
} else { } else {
status = GATT_SUCCESS; status = GATT_SUCCESS;
} }

View File

@ -1448,7 +1448,8 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand
} }
if ((prepare_record->error_code_app == GATT_SUCCESS) if ((prepare_record->error_code_app == GATT_SUCCESS)
&& ((status == GATT_INVALID_OFFSET) || (status == GATT_INVALID_ATTR_LEN))){ // update prepare write status for excute write request
&& (status == GATT_INVALID_OFFSET || status == GATT_INVALID_ATTR_LEN || status == GATT_REQ_NOT_SUPPORTED)) {
prepare_record->error_code_app = status; prepare_record->error_code_app = status;
} }

View File

@ -387,20 +387,21 @@ void example_prepare_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t
{ {
EXAMPLE_DEBUG(EXAMPLE_TAG, "prepare write, handle = %d, value len = %d", param->write.handle, param->write.len); EXAMPLE_DEBUG(EXAMPLE_TAG, "prepare write, handle = %d, value len = %d", param->write.handle, param->write.len);
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (prepare_write_env->prepare_buf == NULL) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(EXAMPLE_TAG, "%s, Gatt_server prep no mem", __func__); ESP_LOGE(EXAMPLE_TAG, "%s, Gatt_server prep no mem", __func__);
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
/*send response when param->write.need_rsp is true */ /*send response when param->write.need_rsp is true */
if (param->write.need_rsp){ if (param->write.need_rsp){
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));

View File

@ -282,20 +282,19 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (param->write.need_rsp) { if (param->write.need_rsp) {
if (param->write.is_prep) { if (param->write.is_prep) {
if (prepare_write_env->prepare_buf == NULL) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem\n"); ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE ||
prepare_write_env->prepare_len > param->write.offset) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));

View File

@ -242,19 +242,18 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (param->write.need_rsp){ if (param->write.need_rsp){
if (param->write.is_prep) { if (param->write.is_prep) {
if (prepare_write_env->prepare_buf == NULL) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem\n"); ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));

View File

@ -771,34 +771,36 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (param->write.need_rsp){ if (param->write.need_rsp){
if (param->write.is_prep) { if (param->write.is_prep) {
if (prepare_write_env->prepare_buf == NULL){ if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem\n"); ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
}
else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));
if (gatt_rsp) {
gatt_rsp->attr_value.len = param->write.len; gatt_rsp->attr_value.len = param->write.len;
gatt_rsp->attr_value.handle = param->write.handle; gatt_rsp->attr_value.handle = param->write.handle;
gatt_rsp->attr_value.offset = param->write.offset; gatt_rsp->attr_value.offset = param->write.offset;
gatt_rsp->attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; gatt_rsp->attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE;
memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len); memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len);
esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp);
param->write.trans_id, status, gatt_rsp);
if (response_err != ESP_OK){ if (response_err != ESP_OK){
ESP_LOGE(GATTS_TAG, "Send response error\n"); ESP_LOGE(GATTS_TAG, "Send response error\n");
} }
free(gatt_rsp); free(gatt_rsp);
} else {
ESP_LOGE(GATTS_TAG, "malloc failed, no resource to send response error\n");
status = ESP_GATT_NO_RESOURCES;
}
if (status != ESP_GATT_OK){ if (status != ESP_GATT_OK){
return; return;
} }
@ -850,7 +852,7 @@ static prepare_type_env_t b_prepare_write_env;
In order to use the prepare buffer, some memory space is allocated for it. In case the allocation fails due to a lack of memory, an error is printed: In order to use the prepare buffer, some memory space is allocated for it. In case the allocation fails due to a lack of memory, an error is printed:
```c ```c
if (prepare_write_env->prepare_buf == NULL) { if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = prepare_write_env->prepare_buf =
(uint8_t*)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); (uint8_t*)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;

View File

@ -283,20 +283,20 @@ void example_prepare_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t
{ {
ESP_LOGI(GATTS_TABLE_TAG, "prepare write, handle = %d, value len = %d", param->write.handle, param->write.len); ESP_LOGI(GATTS_TABLE_TAG, "prepare write, handle = %d, value len = %d", param->write.handle, param->write.len);
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (prepare_write_env->prepare_buf == NULL) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(GATTS_TABLE_TAG, "%s, Gatt_server prep no mem", __func__); ESP_LOGE(GATTS_TABLE_TAG, "%s, Gatt_server prep no mem", __func__);
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
/*send response when param->write.need_rsp is true */ /*send response when param->write.need_rsp is true */
if (param->write.need_rsp){ if (param->write.need_rsp){
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));

View File

@ -199,19 +199,19 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (param->write.need_rsp){ if (param->write.need_rsp){
if (param->write.is_prep) { if (param->write.is_prep) {
if (prepare_write_env->prepare_buf == NULL) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(BT_BLE_COEX_TAG, "Gatt_server prep no mem\n"); ESP_LOGE(BT_BLE_COEX_TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));

View File

@ -526,19 +526,18 @@ static void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
if (param->write.need_rsp) { if (param->write.need_rsp) {
if (param->write.is_prep) { if (param->write.is_prep) {
if (prepare_write_env->prepare_buf == NULL) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t));
prepare_write_env->prepare_len = 0; prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) { if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(COEX_TAG, "Gatt_server prep no mem\n"); ESP_LOGE(COEX_TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES; status = ESP_GATT_NO_RESOURCES;
} }
} else {
if(param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN;
}
} }
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));

View File

@ -105,24 +105,32 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble
void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param) void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param)
{ {
esp_gatt_status_t status = ESP_GATT_OK; esp_gatt_status_t status = ESP_GATT_OK;
// Check if a response is needed
if (param->write.need_rsp) { if (param->write.need_rsp) {
// Check if the write operation is a prepared write
if (param->write.is_prep) { if (param->write.is_prep) {
if (prepare_write_env->prepare_buf == NULL) { // Check for invalid offset or attribute length
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
prepare_write_env->prepare_len = 0;
if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES;
}
} else {
if (param->write.offset > PREPARE_BUF_MAX_SIZE) { if (param->write.offset > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_OFFSET; status = ESP_GATT_INVALID_OFFSET;
} else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) { } else if ((param->write.offset + param->write.len) > PREPARE_BUF_MAX_SIZE) {
status = ESP_GATT_INVALID_ATTR_LEN; status = ESP_GATT_INVALID_ATTR_LEN;
} }
// Allocate memory for the prepare buffer if not already allocated
if (status == ESP_GATT_OK && prepare_write_env->prepare_buf == NULL) {
prepare_write_env->prepare_buf = (uint8_t *)malloc(PREPARE_BUF_MAX_SIZE * sizeof(uint8_t));
prepare_write_env->prepare_len = 0;
// Check for allocation failure
if (prepare_write_env->prepare_buf == NULL) {
ESP_LOGE(TAG, "Gatt_server prep no mem\n");
status = ESP_GATT_NO_RESOURCES;
}
} }
// Allocate and configure the GATT response
esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t)); esp_gatt_rsp_t *gatt_rsp = (esp_gatt_rsp_t *)malloc(sizeof(esp_gatt_rsp_t));
if (gatt_rsp != NULL) {
gatt_rsp->attr_value.len = param->write.len; gatt_rsp->attr_value.len = param->write.len;
gatt_rsp->attr_value.handle = param->write.handle; gatt_rsp->attr_value.handle = param->write.handle;
gatt_rsp->attr_value.offset = param->write.offset; gatt_rsp->attr_value.offset = param->write.offset;
@ -130,18 +138,26 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare
memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len); memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len);
esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp); esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp);
if (response_err != ESP_OK) { if (response_err != ESP_OK) {
ESP_LOGE(TAG, "Send response error\n"); ESP_LOGE(TAG, "Send response error");
} }
free(gatt_rsp); free(gatt_rsp);
}else{
ESP_LOGE(TAG, "%s, malloc failed, and no resource to send response", __func__);
status = ESP_GATT_NO_RESOURCES;
}
if (status != ESP_GATT_OK) { if (status != ESP_GATT_OK) {
return; return;
} }
// Update the prepare buffer with the received data
memcpy(prepare_write_env->prepare_buf + param->write.offset, memcpy(prepare_write_env->prepare_buf + param->write.offset,
param->write.value, param->write.value,
param->write.len); param->write.len);
prepare_write_env->prepare_len += param->write.len; prepare_write_env->prepare_len += param->write.len;
} else { } else {
// Send a response for non-prepared write
esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, NULL); esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, NULL);
} }
} }