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

* Fix for issue #4158: Crash with stack trace originating in Bluedroid
Improved configuration of scan response data in 'BLEAdvertising' avoids the crash:
- Added member variable 'm_scanRespData' to configure scan response differently from advertising data
- Initialization of 'm_scanRespData' in BLEAdvertising constructor
- Use of 'm_scanRespData' within BLEAdvertising::start() to configure the scan response
- 'Flags' and 'Appearance' are cleared in the scan response data
- With this fix, device names of up to 29 characters can be used without causing a crash.
This commit is contained in:
Ernst Sikora 2020-11-02 18:39:20 +01:00 committed by GitHub
parent f57c36782f
commit 7c0572172c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -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;
@ -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;

View File

@ -68,6 +68,7 @@ public:
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?