We have HardwareRNG, let's use it! (#10274)
This commit is contained in:
co-authored by
GitHub
parent
48747ee43d
commit
031f332ec1
@@ -1,6 +1,7 @@
|
|||||||
#include "NRF52Bluetooth.h"
|
#include "NRF52Bluetooth.h"
|
||||||
#include "BLEDfuSecure.h"
|
#include "BLEDfuSecure.h"
|
||||||
#include "BluetoothCommon.h"
|
#include "BluetoothCommon.h"
|
||||||
|
#include "HardwareRNG.h"
|
||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
@@ -272,9 +273,13 @@ void NRF52Bluetooth::setup()
|
|||||||
Bluefruit.setTxPower(NRF52_BLE_TX_POWER);
|
Bluefruit.setTxPower(NRF52_BLE_TX_POWER);
|
||||||
#endif
|
#endif
|
||||||
if (config.bluetooth.mode != meshtastic_Config_BluetoothConfig_PairingMode_NO_PIN) {
|
if (config.bluetooth.mode != meshtastic_Config_BluetoothConfig_PairingMode_NO_PIN) {
|
||||||
configuredPasskey = config.bluetooth.mode == meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN
|
if (config.bluetooth.mode == meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN) {
|
||||||
? config.bluetooth.fixed_pin
|
configuredPasskey = config.bluetooth.fixed_pin;
|
||||||
: random(100000, 999999);
|
} else {
|
||||||
|
uint32_t hwrand = 0;
|
||||||
|
HardwareRNG::fill(reinterpret_cast<uint8_t *>(&hwrand), sizeof(hwrand));
|
||||||
|
configuredPasskey = hwrand % 900000u + 100000u;
|
||||||
|
}
|
||||||
auto pinString = std::to_string(configuredPasskey);
|
auto pinString = std::to_string(configuredPasskey);
|
||||||
LOG_INFO("Bluetooth pin set to '%i'", configuredPasskey);
|
LOG_INFO("Bluetooth pin set to '%i'", configuredPasskey);
|
||||||
Bluefruit.Security.setPIN(pinString.c_str());
|
Bluefruit.Security.setPIN(pinString.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user