Merge pull request #9399 from paul-szczepanek-arm/fix-null-check

BLE: fix missing null checks on Gap event handler
pull/9421/head
Martin Kojtal 2019-01-21 13:43:16 +01:00 committed by GitHub
commit 4019efb21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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]
*/
@ -1784,7 +1788,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) {
_eventHandler->onUpdateConnectionParametersRequest(
UpdateConnectionParametersRequestEvent(
e.connection_handle,
conn_interval_t(e.min_connection_interval),
@ -1793,6 +1798,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,
@ -1808,6 +1816,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,

View File

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