mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-09 06:41:59 +00:00
revised fix for #357
Now supports default password for devices with no display, and override with double press of user button
This commit is contained in:
parent
7d6dbcfa3f
commit
530432411e
@ -422,3 +422,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#define GPS_POWER_CTRL_CH 3
|
||||
#define LORA_POWER_CTRL_CH 2
|
||||
|
||||
// Default Bluetooth PIN
|
||||
#define defaultBLEPin 123456
|
||||
|
@ -150,6 +150,10 @@ void userButtonPressedLong()
|
||||
{
|
||||
screen.adjustBrightness();
|
||||
}
|
||||
void userButtonDoublePressed()
|
||||
{
|
||||
disablePin();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -189,11 +193,13 @@ void setup()
|
||||
userButton = OneButton(BUTTON_PIN, true, true);
|
||||
userButton.attachClick(userButtonPressed);
|
||||
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||
userButton.attachDoubleClick(userButtonDoublePressed);
|
||||
#endif
|
||||
#ifdef BUTTON_PIN_ALT
|
||||
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
|
||||
userButtonAlt.attachClick(userButtonPressed);
|
||||
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||
userButton.attachDoubleClick(userButtonDoublePressed);
|
||||
#endif
|
||||
#ifdef LED_PIN
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "meshwifi/meshwifi.h"
|
||||
|
||||
static bool pinShowing;
|
||||
static uint32_t doublepressed;
|
||||
|
||||
static void startCb(uint32_t pin)
|
||||
{
|
||||
@ -123,6 +124,7 @@ static int gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
struct ble_gap_conn_desc desc;
|
||||
int rc;
|
||||
uint32_t now = millis();
|
||||
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
@ -221,8 +223,17 @@ static int gap_event(struct ble_gap_event *event, void *arg)
|
||||
|
||||
if (event->passkey.params.action == BLE_SM_IOACT_DISP) {
|
||||
pkey.action = event->passkey.params.action;
|
||||
DEBUG_MSG("dp: %d now:%d\n",doublepressed, now);
|
||||
if ((doublepressed > 0 && (doublepressed + (30*1000)) > now) || ssd1306_found != true)
|
||||
{
|
||||
DEBUG_MSG("User has overridden passkey or no display available\n");
|
||||
pkey.passkey = defaultBLEPin;
|
||||
}
|
||||
else {
|
||||
DEBUG_MSG("Using random passkey\n");
|
||||
pkey.passkey = random(
|
||||
100000, 999999); // This is the passkey to be entered on peer - we pick a number >100,000 to ensure 6 digits
|
||||
}
|
||||
DEBUG_MSG("*** Enter passkey %d on the peer side ***\n", pkey.passkey);
|
||||
|
||||
startCb(pkey.passkey);
|
||||
@ -443,6 +454,13 @@ int chr_readwrite8(uint8_t *v, size_t vlen, struct ble_gatt_access_ctxt *ctxt)
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
void disablePin()
|
||||
{
|
||||
DEBUG_MSG("User Override, disabling bluetooth pin requirement\n");
|
||||
// keep track of when it was pressed, so we know it was within X seconds
|
||||
doublepressed = millis();
|
||||
}
|
||||
|
||||
// This routine is called multiple times, once each time we come back from sleep
|
||||
void reinitBluetooth()
|
||||
{
|
||||
@ -472,14 +490,7 @@ void reinitBluetooth()
|
||||
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
if (ssd1306_found == true) {
|
||||
DEBUG_MSG("Screen Found! : using display for passcode\n");
|
||||
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_DISP_ONLY;
|
||||
}
|
||||
else {
|
||||
DEBUG_MSG("No Screen Found! : disabling passcode for pairing\n");
|
||||
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO;
|
||||
}
|
||||
ble_hs_cfg.sm_bonding = 1;
|
||||
ble_hs_cfg.sm_mitm = 1;
|
||||
ble_hs_cfg.sm_sc = 1;
|
||||
|
@ -15,6 +15,7 @@ void updateBatteryLevel(uint8_t level);
|
||||
void deinitBLE();
|
||||
void loopBLE();
|
||||
void reinitBluetooth();
|
||||
void disablePin();
|
||||
|
||||
/**
|
||||
* A helper function that implements simple read and write handling for a uint32_t
|
||||
|
Loading…
Reference in New Issue
Block a user