@@ -375,25 +375,21 @@ ble_error_t GenericSecurityManager::setLinkEncryption(
375
375
return BLE_ERROR_OPERATION_NOT_PERMITTED;
376
376
}
377
377
378
- /* ignore if the link is already at required state*/
379
378
if (current_encryption == encryption) {
380
- eventHandler->linkEncryptionResult (connection, current_encryption);
381
- return BLE_ERROR_NONE;
382
- }
383
379
384
- if (encryption == link_encryption_t ::NOT_ENCRYPTED) {
380
+ /* ignore if the link is already at required state */
385
381
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 */
387
385
388
386
} else if (encryption == link_encryption_t ::ENCRYPTED) {
389
387
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) ;
394
392
}
395
- cb->encryption_requested = true ;
396
- return enable_encryption (connection);
397
393
398
394
} else if (encryption == link_encryption_t ::ENCRYPTED_WITH_MITM) {
399
395
@@ -409,6 +405,8 @@ ble_error_t GenericSecurityManager::setLinkEncryption(
409
405
return BLE_ERROR_INVALID_PARAM;
410
406
}
411
407
408
+ eventHandler->linkEncryptionResult (connection, current_encryption);
409
+
412
410
return BLE_ERROR_NONE;
413
411
}
414
412
0 commit comments