Skip to content

Commit 69e35c4

Browse files
author
Donatien Garnier
committed
Handle resolution policy for peripheral in GenericGap
1 parent 21471bb commit 69e35c4

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <algorithm>
1818
#include <stdint.h>
1919

20+
#include "ble/BLEInstanceBase.h"
2021
#include "ble/BLEProtocol.h"
2122
#include "ble/Gap.h"
2223
#include "ble/pal/PalGap.h"
@@ -1120,6 +1121,37 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
11201121
// TODO: deprecate ownAddrType and ownAddr, those are not specified
11211122
// from the Bluetooth perspective
11221123
if (e.status == pal::hci_error_code_t::SUCCESS) {
1124+
bool needs_pairing = false;
1125+
bool needs_authentication = false;
1126+
1127+
if(_privacy_enabled && (e.role.value() == e.role.SLAVE)) {
1128+
// Apply privacy policy if in peripheral mode for non-resolved addresses
1129+
RandomAddressType_t random_address_type(RandomAddressType_t::RESOLVABLE_PRIVATE);
1130+
ble_error_t ret = getRandomAddressType(e.peer_address.data(), &random_address_type);
1131+
if((ret != BLE_ERROR_NONE)
1132+
|| (random_address_type == RandomAddressType_t::RESOLVABLE_PRIVATE))
1133+
{
1134+
switch(_peripheral_privacy_configuration.resolution_strategy)
1135+
{
1136+
case PeripheralPrivacyConfiguration_t::REJECT_NON_RESOLVED_ADDRESS:
1137+
// Reject connection request - the user will get notified through a callback
1138+
_pal_gap.disconnect(e.connection_handle, pal::disconnection_reason_t::AUTHENTICATION_FAILLURE);
1139+
return;
1140+
1141+
case PeripheralPrivacyConfiguration_t::PERFORM_PAIRING_PROCEDURE:
1142+
needs_pairing = true;
1143+
break;
1144+
1145+
case PeripheralPrivacyConfiguration_t::PERFORM_AUTHENTICATION_PROCEDURE:
1146+
needs_authentication = true;
1147+
break;
1148+
1149+
default:
1150+
break;
1151+
}
1152+
}
1153+
}
1154+
11231155
if (e.role.value() == e.role.SLAVE) {
11241156
_advertising_timeout.detach();
11251157
_pal_gap.advertising_enable(false);
@@ -1149,7 +1181,17 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
11491181
address.data(),
11501182
&connection_params
11511183
);
1152-
} else {
1184+
1185+
// Now starts pairing or authentication procedures if required
1186+
if(needs_pairing) {
1187+
SecurityManager &sm = createBLEInstance()->getSecurityManager();
1188+
sm.requestPairing(e.connection_handle);
1189+
}
1190+
else if(needs_authentication) {
1191+
SecurityManager &sm = createBLEInstance()->getSecurityManager();
1192+
sm.requestAuthentication(e.connection_handle);
1193+
}
1194+
} else {
11531195
// for now notify user that the connection failled by issuing a timeout
11541196
// event
11551197

0 commit comments

Comments
 (0)