fix(ble/bluedroid): Propagate create_attr_tab BTA failures in inter_cb

(cherry picked from commit 4f8027da11)

Co-authored-by: zhanghaipeng <zhanghaipeng@espressif.com>
This commit is contained in:
Zhang Hai Peng
2026-06-02 10:23:56 +08:00
parent 0f5eb923e8
commit c501d559ed

View File

@@ -658,43 +658,55 @@ static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GATTS;
msg.act = event;
if(btc_creat_tab_env.is_tab_creat_svc && btc_creat_tab_env.complete_future) {
switch(event) {
case BTA_GATTS_CREATE_EVT: {
//save the service handle to the btc module after used
//the attribute table method to creat a service
if (btc_creat_tab_env.is_tab_creat_svc && btc_creat_tab_env.complete_future) {
void *result = FUTURE_SUCCESS;
uint16_t index = btc_creat_tab_env.handle_idx;
switch (event) {
case BTA_GATTS_CREATE_EVT:
if (p_data->create.status != BTA_GATT_OK || p_data->create.service_id == 0) {
result = FUTURE_FAIL;
} else {
/* save the service handle after the attribute table method creates a service */
bta_to_btc_uuid(&btc_creat_tab_env.svc_uuid, &p_data->create.uuid);
uint16_t index = btc_creat_tab_env.handle_idx;
btc_creat_tab_env.svc_start_hdl = p_data->create.service_id;
btc_creat_tab_env.handles[index] = p_data->create.service_id;
break;
}
case BTA_GATTS_ADD_INCL_SRVC_EVT: {
uint16_t index = btc_creat_tab_env.handle_idx;
break;
case BTA_GATTS_ADD_INCL_SRVC_EVT:
if (p_data->add_result.status != BTA_GATT_OK || p_data->add_result.attr_id == 0) {
result = FUTURE_FAIL;
} else {
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
break;
}
case BTA_GATTS_ADD_CHAR_EVT: {
uint16_t index = btc_creat_tab_env.handle_idx;
break;
case BTA_GATTS_ADD_CHAR_EVT:
if (p_data->add_result.status != BTA_GATT_OK || p_data->add_result.attr_id == 0) {
result = FUTURE_FAIL;
} else {
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id - 1;
if (index + 1 < btc_creat_tab_env.num_handle) {
btc_creat_tab_env.handles[index+1] = p_data->add_result.attr_id;
btc_creat_tab_env.handles[index + 1] = p_data->add_result.attr_id;
} else {
BTC_TRACE_ERROR("%s handles[%d+1] out of bounds (num_handle=%d)",
__func__, index, btc_creat_tab_env.num_handle);
result = FUTURE_FAIL;
}
break;
}
case BTA_GATTS_ADD_CHAR_DESCR_EVT: {
uint16_t index = btc_creat_tab_env.handle_idx;
break;
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
if (p_data->add_result.status != BTA_GATT_OK || p_data->add_result.attr_id == 0) {
result = FUTURE_FAIL;
} else {
btc_creat_tab_env.handles[index] = p_data->add_result.attr_id;
break;
}
default:
break;
break;
default:
break;
}
future_ready(btc_creat_tab_env.complete_future, FUTURE_SUCCESS);
if (result == FUTURE_FAIL) {
BTC_TRACE_ERROR("%s create_attr_tab failed, event=%d", __func__, event);
}
future_ready(btc_creat_tab_env.complete_future, result);
return;
}
status = btc_transfer_context(&msg, p_data, sizeof(tBTA_GATTS),