Skip to content

Wait for scan response before reporting discovered peripheral #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libraries/CurieBLE/src/internal/BLEDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ BLEDeviceManager::BLEDeviceManager():
memset(_peer_adv_data, 0, sizeof(_peer_adv_data));
memset(_peer_adv_data_len, 0, sizeof(_peer_adv_data_len));
memset(_peer_scan_rsp_data, 0, sizeof(_peer_scan_rsp_data));
memset(_peer_scan_rsp_data_len, 0, sizeof(_peer_scan_rsp_data_len));
memset(_peer_scan_rsp_data_len, -1, sizeof(_peer_scan_rsp_data_len));
memset(_peer_adv_rssi, 0, sizeof(_peer_adv_rssi));

memset(_peer_adv_connectable, 0, sizeof(_peer_adv_connectable));
Expand Down Expand Up @@ -1370,7 +1370,7 @@ BLEDevice BLEDeviceManager::available()
{
uint64_t timestamp_delta = timestamp - _peer_adv_mill[i];
temp = &_peer_adv_buffer[i];
if ((timestamp_delta <= 2000) && (max_delta < timestamp_delta))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For non-connectable device, it doesn't have scan response. So the non-connectable device will be lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgbihu addressed via 022216a

Copy link
Contributor

@sgbihu sgbihu Mar 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandeepmistry I think some peripheral device will not give the scan response. Then those device will no be returned in available. It still has potential bugs. This is the biggest concern I have. And I spend some time to check with BLE spec and the below is I get from the BLE spec.

If the advertiser receives a SCAN_REQ PDU that contains its device address from a scanner allowed by the advertising filter policy it shall reply with a SCAN_RSP PDU on the same advertising channel index. After the SCAN_RSP PDU is sent or if the advertising filter policy prohibited processing the SCAN_REQ PDU the advertiser shall either move to the next used advertising channel index to send another ADV_SCAN_IND PDU, or close the advertising event.

if ((timestamp_delta <= 2000) && (max_delta < timestamp_delta) && (_peer_scan_rsp_data_len[i] >= 0 || !_peer_adv_connectable[i]))
{
// Eable the duplicate filter
if (_adv_duplicate_filter_enabled &&
Expand Down Expand Up @@ -1432,7 +1432,7 @@ bool BLEDeviceManager::setAdvertiseBuffer(const bt_addr_le_t* bt_addr,
if (max_delta > 2000) // expired
{
index = i;
_peer_scan_rsp_data_len[index] = 0; // Invalid the scan response
_peer_scan_rsp_data_len[index] = -1; // Invalid the scan response
}
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/CurieBLE/src/internal/BLEDeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class BLEDeviceManager
uint8_t _peer_adv_data[BLE_MAX_ADV_BUFFER_CFG][BLE_MAX_ADV_SIZE];
uint8_t _peer_adv_data_len[BLE_MAX_ADV_BUFFER_CFG];
uint8_t _peer_scan_rsp_data[BLE_MAX_ADV_BUFFER_CFG][BLE_MAX_ADV_SIZE];
uint8_t _peer_scan_rsp_data_len[BLE_MAX_ADV_BUFFER_CFG];
int8_t _peer_scan_rsp_data_len[BLE_MAX_ADV_BUFFER_CFG];
int8_t _peer_adv_rssi[BLE_MAX_ADV_BUFFER_CFG];
bool _peer_adv_connectable[BLE_MAX_ADV_BUFFER_CFG];

Expand Down