Fix for issue #4158: BLEAdvertising - Crash with stack trace originating in Bluedroid #4182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed Issue:
#4158
Summary of the Problem:
After calling
BLEAdvertising::start()
, a crash with a stack trace originating in Bluedroid occurs.This crash occurs when the payload size of the scan response message exceeds 31 bytes.
Apparently, Bluedroid does not account for the attributes 'Flags' and 'Appearance' being set in the scan response data.
Solution:
Improved configuration of scan response data in
BLEAdvertising::start()
avoids the crash:m_scanRespData
to be able to configure the scan response data differently from the advertising data.m_scanRespData
in BLEAdvertising constructor.m_scanRespData
withinBLEAdvertising::start()
to configure the scan response data.BLEAdvertising::start()
, the content ofm_advData
is copied intom_scanRespData
, and then 'Flags' and 'Appearance' are cleared inm_scanRespData
.Result:
With this fix, device names of up to 29 characters can be used without causing a crash.
Further Considerations:
m_scanRespData
accounts for the remark in the documentation ofesp_ble_gap_config_adv_data()
: 'This memory space cannot be freed until callback of config_adv_data is received'.Not Solved (Future Work):
delete[] m_advData.p_service_uuid;
inBLEAdvertising::start()
might violate the condition to wait for the callback ofesp_ble_gap_config_adv_data
(see above). Yet, I did not experience problems related to this. Hence, I did not change this code.