fix(bt): get remote device name from eir data

This commit is contained in:
gongyantao 2024-07-31 17:24:44 +08:00
parent 85ded0b544
commit 602bd2d89a

View File

@ -275,38 +275,39 @@ static void handle_bt_device_result(struct disc_res_param *disc_res)
uint8_t len = 0; uint8_t len = 0;
uint8_t *data = 0; uint8_t *data = 0;
data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_CMPL_16BITS_UUID, &len); do {
if (data == NULL) { data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_CMPL_16BITS_UUID, &len);
data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_INCMPL_16BITS_UUID, &len); if (data == NULL) {
} data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_INCMPL_16BITS_UUID, &len);
if (data && len == ESP_UUID_LEN_16) { }
uuid.len = ESP_UUID_LEN_16; if (data && len == ESP_UUID_LEN_16) {
uuid.uuid.uuid16 = data[0] + (data[1] << 8); uuid.len = ESP_UUID_LEN_16;
GAP_DBG_PRINTF(", "); print_uuid(&uuid); uuid.uuid.uuid16 = data[0] + (data[1] << 8);
continue; GAP_DBG_PRINTF(", "); print_uuid(&uuid);
} break;
}
data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_CMPL_32BITS_UUID, &len); data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_CMPL_32BITS_UUID, &len);
if (data == NULL) { if (data == NULL) {
data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_INCMPL_32BITS_UUID, &len); data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_INCMPL_32BITS_UUID, &len);
} }
if (data && len == ESP_UUID_LEN_32) { if (data && len == ESP_UUID_LEN_32) {
uuid.len = len; uuid.len = len;
memcpy(&uuid.uuid.uuid32, data, sizeof(uint32_t)); memcpy(&uuid.uuid.uuid32, data, sizeof(uint32_t));
GAP_DBG_PRINTF(", "); print_uuid(&uuid); GAP_DBG_PRINTF(", "); print_uuid(&uuid);
continue; break;
} }
data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_CMPL_128BITS_UUID, &len); data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_CMPL_128BITS_UUID, &len);
if (data == NULL) { if (data == NULL) {
data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_INCMPL_128BITS_UUID, &len); data = esp_bt_gap_resolve_eir_data((uint8_t *)prop->val, ESP_BT_EIR_TYPE_INCMPL_128BITS_UUID, &len);
} }
if (data && len == ESP_UUID_LEN_128) { if (data && len == ESP_UUID_LEN_128) {
uuid.len = len; uuid.len = len;
memcpy(uuid.uuid.uuid128, (uint8_t *)data, len); memcpy(uuid.uuid.uuid128, (uint8_t *)data, len);
GAP_DBG_PRINTF(", "); print_uuid(&uuid); GAP_DBG_PRINTF(", "); print_uuid(&uuid);
continue; }
} } while (0);
//try to find a name //try to find a name
if (name == NULL) { if (name == NULL) {