mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-25 14:17:40 +00:00
Nimble WIP fix bluetooth pairing screen
This commit is contained in:
parent
c5df1bc885
commit
66b147fb31
@ -318,40 +318,31 @@ BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoo
|
|||||||
return pServer;
|
return pServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from loop
|
// Note: these callbacks might be coming in from a different thread.
|
||||||
void loopBLE()
|
BLEServer *serve = initBLE(, , getDeviceName(), HW_VENDOR, optstr(APP_VERSION),
|
||||||
{
|
optstr(HW_VERSION)); // FIXME, use a real name based on the macaddr
|
||||||
bluetoothRebootCheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This routine is called multiple times, once each time we come back from sleep
|
|
||||||
void reinitBluetooth()
|
|
||||||
{
|
|
||||||
DEBUG_MSG("Starting bluetooth\n");
|
|
||||||
|
|
||||||
// Note: these callbacks might be coming in from a different thread.
|
|
||||||
BLEServer *serve = initBLE(
|
|
||||||
[](uint32_t pin) {
|
|
||||||
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
|
|
||||||
screen.startBluetoothPinScreen(pin);
|
|
||||||
},
|
|
||||||
[]() { screen.stopBluetoothPinScreen(); }, getDeviceName(), HW_VENDOR, optstr(APP_VERSION),
|
|
||||||
optstr(HW_VERSION)); // FIXME, use a real name based on the macaddr
|
|
||||||
createMeshBluetoothService(serve);
|
|
||||||
|
|
||||||
// Start advertising - this must be done _after_ creating all services
|
|
||||||
serve->getAdvertising()->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include "PhoneAPI.h"
|
#include "PhoneAPI.h"
|
||||||
|
#include "PowerFSM.h"
|
||||||
#include "host/util/util.h"
|
#include "host/util/util.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "nimble/NimbleDefs.h"
|
#include "nimble/NimbleDefs.h"
|
||||||
#include "services/gap/ble_svc_gap.h"
|
#include "services/gap/ble_svc_gap.h"
|
||||||
#include "services/gatt/ble_svc_gatt.h"
|
#include "services/gatt/ble_svc_gatt.h"
|
||||||
|
|
||||||
|
static void startCb(uint32_t pin)
|
||||||
|
{
|
||||||
|
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
|
||||||
|
screen.startBluetoothPinScreen(pin);
|
||||||
|
};
|
||||||
|
|
||||||
|
static void stopCb()
|
||||||
|
{
|
||||||
|
screen.stopBluetoothPinScreen();
|
||||||
|
};
|
||||||
|
|
||||||
static uint8_t own_addr_type;
|
static uint8_t own_addr_type;
|
||||||
|
|
||||||
// This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in
|
// This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in
|
||||||
@ -511,7 +502,7 @@ static int bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
|
|
||||||
case BLE_GAP_EVENT_DISCONNECT:
|
case BLE_GAP_EVENT_DISCONNECT:
|
||||||
DEBUG_MSG("disconnect; reason=%d ", event->disconnect.reason);
|
DEBUG_MSG("disconnect; reason=%d ", event->disconnect.reason);
|
||||||
// bleprph_print_conn_desc(&event->disconnect.conn);
|
print_conn_desc(&event->disconnect.conn);
|
||||||
DEBUG_MSG("\n");
|
DEBUG_MSG("\n");
|
||||||
|
|
||||||
/* Connection terminated; resume advertising. */
|
/* Connection terminated; resume advertising. */
|
||||||
@ -523,7 +514,7 @@ static int bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
DEBUG_MSG("connection updated; status=%d ", event->conn_update.status);
|
DEBUG_MSG("connection updated; status=%d ", event->conn_update.status);
|
||||||
rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
|
rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
// bleprph_print_conn_desc(&desc);
|
print_conn_desc(&desc);
|
||||||
DEBUG_MSG("\n");
|
DEBUG_MSG("\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -537,8 +528,11 @@ static int bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
DEBUG_MSG("encryption change event; status=%d ", event->enc_change.status);
|
DEBUG_MSG("encryption change event; status=%d ", event->enc_change.status);
|
||||||
rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
|
rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
// bleprph_print_conn_desc(&desc);
|
print_conn_desc(&desc);
|
||||||
DEBUG_MSG("\n");
|
DEBUG_MSG("\n");
|
||||||
|
|
||||||
|
// Remove our custom PIN request screen.
|
||||||
|
stopCb();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case BLE_GAP_EVENT_SUBSCRIBE:
|
case BLE_GAP_EVENT_SUBSCRIBE:
|
||||||
@ -576,12 +570,16 @@ static int bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
|
|
||||||
if (event->passkey.params.action == BLE_SM_IOACT_DISP) {
|
if (event->passkey.params.action == BLE_SM_IOACT_DISP) {
|
||||||
pkey.action = event->passkey.params.action;
|
pkey.action = event->passkey.params.action;
|
||||||
pkey.passkey = 123456; // This is the passkey to be entered on peer
|
pkey.passkey = random(
|
||||||
DEBUG_MSG("Enter passkey %d on the peer side", pkey.passkey);
|
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);
|
||||||
|
|
||||||
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
|
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
|
||||||
DEBUG_MSG("ble_sm_inject_io result: %d\n", rc);
|
DEBUG_MSG("ble_sm_inject_io result: %d\n", rc);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_MSG("FIXME - unexpected auth type\n");
|
DEBUG_MSG("FIXME - unexpected auth type %d\n", event->passkey.params.action);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,6 @@ void dumpCharacteristic(BLECharacteristic *c);
|
|||||||
/** converting endianness pull out a 32 bit value */
|
/** converting endianness pull out a 32 bit value */
|
||||||
uint32_t getValue32(BLECharacteristic *c, uint32_t defaultValue);
|
uint32_t getValue32(BLECharacteristic *c, uint32_t defaultValue);
|
||||||
|
|
||||||
// TODO(girts): create a class for the bluetooth utils helpers?
|
|
||||||
using StartBluetoothPinScreenCallback = std::function<void(uint32_t pass_key)>;
|
|
||||||
using StopBluetoothPinScreenCallback = std::function<void(void)>;
|
|
||||||
|
|
||||||
BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoothPinScreenCallback stopBtPinScreen,
|
BLEServer *initBLE(StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoothPinScreenCallback stopBtPinScreen,
|
||||||
std::string devName, std::string hwVendor, std::string swVersion, std::string hwVersion = "");
|
std::string devName, std::string hwVendor, std::string swVersion, std::string hwVersion = "");
|
||||||
|
|
||||||
@ -36,6 +32,10 @@ extern SimpleAllocator btPool;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO(girts): create a class for the bluetooth utils helpers?
|
||||||
|
using StartBluetoothPinScreenCallback = std::function<void(uint32_t pass_key)>;
|
||||||
|
using StopBluetoothPinScreenCallback = std::function<void(void)>;
|
||||||
|
|
||||||
/// Given a level between 0-100, update the BLE attribute
|
/// Given a level between 0-100, update the BLE attribute
|
||||||
void updateBatteryLevel(uint8_t level);
|
void updateBatteryLevel(uint8_t level);
|
||||||
void deinitBLE();
|
void deinitBLE();
|
||||||
|
Loading…
Reference in New Issue
Block a user