mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 01:42:15 +00:00
Merge branch 'master' into xiao_esp32c6_with_ble
This commit is contained in:
commit
6e012f4774
@ -450,7 +450,6 @@ bool NodeDB::factoryReset(bool eraseBleBonds)
|
|||||||
nvs_flash_erase();
|
nvs_flash_erase();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARCH_NRF52
|
#ifdef ARCH_NRF52
|
||||||
Bluefruit.begin();
|
|
||||||
LOG_INFO("Clear bluetooth bonds!");
|
LOG_INFO("Clear bluetooth bonds!");
|
||||||
bond_print_list(BLE_GAP_ROLE_PERIPH);
|
bond_print_list(BLE_GAP_ROLE_PERIPH);
|
||||||
bond_print_list(BLE_GAP_ROLE_CENTRAL);
|
bond_print_list(BLE_GAP_ROLE_CENTRAL);
|
||||||
|
@ -210,17 +210,8 @@ void NRF52Bluetooth::shutdown()
|
|||||||
{
|
{
|
||||||
// Shutdown bluetooth for minimum power draw
|
// Shutdown bluetooth for minimum power draw
|
||||||
LOG_INFO("Disable NRF52 bluetooth");
|
LOG_INFO("Disable NRF52 bluetooth");
|
||||||
uint8_t connection_num = Bluefruit.connected();
|
Bluefruit.Security.setPairPasskeyCallback(NRF52Bluetooth::onUnwantedPairing); // Actively refuse (during factory reset)
|
||||||
if (connection_num) {
|
disconnect();
|
||||||
for (uint8_t i = 0; i < connection_num; i++) {
|
|
||||||
LOG_INFO("NRF52 bluetooth disconnecting handle %d", i);
|
|
||||||
Bluefruit.disconnect(i);
|
|
||||||
}
|
|
||||||
// Wait for disconnection
|
|
||||||
while (Bluefruit.connected())
|
|
||||||
yield();
|
|
||||||
LOG_INFO("All bluetooth connections ended");
|
|
||||||
}
|
|
||||||
Bluefruit.Advertising.stop();
|
Bluefruit.Advertising.stop();
|
||||||
}
|
}
|
||||||
void NRF52Bluetooth::startDisabled()
|
void NRF52Bluetooth::startDisabled()
|
||||||
@ -372,6 +363,33 @@ bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passke
|
|||||||
LOG_INFO("BLE passkey pair: match_request=%i", match_request);
|
LOG_INFO("BLE passkey pair: match_request=%i", match_request);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actively refuse new BLE pairings
|
||||||
|
// After clearing bonds (at factory reset), clients seem initially able to attempt to re-pair, even with advertising disabled.
|
||||||
|
// On NRF52Bluetooth::shutdown, we change the pairing callback to this method, to aggressively refuse any connection attempts.
|
||||||
|
bool NRF52Bluetooth::onUnwantedPairing(uint16_t conn_handle, uint8_t const passkey[6], bool match_request)
|
||||||
|
{
|
||||||
|
NRF52Bluetooth::disconnect();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disconnect any BLE connections
|
||||||
|
void NRF52Bluetooth::disconnect()
|
||||||
|
{
|
||||||
|
uint8_t connection_num = Bluefruit.connected();
|
||||||
|
if (connection_num) {
|
||||||
|
// Close all connections. We're only expecting one.
|
||||||
|
for (uint8_t i = 0; i < connection_num; i++)
|
||||||
|
Bluefruit.disconnect(i);
|
||||||
|
|
||||||
|
// Wait for disconnection
|
||||||
|
while (Bluefruit.connected())
|
||||||
|
yield();
|
||||||
|
|
||||||
|
LOG_INFO("Ended BLE connection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NRF52Bluetooth::onPairingCompleted(uint16_t conn_handle, uint8_t auth_status)
|
void NRF52Bluetooth::onPairingCompleted(uint16_t conn_handle, uint8_t auth_status)
|
||||||
{
|
{
|
||||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||||
|
@ -19,4 +19,7 @@ class NRF52Bluetooth : BluetoothApi
|
|||||||
static void onConnectionSecured(uint16_t conn_handle);
|
static void onConnectionSecured(uint16_t conn_handle);
|
||||||
static bool onPairingPasskey(uint16_t conn_handle, uint8_t const passkey[6], bool match_request);
|
static bool onPairingPasskey(uint16_t conn_handle, uint8_t const passkey[6], bool match_request);
|
||||||
static void onPairingCompleted(uint16_t conn_handle, uint8_t auth_status);
|
static void onPairingCompleted(uint16_t conn_handle, uint8_t auth_status);
|
||||||
|
|
||||||
|
static bool onUnwantedPairing(uint16_t conn_handle, uint8_t const passkey[6], bool match_request);
|
||||||
|
static void disconnect();
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user