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:
BeardyWalrus
2020-10-03 17:02:17 -04:00
parent 7d6dbcfa3f
commit 530432411e
4 changed files with 31 additions and 10 deletions

View File

@@ -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;
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("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_io_cap = BLE_SM_IO_CAP_DISP_ONLY;
ble_hs_cfg.sm_bonding = 1;
ble_hs_cfg.sm_mitm = 1;
ble_hs_cfg.sm_sc = 1;