|
17 | 17 | #include <algorithm>
|
18 | 18 | #include <stdint.h>
|
19 | 19 |
|
| 20 | +#include "ble/BLEInstanceBase.h" |
20 | 21 | #include "ble/BLEProtocol.h"
|
21 | 22 | #include "ble/Gap.h"
|
22 | 23 | #include "ble/pal/PalGap.h"
|
@@ -1120,6 +1121,37 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
|
1120 | 1121 | // TODO: deprecate ownAddrType and ownAddr, those are not specified
|
1121 | 1122 | // from the Bluetooth perspective
|
1122 | 1123 | 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 | + |
1123 | 1155 | if (e.role.value() == e.role.SLAVE) {
|
1124 | 1156 | _advertising_timeout.detach();
|
1125 | 1157 | _pal_gap.advertising_enable(false);
|
@@ -1149,7 +1181,17 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
|
1149 | 1181 | address.data(),
|
1150 | 1182 | &connection_params
|
1151 | 1183 | );
|
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 { |
1153 | 1195 | // for now notify user that the connection failled by issuing a timeout
|
1154 | 1196 | // event
|
1155 | 1197 |
|
|
0 commit comments