Skip to content

Commit 4019efb

Browse files
authored
Merge pull request #9399 from paul-szczepanek-arm/fix-null-check
BLE: fix missing null checks on Gap event handler
2 parents 5c46fae + 42e4290 commit 4019efb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ static const GapScanningParams default_scan_params;
6464
static const mbed_error_status_t mixed_scan_api_error =
6565
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_USE_INCOMPATIBLE_API);
6666

67+
static const mbed_error_status_t illegal_state_error =
68+
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_ILLEGAL_STATE);
69+
70+
6771
/*
6872
* Return true if value is included in the range [lower_bound : higher_bound]
6973
*/
@@ -1784,7 +1788,8 @@ void GenericGap::on_disconnection_complete(const pal::GapDisconnectionCompleteEv
17841788
void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionParameterRequestEvent &e)
17851789
{
17861790
if (_user_manage_connection_parameter_requests) {
1787-
_eventHandler->onUpdateConnectionParametersRequest(
1791+
if (_eventHandler) {
1792+
_eventHandler->onUpdateConnectionParametersRequest(
17881793
UpdateConnectionParametersRequestEvent(
17891794
e.connection_handle,
17901795
conn_interval_t(e.min_connection_interval),
@@ -1793,6 +1798,9 @@ void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionP
17931798
supervision_timeout_t(e.supervision_timeout)
17941799
)
17951800
);
1801+
} else {
1802+
MBED_ERROR(illegal_state_error, "Event handler required if connection params are user handled");
1803+
}
17961804
} else {
17971805
_pal_gap.accept_connection_parameter_request(
17981806
e.connection_handle,
@@ -1808,6 +1816,10 @@ void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionP
18081816

18091817
void GenericGap::on_connection_update(const pal::GapConnectionUpdateEvent &e)
18101818
{
1819+
if (!_eventHandler) {
1820+
return;
1821+
}
1822+
18111823
_eventHandler->onConnectionParametersUpdateComplete(
18121824
ConnectionParametersUpdateCompleteEvent(
18131825
e.status == pal::hci_error_code_t::SUCCESS ? BLE_ERROR_NONE : BLE_ERROR_UNSPECIFIED,

platform/mbed_error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ typedef enum _mbed_error_code {
792792
MBED_DEFINE_SYSTEM_ERROR(AUTHENTICATION_FAILED, 69), /* 325 Authentication Failed */
793793
MBED_DEFINE_SYSTEM_ERROR(RBP_AUTHENTICATION_FAILED, 70), /* 326 Rollback Protection Authentication Failed */
794794
MBED_DEFINE_SYSTEM_ERROR(BLE_USE_INCOMPATIBLE_API, 71), /* 327 Concurrent use of incompatible versions of a BLE API */
795+
MBED_DEFINE_SYSTEM_ERROR(BLE_ILLEGAL_STATE, 72), /* 328 BLE stack entered illegal state */
795796

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

0 commit comments

Comments
 (0)