mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-05-11 02:55:01 -04:00
Merge branch 'master' of github.com:markqvist/RNode_Firmware
This commit is contained in:
commit
e8e6e2bcbf
1 changed files with 27 additions and 10 deletions
37
Bluetooth.h
37
Bluetooth.h
|
@ -38,6 +38,7 @@
|
||||||
BLEUart SerialBT(BLE_RX_BUF);
|
BLEUart SerialBT(BLE_RX_BUF);
|
||||||
BLEDis bledis;
|
BLEDis bledis;
|
||||||
BLEBas blebas;
|
BLEBas blebas;
|
||||||
|
bool SerialBT_init = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BT_PAIRING_TIMEOUT 35000
|
#define BT_PAIRING_TIMEOUT 35000
|
||||||
|
@ -374,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() {
|
||||||
|
@ -427,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;
|
||||||
}
|
}
|
||||||
|
@ -454,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
|
||||||
|
@ -468,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
|
||||||
|
@ -477,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
|
||||||
|
@ -511,12 +525,14 @@ char bt_devname[11];
|
||||||
// start device information service
|
// start device information service
|
||||||
bledis.begin();
|
bledis.begin();
|
||||||
|
|
||||||
SerialBT.bufferTXD(true); // enable buffering
|
// Guard to ensure SerialBT service is not duplicated through BT being power cycled
|
||||||
|
if (!SerialBT_init) {
|
||||||
|
SerialBT.bufferTXD(true); // enable buffering
|
||||||
|
|
||||||
SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
|
SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
|
||||||
SerialBT.begin();
|
SerialBT.begin();
|
||||||
|
SerialBT_init = true;
|
||||||
blebas.begin();
|
}
|
||||||
|
|
||||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||||
Bluefruit.Advertising.addTxPower();
|
Bluefruit.Advertising.addTxPower();
|
||||||
|
@ -549,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