mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-06-07 14:32:52 -04:00
Merge pull request #103 from jacobeva/nrf52-ble-revamp
Revamp NRF52 BLE pairing to resemble ESP32
This commit is contained in:
commit
b16772cf52
1 changed files with 19 additions and 5 deletions
24
Bluetooth.h
24
Bluetooth.h
|
@ -375,6 +375,8 @@ char bt_devname[11];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
#elif MCU_VARIANT == MCU_NRF52
|
||||||
|
uint32_t pairing_pin = 0;
|
||||||
|
|
||||||
uint8_t eeprom_read(uint32_t mapped_addr);
|
uint8_t eeprom_read(uint32_t mapped_addr);
|
||||||
|
|
||||||
void bt_stop() {
|
void bt_stop() {
|
||||||
|
@ -428,11 +430,6 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
// multiply by tens however many times needed to make numbers appear in order
|
|
||||||
bt_ssp_pin += ((int)passkey[i] - 48) * pow(10, 5-i);
|
|
||||||
}
|
|
||||||
kiss_indicate_btpin();
|
|
||||||
if (bt_allow_pairing) {
|
if (bt_allow_pairing) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -455,6 +452,17 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bt_update_passkey() {
|
||||||
|
pairing_pin = random(899999)+100000;
|
||||||
|
bt_ssp_pin = pairing_pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t bt_get_passkey() {
|
||||||
|
// Serial.println("API passkey request");
|
||||||
|
if (pairing_pin == 0) { bt_update_passkey(); }
|
||||||
|
return pairing_pin;
|
||||||
|
}
|
||||||
|
|
||||||
bool bt_setup_hw() {
|
bool bt_setup_hw() {
|
||||||
if (!bt_ready) {
|
if (!bt_ready) {
|
||||||
#if HAS_EEPROM
|
#if HAS_EEPROM
|
||||||
|
@ -469,6 +477,10 @@ char bt_devname[11];
|
||||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||||
Bluefruit.autoConnLed(false);
|
Bluefruit.autoConnLed(false);
|
||||||
if (Bluefruit.begin()) {
|
if (Bluefruit.begin()) {
|
||||||
|
uint32_t pin = bt_get_passkey();
|
||||||
|
char pin_char[6];
|
||||||
|
sprintf(pin_char,"%lu", pin);
|
||||||
|
|
||||||
Bluefruit.setTxPower(8); // Check bluefruit.h for supported values
|
Bluefruit.setTxPower(8); // Check bluefruit.h for supported values
|
||||||
Bluefruit.Security.setIOCaps(true, false, false); // display, yes; yes / no, no; keyboard, no
|
Bluefruit.Security.setIOCaps(true, false, false); // display, yes; yes / no, no; keyboard, no
|
||||||
// This device is indeed capable of yes / no through the pairing mode
|
// This device is indeed capable of yes / no through the pairing mode
|
||||||
|
@ -478,6 +490,7 @@ char bt_devname[11];
|
||||||
Bluefruit.Security.setMITM(true);
|
Bluefruit.Security.setMITM(true);
|
||||||
Bluefruit.Security.setPairPasskeyCallback(bt_passkey_callback);
|
Bluefruit.Security.setPairPasskeyCallback(bt_passkey_callback);
|
||||||
Bluefruit.Security.setSecuredCallback(bt_connect_callback);
|
Bluefruit.Security.setSecuredCallback(bt_connect_callback);
|
||||||
|
Bluefruit.Security.setPIN(pin_char);
|
||||||
Bluefruit.Periph.setDisconnectCallback(bt_disconnect_callback);
|
Bluefruit.Periph.setDisconnectCallback(bt_disconnect_callback);
|
||||||
Bluefruit.Security.setPairCompleteCallback(bt_pairing_complete);
|
Bluefruit.Security.setPairCompleteCallback(bt_pairing_complete);
|
||||||
Bluefruit.Periph.setConnInterval(6, 12); // 7.5 - 15 ms
|
Bluefruit.Periph.setConnInterval(6, 12); // 7.5 - 15 ms
|
||||||
|
@ -552,6 +565,7 @@ char bt_devname[11];
|
||||||
bt_allow_pairing = true;
|
bt_allow_pairing = true;
|
||||||
bt_pairing_started = millis();
|
bt_pairing_started = millis();
|
||||||
bt_state = BT_STATE_PAIRING;
|
bt_state = BT_STATE_PAIRING;
|
||||||
|
kiss_indicate_btpin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_bt() {
|
void update_bt() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue