Skip to content

Commit 78a115b

Browse files
enabled privacy in the example
1 parent 6c23d9c commit 78a115b

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

BLE_SM/source/main.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,30 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
189189
printf("Error during preserveBondingStateOnReset %d\r\n", error);
190190
}
191191

192+
#if MBED_CONF_APP_FILESYSTEM_SUPPORT
193+
/* Enable privacy so we can find the keys */
194+
error = _ble.gap().enablePrivacy(true);
195+
196+
if (error) {
197+
printf("Error enabling privacy\r\n");
198+
}
199+
200+
Gap::PeripheralPrivacyConfiguration_t configuration_p = {
201+
/* use_non_resolvable_random_address */ false,
202+
Gap::PeripheralPrivacyConfiguration_t::REJECT_NON_RESOLVED_ADDRESS
203+
};
204+
_ble.gap().setPeripheralPrivacyConfiguration(&configuration_p);
205+
206+
Gap::CentralPrivacyConfiguration_t configuration_c = {
207+
/* use_non_resolvable_random_address */ false,
208+
Gap::CentralPrivacyConfiguration_t::RESOLVE_AND_FORWARD
209+
};
210+
_ble.gap().setCentralPrivacyConfiguration(&configuration_c);
211+
212+
/* this demo switches between being master and slave */
213+
_ble.securityManager().setHintFutureRoleReversal(true);
214+
#endif
215+
192216
/* Tell the security manager to use methods in this class to inform us
193217
* of any events. Class needs to implement SecurityManagerEventHandler. */
194218
_ble.securityManager().setSecurityManagerEventHandler(this);
@@ -362,9 +386,6 @@ class SMDeviceCentral : public SMDevice {
362386
printf("Error during Gap::startScan %d\r\n", error);
363387
return;
364388
}
365-
366-
/* send our keys since we will be a peripheral next */
367-
_ble.securityManager().setHintFutureRoleReversal(true);
368389
}
369390

370391
/** Look at scan payload to find a peer device and connect to it */
@@ -379,7 +400,7 @@ class SMDeviceCentral : public SMDevice {
379400
if (memcmp(params->peerAddr, _peer_address, sizeof(_peer_address)) == 0) {
380401

381402
ble_error_t error = _ble.gap().connect(
382-
params->peerAddr, params->addressType,
403+
params->peerAddr, params->peerAddrType,
383404
NULL, NULL
384405
);
385406

0 commit comments

Comments
 (0)