Skip to content
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

BLE: fix missing null checks on Gap event handler #9399

Merged
merged 2 commits into from
Jan 21, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion features/FEATURE_BLE/source/generic/GenericGap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ static const GapScanningParams default_scan_params;
static const mbed_error_status_t mixed_scan_api_error =
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_USE_INCOMPATIBLE_API);

static const mbed_error_status_t illegal_state_error =
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_ILLEGAL_STATE);


/*
* Return true if value is included in the range [lower_bound : higher_bound]
*/
Expand Down Expand Up @@ -1782,7 +1786,8 @@ void GenericGap::on_disconnection_complete(const pal::GapDisconnectionCompleteEv
void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionParameterRequestEvent &e)
{
if (_user_manage_connection_parameter_requests) {
_eventHandler->onUpdateConnectionParametersRequest(
if (_eventHandler) {
pan- marked this conversation as resolved.
Show resolved Hide resolved
_eventHandler->onUpdateConnectionParametersRequest(
UpdateConnectionParametersRequestEvent(
e.connection_handle,
conn_interval_t(e.min_connection_interval),
Expand All @@ -1791,6 +1796,9 @@ void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionP
supervision_timeout_t(e.supervision_timeout)
)
);
} else {
MBED_ERROR(illegal_state_error, "Event handler required if connection params are user handled");
}
} else {
_pal_gap.accept_connection_parameter_request(
e.connection_handle,
Expand All @@ -1806,6 +1814,10 @@ void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionP

void GenericGap::on_connection_update(const pal::GapConnectionUpdateEvent &e)
{
if (!_eventHandler) {
return;
}

_eventHandler->onConnectionParametersUpdateComplete(
ConnectionParametersUpdateCompleteEvent(
e.status == pal::hci_error_code_t::SUCCESS ? BLE_ERROR_NONE : BLE_ERROR_UNSPECIFIED,
Expand Down
1 change: 1 addition & 0 deletions platform/mbed_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ typedef enum _mbed_error_code {
MBED_DEFINE_SYSTEM_ERROR(AUTHENTICATION_FAILED, 69), /* 325 Authentication Failed */
MBED_DEFINE_SYSTEM_ERROR(RBP_AUTHENTICATION_FAILED, 70), /* 326 Rollback Protection Authentication Failed */
MBED_DEFINE_SYSTEM_ERROR(BLE_USE_INCOMPATIBLE_API, 71), /* 327 Concurrent use of incompatible versions of a BLE API */
MBED_DEFINE_SYSTEM_ERROR(BLE_ILLEGAL_STATE, 72), /* 328 BLE stack entered illegal state */

//Everytime you add a new system error code, you must update
//Error documentation under Handbook to capture the info on
Expand Down