mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(nimble): Fix issues found in review for nimble examples
This commit is contained in:
@@ -206,16 +206,17 @@ ext_ble_cts_cent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
{
|
||||
int offset = 0;
|
||||
int ad_struct_len = 0;
|
||||
uint8_t test_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) {
|
||||
uint8_t test_addr[6] = {0};
|
||||
if (!(disc->props & BLE_HCI_ADV_CONN_MASK)) {
|
||||
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 */
|
||||
peer_addr_parse(CONFIG_EXAMPLE_PEER_ADDR, test_addr);
|
||||
/* Convert string to address */
|
||||
if (peer_addr_parse(CONFIG_EXAMPLE_PEER_ADDR, test_addr) != 6) {
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(test_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -224,17 +225,24 @@ ext_ble_cts_cent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
/* The device has to advertise support for the CTS
|
||||
* service (0x1805).
|
||||
*/
|
||||
do {
|
||||
while (offset < disc->length_data) {
|
||||
if (offset + 1 >= disc->length_data) {
|
||||
break;
|
||||
}
|
||||
ad_struct_len = disc->data[offset];
|
||||
|
||||
if (!ad_struct_len) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (offset + ad_struct_len >= disc->length_data) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Search if cts UUID is advertised */
|
||||
if (disc->data[offset + 1] == 0x03) {
|
||||
int temp = 2;
|
||||
while (temp < ad_struct_len) {
|
||||
while (temp < ad_struct_len && (offset + temp + 1) < disc->length_data) {
|
||||
if(disc->data[offset + temp] == 0x05 &&
|
||||
disc->data[offset + temp + 1] == 0x18) {
|
||||
return 1;
|
||||
@@ -243,7 +251,7 @@ ext_ble_cts_cent_should_connect(const struct ble_gap_ext_disc_desc *disc)
|
||||
}
|
||||
}
|
||||
offset += ad_struct_len + 1;
|
||||
} while ( offset < disc->length_data );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -255,7 +263,7 @@ ble_cts_cent_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
struct ble_hs_adv_fields fields;
|
||||
int rc;
|
||||
int i;
|
||||
uint8_t test_addr[6];
|
||||
uint8_t test_addr[6] = {0};
|
||||
/* The device has to be advertising connectability. */
|
||||
if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
|
||||
disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
|
||||
@@ -271,7 +279,9 @@ ble_cts_cent_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
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 */
|
||||
peer_addr_parse(CONFIG_EXAMPLE_PEER_ADDR, test_addr);
|
||||
if (peer_addr_parse(CONFIG_EXAMPLE_PEER_ADDR, test_addr) != 6) {
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(test_addr, disc->addr.val, sizeof(disc->addr.val)) != 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -326,6 +336,9 @@ ble_cts_cent_connect_if_interesting(void *disc)
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
|
||||
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||
ble_cts_cent_scan();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -343,6 +356,9 @@ ble_cts_cent_connect_if_interesting(void *disc)
|
||||
MODLOG_DFLT(ERROR, "Error: Failed to connect to device; addr_type=%d "
|
||||
"addr=%s; rc=%d\n",
|
||||
addr->type, addr_str(addr->val), rc);
|
||||
#if !(MYNEWT_VAL(BLE_HOST_ALLOW_CONNECT_WITH_SCAN))
|
||||
ble_cts_cent_scan();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -365,11 +381,13 @@ static int
|
||||
ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
struct ble_gap_conn_desc desc;
|
||||
struct ble_hs_adv_fields fields;
|
||||
int rc;
|
||||
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_DISC:
|
||||
#if !CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
{
|
||||
struct ble_hs_adv_fields fields;
|
||||
rc = ble_hs_adv_parse_fields(&fields, event->disc.data,
|
||||
event->disc.length_data);
|
||||
if (rc != 0) {
|
||||
@@ -381,6 +399,8 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
|
||||
/* Try to connect to the advertiser if it looks interesting. */
|
||||
ble_cts_cent_connect_if_interesting(&event->disc);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
@@ -597,11 +617,14 @@ app_main(void)
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
if (rc != 0) {
|
||||
ESP_LOGE(tag, "Failed to init peer tracking; rc=%d", rc);
|
||||
nimble_port_deinit();
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
|
||||
Reference in New Issue
Block a user