Skip to content

Commit b89f9f2

Browse files
added callback on encryption request even if lower and restructured for clarity
1 parent e8f29f7 commit b89f9f2

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -375,25 +375,21 @@ ble_error_t GenericSecurityManager::setLinkEncryption(
375375
return BLE_ERROR_OPERATION_NOT_PERMITTED;
376376
}
377377

378-
/* ignore if the link is already at required state*/
379378
if (current_encryption == encryption) {
380-
eventHandler->linkEncryptionResult(connection, current_encryption);
381-
return BLE_ERROR_NONE;
382-
}
383379

384-
if (encryption == link_encryption_t::NOT_ENCRYPTED) {
380+
/* ignore if the link is already at required state*/
385381

386-
return BLE_ERROR_INVALID_STATE;
382+
} else if (encryption == link_encryption_t::NOT_ENCRYPTED) {
383+
384+
/* ignore if we are requesting an open link on an already encrypted link */
387385

388386
} else if (encryption == link_encryption_t::ENCRYPTED) {
389387

390-
/* if already better than encrypted don't bother */
391-
if (current_encryption == link_encryption_t::ENCRYPTED_WITH_MITM) {
392-
eventHandler->linkEncryptionResult(connection, current_encryption);
393-
return BLE_ERROR_NONE;
388+
/* only change if we're not already encrypted with mitm */
389+
if (current_encryption != link_encryption_t::ENCRYPTED_WITH_MITM) {
390+
cb->encryption_requested = true;
391+
return enable_encryption(connection);
394392
}
395-
cb->encryption_requested = true;
396-
return enable_encryption(connection);
397393

398394
} else if (encryption == link_encryption_t::ENCRYPTED_WITH_MITM) {
399395

@@ -409,6 +405,8 @@ ble_error_t GenericSecurityManager::setLinkEncryption(
409405
return BLE_ERROR_INVALID_PARAM;
410406
}
411407

408+
eventHandler->linkEncryptionResult(connection, current_encryption);
409+
412410
return BLE_ERROR_NONE;
413411
}
414412

0 commit comments

Comments
 (0)