Skip to content

Fix for issue #4158: BLEAdvertising - Crash with stack trace originating in Bluedroid #4182

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
merged 4 commits into from
Nov 2, 2020
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
17 changes: 12 additions & 5 deletions libraries/BLE/src/BLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
* @brief Construct a default advertising object.
*
*/
BLEAdvertising::BLEAdvertising() {
BLEAdvertising::BLEAdvertising()
: m_scanRespData{}
{
m_advData.set_scan_rsp = false;
m_advData.include_name = true;
m_advData.include_txpower = true;
Expand Down Expand Up @@ -215,10 +217,15 @@ void BLEAdvertising::start() {
}

if (!m_customScanResponseData && m_scanResp) {
m_advData.set_scan_rsp = true;
m_advData.include_name = m_scanResp;
m_advData.include_txpower = m_scanResp;
errRc = ::esp_ble_gap_config_adv_data(&m_advData);
// Set the configuration for scan response.
memcpy(&m_scanRespData, &m_advData, sizeof(esp_ble_adv_data_t)); // Copy the content of m_advData.
m_scanRespData.set_scan_rsp = true; // Define this struct as scan response data
m_scanRespData.include_name = true; // Caution: This may lead to a crash if the device name has more than 29 characters
m_scanRespData.include_txpower = true;
m_scanRespData.appearance = 0; // If defined the 'Appearance' attribute is already included in the advertising data
m_scanRespData.flag = 0; // 'Flags' attribute should no be included in the scan response

errRc = ::esp_ble_gap_config_adv_data(&m_scanRespData);
if (errRc != ESP_OK) {
log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
Expand Down
5 changes: 3 additions & 2 deletions libraries/BLE/src/BLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BLEAdvertisementData {
void setPartialServices(BLEUUID uuid);
void setServiceData(BLEUUID uuid, std::string data);
void setShortName(std::string name);
void addData(std::string data); // Add data to the payload.
void addData(std::string data); // Add data to the payload.
std::string getPayload(); // Retrieve the current advert payload.

private:
Expand Down Expand Up @@ -68,12 +68,13 @@ class BLEAdvertising {

private:
esp_ble_adv_data_t m_advData;
esp_ble_adv_data_t m_scanRespData; // Used for configuration of scan response data when m_scanResp is true
esp_ble_adv_params_t m_advParams;
std::vector<BLEUUID> m_serviceUUIDs;
bool m_customAdvData = false; // Are we using custom advertising data?
bool m_customScanResponseData = false; // Are we using custom scan response data?
FreeRTOS::Semaphore m_semaphoreSetAdv = FreeRTOS::Semaphore("startAdvert");
bool m_scanResp = true;
bool m_scanResp = true;

};
#endif /* CONFIG_BT_ENABLED */
Expand Down