mirror of
https://github.com/espressif/esp-idf.git
synced 2026-06-04 20:26:38 +03:00
fix(nimble): Added device name log for ext adv in blecent_throughput
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -564,20 +564,20 @@ blecent_scan(void)
|
||||
* advertisement. The function returns a positive result if the device
|
||||
* advertises connectability and support for the LE PHY service.
|
||||
*/
|
||||
static int
|
||||
ext_blecent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
{
|
||||
int offset = 0;
|
||||
int ad_struct_len = 0;
|
||||
uint8_t test_addr[6];
|
||||
uint32_t peer_addr[6];
|
||||
|
||||
if (disc->legacy_event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
|
||||
disc->legacy_event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
|
||||
return 0;
|
||||
}
|
||||
if (strlen(CONFIG_EXAMPLE_PEER_ADDR) && (strncmp(CONFIG_EXAMPLE_PEER_ADDR, "ADDR_ANY", strlen("ADDR_ANY")) != 0)) {
|
||||
// ESP_LOGI(tag, "Peer address from menuconfig: %s", CONFIG_EXAMPLE_PEER_ADDR);
|
||||
static int
|
||||
ext_blecent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
{
|
||||
int offset = 0;
|
||||
int ad_struct_len = 0;
|
||||
uint8_t test_addr[6];
|
||||
uint32_t peer_addr[6];
|
||||
uint8_t phy_uuid_found = 0;
|
||||
if (disc->legacy_event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
|
||||
disc->legacy_event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
|
||||
return 0;
|
||||
}
|
||||
if (strlen(CONFIG_EXAMPLE_PEER_ADDR) && (strncmp(CONFIG_EXAMPLE_PEER_ADDR, "ADDR_ANY", strlen("ADDR_ANY")) != 0)) {
|
||||
// ESP_LOGI(tag, "Peer address from menuconfig: %s", CONFIG_EXAMPLE_PEER_ADDR);
|
||||
/* Convert string to address */
|
||||
sscanf(CONFIG_EXAMPLE_PEER_ADDR, "%lx:%lx:%lx:%lx:%lx:%lx",
|
||||
&peer_addr[5], &peer_addr[4], &peer_addr[3],
|
||||
@@ -587,32 +587,48 @@ blecent_scan(void)
|
||||
for (int i=0; i<6; i++) {
|
||||
test_addr[5 - i] = (uint8_t )peer_addr[i];
|
||||
}
|
||||
if (memcmp(test_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (memcmp(test_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* The device has to advertise support LE PHY UUID (0xABF2).
|
||||
*/
|
||||
do {
|
||||
if (offset + 1 >= (int)disc->length_data) {
|
||||
break;
|
||||
}
|
||||
ad_struct_len = disc->data[offset];
|
||||
if (!ad_struct_len || offset + ad_struct_len + 1 > (int)disc->length_data) {
|
||||
break;
|
||||
/* The device has to advertise support LE PHY UUID (0xABF2).
|
||||
*/
|
||||
do {
|
||||
ad_struct_len = disc->data[offset];
|
||||
|
||||
if (!ad_struct_len) {
|
||||
break;
|
||||
}
|
||||
/* Search for Complete Local Name (AD type 0x09) */
|
||||
if (disc->data[offset + 1] == 0x09 && phy_uuid_found) {
|
||||
int name_len = disc->data[offset] - 1; /* Length minus type byte */
|
||||
char serv_name[] = "nimble_prph";
|
||||
if (name_len > 0) {
|
||||
ESP_LOGI(tag, "Device Name = %.*s",name_len, (char *)&disc->data[offset + 2]);
|
||||
if (name_len == strlen(serv_name) &&
|
||||
memcmp(&disc->data[offset + 2], serv_name, name_len) == 0) {
|
||||
ESP_LOGI(tag, "central connect to `nimble_prph` success");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Search if LE PHY UUID is advertised */
|
||||
if (disc->data[offset] == 0x03 && disc->data[offset + 1] == 0x03 &&
|
||||
offset + 3 < (int)disc->length_data &&
|
||||
disc->data[offset + 2] == 0xAB && disc->data[offset + 3] == 0xF2) {
|
||||
return 1;
|
||||
if (disc->data[offset] == 0x03 && disc->data[offset + 1] == 0x03) {
|
||||
if ( disc->data[offset + 2] == 0xAB && disc->data[offset + 3] == 0xF2 ) {
|
||||
phy_uuid_found = 1;
|
||||
}
|
||||
}
|
||||
offset += ad_struct_len + 1;
|
||||
} while (offset < (int)disc->length_data);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
offset += ad_struct_len + 1;
|
||||
|
||||
} while ( offset < disc->length_data );
|
||||
|
||||
return phy_uuid_found;
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* Indicates whether we should try to connect to the sender of the specified
|
||||
* advertisement. The function returns a positive result if the device
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
static uint8_t ext_adv_pattern[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x03, 0x03, 0xab, 0xcd,
|
||||
0x03, 0x03, 0xAB, 0xF2,
|
||||
0x0e, 0X09, 'n', 'i', 'm', 'b', 'l', 'e', '-', 'b', 'l', 'e', 'p', 'r', 'p', 'h'
|
||||
0x02, BLE_HS_ADV_TYPE_FLAGS, 0x06,
|
||||
0x03, BLE_HS_ADV_TYPE_COMP_UUIDS16, 0xab, 0xcd,
|
||||
0x03, BLE_HS_ADV_TYPE_COMP_UUIDS16, 0xAB, 0xF2,
|
||||
0x0c, BLE_HS_ADV_TYPE_COMP_NAME, 'n', 'i', 'm', 'b', 'l', 'e', '_', 'p', 'r', 'p', 'h'
|
||||
};
|
||||
|
||||
static uint8_t s_current_phy;
|
||||
|
||||
Reference in New Issue
Block a user