Skip to content

Commit 557eac0

Browse files
committed
BLE: Conditional compilation of the security manager
Depends on the role (central or peripheral), signing enabled and secure connection enabled.
1 parent 2e859cd commit 557eac0

File tree

7 files changed

+278
-86
lines changed

7 files changed

+278
-86
lines changed

connectivity/FEATURE_BLE/include/ble/SecurityManager.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class SecurityManager
247247
// Pairing
248248
//
249249

250+
#if BLE_ROLE_PERIPHERAL
250251
/**
251252
* Request application to accept or reject pairing. Application should respond by
252253
* calling the appropriate function: acceptPairingRequest or cancelPairingRequest
@@ -256,6 +257,7 @@ class SecurityManager
256257
virtual void pairingRequest(ble::connection_handle_t connectionHandle) {
257258
(void)connectionHandle;
258259
}
260+
#endif // BLE_ROLE_PERIPHERAL
259261

260262
/**
261263
* Indicate to the application that pairing has completed.
@@ -327,6 +329,7 @@ class SecurityManager
327329
(void)passkey;
328330
}
329331

332+
#if BLE_FEATURE_SECURE_CONNECTIONS
330333
/**
331334
* Indicate to the application that a confirmation is required. This is used
332335
* when the device does not have a keyboard but has a yes/no button. The device
@@ -339,6 +342,7 @@ class SecurityManager
339342
virtual void confirmationRequest(ble::connection_handle_t connectionHandle) {
340343
(void)connectionHandle;
341344
}
345+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
342346

343347
/**
344348
* Indicate to the application that a passkey is required. The application should
@@ -350,6 +354,7 @@ class SecurityManager
350354
(void)connectionHandle;
351355
}
352356

357+
#if BLE_FEATURE_SECURE_CONNECTIONS
353358
/**
354359
* Notify the application that a key was pressed by the peer during passkey entry.
355360
*
@@ -360,6 +365,7 @@ class SecurityManager
360365
(void)connectionHandle;
361366
(void)keypress;
362367
}
368+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
363369

364370
/**
365371
* Indicate to the application it needs to return legacy pairing OOB to the stack.
@@ -402,6 +408,7 @@ class SecurityManager
402408
// Keys
403409
//
404410

411+
#if BLE_FEATURE_SIGNING
405412
/**
406413
* Deliver the signing key to the application.
407414
*
@@ -414,6 +421,8 @@ class SecurityManager
414421
(void)csrk;
415422
(void)authenticated;
416423
}
424+
#endif // BLE_FEATURE_SIGNING
425+
417426
/**
418427
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
419428
* as the SecurityManager class will never delete the instance it contains.
@@ -526,6 +535,7 @@ class SecurityManager
526535
// Pairing
527536
//
528537

538+
#if BLE_ROLE_CENTRAL
529539
/**
530540
* Request pairing with the peer. Called by the master.
531541
* @note Slave can call requestAuthentication or setLinkEncryption to achieve security.
@@ -534,7 +544,9 @@ class SecurityManager
534544
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
535545
*/
536546
ble_error_t requestPairing(ble::connection_handle_t connectionHandle);
547+
#endif // BLE_ROLE_CENTRAL
537548

549+
#if BLE_ROLE_PERIPHERAL
538550
/**
539551
* Accept the pairing request. Called as a result of pairingRequest being called
540552
* on the event handler.
@@ -543,6 +555,7 @@ class SecurityManager
543555
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
544556
*/
545557
ble_error_t acceptPairingRequest(ble::connection_handle_t connectionHandle);
558+
#endif // BLE_ROLE_PERIPHERAL
546559

547560
/**
548561
* Reject pairing request if the local device is the slave or cancel an outstanding
@@ -577,6 +590,7 @@ class SecurityManager
577590
// Feature support
578591
//
579592

593+
#if BLE_FEATURE_SECURE_CONNECTIONS
580594
/**
581595
* Allow of disallow the use of legacy pairing in case the application only wants
582596
* to force the use of Secure Connections. If legacy pairing is disallowed and either
@@ -594,6 +608,7 @@ class SecurityManager
594608
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
595609
*/
596610
ble_error_t getSecureConnectionsSupport(bool *enabled);
611+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
597612

598613
////////////////////////////////////////////////////////////////////////////
599614
// Security settings
@@ -766,6 +781,7 @@ class SecurityManager
766781
*/
767782
ble_error_t setOOBDataUsage(ble::connection_handle_t connectionHandle, bool useOOB, bool OOBProvidesMITM = true);
768783

784+
#if BLE_FEATURE_SECURE_CONNECTIONS
769785
/**
770786
* Report to the stack if the passkey matches or not. Used during pairing to provide MITM protection.
771787
*
@@ -774,6 +790,7 @@ class SecurityManager
774790
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
775791
*/
776792
ble_error_t confirmationEntered(ble::connection_handle_t connectionHandle, bool confirmation);
793+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
777794

778795
/**
779796
* Supply the stack with the user entered passkey.
@@ -784,6 +801,7 @@ class SecurityManager
784801
*/
785802
ble_error_t passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey);
786803

804+
#if BLE_FEATURE_SECURE_CONNECTIONS
787805
/**
788806
* Send a notification to the peer that the user pressed a key on the local device.
789807
* @note This will only be delivered if the keypress notifications have been enabled during pairing.
@@ -793,6 +811,7 @@ class SecurityManager
793811
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
794812
*/
795813
ble_error_t sendKeypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress);
814+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
796815

797816
/**
798817
* Supply the stack with the OOB data for legacy connections.
@@ -803,6 +822,7 @@ class SecurityManager
803822
*/
804823
ble_error_t legacyPairingOobReceived(const ble::address_t *address, const ble::oob_tk_t *tk);
805824

825+
#if BLE_FEATURE_SECURE_CONNECTIONS
806826
/**
807827
* Supply the stack with the OOB data for secure connections.
808828
*
@@ -813,11 +833,13 @@ class SecurityManager
813833
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
814834
*/
815835
ble_error_t oobReceived(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm);
836+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
816837

817838
////////////////////////////////////////////////////////////////////////////
818839
// Keys
819840
//
820841

842+
#if BLE_FEATURE_SIGNING
821843
/**
822844
* Retrieves a signing key through a signingKey event.
823845
* If a signing key is not present, pairing/authentication will be attempted.
@@ -830,6 +852,7 @@ class SecurityManager
830852
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
831853
*/
832854
ble_error_t getSigningKey(ble::connection_handle_t connectionHandle, bool authenticated);
855+
#endif // BLE_FEATURE_SIGNING
833856

834857
////////////////////////////////////////////////////////////////////////////
835858
// Privacy

connectivity/FEATURE_BLE/source/SecurityManager.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ ble_error_t SecurityManager::generateWhitelistFromBondTable(::ble::whitelist_t *
5757
return impl->generateWhitelistFromBondTable(whitelist);
5858
}
5959

60+
#if BLE_ROLE_CENTRAL
6061
ble_error_t SecurityManager::requestPairing(ble::connection_handle_t connectionHandle)
6162
{
6263
return impl->requestPairing(connectionHandle);
6364
}
65+
#endif
6466

67+
#if BLE_ROLE_PERIPHERAL
6568
ble_error_t SecurityManager::acceptPairingRequest(ble::connection_handle_t connectionHandle)
6669
{
6770
return impl->acceptPairingRequest(connectionHandle);
6871
}
72+
#endif
6973

7074
ble_error_t SecurityManager::cancelPairingRequest(ble::connection_handle_t connectionHandle)
7175
{
@@ -82,6 +86,7 @@ ble_error_t SecurityManager::getPeerIdentity(ble::connection_handle_t connection
8286
return impl->getPeerIdentity(connectionHandle);
8387
}
8488

89+
#if BLE_FEATURE_SECURE_CONNECTIONS
8590
ble_error_t SecurityManager::allowLegacyPairing(bool allow)
8691
{
8792
return impl->allowLegacyPairing(allow);
@@ -91,6 +96,7 @@ ble_error_t SecurityManager::getSecureConnectionsSupport(bool *enabled)
9196
{
9297
return impl->getSecureConnectionsSupport(enabled);
9398
}
99+
#endif
94100

95101
ble_error_t SecurityManager::setIoCapability(SecurityIOCapabilities_t iocaps)
96102
{
@@ -162,35 +168,43 @@ ble_error_t SecurityManager::setOOBDataUsage(ble::connection_handle_t connection
162168
return impl->setOOBDataUsage(connectionHandle, useOOB, OOBProvidesMITM);
163169
}
164170

171+
#if BLE_FEATURE_SECURE_CONNECTIONS
165172
ble_error_t SecurityManager::confirmationEntered(ble::connection_handle_t connectionHandle, bool confirmation)
166173
{
167174
return impl->confirmationEntered(connectionHandle, confirmation);
168175
}
176+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
169177

170178
ble_error_t SecurityManager::passkeyEntered(ble::connection_handle_t connectionHandle, Passkey_t passkey)
171179
{
172180
return impl->passkeyEntered(connectionHandle, passkey);
173181
}
174182

183+
#if BLE_FEATURE_SECURE_CONNECTIONS
175184
ble_error_t SecurityManager::sendKeypressNotification(ble::connection_handle_t connectionHandle, ble::Keypress_t keypress)
176185
{
177186
return impl->sendKeypressNotification(connectionHandle, keypress);
178187
}
188+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
179189

180190
ble_error_t SecurityManager::legacyPairingOobReceived(const ble::address_t *address, const ble::oob_tk_t *tk)
181191
{
182192
return impl->legacyPairingOobReceived(address, tk);
183193
}
184194

195+
#if BLE_FEATURE_SECURE_CONNECTIONS
185196
ble_error_t SecurityManager::oobReceived(const ble::address_t *address, const ble::oob_lesc_value_t *random, const ble::oob_confirm_t *confirm)
186197
{
187198
return impl->oobReceived(address, random, confirm);
188199
}
200+
#endif // BLE_FEATURE_SECURE_CONNECTIONS
189201

202+
#if BLE_FEATURE_SIGNING
190203
ble_error_t SecurityManager::getSigningKey(ble::connection_handle_t connectionHandle, bool authenticated)
191204
{
192205
return impl->getSigningKey(connectionHandle, authenticated);
193206
}
207+
#endif // BLE_FEATURE_SIGNING
194208

195209
#if BLE_FEATURE_PRIVACY
196210
ble_error_t SecurityManager::setPrivateAddressTimeout(

0 commit comments

Comments
 (0)