mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-27 10:21:40 +00:00
Bluetooth modes (#1633)
* Formatting and comments * Esp32 bluetooth modes * Comment
This commit is contained in:
parent
86d3759f55
commit
b028af0d82
@ -103,7 +103,7 @@ debug_init_break = tbreak setup
|
|||||||
build_flags =
|
build_flags =
|
||||||
${arduino_base.build_flags} -Wall -Wextra -Isrc/platform/esp32 -lnimble -std=c++11
|
${arduino_base.build_flags} -Wall -Wextra -Isrc/platform/esp32 -lnimble -std=c++11
|
||||||
-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL
|
-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL
|
||||||
-DAXP_DEBUG_PORT=Serial -DUSE_NEW_ESP32_BLUETOOTH -DCONFIG_BT_NIMBLE_ENABLED -DCONFIG_NIMBLE_CPP_LOG_LEVEL=1
|
-DAXP_DEBUG_PORT=Serial -DUSE_NEW_ESP32_BLUETOOTH -DCONFIG_BT_NIMBLE_ENABLED -DCONFIG_NIMBLE_CPP_LOG_LEVEL=1 -DCONFIG_BT_NIMBLE_MAX_CCCDS=20
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${arduino_base.lib_deps}
|
${arduino_base.lib_deps}
|
||||||
${networking_base.lib_deps}
|
${networking_base.lib_deps}
|
||||||
|
@ -159,6 +159,7 @@ void NodeDB::installDefaultConfig()
|
|||||||
// FIXME: Default to bluetooth capability of platform as default
|
// FIXME: Default to bluetooth capability of platform as default
|
||||||
config.bluetooth.enabled = true;
|
config.bluetooth.enabled = true;
|
||||||
config.bluetooth.fixed_pin = defaultBLEPin;
|
config.bluetooth.fixed_pin = defaultBLEPin;
|
||||||
|
config.bluetooth.mode = screen_found ? Config_BluetoothConfig_PairingMode_RandomPin : Config_BluetoothConfig_PairingMode_FixedPin;
|
||||||
// for backward compat, default position flags are ALT+MSL
|
// for backward compat, default position flags are ALT+MSL
|
||||||
config.position.position_flags = (Config_PositionConfig_PositionFlags_POS_ALTITUDE | Config_PositionConfig_PositionFlags_POS_ALT_MSL);
|
config.position.position_flags = (Config_PositionConfig_PositionFlags_POS_ALTITUDE | Config_PositionConfig_PositionFlags_POS_ALT_MSL);
|
||||||
}
|
}
|
||||||
|
@ -72,13 +72,13 @@ class ESP32BluetoothFromRadioCallback : public NimBLECharacteristicCallbacks
|
|||||||
class ESP32BluetoothServerCallback : public NimBLEServerCallbacks
|
class ESP32BluetoothServerCallback : public NimBLEServerCallbacks
|
||||||
{
|
{
|
||||||
virtual uint32_t onPassKeyRequest() {
|
virtual uint32_t onPassKeyRequest() {
|
||||||
|
uint32_t passkey = config.bluetooth.fixed_pin;
|
||||||
uint32_t passkey = 0;
|
|
||||||
|
|
||||||
if (doublepressed > 0 && (doublepressed + (30 * 1000)) > millis()) {
|
if (doublepressed > 0 && (doublepressed + (30 * 1000)) > millis()) {
|
||||||
DEBUG_MSG("User has overridden passkey\n");
|
DEBUG_MSG("User has set BLE pairing mode to fixed-pin\n");
|
||||||
passkey = defaultBLEPin;
|
config.bluetooth.mode = Config_BluetoothConfig_PairingMode_FixedPin;
|
||||||
} else {
|
nodeDB.saveToDisk();
|
||||||
|
} else if (config.bluetooth.mode == Config_BluetoothConfig_PairingMode_RandomPin) {
|
||||||
DEBUG_MSG("Using random passkey\n");
|
DEBUG_MSG("Using random passkey\n");
|
||||||
// This is the passkey to be entered on peer - we pick a number >100,000 to ensure 6 digits
|
// This is the passkey to be entered on peer - we pick a number >100,000 to ensure 6 digits
|
||||||
passkey = random(100000, 999999);
|
passkey = random(100000, 999999);
|
||||||
@ -134,8 +134,15 @@ void ESP32Bluetooth::setup()
|
|||||||
NimBLEDevice::init(getDeviceName());
|
NimBLEDevice::init(getDeviceName());
|
||||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
||||||
|
|
||||||
NimBLEDevice::setSecurityAuth(true, true, true);
|
// FIXME fails in iOS
|
||||||
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY);
|
if (config.bluetooth.mode == Config_BluetoothConfig_PairingMode_NoPin) {
|
||||||
|
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_NO_INPUT_OUTPUT);
|
||||||
|
NimBLEDevice::setSecurityAuth(true, false, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NimBLEDevice::setSecurityAuth(true, true, true);
|
||||||
|
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY);
|
||||||
|
}
|
||||||
bleServer = NimBLEDevice::createServer();
|
bleServer = NimBLEDevice::createServer();
|
||||||
|
|
||||||
ESP32BluetoothServerCallback *serverCallbacks = new ESP32BluetoothServerCallback();
|
ESP32BluetoothServerCallback *serverCallbacks = new ESP32BluetoothServerCallback();
|
||||||
|
@ -130,12 +130,8 @@ void fromRadioAuthorizeCb(uint16_t conn_hdl, BLECharacteristic *chr, ble_gatts_e
|
|||||||
{
|
{
|
||||||
if (request->offset == 0) {
|
if (request->offset == 0) {
|
||||||
// If the read is long, we will get multiple authorize invocations - we only populate data on the first
|
// If the read is long, we will get multiple authorize invocations - we only populate data on the first
|
||||||
|
|
||||||
size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes);
|
size_t numBytes = bluetoothPhoneAPI->getFromRadio(fromRadioBytes);
|
||||||
|
|
||||||
// DEBUG_MSG("fromRadioAuthorizeCb numBytes=%u\n", numBytes);
|
|
||||||
// if (numBytes >= 2) DEBUG_MSG("fromRadio bytes %x %x\n", fromRadioBytes[0], fromRadioBytes[1]);
|
|
||||||
|
|
||||||
// Someone is going to read our value as soon as this callback returns. So fill it with the next message in the queue
|
// Someone is going to read our value as soon as this callback returns. So fill it with the next message in the queue
|
||||||
// or make empty if the queue is empty
|
// or make empty if the queue is empty
|
||||||
fromRadio.write(fromRadioBytes, numBytes);
|
fromRadio.write(fromRadioBytes, numBytes);
|
||||||
@ -175,17 +171,13 @@ void setupMeshService(void)
|
|||||||
|
|
||||||
fromNum.setProperties(CHR_PROPS_NOTIFY | CHR_PROPS_READ);
|
fromNum.setProperties(CHR_PROPS_NOTIFY | CHR_PROPS_READ);
|
||||||
fromNum.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); // FIXME, secure this!!!
|
fromNum.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); // FIXME, secure this!!!
|
||||||
fromNum.setFixedLen(
|
fromNum.setFixedLen(0); // Variable len (either 0 or 4) FIXME consider changing protocol so it is fixed 4 byte len, where 0 means empty
|
||||||
0); // Variable len (either 0 or 4) FIXME consider changing protocol so it is fixed 4 byte len, where 0 means empty
|
|
||||||
fromNum.setMaxLen(4);
|
fromNum.setMaxLen(4);
|
||||||
fromNum.setCccdWriteCallback(cccd_callback); // Optionally capture CCCD updates
|
fromNum.setCccdWriteCallback(cccd_callback); // Optionally capture CCCD updates
|
||||||
// We don't yet need to hook the fromNum auth callback
|
// We don't yet need to hook the fromNum auth callback
|
||||||
// fromNum.setReadAuthorizeCallback(fromNumAuthorizeCb);
|
// fromNum.setReadAuthorizeCallback(fromNumAuthorizeCb);
|
||||||
fromNum.write32(0); // Provide default fromNum of 0
|
fromNum.write32(0); // Provide default fromNum of 0
|
||||||
fromNum.begin();
|
fromNum.begin();
|
||||||
// uint8_t hrmdata[2] = {0b00000110, 0x40}; // Set the characteristic to use 8-bit values, with the sensor connected and
|
|
||||||
// detected
|
|
||||||
// hrmc.write(hrmdata, 2);
|
|
||||||
|
|
||||||
fromRadio.setProperties(CHR_PROPS_READ);
|
fromRadio.setProperties(CHR_PROPS_READ);
|
||||||
fromRadio.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); // FIXME secure this!
|
fromRadio.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); // FIXME secure this!
|
||||||
@ -202,9 +194,8 @@ void setupMeshService(void)
|
|||||||
toRadio.setFixedLen(0);
|
toRadio.setFixedLen(0);
|
||||||
toRadio.setMaxLen(512);
|
toRadio.setMaxLen(512);
|
||||||
toRadio.setBuffer(toRadioBytes, sizeof(toRadioBytes));
|
toRadio.setBuffer(toRadioBytes, sizeof(toRadioBytes));
|
||||||
toRadio.setWriteCallback(
|
// We don't call this callback via the adafruit queue, because we can safely run in the BLE context
|
||||||
toRadioWriteCb,
|
toRadio.setWriteCallback(toRadioWriteCb, false);
|
||||||
false); // We don't call this callback via the adafruit queue, because we can safely run in the BLE context
|
|
||||||
toRadio.begin();
|
toRadio.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,8 +230,6 @@ void NRF52Bluetooth::setup()
|
|||||||
|
|
||||||
// Configure and Start the Device Information Service
|
// Configure and Start the Device Information Service
|
||||||
DEBUG_MSG("Configuring the Device Information Service\n");
|
DEBUG_MSG("Configuring the Device Information Service\n");
|
||||||
// FIXME, we should set a mfg string based on our HW_VENDOR enum
|
|
||||||
// bledis.setManufacturer(HW_VENDOR);
|
|
||||||
bledis.setModel(optstr(HW_VERSION));
|
bledis.setModel(optstr(HW_VERSION));
|
||||||
bledis.setFirmwareRev(optstr(APP_VERSION));
|
bledis.setFirmwareRev(optstr(APP_VERSION));
|
||||||
bledis.begin();
|
bledis.begin();
|
||||||
@ -249,7 +238,6 @@ void NRF52Bluetooth::setup()
|
|||||||
DEBUG_MSG("Configuring the Battery Service\n");
|
DEBUG_MSG("Configuring the Battery Service\n");
|
||||||
blebas.begin();
|
blebas.begin();
|
||||||
blebas.write(0); // Unknown battery level for now
|
blebas.write(0); // Unknown battery level for now
|
||||||
|
|
||||||
bledfu.begin(); // Install the DFU helper
|
bledfu.begin(); // Install the DFU helper
|
||||||
|
|
||||||
// Setup the Heart Rate Monitor service using
|
// Setup the Heart Rate Monitor service using
|
||||||
@ -258,7 +246,8 @@ void NRF52Bluetooth::setup()
|
|||||||
setupMeshService();
|
setupMeshService();
|
||||||
|
|
||||||
// Supposedly debugging works with soft device if you disable advertising
|
// Supposedly debugging works with soft device if you disable advertising
|
||||||
if (isSoftDeviceAllowed) {
|
if (isSoftDeviceAllowed)
|
||||||
|
{
|
||||||
// Setup the advertising packet(s)
|
// Setup the advertising packet(s)
|
||||||
DEBUG_MSG("Setting up the advertising payload(s)\n");
|
DEBUG_MSG("Setting up the advertising payload(s)\n");
|
||||||
startAdv();
|
startAdv();
|
||||||
|
Loading…
Reference in New Issue
Block a user