mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Merge remote-tracking branch 'origin/dev' into awolden/t3lora
This commit is contained in:
commit
86389579eb
19 changed files with 745 additions and 84 deletions
|
|
@ -3,7 +3,7 @@
|
|||
#define ED25519_NO_SEED 1
|
||||
#include <ed_25519.h>
|
||||
|
||||
// For ESP32, we use libsodium for cryptographic operations to reduce stack usage
|
||||
// For weaker ESP32 boards, we use libsodium for cryptographic operations to reduce stack usage
|
||||
#ifdef USE_ESP32_ENCRYPTION
|
||||
#include <sodium.h>
|
||||
#endif
|
||||
|
|
@ -20,9 +20,6 @@ Identity::Identity(const char* pub_hex) {
|
|||
|
||||
bool Identity::verify(const uint8_t* sig, const uint8_t* message, int msg_len) const {
|
||||
#ifdef USE_ESP32_ENCRYPTION
|
||||
// Using libsodium for verification on ESP32 to reduce stack usage
|
||||
// This function performs signature verification with much lower stack requirements
|
||||
// than the default implementation
|
||||
return crypto_sign_ed25519_verify_detached(sig, message, msg_len, pub_key) == 0;
|
||||
#else
|
||||
return ed25519_verify(sig, message, msg_len, pub_key);
|
||||
|
|
@ -108,7 +105,6 @@ void LocalIdentity::readFrom(const uint8_t* src, size_t len) {
|
|||
#ifdef USE_ESP32_ENCRYPTION
|
||||
// In libsodium, the private key already contains the public key in its last 32 bytes
|
||||
// We can just extract it directly, avoiding the expensive derivation calculation
|
||||
// This significantly reduces stack usage on ESP32
|
||||
memcpy(pub_key, prv_key + 32, 32);
|
||||
#else
|
||||
// now need to re-calculate the pub_key
|
||||
|
|
@ -119,8 +115,6 @@ void LocalIdentity::readFrom(const uint8_t* src, size_t len) {
|
|||
|
||||
void LocalIdentity::sign(uint8_t* sig, const uint8_t* message, int msg_len) const {
|
||||
#ifdef USE_ESP32_ENCRYPTION
|
||||
// Use libsodium for signing on ESP32 to reduce stack usage
|
||||
// The libsodium implementation uses less stack space than the default ed25519 implementation
|
||||
crypto_sign_ed25519_detached(sig, NULL, message, msg_len, prv_key);
|
||||
#else
|
||||
ed25519_sign(sig, message, msg_len, pub_key, prv_key);
|
||||
|
|
@ -130,13 +124,11 @@ void LocalIdentity::sign(uint8_t* sig, const uint8_t* message, int msg_len) cons
|
|||
void LocalIdentity::calcSharedSecret(uint8_t* secret, const uint8_t* other_pub_key) {
|
||||
#ifdef USE_ESP32_ENCRYPTION
|
||||
// NOTE: To calculate a shared secret with Ed25519 keys and libsodium, we need to:
|
||||
// 1. Convert the Ed25519 keys to Curve25519 (X25519) format
|
||||
// 2. Perform the key exchange using the converted keys
|
||||
// Convert the Ed25519 keys to Curve25519 (X25519) format
|
||||
// Perform the key exchange using the converted keys
|
||||
//
|
||||
// The default implementation handles this conversion internally,
|
||||
// but with libsodium we need to do these steps explicitly.
|
||||
// This approach uses less stack space compared to the original implementation.
|
||||
|
||||
// but with libsodium we need to do these steps explicitly.
|
||||
unsigned char x25519_pk[crypto_scalarmult_curve25519_BYTES];
|
||||
unsigned char x25519_sk[crypto_scalarmult_curve25519_BYTES];
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
|
|||
// len can be > original length, but 'text' will be padded with zeroes
|
||||
data[len] = 0; // need to make a C string again, with null terminator
|
||||
|
||||
//if ( ! alreadyReceived timestamp ) {
|
||||
if (flags == TXT_TYPE_PLAIN) {
|
||||
onMessageRecv(from, packet->isRouteFlood() ? packet->path_len : 0xFF, timestamp, (const char *) &data[5]); // let UI know
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender
|
|||
// NOTE: no ack expected for CLI_DATA replies
|
||||
|
||||
if (packet->isRouteFlood()) {
|
||||
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
|
||||
// let this sender know path TO here, so they can use sendDirect() (NOTE: no ACK as extra)
|
||||
mesh::Packet* path = createPathReturn(from.id, secret, packet->path, packet->path_len, 0, NULL, 0);
|
||||
if (path) sendFlood(path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,89 @@ static uint32_t _atoi(const char* sp) {
|
|||
return n;
|
||||
}
|
||||
|
||||
void CommonCLI::loadPrefs(FILESYSTEM* fs) {
|
||||
if (fs->exists("/node_prefs")) {
|
||||
File file = fs->open("/node_prefs");
|
||||
if (file) {
|
||||
uint8_t pad[8];
|
||||
|
||||
file.read((uint8_t *) &_prefs->airtime_factor, sizeof(_prefs->airtime_factor)); // 0
|
||||
file.read((uint8_t *) &_prefs->node_name, sizeof(_prefs->node_name)); // 4
|
||||
file.read(pad, 4); // 36
|
||||
file.read((uint8_t *) &_prefs->node_lat, sizeof(_prefs->node_lat)); // 40
|
||||
file.read((uint8_t *) &_prefs->node_lon, sizeof(_prefs->node_lon)); // 48
|
||||
file.read((uint8_t *) &_prefs->password[0], sizeof(_prefs->password)); // 56
|
||||
file.read((uint8_t *) &_prefs->freq, sizeof(_prefs->freq)); // 72
|
||||
file.read((uint8_t *) &_prefs->tx_power_dbm, sizeof(_prefs->tx_power_dbm)); // 76
|
||||
file.read((uint8_t *) &_prefs->disable_fwd, sizeof(_prefs->disable_fwd)); // 77
|
||||
file.read((uint8_t *) &_prefs->advert_interval, sizeof(_prefs->advert_interval)); // 78
|
||||
file.read((uint8_t *) &_prefs->unused, sizeof(_prefs->unused)); // 79
|
||||
file.read((uint8_t *) &_prefs->rx_delay_base, sizeof(_prefs->rx_delay_base)); // 80
|
||||
file.read((uint8_t *) &_prefs->tx_delay_factor, sizeof(_prefs->tx_delay_factor)); // 84
|
||||
file.read((uint8_t *) &_prefs->guest_password[0], sizeof(_prefs->guest_password)); // 88
|
||||
file.read((uint8_t *) &_prefs->direct_tx_delay_factor, sizeof(_prefs->direct_tx_delay_factor)); // 104
|
||||
file.read(pad, 4); // 108
|
||||
file.read((uint8_t *) &_prefs->sf, sizeof(_prefs->sf)); // 112
|
||||
file.read((uint8_t *) &_prefs->cr, sizeof(_prefs->cr)); // 113
|
||||
file.read((uint8_t *) &_prefs->reserved1, sizeof(_prefs->reserved1)); // 114
|
||||
file.read((uint8_t *) &_prefs->reserved2, sizeof(_prefs->reserved2)); // 115
|
||||
file.read((uint8_t *) &_prefs->bw, sizeof(_prefs->bw)); // 116
|
||||
file.read(pad, 4); // 120
|
||||
|
||||
// sanitise bad pref values
|
||||
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
|
||||
_prefs->tx_delay_factor = constrain(_prefs->tx_delay_factor, 0, 2.0f);
|
||||
_prefs->direct_tx_delay_factor = constrain(_prefs->direct_tx_delay_factor, 0, 2.0f);
|
||||
_prefs->airtime_factor = constrain(_prefs->airtime_factor, 0, 9.0f);
|
||||
_prefs->freq = constrain(_prefs->freq, 400.0f, 2500.0f);
|
||||
_prefs->bw = constrain(_prefs->bw, 62.5f, 500.0f);
|
||||
_prefs->sf = constrain(_prefs->sf, 7, 12);
|
||||
_prefs->cr = constrain(_prefs->cr, 5, 8);
|
||||
_prefs->tx_power_dbm = constrain(_prefs->tx_power_dbm, 1, 30);
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
File file = fs->open("/node_prefs", FILE_O_WRITE);
|
||||
if (file) { file.seek(0); file.truncate(); }
|
||||
#else
|
||||
File file = fs->open("/node_prefs", "w", true);
|
||||
#endif
|
||||
if (file) {
|
||||
uint8_t pad[8];
|
||||
memset(pad, 0, sizeof(pad));
|
||||
|
||||
file.write((uint8_t *) &_prefs->airtime_factor, sizeof(_prefs->airtime_factor)); // 0
|
||||
file.write((uint8_t *) &_prefs->node_name, sizeof(_prefs->node_name)); // 4
|
||||
file.write(pad, 4); // 36
|
||||
file.write((uint8_t *) &_prefs->node_lat, sizeof(_prefs->node_lat)); // 40
|
||||
file.write((uint8_t *) &_prefs->node_lon, sizeof(_prefs->node_lon)); // 48
|
||||
file.write((uint8_t *) &_prefs->password[0], sizeof(_prefs->password)); // 56
|
||||
file.write((uint8_t *) &_prefs->freq, sizeof(_prefs->freq)); // 72
|
||||
file.write((uint8_t *) &_prefs->tx_power_dbm, sizeof(_prefs->tx_power_dbm)); // 76
|
||||
file.write((uint8_t *) &_prefs->disable_fwd, sizeof(_prefs->disable_fwd)); // 77
|
||||
file.write((uint8_t *) &_prefs->advert_interval, sizeof(_prefs->advert_interval)); // 78
|
||||
file.write((uint8_t *) &_prefs->unused, sizeof(_prefs->unused)); // 79
|
||||
file.write((uint8_t *) &_prefs->rx_delay_base, sizeof(_prefs->rx_delay_base)); // 80
|
||||
file.write((uint8_t *) &_prefs->tx_delay_factor, sizeof(_prefs->tx_delay_factor)); // 84
|
||||
file.write((uint8_t *) &_prefs->guest_password[0], sizeof(_prefs->guest_password)); // 88
|
||||
file.write((uint8_t *) &_prefs->direct_tx_delay_factor, sizeof(_prefs->direct_tx_delay_factor)); // 104
|
||||
file.write(pad, 4); // 108
|
||||
file.write((uint8_t *) &_prefs->sf, sizeof(_prefs->sf)); // 112
|
||||
file.write((uint8_t *) &_prefs->cr, sizeof(_prefs->cr)); // 113
|
||||
file.write((uint8_t *) &_prefs->reserved1, sizeof(_prefs->reserved1)); // 114
|
||||
file.write((uint8_t *) &_prefs->reserved2, sizeof(_prefs->reserved2)); // 115
|
||||
file.write((uint8_t *) &_prefs->bw, sizeof(_prefs->bw)); // 116
|
||||
file.write(pad, 4); // 120
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
#define MIN_LOCAL_ADVERT_INTERVAL 60
|
||||
|
||||
void CommonCLI::checkAdvertInterval() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Mesh.h"
|
||||
#include <helpers/IdentityStore.h>
|
||||
|
||||
struct NodePrefs { // persisted to file
|
||||
float airtime_factor;
|
||||
|
|
@ -54,5 +55,7 @@ public:
|
|||
CommonCLI(mesh::MainBoard& board, mesh::Mesh* mesh, NodePrefs* prefs, CommonCLICallbacks* callbacks)
|
||||
: _board(&board), _mesh(mesh), _prefs(prefs), _callbacks(callbacks) { }
|
||||
|
||||
void loadPrefs(FILESYSTEM* _fs);
|
||||
void savePrefs(FILESYSTEM* _fs);
|
||||
void handleCommand(uint32_t sender_timestamp, const char* command, char* reply);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#define PIN_ADC_CTRL_ACTIVE LOW
|
||||
#define PIN_ADC_CTRL_INACTIVE HIGH
|
||||
#define PIN_LED_BUILTIN 35
|
||||
#define PIN_VEXT_EN 36
|
||||
|
||||
#include "ESP32Board.h"
|
||||
|
||||
|
|
@ -28,6 +29,7 @@ public:
|
|||
ESP32Board::begin();
|
||||
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
//pinMode(PIN_VEXT_EN, OUTPUT);
|
||||
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
|
|
|
|||
27
src/helpers/ui/DisplayDriver.h
Normal file
27
src/helpers/ui/DisplayDriver.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class DisplayDriver {
|
||||
int _w, _h;
|
||||
protected:
|
||||
DisplayDriver(int w, int h) { _w = w; _h = h; }
|
||||
public:
|
||||
enum Color { DARK, LIGHT };
|
||||
|
||||
int width() const { return _w; }
|
||||
int height() const { return _h; }
|
||||
|
||||
virtual bool isOn() = 0;
|
||||
virtual void turnOn() = 0;
|
||||
virtual void turnOff() = 0;
|
||||
virtual void startFrame(Color bkg = DARK) = 0;
|
||||
virtual void setTextSize(int sz) = 0;
|
||||
virtual void setColor(Color c) = 0;
|
||||
virtual void setCursor(int x, int y) = 0;
|
||||
virtual void print(const char* str) = 0;
|
||||
virtual void fillRect(int x, int y, int w, int h) = 0;
|
||||
virtual void drawRect(int x, int y, int w, int h) = 0;
|
||||
virtual void drawXbm(int x, int y, const uint8_t* bits, int w, int h) = 0;
|
||||
virtual void endFrame() = 0;
|
||||
};
|
||||
56
src/helpers/ui/SSD1306Display.cpp
Normal file
56
src/helpers/ui/SSD1306Display.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "SSD1306Display.h"
|
||||
|
||||
bool SSD1306Display::begin() {
|
||||
return display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS);
|
||||
}
|
||||
|
||||
void SSD1306Display::turnOn() {
|
||||
display.ssd1306_command(SSD1306_DISPLAYON);
|
||||
_isOn = true;
|
||||
}
|
||||
|
||||
void SSD1306Display::turnOff() {
|
||||
display.ssd1306_command(SSD1306_DISPLAYOFF);
|
||||
_isOn = false;
|
||||
}
|
||||
|
||||
void SSD1306Display::startFrame(Color bkg) {
|
||||
display.clearDisplay(); // TODO: apply 'bkg'
|
||||
_color = SSD1306_WHITE;
|
||||
display.setTextColor(_color);
|
||||
display.setTextSize(1);
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
}
|
||||
|
||||
void SSD1306Display::setTextSize(int sz) {
|
||||
display.setTextSize(sz);
|
||||
}
|
||||
|
||||
void SSD1306Display::setColor(Color c) {
|
||||
_color = (c == LIGHT) ? SSD1306_WHITE : SSD1306_BLACK;
|
||||
display.setTextColor(_color);
|
||||
}
|
||||
|
||||
void SSD1306Display::setCursor(int x, int y) {
|
||||
display.setCursor(x, y);
|
||||
}
|
||||
|
||||
void SSD1306Display::print(const char* str) {
|
||||
display.print(str);
|
||||
}
|
||||
|
||||
void SSD1306Display::fillRect(int x, int y, int w, int h) {
|
||||
display.fillRect(x, y, w, h, _color);
|
||||
}
|
||||
|
||||
void SSD1306Display::drawRect(int x, int y, int w, int h) {
|
||||
display.drawRect(x, y, w, h, _color);
|
||||
}
|
||||
|
||||
void SSD1306Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
|
||||
display.drawBitmap(x, y, bits, w, h, SSD1306_WHITE);
|
||||
}
|
||||
|
||||
void SSD1306Display::endFrame() {
|
||||
display.display();
|
||||
}
|
||||
37
src/helpers/ui/SSD1306Display.h
Normal file
37
src/helpers/ui/SSD1306Display.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "DisplayDriver.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#ifndef PIN_OLED_RESET
|
||||
#define PIN_OLED_RESET 21 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||
#endif
|
||||
|
||||
#ifndef DISPLAY_ADDRESS
|
||||
#define DISPLAY_ADDRESS 0x3C
|
||||
#endif
|
||||
|
||||
class SSD1306Display : public DisplayDriver {
|
||||
Adafruit_SSD1306 display;
|
||||
bool _isOn;
|
||||
uint8_t _color;
|
||||
|
||||
public:
|
||||
SSD1306Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) { _isOn = false; }
|
||||
bool begin();
|
||||
|
||||
bool isOn() override { return _isOn; }
|
||||
void turnOn() override;
|
||||
void turnOff() override;
|
||||
void startFrame(Color bkg = DARK) override;
|
||||
void setTextSize(int sz) override;
|
||||
void setColor(Color c) override;
|
||||
void setCursor(int x, int y) override;
|
||||
void print(const char* str) override;
|
||||
void fillRect(int x, int y, int w, int h) override;
|
||||
void drawRect(int x, int y, int w, int h) override;
|
||||
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
|
||||
void endFrame() override;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue